Annotation of loncom/interface/domainprefs.pm, revision 1.281
1.1 raeburn 1: # The LearningOnline Network with CAPA
2: # Handler to set domain-wide configuration settings
3: #
1.281 ! raeburn 4: # $Id: domainprefs.pm,v 1.280 2016/09/16 23:42:58 raeburn Exp $
1.2 albertel 5: #
1.1 raeburn 6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA#
23: # /home/httpd/html/adm/gpl.txt
24: #
25: # http://www.lon-capa.org/
26: #
27: #
28: ###############################################################
29: ##############################################################
30:
1.101 raeburn 31: =pod
32:
33: =head1 NAME
34:
35: Apache::domainprefs.pm
36:
37: =head1 SYNOPSIS
38:
39: Handles configuration of a LON-CAPA domain.
40:
41: This is part of the LearningOnline Network with CAPA project
42: described at http://www.lon-capa.org.
43:
44:
45: =head1 OVERVIEW
46:
47: Each institution using LON-CAPA will typically have a single domain designated
1.183 bisitz 48: for use by individuals affiliated with the institution. Accordingly, each domain
1.101 raeburn 49: may define a default set of logos and a color scheme which can be used to "brand"
50: the LON-CAPA instance. In addition, an institution will typically have a language
51: and timezone which are used for the majority of courses.
52:
53: LON-CAPA provides a mechanism to display and modify these defaults, as well as a
54: host of other domain-wide settings which determine the types of functionality
55: available to users and courses in the domain.
56:
57: There is also a mechanism to configure cataloging of courses in the domain, and
58: controls on the operation of automated processes which govern such things as
59: roster updates, user directory updates and processing of course requests.
60:
61: The domain coordination manual which is built dynamically on install/update of
62: LON-CAPA from the relevant help items provides more information about domain
63: configuration.
64:
65: Most of the domain settings are stored in the configuration.db GDBM file which is
66: housed on the primary library server for the domain in /home/httpd/lonUsers/$dom,
67: where $dom is the domain. The configuration.db stores settings in a number of
68: frozen hashes of hashes. In a few cases, domain information must be uploaded to
69: the domain as files (e.g., image files for logos etc., or plain text files for
70: bubblesheet formats). In this case the domainprefs.pm must be running in a user
71: session hosted on the primary library server in the domain, as these files are
72: stored in author space belonging to a special $dom-domainconfig user.
73:
74: domainprefs.pm in combination with lonconfigsettings.pm will retrieve and display
75: the current settings, and provides an interface to make modifications.
76:
77: =head1 SUBROUTINES
78:
79: =over
80:
81: =item print_quotas()
82:
83: Inputs: 4
84:
85: $dom,$settings,$rowtotal,$action.
86:
87: $dom is the domain, $settings is a reference to a hash of current settings for
88: the current context, $rowtotal is a reference to the scalar used to record the
1.210 raeburn 89: number of rows displayed on the page, and $action is the context (quotas,
1.163 raeburn 90: requestcourses or requestauthor).
1.101 raeburn 91:
92: The print_quotas routine was orginally created to display/store information
93: about default quota sizes for portfolio spaces for the different types of
94: institutional affiliation in the domain (e.g., Faculty, Staff, Student etc.),
95: but is now also used to manage availability of user tools:
96: i.e., blogs, aboutme page, and portfolios, and the course request tool,
1.197 raeburn 97: used by course owners to request creation of a course, and to display/store
1.223 bisitz 98: default quota sizes for Authoring Spaces.
1.101 raeburn 99:
100: Outputs: 1
101:
102: $datatable - HTML containing form elements which allow settings to be changed.
103:
104: In the case of course requests, radio buttons are displayed for each institutional
105: affiliate type (and also default, and _LC_adv) for each of the course types
1.271 raeburn 106: (official, unofficial, community, textbook, and placement).
107: In each case the radio buttons allow the selection of one of four values:
1.101 raeburn 108:
1.104 raeburn 109: 0, approval, validate, autolimit=N (where N is blank, or a positive integer).
1.101 raeburn 110: which have the following effects:
111:
112: 0
113:
114: =over
115:
116: - course requests are not allowed for this course types/affiliation
117:
118: =back
119:
1.104 raeburn 120: approval
1.101 raeburn 121:
122: =over
123:
124: - course requests must be approved by a Doman Coordinator in the
125: course's domain
126:
127: =back
128:
129: validate
130:
131: =over
132:
133: - an institutional validation (e.g., check requestor is instructor
134: of record) needs to be passed before the course will be created. The required
135: validation is in localenroll.pm on the primary library server for the course
136: domain.
137:
138: =back
139:
140: autolimit
141:
142: =over
143:
1.143 raeburn 144: - course requests will be processed automatically up to a limit of
1.101 raeburn 145: N requests for the course type for the particular requestor.
146: If N is undefined, there is no limit to the number of course requests
147: which a course owner may submit and have processed automatically.
148:
149: =back
150:
151: =item modify_quotas()
152:
153: =back
154:
155: =cut
156:
1.1 raeburn 157: package Apache::domainprefs;
158:
159: use strict;
160: use Apache::Constants qw(:common :http);
161: use Apache::lonnet;
162: use Apache::loncommon();
163: use Apache::lonhtmlcommon();
164: use Apache::lonlocal;
1.43 raeburn 165: use Apache::lonmsg();
1.91 raeburn 166: use Apache::lonconfigsettings;
1.232 raeburn 167: use Apache::lonuserutils();
1.235 raeburn 168: use Apache::loncoursequeueadmin();
1.69 raeburn 169: use LONCAPA qw(:DEFAULT :match);
1.6 raeburn 170: use LONCAPA::Enrollment;
1.81 raeburn 171: use LONCAPA::lonauthcgi();
1.275 raeburn 172: use LONCAPA::SSL;
1.9 raeburn 173: use File::Copy;
1.43 raeburn 174: use Locale::Language;
1.62 raeburn 175: use DateTime::TimeZone;
1.68 raeburn 176: use DateTime::Locale;
1.267 raeburn 177: use Time::HiRes qw( sleep );
1.1 raeburn 178:
1.155 raeburn 179: my $registered_cleanup;
180: my $modified_urls;
181:
1.1 raeburn 182: sub handler {
183: my $r=shift;
184: if ($r->header_only) {
185: &Apache::loncommon::content_type($r,'text/html');
186: $r->send_http_header;
187: return OK;
188: }
189:
1.91 raeburn 190: my $context = 'domain';
1.1 raeburn 191: my $dom = $env{'request.role.domain'};
1.5 albertel 192: my $domdesc = &Apache::lonnet::domain($dom,'description');
1.1 raeburn 193: if (&Apache::lonnet::allowed('mau',$dom)) {
194: &Apache::loncommon::content_type($r,'text/html');
195: $r->send_http_header;
196: } else {
197: $env{'user.error.msg'}=
198: "/adm/domainprefs:mau:0:0:Cannot modify domain settings";
199: return HTTP_NOT_ACCEPTABLE;
200: }
1.155 raeburn 201:
202: $registered_cleanup=0;
203: @{$modified_urls}=();
204:
1.1 raeburn 205: &Apache::lonhtmlcommon::clear_breadcrumbs();
206: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.58 raeburn 207: ['phase','actions']);
1.30 raeburn 208: my $phase = 'pickactions';
1.3 raeburn 209: if ( exists($env{'form.phase'}) ) {
210: $phase = $env{'form.phase'};
211: }
1.150 raeburn 212: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.3 raeburn 213: my %domconfig =
1.6 raeburn 214: &Apache::lonnet::get_dom('configuration',['login','rolecolors',
1.125 raeburn 215: 'quotas','autoenroll','autoupdate','autocreate',
216: 'directorysrch','usercreation','usermodification',
217: 'contacts','defaults','scantron','coursecategories',
218: 'serverstatuses','requestcourses','helpsettings',
1.163 raeburn 219: 'coursedefaults','usersessions','loadbalancing',
1.267 raeburn 220: 'requestauthor','selfenrollment','inststatus',
1.279 raeburn 221: 'ltitools','ssl','trust'],$dom);
1.43 raeburn 222: my @prefs_order = ('rolecolors','login','defaults','quotas','autoenroll',
1.125 raeburn 223: 'autoupdate','autocreate','directorysrch','contacts',
1.224 raeburn 224: 'usercreation','selfcreation','usermodification','scantron',
1.163 raeburn 225: 'requestcourses','requestauthor','coursecategories',
1.267 raeburn 226: 'serverstatuses','helpsettings','coursedefaults',
1.279 raeburn 227: 'ltitools','selfenrollment','usersessions','ssl','trust');
1.171 raeburn 228: my %existing;
229: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
230: %existing = %{$domconfig{'loadbalancing'}};
231: }
232: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
1.150 raeburn 233: push(@prefs_order,'loadbalancing');
234: }
1.30 raeburn 235: my %prefs = (
236: 'rolecolors' =>
237: { text => 'Default color schemes',
1.67 raeburn 238: help => 'Domain_Configuration_Color_Schemes',
1.30 raeburn 239: header => [{col1 => 'Student Settings',
240: col2 => '',},
241: {col1 => 'Coordinator Settings',
242: col2 => '',},
243: {col1 => 'Author Settings',
244: col2 => '',},
245: {col1 => 'Administrator Settings',
246: col2 => '',}],
1.230 raeburn 247: print => \&print_rolecolors,
248: modify => \&modify_rolecolors,
1.30 raeburn 249: },
1.110 raeburn 250: 'login' =>
1.30 raeburn 251: { text => 'Log-in page options',
1.67 raeburn 252: help => 'Domain_Configuration_Login_Page',
1.168 raeburn 253: header => [{col1 => 'Log-in Page Items',
254: col2 => '',},
255: {col1 => 'Log-in Help',
1.256 raeburn 256: col2 => 'Value'},
257: {col1 => 'Custom HTML in document head',
1.168 raeburn 258: col2 => 'Value'}],
1.230 raeburn 259: print => \&print_login,
260: modify => \&modify_login,
1.30 raeburn 261: },
1.43 raeburn 262: 'defaults' =>
1.236 raeburn 263: { text => 'Default authentication/language/timezone/portal/types',
1.67 raeburn 264: help => 'Domain_Configuration_LangTZAuth',
1.43 raeburn 265: header => [{col1 => 'Setting',
1.236 raeburn 266: col2 => 'Value'},
267: {col1 => 'Institutional user types',
268: col2 => 'Assignable to e-mail usernames'}],
1.230 raeburn 269: print => \&print_defaults,
270: modify => \&modify_defaults,
1.43 raeburn 271: },
1.30 raeburn 272: 'quotas' =>
1.197 raeburn 273: { text => 'Blogs, personal web pages, webDAV/quotas, portfolios',
1.67 raeburn 274: help => 'Domain_Configuration_Quotas',
1.77 raeburn 275: header => [{col1 => 'User affiliation',
1.72 raeburn 276: col2 => 'Available tools',
1.213 raeburn 277: col3 => 'Quotas, MB; (Authoring requires role)',}],
1.230 raeburn 278: print => \&print_quotas,
279: modify => \&modify_quotas,
1.30 raeburn 280: },
281: 'autoenroll' =>
282: { text => 'Auto-enrollment settings',
1.67 raeburn 283: help => 'Domain_Configuration_Auto_Enrollment',
1.30 raeburn 284: header => [{col1 => 'Configuration setting',
285: col2 => 'Value(s)'}],
1.230 raeburn 286: print => \&print_autoenroll,
287: modify => \&modify_autoenroll,
1.30 raeburn 288: },
289: 'autoupdate' =>
290: { text => 'Auto-update settings',
1.67 raeburn 291: help => 'Domain_Configuration_Auto_Updates',
1.30 raeburn 292: header => [{col1 => 'Setting',
293: col2 => 'Value',},
1.131 raeburn 294: {col1 => 'Setting',
295: col2 => 'Affiliation'},
1.43 raeburn 296: {col1 => 'User population',
1.227 bisitz 297: col2 => 'Updatable user data'}],
1.230 raeburn 298: print => \&print_autoupdate,
299: modify => \&modify_autoupdate,
1.30 raeburn 300: },
1.125 raeburn 301: 'autocreate' =>
302: { text => 'Auto-course creation settings',
303: help => 'Domain_Configuration_Auto_Creation',
304: header => [{col1 => 'Configuration Setting',
305: col2 => 'Value',}],
1.230 raeburn 306: print => \&print_autocreate,
307: modify => \&modify_autocreate,
1.125 raeburn 308: },
1.30 raeburn 309: 'directorysrch' =>
1.277 raeburn 310: { text => 'Directory searches',
1.67 raeburn 311: help => 'Domain_Configuration_InstDirectory_Search',
1.277 raeburn 312: header => [{col1 => 'Institutional Directory Setting',
313: col2 => 'Value',},
314: {col1 => 'LON-CAPA Directory Setting',
1.30 raeburn 315: col2 => 'Value',}],
1.230 raeburn 316: print => \&print_directorysrch,
317: modify => \&modify_directorysrch,
1.30 raeburn 318: },
319: 'contacts' =>
320: { text => 'Contact Information',
1.67 raeburn 321: help => 'Domain_Configuration_Contact_Info',
1.30 raeburn 322: header => [{col1 => 'Setting',
323: col2 => 'Value',}],
1.230 raeburn 324: print => \&print_contacts,
325: modify => \&modify_contacts,
1.30 raeburn 326: },
327: 'usercreation' =>
328: { text => 'User creation',
1.67 raeburn 329: help => 'Domain_Configuration_User_Creation',
1.43 raeburn 330: header => [{col1 => 'Format rule type',
331: col2 => 'Format rules in force'},
1.34 raeburn 332: {col1 => 'User account creation',
333: col2 => 'Usernames which may be created',},
1.30 raeburn 334: {col1 => 'Context',
1.43 raeburn 335: col2 => 'Assignable authentication types'}],
1.230 raeburn 336: print => \&print_usercreation,
337: modify => \&modify_usercreation,
1.30 raeburn 338: },
1.224 raeburn 339: 'selfcreation' =>
340: { text => 'Users self-creating accounts',
341: help => 'Domain_Configuration_Self_Creation',
342: header => [{col1 => 'Self-creation with institutional username',
343: col2 => 'Enabled?'},
344: {col1 => 'Institutional user type (login/SSO self-creation)',
345: col2 => 'Information user can enter'},
346: {col1 => 'Self-creation with e-mail as username',
347: col2 => 'Settings'}],
1.230 raeburn 348: print => \&print_selfcreation,
349: modify => \&modify_selfcreation,
1.224 raeburn 350: },
1.69 raeburn 351: 'usermodification' =>
1.33 raeburn 352: { text => 'User modification',
1.67 raeburn 353: help => 'Domain_Configuration_User_Modification',
1.33 raeburn 354: header => [{col1 => 'Target user has role',
1.227 bisitz 355: col2 => 'User information updatable in author context'},
1.33 raeburn 356: {col1 => 'Target user has role',
1.227 bisitz 357: col2 => 'User information updatable in course context'}],
1.230 raeburn 358: print => \&print_usermodification,
359: modify => \&modify_usermodification,
1.33 raeburn 360: },
1.69 raeburn 361: 'scantron' =>
1.95 www 362: { text => 'Bubblesheet format file',
1.67 raeburn 363: help => 'Domain_Configuration_Scantron_Format',
1.46 raeburn 364: header => [ {col1 => 'Item',
365: col2 => '',
366: }],
1.230 raeburn 367: print => \&print_scantron,
368: modify => \&modify_scantron,
1.46 raeburn 369: },
1.86 raeburn 370: 'requestcourses' =>
371: {text => 'Request creation of courses',
372: help => 'Domain_Configuration_Request_Courses',
373: header => [{col1 => 'User affiliation',
1.102 raeburn 374: col2 => 'Availability/Processing of requests',},
375: {col1 => 'Setting',
1.216 raeburn 376: col2 => 'Value'},
377: {col1 => 'Available textbooks',
1.235 raeburn 378: col2 => ''},
1.242 raeburn 379: {col1 => 'Available templates',
380: col2 => ''},
1.235 raeburn 381: {col1 => 'Validation (not official courses)',
382: col2 => 'Value'},],
1.230 raeburn 383: print => \&print_quotas,
384: modify => \&modify_quotas,
1.86 raeburn 385: },
1.163 raeburn 386: 'requestauthor' =>
1.223 bisitz 387: {text => 'Request Authoring Space',
1.163 raeburn 388: help => 'Domain_Configuration_Request_Author',
389: header => [{col1 => 'User affiliation',
390: col2 => 'Availability/Processing of requests',},
391: {col1 => 'Setting',
392: col2 => 'Value'}],
1.230 raeburn 393: print => \&print_quotas,
394: modify => \&modify_quotas,
1.163 raeburn 395: },
1.69 raeburn 396: 'coursecategories' =>
1.120 raeburn 397: { text => 'Cataloging of courses/communities',
1.67 raeburn 398: help => 'Domain_Configuration_Cataloging_Courses',
1.238 raeburn 399: header => [{col1 => 'Catalog type/availability',
400: col2 => '',},
401: {col1 => 'Category settings for standard catalog',
1.57 raeburn 402: col2 => '',},
403: {col1 => 'Categories',
404: col2 => '',
405: }],
1.230 raeburn 406: print => \&print_coursecategories,
407: modify => \&modify_coursecategories,
1.69 raeburn 408: },
409: 'serverstatuses' =>
1.77 raeburn 410: {text => 'Access to server status pages',
1.69 raeburn 411: help => 'Domain_Configuration_Server_Status',
412: header => [{col1 => 'Status Page',
413: col2 => 'Other named users',
414: col3 => 'Specific IPs',
415: }],
1.230 raeburn 416: print => \&print_serverstatuses,
417: modify => \&modify_serverstatuses,
1.69 raeburn 418: },
1.118 jms 419: 'helpsettings' =>
420: {text => 'Help page settings',
421: help => 'Domain_Configuration_Help_Settings',
1.166 raeburn 422: header => [{col1 => 'Help Settings (logged-in users)',
423: col2 => 'Value'}],
1.230 raeburn 424: print => \&print_helpsettings,
425: modify => \&modify_helpsettings,
1.118 jms 426: },
1.121 raeburn 427: 'coursedefaults' =>
428: {text => 'Course/Community defaults',
429: help => 'Domain_Configuration_Course_Defaults',
1.139 raeburn 430: header => [{col1 => 'Defaults which can be overridden in each course by a CC',
431: col2 => 'Value',},
432: {col1 => 'Defaults which can be overridden for each course by a DC',
433: col2 => 'Value',},],
1.230 raeburn 434: print => \&print_coursedefaults,
435: modify => \&modify_coursedefaults,
1.121 raeburn 436: },
1.231 raeburn 437: 'selfenrollment' =>
438: {text => 'Self-enrollment in Course/Community',
439: help => 'Domain_Configuration_Selfenrollment',
440: header => [{col1 => 'Configuration Rights',
441: col2 => 'Configured by Course Personnel or Domain Coordinator?'},
442: {col1 => 'Defaults',
443: col2 => 'Value'},
444: {col1 => 'Self-enrollment validation (optional)',
445: col2 => 'Value'},],
446: print => \&print_selfenrollment,
447: modify => \&modify_selfenrollment,
448: },
1.120 raeburn 449: 'privacy' =>
450: {text => 'User Privacy',
451: help => 'Domain_Configuration_User_Privacy',
452: header => [{col1 => 'Setting',
453: col2 => 'Value',}],
1.230 raeburn 454: print => \&print_privacy,
455: modify => \&modify_privacy,
1.120 raeburn 456: },
1.141 raeburn 457: 'usersessions' =>
1.145 raeburn 458: {text => 'User session hosting/offloading',
1.137 raeburn 459: help => 'Domain_Configuration_User_Sessions',
1.145 raeburn 460: header => [{col1 => 'Domain server',
461: col2 => 'Servers to offload sessions to when busy'},
462: {col1 => 'Hosting of users from other domains',
1.137 raeburn 463: col2 => 'Rules'},
464: {col1 => "Hosting domain's own users elsewhere",
465: col2 => 'Rules'}],
1.230 raeburn 466: print => \&print_usersessions,
467: modify => \&modify_usersessions,
1.137 raeburn 468: },
1.279 raeburn 469: 'loadbalancing' =>
1.185 raeburn 470: {text => 'Dedicated Load Balancer(s)',
1.150 raeburn 471: help => 'Domain_Configuration_Load_Balancing',
1.171 raeburn 472: header => [{col1 => 'Balancers',
1.150 raeburn 473: col2 => 'Default destinations',
1.183 bisitz 474: col3 => 'User affiliation',
1.150 raeburn 475: col4 => 'Overrides'},
476: ],
1.230 raeburn 477: print => \&print_loadbalancing,
478: modify => \&modify_loadbalancing,
1.150 raeburn 479: },
1.279 raeburn 480: 'ltitools' =>
1.267 raeburn 481: {text => 'External Tools (LTI)',
482: help => 'Domain_configuration_LTI_Tools',
483: header => [{col1 => 'Setting',
484: col2 => 'Value',}],
485: print => \&print_ltitools,
486: modify => \&modify_ltitools,
487: },
1.279 raeburn 488: 'ssl' =>
1.275 raeburn 489: {text => 'LON-CAPA Network (SSL)',
490: help => 'Domain_Configuration_Network_SSL',
491: header => [{col1 => 'Server',
492: col2 => 'Certificate Status'},
493: {col1 => 'Connections to other servers',
494: col2 => 'Rules'},
495: {col1 => "Replicating domain's published content",
496: col2 => 'Rules'}],
497: print => \&print_ssl,
498: modify => \&modify_ssl,
499: },
1.279 raeburn 500: 'trust' =>
501: {text => 'Trust Settings',
502: help => 'Domain_Configuration_Trust',
503: header => [{col1 => "Access to this domain's content by others",
504: col2 => 'Rules'},
505: {col1 => "Access to other domain's content by this domain",
506: col2 => 'Rules'},
507: {col1 => "Enrollment in this domain's courses by others",
508: col2 => 'Rules',},
509: {col1 => "Co-author roles in this domain for others",
510: col2 => 'Rules',},
511: {col1 => "Co-author roles for this domain's users elsewhere",
512: col2 => 'Rules',},
513: {col1 => "Domain roles in this domain assignable to others",
514: col2 => 'Rules'},
515: {col1 => "Course catalog for this domain displayed elsewhere",
516: col2 => 'Rules'},
517: {col1 => "Requests for creation of courses in this domain by others",
518: col2 => 'Rules'},
519: {col1 => "Users in other domains can send messages to this domain",
520: col2 => 'Rules'},],
521: print => \&print_trust,
522: modify => \&modify_trust,
523: },
1.3 raeburn 524: );
1.110 raeburn 525: if (keys(%servers) > 1) {
526: $prefs{'login'} = { text => 'Log-in page options',
527: help => 'Domain_Configuration_Login_Page',
528: header => [{col1 => 'Log-in Service',
529: col2 => 'Server Setting',},
530: {col1 => 'Log-in Page Items',
1.168 raeburn 531: col2 => ''},
532: {col1 => 'Log-in Help',
1.256 raeburn 533: col2 => 'Value'},
534: {col1 => 'Custom HTML in document head',
1.168 raeburn 535: col2 => 'Value'}],
1.230 raeburn 536: print => \&print_login,
537: modify => \&modify_login,
1.110 raeburn 538: };
539: }
1.174 foxr 540:
1.6 raeburn 541: my @roles = ('student','coordinator','author','admin');
1.30 raeburn 542: my @actions = &Apache::loncommon::get_env_multiple('form.actions');
1.3 raeburn 543: &Apache::lonhtmlcommon::add_breadcrumb
1.30 raeburn 544: ({href=>"javascript:changePage(document.$phase,'pickactions')",
1.133 raeburn 545: text=>"Settings to display/modify"});
1.9 raeburn 546: my $confname = $dom.'-domainconfig';
1.174 foxr 547:
1.3 raeburn 548: if ($phase eq 'process') {
1.212 raeburn 549: my $result = &Apache::lonconfigsettings::make_changes($r,$dom,$phase,$context,\@prefs_order,
550: \%prefs,\%domconfig,$confname,\@roles);
1.224 raeburn 551: if ((ref($result) eq 'HASH') && (keys(%{$result}))) {
1.205 raeburn 552: $r->rflush();
1.212 raeburn 553: &devalidate_remote_domconfs($dom,$result);
1.205 raeburn 554: }
1.30 raeburn 555: } elsif ($phase eq 'display') {
1.192 raeburn 556: my $js = &recaptcha_js().
1.236 raeburn 557: &toggle_display_js();
1.171 raeburn 558: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
1.152 raeburn 559: my ($othertitle,$usertypes,$types) =
560: &Apache::loncommon::sorted_inst_types($dom);
1.171 raeburn 561: $js .= &lonbalance_targets_js($dom,$types,\%servers,
562: $domconfig{'loadbalancing'}).
1.170 raeburn 563: &new_spares_js().
564: &common_domprefs_js().
565: &Apache::loncommon::javascript_array_indexof();
1.152 raeburn 566: }
1.216 raeburn 567: if (grep(/^requestcourses$/,@actions)) {
568: my $javascript_validations;
569: my $coursebrowserjs=&Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'});
570: $js .= <<END;
571: <script type="text/javascript">
572: $javascript_validations
573: </script>
574: $coursebrowserjs
575: END
576: }
1.150 raeburn 577: &Apache::lonconfigsettings::display_settings($r,$dom,$phase,$context,\@prefs_order,\%prefs,\%domconfig,$confname,$js);
1.1 raeburn 578: } else {
1.180 raeburn 579: # check if domconfig user exists for the domain.
580: my $servadm = $r->dir_config('lonAdmEMail');
581: my ($configuserok,$author_ok,$switchserver) =
582: &config_check($dom,$confname,$servadm);
583: unless ($configuserok eq 'ok') {
1.181 raeburn 584: &Apache::lonconfigsettings::print_header($r,$phase,$context);
585: $r->print(&mt('The domain configuration user "[_1]" has yet to be created.',
1.210 raeburn 586: $confname).
1.181 raeburn 587: '<br />'
588: );
1.180 raeburn 589: if ($switchserver) {
1.181 raeburn 590: $r->print(&mt('Ordinarily, that domain configuration user is created when the ./UPDATE script is run to install LON-CAPA for the first time.').
591: '<br />'.
592: &mt('However, that does not apply when new domains are added to a multi-domain server, and ./UPDATE has not been run recently.').
593: '<br />'.
594: &mt('The "[_1]" user can be created automatically when a Domain Coordinator visits the web-based "Set domain configuration" screen, in a session hosted on the primary library server.',$confname).
595: '<br />'.
596: &mt('To do that now, use the following link: [_1]',$switchserver)
597: );
598: } else {
599: $r->print(&mt('To create that user from the command line run the ./UPDATE script found in the top level directory of the extracted LON-CAPA tarball.').
600: '<br />'.
601: &mt('Once that is done, you will be able to use the web-based "Set domain configuration" to configure the domain')
602: );
1.180 raeburn 603: }
604: $r->print(&Apache::loncommon::end_page());
605: return OK;
606: }
1.21 raeburn 607: if (keys(%domconfig) == 0) {
608: my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
1.29 raeburn 609: my @ids=&Apache::lonnet::current_machine_ids();
610: if (!grep(/^\Q$primarylibserv\E$/,@ids)) {
1.21 raeburn 611: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.41 raeburn 612: my @loginimages = ('img','logo','domlogo','login');
1.21 raeburn 613: my $custom_img_count = 0;
614: foreach my $img (@loginimages) {
615: if ($designhash{$dom.'.login.'.$img} ne '') {
616: $custom_img_count ++;
617: }
618: }
619: foreach my $role (@roles) {
620: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
621: $custom_img_count ++;
622: }
623: }
624: if ($custom_img_count > 0) {
1.94 raeburn 625: &Apache::lonconfigsettings::print_header($r,$phase,$context);
1.21 raeburn 626: my $switch_server = &check_switchserver($dom,$confname);
1.29 raeburn 627: $r->print(
628: &mt('Domain configuration settings have yet to be saved for this domain via the web-based domain preferences interface.').'<br />'.
629: &mt("While this remains so, you must switch to the domain's primary library server in order to update settings.").'<br /><br />'.
630: &mt("Thereafter, (with a Domain Coordinator role selected in the domain) you will be able to update settings when logged in to any server in the LON-CAPA network.").'<br />'.
631: &mt("However, you will still need to switch to the domain's primary library server to upload new images or logos.").'<br /><br />');
632: if ($switch_server) {
1.30 raeburn 633: $r->print($switch_server.' '.&mt('to primary library server for domain: [_1]',$dom));
1.29 raeburn 634: }
1.91 raeburn 635: $r->print(&Apache::loncommon::end_page());
1.21 raeburn 636: return OK;
637: }
638: }
639: }
1.91 raeburn 640: &Apache::lonconfigsettings::display_choices($r,$phase,$context,\@prefs_order,\%prefs);
1.3 raeburn 641: }
642: return OK;
643: }
644:
645: sub process_changes {
1.205 raeburn 646: my ($r,$dom,$confname,$action,$roles,$values,$lastactref) = @_;
1.92 raeburn 647: my %domconfig;
648: if (ref($values) eq 'HASH') {
649: %domconfig = %{$values};
650: }
1.3 raeburn 651: my $output;
652: if ($action eq 'login') {
1.205 raeburn 653: $output = &modify_login($r,$dom,$confname,$lastactref,%domconfig);
1.6 raeburn 654: } elsif ($action eq 'rolecolors') {
1.9 raeburn 655: $output = &modify_rolecolors($r,$dom,$confname,$roles,
1.205 raeburn 656: $lastactref,%domconfig);
1.3 raeburn 657: } elsif ($action eq 'quotas') {
1.216 raeburn 658: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.3 raeburn 659: } elsif ($action eq 'autoenroll') {
1.205 raeburn 660: $output = &modify_autoenroll($dom,$lastactref,%domconfig);
1.3 raeburn 661: } elsif ($action eq 'autoupdate') {
662: $output = &modify_autoupdate($dom,%domconfig);
1.125 raeburn 663: } elsif ($action eq 'autocreate') {
664: $output = &modify_autocreate($dom,%domconfig);
1.23 raeburn 665: } elsif ($action eq 'directorysrch') {
666: $output = &modify_directorysrch($dom,%domconfig);
1.27 raeburn 667: } elsif ($action eq 'usercreation') {
1.28 raeburn 668: $output = &modify_usercreation($dom,%domconfig);
1.224 raeburn 669: } elsif ($action eq 'selfcreation') {
670: $output = &modify_selfcreation($dom,%domconfig);
1.33 raeburn 671: } elsif ($action eq 'usermodification') {
672: $output = &modify_usermodification($dom,%domconfig);
1.28 raeburn 673: } elsif ($action eq 'contacts') {
1.205 raeburn 674: $output = &modify_contacts($dom,$lastactref,%domconfig);
1.43 raeburn 675: } elsif ($action eq 'defaults') {
1.212 raeburn 676: $output = &modify_defaults($dom,$lastactref,%domconfig);
1.46 raeburn 677: } elsif ($action eq 'scantron') {
1.205 raeburn 678: $output = &modify_scantron($r,$dom,$confname,$lastactref,%domconfig);
1.48 raeburn 679: } elsif ($action eq 'coursecategories') {
1.239 raeburn 680: $output = &modify_coursecategories($dom,$lastactref,%domconfig);
1.69 raeburn 681: } elsif ($action eq 'serverstatuses') {
682: $output = &modify_serverstatuses($dom,%domconfig);
1.86 raeburn 683: } elsif ($action eq 'requestcourses') {
1.216 raeburn 684: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.163 raeburn 685: } elsif ($action eq 'requestauthor') {
1.216 raeburn 686: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.118 jms 687: } elsif ($action eq 'helpsettings') {
1.122 jms 688: $output = &modify_helpsettings($r,$dom,$confname,%domconfig);
1.121 raeburn 689: } elsif ($action eq 'coursedefaults') {
1.212 raeburn 690: $output = &modify_coursedefaults($dom,$lastactref,%domconfig);
1.231 raeburn 691: } elsif ($action eq 'selfenrollment') {
692: $output = &modify_selfenrollment($dom,$lastactref,%domconfig)
1.137 raeburn 693: } elsif ($action eq 'usersessions') {
1.212 raeburn 694: $output = &modify_usersessions($dom,$lastactref,%domconfig);
1.150 raeburn 695: } elsif ($action eq 'loadbalancing') {
696: $output = &modify_loadbalancing($dom,%domconfig);
1.267 raeburn 697: } elsif ($action eq 'ltitools') {
698: $output = &modify_ltitools($r,$dom,$action,$lastactref,%domconfig);
1.275 raeburn 699: } elsif ($action eq 'ssl') {
700: $output = &modify_ssl($dom,$lastactref,%domconfig);
1.279 raeburn 701: } elsif ($action eq 'trust') {
702: $output = &modify_trust($dom,$lastactref,%domconfig);
1.3 raeburn 703: }
704: return $output;
705: }
706:
707: sub print_config_box {
1.9 raeburn 708: my ($r,$dom,$confname,$phase,$action,$item,$settings) = @_;
1.30 raeburn 709: my $rowtotal = 0;
1.49 raeburn 710: my $output;
711: if ($action eq 'coursecategories') {
712: $output = &coursecategories_javascript($settings);
1.236 raeburn 713: } elsif ($action eq 'defaults') {
714: $output = &defaults_javascript($settings);
1.91 raeburn 715: }
1.236 raeburn 716: $output .=
1.30 raeburn 717: '<table class="LC_nested_outer">
1.3 raeburn 718: <tr>
1.66 raeburn 719: <th align="left" valign="middle"><span class="LC_nobreak">'.
720: &mt($item->{text}).' '.
721: &Apache::loncommon::help_open_topic($item->{'help'}).'</span></th>'."\n".
722: '</tr>';
1.30 raeburn 723: $rowtotal ++;
1.110 raeburn 724: my $numheaders = 1;
725: if (ref($item->{'header'}) eq 'ARRAY') {
726: $numheaders = scalar(@{$item->{'header'}});
727: }
728: if ($numheaders > 1) {
1.64 raeburn 729: my $colspan = '';
1.145 raeburn 730: my $rightcolspan = '';
1.238 raeburn 731: if (($action eq 'rolecolors') || ($action eq 'defaults') ||
1.277 raeburn 732: ($action eq 'directorysrch') ||
1.256 raeburn 733: (($action eq 'login') && ($numheaders < 4))) {
1.64 raeburn 734: $colspan = ' colspan="2"';
735: }
1.145 raeburn 736: if ($action eq 'usersessions') {
737: $rightcolspan = ' colspan="3"';
738: }
1.30 raeburn 739: $output .= '
1.3 raeburn 740: <tr>
741: <td>
742: <table class="LC_nested">
743: <tr class="LC_info_row">
1.59 bisitz 744: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[0]->{'col1'}).'</td>
1.145 raeburn 745: <td class="LC_right_item"'.$rightcolspan.'>'.&mt($item->{'header'}->[0]->{'col2'}).'</td>
1.30 raeburn 746: </tr>';
1.69 raeburn 747: $rowtotal ++;
1.230 raeburn 748: if (($action eq 'autoupdate') || ($action eq 'usercreation') || ($action eq 'selfcreation') ||
1.236 raeburn 749: ($action eq 'usermodification') || ($action eq 'defaults') || ($action eq 'coursedefaults') ||
1.277 raeburn 750: ($action eq 'selfenrollment') || ($action eq 'usersessions') || ($action eq 'ssl') ||
1.279 raeburn 751: ($action eq 'directorysrch') || ($action eq 'trust')) {
1.230 raeburn 752: $output .= $item->{'print'}->('top',$dom,$settings,\$rowtotal);
1.57 raeburn 753: } elsif ($action eq 'coursecategories') {
1.230 raeburn 754: $output .= $item->{'print'}->('top',$dom,$item,$settings,\$rowtotal);
1.110 raeburn 755: } elsif ($action eq 'login') {
1.256 raeburn 756: if ($numheaders == 4) {
1.168 raeburn 757: $colspan = ' colspan="2"';
758: $output .= &print_login('service',$dom,$confname,$phase,$settings,\$rowtotal);
759: } else {
760: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal);
761: }
1.230 raeburn 762: } elsif (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.163 raeburn 763: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.122 jms 764: } elsif ($action eq 'rolecolors') {
1.30 raeburn 765: $output .= &print_rolecolors($phase,'student',$dom,$confname,$settings,\$rowtotal);
1.6 raeburn 766: }
1.30 raeburn 767: $output .= '
1.6 raeburn 768: </table>
769: </td>
770: </tr>
771: <tr>
772: <td>
773: <table class="LC_nested">
774: <tr class="LC_info_row">
1.230 raeburn 775: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col1'}).'</td>
1.59 bisitz 776: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col2'}).'</td>
1.30 raeburn 777: </tr>';
778: $rowtotal ++;
1.230 raeburn 779: if (($action eq 'autoupdate') || ($action eq 'usercreation') ||
780: ($action eq 'selfcreation') || ($action eq 'selfenrollment') ||
1.275 raeburn 781: ($action eq 'usersessions') || ($action eq 'coursecategories') ||
1.279 raeburn 782: ($action eq 'ssl') || ($action eq 'trust')) {
1.238 raeburn 783: if ($action eq 'coursecategories') {
784: $output .= &print_coursecategories('middle',$dom,$item,$settings,\$rowtotal);
785: $colspan = ' colspan="2"';
1.279 raeburn 786: } elsif ($action eq 'trust') {
787: $output .= $item->{'print'}->('shared',$dom,$settings,\$rowtotal);
1.238 raeburn 788: } else {
789: $output .= $item->{'print'}->('middle',$dom,$settings,\$rowtotal);
790: }
1.279 raeburn 791: if ($action eq 'trust') {
792: $output .= '
793: </table>
794: </td>
795: </tr>';
796: my @trusthdrs = qw(2 3 4 5 6 7);
797: my @prefixes = qw(enroll othcoau coaurem domroles catalog reqcrs);
798: for (my $i=0; $i<@trusthdrs; $i++) {
799: $output .= '
800: <tr>
801: <td>
802: <table class="LC_nested">
803: <tr class="LC_info_row">
804: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[$trusthdrs[$i]]->{'col1'}).'</td>
805: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[$trusthdrs[$i]]->{'col2'}).'</td></tr>'.
806: $item->{'print'}->($prefixes[$i],$dom,$settings,\$rowtotal).'
807: </table>
808: </td>
809: </tr>';
810: }
811: $output .= '
812: <tr>
813: <td>
814: <table class="LC_nested">
815: <tr class="LC_info_row">
816: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[8]->{'col1'}).'</td>
817: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[8]->{'col2'}).'</td></tr>'.
818: $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
819: } else {
820: $output .= '
1.63 raeburn 821: </table>
822: </td>
823: </tr>
824: <tr>
825: <td>
826: <table class="LC_nested">
827: <tr class="LC_info_row">
828: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1.224 raeburn 829: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
1.238 raeburn 830: </tr>'."\n";
1.279 raeburn 831: if ($action eq 'coursecategories') {
832: $output .= &print_coursecategories('bottom',$dom,$item,$settings,\$rowtotal);
833: } else {
834: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
835: }
1.238 raeburn 836: }
1.63 raeburn 837: $rowtotal ++;
1.236 raeburn 838: } elsif (($action eq 'usermodification') || ($action eq 'coursedefaults') ||
1.277 raeburn 839: ($action eq 'defaults') || ($action eq 'directorysrch')) {
1.230 raeburn 840: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1.110 raeburn 841: } elsif ($action eq 'login') {
1.256 raeburn 842: if ($numheaders == 4) {
1.168 raeburn 843: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal).'
844: </table>
845: </td>
846: </tr>
847: <tr>
848: <td>
849: <table class="LC_nested">
850: <tr class="LC_info_row">
851: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1.216 raeburn 852: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td></tr>'.
1.168 raeburn 853: &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
854: $rowtotal ++;
855: } else {
856: $output .= &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
857: }
1.256 raeburn 858: $output .= '
859: </table>
860: </td>
861: </tr>
862: <tr>
863: <td>
864: <table class="LC_nested">
865: <tr class="LC_info_row">';
866: if ($numheaders == 4) {
867: $output .= '
868: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
869: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
870: </tr>';
871: } else {
872: $output .= '
873: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
874: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
875: </tr>';
876: }
877: $rowtotal ++;
878: $output .= &print_login('headtag',$dom,$confname,$phase,$settings,\$rowtotal);
1.102 raeburn 879: } elsif ($action eq 'requestcourses') {
1.247 raeburn 880: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
881: $rowtotal ++;
882: $output .= &print_studentcode($settings,\$rowtotal).'
1.216 raeburn 883: </table>
884: </td>
885: </tr>
886: <tr>
887: <td>
888: <table class="LC_nested">
889: <tr class="LC_info_row">
890: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
891: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
1.242 raeburn 892: &textbookcourses_javascript($settings).
893: &print_textbookcourses($dom,'textbooks',$settings,\$rowtotal).'
894: </table>
895: </td>
896: </tr>
897: <tr>
898: <td>
899: <table class="LC_nested">
900: <tr class="LC_info_row">
901: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
902: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td> </tr>'.
903: &print_textbookcourses($dom,'templates',$settings,\$rowtotal).'
1.235 raeburn 904: </table>
905: </td>
906: </tr>
907: <tr>
908: <td>
909: <table class="LC_nested">
910: <tr class="LC_info_row">
1.242 raeburn 911: <td class="LC_left_item"'.$colspan.' valign="top">'.&mt($item->{'header'}->[4]->{'col1'}).'</td>
912: <td class="LC_right_item" valign="top">'.&mt($item->{'header'}->[4]->{'col2'}).'</td>
1.235 raeburn 913: </tr>'.
914: &print_validation_rows('requestcourses',$dom,$settings,\$rowtotal);
1.163 raeburn 915: } elsif ($action eq 'requestauthor') {
916: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
1.247 raeburn 917: $rowtotal ++;
1.122 jms 918: } elsif ($action eq 'rolecolors') {
1.30 raeburn 919: $output .= &print_rolecolors($phase,'coordinator',$dom,$confname,$settings,\$rowtotal).'
1.6 raeburn 920: </table>
921: </td>
922: </tr>
923: <tr>
924: <td>
925: <table class="LC_nested">
926: <tr class="LC_info_row">
1.69 raeburn 927: <td class="LC_left_item"'.$colspan.' valign="top">'.
928: &mt($item->{'header'}->[2]->{'col1'}).'</td>
929: <td class="LC_right_item" valign="top">'.
930: &mt($item->{'header'}->[2]->{'col2'}).'</td>
1.3 raeburn 931: </tr>'.
1.30 raeburn 932: &print_rolecolors($phase,'author',$dom,$confname,$settings,\$rowtotal).'
1.3 raeburn 933: </table>
934: </td>
935: </tr>
936: <tr>
937: <td>
938: <table class="LC_nested">
939: <tr class="LC_info_row">
1.59 bisitz 940: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
941: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
1.3 raeburn 942: </tr>'.
1.30 raeburn 943: &print_rolecolors($phase,'admin',$dom,$confname,$settings,\$rowtotal);
944: $rowtotal += 2;
1.6 raeburn 945: }
1.3 raeburn 946: } else {
1.30 raeburn 947: $output .= '
1.3 raeburn 948: <tr>
949: <td>
950: <table class="LC_nested">
1.30 raeburn 951: <tr class="LC_info_row">';
1.277 raeburn 952: if ($action eq 'login') {
1.30 raeburn 953: $output .= '
1.59 bisitz 954: <td class="LC_left_item" colspan="2">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
1.69 raeburn 955: } elsif ($action eq 'serverstatuses') {
956: $output .= '
957: <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).
958: '<br />('.&mt('Automatic access for Dom. Coords.').')</td>';
959:
1.6 raeburn 960: } else {
1.30 raeburn 961: $output .= '
1.69 raeburn 962: <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
963: }
1.72 raeburn 964: if (defined($item->{'header'}->[0]->{'col3'})) {
965: $output .= '<td class="LC_left_item" valign="top">'.
966: &mt($item->{'header'}->[0]->{'col2'});
967: if ($action eq 'serverstatuses') {
968: $output .= '<br />(<tt>'.&mt('user1:domain1,user2:domain2 etc.').'</tt>)';
969: }
1.69 raeburn 970: } else {
971: $output .= '<td class="LC_right_item" valign="top">'.
972: &mt($item->{'header'}->[0]->{'col2'});
973: }
974: $output .= '</td>';
975: if ($item->{'header'}->[0]->{'col3'}) {
1.150 raeburn 976: if (defined($item->{'header'}->[0]->{'col4'})) {
977: $output .= '<td class="LC_left_item" valign="top">'.
978: &mt($item->{'header'}->[0]->{'col3'});
979: } else {
980: $output .= '<td class="LC_right_item" valign="top">'.
981: &mt($item->{'header'}->[0]->{'col3'});
982: }
1.69 raeburn 983: if ($action eq 'serverstatuses') {
984: $output .= '<br />(<tt>'.&mt('IP1,IP2 etc.').'</tt>)';
985: }
986: $output .= '</td>';
1.6 raeburn 987: }
1.150 raeburn 988: if ($item->{'header'}->[0]->{'col4'}) {
989: $output .= '<td class="LC_right_item" valign="top">'.
990: &mt($item->{'header'}->[0]->{'col4'});
991: }
1.69 raeburn 992: $output .= '</tr>';
1.48 raeburn 993: $rowtotal ++;
1.168 raeburn 994: if ($action eq 'quotas') {
1.86 raeburn 995: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.277 raeburn 996: } elsif (($action eq 'autoenroll') || ($action eq 'autocreate') ||
997: ($action eq 'contacts') || ($action eq 'serverstatuses') ||
998: ($action eq 'loadbalancing') || ($action eq 'ltitools')) {
1.230 raeburn 999: $output .= $item->{'print'}->($dom,$settings,\$rowtotal);
1.46 raeburn 1000: } elsif ($action eq 'scantron') {
1001: $output .= &print_scantronformat($r,$dom,$confname,$settings,\$rowtotal);
1.118 jms 1002: } elsif ($action eq 'helpsettings') {
1.168 raeburn 1003: $output .= &print_helpsettings($dom,$confname,$settings,\$rowtotal);
1.121 raeburn 1004: }
1.3 raeburn 1005: }
1.30 raeburn 1006: $output .= '
1.3 raeburn 1007: </table>
1008: </td>
1009: </tr>
1.30 raeburn 1010: </table><br />';
1011: return ($output,$rowtotal);
1.1 raeburn 1012: }
1013:
1.3 raeburn 1014: sub print_login {
1.168 raeburn 1015: my ($caller,$dom,$confname,$phase,$settings,$rowtotal) = @_;
1.110 raeburn 1016: my ($css_class,$datatable);
1.6 raeburn 1017: my %choices = &login_choices();
1.110 raeburn 1018:
1.168 raeburn 1019: if ($caller eq 'service') {
1.149 raeburn 1020: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.110 raeburn 1021: my $choice = $choices{'disallowlogin'};
1022: $css_class = ' class="LC_odd_row"';
1.128 raeburn 1023: $datatable .= '<tr'.$css_class.'><td>'.$choice.'</td>'.
1.110 raeburn 1024: '<td align="right"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1.128 raeburn 1025: '<th>'.$choices{'server'}.'</th>'.
1026: '<th>'.$choices{'serverpath'}.'</th>'.
1027: '<th>'.$choices{'custompath'}.'</th>'.
1028: '<th><span class="LC_nobreak">'.$choices{'exempt'}.'</span></th></tr>'."\n";
1.110 raeburn 1029: my %disallowed;
1030: if (ref($settings) eq 'HASH') {
1031: if (ref($settings->{'loginvia'}) eq 'HASH') {
1032: %disallowed = %{$settings->{'loginvia'}};
1033: }
1034: }
1035: foreach my $lonhost (sort(keys(%servers))) {
1036: my $direct = 'selected="selected"';
1.128 raeburn 1037: if (ref($disallowed{$lonhost}) eq 'HASH') {
1038: if ($disallowed{$lonhost}{'server'} ne '') {
1039: $direct = '';
1040: }
1.110 raeburn 1041: }
1.115 raeburn 1042: $datatable .= '<tr><td>'.$servers{$lonhost}.'</td>'.
1.128 raeburn 1043: '<td><select name="'.$lonhost.'_server">'.
1.110 raeburn 1044: '<option value=""'.$direct.'>'.$choices{'directlogin'}.
1045: '</option>';
1.184 raeburn 1046: foreach my $hostid (sort(keys(%servers))) {
1.115 raeburn 1047: next if ($servers{$hostid} eq $servers{$lonhost});
1.110 raeburn 1048: my $selected = '';
1.128 raeburn 1049: if (ref($disallowed{$lonhost}) eq 'HASH') {
1050: if ($hostid eq $disallowed{$lonhost}{'server'}) {
1051: $selected = 'selected="selected"';
1052: }
1.110 raeburn 1053: }
1054: $datatable .= '<option value="'.$hostid.'"'.$selected.'>'.
1055: $servers{$hostid}.'</option>';
1056: }
1.128 raeburn 1057: $datatable .= '</select></td>'.
1058: '<td><select name="'.$lonhost.'_serverpath">';
1059: foreach my $path ('','/','/adm/login','/adm/roles','custom') {
1060: my $pathname = $path;
1061: if ($path eq 'custom') {
1062: $pathname = &mt('Custom Path').' ->';
1063: }
1064: my $selected = '';
1065: if (ref($disallowed{$lonhost}) eq 'HASH') {
1066: if ($path eq $disallowed{$lonhost}{'serverpath'}) {
1067: $selected = 'selected="selected"';
1068: }
1069: } elsif ($path eq '') {
1070: $selected = 'selected="selected"';
1071: }
1072: $datatable .= '<option value="'.$path.'"'.$selected.'>'.$pathname.'</option>';
1073: }
1074: $datatable .= '</select></td>';
1075: my ($custom,$exempt);
1076: if (ref($disallowed{$lonhost}) eq 'HASH') {
1077: $custom = $disallowed{$lonhost}{'custompath'};
1078: $exempt = $disallowed{$lonhost}{'exempt'};
1079: }
1080: $datatable .= '<td><input type="text" name="'.$lonhost.'_custompath" size="6" value="'.$custom.'" /></td>'.
1081: '<td><input type="text" name="'.$lonhost.'_exempt" size="8" value="'.$exempt.'" /></td>'.
1082: '</tr>';
1.110 raeburn 1083: }
1084: $datatable .= '</table></td></tr>';
1085: return $datatable;
1.168 raeburn 1086: } elsif ($caller eq 'page') {
1087: my %defaultchecked = (
1088: 'coursecatalog' => 'on',
1.188 raeburn 1089: 'helpdesk' => 'on',
1.168 raeburn 1090: 'adminmail' => 'off',
1091: 'newuser' => 'off',
1092: );
1.188 raeburn 1093: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.168 raeburn 1094: my (%checkedon,%checkedoff);
1.42 raeburn 1095: foreach my $item (@toggles) {
1.168 raeburn 1096: if ($defaultchecked{$item} eq 'on') {
1097: $checkedon{$item} = ' checked="checked" ';
1.42 raeburn 1098: $checkedoff{$item} = ' ';
1.168 raeburn 1099: } elsif ($defaultchecked{$item} eq 'off') {
1100: $checkedoff{$item} = ' checked="checked" ';
1.42 raeburn 1101: $checkedon{$item} = ' ';
1102: }
1.1 raeburn 1103: }
1.168 raeburn 1104: my @images = ('img','logo','domlogo','login');
1105: my @logintext = ('textcol','bgcol');
1106: my @bgs = ('pgbg','mainbg','sidebg');
1107: my @links = ('link','alink','vlink');
1108: my %designhash = &Apache::loncommon::get_domainconf($dom);
1109: my %defaultdesign = %Apache::loncommon::defaultdesign;
1110: my (%is_custom,%designs);
1111: my %defaults = (
1112: font => $defaultdesign{'login.font'},
1113: );
1.6 raeburn 1114: foreach my $item (@images) {
1.168 raeburn 1115: $defaults{$item} = $defaultdesign{'login.'.$item};
1116: $defaults{'showlogo'}{$item} = 1;
1117: }
1118: foreach my $item (@bgs) {
1119: $defaults{'bgs'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 1120: }
1.41 raeburn 1121: foreach my $item (@logintext) {
1.168 raeburn 1122: $defaults{'logintext'}{$item} = $defaultdesign{'login.'.$item};
1.41 raeburn 1123: }
1.168 raeburn 1124: foreach my $item (@links) {
1125: $defaults{'links'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 1126: }
1.168 raeburn 1127: if (ref($settings) eq 'HASH') {
1128: foreach my $item (@toggles) {
1129: if ($settings->{$item} eq '1') {
1130: $checkedon{$item} = ' checked="checked" ';
1131: $checkedoff{$item} = ' ';
1132: } elsif ($settings->{$item} eq '0') {
1133: $checkedoff{$item} = ' checked="checked" ';
1134: $checkedon{$item} = ' ';
1135: }
1136: }
1137: foreach my $item (@images) {
1138: if (defined($settings->{$item})) {
1139: $designs{$item} = $settings->{$item};
1140: $is_custom{$item} = 1;
1141: }
1142: if (defined($settings->{'showlogo'}{$item})) {
1143: $designs{'showlogo'}{$item} = $settings->{'showlogo'}{$item};
1144: }
1145: }
1146: foreach my $item (@logintext) {
1147: if ($settings->{$item} ne '') {
1148: $designs{'logintext'}{$item} = $settings->{$item};
1149: $is_custom{$item} = 1;
1150: }
1151: }
1152: if ($settings->{'font'} ne '') {
1153: $designs{'font'} = $settings->{'font'};
1154: $is_custom{'font'} = 1;
1155: }
1156: foreach my $item (@bgs) {
1157: if ($settings->{$item} ne '') {
1158: $designs{'bgs'}{$item} = $settings->{$item};
1159: $is_custom{$item} = 1;
1160: }
1161: }
1162: foreach my $item (@links) {
1163: if ($settings->{$item} ne '') {
1164: $designs{'links'}{$item} = $settings->{$item};
1165: $is_custom{$item} = 1;
1166: }
1167: }
1168: } else {
1169: if ($designhash{$dom.'.login.font'} ne '') {
1170: $designs{'font'} = $designhash{$dom.'.login.font'};
1171: $is_custom{'font'} = 1;
1172: }
1173: foreach my $item (@images) {
1174: if ($designhash{$dom.'.login.'.$item} ne '') {
1175: $designs{$item} = $designhash{$dom.'.login.'.$item};
1176: $is_custom{$item} = 1;
1177: }
1178: }
1179: foreach my $item (@bgs) {
1180: if ($designhash{$dom.'.login.'.$item} ne '') {
1181: $designs{'bgs'}{$item} = $designhash{$dom.'.login.'.$item};
1182: $is_custom{$item} = 1;
1183: }
1.6 raeburn 1184: }
1.168 raeburn 1185: foreach my $item (@links) {
1186: if ($designhash{$dom.'.login.'.$item} ne '') {
1187: $designs{'links'}{$item} = $designhash{$dom.'.login.'.$item};
1188: $is_custom{$item} = 1;
1189: }
1.6 raeburn 1190: }
1191: }
1.168 raeburn 1192: my %alt_text = &Apache::lonlocal::texthash ( img => 'Log-in banner',
1193: logo => 'Institution Logo',
1194: domlogo => 'Domain Logo',
1195: login => 'Login box');
1196: my $itemcount = 1;
1197: foreach my $item (@toggles) {
1198: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1199: $datatable .=
1200: '<tr'.$css_class.'><td colspan="2">'.$choices{$item}.
1201: '</td><td>'.
1202: '<span class="LC_nobreak"><label><input type="radio" name="'.
1203: $item.'"'.$checkedon{$item}.' value="1" />'.&mt('Yes').
1204: '</label> <label><input type="radio" name="'.$item.'"'.
1205: $checkedoff{$item}.' value="0" />'.&mt('No').'</label></span></td>'.
1206: '</tr>';
1207: $itemcount ++;
1.6 raeburn 1208: }
1.168 raeburn 1209: $datatable .= &display_color_options($dom,$confname,$phase,'login',$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal,\@logintext);
1210: $datatable .= '</tr></table></td></tr>';
1211: } elsif ($caller eq 'help') {
1212: my ($defaulturl,$defaulttype,%url,%type,%lt,%langchoices);
1213: my $switchserver = &check_switchserver($dom,$confname);
1214: my $itemcount = 1;
1215: $defaulturl = '/adm/loginproblems.html';
1216: $defaulttype = 'default';
1217: %lt = &Apache::lonlocal::texthash (
1218: del => 'Delete?',
1219: rep => 'Replace:',
1220: upl => 'Upload:',
1221: default => 'Default',
1222: custom => 'Custom',
1223: );
1224: %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
1225: my @currlangs;
1226: if (ref($settings) eq 'HASH') {
1227: if (ref($settings->{'helpurl'}) eq 'HASH') {
1228: foreach my $key (sort(keys(%{$settings->{'helpurl'}}))) {
1229: next if ($settings->{'helpurl'}{$key} eq '');
1230: $url{$key} = $settings->{'helpurl'}{$key}.'?inhibitmenu=yes';
1231: $type{$key} = 'custom';
1232: unless ($key eq 'nolang') {
1233: push(@currlangs,$key);
1234: }
1235: }
1236: } elsif ($settings->{'helpurl'} ne '') {
1237: $type{'nolang'} = 'custom';
1238: $url{'nolang'} = $settings->{'helpurl'}.'?inhibitmenu=yes';
1.8 raeburn 1239: }
1240: }
1.168 raeburn 1241: foreach my $lang ('nolang',sort(@currlangs)) {
1242: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1243: $datatable .= '<tr'.$css_class.'>';
1244: if ($url{$lang} eq '') {
1245: $url{$lang} = $defaulturl;
1246: }
1247: if ($type{$lang} eq '') {
1248: $type{$lang} = $defaulttype;
1249: }
1250: $datatable .= '<td colspan="2"><span class="LC_nobreak">';
1251: if ($lang eq 'nolang') {
1252: $datatable .= &mt('Log-in help page if no specific language file: [_1]',
1253: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1254: } else {
1255: $datatable .= &mt('Log-in help page for language: [_1] is [_2]',
1256: $langchoices{$lang},
1257: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1258: }
1259: $datatable .= '</span></td>'."\n".
1260: '<td class="LC_left_item">';
1261: if ($type{$lang} eq 'custom') {
1262: $datatable .= '<span class="LC_nobreak"><label>'.
1263: '<input type="checkbox" name="loginhelpurl_del" value="'.$lang.'" />'.
1264: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1265: } else {
1266: $datatable .= $lt{'upl'};
1267: }
1268: $datatable .='<br />';
1269: if ($switchserver) {
1270: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1271: } else {
1272: $datatable .= '<input type="file" name="loginhelpurl_'.$lang.'" />';
1.6 raeburn 1273: }
1.168 raeburn 1274: $datatable .= '</td></tr>';
1275: $itemcount ++;
1.6 raeburn 1276: }
1.168 raeburn 1277: my @addlangs;
1278: foreach my $lang (sort(keys(%langchoices))) {
1279: next if ((grep(/^\Q$lang\E$/,@currlangs)) || ($lang eq 'x_chef'));
1280: push(@addlangs,$lang);
1281: }
1282: if (@addlangs > 0) {
1283: my %toadd;
1284: map { $toadd{$_} = $langchoices{$_} ; } @addlangs;
1285: $toadd{''} = &mt('Select');
1286: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1287: $datatable .= '<tr'.$css_class.'><td class="LC_left_item" colspan="2">'.
1288: &mt('Add log-in help page for a specific language:').' '.
1289: &Apache::loncommon::select_form('','loginhelpurl_add_lang',\%toadd).
1290: '</td><td class="LC_left_item">'.$lt{'upl'}.'<br />';
1291: if ($switchserver) {
1292: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1293: } else {
1294: $datatable .= '<input type="file" name="loginhelpurl_add_file" />';
1.6 raeburn 1295: }
1.168 raeburn 1296: $datatable .= '</td></tr>';
1.169 raeburn 1297: $itemcount ++;
1.6 raeburn 1298: }
1.169 raeburn 1299: $datatable .= &captcha_choice('login',$settings,$itemcount);
1.256 raeburn 1300: } elsif ($caller eq 'headtag') {
1301: my %domservers = &Apache::lonnet::get_servers($dom);
1302: my $choice = $choices{'headtag'};
1303: $css_class = ' class="LC_odd_row"';
1304: $datatable .= '<tr'.$css_class.'><td colspan="2">'.$choice.'</td>'.
1305: '<td align="left"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1306: '<th>'.$choices{'current'}.'</th>'.
1307: '<th>'.$choices{'action'}.'</th>'.
1308: '<th>'.$choices{'exempt'}.'</th></tr>'."\n";
1309: my (%currurls,%currexempt);
1310: if (ref($settings) eq 'HASH') {
1311: if (ref($settings->{'headtag'}) eq 'HASH') {
1312: foreach my $lonhost (keys(%{$settings->{'headtag'}})) {
1313: if (ref($settings->{'headtag'}{$lonhost}) eq 'HASH') {
1314: $currurls{$lonhost} = $settings->{'headtag'}{$lonhost}{'url'};
1315: $currexempt{$lonhost} = $settings->{'headtag'}{$lonhost}{'exempt'};
1316: }
1317: }
1318: }
1319: }
1320: my %lt = &Apache::lonlocal::texthash(
1321: del => 'Delete?',
1322: rep => 'Replace:',
1323: upl => 'Upload:',
1324: curr => 'View contents',
1325: none => 'None',
1326: );
1327: my $switchserver = &check_switchserver($dom,$confname);
1328: foreach my $lonhost (sort(keys(%domservers))) {
1329: my $exempt = &check_exempt_addresses($currexempt{$lonhost});
1330: $datatable .= '<tr><td>'.$domservers{$lonhost}.'</td>';
1331: if ($currurls{$lonhost}) {
1332: $datatable .= '<td class="LC_right_item"><a href="'.
1333: "javascript:void(open('$currurls{$lonhost}?inhibitmenu=yes','Custom_HeadTag',
1334: 'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
1335: '">'.$lt{'curr'}.'</a></td>'.
1336: '<td><span class="LC_nobreak"><label>'.
1337: '<input type="checkbox" name="loginheadtag_del" value="'.$lonhost.'" />'.
1338: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1339: } else {
1340: $datatable .= '<td class="LC_right_item">'.$lt{'none'}.'</td><td>'.$lt{'upl'};
1341: }
1342: $datatable .='<br />';
1343: if ($switchserver) {
1344: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1345: } else {
1346: $datatable .= '<input type="file" name="loginheadtag_'.$lonhost.'" />';
1347: }
1348: $datatable .= '</td><td><input type="textbox" name="loginheadtagexempt_'.$lonhost.'" value="'.$exempt.'" /></td></tr>';
1349: }
1350: $datatable .= '</table></td></tr>';
1.1 raeburn 1351: }
1.6 raeburn 1352: return $datatable;
1353: }
1354:
1355: sub login_choices {
1356: my %choices =
1357: &Apache::lonlocal::texthash (
1.116 bisitz 1358: coursecatalog => 'Display Course/Community Catalog link?',
1.110 raeburn 1359: adminmail => "Display Administrator's E-mail Address?",
1.188 raeburn 1360: helpdesk => 'Display "Contact Helpdesk" link',
1.110 raeburn 1361: disallowlogin => "Login page requests redirected",
1362: hostid => "Server",
1.128 raeburn 1363: server => "Redirect to:",
1364: serverpath => "Path",
1365: custompath => "Custom",
1366: exempt => "Exempt IP(s)",
1.110 raeburn 1367: directlogin => "No redirect",
1368: newuser => "Link to create a user account",
1369: img => "Header",
1370: logo => "Main Logo",
1371: domlogo => "Domain Logo",
1372: login => "Log-in Header",
1373: textcol => "Text color",
1374: bgcol => "Box color",
1375: bgs => "Background colors",
1376: links => "Link colors",
1377: font => "Font color",
1378: pgbg => "Header",
1379: mainbg => "Page",
1380: sidebg => "Login box",
1381: link => "Link",
1382: alink => "Active link",
1383: vlink => "Visited link",
1.256 raeburn 1384: headtag => "Custom markup",
1385: action => "Action",
1386: current => "Current",
1.6 raeburn 1387: );
1388: return %choices;
1389: }
1390:
1391: sub print_rolecolors {
1.30 raeburn 1392: my ($phase,$role,$dom,$confname,$settings,$rowtotal) = @_;
1.6 raeburn 1393: my %choices = &color_font_choices();
1394: my @bgs = ('pgbg','tabbg','sidebg');
1395: my @links = ('link','alink','vlink');
1396: my @images = ('img');
1397: my %alt_text = &Apache::lonlocal::texthash(img => "Banner for $role role");
1.7 albertel 1398: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.6 raeburn 1399: my %defaultdesign = %Apache::loncommon::defaultdesign;
1400: my (%is_custom,%designs);
1.200 raeburn 1401: my %defaults = &role_defaults($role,\@bgs,\@links,\@images);
1.6 raeburn 1402: if (ref($settings) eq 'HASH') {
1403: if (ref($settings->{$role}) eq 'HASH') {
1404: if ($settings->{$role}->{'img'} ne '') {
1405: $designs{'img'} = $settings->{$role}->{'img'};
1406: $is_custom{'img'} = 1;
1407: }
1408: if ($settings->{$role}->{'font'} ne '') {
1409: $designs{'font'} = $settings->{$role}->{'font'};
1410: $is_custom{'font'} = 1;
1411: }
1.97 tempelho 1412: if ($settings->{$role}->{'fontmenu'} ne '') {
1413: $designs{'fontmenu'} = $settings->{$role}->{'fontmenu'};
1414: $is_custom{'fontmenu'} = 1;
1415: }
1.6 raeburn 1416: foreach my $item (@bgs) {
1417: if ($settings->{$role}->{$item} ne '') {
1418: $designs{'bgs'}{$item} = $settings->{$role}->{$item};
1419: $is_custom{$item} = 1;
1420: }
1421: }
1422: foreach my $item (@links) {
1423: if ($settings->{$role}->{$item} ne '') {
1424: $designs{'links'}{$item} = $settings->{$role}->{$item};
1425: $is_custom{$item} = 1;
1426: }
1427: }
1428: }
1429: } else {
1430: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
1431: $designs{img} = $designhash{$dom.'.'.$role.'.img'};
1432: $is_custom{'img'} = 1;
1433: }
1.97 tempelho 1434: if ($designhash{$dom.'.'.$role.'.fontmenu'} ne '') {
1435: $designs{fontmenu} = $designhash{$dom.'.'.$role.'.fontmenu'};
1436: $is_custom{'fontmenu'} = 1;
1437: }
1.6 raeburn 1438: if ($designhash{$dom.'.'.$role.'.font'} ne '') {
1439: $designs{font} = $designhash{$dom.'.'.$role.'.font'};
1440: $is_custom{'font'} = 1;
1441: }
1442: foreach my $item (@bgs) {
1443: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1444: $designs{'bgs'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1445: $is_custom{$item} = 1;
1446:
1447: }
1448: }
1449: foreach my $item (@links) {
1450: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1451: $designs{'links'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1452: $is_custom{$item} = 1;
1453: }
1454: }
1455: }
1456: my $itemcount = 1;
1.30 raeburn 1457: my $datatable = &display_color_options($dom,$confname,$phase,$role,$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal);
1.6 raeburn 1458: $datatable .= '</tr></table></td></tr>';
1459: return $datatable;
1460: }
1461:
1.200 raeburn 1462: sub role_defaults {
1463: my ($role,$bgs,$links,$images,$logintext) = @_;
1.202 raeburn 1464: my %defaults;
1465: unless ((ref($bgs) eq 'ARRAY') && (ref($links) eq 'ARRAY') && (ref($images) eq 'ARRAY')) {
1.200 raeburn 1466: return %defaults;
1467: }
1468: my %defaultdesign = %Apache::loncommon::defaultdesign;
1469: if ($role eq 'login') {
1470: %defaults = (
1471: font => $defaultdesign{$role.'.font'},
1472: );
1473: if (ref($logintext) eq 'ARRAY') {
1474: foreach my $item (@{$logintext}) {
1475: $defaults{'logintext'}{$item} = $defaultdesign{$role.'.'.$item};
1476: }
1477: }
1478: foreach my $item (@{$images}) {
1479: $defaults{'showlogo'}{$item} = 1;
1480: }
1481: } else {
1482: %defaults = (
1483: img => $defaultdesign{$role.'.img'},
1484: font => $defaultdesign{$role.'.font'},
1485: fontmenu => $defaultdesign{$role.'.fontmenu'},
1486: );
1487: }
1488: foreach my $item (@{$bgs}) {
1489: $defaults{'bgs'}{$item} = $defaultdesign{$role.'.'.$item};
1490: }
1491: foreach my $item (@{$links}) {
1492: $defaults{'links'}{$item} = $defaultdesign{$role.'.'.$item};
1493: }
1494: foreach my $item (@{$images}) {
1495: $defaults{$item} = $defaultdesign{$role.'.'.$item};
1496: }
1497: return %defaults;
1498: }
1499:
1.6 raeburn 1500: sub display_color_options {
1.9 raeburn 1501: my ($dom,$confname,$phase,$role,$itemcount,$choices,$is_custom,$defaults,$designs,
1.135 bisitz 1502: $images,$bgs,$links,$alt_text,$rowtotal,$logintext) = @_;
1.159 raeburn 1503: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.6 raeburn 1504: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.176 raeburn 1505: my $datatable = '<tr'.$css_class.'>'.
1.6 raeburn 1506: '<td>'.$choices->{'font'}.'</td>';
1507: if (!$is_custom->{'font'}) {
1.30 raeburn 1508: $datatable .= '<td>'.&mt('Default in use:').' <span id="css_default_'.$role.'_font" style="color: '.$defaults->{'font'}.';">'.$defaults->{'font'}.'</span></td>';
1.6 raeburn 1509: } else {
1510: $datatable .= '<td> </td>';
1511: }
1.174 foxr 1512: my $current_color = $designs->{'font'} ? $designs->{'font'} : $defaults->{'font'};
1513:
1.8 raeburn 1514: $datatable .= '<td><span class="LC_nobreak">'.
1.174 foxr 1515: '<input type="text" class="colorchooser" size="10" name="'.$role.'_font"'.
1.202 raeburn 1516: ' value="'.$current_color.'" /> '.
1.174 foxr 1517: ' </td></tr>';
1.107 raeburn 1518: unless ($role eq 'login') {
1519: $datatable .= '<tr'.$css_class.'>'.
1520: '<td>'.$choices->{'fontmenu'}.'</td>';
1521: if (!$is_custom->{'fontmenu'}) {
1522: $datatable .= '<td>'.&mt('Default in use:').' <span id="css_default_'.$role.'_font" style="color: '.$defaults->{'fontmenu'}.';">'.$defaults->{'fontmenu'}.'</span></td>';
1523: } else {
1524: $datatable .= '<td> </td>';
1525: }
1.202 raeburn 1526: $current_color = $designs->{'fontmenu'} ?
1.174 foxr 1527: $designs->{'fontmenu'} : $defaults->{'fontmenu'};
1.107 raeburn 1528: $datatable .= '<td><span class="LC_nobreak">'.
1.174 foxr 1529: '<input class="colorchooser" type="text" size="10" name="'
1530: .$role.'_fontmenu"'.
1531: ' value="'.$current_color.'" /> '.
1532: ' </td></tr>';
1.97 tempelho 1533: }
1.9 raeburn 1534: my $switchserver = &check_switchserver($dom,$confname);
1.6 raeburn 1535: foreach my $img (@{$images}) {
1.18 albertel 1536: $itemcount ++;
1.6 raeburn 1537: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.8 raeburn 1538: $datatable .= '<tr'.$css_class.'>'.
1.70 raeburn 1539: '<td>'.$choices->{$img};
1.41 raeburn 1540: my ($imgfile,$img_import,$login_hdr_pick,$logincolors);
1.70 raeburn 1541: if ($role eq 'login') {
1542: if ($img eq 'login') {
1543: $login_hdr_pick =
1.135 bisitz 1544: &login_header_options($img,$role,$defaults,$is_custom,$choices);
1.70 raeburn 1545: $logincolors =
1546: &login_text_colors($img,$role,$logintext,$phase,$choices,
1.201 raeburn 1547: $designs,$defaults);
1.70 raeburn 1548: } elsif ($img ne 'domlogo') {
1549: $datatable.= &logo_display_options($img,$defaults,$designs);
1550: }
1551: }
1552: $datatable .= '</td>';
1.6 raeburn 1553: if ($designs->{$img} ne '') {
1554: $imgfile = $designs->{$img};
1.18 albertel 1555: $img_import = ($imgfile =~ m{^/adm/});
1.6 raeburn 1556: } else {
1557: $imgfile = $defaults->{$img};
1558: }
1559: if ($imgfile) {
1.9 raeburn 1560: my ($showfile,$fullsize);
1561: if ($imgfile =~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
1.6 raeburn 1562: my $urldir = $1;
1563: my $filename = $2;
1564: my @info = &Apache::lonnet::stat_file($designs->{$img});
1565: if (@info) {
1566: my $thumbfile = 'tn-'.$filename;
1567: my @thumb=&Apache::lonnet::stat_file($urldir.'/'.$thumbfile);
1568: if (@thumb) {
1569: $showfile = $urldir.'/'.$thumbfile;
1570: } else {
1571: $showfile = $imgfile;
1572: }
1573: } else {
1574: $showfile = '';
1575: }
1576: } elsif ($imgfile =~ m-^/(adm/[^/]+)/([^/]+)$-) {
1.16 raeburn 1577: $showfile = $imgfile;
1.6 raeburn 1578: my $imgdir = $1;
1579: my $filename = $2;
1.159 raeburn 1580: if (-e "$londocroot/$imgdir/tn-".$filename) {
1.6 raeburn 1581: $showfile = "/$imgdir/tn-".$filename;
1582: } else {
1.159 raeburn 1583: my $input = $londocroot.$imgfile;
1584: my $output = "$londocroot/$imgdir/tn-".$filename;
1.6 raeburn 1585: if (!-e $output) {
1.9 raeburn 1586: my ($width,$height) = &thumb_dimensions();
1.16 raeburn 1587: my ($fullwidth,$fullheight) = &check_dimensions($input);
1588: if ($fullwidth ne '' && $fullheight ne '') {
1589: if ($fullwidth > $width && $fullheight > $height) {
1590: my $size = $width.'x'.$height;
1591: system("convert -sample $size $input $output");
1.159 raeburn 1592: $showfile = "/$imgdir/tn-".$filename;
1.16 raeburn 1593: }
1594: }
1.6 raeburn 1595: }
1596: }
1.16 raeburn 1597: }
1.6 raeburn 1598: if ($showfile) {
1.40 raeburn 1599: if ($showfile =~ m{^/(adm|res)/}) {
1600: if ($showfile =~ m{^/res/}) {
1601: my $local_showfile =
1602: &Apache::lonnet::filelocation('',$showfile);
1603: &Apache::lonnet::repcopy($local_showfile);
1604: }
1605: $showfile = &Apache::loncommon::lonhttpdurl($showfile);
1606: }
1607: if ($imgfile) {
1608: if ($imgfile =~ m{^/(adm|res)/}) {
1609: if ($imgfile =~ m{^/res/}) {
1610: my $local_imgfile =
1611: &Apache::lonnet::filelocation('',$imgfile);
1612: &Apache::lonnet::repcopy($local_imgfile);
1613: }
1614: $fullsize = &Apache::loncommon::lonhttpdurl($imgfile);
1615: } else {
1616: $fullsize = $imgfile;
1617: }
1618: }
1.41 raeburn 1619: $datatable .= '<td>';
1620: if ($img eq 'login') {
1.135 bisitz 1621: $datatable .= $login_hdr_pick;
1622: }
1.41 raeburn 1623: $datatable .= &image_changes($is_custom->{$img},$alt_text->{$img},$img_import,
1624: $showfile,$fullsize,$role,$img,$imgfile,$logincolors);
1.6 raeburn 1625: } else {
1.201 raeburn 1626: $datatable .= '<td> </td><td class="LC_left_item">'.
1627: &mt('Upload:').'<br />';
1.6 raeburn 1628: }
1629: } else {
1.201 raeburn 1630: $datatable .= '<td> </td><td class="LC_left_item">'.
1631: &mt('Upload:').'<br />';
1.6 raeburn 1632: }
1.9 raeburn 1633: if ($switchserver) {
1634: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1635: } else {
1.135 bisitz 1636: if ($img ne 'login') { # suppress file selection for Log-in header
1637: $datatable .=' <input type="file" name="'.$role.'_'.$img.'" />';
1638: }
1.9 raeburn 1639: }
1640: $datatable .= '</td></tr>';
1.6 raeburn 1641: }
1642: $itemcount ++;
1643: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1644: $datatable .= '<tr'.$css_class.'>'.
1645: '<td>'.$choices->{'bgs'}.'</td>';
1646: my $bgs_def;
1647: foreach my $item (@{$bgs}) {
1648: if (!$is_custom->{$item}) {
1.70 raeburn 1649: $bgs_def .= '<td><span class="LC_nobreak">'.$choices->{$item}.'</span> <span id="css_default_'.$role.'_'.$item.'" style="background-color: '.$defaults->{'bgs'}{$item}.';"> </span><br />'.$defaults->{'bgs'}{$item}.'</td>';
1.6 raeburn 1650: }
1651: }
1652: if ($bgs_def) {
1.8 raeburn 1653: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$bgs_def.'</tr></table></td>';
1.6 raeburn 1654: } else {
1655: $datatable .= '<td> </td>';
1656: }
1657: $datatable .= '<td class="LC_right_item">'.
1658: '<table border="0"><tr>';
1.174 foxr 1659:
1.6 raeburn 1660: foreach my $item (@{$bgs}) {
1.201 raeburn 1661: $datatable .= '<td align="center">'.$choices->{$item};
1.174 foxr 1662: my $color = $designs->{'bgs'}{$item} ? $designs->{'bgs'}{$item} : $defaults->{'bgs'}{$item};
1.6 raeburn 1663: if ($designs->{'bgs'}{$item}) {
1.174 foxr 1664: $datatable .= ' ';
1.6 raeburn 1665: }
1.174 foxr 1666: $datatable .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1.41 raeburn 1667: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.6 raeburn 1668: }
1669: $datatable .= '</tr></table></td></tr>';
1670: $itemcount ++;
1671: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1672: $datatable .= '<tr'.$css_class.'>'.
1673: '<td>'.$choices->{'links'}.'</td>';
1674: my $links_def;
1675: foreach my $item (@{$links}) {
1676: if (!$is_custom->{$item}) {
1.30 raeburn 1677: $links_def .= '<td>'.$choices->{$item}.'<br /><span id="css_default_'.$role.'_'.$item.'" style="color: '.$defaults->{'links'}{$item}.';">'.$defaults->{'links'}{$item}.'</span></td>';
1.6 raeburn 1678: }
1679: }
1680: if ($links_def) {
1.8 raeburn 1681: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$links_def.'</tr></table></td>';
1.6 raeburn 1682: } else {
1683: $datatable .= '<td> </td>';
1684: }
1685: $datatable .= '<td class="LC_right_item">'.
1686: '<table border="0"><tr>';
1687: foreach my $item (@{$links}) {
1.234 raeburn 1688: my $color = $designs->{'links'}{$item} ? $designs->{'links'}{$item} : $defaults->{'links'}{$item};
1.201 raeburn 1689: $datatable .= '<td align="center">'.$choices->{$item}."\n";
1.6 raeburn 1690: if ($designs->{'links'}{$item}) {
1.174 foxr 1691: $datatable.=' ';
1.6 raeburn 1692: }
1.174 foxr 1693: $datatable .= '<br /><input type="text" size="8" class="colorchooser" name="'.$role.'_'.$item.'" value="'.$color.
1.6 raeburn 1694: '" /></td>';
1695: }
1.30 raeburn 1696: $$rowtotal += $itemcount;
1.3 raeburn 1697: return $datatable;
1698: }
1699:
1.70 raeburn 1700: sub logo_display_options {
1701: my ($img,$defaults,$designs) = @_;
1702: my $checkedon;
1703: if (ref($defaults) eq 'HASH') {
1704: if (ref($defaults->{'showlogo'}) eq 'HASH') {
1705: if ($defaults->{'showlogo'}{$img}) {
1706: $checkedon = 'checked="checked" ';
1707: }
1708: }
1709: }
1710: if (ref($designs) eq 'HASH') {
1711: if (ref($designs->{'showlogo'}) eq 'HASH') {
1712: if (defined($designs->{'showlogo'}{$img})) {
1713: if ($designs->{'showlogo'}{$img} == 0) {
1714: $checkedon = '';
1715: } elsif ($designs->{'showlogo'}{$img} == 1) {
1716: $checkedon = 'checked="checked" ';
1717: }
1718: }
1719: }
1720: }
1721: return '<br /><label> <input type="checkbox" name="'.
1722: 'login_showlogo_'.$img.'" value="1" '.$checkedon.'/>'.
1723: &mt('show').'</label>'."\n";
1724: }
1725:
1.41 raeburn 1726: sub login_header_options {
1.135 bisitz 1727: my ($img,$role,$defaults,$is_custom,$choices) = @_;
1728: my $output = '';
1.41 raeburn 1729: if ((!$is_custom->{'textcol'}) || (!$is_custom->{'bgcol'})) {
1.135 bisitz 1730: $output .= &mt('Text default(s):').'<br />';
1.41 raeburn 1731: if (!$is_custom->{'textcol'}) {
1732: $output .= $choices->{'textcol'}.': '.$defaults->{'logintext'}{'textcol'}.
1733: ' ';
1734: }
1735: if (!$is_custom->{'bgcol'}) {
1736: $output .= $choices->{'bgcol'}.': '.
1737: '<span id="css_'.$role.'_font" style="background-color: '.
1738: $defaults->{'logintext'}{'bgcol'}.';"> </span>';
1739: }
1740: $output .= '<br />';
1741: }
1742: $output .='<br />';
1743: return $output;
1744: }
1745:
1746: sub login_text_colors {
1.201 raeburn 1747: my ($img,$role,$logintext,$phase,$choices,$designs,$defaults) = @_;
1.41 raeburn 1748: my $color_menu = '<table border="0"><tr>';
1749: foreach my $item (@{$logintext}) {
1.201 raeburn 1750: $color_menu .= '<td align="center">'.$choices->{$item};
1751: my $color = $designs->{'logintext'}{$item} ? $designs->{'logintext'}{$item} : $defaults->{'logintext'}{$item};
1752: $color_menu .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1753: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.41 raeburn 1754: }
1755: $color_menu .= '</tr></table><br />';
1756: return $color_menu;
1757: }
1758:
1759: sub image_changes {
1760: my ($is_custom,$alt_text,$img_import,$showfile,$fullsize,$role,$img,$imgfile,$logincolors) = @_;
1761: my $output;
1.135 bisitz 1762: if ($img eq 'login') {
1763: # suppress image for Log-in header
1764: } elsif (!$is_custom) {
1.70 raeburn 1765: if ($img ne 'domlogo') {
1.41 raeburn 1766: $output .= &mt('Default image:').'<br />';
1767: } else {
1768: $output .= &mt('Default in use:').'<br />';
1769: }
1770: }
1.135 bisitz 1771: if ($img eq 'login') { # suppress image for Log-in header
1772: $output .= '<td>'.$logincolors;
1.41 raeburn 1773: } else {
1.135 bisitz 1774: if ($img_import) {
1775: $output .= '<input type="hidden" name="'.$role.'_import_'.$img.'" value="'.$imgfile.'" />';
1776: }
1777: $output .= '<a href="'.$fullsize.'" target="_blank"><img src="'.
1778: $showfile.'" alt="'.$alt_text.'" border="0" /></a></td>';
1779: if ($is_custom) {
1780: $output .= '<td>'.$logincolors.'<span class="LC_nobreak"><label>'.
1781: '<input type="checkbox" name="'.
1782: $role.'_del_'.$img.'" value="1" />'.&mt('Delete?').
1783: '</label> '.&mt('Replace:').'</span><br />';
1784: } else {
1.201 raeburn 1785: $output .= '<td valign="middle">'.$logincolors.&mt('Upload:').'<br />';
1.135 bisitz 1786: }
1.41 raeburn 1787: }
1788: return $output;
1789: }
1790:
1.3 raeburn 1791: sub print_quotas {
1.86 raeburn 1792: my ($dom,$settings,$rowtotal,$action) = @_;
1793: my $context;
1794: if ($action eq 'quotas') {
1795: $context = 'tools';
1796: } else {
1797: $context = $action;
1798: }
1.197 raeburn 1799: my ($datatable,$defaultquota,$authorquota,@usertools,@options,%validations);
1.44 raeburn 1800: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.3 raeburn 1801: my $typecount = 0;
1.101 raeburn 1802: my ($css_class,%titles);
1.86 raeburn 1803: if ($context eq 'requestcourses') {
1.271 raeburn 1804: @usertools = ('official','unofficial','community','textbook','placement');
1.106 raeburn 1805: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 1806: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
1807: %titles = &courserequest_titles();
1.163 raeburn 1808: } elsif ($context eq 'requestauthor') {
1809: @usertools = ('author');
1810: @options = ('norequest','approval','automatic');
1.210 raeburn 1811: %titles = &authorrequest_titles();
1.86 raeburn 1812: } else {
1.162 raeburn 1813: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 1814: %titles = &tool_titles();
1.86 raeburn 1815: }
1.26 raeburn 1816: if (ref($types) eq 'ARRAY') {
1.23 raeburn 1817: foreach my $type (@{$types}) {
1.197 raeburn 1818: my ($currdefquota,$currauthorquota);
1.163 raeburn 1819: unless (($context eq 'requestcourses') ||
1820: ($context eq 'requestauthor')) {
1.86 raeburn 1821: if (ref($settings) eq 'HASH') {
1822: if (ref($settings->{defaultquota}) eq 'HASH') {
1.197 raeburn 1823: $currdefquota = $settings->{defaultquota}->{$type};
1.86 raeburn 1824: } else {
1825: $currdefquota = $settings->{$type};
1826: }
1.197 raeburn 1827: if (ref($settings->{authorquota}) eq 'HASH') {
1828: $currauthorquota = $settings->{authorquota}->{$type};
1829: }
1.78 raeburn 1830: }
1.72 raeburn 1831: }
1.3 raeburn 1832: if (defined($usertypes->{$type})) {
1833: $typecount ++;
1834: $css_class = $typecount%2?' class="LC_odd_row"':'';
1.72 raeburn 1835: $datatable .= '<tr'.$css_class.'>'.
1.3 raeburn 1836: '<td>'.$usertypes->{$type}.'</td>'.
1.72 raeburn 1837: '<td class="LC_left_item">';
1.101 raeburn 1838: if ($context eq 'requestcourses') {
1839: $datatable .= '<table><tr>';
1840: }
1841: my %cell;
1.72 raeburn 1842: foreach my $item (@usertools) {
1.101 raeburn 1843: if ($context eq 'requestcourses') {
1844: my ($curroption,$currlimit);
1845: if (ref($settings) eq 'HASH') {
1846: if (ref($settings->{$item}) eq 'HASH') {
1847: $curroption = $settings->{$item}->{$type};
1848: if ($curroption =~ /^autolimit=(\d*)$/) {
1849: $currlimit = $1;
1850: }
1851: }
1852: }
1853: if (!$curroption) {
1854: $curroption = 'norequest';
1855: }
1856: $datatable .= '<th>'.$titles{$item}.'</th>';
1857: foreach my $option (@options) {
1858: my $val = $option;
1859: if ($option eq 'norequest') {
1860: $val = 0;
1861: }
1862: if ($option eq 'validate') {
1863: my $canvalidate = 0;
1864: if (ref($validations{$item}) eq 'HASH') {
1865: if ($validations{$item}{$type}) {
1866: $canvalidate = 1;
1867: }
1868: }
1869: next if (!$canvalidate);
1870: }
1871: my $checked = '';
1872: if ($option eq $curroption) {
1873: $checked = ' checked="checked"';
1874: } elsif ($option eq 'autolimit') {
1875: if ($curroption =~ /^autolimit/) {
1876: $checked = ' checked="checked"';
1877: }
1878: }
1879: $cell{$item} .= '<span class="LC_nobreak"><label>'.
1880: '<input type="radio" name="crsreq_'.$item.
1881: '_'.$type.'" value="'.$val.'"'.$checked.' />'.
1.127 raeburn 1882: $titles{$option}.'</label>';
1.101 raeburn 1883: if ($option eq 'autolimit') {
1.127 raeburn 1884: $cell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 1885: $item.'_limit_'.$type.'" size="1" '.
1.103 raeburn 1886: 'value="'.$currlimit.'" />';
1.101 raeburn 1887: }
1.127 raeburn 1888: $cell{$item} .= '</span> ';
1.103 raeburn 1889: if ($option eq 'autolimit') {
1.127 raeburn 1890: $cell{$item} .= $titles{'unlimited'};
1.103 raeburn 1891: }
1.101 raeburn 1892: }
1.163 raeburn 1893: } elsif ($context eq 'requestauthor') {
1894: my $curroption;
1895: if (ref($settings) eq 'HASH') {
1896: $curroption = $settings->{$type};
1897: }
1898: if (!$curroption) {
1899: $curroption = 'norequest';
1900: }
1901: foreach my $option (@options) {
1902: my $val = $option;
1903: if ($option eq 'norequest') {
1904: $val = 0;
1905: }
1906: my $checked = '';
1907: if ($option eq $curroption) {
1908: $checked = ' checked="checked"';
1909: }
1910: $datatable .= '<span class="LC_nobreak"><label>'.
1911: '<input type="radio" name="authorreq_'.$type.
1912: '" value="'.$val.'"'.$checked.' />'.
1913: $titles{$option}.'</label></span> ';
1914: }
1.101 raeburn 1915: } else {
1916: my $checked = 'checked="checked" ';
1917: if (ref($settings) eq 'HASH') {
1918: if (ref($settings->{$item}) eq 'HASH') {
1919: if ($settings->{$item}->{$type} == 0) {
1920: $checked = '';
1921: } elsif ($settings->{$item}->{$type} == 1) {
1922: $checked = 'checked="checked" ';
1923: }
1.78 raeburn 1924: }
1.72 raeburn 1925: }
1.101 raeburn 1926: $datatable .= '<span class="LC_nobreak"><label>'.
1927: '<input type="checkbox" name="'.$context.'_'.$item.
1928: '" value="'.$type.'" '.$checked.'/>'.$titles{$item}.
1929: '</label></span> ';
1.72 raeburn 1930: }
1.101 raeburn 1931: }
1932: if ($context eq 'requestcourses') {
1933: $datatable .= '</tr><tr>';
1934: foreach my $item (@usertools) {
1.106 raeburn 1935: $datatable .= '<td style="vertical-align: top">'.$cell{$item}.'</td>';
1.101 raeburn 1936: }
1937: $datatable .= '</tr></table>';
1.72 raeburn 1938: }
1.86 raeburn 1939: $datatable .= '</td>';
1.163 raeburn 1940: unless (($context eq 'requestcourses') ||
1941: ($context eq 'requestauthor')) {
1.86 raeburn 1942: $datatable .=
1.197 raeburn 1943: '<td class="LC_right_item">'.
1944: '<span class="LC_nobreak">'.&mt('Portfolio').': '.
1.3 raeburn 1945: '<input type="text" name="quota_'.$type.
1.72 raeburn 1946: '" value="'.$currdefquota.
1.197 raeburn 1947: '" size="5" /></span>'.(' ' x 2).
1948: '<span class="LC_nobreak">'.&mt('Authoring').': '.
1949: '<input type="text" name="authorquota_'.$type.
1950: '" value="'.$currauthorquota.
1951: '" size="5" /></span></td>';
1.86 raeburn 1952: }
1953: $datatable .= '</tr>';
1.3 raeburn 1954: }
1955: }
1956: }
1.163 raeburn 1957: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 1958: $defaultquota = '20';
1.197 raeburn 1959: $authorquota = '500';
1.86 raeburn 1960: if (ref($settings) eq 'HASH') {
1961: if (ref($settings->{'defaultquota'}) eq 'HASH') {
1962: $defaultquota = $settings->{'defaultquota'}->{'default'};
1963: } elsif (defined($settings->{'default'})) {
1964: $defaultquota = $settings->{'default'};
1965: }
1.197 raeburn 1966: if (ref($settings->{'authorquota'}) eq 'HASH') {
1967: $authorquota = $settings->{'authorquota'}->{'default'};
1968: }
1.3 raeburn 1969: }
1970: }
1971: $typecount ++;
1972: $css_class = $typecount%2?' class="LC_odd_row"':'';
1973: $datatable .= '<tr'.$css_class.'>'.
1.26 raeburn 1974: '<td>'.$othertitle.'</td>'.
1.72 raeburn 1975: '<td class="LC_left_item">';
1.101 raeburn 1976: if ($context eq 'requestcourses') {
1977: $datatable .= '<table><tr>';
1978: }
1979: my %defcell;
1.72 raeburn 1980: foreach my $item (@usertools) {
1.101 raeburn 1981: if ($context eq 'requestcourses') {
1982: my ($curroption,$currlimit);
1983: if (ref($settings) eq 'HASH') {
1984: if (ref($settings->{$item}) eq 'HASH') {
1985: $curroption = $settings->{$item}->{'default'};
1986: if ($curroption =~ /^autolimit=(\d*)$/) {
1987: $currlimit = $1;
1988: }
1989: }
1990: }
1991: if (!$curroption) {
1992: $curroption = 'norequest';
1993: }
1994: $datatable .= '<th>'.$titles{$item}.'</th>';
1995: foreach my $option (@options) {
1996: my $val = $option;
1997: if ($option eq 'norequest') {
1998: $val = 0;
1999: }
2000: if ($option eq 'validate') {
2001: my $canvalidate = 0;
2002: if (ref($validations{$item}) eq 'HASH') {
2003: if ($validations{$item}{'default'}) {
2004: $canvalidate = 1;
2005: }
2006: }
2007: next if (!$canvalidate);
2008: }
2009: my $checked = '';
2010: if ($option eq $curroption) {
2011: $checked = ' checked="checked"';
2012: } elsif ($option eq 'autolimit') {
2013: if ($curroption =~ /^autolimit/) {
2014: $checked = ' checked="checked"';
2015: }
2016: }
2017: $defcell{$item} .= '<span class="LC_nobreak"><label>'.
2018: '<input type="radio" name="crsreq_'.$item.
2019: '_default" value="'.$val.'"'.$checked.' />'.
2020: $titles{$option}.'</label>';
2021: if ($option eq 'autolimit') {
1.127 raeburn 2022: $defcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 2023: $item.'_limit_default" size="1" '.
2024: 'value="'.$currlimit.'" />';
2025: }
1.127 raeburn 2026: $defcell{$item} .= '</span> ';
1.104 raeburn 2027: if ($option eq 'autolimit') {
1.127 raeburn 2028: $defcell{$item} .= $titles{'unlimited'};
1.104 raeburn 2029: }
1.101 raeburn 2030: }
1.163 raeburn 2031: } elsif ($context eq 'requestauthor') {
2032: my $curroption;
2033: if (ref($settings) eq 'HASH') {
1.172 raeburn 2034: $curroption = $settings->{'default'};
1.163 raeburn 2035: }
2036: if (!$curroption) {
2037: $curroption = 'norequest';
2038: }
2039: foreach my $option (@options) {
2040: my $val = $option;
2041: if ($option eq 'norequest') {
2042: $val = 0;
2043: }
2044: my $checked = '';
2045: if ($option eq $curroption) {
2046: $checked = ' checked="checked"';
2047: }
2048: $datatable .= '<span class="LC_nobreak"><label>'.
2049: '<input type="radio" name="authorreq_default"'.
2050: ' value="'.$val.'"'.$checked.' />'.
2051: $titles{$option}.'</label></span> ';
2052: }
1.101 raeburn 2053: } else {
2054: my $checked = 'checked="checked" ';
2055: if (ref($settings) eq 'HASH') {
2056: if (ref($settings->{$item}) eq 'HASH') {
2057: if ($settings->{$item}->{'default'} == 0) {
2058: $checked = '';
2059: } elsif ($settings->{$item}->{'default'} == 1) {
2060: $checked = 'checked="checked" ';
2061: }
1.78 raeburn 2062: }
1.72 raeburn 2063: }
1.101 raeburn 2064: $datatable .= '<span class="LC_nobreak"><label>'.
2065: '<input type="checkbox" name="'.$context.'_'.$item.
2066: '" value="default" '.$checked.'/>'.$titles{$item}.
2067: '</label></span> ';
2068: }
2069: }
2070: if ($context eq 'requestcourses') {
2071: $datatable .= '</tr><tr>';
2072: foreach my $item (@usertools) {
1.106 raeburn 2073: $datatable .= '<td style="vertical-align: top">'.$defcell{$item}.'</td>';
1.72 raeburn 2074: }
1.101 raeburn 2075: $datatable .= '</tr></table>';
1.72 raeburn 2076: }
1.86 raeburn 2077: $datatable .= '</td>';
1.163 raeburn 2078: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.197 raeburn 2079: $datatable .= '<td class="LC_right_item">'.
2080: '<span class="LC_nobreak">'.&mt('Portfolio').': '.
1.86 raeburn 2081: '<input type="text" name="defaultquota" value="'.
1.197 raeburn 2082: $defaultquota.'" size="5" /></span>'.(' ' x2).
2083: '<span class="LC_nobreak">'.&mt('Authoring').': '.
2084: '<input type="text" name="authorquota" value="'.
2085: $authorquota.'" size="5" /></span></td>';
1.86 raeburn 2086: }
2087: $datatable .= '</tr>';
1.72 raeburn 2088: $typecount ++;
2089: $css_class = $typecount%2?' class="LC_odd_row"':'';
2090: $datatable .= '<tr'.$css_class.'>'.
1.197 raeburn 2091: '<td>'.&mt('LON-CAPA Advanced Users').'<br />';
1.104 raeburn 2092: if ($context eq 'requestcourses') {
1.109 raeburn 2093: $datatable .= &mt('(overrides affiliation, if set)').
2094: '</td>'.
2095: '<td class="LC_left_item">'.
2096: '<table><tr>';
1.101 raeburn 2097: } else {
1.109 raeburn 2098: $datatable .= &mt('(overrides affiliation, if checked)').
2099: '</td>'.
2100: '<td class="LC_left_item" colspan="2">'.
2101: '<br />';
1.101 raeburn 2102: }
2103: my %advcell;
1.72 raeburn 2104: foreach my $item (@usertools) {
1.101 raeburn 2105: if ($context eq 'requestcourses') {
2106: my ($curroption,$currlimit);
2107: if (ref($settings) eq 'HASH') {
2108: if (ref($settings->{$item}) eq 'HASH') {
2109: $curroption = $settings->{$item}->{'_LC_adv'};
2110: if ($curroption =~ /^autolimit=(\d*)$/) {
2111: $currlimit = $1;
2112: }
2113: }
2114: }
2115: $datatable .= '<th>'.$titles{$item}.'</th>';
1.104 raeburn 2116: my $checked = '';
2117: if ($curroption eq '') {
2118: $checked = ' checked="checked"';
2119: }
2120: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
2121: '<input type="radio" name="crsreq_'.$item.
2122: '__LC_adv" value=""'.$checked.' />'.
2123: &mt('No override set').'</label></span> ';
1.101 raeburn 2124: foreach my $option (@options) {
2125: my $val = $option;
2126: if ($option eq 'norequest') {
2127: $val = 0;
2128: }
2129: if ($option eq 'validate') {
2130: my $canvalidate = 0;
2131: if (ref($validations{$item}) eq 'HASH') {
2132: if ($validations{$item}{'_LC_adv'}) {
2133: $canvalidate = 1;
2134: }
2135: }
2136: next if (!$canvalidate);
2137: }
2138: my $checked = '';
1.104 raeburn 2139: if ($val eq $curroption) {
1.101 raeburn 2140: $checked = ' checked="checked"';
2141: } elsif ($option eq 'autolimit') {
2142: if ($curroption =~ /^autolimit/) {
2143: $checked = ' checked="checked"';
2144: }
2145: }
2146: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
2147: '<input type="radio" name="crsreq_'.$item.
2148: '__LC_adv" value="'.$val.'"'.$checked.' />'.
2149: $titles{$option}.'</label>';
2150: if ($option eq 'autolimit') {
1.127 raeburn 2151: $advcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 2152: $item.'_limit__LC_adv" size="1" '.
2153: 'value="'.$currlimit.'" />';
2154: }
1.127 raeburn 2155: $advcell{$item} .= '</span> ';
1.104 raeburn 2156: if ($option eq 'autolimit') {
1.127 raeburn 2157: $advcell{$item} .= $titles{'unlimited'};
1.104 raeburn 2158: }
1.101 raeburn 2159: }
1.163 raeburn 2160: } elsif ($context eq 'requestauthor') {
2161: my $curroption;
2162: if (ref($settings) eq 'HASH') {
2163: $curroption = $settings->{'_LC_adv'};
2164: }
2165: my $checked = '';
2166: if ($curroption eq '') {
2167: $checked = ' checked="checked"';
2168: }
2169: $datatable .= '<span class="LC_nobreak"><label>'.
2170: '<input type="radio" name="authorreq__LC_adv"'.
2171: ' value=""'.$checked.' />'.
2172: &mt('No override set').'</label></span> ';
2173: foreach my $option (@options) {
2174: my $val = $option;
2175: if ($option eq 'norequest') {
2176: $val = 0;
2177: }
2178: my $checked = '';
2179: if ($val eq $curroption) {
2180: $checked = ' checked="checked"';
2181: }
2182: $datatable .= '<span class="LC_nobreak"><label>'.
1.173 raeburn 2183: '<input type="radio" name="authorreq__LC_adv"'.
2184: ' value="'.$val.'"'.$checked.' />'.
1.163 raeburn 2185: $titles{$option}.'</label></span> ';
2186: }
1.101 raeburn 2187: } else {
2188: my $checked = 'checked="checked" ';
2189: if (ref($settings) eq 'HASH') {
2190: if (ref($settings->{$item}) eq 'HASH') {
2191: if ($settings->{$item}->{'_LC_adv'} == 0) {
2192: $checked = '';
2193: } elsif ($settings->{$item}->{'_LC_adv'} == 1) {
2194: $checked = 'checked="checked" ';
2195: }
1.79 raeburn 2196: }
1.72 raeburn 2197: }
1.101 raeburn 2198: $datatable .= '<span class="LC_nobreak"><label>'.
2199: '<input type="checkbox" name="'.$context.'_'.$item.
2200: '" value="_LC_adv" '.$checked.'/>'.$titles{$item}.
2201: '</label></span> ';
2202: }
2203: }
2204: if ($context eq 'requestcourses') {
2205: $datatable .= '</tr><tr>';
2206: foreach my $item (@usertools) {
1.106 raeburn 2207: $datatable .= '<td style="vertical-align: top">'.$advcell{$item}.'</td>';
1.72 raeburn 2208: }
1.101 raeburn 2209: $datatable .= '</tr></table>';
1.72 raeburn 2210: }
1.98 raeburn 2211: $datatable .= '</td></tr>';
1.30 raeburn 2212: $$rowtotal += $typecount;
1.3 raeburn 2213: return $datatable;
2214: }
2215:
1.163 raeburn 2216: sub print_requestmail {
2217: my ($dom,$action,$settings,$rowtotal) = @_;
1.208 raeburn 2218: my ($now,$datatable,%currapp);
1.102 raeburn 2219: $now = time;
2220: if (ref($settings) eq 'HASH') {
2221: if (ref($settings->{'notify'}) eq 'HASH') {
2222: if ($settings->{'notify'}{'approval'} ne '') {
1.224 raeburn 2223: map {$currapp{$_}=1;} split(/,/,$settings->{'notify'}{'approval'});
1.102 raeburn 2224: }
2225: }
2226: }
1.191 raeburn 2227: my $numinrow = 2;
1.224 raeburn 2228: my $css_class;
2229: $css_class = ($$rowtotal%2? ' class="LC_odd_row"':'');
1.163 raeburn 2230: my $text;
2231: if ($action eq 'requestcourses') {
2232: $text = &mt('Receive notification of course requests requiring approval');
1.224 raeburn 2233: } elsif ($action eq 'requestauthor') {
2234: $text = &mt('Receive notification of Authoring Space requests requiring approval');
1.163 raeburn 2235: } else {
1.224 raeburn 2236: $text = &mt('Receive notification of queued requests for self-created user accounts requiring approval');
1.163 raeburn 2237: }
1.224 raeburn 2238: $datatable = '<tr'.$css_class.'>'.
1.163 raeburn 2239: ' <td>'.$text.'</td>'.
1.102 raeburn 2240: ' <td class="LC_left_item">';
1.191 raeburn 2241: my ($numdc,$table,$rows) = &active_dc_picker($dom,$numinrow,'checkbox',
1.224 raeburn 2242: $action.'notifyapproval',%currapp);
1.191 raeburn 2243: if ($numdc > 0) {
2244: $datatable .= $table;
1.102 raeburn 2245: } else {
2246: $datatable .= &mt('There are no active Domain Coordinators');
2247: }
2248: $datatable .='</td></tr>';
2249: return $datatable;
2250: }
2251:
1.216 raeburn 2252: sub print_studentcode {
2253: my ($settings,$rowtotal) = @_;
2254: my $rownum = 0;
1.218 raeburn 2255: my ($output,%current);
1.271 raeburn 2256: my @crstypes = ('official','unofficial','community','textbook','placement');
1.248 raeburn 2257: if (ref($settings) eq 'HASH') {
2258: if (ref($settings->{'uniquecode'}) eq 'HASH') {
2259: foreach my $type (@crstypes) {
2260: $current{$type} = $settings->{'uniquecode'}{$type};
2261: }
1.218 raeburn 2262: }
2263: }
2264: $output .= '<tr>'.
2265: '<td class="LC_left_item">'.&mt('Generate unique six character code as course identifier?').'</td>'.
2266: '<td class="LC_left_item">';
2267: foreach my $type (@crstypes) {
2268: my $check = ' ';
2269: if ($current{$type}) {
2270: $check = ' checked="checked" ';
2271: }
2272: $output .= '<span class="LC_nobreak"><label>'.
2273: '<input type="checkbox" name="uniquecode" value="'.$type.'"'.$check.'/>'.
2274: &mt($type).'</label></span>'.(' 'x2).' ';
2275: }
2276: $output .= '</td></tr>';
2277: $$rowtotal ++;
2278: return $output;
1.216 raeburn 2279: }
2280:
2281: sub print_textbookcourses {
1.242 raeburn 2282: my ($dom,$type,$settings,$rowtotal) = @_;
1.216 raeburn 2283: my $rownum = 0;
2284: my $css_class;
2285: my $itemcount = 1;
2286: my $maxnum = 0;
2287: my $bookshash;
2288: if (ref($settings) eq 'HASH') {
1.242 raeburn 2289: $bookshash = $settings->{$type};
1.216 raeburn 2290: }
2291: my %ordered;
2292: if (ref($bookshash) eq 'HASH') {
2293: foreach my $item (keys(%{$bookshash})) {
2294: if (ref($bookshash->{$item}) eq 'HASH') {
2295: my $num = $bookshash->{$item}{'order'};
2296: $ordered{$num} = $item;
2297: }
2298: }
2299: }
2300: my $confname = $dom.'-domainconfig';
2301: my $switchserver = &check_switchserver($dom,$confname);
1.242 raeburn 2302: my $maxnum = scalar(keys(%ordered));
2303: my $datatable;
1.216 raeburn 2304: if (keys(%ordered)) {
2305: my @items = sort { $a <=> $b } keys(%ordered);
2306: for (my $i=0; $i<@items; $i++) {
2307: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2308: my $key = $ordered{$items[$i]};
2309: my %coursehash=&Apache::lonnet::coursedescription($key);
2310: my $coursetitle = $coursehash{'description'};
1.243 raeburn 2311: my ($subject,$title,$author,$publisher,$image,$imgsrc,$cdom,$cnum);
1.216 raeburn 2312: if (ref($bookshash->{$key}) eq 'HASH') {
2313: $subject = $bookshash->{$key}->{'subject'};
2314: $title = $bookshash->{$key}->{'title'};
1.242 raeburn 2315: if ($type eq 'textbooks') {
1.243 raeburn 2316: $publisher = $bookshash->{$key}->{'publisher'};
1.242 raeburn 2317: $author = $bookshash->{$key}->{'author'};
2318: $image = $bookshash->{$key}->{'image'};
2319: if ($image ne '') {
2320: my ($path,$imagefile) = ($image =~ m{^(.+)/([^/]+)$});
2321: my $imagethumb = "$path/tn-".$imagefile;
2322: $imgsrc = '<img src="'.$imagethumb.'" alt="'.&mt('Textbook image').'" />';
2323: }
1.216 raeburn 2324: }
2325: }
1.242 raeburn 2326: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type".'_'."$key','$type'".');"';
1.216 raeburn 2327: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.242 raeburn 2328: .'<select name="'.$type.'_'.$key.'"'.$chgstr.'>';
1.216 raeburn 2329: for (my $k=0; $k<=$maxnum; $k++) {
2330: my $vpos = $k+1;
2331: my $selstr;
2332: if ($k == $i) {
2333: $selstr = ' selected="selected" ';
2334: }
2335: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2336: }
2337: $datatable .= '</select>'.(' 'x2).
1.242 raeburn 2338: '<label><input type="checkbox" name="'.$type.'_del" value="'.$key.'" />'.
1.216 raeburn 2339: &mt('Delete?').'</label></span></td>'.
2340: '<td colspan="2">'.
1.242 raeburn 2341: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_subject_'.$i.'" value="'.$subject.'" /></span> '.
1.216 raeburn 2342: (' 'x2).
1.242 raeburn 2343: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_title_'.$i.'" value="'.$title.'" /></span> ';
2344: if ($type eq 'textbooks') {
2345: $datatable .= (' 'x2).
1.243 raeburn 2346: '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_publisher_'.$i.'" value="'.$publisher.'" /></span> '.
2347: (' 'x2).
1.242 raeburn 2348: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_author_'.$i.'" value="'.$author.'" /></span> '.
2349: (' 'x2).
2350: '<span class="LC_nobreak">'.&mt('Thumbnail:');
2351: if ($image) {
1.267 raeburn 2352: $datatable .= $imgsrc.
1.242 raeburn 2353: '<label><input type="checkbox" name="'.$type.'_image_del"'.
2354: ' value="'.$key.'" />'.&mt('Delete?').'</label></span> '.
2355: '<span class="LC_nobreak"> '.&mt('Replace:').' ';
2356: }
2357: if ($switchserver) {
2358: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2359: } else {
2360: $datatable .= '<input type="file" name="'.$type.'_image_'.$i.'" value="" />';
2361: }
1.216 raeburn 2362: }
1.242 raeburn 2363: $datatable .= '<input type="hidden" name="'.$type.'_id_'.$i.'" value="'.$type.'_'.$key.'" /></span> '.
1.216 raeburn 2364: '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
2365: $coursetitle.'</span></td></tr>'."\n";
2366: $itemcount ++;
2367: }
2368: }
2369: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.242 raeburn 2370: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type"."_addbook_pos','$type'".');"';
1.216 raeburn 2371: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
1.242 raeburn 2372: '<input type="hidden" name="'.$type.'_maxnum" value="'.$maxnum.'" />'."\n".
2373: '<select name="'.$type.'_addbook_pos"'.$chgstr.'>';
1.216 raeburn 2374: for (my $k=0; $k<$maxnum+1; $k++) {
2375: my $vpos = $k+1;
2376: my $selstr;
2377: if ($k == $maxnum) {
2378: $selstr = ' selected="selected" ';
2379: }
2380: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2381: }
2382: $datatable .= '</select> '."\n".
1.242 raeburn 2383: '<input type="checkbox" name="'.$type.'_addbook" value="1" />'.&mt('Add').'</td>'."\n".
1.216 raeburn 2384: '<td colspan="2">'.
1.242 raeburn 2385: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_addbook_subject" value="" /></span> '."\n".
1.216 raeburn 2386: (' 'x2).
1.242 raeburn 2387: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_addbook_title" value="" /></span> '."\n".
2388: (' 'x2);
2389: if ($type eq 'textbooks') {
1.243 raeburn 2390: $datatable .= '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_addbook_publisher" value="" /></span> '."\n".
2391: (' 'x2).
2392: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_addbook_author" value="" /></span> '."\n".
1.242 raeburn 2393: (' 'x2).
2394: '<span class="LC_nobreak">'.&mt('Image:').' ';
2395: if ($switchserver) {
2396: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2397: } else {
2398: $datatable .= '<input type="file" name="'.$type.'_addbook_image" value="" />';
2399: }
1.216 raeburn 2400: }
2401: $datatable .= '</span>'."\n".
2402: '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
1.242 raeburn 2403: &Apache::loncommon::select_dom_form($env{'request.role.domain'},$type.'_addbook_cdom').
2404: '<input type="text" size="25" name="'.$type.'_addbook_cnum" value="" />'.
1.216 raeburn 2405: &Apache::loncommon::selectcourse_link
1.242 raeburn 2406: ('display',$type.'_addbook_cnum',$type.'_addbook_cdom',undef,undef,undef,'Course');
1.216 raeburn 2407: '</span></td>'."\n".
2408: '</tr>'."\n";
2409: $itemcount ++;
2410: return $datatable;
2411: }
2412:
1.217 raeburn 2413: sub textbookcourses_javascript {
1.242 raeburn 2414: my ($settings) = @_;
2415: return unless(ref($settings) eq 'HASH');
2416: my (%ordered,%total,%jstext);
2417: foreach my $type ('textbooks','templates') {
2418: $total{$type} = 0;
2419: if (ref($settings->{$type}) eq 'HASH') {
2420: foreach my $item (keys(%{$settings->{$type}})) {
2421: if (ref($settings->{$type}->{$item}) eq 'HASH') {
2422: my $num = $settings->{$type}->{$item}{'order'};
2423: $ordered{$type}{$num} = $item;
2424: }
2425: }
2426: $total{$type} = scalar(keys(%{$settings->{$type}}));
2427: }
2428: my @jsarray = ();
2429: foreach my $item (sort {$a <=> $b } (keys(%{$ordered{$type}}))) {
2430: push(@jsarray,$ordered{$type}{$item});
2431: }
2432: $jstext{$type} = ' var '.$type.' = Array('."'".join("','",@jsarray)."'".');'."\n";
1.217 raeburn 2433: }
2434: return <<"ENDSCRIPT";
2435: <script type="text/javascript">
2436: // <![CDATA[
1.242 raeburn 2437: function reorderBooks(form,item,caller) {
1.217 raeburn 2438: var changedVal;
1.242 raeburn 2439: $jstext{'textbooks'};
2440: $jstext{'templates'};
2441: var newpos;
2442: var maxh;
2443: if (caller == 'textbooks') {
2444: newpos = 'textbooks_addbook_pos';
2445: maxh = 1 + $total{'textbooks'};
2446: } else {
2447: newpos = 'templates_addbook_pos';
2448: maxh = 1 + $total{'templates'};
2449: }
1.217 raeburn 2450: var current = new Array;
2451: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
2452: if (item == newpos) {
2453: changedVal = newitemVal;
2454: } else {
2455: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
2456: current[newitemVal] = newpos;
2457: }
1.242 raeburn 2458: if (caller == 'textbooks') {
2459: for (var i=0; i<textbooks.length; i++) {
2460: var elementName = 'textbooks_'+textbooks[i];
2461: if (elementName != item) {
2462: if (form.elements[elementName]) {
2463: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2464: current[currVal] = elementName;
2465: }
2466: }
2467: }
2468: }
2469: if (caller == 'templates') {
2470: for (var i=0; i<templates.length; i++) {
2471: var elementName = 'templates_'+templates[i];
2472: if (elementName != item) {
2473: if (form.elements[elementName]) {
2474: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2475: current[currVal] = elementName;
2476: }
1.217 raeburn 2477: }
2478: }
2479: }
2480: var oldVal;
2481: for (var j=0; j<maxh; j++) {
2482: if (current[j] == undefined) {
2483: oldVal = j;
2484: }
2485: }
2486: if (oldVal < changedVal) {
2487: for (var k=oldVal+1; k<=changedVal ; k++) {
2488: var elementName = current[k];
2489: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
2490: }
2491: } else {
2492: for (var k=changedVal; k<oldVal; k++) {
2493: var elementName = current[k];
2494: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
2495: }
2496: }
2497: return;
2498: }
2499:
2500: // ]]>
2501: </script>
2502:
2503: ENDSCRIPT
2504: }
2505:
1.267 raeburn 2506: sub ltitools_javascript {
2507: my ($settings) = @_;
2508: return unless(ref($settings) eq 'HASH');
2509: my (%ordered,$total,%jstext);
2510: $total = 0;
2511: foreach my $item (keys(%{$settings})) {
2512: if (ref($settings->{$item}) eq 'HASH') {
2513: my $num = $settings->{$item}{'order'};
2514: $ordered{$num} = $item;
2515: }
2516: }
2517: $total = scalar(keys(%{$settings}));
2518: my @jsarray = ();
2519: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
2520: push(@jsarray,$ordered{$item});
2521: }
2522: my $jstext = ' var ltitools = Array('."'".join("','",@jsarray)."'".');'."\n";
2523: return <<"ENDSCRIPT";
2524: <script type="text/javascript">
2525: // <![CDATA[
2526: function reorderLTI(form,item) {
2527: var changedVal;
2528: $jstext
2529: var newpos = 'ltitools_add_pos';
2530: var maxh = 1 + $total;
2531: var current = new Array;
2532: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
2533: if (item == newpos) {
2534: changedVal = newitemVal;
2535: } else {
2536: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
2537: current[newitemVal] = newpos;
2538: }
2539: for (var i=0; i<ltitools.length; i++) {
2540: var elementName = 'ltitools_'+ltitools[i];
2541: if (elementName != item) {
2542: if (form.elements[elementName]) {
2543: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2544: current[currVal] = elementName;
2545: }
2546: }
2547: }
2548: var oldVal;
2549: for (var j=0; j<maxh; j++) {
2550: if (current[j] == undefined) {
2551: oldVal = j;
2552: }
2553: }
2554: if (oldVal < changedVal) {
2555: for (var k=oldVal+1; k<=changedVal ; k++) {
2556: var elementName = current[k];
2557: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
2558: }
2559: } else {
2560: for (var k=changedVal; k<oldVal; k++) {
2561: var elementName = current[k];
2562: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
2563: }
2564: }
2565: return;
2566: }
2567:
2568: // ]]>
2569: </script>
2570:
2571: ENDSCRIPT
2572: }
2573:
1.3 raeburn 2574: sub print_autoenroll {
1.30 raeburn 2575: my ($dom,$settings,$rowtotal) = @_;
1.3 raeburn 2576: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
1.274 raeburn 2577: my ($defdom,$runon,$runoff,$coownerson,$coownersoff,$failsafe);
1.3 raeburn 2578: if (ref($settings) eq 'HASH') {
2579: if (exists($settings->{'run'})) {
2580: if ($settings->{'run'} eq '0') {
2581: $runoff = ' checked="checked" ';
2582: $runon = ' ';
2583: } else {
2584: $runon = ' checked="checked" ';
2585: $runoff = ' ';
2586: }
2587: } else {
2588: if ($autorun) {
2589: $runon = ' checked="checked" ';
2590: $runoff = ' ';
2591: } else {
2592: $runoff = ' checked="checked" ';
2593: $runon = ' ';
2594: }
2595: }
1.129 raeburn 2596: if (exists($settings->{'co-owners'})) {
2597: if ($settings->{'co-owners'} eq '0') {
2598: $coownersoff = ' checked="checked" ';
2599: $coownerson = ' ';
2600: } else {
2601: $coownerson = ' checked="checked" ';
2602: $coownersoff = ' ';
2603: }
2604: } else {
2605: $coownersoff = ' checked="checked" ';
2606: $coownerson = ' ';
2607: }
1.3 raeburn 2608: if (exists($settings->{'sender_domain'})) {
2609: $defdom = $settings->{'sender_domain'};
2610: }
1.274 raeburn 2611: if (exists($settings->{'autofailsafe'})) {
2612: $failsafe = $settings->{'autofailsafe'};
2613: }
1.14 raeburn 2614: } else {
2615: if ($autorun) {
2616: $runon = ' checked="checked" ';
2617: $runoff = ' ';
2618: } else {
2619: $runoff = ' checked="checked" ';
2620: $runon = ' ';
2621: }
1.3 raeburn 2622: }
2623: my $domform = &Apache::loncommon::select_dom_form($defdom,'sender_domain',1);
1.39 raeburn 2624: my $notif_sender;
2625: if (ref($settings) eq 'HASH') {
2626: $notif_sender = $settings->{'sender_uname'};
2627: }
1.3 raeburn 2628: my $datatable='<tr class="LC_odd_row">'.
2629: '<td>'.&mt('Auto-enrollment active?').'</td>'.
1.8 raeburn 2630: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 2631: '<input type="radio" name="autoenroll_run"'.
1.8 raeburn 2632: $runon.' value="1" />'.&mt('Yes').'</label> '.
2633: '<label><input type="radio" name="autoenroll_run"'.
1.14 raeburn 2634: $runoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 2635: '</tr><tr>'.
2636: '<td>'.&mt('Notification messages - sender').
1.8 raeburn 2637: '</td><td class="LC_right_item"><span class="LC_nobreak">'.
1.3 raeburn 2638: &mt('username').': '.
2639: '<input type="text" name="sender_uname" value="'.
1.39 raeburn 2640: $notif_sender.'" size="10" /> '.&mt('domain').
1.129 raeburn 2641: ': '.$domform.'</span></td></tr>'.
2642: '<tr class="LC_odd_row">'.
2643: '<td>'.&mt('Automatically assign co-ownership').'</td>'.
2644: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2645: '<input type="radio" name="autoassign_coowners"'.
2646: $coownerson.' value="1" />'.&mt('Yes').'</label> '.
2647: '<label><input type="radio" name="autoassign_coowners"'.
2648: $coownersoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.274 raeburn 2649: '</tr><tr>'.
2650: '<td>'.&mt('Failsafe for no drops when institutional data missing').'</td>'.
2651: '<td class="LC_right_item"><span class="LC_nobreak">'.
2652: '<input type="text" name="autoenroll_failsafe"'.
2653: ' value="'.$failsafe.'" size="4" /></td></tr>';
2654: $$rowtotal += 4;
1.3 raeburn 2655: return $datatable;
2656: }
2657:
2658: sub print_autoupdate {
1.30 raeburn 2659: my ($position,$dom,$settings,$rowtotal) = @_;
1.3 raeburn 2660: my $datatable;
2661: if ($position eq 'top') {
2662: my $updateon = ' ';
2663: my $updateoff = ' checked="checked" ';
2664: my $classlistson = ' ';
2665: my $classlistsoff = ' checked="checked" ';
2666: if (ref($settings) eq 'HASH') {
2667: if ($settings->{'run'} eq '1') {
2668: $updateon = $updateoff;
2669: $updateoff = ' ';
2670: }
2671: if ($settings->{'classlists'} eq '1') {
2672: $classlistson = $classlistsoff;
2673: $classlistsoff = ' ';
2674: }
2675: }
2676: my %title = (
2677: run => 'Auto-update active?',
2678: classlists => 'Update information in classlists?',
2679: );
2680: $datatable = '<tr class="LC_odd_row">'.
2681: '<td>'.&mt($title{'run'}).'</td>'.
1.8 raeburn 2682: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 2683: '<input type="radio" name="autoupdate_run"'.
1.8 raeburn 2684: $updateon.' value="1" />'.&mt('Yes').'</label> '.
2685: '<label><input type="radio" name="autoupdate_run"'.
2686: $updateoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 2687: '</tr><tr>'.
2688: '<td>'.&mt($title{'classlists'}).'</td>'.
1.8 raeburn 2689: '<td class="LC_right_item"><span class="LC_nobreak">'.
2690: '<label><input type="radio" name="classlists"'.
2691: $classlistson.' value="1" />'.&mt('Yes').'</label> '.
2692: '<label><input type="radio" name="classlists"'.
2693: $classlistsoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 2694: '</tr>';
1.30 raeburn 2695: $$rowtotal += 2;
1.131 raeburn 2696: } elsif ($position eq 'middle') {
2697: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
2698: my $numinrow = 3;
2699: my $locknamesettings;
2700: $datatable .= &insttypes_row($settings,$types,$usertypes,
2701: $dom,$numinrow,$othertitle,
2702: 'lockablenames');
2703: $$rowtotal ++;
1.3 raeburn 2704: } else {
1.44 raeburn 2705: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.132 raeburn 2706: my @fields = ('lastname','firstname','middlename','generation',
1.20 raeburn 2707: 'permanentemail','id');
1.33 raeburn 2708: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1.3 raeburn 2709: my $numrows = 0;
1.26 raeburn 2710: if (ref($types) eq 'ARRAY') {
2711: if (@{$types} > 0) {
2712: $datatable =
2713: &usertype_update_row($settings,$usertypes,\%fieldtitles,
2714: \@fields,$types,\$numrows);
1.30 raeburn 2715: $$rowtotal += @{$types};
1.26 raeburn 2716: }
1.3 raeburn 2717: }
2718: $datatable .=
2719: &usertype_update_row($settings,{'default' => $othertitle},
2720: \%fieldtitles,\@fields,['default'],
2721: \$numrows);
1.30 raeburn 2722: $$rowtotal ++;
1.3 raeburn 2723: }
2724: return $datatable;
2725: }
2726:
1.125 raeburn 2727: sub print_autocreate {
2728: my ($dom,$settings,$rowtotal) = @_;
1.191 raeburn 2729: my (%createon,%createoff,%currhash);
1.125 raeburn 2730: my @types = ('xml','req');
2731: if (ref($settings) eq 'HASH') {
2732: foreach my $item (@types) {
2733: $createoff{$item} = ' checked="checked" ';
2734: $createon{$item} = ' ';
2735: if (exists($settings->{$item})) {
2736: if ($settings->{$item}) {
2737: $createon{$item} = ' checked="checked" ';
2738: $createoff{$item} = ' ';
2739: }
2740: }
2741: }
1.210 raeburn 2742: if ($settings->{'xmldc'} ne '') {
1.191 raeburn 2743: $currhash{$settings->{'xmldc'}} = 1;
2744: }
1.125 raeburn 2745: } else {
2746: foreach my $item (@types) {
2747: $createoff{$item} = ' checked="checked" ';
2748: $createon{$item} = ' ';
2749: }
2750: }
2751: $$rowtotal += 2;
1.191 raeburn 2752: my $numinrow = 2;
1.125 raeburn 2753: my $datatable='<tr class="LC_odd_row">'.
2754: '<td>'.&mt('Create pending official courses from XML files').'</td>'.
2755: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2756: '<input type="radio" name="autocreate_xml"'.
2757: $createon{'xml'}.' value="1" />'.&mt('Yes').'</label> '.
2758: '<label><input type="radio" name="autocreate_xml"'.
1.143 raeburn 2759: $createoff{'xml'}.' value="0" />'.&mt('No').'</label></span>'.
2760: '</td></tr><tr>'.
2761: '<td>'.&mt('Create pending requests for official courses (if validated)').'</td>'.
2762: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2763: '<input type="radio" name="autocreate_req"'.
2764: $createon{'req'}.' value="1" />'.&mt('Yes').'</label> '.
2765: '<label><input type="radio" name="autocreate_req"'.
2766: $createoff{'req'}.' value="0" />'.&mt('No').'</label></span>';
1.191 raeburn 2767: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
2768: 'autocreate_xmldc',%currhash);
1.247 raeburn 2769: $datatable .= '</td></tr><tr class="LC_odd_row"><td>';
1.125 raeburn 2770: if ($numdc > 1) {
1.247 raeburn 2771: $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)').
2772: '</td><td class="LC_left_item">';
1.125 raeburn 2773: } else {
1.247 raeburn 2774: $datatable .= &mt('Course creation processed as:').
2775: '</td><td class="LC_right_item">';
1.125 raeburn 2776: }
1.247 raeburn 2777: $datatable .= $dctable.'</td></tr>';
1.191 raeburn 2778: $$rowtotal += $rows;
1.125 raeburn 2779: return $datatable;
2780: }
2781:
1.23 raeburn 2782: sub print_directorysrch {
1.277 raeburn 2783: my ($position,$dom,$settings,$rowtotal) = @_;
2784: my $datatable;
2785: if ($position eq 'top') {
2786: my $instsrchon = ' ';
2787: my $instsrchoff = ' checked="checked" ';
2788: my ($exacton,$containson,$beginson);
2789: my $instlocalon = ' ';
2790: my $instlocaloff = ' checked="checked" ';
2791: if (ref($settings) eq 'HASH') {
2792: if ($settings->{'available'} eq '1') {
2793: $instsrchon = $instsrchoff;
2794: $instsrchoff = ' ';
2795: }
2796: if ($settings->{'localonly'} eq '1') {
2797: $instlocalon = $instlocaloff;
2798: $instlocaloff = ' ';
2799: }
2800: if (ref($settings->{'searchtypes'}) eq 'ARRAY') {
2801: foreach my $type (@{$settings->{'searchtypes'}}) {
2802: if ($type eq 'exact') {
2803: $exacton = ' checked="checked" ';
2804: } elsif ($type eq 'contains') {
2805: $containson = ' checked="checked" ';
2806: } elsif ($type eq 'begins') {
2807: $beginson = ' checked="checked" ';
2808: }
2809: }
2810: } else {
2811: if ($settings->{'searchtypes'} eq 'exact') {
2812: $exacton = ' checked="checked" ';
2813: } elsif ($settings->{'searchtypes'} eq 'contains') {
2814: $containson = ' checked="checked" ';
2815: } elsif ($settings->{'searchtypes'} eq 'specify') {
1.25 raeburn 2816: $exacton = ' checked="checked" ';
2817: $containson = ' checked="checked" ';
2818: }
2819: }
1.277 raeburn 2820: }
2821: my ($searchtitles,$titleorder) = &sorted_searchtitles();
2822: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
2823:
2824: my $numinrow = 4;
2825: my $cansrchrow = 0;
2826: $datatable='<tr class="LC_odd_row">'.
2827: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Institutional directory search available?').'</span></td>'.
2828: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2829: '<input type="radio" name="dirsrch_available"'.
2830: $instsrchon.' value="1" />'.&mt('Yes').'</label> '.
2831: '<label><input type="radio" name="dirsrch_available"'.
2832: $instsrchoff.' value="0" />'.&mt('No').'</label></span></td>'.
2833: '</tr><tr>'.
2834: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search institution?').'</span></td>'.
2835: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2836: '<input type="radio" name="dirsrch_instlocalonly"'.
2837: $instlocaloff.' value="0" />'.&mt('Yes').'</label> '.
2838: '<label><input type="radio" name="dirsrch_instlocalonly"'.
2839: $instlocalon.' value="1" />'.&mt('No').'</label></span></td>'.
2840: '</tr>';
2841: $$rowtotal += 2;
2842: if (ref($usertypes) eq 'HASH') {
2843: if (keys(%{$usertypes}) > 0) {
2844: $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
2845: $numinrow,$othertitle,'cansearch');
2846: $cansrchrow = 1;
1.25 raeburn 2847: }
1.23 raeburn 2848: }
1.277 raeburn 2849: if ($cansrchrow) {
2850: $$rowtotal ++;
2851: $datatable .= '<tr>';
2852: } else {
2853: $datatable .= '<tr class="LC_odd_row">';
1.26 raeburn 2854: }
1.277 raeburn 2855: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Supported search methods').
2856: '</span></td><td class="LC_left_item" colspan="2"><table><tr>';
2857: foreach my $title (@{$titleorder}) {
2858: if (defined($searchtitles->{$title})) {
2859: my $check = ' ';
2860: if (ref($settings) eq 'HASH') {
2861: if (ref($settings->{'searchby'}) eq 'ARRAY') {
2862: if (grep(/^\Q$title\E$/,@{$settings->{'searchby'}})) {
2863: $check = ' checked="checked" ';
2864: }
1.39 raeburn 2865: }
1.25 raeburn 2866: }
1.277 raeburn 2867: $datatable .= '<td class="LC_left_item">'.
2868: '<span class="LC_nobreak"><label>'.
2869: '<input type="checkbox" name="searchby" '.
2870: 'value="'.$title.'"'.$check.'/>'.
2871: $searchtitles->{$title}.'</label></span></td>';
1.25 raeburn 2872: }
2873: }
1.277 raeburn 2874: $datatable .= '</tr></table></td></tr>';
2875: $$rowtotal ++;
2876: if ($cansrchrow) {
2877: $datatable .= '<tr class="LC_odd_row">';
2878: } else {
2879: $datatable .= '<tr>';
2880: }
2881: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Search latitude').'</span></td>'.
2882: '<td class="LC_left_item" colspan="2">'.
2883: '<span class="LC_nobreak"><label>'.
2884: '<input type="checkbox" name="searchtypes" '.
2885: $exacton.' value="exact" />'.&mt('Exact match').
2886: '</label> '.
2887: '<label><input type="checkbox" name="searchtypes" '.
2888: $beginson.' value="begins" />'.&mt('Begins with').
2889: '</label> '.
2890: '<label><input type="checkbox" name="searchtypes" '.
2891: $containson.' value="contains" />'.&mt('Contains').
2892: '</label></span></td></tr>';
2893: $$rowtotal ++;
1.26 raeburn 2894: } else {
1.277 raeburn 2895: my $domsrchon = ' checked="checked" ';
2896: my $domsrchoff = ' ';
2897: my $domlocalon = ' ';
2898: my $domlocaloff = ' checked="checked" ';
2899: if (ref($settings) eq 'HASH') {
2900: if ($settings->{'lclocalonly'} eq '1') {
2901: $domlocalon = $domlocaloff;
2902: $domlocaloff = ' ';
2903: }
2904: if ($settings->{'lcavailable'} eq '0') {
2905: $domsrchoff = $domsrchon;
2906: $domsrchon = ' ';
2907: }
2908: }
2909: $datatable='<tr class="LC_odd_row">'.
2910: '<td colspan="2"><span class ="LC_nobreak">'.&mt('LON-CAPA directory search available?').'</span></td>'.
2911: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2912: '<input type="radio" name="dirsrch_domavailable"'.
2913: $domsrchon.' value="1" />'.&mt('Yes').'</label> '.
2914: '<label><input type="radio" name="dirsrch_domavailable"'.
2915: $domsrchoff.' value="0" />'.&mt('No').'</label></span></td>'.
2916: '</tr><tr>'.
2917: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search LON-CAPA domain?').'</span></td>'.
2918: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2919: '<input type="radio" name="dirsrch_domlocalonly"'.
2920: $domlocaloff.' value="0" />'.&mt('Yes').'</label> '.
2921: '<label><input type="radio" name="dirsrch_domlocalonly"'.
2922: $domlocalon.' value="1" />'.&mt('No').'</label></span></td>'.
2923: '</tr>';
2924: $$rowtotal += 2;
1.26 raeburn 2925: }
1.25 raeburn 2926: return $datatable;
2927: }
2928:
1.28 raeburn 2929: sub print_contacts {
1.30 raeburn 2930: my ($dom,$settings,$rowtotal) = @_;
1.28 raeburn 2931: my $datatable;
2932: my @contacts = ('adminemail','supportemail');
1.134 raeburn 2933: my (%checked,%to,%otheremails,%bccemails);
1.102 raeburn 2934: my @mailings = ('errormail','packagesmail','lonstatusmail','helpdeskmail',
1.203 raeburn 2935: 'requestsmail','updatesmail','idconflictsmail');
1.28 raeburn 2936: foreach my $type (@mailings) {
2937: $otheremails{$type} = '';
2938: }
1.134 raeburn 2939: $bccemails{'helpdeskmail'} = '';
1.28 raeburn 2940: if (ref($settings) eq 'HASH') {
2941: foreach my $item (@contacts) {
2942: if (exists($settings->{$item})) {
2943: $to{$item} = $settings->{$item};
2944: }
2945: }
2946: foreach my $type (@mailings) {
2947: if (exists($settings->{$type})) {
2948: if (ref($settings->{$type}) eq 'HASH') {
2949: foreach my $item (@contacts) {
2950: if ($settings->{$type}{$item}) {
2951: $checked{$type}{$item} = ' checked="checked" ';
2952: }
2953: }
2954: $otheremails{$type} = $settings->{$type}{'others'};
1.134 raeburn 2955: if ($type eq 'helpdeskmail') {
2956: $bccemails{$type} = $settings->{$type}{'bcc'};
2957: }
1.28 raeburn 2958: }
1.89 raeburn 2959: } elsif ($type eq 'lonstatusmail') {
2960: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
1.28 raeburn 2961: }
2962: }
2963: } else {
2964: $to{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
2965: $to{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
2966: $checked{'errormail'}{'adminemail'} = ' checked="checked" ';
2967: $checked{'packagesmail'}{'adminemail'} = ' checked="checked" ';
1.89 raeburn 2968: $checked{'helpdeskmail'}{'supportemail'} = ' checked="checked" ';
2969: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
1.102 raeburn 2970: $checked{'requestsmail'}{'adminemail'} = ' checked="checked" ';
1.190 raeburn 2971: $checked{'updatesmail'}{'adminemail'} = ' checked="checked" ';
1.203 raeburn 2972: $checked{'idconflictsmail'}{'adminemail'} = ' checked="checked" ';
1.28 raeburn 2973: }
2974: my ($titles,$short_titles) = &contact_titles();
2975: my $rownum = 0;
2976: my $css_class;
2977: foreach my $item (@contacts) {
1.69 raeburn 2978: $css_class = $rownum%2?' class="LC_odd_row"':'';
1.30 raeburn 2979: $datatable .= '<tr'.$css_class.'>'.
2980: '<td><span class="LC_nobreak">'.$titles->{$item}.
2981: '</span></td><td class="LC_right_item">'.
1.28 raeburn 2982: '<input type="text" name="'.$item.'" value="'.
2983: $to{$item}.'" /></td></tr>';
1.203 raeburn 2984: $rownum ++;
1.28 raeburn 2985: }
2986: foreach my $type (@mailings) {
1.69 raeburn 2987: $css_class = $rownum%2?' class="LC_odd_row"':'';
1.28 raeburn 2988: $datatable .= '<tr'.$css_class.'>'.
1.30 raeburn 2989: '<td><span class="LC_nobreak">'.
2990: $titles->{$type}.': </span></td>'.
1.28 raeburn 2991: '<td class="LC_left_item">'.
2992: '<span class="LC_nobreak">';
2993: foreach my $item (@contacts) {
2994: $datatable .= '<label>'.
2995: '<input type="checkbox" name="'.$type.'"'.
2996: $checked{$type}{$item}.
2997: ' value="'.$item.'" />'.$short_titles->{$item}.
2998: '</label> ';
2999: }
3000: $datatable .= '</span><br />'.&mt('Others').': '.
3001: '<input type="text" name="'.$type.'_others" '.
1.134 raeburn 3002: 'value="'.$otheremails{$type}.'" />';
3003: if ($type eq 'helpdeskmail') {
1.136 raeburn 3004: $datatable .= '<br />'.&mt('Bcc:').(' 'x6).
1.134 raeburn 3005: '<input type="text" name="'.$type.'_bcc" '.
3006: 'value="'.$bccemails{$type}.'" />';
3007: }
3008: $datatable .= '</td></tr>'."\n";
1.203 raeburn 3009: $rownum ++;
1.28 raeburn 3010: }
1.203 raeburn 3011: my %choices;
3012: $choices{'reporterrors'} = &mt('E-mail error reports to [_1]',
3013: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
3014: &mt('LON-CAPA core group - MSU'),600,500));
3015: $choices{'reportupdates'} = &mt('E-mail record of completed LON-CAPA updates to [_1]',
3016: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
3017: &mt('LON-CAPA core group - MSU'),600,500));
3018: my @toggles = ('reporterrors','reportupdates');
3019: my %defaultchecked = ('reporterrors' => 'on',
3020: 'reportupdates' => 'on');
3021: (my $reports,$rownum) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
3022: \%choices,$rownum);
3023: $datatable .= $reports;
1.30 raeburn 3024: $$rowtotal += $rownum;
1.28 raeburn 3025: return $datatable;
3026: }
3027:
1.118 jms 3028: sub print_helpsettings {
1.168 raeburn 3029: my ($dom,$confname,$settings,$rowtotal) = @_;
3030: my ($datatable,$itemcount);
1.166 raeburn 3031: $itemcount = 1;
1.168 raeburn 3032: my (%choices,%defaultchecked,@toggles);
3033: $choices{'submitbugs'} = &mt('Display link to: [_1]?',
3034: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
3035: &mt('LON-CAPA bug tracker'),600,500));
3036: %defaultchecked = ('submitbugs' => 'on');
3037: @toggles = ('submitbugs',);
1.166 raeburn 3038:
1.168 raeburn 3039: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
3040: \%choices,$itemcount);
1.166 raeburn 3041: return $datatable;
1.121 raeburn 3042: }
3043:
3044: sub radiobutton_prefs {
1.192 raeburn 3045: my ($settings,$toggles,$defaultchecked,$choices,$itemcount,$onclick,
1.257 raeburn 3046: $additional,$align) = @_;
1.121 raeburn 3047: return unless ((ref($toggles) eq 'ARRAY') && (ref($defaultchecked) eq 'HASH') &&
3048: (ref($choices) eq 'HASH'));
3049:
1.170 raeburn 3050: my (%checkedon,%checkedoff,$datatable,$css_class);
1.121 raeburn 3051:
3052: foreach my $item (@{$toggles}) {
3053: if ($defaultchecked->{$item} eq 'on') {
1.118 jms 3054: $checkedon{$item} = ' checked="checked" ';
3055: $checkedoff{$item} = ' ';
1.121 raeburn 3056: } elsif ($defaultchecked->{$item} eq 'off') {
1.118 jms 3057: $checkedoff{$item} = ' checked="checked" ';
3058: $checkedon{$item} = ' ';
3059: }
3060: }
3061: if (ref($settings) eq 'HASH') {
1.121 raeburn 3062: foreach my $item (@{$toggles}) {
1.118 jms 3063: if ($settings->{$item} eq '1') {
3064: $checkedon{$item} = ' checked="checked" ';
3065: $checkedoff{$item} = ' ';
3066: } elsif ($settings->{$item} eq '0') {
3067: $checkedoff{$item} = ' checked="checked" ';
3068: $checkedon{$item} = ' ';
3069: }
3070: }
1.121 raeburn 3071: }
1.192 raeburn 3072: if ($onclick) {
3073: $onclick = ' onclick="'.$onclick.'"';
3074: }
1.121 raeburn 3075: foreach my $item (@{$toggles}) {
1.118 jms 3076: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.121 raeburn 3077: $datatable .=
1.192 raeburn 3078: '<tr'.$css_class.'><td valign="top">'.
3079: '<span class="LC_nobreak">'.$choices->{$item}.
1.257 raeburn 3080: '</span></td>';
3081: if ($align eq 'left') {
3082: $datatable .= '<td class="LC_left_item">';
3083: } else {
3084: $datatable .= '<td class="LC_right_item">';
3085: }
3086: $datatable .=
3087: '<span class="LC_nobreak">'.
1.118 jms 3088: '<label><input type="radio" name="'.
1.192 raeburn 3089: $item.'" '.$checkedon{$item}.' value="1"'.$onclick.' />'.&mt('Yes').
1.118 jms 3090: '</label> <label><input type="radio" name="'.$item.'" '.
1.192 raeburn 3091: $checkedoff{$item}.' value="0"'.$onclick.' />'.&mt('No').'</label>'.
3092: '</span>'.$additional.
3093: '</td>'.
1.118 jms 3094: '</tr>';
3095: $itemcount ++;
1.121 raeburn 3096: }
3097: return ($datatable,$itemcount);
3098: }
3099:
1.267 raeburn 3100: sub print_ltitools {
3101: my ($dom,$settings,$rowtotal) = @_;
3102: my $rownum = 0;
3103: my $css_class;
3104: my $itemcount = 1;
3105: my $maxnum = 0;
3106: my %ordered;
3107: if (ref($settings) eq 'HASH') {
3108: foreach my $item (keys(%{$settings})) {
3109: if (ref($settings->{$item}) eq 'HASH') {
3110: my $num = $settings->{$item}{'order'};
3111: $ordered{$num} = $item;
3112: }
3113: }
3114: }
3115: my $confname = $dom.'-domainconfig';
3116: my $switchserver = &check_switchserver($dom,$confname);
3117: my $maxnum = scalar(keys(%ordered));
3118: my $datatable = <itools_javascript($settings);
3119: my %lt = <itools_names();
3120: my @courseroles = ('cc','in','ta','ep','st');
3121: my @ltiroles = qw(Instructor ContentDeveloper TeachingAssistant Learner);
3122: my @fields = ('fullname','firstname','lastname','email','user','roles');
3123: if (keys(%ordered)) {
3124: my @items = sort { $a <=> $b } keys(%ordered);
3125: for (my $i=0; $i<@items; $i++) {
3126: $css_class = $itemcount%2?' class="LC_odd_row"':'';
3127: my $item = $ordered{$items[$i]};
3128: my ($title,$key,$secret,$url,$imgsrc,$version);
3129: if (ref($settings->{$item}) eq 'HASH') {
3130: $title = $settings->{$item}->{'title'};
3131: $url = $settings->{$item}->{'url'};
3132: $key = $settings->{$item}->{'key'};
3133: $secret = $settings->{$item}->{'secret'};
3134: my $image = $settings->{$item}->{'image'};
3135: if ($image ne '') {
3136: $imgsrc = '<img src="'.$image.'" alt="'.&mt('Tool Provider icon').'" />';
3137: }
3138: }
3139: my $chgstr = ' onchange="javascript:reorderLTI(this.form,'."'ltitools_".$item."'".');"';
3140: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
3141: .'<select name="ltitools_'.$item.'"'.$chgstr.'>';
3142: for (my $k=0; $k<=$maxnum; $k++) {
3143: my $vpos = $k+1;
3144: my $selstr;
3145: if ($k == $i) {
3146: $selstr = ' selected="selected" ';
3147: }
3148: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
3149: }
3150: $datatable .= '</select>'.(' 'x2).
3151: '<label><input type="checkbox" name="ltitools_del" value="'.$item.'" />'.
3152: &mt('Delete?').'</label></span></td>'.
3153: '<td colspan="2">'.
3154: '<fieldset><legend>'.&mt('Required settings').'</legend>'.
3155: '<span class="LC_nobreak">'.$lt{'title'}.':<input type="text" size="30" name="ltitools_title_'.$i.'" value="'.$title.'" /></span> '.
3156: (' 'x2).
3157: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="ltitools_version_'.$i.'">'.
3158: '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '.
3159: (' 'x2).
3160: '<span class="LC_nobreak">'.$lt{'msgtype'}.':<select name="ltitools_msgtype_'.$i.'">'.
3161: '<option value="basic-lti-launch-request" selected="selected">Launch</option></select></span> '.
3162: '<br /><br />'.
3163: '<span class="LC_nobreak">'.$lt{'url'}.':<input type="text" size="30" name="ltitools_url_'.$i.'"'.
3164: ' value="'.$url.'" /></span>'.
3165: (' 'x2).
3166: '<span class="LC_nobreak">'.$lt{'key'}.
3167: '<input type="text" size="25" name="ltitools_key_'.$i.'" value="'.$key.'" /></span> '.
3168: (' 'x2).
3169: '<span class="LC_nobreak">'.$lt{'secret'}.':'.
3170: '<input type="password" size="20" name="ltitools_secret_'.$i.'" value="'.$secret.'" />'.
3171: '<label><input type="checkbox" name="visible" onclick="if (this.checked) { this.form.ltitools_secret_'.$i.'.type='."'text'".' } else { this.form.ltitools_secret_'.$i.'.type='."'password'".' }" />'.&mt('Visible input').'</label>'.
3172: '<input type="hidden" name="ltitools_id_'.$i.'" value="'.$item.'" /></span>'.
3173: '</fieldset>'.
3174: '<fieldset><legend>'.&mt('Optional settings').'</legend>'.
3175: '<span class="LC_nobreak">'.&mt('Display target:');
3176: my %currdisp;
3177: if (ref($settings->{$item}->{'display'}) eq 'HASH') {
3178: if ($settings->{$item}->{'display'}->{'target'} eq 'window') {
3179: $currdisp{'window'} = ' checked="checked"';
3180: } else {
3181: $currdisp{'iframe'} = ' checked="checked"';
3182: }
3183: if ($settings->{$item}->{'display'}->{'width'} =~ /^(\d+)$/) {
3184: $currdisp{'width'} = $1;
3185: }
3186: if ($settings->{$item}->{'display'}->{'height'} =~ /^(\d+)$/) {
3187: $currdisp{'height'} = $1;
3188: }
3189: } else {
3190: $currdisp{'iframe'} = ' checked="checked"';
3191: }
3192: foreach my $disp ('iframe','window') {
3193: $datatable .= '<label><input type="radio" name="ltitools_target_'.$i.'" value="'.$disp.'"'.$currdisp{$disp}.' />'.
3194: $lt{$disp}.'</label>'.(' 'x2);
3195: }
3196: $datatable .= (' 'x4);
3197: foreach my $dimen ('width','height') {
3198: $datatable .= '<label>'.$lt{$dimen}.' '.
3199: '<input type="text" name="ltitools_'.$dimen.'_'.$i.'" size="5" value="'.$currdisp{$dimen}.'" /></label>'.
3200: (' 'x2);
3201: }
3202: $datatable .= '<br />';
3203: foreach my $extra ('passback','roster') {
3204: my $checkedon = '';
3205: my $checkedoff = ' checked="checked"';
3206: if ($settings->{$item}->{$extra}) {
3207: $checkedon = $checkedoff;
3208: $checkedoff = '';
3209: }
3210: $datatable .= $lt{$extra}.' '.
3211: '<label><input type="radio" name="ltitools_'.$extra.'_'.$i.'" value="1"'.$checkedon.' />'.
3212: &mt('Yes').'</label>'.(' 'x2).
3213: '<label><input type="radio" name="ltitools_'.$extra.'_'.$i.'" value="0"'.$checkedoff.' />'.
3214: &mt('No').'</label>'.(' 'x4);
3215: }
3216: $datatable .= '<br /><br /><span class="LC_nobreak">'.$lt{'icon'}.': ';
3217: if ($imgsrc) {
3218: $datatable .= $imgsrc.
3219: '<label><input type="checkbox" name="ltitools_image_del"'.
3220: ' value="'.$item.'" />'.&mt('Delete?').'</label></span> '.
3221: '<span class="LC_nobreak"> '.&mt('Replace:').' ';
3222: } else {
3223: $datatable .= '('.&mt('if larger than 21x21 pixels, image will be scaled').') ';
3224: }
3225: if ($switchserver) {
3226: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
3227: } else {
3228: $datatable .= '<input type="file" name="ltitools_image_'.$i.'" value="" />';
3229: }
3230: $datatable .= '</span></fieldset>';
3231: my (%checkedfields,%rolemaps);
3232: if (ref($settings->{$item}) eq 'HASH') {
3233: if (ref($settings->{$item}->{'fields'}) eq 'HASH') {
3234: %checkedfields = %{$settings->{$item}->{'fields'}};
3235: }
3236: if (ref($settings->{$item}->{'roles'}) eq 'HASH') {
3237: %rolemaps = %{$settings->{$item}->{'roles'}};
3238: $checkedfields{'roles'} = 1;
3239: }
3240: }
3241: $datatable .= '<fieldset><legend>'.&mt('User data sent on launch').'</legend>'.
3242: '<span class="LC_nobreak">';
3243: foreach my $field (@fields) {
3244: my $checked;
3245: if ($checkedfields{$field}) {
3246: $checked = ' checked="checked"';
3247: }
3248: $datatable .= '<label>'.
3249: '<input type="checkbox" name="ltitools_fields_'.$i.'" value="'.$field.'"'.$checked.' />'.
3250: $lt{$field}.'</label>'.(' ' x2);
3251: }
3252: $datatable .= '</span></fieldset>'.
3253: '<fieldset><legend>'.&mt('Role mapping').'</legend><table><tr>';
3254: foreach my $role (@courseroles) {
3255: my ($selected,$selectnone);
3256: if (!$rolemaps{$role}) {
3257: $selectnone = ' selected="selected"';
3258: }
3259: $datatable .= '<td align="center">'.
3260: &Apache::lonnet::plaintext($role,'Course').'<br />'.
3261: '<select name="ltitools_roles_'.$role.'_'.$i.'">'.
3262: '<option value=""'.$selectnone.'>'.&mt('Select').'</option>';
3263: foreach my $ltirole (@ltiroles) {
3264: unless ($selectnone) {
3265: if ($rolemaps{$role} eq $ltirole) {
3266: $selected = ' selected="selected"';
3267: } else {
3268: $selected = '';
3269: }
3270: }
3271: $datatable .= '<option value="'.$ltirole.'"'.$selected.'>'.$ltirole.'</option>';
3272: }
3273: $datatable .= '</select></td>';
3274: }
1.273 raeburn 3275: $datatable .= '</tr></table></fieldset>';
3276: my %courseconfig;
3277: if (ref($settings->{$item}) eq 'HASH') {
3278: if (ref($settings->{$item}->{'crsconf'}) eq 'HASH') {
3279: %courseconfig = %{$settings->{$item}->{'crsconf'}};
3280: }
3281: }
3282: $datatable .= '<fieldset><legend>'.&mt('Configurable in course').'</legend><span class="LC_nobreak">';
3283: foreach my $item ('label','title','target') {
3284: my $checked;
3285: if ($courseconfig{$item}) {
3286: $checked = ' checked="checked"';
3287: }
3288: $datatable .= '<label>'.
3289: '<input type="checkbox" name="ltitools_courseconfig_'.$i.'" value="'.$item.'"'.$checked.' />'.
3290: $lt{'crs'.$item}.'</label>'.(' ' x2)."\n";
3291: }
3292: $datatable .= '</span></fieldset>'.
1.267 raeburn 3293: '<fieldset><legend>'.&mt('Custom items sent on launch').'</legend>'.
3294: '<table><tr><th>'.&mt('Action').'</th><th>'.&mt('Name').'</th><th>'.&mt('Value').'</th></tr>';
3295: if (ref($settings->{$item}->{'custom'}) eq 'HASH') {
3296: my %custom = %{$settings->{$item}->{'custom'}};
3297: if (keys(%custom) > 0) {
3298: foreach my $key (sort(keys(%custom))) {
3299: $datatable .= '<tr><td><span class="LC_nobreak">'.
3300: '<label><input type="checkbox" name="ltitools_customdel_'.$i.'" value="'.
3301: $key.'" />'.&mt('Delete').'</label></span></td><td>'.$key.'</td>'.
3302: '<td><input type="text" name="ltitools_customval_'.$key.'_'.$i.'"'.
3303: ' value="'.$custom{$key}.'" /></td></tr>';
3304: }
3305: }
3306: }
3307: $datatable .= '<tr><td><span class="LC_nobreak">'.
3308: '<label><input type="checkbox" name="ltitools_customadd" value="'.$i.'" />'.
3309: &mt('Add').'</label></span></td><td><input type="text" name="ltitools_custom_name_'.$i.'" />'.
3310: '</td><td><input type="text" name="ltitools_custom_value_'.$i.'" /></td></tr>';
3311: $datatable .= '</table></fieldset></td></tr>'."\n";
3312: $itemcount ++;
3313: }
3314: }
3315: $css_class = $itemcount%2?' class="LC_odd_row"':'';
3316: my $chgstr = ' onchange="javascript:reorderLTI(this.form,'."'ltitools_add_pos'".');"';
3317: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
3318: '<input type="hidden" name="ltitools_maxnum" value="'.$maxnum.'" />'."\n".
3319: '<select name="ltitools_add_pos"'.$chgstr.'>';
3320: for (my $k=0; $k<$maxnum+1; $k++) {
3321: my $vpos = $k+1;
3322: my $selstr;
3323: if ($k == $maxnum) {
3324: $selstr = ' selected="selected" ';
3325: }
3326: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
3327: }
3328: $datatable .= '</select> '."\n".
3329: '<input type="checkbox" name="ltitools_add" value="1" />'.&mt('Add').'</td>'."\n".
3330: '<td colspan="2">'.
3331: '<fieldset><legend>'.&mt('Required settings').'</legend>'.
3332: '<span class="LC_nobreak">'.$lt{'title'}.':<input type="text" size="30" name="ltitools_add_title" value="" /></span> '."\n".
3333: (' 'x2).
3334: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="ltitools_add_version">'.
3335: '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '."\n".
3336: (' 'x2).
3337: '<span class="LC_nobreak">'.$lt{'msgtype'}.':<select name="ltitools_add_msgtype">'.
3338: '<option value="basic-lti-launch-request" selected="selected">Launch</option></select></span> '.
3339: '<br />'.
3340: '<span class="LC_nobreak">'.$lt{'url'}.':<input type="text" size="30" name="ltitools_add_url" value="" /></span> '."\n".
3341: (' 'x2).
3342: '<span class="LC_nobreak">'.$lt{'key'}.':<input type="text" size="25" name="ltitools_add_key" value="" /></span> '."\n".
3343: (' 'x2).
3344: '<span class="LC_nobreak">'.$lt{'secret'}.':<input type="password" size="20" name="ltitools_add_secret" value="" />'.
3345: '<label><input type="checkbox" name="visible" onclick="if (this.checked) { this.form.ltitools_add_secret.type='."'text'".' } else { this.form.ltitools_add_secret.type='."'password'".' }" />'.&mt('Visible input').'</label></span> '."\n".
3346: '</fieldset>'.
3347: '<fieldset><legend>'.&mt('Optional settings').'</legend>'.
3348: '<span class="LC_nobreak">'.&mt('Display target:');
3349: my %defaultdisp;
3350: $defaultdisp{'iframe'} = ' checked="checked"';
3351: foreach my $disp ('iframe','window') {
3352: $datatable .= '<label><input type="radio" name="ltitools_add_target" value="'.$disp.'"'.$defaultdisp{$disp}.' />'.
3353: $lt{$disp}.'</label>'.(' 'x2);
3354: }
3355: $datatable .= (' 'x4);
3356: foreach my $dimen ('width','height') {
3357: $datatable .= '<label>'.$lt{$dimen}.' '.
3358: '<input type="text" name="ltitools_add_'.$dimen.'" size="5" /></label>'.
3359: (' 'x2);
3360: }
3361: $datatable .= '<br />';
3362: foreach my $extra ('passback','roster') {
3363: $datatable .= $lt{$extra}.' '.
3364: '<label><input type="radio" name="ltitools_add_'.$extra.'" value="1" />'.
3365: &mt('Yes').'</label>'.(' 'x2).
3366: '<label><input type="radio" name="ltitools_add_'.$extra.'" value="0" checked="checked" />'.
3367: &mt('No').'</label>'.(' 'x4);
3368: }
3369: $datatable .= '<br /><br /><span class="LC_nobreak">'.$lt{'icon'}.': '.
3370: '('.&mt('if larger than 21x21 pixels, image will be scaled').') ';
3371: if ($switchserver) {
3372: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
3373: } else {
3374: $datatable .= '<input type="file" name="ltitools_add_image" value="" />';
3375: }
3376: $datatable .= '</span></fieldset>'.
3377: '<fieldset><legend>'.&mt('User data sent on launch').'</legend>'.
3378: '<span class="LC_nobreak">';
3379: foreach my $field (@fields) {
3380: $datatable .= '<label>'.
3381: '<input type="checkbox" name="ltitools_add_fields" value="'.$field.'" />'.
3382: $lt{$field}.'</label>'.(' ' x2);
3383: }
3384: $datatable .= '</span></fieldset>'.
3385: '<fieldset><legend>'.&mt('Role mapping').'</legend><table><tr>';
3386: foreach my $role (@courseroles) {
3387: my ($checked,$checkednone);
3388: $datatable .= '<td align="center">'.
3389: &Apache::lonnet::plaintext($role,'Course').'<br />'.
3390: '<select name="ltitools_add_roles_'.$role.'">'.
3391: '<option value="" selected="selected">'.&mt('Select').'</option>';
3392: foreach my $ltirole (@ltiroles) {
3393: $datatable .= '<option value="'.$ltirole.'">'.$ltirole.'</option>';
3394: }
3395: $datatable .= '</select></td>';
3396: }
3397: $datatable .= '</tr></table></fieldset>'.
1.273 raeburn 3398: '<fieldset><legend>'.&mt('Configurable in course').'</legend><span class="LC_nobreak">';
3399: foreach my $item ('label','title','target') {
3400: $datatable .= '<label>'.
3401: '<input type="checkbox" name="ltitools_courseconfig" value="'.$item.'" checked="checked" />'.
3402: $lt{'crs'.$item}.'</label>'.(' ' x2)."\n";
3403: }
3404: $datatable .= '</span></fieldset>'.
1.267 raeburn 3405: '<fieldset><legend>'.&mt('Custom items sent on launch').'</legend>'.
3406: '<table><tr><th>'.&mt('Action').'</th><th>'.&mt('Name').'</th><th>'.&mt('Value').'</th></tr>'.
3407: '<tr><td><span class="LC_nobreak">'.
3408: '<label><input type="checkbox" name="ltitools_add_custom" value="1" />'.
3409: &mt('Add').'</label></span></td><td><input type="text" name="ltitools_add_custom_name" />'.
3410: '</td><td><input type="text" name="ltitools_add_custom_value" /></td></tr>'.
3411: '</table></fieldset></td></tr>'."\n".
3412: '</td>'."\n".
3413: '</tr>'."\n";
3414: $itemcount ++;
3415: return $datatable;
3416: }
3417:
3418: sub ltitools_names {
3419: my %lt = &Apache::lonlocal::texthash(
3420: 'title' => 'Title',
3421: 'version' => 'Version',
3422: 'msgtype' => 'Message Type',
3423: 'url' => 'URL',
3424: 'key' => 'Key',
3425: 'secret' => 'Secret',
3426: 'icon' => 'Icon',
3427: 'user' => 'Username:domain',
3428: 'fullname' => 'Full Name',
3429: 'firstname' => 'First Name',
3430: 'lastname' => 'Last Name',
3431: 'email' => 'E-mail',
3432: 'roles' => 'Role',
3433: 'window' => 'Window/Tab',
3434: 'iframe' => 'iFrame',
3435: 'height' => 'Height',
3436: 'width' => 'Width',
3437: 'passback' => 'Tool can return grades:',
3438: 'roster' => 'Tool can retrieve roster:',
1.273 raeburn 3439: 'crstarget' => 'Display target',
3440: 'crslabel' => 'Course label',
3441: 'crstitle' => 'Course title',
1.267 raeburn 3442: );
3443: return %lt;
3444: }
3445:
1.121 raeburn 3446: sub print_coursedefaults {
1.139 raeburn 3447: my ($position,$dom,$settings,$rowtotal) = @_;
1.192 raeburn 3448: my ($css_class,$datatable,%checkedon,%checkedoff,%defaultchecked,@toggles);
1.121 raeburn 3449: my $itemcount = 1;
1.192 raeburn 3450: my %choices = &Apache::lonlocal::texthash (
3451: canuse_pdfforms => 'Course/Community users can create/upload PDF forms',
1.198 raeburn 3452: uploadquota => 'Default quota for files uploaded directly to course/community using Course Editor (MB)',
1.192 raeburn 3453: anonsurvey_threshold => 'Responder count needed before showing submissions for anonymous surveys',
3454: coursecredits => 'Credits can be specified for courses',
1.257 raeburn 3455: uselcmath => 'Math preview uses LON-CAPA previewer (javascript) in place of DragMath (Java)',
3456: usejsme => 'Molecule editor uses JSME (HTML5) in place of JME (Java)',
3457: postsubmit => 'Disable submit button/keypress following student submission',
1.276 raeburn 3458: canclone => "People who may clone a course (besides course's owner and coordinators)",
3459: mysqltables => 'Lifetime (s) of "Temporary" MySQL tables (student performance data) on homeserver',
1.192 raeburn 3460: );
1.198 raeburn 3461: my %staticdefaults = (
3462: anonsurvey_threshold => 10,
3463: uploadquota => 500,
1.257 raeburn 3464: postsubmit => 60,
1.276 raeburn 3465: mysqltables => 172800,
1.198 raeburn 3466: );
1.139 raeburn 3467: if ($position eq 'top') {
1.257 raeburn 3468: %defaultchecked = (
3469: 'canuse_pdfforms' => 'off',
3470: 'uselcmath' => 'on',
3471: 'usejsme' => 'on',
1.264 raeburn 3472: 'canclone' => 'none',
1.257 raeburn 3473: );
3474: @toggles = ('canuse_pdfforms','uselcmath','usejsme');
1.139 raeburn 3475: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
1.257 raeburn 3476: \%choices,$itemcount);
1.264 raeburn 3477: $css_class = $itemcount%2?' class="LC_odd_row"':'';
3478: $datatable .=
3479: '<tr'.$css_class.'><td valign="top">'.
3480: '<span class="LC_nobreak">'.$choices{'canclone'}.
3481: '</span></td><td class="LC_left_item">';
3482: my $currcanclone = 'none';
3483: my $onclick;
3484: my @cloneoptions = ('none','domain');
3485: my %clonetitles = (
3486: none => 'No additional course requesters',
3487: domain => "Any course requester in course's domain",
3488: instcode => 'Course requests for official courses ...',
3489: );
3490: my (%codedefaults,@code_order,@posscodes);
3491: if (&Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
3492: \@code_order) eq 'ok') {
3493: if (@code_order > 0) {
3494: push(@cloneoptions,'instcode');
3495: $onclick = ' onclick="toggleDisplay(this.form,'."'cloneinstcode'".');"';
3496: }
3497: }
3498: if (ref($settings) eq 'HASH') {
3499: if ($settings->{'canclone'}) {
3500: if (ref($settings->{'canclone'}) eq 'HASH') {
3501: if (ref($settings->{'canclone'}{'instcode'}) eq 'ARRAY') {
3502: if (@code_order > 0) {
3503: $currcanclone = 'instcode';
3504: @posscodes = @{$settings->{'canclone'}{'instcode'}};
3505: }
3506: }
3507: } elsif ($settings->{'canclone'} eq 'domain') {
3508: $currcanclone = $settings->{'canclone'};
3509: }
3510: }
3511: }
3512: foreach my $option (@cloneoptions) {
3513: my ($checked,$additional);
3514: if ($currcanclone eq $option) {
3515: $checked = ' checked="checked"';
3516: }
3517: if ($option eq 'instcode') {
3518: if (@code_order) {
3519: my $show = 'none';
3520: if ($checked) {
3521: $show = 'block';
3522: }
3523: $additional = '<div id="cloneinstcode" style="display:'.$show.'" />'.
3524: &mt('Institutional codes for new and cloned course have identical:').
3525: '<br />';
3526: foreach my $item (@code_order) {
3527: my $codechk;
3528: if ($checked) {
3529: if (grep(/^\Q$item\E$/,@posscodes)) {
3530: $codechk = ' checked="checked"';
3531: }
3532: }
3533: $additional .= '<label>'.
3534: '<input type="checkbox" name="clonecode" value="'.$item.'"'.$codechk.' />'.
3535: $item.'</label>';
3536: }
3537: $additional .= (' 'x2).'('.&mt('check as many as needed').')</div>';
3538: }
3539: }
3540: $datatable .=
3541: '<span class="LC_nobreak"><label><input type="radio" name="canclone"'.$checked.
3542: ' value="'.$option.'"'.$onclick.' />'.$clonetitles{$option}.
3543: '</label> '.$additional.'</span><br />';
3544: }
3545: $datatable .= '</td>'.
3546: '</tr>';
3547: $itemcount ++;
1.139 raeburn 3548: } else {
3549: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.276 raeburn 3550: my ($currdefresponder,%defcredits,%curruploadquota,%deftimeout,%currmysql);
1.192 raeburn 3551: my $currusecredits = 0;
1.257 raeburn 3552: my $postsubmitclient = 1;
1.271 raeburn 3553: my @types = ('official','unofficial','community','textbook','placement');
1.139 raeburn 3554: if (ref($settings) eq 'HASH') {
3555: $currdefresponder = $settings->{'anonsurvey_threshold'};
1.198 raeburn 3556: if (ref($settings->{'uploadquota'}) eq 'HASH') {
3557: foreach my $type (keys(%{$settings->{'uploadquota'}})) {
3558: $curruploadquota{$type} = $settings->{'uploadquota'}{$type};
3559: }
3560: }
1.192 raeburn 3561: if (ref($settings->{'coursecredits'}) eq 'HASH') {
1.257 raeburn 3562: foreach my $type (@types) {
3563: next if ($type eq 'community');
3564: $defcredits{$type} = $settings->{'coursecredits'}->{$type};
3565: if ($defcredits{$type} ne '') {
3566: $currusecredits = 1;
3567: }
3568: }
3569: }
3570: if (ref($settings->{'postsubmit'}) eq 'HASH') {
3571: if ($settings->{'postsubmit'}->{'client'} eq 'off') {
3572: $postsubmitclient = 0;
3573: foreach my $type (@types) {
3574: $deftimeout{$type} = $staticdefaults{'postsubmit'};
3575: }
3576: } else {
3577: foreach my $type (@types) {
3578: if (ref($settings->{'postsubmit'}->{'timeout'}) eq 'HASH') {
3579: if ($settings->{'postsubmit'}->{'timeout'}->{$type} =~ /^\d+$/) {
3580: $deftimeout{$type} = $settings->{'postsubmit'}->{'timeout'}->{$type};
3581: } else {
3582: $deftimeout{$type} = $staticdefaults{'postsubmit'};
3583: }
3584: } else {
3585: $deftimeout{$type} = $staticdefaults{'postsubmit'};
3586: }
3587: }
3588: }
3589: } else {
3590: foreach my $type (@types) {
3591: $deftimeout{$type} = $staticdefaults{'postsubmit'};
1.192 raeburn 3592: }
3593: }
1.276 raeburn 3594: if (ref($settings->{'mysqltables'}) eq 'HASH') {
3595: foreach my $type (keys(%{$settings->{'mysqltables'}})) {
3596: $currmysql{$type} = $settings->{'mysqltables'}{$type};
3597: }
3598: } else {
3599: foreach my $type (@types) {
3600: $currmysql{$type} = $staticdefaults{'mysqltables'};
3601: }
3602: }
1.258 raeburn 3603: } else {
3604: foreach my $type (@types) {
3605: $deftimeout{$type} = $staticdefaults{'postsubmit'};
3606: }
1.139 raeburn 3607: }
3608: if (!$currdefresponder) {
1.198 raeburn 3609: $currdefresponder = $staticdefaults{'anonsurvey_threshold'};
1.139 raeburn 3610: } elsif ($currdefresponder < 1) {
3611: $currdefresponder = 1;
3612: }
1.198 raeburn 3613: foreach my $type (@types) {
3614: if ($curruploadquota{$type} eq '') {
3615: $curruploadquota{$type} = $staticdefaults{'uploadquota'};
3616: }
3617: }
1.139 raeburn 3618: $datatable .=
1.192 raeburn 3619: '<tr'.$css_class.'><td><span class="LC_nobreak">'.
3620: $choices{'anonsurvey_threshold'}.
1.139 raeburn 3621: '</span></td>'.
3622: '<td class="LC_right_item"><span class="LC_nobreak">'.
3623: '<input type="text" name="anonsurvey_threshold"'.
3624: ' value="'.$currdefresponder.'" size="5" /></span>'.
1.230 raeburn 3625: '</td></tr>'."\n";
3626: $itemcount ++;
3627: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
3628: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
3629: $choices{'uploadquota'}.
3630: '</span></td>'.
3631: '<td align="right" class="LC_right_item">'.
3632: '<table><tr>';
1.198 raeburn 3633: foreach my $type (@types) {
3634: $datatable .= '<td align="center">'.&mt($type).'<br />'.
3635: '<input type="text" name="uploadquota_'.$type.'"'.
3636: ' value="'.$curruploadquota{$type}.'" size="5" /></td>';
3637: }
3638: $datatable .= '</tr></table></td></tr>'."\n";
1.230 raeburn 3639: $itemcount ++;
1.236 raeburn 3640: my $onclick = "toggleDisplay(this.form,'credits');";
1.210 raeburn 3641: my $display = 'none';
1.192 raeburn 3642: if ($currusecredits) {
3643: $display = 'block';
3644: }
3645: my $additional = '<div id="credits" style="display: '.$display.'">'.
1.257 raeburn 3646: '<i>'.&mt('Default credits').'</i><br /><table><tr>';
3647: foreach my $type (@types) {
3648: next if ($type eq 'community');
3649: $additional .= '<td align="center">'.&mt($type).'<br />'.
3650: '<input type="text" name="'.$type.'_credits"'.
1.258 raeburn 3651: ' value="'.$defcredits{$type}.'" size="3" /></td>';
1.257 raeburn 3652: }
3653: $additional .= '</tr></table></div>'."\n";
1.192 raeburn 3654: %defaultchecked = ('coursecredits' => 'off');
3655: @toggles = ('coursecredits');
3656: my $current = {
3657: 'coursecredits' => $currusecredits,
3658: };
3659: (my $table,$itemcount) =
3660: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
1.257 raeburn 3661: \%choices,$itemcount,$onclick,$additional,'left');
3662: $datatable .= $table;
3663: $onclick = "toggleDisplay(this.form,'studentsubmission');";
3664: my $display = 'none';
3665: if ($postsubmitclient) {
3666: $display = 'block';
3667: }
3668: $additional = '<div id="studentsubmission" style="display: '.$display.'">'.
1.259 raeburn 3669: &mt('Number of seconds submit is disabled').'<br />'.
3670: '<i>'.&mt('Enter 0 to remain disabled until page reload.').'</i><br />'.
3671: '<table><tr>';
1.257 raeburn 3672: foreach my $type (@types) {
3673: $additional .= '<td align="center">'.&mt($type).'<br />'.
3674: '<input type="text" name="'.$type.'_timeout" value="'.
3675: $deftimeout{$type}.'" size="5" /></td>';
3676: }
3677: $additional .= '</tr></table></div>'."\n";
3678: %defaultchecked = ('postsubmit' => 'on');
3679: @toggles = ('postsubmit');
1.280 raeburn 3680: $current = {
3681: 'postsubmit' => $postsubmitclient,
3682: };
1.257 raeburn 3683: ($table,$itemcount) =
3684: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
3685: \%choices,$itemcount,$onclick,$additional,'left');
1.192 raeburn 3686: $datatable .= $table;
1.276 raeburn 3687: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
3688: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
3689: $choices{'mysqltables'}.
3690: '</span></td>'.
3691: '<td align="right" class="LC_right_item">'.
3692: '<table><tr>';
3693: foreach my $type (@types) {
3694: $datatable .= '<td align="center">'.&mt($type).'<br />'.
3695: '<input type="text" name="mysqltables_'.$type.'"'.
3696: ' value="'.$currmysql{$type}.'" size="5" /></td>';
3697: }
3698: $datatable .= '</tr></table></td></tr>'."\n";
3699: $itemcount ++;
3700:
1.139 raeburn 3701: }
1.192 raeburn 3702: $$rowtotal += $itemcount;
1.121 raeburn 3703: return $datatable;
1.118 jms 3704: }
3705:
1.231 raeburn 3706: sub print_selfenrollment {
3707: my ($position,$dom,$settings,$rowtotal) = @_;
3708: my ($css_class,$datatable);
3709: my $itemcount = 1;
1.271 raeburn 3710: my @types = ('official','unofficial','community','textbook','placement');
1.231 raeburn 3711: if (($position eq 'top') || ($position eq 'middle')) {
1.232 raeburn 3712: my ($rowsref,$titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
3713: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
1.231 raeburn 3714: my @rows;
3715: my $key;
3716: if ($position eq 'top') {
3717: $key = 'admin';
3718: if (ref($rowsref) eq 'ARRAY') {
3719: @rows = @{$rowsref};
3720: }
3721: } elsif ($position eq 'middle') {
3722: $key = 'default';
3723: @rows = ('types','registered','approval','limit');
3724: }
3725: foreach my $row (@rows) {
3726: if (defined($titlesref->{$row})) {
3727: $itemcount ++;
3728: $css_class = $itemcount%2?' class="LC_odd_row"':'';
3729: $datatable .= '<tr'.$css_class.'>'.
3730: '<td>'.$titlesref->{$row}.'</td>'.
3731: '<td class="LC_left_item">'.
3732: '<table><tr>';
3733: my (%current,%currentcap);
3734: if (ref($settings) eq 'HASH') {
3735: if (ref($settings->{$key}) eq 'HASH') {
3736: foreach my $type (@types) {
3737: if (ref($settings->{$key}->{$type}) eq 'HASH') {
3738: $current{$type} = $settings->{$key}->{$type}->{$row};
3739: }
3740: if (($row eq 'limit') && ($key eq 'default')) {
3741: if (ref($settings->{$key}->{$type}) eq 'HASH') {
3742: $currentcap{$type} = $settings->{$key}->{$type}->{'cap'};
3743: }
3744: }
3745: }
3746: }
3747: }
3748: my %roles = (
3749: '0' => &Apache::lonnet::plaintext('dc'),
3750: );
3751:
3752: foreach my $type (@types) {
3753: unless (($row eq 'registered') && ($key eq 'default')) {
3754: $datatable .= '<th>'.&mt($type).'</th>';
3755: }
3756: }
3757: unless (($row eq 'registered') && ($key eq 'default')) {
3758: $datatable .= '</tr><tr>';
3759: }
3760: foreach my $type (@types) {
3761: if ($type eq 'community') {
3762: $roles{'1'} = &mt('Community personnel');
3763: } else {
3764: $roles{'1'} = &mt('Course personnel');
3765: }
3766: $datatable .= '<td style="vertical-align: top">';
3767: if ($position eq 'top') {
3768: my %checked;
3769: if ($current{$type} eq '0') {
3770: $checked{'0'} = ' checked="checked"';
3771: } else {
3772: $checked{'1'} = ' checked="checked"';
3773: }
3774: foreach my $role ('1','0') {
3775: $datatable .= '<span class="LC_nobreak"><label>'.
3776: '<input type="radio" name="selfenrolladmin_'.$row.'_'.$type.'" '.
3777: 'value="'.$role.'"'.$checked{$role}.' />'.
3778: $roles{$role}.'</label></span> ';
3779: }
3780: } else {
3781: if ($row eq 'types') {
3782: my %checked;
3783: if ($current{$type} =~ /^(all|dom)$/) {
3784: $checked{$1} = ' checked="checked"';
3785: } else {
3786: $checked{''} = ' checked="checked"';
3787: }
3788: foreach my $val ('','dom','all') {
3789: $datatable .= '<span class="LC_nobreak"><label>'.
3790: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
3791: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
3792: }
3793: } elsif ($row eq 'registered') {
3794: my %checked;
3795: if ($current{$type} eq '1') {
3796: $checked{'1'} = ' checked="checked"';
3797: } else {
3798: $checked{'0'} = ' checked="checked"';
3799: }
3800: foreach my $val ('0','1') {
3801: $datatable .= '<span class="LC_nobreak"><label>'.
3802: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
3803: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
3804: }
3805: } elsif ($row eq 'approval') {
3806: my %checked;
3807: if ($current{$type} =~ /^([12])$/) {
3808: $checked{$1} = ' checked="checked"';
3809: } else {
3810: $checked{'0'} = ' checked="checked"';
3811: }
3812: for my $val (0..2) {
3813: $datatable .= '<span class="LC_nobreak"><label>'.
3814: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
3815: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
3816: }
3817: } elsif ($row eq 'limit') {
3818: my %checked;
3819: if ($current{$type} =~ /^(allstudents|selfenrolled)$/) {
3820: $checked{$1} = ' checked="checked"';
3821: } else {
3822: $checked{'none'} = ' checked="checked"';
3823: }
3824: my $cap;
3825: if ($currentcap{$type} =~ /^\d+$/) {
3826: $cap = $currentcap{$type};
3827: }
3828: foreach my $val ('none','allstudents','selfenrolled') {
3829: $datatable .= '<span class="LC_nobreak"><label>'.
3830: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
3831: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
3832: }
3833: $datatable .= '<br />'.
3834: '<span class="LC_nobreak">'.&mt('Maximum allowed: ').
3835: '<input type="text" name="selfenrolldefault_cap_'.$type.'" size = "5" value="'.$cap.'" />'.
3836: '</span>';
3837: }
3838: }
3839: $datatable .= '</td>';
3840: }
3841: $datatable .= '</tr>';
3842: }
3843: $datatable .= '</table></td></tr>';
3844: }
3845: } elsif ($position eq 'bottom') {
1.235 raeburn 3846: $datatable .= &print_validation_rows('selfenroll',$dom,$settings,\$itemcount);
3847: }
3848: $$rowtotal += $itemcount;
3849: return $datatable;
3850: }
3851:
3852: sub print_validation_rows {
3853: my ($caller,$dom,$settings,$rowtotal) = @_;
3854: my ($itemsref,$namesref,$fieldsref);
3855: if ($caller eq 'selfenroll') {
3856: ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
3857: } elsif ($caller eq 'requestcourses') {
3858: ($itemsref,$namesref,$fieldsref) = &Apache::loncoursequeueadmin::requestcourses_validation_types();
3859: }
3860: my %currvalidation;
3861: if (ref($settings) eq 'HASH') {
3862: if (ref($settings->{'validation'}) eq 'HASH') {
3863: %currvalidation = %{$settings->{'validation'}};
1.231 raeburn 3864: }
1.235 raeburn 3865: }
3866: my $datatable;
3867: my $itemcount = 0;
3868: foreach my $item (@{$itemsref}) {
3869: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
3870: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
3871: $namesref->{$item}.
3872: '</span></td>'.
3873: '<td class="LC_left_item">';
3874: if (($item eq 'url') || ($item eq 'button')) {
3875: $datatable .= '<span class="LC_nobreak">'.
3876: '<input type="text" name="'.$caller.'_validation_'.$item.'"'.
3877: ' value="'.$currvalidation{$item}.'" size="50" /></span>';
3878: } elsif ($item eq 'fields') {
3879: my @currfields;
3880: if (ref($currvalidation{$item}) eq 'ARRAY') {
3881: @currfields = @{$currvalidation{$item}};
3882: }
3883: foreach my $field (@{$fieldsref}) {
3884: my $check = '';
3885: if (grep(/^\Q$field\E$/,@currfields)) {
3886: $check = ' checked="checked"';
3887: }
3888: $datatable .= '<span class="LC_nobreak"><label>'.
3889: '<input type="checkbox" name="'.$caller.'_validation_fields"'.
3890: ' value="'.$field.'"'.$check.' />'.$field.
3891: '</label></span> ';
3892: }
3893: } elsif ($item eq 'markup') {
3894: $datatable .= '<textarea name="'.$caller.'_validation_markup" cols="50" rows="5" wrap="soft">'.
3895: $currvalidation{$item}.
1.231 raeburn 3896: '</textarea>';
1.235 raeburn 3897: }
3898: $datatable .= '</td></tr>'."\n";
3899: if (ref($rowtotal)) {
1.231 raeburn 3900: $itemcount ++;
3901: }
3902: }
1.235 raeburn 3903: if ($caller eq 'requestcourses') {
3904: my %currhash;
1.248 raeburn 3905: if (ref($settings) eq 'HASH') {
3906: if (ref($settings->{'validation'}) eq 'HASH') {
3907: if ($settings->{'validation'}{'dc'} ne '') {
3908: $currhash{$settings->{'validation'}{'dc'}} = 1;
3909: }
1.235 raeburn 3910: }
3911: }
3912: my $numinrow = 2;
3913: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
3914: 'validationdc',%currhash);
1.247 raeburn 3915: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
3916: $datatable .= '</td></tr><tr'.$css_class.'><td>';
1.235 raeburn 3917: if ($numdc > 1) {
1.247 raeburn 3918: $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)');
1.235 raeburn 3919: } else {
1.247 raeburn 3920: $datatable .= &mt('Course creation processed as: ');
1.235 raeburn 3921: }
1.247 raeburn 3922: $datatable .= '</td><td class="LC_left_item">'.$dctable.'</td></tr>';
1.235 raeburn 3923: $itemcount ++;
3924: }
3925: if (ref($rowtotal)) {
3926: $$rowtotal += $itemcount;
3927: }
1.231 raeburn 3928: return $datatable;
3929: }
3930:
1.137 raeburn 3931: sub print_usersessions {
3932: my ($position,$dom,$settings,$rowtotal) = @_;
1.279 raeburn 3933: my ($css_class,$datatable,$itemcount,%checked,%choices);
1.275 raeburn 3934: my (%by_ip,%by_location,@intdoms,@instdoms);
3935: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
1.145 raeburn 3936:
3937: my @alldoms = &Apache::lonnet::all_domains();
1.152 raeburn 3938: my %serverhomes = %Apache::lonnet::serverhomeIDs;
1.149 raeburn 3939: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.152 raeburn 3940: my %altids = &id_for_thisdom(%servers);
1.145 raeburn 3941: if ($position eq 'top') {
1.152 raeburn 3942: if (keys(%serverhomes) > 1) {
1.145 raeburn 3943: my %spareid = ¤t_offloads_to($dom,$settings,\%servers);
1.261 raeburn 3944: my $curroffloadnow;
3945: if (ref($settings) eq 'HASH') {
3946: if (ref($settings->{'offloadnow'}) eq 'HASH') {
3947: $curroffloadnow = $settings->{'offloadnow'};
3948: }
3949: }
3950: $datatable .= &spares_row($dom,\%servers,\%spareid,\%serverhomes,\%altids,$curroffloadnow,$rowtotal);
1.145 raeburn 3951: } else {
1.140 raeburn 3952: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.279 raeburn 3953: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one server.').
3954: '</td></tr>';
1.140 raeburn 3955: }
1.137 raeburn 3956: } else {
1.279 raeburn 3957: my %titles = &usersession_titles();
3958: my ($prefix,@types);
3959: if ($position eq 'bottom') {
3960: $prefix = 'remote';
3961: @types = ('version','excludedomain','includedomain');
1.145 raeburn 3962: } else {
1.279 raeburn 3963: $prefix = 'hosted';
3964: @types = ('excludedomain','includedomain');
3965: }
3966: ($datatable,$itemcount) = &rules_by_location($settings,$prefix,\%by_location,\%by_ip,\@types,\%titles);
3967: }
3968: $$rowtotal += $itemcount;
3969: return $datatable;
3970: }
3971:
3972: sub rules_by_location {
3973: my ($settings,$prefix,$by_location,$by_ip,$types,$titles) = @_;
3974: my ($datatable,$itemcount,$css_class);
3975: if (keys(%{$by_location}) == 0) {
3976: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
3977: $datatable = '<tr'.$css_class.'><td colspan="2">'.
3978: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one institution.').
3979: '</td></tr>';
3980: $itemcount = 1;
3981: } else {
3982: $itemcount = 0;
3983: my $numinrow = 5;
3984: my (%current,%checkedon,%checkedoff);
3985: my @locations = sort(keys(%{$by_location}));
3986: foreach my $type (@{$types}) {
3987: $checkedon{$type} = '';
3988: $checkedoff{$type} = ' checked="checked"';
3989: }
3990: if (ref($settings) eq 'HASH') {
3991: if (ref($settings->{$prefix}) eq 'HASH') {
3992: foreach my $key (keys(%{$settings->{$prefix}})) {
3993: $current{$key} = $settings->{$prefix}{$key};
3994: if ($key eq 'version') {
3995: if ($current{$key} ne '') {
1.145 raeburn 3996: $checkedon{$key} = ' checked="checked"';
3997: $checkedoff{$key} = '';
3998: }
1.279 raeburn 3999: } elsif (ref($current{$key}) eq 'ARRAY') {
4000: $checkedon{$key} = ' checked="checked"';
4001: $checkedoff{$key} = '';
1.137 raeburn 4002: }
4003: }
4004: }
1.279 raeburn 4005: }
4006: foreach my $type (@{$types}) {
4007: next if ($type ne 'version' && !@locations);
4008: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
4009: $datatable .= '<tr'.$css_class.'>
4010: <td><span class="LC_nobreak">'.$titles->{$type}.'</span><br />
4011: <span class="LC_nobreak">
4012: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedoff{$type}.' value="0" />'.&mt('Not in use').'</label>
4013: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedon{$type}.' value="1" />'.&mt('In use').'</label></span></td><td>';
4014: if ($type eq 'version') {
4015: my @lcversions = &Apache::lonnet::all_loncaparevs();
4016: my $selector = '<select name="'.$prefix.'_version">';
4017: foreach my $version (@lcversions) {
4018: my $selected = '';
4019: if ($current{'version'} eq $version) {
4020: $selected = ' selected="selected"';
1.145 raeburn 4021: }
1.279 raeburn 4022: $selector .= ' <option value="'.$version.'"'.
4023: $selected.'>'.$version.'</option>';
4024: }
4025: $selector .= '</select> ';
4026: $datatable .= &mt('remote server must be version: [_1] or later',$selector);
4027: } else {
4028: $datatable.= '<div><input type="button" value="'.&mt('check all').'" '.
4029: 'onclick="javascript:checkAll(document.display.'.$prefix.'_'.$type.')"'.
4030: ' />'.(' 'x2).
4031: '<input type="button" value="'.&mt('uncheck all').'" '.
4032: 'onclick="javascript:uncheckAll(document.display.'.$prefix.'_'.$type.')" />'.
4033: "\n".
4034: '</div><div><table>';
4035: my $rem;
4036: for (my $i=0; $i<@locations; $i++) {
4037: my ($showloc,$value,$checkedtype);
4038: if (ref($by_location->{$locations[$i]}) eq 'ARRAY') {
4039: my $ip = $by_location->{$locations[$i]}->[0];
4040: if (ref($by_ip->{$ip}) eq 'ARRAY') {
4041: $value = join(':',@{$by_ip->{$ip}});
4042: $showloc = join(', ',@{$by_ip->{$ip}});
4043: if (ref($current{$type}) eq 'ARRAY') {
4044: foreach my $loc (@{$by_ip->{$ip}}) {
4045: if (grep(/^\Q$loc\E$/,@{$current{$type}})) {
4046: $checkedtype = ' checked="checked"';
4047: last;
1.145 raeburn 4048: }
1.138 raeburn 4049: }
4050: }
4051: }
1.137 raeburn 4052: }
1.279 raeburn 4053: $rem = $i%($numinrow);
4054: if ($rem == 0) {
4055: if ($i > 0) {
4056: $datatable .= '</tr>';
4057: }
4058: $datatable .= '<tr>';
4059: }
4060: $datatable .= '<td class="LC_left_item">'.
4061: '<span class="LC_nobreak"><label>'.
4062: '<input type="checkbox" name="'.$prefix.'_'.$type.
4063: '" value="'.$value.'"'.$checkedtype.' />'.$showloc.
4064: '</label></span></td>';
4065: }
4066: $rem = @locations%($numinrow);
4067: my $colsleft = $numinrow - $rem;
4068: if ($colsleft > 1 ) {
4069: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
4070: ' </td>';
4071: } elsif ($colsleft == 1) {
4072: $datatable .= '<td class="LC_left_item"> </td>';
1.137 raeburn 4073: }
1.279 raeburn 4074: $datatable .= '</tr></table>';
1.137 raeburn 4075: }
1.279 raeburn 4076: $datatable .= '</td></tr>';
4077: $itemcount ++;
1.137 raeburn 4078: }
4079: }
1.279 raeburn 4080: return ($datatable,$itemcount);
1.137 raeburn 4081: }
4082:
1.275 raeburn 4083: sub print_ssl {
4084: my ($position,$dom,$settings,$rowtotal) = @_;
4085: my ($css_class,$datatable);
4086: my $itemcount = 1;
4087: if ($position eq 'top') {
1.281 ! raeburn 4088: my $primary_id = &Apache::lonnet::domain($dom,'primary');
! 4089: my $intdom = &Apache::lonnet::internet_dom($primary_id);
! 4090: my $same_institution;
! 4091: if ($intdom ne '') {
! 4092: my $internet_names = &Apache::lonnet::get_internet_names($Apache::lonnet::perlvar{'lonHostID'});
! 4093: if (ref($internet_names) eq 'ARRAY') {
! 4094: if (grep(/^\Q$intdom\E$/,@{$internet_names})) {
! 4095: $same_institution = 1;
! 4096: }
! 4097: }
! 4098: }
1.275 raeburn 4099: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.281 ! raeburn 4100: $datatable = '<tr'.$css_class.'><td colspan="2">';
! 4101: if ($same_institution) {
! 4102: my %domservers = &Apache::lonnet::get_servers($dom);
! 4103: $datatable .= &LONCAPA::SSL::print_certstatus(\%domservers,'web','domprefs');
! 4104: } else {
! 4105: $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.");
! 4106: }
! 4107: $datatable .= '</td></tr>';
1.275 raeburn 4108: $itemcount ++;
4109: } else {
4110: my %titles = &ssl_titles();
4111: my (%by_ip,%by_location,@intdoms,@instdoms);
4112: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
4113: my @alldoms = &Apache::lonnet::all_domains();
4114: my %serverhomes = %Apache::lonnet::serverhomeIDs;
4115: my @domservers = &Apache::lonnet::get_servers($dom);
4116: my %servers = &Apache::lonnet::internet_dom_servers($dom);
4117: my %altids = &id_for_thisdom(%servers);
4118: if ($position eq 'middle') {
4119: foreach my $type ('dom','intdom','other') {
4120: my %checked;
4121: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4122: $datatable .= '<tr'.$css_class.'><td>'.$titles{$type}.'</td>'.
4123: '<td class="LC_right_item">';
4124: my $skip;
4125: if ($type eq 'dom') {
4126: unless (keys(%servers) > 1) {
4127: $datatable .= &mt('Nothing to set here, as there are no other servers/VMs');
4128: $skip = 1;
4129: }
4130: }
4131: if ($type eq 'intdom') {
4132: unless (@instdoms > 1) {
4133: $datatable .= &mt('Nothing to set here, as there are no other domains for this institution');
4134: $skip = 1;
4135: }
4136: } elsif ($type eq 'other') {
4137: if (keys(%by_location) == 0) {
4138: $datatable .= &mt('Nothing to set here, as there are no other institutions');
4139: $skip = 1;
4140: }
4141: }
4142: unless ($skip) {
4143: $checked{'yes'} = ' checked="checked"';
4144: if (ref($settings) eq 'HASH') {
4145: if (ref($settings->{'connect'}) eq 'HASH') {
4146: if ($settings->{'connect'}->{$type} =~ /^(no|req)$/) {
4147: $checked{$1} = $checked{'yes'};
4148: delete($checked{'yes'});
4149: }
4150: }
4151: }
4152: foreach my $option ('no','yes','req') {
4153: $datatable .= '<span class="LC_nobreak"><label>'.
4154: '<input type="radio" name="connect_'.$type.'" '.
4155: 'value="'.$option.'"'.$checked{$option}.' />'.$titles{$option}.
4156: '</label></span>'.(' 'x2);
4157: }
4158: }
4159: $datatable .= '</td></tr>';
4160: $itemcount ++;
4161: }
4162: } else {
4163: my $prefix = 'replication';
4164: my @types = ('certreq','nocertreq');
1.279 raeburn 4165: if (keys(%by_location) == 0) {
4166: $datatable .= '<tr'.$css_class.'><td>'.
4167: &mt('Nothing to set here, as there are no other institutions').
4168: '</td></tr>';
4169: $itemcount ++;
1.275 raeburn 4170: } else {
1.279 raeburn 4171: ($datatable,$itemcount) =
4172: &rules_by_location($settings,$prefix,\%by_location,\%by_ip,\@types,\%titles);
1.275 raeburn 4173: }
4174: }
4175: }
4176: $$rowtotal += $itemcount;
4177: return $datatable;
4178: }
4179:
4180: sub ssl_titles {
4181: return &Apache::lonlocal::texthash (
4182: dom => 'LON-CAPA servers/VMs from same domain',
4183: intdom => 'LON-CAPA servers/VMs from same "internet" domain',
4184: other => 'External LON-CAPA servers/VMs',
4185: connect => 'Connections to other servers',
4186: replication => 'Replicating content to other institutions',
4187: certreq => 'Client certificate required, but specific domains exempt',
4188: nocertreq => 'No client certificate required, except for specific domains',
4189: no => 'SSL not used',
4190: yes => 'SSL Optional (used if available)',
4191: req => 'SSL Required',
4192: );
1.279 raeburn 4193: }
4194:
4195: sub print_trust {
4196: my ($prefix,$dom,$settings,$rowtotal) = @_;
4197: my ($css_class,$datatable,%checked,%choices);
4198: my (%by_ip,%by_location,@intdoms,@instdoms);
4199: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
4200: my $itemcount = 1;
4201: my %titles = &trust_titles();
4202: my @types = ('exc','inc');
4203: if ($prefix eq 'top') {
4204: $prefix = 'content';
4205: } elsif ($prefix eq 'bottom') {
4206: $prefix = 'msg';
4207: }
4208: ($datatable,$itemcount) = &rules_by_location($settings,$prefix,\%by_location,\%by_ip,\@types,\%titles);
4209: $$rowtotal += $itemcount;
4210: return $datatable;
4211: }
4212:
4213: sub trust_titles {
4214: return &Apache::lonlocal::texthash(
4215: content => "Access to this domain's content by others",
4216: shared => "Access to other domain's content by this domain",
4217: enroll => "Enrollment in this domain's courses by others",
4218: othcoau => "Co-author roles in this domain for others",
4219: coaurem => "Co-author roles for this domain's users elsewhere",
4220: domroles => "Domain roles in this domain assignable to others",
4221: catalog => "Course Catalog for this domain displayed elsewhere",
4222: reqcrs => "Requests for creation of courses in this domain by others",
4223: msg => "Users in other domains can send messages to this domain",
4224: exc => "Allow all, but exclude specific domains",
4225: inc => "Deny all, but include specific domains",
4226: );
1.275 raeburn 4227: }
4228:
1.138 raeburn 4229: sub build_location_hashes {
1.275 raeburn 4230: my ($intdoms,$by_ip,$by_location,$instdoms) = @_;
1.138 raeburn 4231: return unless((ref($intdoms) eq 'ARRAY') && (ref($by_ip) eq 'HASH') &&
1.275 raeburn 4232: (ref($by_location) eq 'HASH') && (ref($instdoms) eq 'ARRAY'));
1.138 raeburn 4233: my %iphost = &Apache::lonnet::get_iphost();
4234: my $primary_id = &Apache::lonnet::domain($env{'request.role.domain'},'primary');
4235: my $primary_ip = &Apache::lonnet::get_host_ip($primary_id);
4236: if (ref($iphost{$primary_ip}) eq 'ARRAY') {
4237: foreach my $id (@{$iphost{$primary_ip}}) {
4238: my $intdom = &Apache::lonnet::internet_dom($id);
4239: unless(grep(/^\Q$intdom\E$/,@{$intdoms})) {
4240: push(@{$intdoms},$intdom);
4241: }
4242: }
4243: }
4244: foreach my $ip (keys(%iphost)) {
4245: if (ref($iphost{$ip}) eq 'ARRAY') {
4246: foreach my $id (@{$iphost{$ip}}) {
4247: my $location = &Apache::lonnet::internet_dom($id);
4248: if ($location) {
1.275 raeburn 4249: if (grep(/^\Q$location\E$/,@{$intdoms})) {
4250: my $dom = &Apache::lonnet::host_domain($id);
4251: unless (grep(/^\Q$dom\E/,@{$instdoms})) {
4252: push(@{$instdoms},$dom);
4253: }
4254: next;
4255: }
1.138 raeburn 4256: if (ref($by_ip->{$ip}) eq 'ARRAY') {
4257: unless(grep(/^\Q$location\E$/,@{$by_ip->{$ip}})) {
4258: push(@{$by_ip->{$ip}},$location);
4259: }
4260: } else {
4261: $by_ip->{$ip} = [$location];
4262: }
4263: }
4264: }
4265: }
4266: }
4267: foreach my $ip (sort(keys(%{$by_ip}))) {
4268: if (ref($by_ip->{$ip}) eq 'ARRAY') {
4269: @{$by_ip->{$ip}} = sort(@{$by_ip->{$ip}});
4270: my $first = $by_ip->{$ip}->[0];
4271: if (ref($by_location->{$first}) eq 'ARRAY') {
4272: unless (grep(/^\Q$ip\E$/,@{$by_location->{$first}})) {
4273: push(@{$by_location->{$first}},$ip);
4274: }
4275: } else {
4276: $by_location->{$first} = [$ip];
4277: }
4278: }
4279: }
4280: return;
4281: }
4282:
1.145 raeburn 4283: sub current_offloads_to {
4284: my ($dom,$settings,$servers) = @_;
4285: my (%spareid,%otherdomconfigs);
1.152 raeburn 4286: if (ref($servers) eq 'HASH') {
1.145 raeburn 4287: foreach my $lonhost (sort(keys(%{$servers}))) {
4288: my $gotspares;
1.152 raeburn 4289: if (ref($settings) eq 'HASH') {
4290: if (ref($settings->{'spares'}) eq 'HASH') {
4291: if (ref($settings->{'spares'}{$lonhost}) eq 'HASH') {
4292: $spareid{$lonhost}{'primary'} = $settings->{'spares'}{$lonhost}{'primary'};
4293: $spareid{$lonhost}{'default'} = $settings->{'spares'}{$lonhost}{'default'};
4294: $gotspares = 1;
4295: }
1.145 raeburn 4296: }
4297: }
4298: unless ($gotspares) {
4299: my $gotspares;
4300: my $serverhomeID =
4301: &Apache::lonnet::get_server_homeID($servers->{$lonhost});
4302: my $serverhomedom =
4303: &Apache::lonnet::host_domain($serverhomeID);
4304: if ($serverhomedom ne $dom) {
4305: if (ref($otherdomconfigs{$serverhomedom} eq 'HASH')) {
4306: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
4307: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
4308: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
4309: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
4310: $gotspares = 1;
4311: }
4312: }
4313: } else {
4314: $otherdomconfigs{$serverhomedom} =
4315: &Apache::lonnet::get_dom('configuration',['usersessions'],$serverhomedom);
4316: if (ref($otherdomconfigs{$serverhomedom}) eq 'HASH') {
4317: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
4318: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
4319: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{$lonhost}) eq 'HASH') {
4320: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
4321: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
4322: $gotspares = 1;
4323: }
4324: }
4325: }
4326: }
4327: }
4328: }
4329: }
4330: unless ($gotspares) {
4331: if ($lonhost eq $Apache::lonnet::perlvar{'lonHostID'}) {
4332: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
4333: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
4334: } else {
4335: my $server_hostname = &Apache::lonnet::hostname($lonhost);
4336: my $server_homeID = &Apache::lonnet::get_server_homeID($server_hostname);
4337: if ($server_homeID eq $Apache::lonnet::perlvar{'lonHostID'}) {
4338: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
4339: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
4340: } else {
1.150 raeburn 4341: my %what = (
4342: spareid => 1,
4343: );
4344: my ($result,$returnhash) =
4345: &Apache::lonnet::get_remote_globals($lonhost,\%what);
4346: if ($result eq 'ok') {
4347: if (ref($returnhash) eq 'HASH') {
4348: if (ref($returnhash->{'spareid'}) eq 'HASH') {
4349: $spareid{$lonhost}{'primary'} = $returnhash->{'spareid'}->{'primary'};
4350: $spareid{$lonhost}{'default'} = $returnhash->{'spareid'}->{'default'};
4351: }
4352: }
1.145 raeburn 4353: }
4354: }
4355: }
4356: }
4357: }
4358: }
4359: return %spareid;
4360: }
4361:
4362: sub spares_row {
1.261 raeburn 4363: my ($dom,$servers,$spareid,$serverhomes,$altids,$curroffloadnow,$rowtotal) = @_;
1.145 raeburn 4364: my $css_class;
4365: my $numinrow = 4;
4366: my $itemcount = 1;
4367: my $datatable;
1.152 raeburn 4368: my %typetitles = &sparestype_titles();
4369: if ((ref($servers) eq 'HASH') && (ref($spareid) eq 'HASH') && (ref($altids) eq 'HASH')) {
1.145 raeburn 4370: foreach my $server (sort(keys(%{$servers}))) {
1.152 raeburn 4371: my $serverhome = &Apache::lonnet::get_server_homeID($servers->{$server});
4372: my ($othercontrol,$serverdom);
4373: if ($serverhome ne $server) {
4374: $serverdom = &Apache::lonnet::host_domain($serverhome);
4375: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
4376: } else {
4377: $serverdom = &Apache::lonnet::host_domain($server);
4378: if ($serverdom ne $dom) {
4379: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
4380: }
4381: }
4382: next unless (ref($spareid->{$server}) eq 'HASH');
1.261 raeburn 4383: my $checkednow;
4384: if (ref($curroffloadnow) eq 'HASH') {
4385: if ($curroffloadnow->{$server}) {
4386: $checkednow = ' checked="checked"';
4387: }
4388: }
1.145 raeburn 4389: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
4390: $datatable .= '<tr'.$css_class.'>
4391: <td rowspan="2">
1.183 bisitz 4392: <span class="LC_nobreak">'.
4393: &mt('[_1] when busy, offloads to:'
1.261 raeburn 4394: ,'<b>'.$server.'</b>').'</span><br />'.
4395: '<span class="LC_nobreak">'."\n".
4396: '<label><input type="checkbox" name="offloadnow" value="'.$server.'"'.$checkednow.' />'.
4397: ' '.&mt('Switch active users on next access').'</label></span>'.
1.183 bisitz 4398: "\n";
1.145 raeburn 4399: my (%current,%canselect);
1.152 raeburn 4400: my @choices =
4401: &possible_newspares($server,$spareid->{$server},$serverhomes,$altids);
4402: foreach my $type ('primary','default') {
4403: if (ref($spareid->{$server}) eq 'HASH') {
1.145 raeburn 4404: if (ref($spareid->{$server}{$type}) eq 'ARRAY') {
4405: my @spares = @{$spareid->{$server}{$type}};
4406: if (@spares > 0) {
1.152 raeburn 4407: if ($othercontrol) {
4408: $current{$type} = join(', ',@spares);
4409: } else {
4410: $current{$type} .= '<table>';
4411: my $numspares = scalar(@spares);
4412: for (my $i=0; $i<@spares; $i++) {
4413: my $rem = $i%($numinrow);
4414: if ($rem == 0) {
4415: if ($i > 0) {
4416: $current{$type} .= '</tr>';
4417: }
4418: $current{$type} .= '<tr>';
1.145 raeburn 4419: }
1.152 raeburn 4420: $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'".');" /> '.
4421: $spareid->{$server}{$type}[$i].
4422: '</label></td>'."\n";
4423: }
4424: my $rem = @spares%($numinrow);
4425: my $colsleft = $numinrow - $rem;
4426: if ($colsleft > 1 ) {
4427: $current{$type} .= '<td colspan="'.$colsleft.
4428: '" class="LC_left_item">'.
4429: ' </td>';
4430: } elsif ($colsleft == 1) {
4431: $current{$type} .= '<td class="LC_left_item"> </td>'."\n";
1.145 raeburn 4432: }
1.152 raeburn 4433: $current{$type} .= '</tr></table>';
1.150 raeburn 4434: }
1.145 raeburn 4435: }
4436: }
4437: if ($current{$type} eq '') {
4438: $current{$type} = &mt('None specified');
4439: }
1.152 raeburn 4440: if ($othercontrol) {
4441: if ($type eq 'primary') {
4442: $canselect{$type} = $othercontrol;
4443: }
4444: } else {
4445: $canselect{$type} =
4446: &mt('Add new [_1]'.$type.'[_2]:','<i>','</i>').' '.
4447: '<select name="newspare_'.$type.'_'.$server.'" '.
4448: 'id="newspare_'.$type.'_'.$server.'" onchange="checkNewSpares('."'$server','$type'".');">'."\n".
4449: '<option value="" selected ="selected">'.&mt('Select').'</option>'."\n";
4450: if (@choices > 0) {
4451: foreach my $lonhost (@choices) {
4452: $canselect{$type} .= '<option value="'.$lonhost.'">'.$lonhost.'</option>'."\n";
4453: }
4454: }
4455: $canselect{$type} .= '</select>'."\n";
4456: }
4457: } else {
4458: $current{$type} = &mt('Could not be determined');
4459: if ($type eq 'primary') {
4460: $canselect{$type} = $othercontrol;
4461: }
1.145 raeburn 4462: }
1.152 raeburn 4463: if ($type eq 'default') {
4464: $datatable .= '<tr'.$css_class.'>';
4465: }
4466: $datatable .= '<td><i>'.$typetitles{$type}.'</i></td>'."\n".
4467: '<td>'.$current{$type}.'</td>'."\n".
4468: '<td>'.$canselect{$type}.'</td></tr>'."\n";
1.145 raeburn 4469: }
4470: $itemcount ++;
4471: }
4472: }
4473: $$rowtotal += $itemcount;
4474: return $datatable;
4475: }
4476:
1.152 raeburn 4477: sub possible_newspares {
4478: my ($server,$currspares,$serverhomes,$altids) = @_;
4479: my $serverhostname = &Apache::lonnet::hostname($server);
4480: my %excluded;
4481: if ($serverhostname ne '') {
4482: %excluded = (
4483: $serverhostname => 1,
4484: );
4485: }
4486: if (ref($currspares) eq 'HASH') {
4487: foreach my $type (keys(%{$currspares})) {
4488: if (ref($currspares->{$type}) eq 'ARRAY') {
4489: if (@{$currspares->{$type}} > 0) {
4490: foreach my $curr (@{$currspares->{$type}}) {
4491: my $hostname = &Apache::lonnet::hostname($curr);
4492: $excluded{$hostname} = 1;
4493: }
4494: }
4495: }
4496: }
4497: }
4498: my @choices;
4499: if ((ref($serverhomes) eq 'HASH') && (ref($altids) eq 'HASH')) {
4500: if (keys(%{$serverhomes}) > 1) {
4501: foreach my $name (sort(keys(%{$serverhomes}))) {
4502: unless ($excluded{$name}) {
4503: if (exists($altids->{$serverhomes->{$name}})) {
4504: push(@choices,$altids->{$serverhomes->{$name}});
4505: } else {
4506: push(@choices,$serverhomes->{$name});
1.145 raeburn 4507: }
4508: }
4509: }
4510: }
4511: }
1.152 raeburn 4512: return sort(@choices);
1.145 raeburn 4513: }
4514:
1.150 raeburn 4515: sub print_loadbalancing {
4516: my ($dom,$settings,$rowtotal) = @_;
4517: my $primary_id = &Apache::lonnet::domain($dom,'primary');
4518: my $intdom = &Apache::lonnet::internet_dom($primary_id);
4519: my $numinrow = 1;
4520: my $datatable;
4521: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.171 raeburn 4522: my (%currbalancer,%currtargets,%currrules,%existing);
4523: if (ref($settings) eq 'HASH') {
4524: %existing = %{$settings};
4525: }
4526: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
4527: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
4528: \%currtargets,\%currrules);
1.150 raeburn 4529: } else {
4530: return;
4531: }
4532: my ($othertitle,$usertypes,$types) =
4533: &Apache::loncommon::sorted_inst_types($dom);
1.209 raeburn 4534: my $rownum = 8;
1.150 raeburn 4535: if (ref($types) eq 'ARRAY') {
4536: $rownum += scalar(@{$types});
4537: }
1.171 raeburn 4538: my @css_class = ('LC_odd_row','LC_even_row');
4539: my $balnum = 0;
4540: my $islast;
4541: my (@toshow,$disabledtext);
4542: if (keys(%currbalancer) > 0) {
4543: @toshow = sort(keys(%currbalancer));
4544: if (scalar(@toshow) < scalar(keys(%servers)) + 1) {
4545: push(@toshow,'');
4546: }
4547: } else {
4548: @toshow = ('');
4549: $disabledtext = &mt('No existing load balancer');
4550: }
4551: foreach my $lonhost (@toshow) {
4552: if ($balnum == scalar(@toshow)-1) {
4553: $islast = 1;
4554: } else {
4555: $islast = 0;
4556: }
4557: my $cssidx = $balnum%2;
4558: my $targets_div_style = 'display: none';
4559: my $disabled_div_style = 'display: block';
4560: my $homedom_div_style = 'display: none';
4561: $datatable .= '<tr class="'.$css_class[$cssidx].'">'.
4562: '<td rowspan="'.$rownum.'" valign="top">'.
4563: '<p>';
4564: if ($lonhost eq '') {
1.210 raeburn 4565: $datatable .= '<span class="LC_nobreak">';
1.171 raeburn 4566: if (keys(%currbalancer) > 0) {
4567: $datatable .= &mt('Add balancer:');
4568: } else {
4569: $datatable .= &mt('Enable balancer:');
4570: }
4571: $datatable .= ' '.
4572: '<select name="loadbalancing_lonhost_'.$balnum.'"'.
4573: ' id="loadbalancing_lonhost_'.$balnum.'"'.
4574: ' onchange="toggleTargets('."'$balnum'".');">'."\n".
4575: '<option value="" selected="selected">'.&mt('None').
4576: '</option>'."\n";
4577: foreach my $server (sort(keys(%servers))) {
4578: next if ($currbalancer{$server});
4579: $datatable .= '<option value="'.$server.'">'.$server.'</option>'."\n";
4580: }
1.210 raeburn 4581: $datatable .=
1.171 raeburn 4582: '</select>'."\n".
4583: '<input type="hidden" name="loadbalancing_prevlonhost_'.$balnum.'" id="loadbalancing_prevlonhost_'.$balnum.'" value="" /> </span>'."\n";
4584: } else {
4585: $datatable .= '<i>'.$lonhost.'</i><br /><span class="LC_nobreak">'.
4586: '<label><input type="checkbox" name="loadbalancing_delete" value="'.$balnum.'" id="loadbalancing_delete_'.$balnum.'" onclick="javascript:balancerDeleteChange('."'$balnum'".');" /> '.
4587: &mt('Stop balancing').'</label>'.
4588: '<input type="hidden" name="loadbalancing_lonhost_'.$balnum.'" value="'.$lonhost.'" id="loadbalancing_lonhost_'.$balnum.'" /></span>';
4589: $targets_div_style = 'display: block';
4590: $disabled_div_style = 'display: none';
4591: if ($dom eq &Apache::lonnet::host_domain($lonhost)) {
4592: $homedom_div_style = 'display: block';
4593: }
4594: }
4595: $datatable .= '</p></td><td rowspan="'.$rownum.'" valign="top">'.
4596: '<div id="loadbalancing_disabled_'.$balnum.'" style="'.
4597: $disabled_div_style.'">'.$disabledtext.'</div>'."\n".
4598: '<div id="loadbalancing_targets_'.$balnum.'" style="'.$targets_div_style.'">'.&mt('Offloads to:').'<br />';
4599: my ($numspares,@spares) = &count_servers($lonhost,%servers);
4600: my @sparestypes = ('primary','default');
4601: my %typetitles = &sparestype_titles();
4602: foreach my $sparetype (@sparestypes) {
4603: my $targettable;
4604: for (my $i=0; $i<$numspares; $i++) {
4605: my $checked;
4606: if (ref($currtargets{$lonhost}) eq 'HASH') {
4607: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
4608: if (grep(/^\Q$spares[$i]\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
4609: $checked = ' checked="checked"';
4610: }
4611: }
4612: }
4613: my ($chkboxval,$disabled);
4614: if (($lonhost ne '') && (exists($servers{$lonhost}))) {
4615: $chkboxval = $spares[$i];
4616: }
4617: if (exists($currbalancer{$spares[$i]})) {
4618: $disabled = ' disabled="disabled"';
4619: }
1.210 raeburn 4620: $targettable .=
1.253 raeburn 4621: '<td><span class="LC_nobreak"><label>'.
4622: '<input type="checkbox" name="loadbalancing_target_'.$balnum.'_'.$sparetype.'"'.
1.171 raeburn 4623: $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 4624: '</span></label></span></td>';
1.171 raeburn 4625: my $rem = $i%($numinrow);
4626: if ($rem == 0) {
4627: if (($i > 0) && ($i < $numspares-1)) {
4628: $targettable .= '</tr>';
4629: }
4630: if ($i < $numspares-1) {
4631: $targettable .= '<tr>';
1.150 raeburn 4632: }
4633: }
4634: }
1.171 raeburn 4635: if ($targettable ne '') {
4636: my $rem = $numspares%($numinrow);
4637: my $colsleft = $numinrow - $rem;
4638: if ($colsleft > 1 ) {
4639: $targettable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
4640: ' </td>';
4641: } elsif ($colsleft == 1) {
4642: $targettable .= '<td class="LC_left_item"> </td>';
4643: }
4644: $datatable .= '<i>'.$typetitles{$sparetype}.'</i><br />'.
4645: '<table><tr>'.$targettable.'</tr></table><br />';
4646: }
4647: }
4648: $datatable .= '</div></td></tr>'.
4649: &loadbalancing_rules($dom,$intdom,$currrules{$lonhost},
4650: $othertitle,$usertypes,$types,\%servers,
4651: \%currbalancer,$lonhost,
4652: $targets_div_style,$homedom_div_style,
4653: $css_class[$cssidx],$balnum,$islast);
4654: $$rowtotal += $rownum;
4655: $balnum ++;
4656: }
4657: $datatable .= '<input type="hidden" name="loadbalancing_total" id="loadbalancing_total" value="'.$balnum.'" />';
4658: return $datatable;
4659: }
4660:
4661: sub get_loadbalancers_config {
4662: my ($servers,$existing,$currbalancer,$currtargets,$currrules) = @_;
4663: return unless ((ref($servers) eq 'HASH') &&
4664: (ref($existing) eq 'HASH') && (ref($currbalancer) eq 'HASH') &&
4665: (ref($currtargets) eq 'HASH') && (ref($currrules) eq 'HASH'));
4666: if (keys(%{$existing}) > 0) {
4667: my $oldlonhost;
4668: foreach my $key (sort(keys(%{$existing}))) {
4669: if ($key eq 'lonhost') {
4670: $oldlonhost = $existing->{'lonhost'};
4671: $currbalancer->{$oldlonhost} = 1;
4672: } elsif ($key eq 'targets') {
4673: if ($oldlonhost) {
4674: $currtargets->{$oldlonhost} = $existing->{'targets'};
4675: }
4676: } elsif ($key eq 'rules') {
4677: if ($oldlonhost) {
4678: $currrules->{$oldlonhost} = $existing->{'rules'};
4679: }
4680: } elsif (ref($existing->{$key}) eq 'HASH') {
4681: $currbalancer->{$key} = 1;
4682: $currtargets->{$key} = $existing->{$key}{'targets'};
4683: $currrules->{$key} = $existing->{$key}{'rules'};
1.150 raeburn 4684: }
4685: }
1.171 raeburn 4686: } else {
4687: my ($balancerref,$targetsref) =
4688: &Apache::lonnet::get_lonbalancer_config($servers);
4689: if ((ref($balancerref) eq 'HASH') && (ref($targetsref) eq 'HASH')) {
4690: foreach my $server (sort(keys(%{$balancerref}))) {
4691: $currbalancer->{$server} = 1;
4692: $currtargets->{$server} = $targetsref->{$server};
1.150 raeburn 4693: }
4694: }
4695: }
1.171 raeburn 4696: return;
1.150 raeburn 4697: }
4698:
4699: sub loadbalancing_rules {
4700: my ($dom,$intdom,$currrules,$othertitle,$usertypes,$types,$servers,
1.171 raeburn 4701: $currbalancer,$lonhost,$targets_div_style,$homedom_div_style,
4702: $css_class,$balnum,$islast) = @_;
1.150 raeburn 4703: my $output;
1.171 raeburn 4704: my $num = 0;
1.210 raeburn 4705: my ($alltypes,$othertypes,$titles) =
1.150 raeburn 4706: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
4707: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
4708: foreach my $type (@{$alltypes}) {
1.171 raeburn 4709: $num ++;
1.150 raeburn 4710: my $current;
4711: if (ref($currrules) eq 'HASH') {
4712: $current = $currrules->{$type};
4713: }
1.253 raeburn 4714: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.171 raeburn 4715: if ($dom ne &Apache::lonnet::host_domain($lonhost)) {
1.150 raeburn 4716: $current = '';
4717: }
4718: }
4719: $output .= &loadbalance_rule_row($type,$titles->{$type},$current,
1.171 raeburn 4720: $servers,$currbalancer,$lonhost,$dom,
4721: $targets_div_style,$homedom_div_style,
4722: $css_class,$balnum,$num,$islast);
1.150 raeburn 4723: }
4724: }
4725: return $output;
4726: }
4727:
4728: sub loadbalancing_titles {
4729: my ($dom,$intdom,$usertypes,$types) = @_;
4730: my %othertypes = (
4731: '_LC_adv' => &mt('Advanced users from [_1]',$dom),
4732: '_LC_author' => &mt('Users from [_1] with author role',$dom),
4733: '_LC_internetdom' => &mt('Users not from [_1], but from [_2]',$dom,$intdom),
4734: '_LC_external' => &mt('Users not from [_1]',$intdom),
1.209 raeburn 4735: '_LC_ipchangesso' => &mt('SSO users from [_1], with IP mismatch',$dom),
4736: '_LC_ipchange' => &mt('Non-SSO users with IP mismatch'),
1.150 raeburn 4737: );
1.209 raeburn 4738: my @alltypes = ('_LC_adv','_LC_author','_LC_internetdom','_LC_external','_LC_ipchangesso','_LC_ipchange');
1.150 raeburn 4739: if (ref($types) eq 'ARRAY') {
4740: unshift(@alltypes,@{$types},'default');
4741: }
4742: my %titles;
4743: foreach my $type (@alltypes) {
4744: if ($type =~ /^_LC_/) {
4745: $titles{$type} = $othertypes{$type};
4746: } elsif ($type eq 'default') {
4747: $titles{$type} = &mt('All users from [_1]',$dom);
4748: if (ref($types) eq 'ARRAY') {
4749: if (@{$types} > 0) {
4750: $titles{$type} = &mt('Other users from [_1]',$dom);
4751: }
4752: }
4753: } elsif (ref($usertypes) eq 'HASH') {
4754: $titles{$type} = $usertypes->{$type};
4755: }
4756: }
4757: return (\@alltypes,\%othertypes,\%titles);
4758: }
4759:
4760: sub loadbalance_rule_row {
1.171 raeburn 4761: my ($type,$title,$current,$servers,$currbalancer,$lonhost,$dom,
4762: $targets_div_style,$homedom_div_style,$css_class,$balnum,$num,$islast) = @_;
1.209 raeburn 4763: my @rulenames;
1.150 raeburn 4764: my %ruletitles = &offloadtype_text();
1.209 raeburn 4765: if (($type eq '_LC_ipchangesso') || ($type eq '_LC_ipchange')) {
1.254 raeburn 4766: @rulenames = ('balancer','offloadedto','specific');
1.150 raeburn 4767: } else {
1.209 raeburn 4768: @rulenames = ('default','homeserver');
4769: if ($type eq '_LC_external') {
4770: push(@rulenames,'externalbalancer');
4771: } else {
4772: push(@rulenames,'specific');
4773: }
4774: push(@rulenames,'none');
1.150 raeburn 4775: }
4776: my $style = $targets_div_style;
1.253 raeburn 4777: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.150 raeburn 4778: $style = $homedom_div_style;
4779: }
1.171 raeburn 4780: my $space;
4781: if ($islast && $num == 1) {
4782: $space = '<div display="inline-block"> </div>';
4783: }
1.210 raeburn 4784: my $output =
1.171 raeburn 4785: '<tr class="'.$css_class.'" id="balanceruletr_'.$balnum.'_'.$num.'"><td valign="top">'.$space.
4786: '<div id="balanceruletitle_'.$balnum.'_'.$type.'" style="'.$style.'">'.$title.'</div></td>'."\n".
4787: '<td valaign="top">'.$space.
4788: '<div id="balancerule_'.$balnum.'_'.$type.'" style="'.$style.'">'."\n";
1.150 raeburn 4789: for (my $i=0; $i<@rulenames; $i++) {
4790: my $rule = $rulenames[$i];
4791: my ($checked,$extra);
4792: if ($rulenames[$i] eq 'default') {
4793: $rule = '';
4794: }
4795: if ($rulenames[$i] eq 'specific') {
4796: if (ref($servers) eq 'HASH') {
4797: my $default;
4798: if (($current ne '') && (exists($servers->{$current}))) {
4799: $checked = ' checked="checked"';
4800: }
4801: unless ($checked) {
4802: $default = ' selected="selected"';
4803: }
1.210 raeburn 4804: $extra =
1.171 raeburn 4805: ': <select name="loadbalancing_singleserver_'.$balnum.'_'.$type.
4806: '" id="loadbalancing_singleserver_'.$balnum.'_'.$type.
4807: '" onchange="singleServerToggle('."'$balnum','$type'".')">'."\n".
4808: '<option value=""'.$default.'></option>'."\n";
4809: foreach my $server (sort(keys(%{$servers}))) {
4810: if (ref($currbalancer) eq 'HASH') {
4811: next if (exists($currbalancer->{$server}));
4812: }
1.150 raeburn 4813: my $selected;
1.171 raeburn 4814: if ($server eq $current) {
1.150 raeburn 4815: $selected = ' selected="selected"';
4816: }
1.171 raeburn 4817: $extra .= '<option value="'.$server.'"'.$selected.'>'.$server.'</option>';
1.150 raeburn 4818: }
4819: $extra .= '</select>';
4820: }
4821: } elsif ($rule eq $current) {
4822: $checked = ' checked="checked"';
4823: }
4824: $output .= '<span class="LC_nobreak"><label>'.
1.171 raeburn 4825: '<input type="radio" name="loadbalancing_rules_'.$balnum.'_'.$type.
4826: '" id="loadbalancing_rules_'.$balnum.'_'.$type.'_'.$i.'" value="'.
4827: $rule.'" onclick="balanceruleChange('."this.form,'$balnum','$type'".
1.254 raeburn 4828: ')"'.$checked.' /> ';
4829: if (($rulenames[$i] eq 'specific') && ($type =~ /^_LC_ipchange/)) {
4830: $output .= $ruletitles{'particular'};
4831: } else {
4832: $output .= $ruletitles{$rulenames[$i]};
4833: }
4834: $output .= '</label>'.$extra.'</span><br />'."\n";
1.150 raeburn 4835: }
4836: $output .= '</div></td></tr>'."\n";
4837: return $output;
4838: }
4839:
4840: sub offloadtype_text {
4841: my %ruletitles = &Apache::lonlocal::texthash (
4842: 'default' => 'Offloads to default destinations',
4843: 'homeserver' => "Offloads to user's home server",
4844: 'externalbalancer' => "Offloads to Load Balancer in user's domain",
4845: 'specific' => 'Offloads to specific server',
1.161 raeburn 4846: 'none' => 'No offload',
1.209 raeburn 4847: 'balancer' => 'Session hosted on Load Balancer, after re-authentication',
4848: 'offloadedto' => 'Session hosted on offload server, after re-authentication',
1.254 raeburn 4849: 'particular' => 'Session hosted (after re-auth) on server:',
1.150 raeburn 4850: );
4851: return %ruletitles;
4852: }
4853:
4854: sub sparestype_titles {
4855: my %typestitles = &Apache::lonlocal::texthash (
4856: 'primary' => 'primary',
4857: 'default' => 'default',
4858: );
4859: return %typestitles;
4860: }
4861:
1.28 raeburn 4862: sub contact_titles {
4863: my %titles = &Apache::lonlocal::texthash (
4864: 'supportemail' => 'Support E-mail address',
1.69 raeburn 4865: 'adminemail' => 'Default Server Admin E-mail address',
1.28 raeburn 4866: 'errormail' => 'Error reports to be e-mailed to',
4867: 'packagesmail' => 'Package update alerts to be e-mailed to',
1.89 raeburn 4868: 'helpdeskmail' => 'Helpdesk requests to be e-mailed to',
4869: 'lonstatusmail' => 'E-mail from nightly status check (warnings/errors)',
1.102 raeburn 4870: 'requestsmail' => 'E-mail from course requests requiring approval',
1.190 raeburn 4871: 'updatesmail' => 'E-mail from nightly check of LON-CAPA module integrity/updates',
1.203 raeburn 4872: 'idconflictsmail' => 'E-mail from bi-nightly check for multiple users sharing same student/employee ID',
1.28 raeburn 4873: );
4874: my %short_titles = &Apache::lonlocal::texthash (
4875: adminemail => 'Admin E-mail address',
4876: supportemail => 'Support E-mail',
4877: );
4878: return (\%titles,\%short_titles);
4879: }
4880:
1.72 raeburn 4881: sub tool_titles {
4882: my %titles = &Apache::lonlocal::texthash (
1.162 raeburn 4883: aboutme => 'Personal web page',
1.86 raeburn 4884: blog => 'Blog',
1.162 raeburn 4885: webdav => 'WebDAV',
1.86 raeburn 4886: portfolio => 'Portfolio',
1.88 bisitz 4887: official => 'Official courses (with institutional codes)',
4888: unofficial => 'Unofficial courses',
1.98 raeburn 4889: community => 'Communities',
1.216 raeburn 4890: textbook => 'Textbook courses',
1.271 raeburn 4891: placement => 'Placement tests',
1.86 raeburn 4892: );
1.72 raeburn 4893: return %titles;
4894: }
4895:
1.101 raeburn 4896: sub courserequest_titles {
4897: my %titles = &Apache::lonlocal::texthash (
4898: official => 'Official',
4899: unofficial => 'Unofficial',
4900: community => 'Communities',
1.216 raeburn 4901: textbook => 'Textbook',
1.271 raeburn 4902: placement => 'Placement tests',
1.101 raeburn 4903: norequest => 'Not allowed',
1.104 raeburn 4904: approval => 'Approval by Dom. Coord.',
1.101 raeburn 4905: validate => 'With validation',
4906: autolimit => 'Numerical limit',
1.103 raeburn 4907: unlimited => '(blank for unlimited)',
1.101 raeburn 4908: );
4909: return %titles;
4910: }
4911:
1.163 raeburn 4912: sub authorrequest_titles {
4913: my %titles = &Apache::lonlocal::texthash (
4914: norequest => 'Not allowed',
4915: approval => 'Approval by Dom. Coord.',
4916: automatic => 'Automatic approval',
4917: );
4918: return %titles;
1.210 raeburn 4919: }
1.163 raeburn 4920:
1.101 raeburn 4921: sub courserequest_conditions {
4922: my %conditions = &Apache::lonlocal::texthash (
1.104 raeburn 4923: approval => '(Processing of request subject to approval by Domain Coordinator).',
1.193 bisitz 4924: validate => '(Processing of request subject to institutional validation).',
1.101 raeburn 4925: );
4926: return %conditions;
4927: }
4928:
4929:
1.27 raeburn 4930: sub print_usercreation {
1.30 raeburn 4931: my ($position,$dom,$settings,$rowtotal) = @_;
1.27 raeburn 4932: my $numinrow = 4;
1.28 raeburn 4933: my $datatable;
4934: if ($position eq 'top') {
1.30 raeburn 4935: $$rowtotal ++;
1.34 raeburn 4936: my $rowcount = 0;
1.32 raeburn 4937: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username');
1.28 raeburn 4938: if (ref($rules) eq 'HASH') {
4939: if (keys(%{$rules}) > 0) {
1.32 raeburn 4940: $datatable .= &user_formats_row('username',$settings,$rules,
4941: $ruleorder,$numinrow,$rowcount);
1.30 raeburn 4942: $$rowtotal ++;
1.32 raeburn 4943: $rowcount ++;
4944: }
4945: }
4946: my ($idrules,$idruleorder) = &Apache::lonnet::inst_userrules($dom,'id');
4947: if (ref($idrules) eq 'HASH') {
4948: if (keys(%{$idrules}) > 0) {
4949: $datatable .= &user_formats_row('id',$settings,$idrules,
4950: $idruleorder,$numinrow,$rowcount);
4951: $$rowtotal ++;
4952: $rowcount ++;
1.28 raeburn 4953: }
4954: }
1.39 raeburn 4955: if ($rowcount == 0) {
4956: $datatable .= '<tr><td colspan="2">'.&mt('No format rules have been defined for usernames or IDs in this domain.').'</td></tr>';
4957: $$rowtotal ++;
4958: $rowcount ++;
4959: }
1.34 raeburn 4960: } elsif ($position eq 'middle') {
1.224 raeburn 4961: my @creators = ('author','course','requestcrs');
1.37 raeburn 4962: my ($rules,$ruleorder) =
4963: &Apache::lonnet::inst_userrules($dom,'username');
1.34 raeburn 4964: my %lt = &usercreation_types();
4965: my %checked;
4966: if (ref($settings) eq 'HASH') {
4967: if (ref($settings->{'cancreate'}) eq 'HASH') {
4968: foreach my $item (@creators) {
4969: $checked{$item} = $settings->{'cancreate'}{$item};
4970: }
4971: } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {
4972: foreach my $item (@creators) {
4973: if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {
4974: $checked{$item} = 'none';
4975: }
4976: }
4977: }
4978: }
4979: my $rownum = 0;
4980: foreach my $item (@creators) {
4981: $rownum ++;
1.224 raeburn 4982: if ($checked{$item} eq '') {
4983: $checked{$item} = 'any';
1.34 raeburn 4984: }
4985: my $css_class;
4986: if ($rownum%2) {
4987: $css_class = '';
4988: } else {
4989: $css_class = ' class="LC_odd_row" ';
4990: }
4991: $datatable .= '<tr'.$css_class.'>'.
4992: '<td><span class="LC_nobreak">'.$lt{$item}.
4993: '</span></td><td align="right">';
1.224 raeburn 4994: my @options = ('any');
4995: if (ref($rules) eq 'HASH') {
4996: if (keys(%{$rules}) > 0) {
4997: push(@options,('official','unofficial'));
1.37 raeburn 4998: }
4999: }
1.224 raeburn 5000: push(@options,'none');
1.37 raeburn 5001: foreach my $option (@options) {
1.50 raeburn 5002: my $type = 'radio';
1.34 raeburn 5003: my $check = ' ';
1.224 raeburn 5004: if ($checked{$item} eq $option) {
5005: $check = ' checked="checked" ';
1.34 raeburn 5006: }
5007: $datatable .= '<span class="LC_nobreak"><label>'.
1.50 raeburn 5008: '<input type="'.$type.'" name="can_createuser_'.
1.34 raeburn 5009: $item.'" value="'.$option.'"'.$check.'/> '.
5010: $lt{$option}.'</label> </span>';
5011: }
5012: $datatable .= '</td></tr>';
5013: }
1.28 raeburn 5014: } else {
5015: my @contexts = ('author','course','domain');
5016: my @authtypes = ('int','krb4','krb5','loc');
5017: my %checked;
5018: if (ref($settings) eq 'HASH') {
5019: if (ref($settings->{'authtypes'}) eq 'HASH') {
5020: foreach my $item (@contexts) {
5021: if (ref($settings->{'authtypes'}{$item}) eq 'HASH') {
5022: foreach my $auth (@authtypes) {
5023: if ($settings->{'authtypes'}{$item}{$auth}) {
5024: $checked{$item}{$auth} = ' checked="checked" ';
5025: }
5026: }
5027: }
5028: }
1.27 raeburn 5029: }
1.35 raeburn 5030: } else {
5031: foreach my $item (@contexts) {
1.36 raeburn 5032: foreach my $auth (@authtypes) {
1.35 raeburn 5033: $checked{$item}{$auth} = ' checked="checked" ';
5034: }
5035: }
1.27 raeburn 5036: }
1.28 raeburn 5037: my %title = &context_names();
5038: my %authname = &authtype_names();
5039: my $rownum = 0;
5040: my $css_class;
5041: foreach my $item (@contexts) {
5042: if ($rownum%2) {
5043: $css_class = '';
5044: } else {
5045: $css_class = ' class="LC_odd_row" ';
5046: }
1.30 raeburn 5047: $datatable .= '<tr'.$css_class.'>'.
1.28 raeburn 5048: '<td>'.$title{$item}.
5049: '</td><td class="LC_left_item">'.
5050: '<span class="LC_nobreak">';
5051: foreach my $auth (@authtypes) {
5052: $datatable .= '<label>'.
5053: '<input type="checkbox" name="'.$item.'_auth" '.
5054: $checked{$item}{$auth}.' value="'.$auth.'" />'.
5055: $authname{$auth}.'</label> ';
5056: }
5057: $datatable .= '</span></td></tr>';
5058: $rownum ++;
1.27 raeburn 5059: }
1.30 raeburn 5060: $$rowtotal += $rownum;
1.27 raeburn 5061: }
5062: return $datatable;
5063: }
5064:
1.224 raeburn 5065: sub print_selfcreation {
5066: my ($position,$dom,$settings,$rowtotal) = @_;
1.236 raeburn 5067: my (@selfcreate,$createsettings,$processing,$datatable);
1.224 raeburn 5068: if (ref($settings) eq 'HASH') {
5069: if (ref($settings->{'cancreate'}) eq 'HASH') {
5070: $createsettings = $settings->{'cancreate'};
1.236 raeburn 5071: if (ref($createsettings) eq 'HASH') {
5072: if (ref($createsettings->{'selfcreate'}) eq 'ARRAY') {
5073: @selfcreate = @{$createsettings->{'selfcreate'}};
5074: } elsif ($createsettings->{'selfcreate'} ne '') {
5075: if ($settings->{'cancreate'}{'selfcreate'} eq 'any') {
5076: @selfcreate = ('email','login','sso');
5077: } elsif ($createsettings->{'selfcreate'} ne 'none') {
5078: @selfcreate = ($createsettings->{'selfcreate'});
5079: }
5080: }
5081: if (ref($createsettings->{'selfcreateprocessing'}) eq 'HASH') {
5082: $processing = $createsettings->{'selfcreateprocessing'};
1.224 raeburn 5083: }
5084: }
5085: }
5086: }
5087: my %radiohash;
5088: my $numinrow = 4;
5089: map { $radiohash{'cancreate_'.$_} = 1; } @selfcreate;
5090: if ($position eq 'top') {
5091: my %choices = &Apache::lonlocal::texthash (
5092: cancreate_login => 'Institutional Login',
5093: cancreate_sso => 'Institutional Single Sign On',
5094: );
5095: my @toggles = sort(keys(%choices));
5096: my %defaultchecked = (
5097: 'cancreate_login' => 'off',
5098: 'cancreate_sso' => 'off',
5099: );
1.228 raeburn 5100: my ($onclick,$itemcount);
1.224 raeburn 5101: ($datatable,$itemcount) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
5102: \%choices,$itemcount,$onclick);
1.228 raeburn 5103: $$rowtotal += $itemcount;
5104:
1.224 raeburn 5105: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
5106:
5107: if (ref($usertypes) eq 'HASH') {
5108: if (keys(%{$usertypes}) > 0) {
5109: $datatable .= &insttypes_row($createsettings,$types,$usertypes,
5110: $dom,$numinrow,$othertitle,
1.228 raeburn 5111: 'statustocreate',$$rowtotal);
1.224 raeburn 5112: $$rowtotal ++;
5113: }
5114: }
1.240 raeburn 5115: my @fields = ('lastname','firstname','middlename','permanentemail','id','inststatus');
5116: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
5117: $fieldtitles{'inststatus'} = &mt('Institutional status');
5118: my $rem;
5119: my $numperrow = 2;
5120: my $css_class = $$rowtotal%2?' class="LC_odd_row"':'';
5121: $datatable .= '<tr'.$css_class.'>'.
1.241 raeburn 5122: '<td class="LC_left_item">'.&mt('Mapping of Shibboleth environment variable names to user data fields (SSO auth)').'</td>'.
1.240 raeburn 5123: '<td class="LC_left_item">'."\n".
5124: '<table><tr><td>'."\n";
5125: for (my $i=0; $i<@fields; $i++) {
5126: $rem = $i%($numperrow);
5127: if ($rem == 0) {
5128: if ($i > 0) {
5129: $datatable .= '</tr>';
5130: }
5131: $datatable .= '<tr>';
5132: }
5133: my $currval;
1.248 raeburn 5134: if (ref($createsettings) eq 'HASH') {
5135: if (ref($createsettings->{'shibenv'}) eq 'HASH') {
5136: $currval = $createsettings->{'shibenv'}{$fields[$i]};
5137: }
1.240 raeburn 5138: }
5139: $datatable .= '<td class="LC_left_item">'.
5140: '<span class="LC_nobreak">'.
5141: '<input type="text" name="shibenv_'.$fields[$i].'" '.
5142: 'value="'.$currval.'" size="10" /> '.
5143: $fieldtitles{$fields[$i]}.'</span></td>';
5144: }
5145: my $colsleft = $numperrow - $rem;
5146: if ($colsleft > 1 ) {
5147: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
5148: ' </td>';
5149: } elsif ($colsleft == 1) {
5150: $datatable .= '<td class="LC_left_item"> </td>';
5151: }
5152: $datatable .= '</tr></table></td></tr>';
5153: $$rowtotal ++;
1.224 raeburn 5154: } elsif ($position eq 'middle') {
5155: my %domconf = &Apache::lonnet::get_dom('configuration',['usermodification'],$dom);
5156: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
5157: $usertypes->{'default'} = $othertitle;
5158: if (ref($types) eq 'ARRAY') {
5159: push(@{$types},'default');
5160: $usertypes->{'default'} = $othertitle;
5161: foreach my $status (@{$types}) {
5162: $datatable .= &modifiable_userdata_row('selfcreate',$status,$domconf{'usermodification'},
1.228 raeburn 5163: $numinrow,$$rowtotal,$usertypes);
1.240 raeburn 5164: $$rowtotal ++;
1.224 raeburn 5165: }
5166: }
5167: } else {
1.236 raeburn 5168: my %choices = &Apache::lonlocal::texthash (
5169: cancreate_email => 'E-mail address as username',
5170: );
5171: my @toggles = sort(keys(%choices));
5172: my %defaultchecked = (
5173: 'cancreate_email' => 'off',
5174: );
5175: my $itemcount = 0;
5176: my $display = 'none';
5177: if (grep(/^\Qemail\E$/,@selfcreate)) {
5178: $display = 'block';
5179: }
5180: my $onclick = "toggleDisplay(this.form,'emailoptions');";
5181: my $additional = '<div id="emailoptions" style="display: '.$display.'">';
5182: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
5183: my $usertypes = {};
5184: my $order = [];
5185: if ((ref($domdefaults{'inststatustypes'}) eq 'HASH') && (ref($domdefaults{'inststatusguest'}) eq 'ARRAY')) {
5186: $usertypes = $domdefaults{'inststatustypes'};
5187: $order = $domdefaults{'inststatusguest'};
5188: }
5189: if (ref($order) eq 'ARRAY') {
5190: push(@{$order},'default');
5191: if (@{$order} > 1) {
5192: $usertypes->{'default'} = &mt('Other users');
5193: $additional .= '<table><tr>';
5194: foreach my $status (@{$order}) {
5195: $additional .= '<th>'.$usertypes->{$status}.'</th>';
5196: }
5197: $additional .= '</tr><tr>';
5198: foreach my $status (@{$order}) {
5199: $additional .= '<td>'.&email_as_username($rowtotal,$processing,$status).'</td>';
1.224 raeburn 5200: }
1.236 raeburn 5201: $additional .= '</tr></table>';
1.224 raeburn 5202: } else {
1.236 raeburn 5203: $usertypes->{'default'} = &mt('All users');
5204: $additional .= &email_as_username($rowtotal,$processing);
1.224 raeburn 5205: }
5206: }
1.236 raeburn 5207: $additional .= '</div>'."\n";
5208:
5209: ($datatable,$itemcount) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
1.240 raeburn 5210: \%choices,$$rowtotal,$onclick,$additional);
5211: $$rowtotal ++;
1.236 raeburn 5212: $datatable .= &print_requestmail($dom,'selfcreation',$createsettings,$rowtotal);
1.228 raeburn 5213: $$rowtotal ++;
1.224 raeburn 5214: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
1.228 raeburn 5215: $numinrow = 1;
1.236 raeburn 5216: if (ref($order) eq 'ARRAY') {
5217: foreach my $status (@{$order}) {
1.228 raeburn 5218: $datatable .= &modifiable_userdata_row('cancreate','emailusername_'.$status,$settings,
5219: $numinrow,$$rowtotal,$usertypes,$infofields,$infotitles);
5220: $$rowtotal ++;
5221: }
5222: }
1.224 raeburn 5223: my ($emailrules,$emailruleorder) =
5224: &Apache::lonnet::inst_userrules($dom,'email');
5225: if (ref($emailrules) eq 'HASH') {
5226: if (keys(%{$emailrules}) > 0) {
5227: $datatable .= &user_formats_row('email',$settings,$emailrules,
1.228 raeburn 5228: $emailruleorder,$numinrow,$$rowtotal);
1.224 raeburn 5229: $$rowtotal ++;
5230: }
5231: }
1.228 raeburn 5232: $datatable .= &captcha_choice('cancreate',$createsettings,$$rowtotal);
1.224 raeburn 5233: }
5234: return $datatable;
5235: }
5236:
1.236 raeburn 5237: sub email_as_username {
5238: my ($rowtotal,$processing,$type) = @_;
5239: my %choices =
5240: &Apache::lonlocal::texthash (
5241: automatic => 'Automatic approval',
5242: approval => 'Queued for approval',
5243: );
5244: my $output;
5245: foreach my $option ('automatic','approval') {
5246: my $checked;
5247: if (ref($processing) eq 'HASH') {
5248: if ($type eq '') {
5249: if (!exists($processing->{'default'})) {
5250: if ($option eq 'automatic') {
5251: $checked = ' checked="checked"';
5252: }
5253: } else {
5254: if ($processing->{'default'} eq $option) {
5255: $checked = ' checked="checked"';
5256: }
5257: }
5258: } else {
5259: if (!exists($processing->{$type})) {
5260: if ($option eq 'automatic') {
5261: $checked = ' checked="checked"';
5262: }
5263: } else {
5264: if ($processing->{$type} eq $option) {
5265: $checked = ' checked="checked"';
5266: }
5267: }
5268: }
5269: } elsif ($option eq 'automatic') {
5270: $checked = ' checked="checked"';
5271: }
5272: my $name = 'cancreate_emailprocess';
5273: if (($type ne '') && ($type ne 'default')) {
5274: $name .= '_'.$type;
5275: }
5276: $output .= '<span class="LC_nobreak"><label>'.
5277: '<input type="radio" name="'.$name.'"'.
5278: $checked.' value="'.$option.'" />'.
5279: $choices{$option}.'</label></span>';
5280: if ($type eq '') {
5281: $output .= ' ';
5282: } else {
5283: $output .= '<br />';
5284: }
5285: }
5286: $$rowtotal ++;
5287: return $output;
5288: }
5289:
1.165 raeburn 5290: sub captcha_choice {
1.169 raeburn 5291: my ($context,$settings,$itemcount) = @_;
1.269 raeburn 5292: my ($keyentry,$currpub,$currpriv,%checked,$rowname,$pubtext,$privtext,
5293: $vertext,$currver);
1.165 raeburn 5294: my %lt = &captcha_phrases();
5295: $keyentry = 'hidden';
5296: if ($context eq 'cancreate') {
1.224 raeburn 5297: $rowname = &mt('CAPTCHA validation');
1.169 raeburn 5298: } elsif ($context eq 'login') {
5299: $rowname = &mt('"Contact helpdesk" CAPTCHA validation');
1.165 raeburn 5300: }
5301: if (ref($settings) eq 'HASH') {
5302: if ($settings->{'captcha'}) {
5303: $checked{$settings->{'captcha'}} = ' checked="checked"';
5304: } else {
5305: $checked{'original'} = ' checked="checked"';
5306: }
5307: if ($settings->{'captcha'} eq 'recaptcha') {
5308: $pubtext = $lt{'pub'};
5309: $privtext = $lt{'priv'};
5310: $keyentry = 'text';
1.269 raeburn 5311: $vertext = $lt{'ver'};
5312: $currver = $settings->{'recaptchaversion'};
5313: if ($currver ne '2') {
5314: $currver = 1;
5315: }
1.165 raeburn 5316: }
5317: if (ref($settings->{'recaptchakeys'}) eq 'HASH') {
5318: $currpub = $settings->{'recaptchakeys'}{'public'};
5319: $currpriv = $settings->{'recaptchakeys'}{'private'};
5320: }
5321: } else {
5322: $checked{'original'} = ' checked="checked"';
5323: }
1.169 raeburn 5324: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
5325: my $output = '<tr'.$css_class.'>'.
5326: '<td class="LC_left_item">'.$rowname.'</td><td class="LC_left_item" colspan="2">'."\n".
1.165 raeburn 5327: '<table><tr><td>'."\n";
5328: foreach my $option ('original','recaptcha','notused') {
5329: $output .= '<span class="LC_nobreak"><label><input type="radio" name="'.$context.'_captcha" value="'.
5330: $option.'" '.$checked{$option}.' onchange="javascript:updateCaptcha('."this,'$context'".');" />'.
5331: $lt{$option}.'</label></span>';
5332: unless ($option eq 'notused') {
5333: $output .= (' 'x2)."\n";
5334: }
5335: }
5336: #
5337: # Note: If reCAPTCHA is to be used for LON-CAPA servers in a domain, a domain coordinator should visit:
5338: # https://www.google.com/recaptcha and generate a Public and Private key. For domains with multiple
1.210 raeburn 5339: # servers a single key pair will be used for all servers, so the internet domain (e.g., yourcollege.edu)
1.165 raeburn 5340: # specified for use with the key should be broad enough to accommodate all servers in the LON-CAPA domain.
1.210 raeburn 5341: #
1.165 raeburn 5342: $output .= '</td></tr>'."\n".
5343: '<tr><td>'."\n".
5344: '<span class="LC_nobreak"><span id="'.$context.'_recaptchapubtxt">'.$pubtext.'</span> '."\n".
5345: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapub" name="'.$context.'_recaptchapub" value="'.
5346: $currpub.'" size="40" /></span><br />'."\n".
5347: '<span class="LC_nobreak"><span id="'.$context.'_recaptchaprivtxt">'.$privtext.'</span> '."\n".
5348: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapriv" name="'.$context.'_recaptchapriv" value="'.
1.269 raeburn 5349: $currpriv.'" size="40" /></span><br />'.
5350: '<span class="LC_nobreak"><span id="'.$context.'_recaptchavertxt">'.$vertext.'</span> '."\n".
5351: '<input type="'.$keyentry.'" id="'.$context.'_recaptchaversion" name="'.$context.'_recaptchaversion" value="'.
5352: $currver.'" size="3" /></span><br />'.
5353: '</td></tr></table>'."\n".
1.165 raeburn 5354: '</td></tr>';
5355: return $output;
5356: }
5357:
1.32 raeburn 5358: sub user_formats_row {
5359: my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount) = @_;
5360: my $output;
5361: my %text = (
5362: 'username' => 'new usernames',
5363: 'id' => 'IDs',
1.45 raeburn 5364: 'email' => 'self-created accounts (e-mail)',
1.32 raeburn 5365: );
5366: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
5367: $output = '<tr '.$css_class.'>'.
1.63 raeburn 5368: '<td><span class="LC_nobreak">';
5369: if ($type eq 'email') {
5370: $output .= &mt("Formats disallowed for $text{$type}: ");
5371: } else {
5372: $output .= &mt("Format rules to check for $text{$type}: ");
5373: }
5374: $output .= '</span></td>'.
5375: '<td class="LC_left_item" colspan="2"><table>';
1.27 raeburn 5376: my $rem;
5377: if (ref($ruleorder) eq 'ARRAY') {
5378: for (my $i=0; $i<@{$ruleorder}; $i++) {
5379: if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
5380: my $rem = $i%($numinrow);
5381: if ($rem == 0) {
5382: if ($i > 0) {
5383: $output .= '</tr>';
5384: }
5385: $output .= '<tr>';
5386: }
5387: my $check = ' ';
1.39 raeburn 5388: if (ref($settings) eq 'HASH') {
5389: if (ref($settings->{$type.'_rule'}) eq 'ARRAY') {
5390: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) {
5391: $check = ' checked="checked" ';
5392: }
1.27 raeburn 5393: }
5394: }
5395: $output .= '<td class="LC_left_item">'.
5396: '<span class="LC_nobreak"><label>'.
1.32 raeburn 5397: '<input type="checkbox" name="'.$type.'_rule" '.
1.27 raeburn 5398: 'value="'.$ruleorder->[$i].'"'.$check.'/>'.
5399: $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
5400: }
5401: }
5402: $rem = @{$ruleorder}%($numinrow);
5403: }
5404: my $colsleft = $numinrow - $rem;
5405: if ($colsleft > 1 ) {
5406: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
5407: ' </td>';
5408: } elsif ($colsleft == 1) {
5409: $output .= '<td class="LC_left_item"> </td>';
5410: }
5411: $output .= '</tr></table></td></tr>';
5412: return $output;
5413: }
5414:
1.34 raeburn 5415: sub usercreation_types {
5416: my %lt = &Apache::lonlocal::texthash (
5417: author => 'When adding a co-author',
5418: course => 'When adding a user to a course',
1.100 raeburn 5419: requestcrs => 'When requesting a course',
1.34 raeburn 5420: any => 'Any',
5421: official => 'Institutional only ',
5422: unofficial => 'Non-institutional only',
5423: none => 'None',
5424: );
5425: return %lt;
1.48 raeburn 5426: }
1.34 raeburn 5427:
1.224 raeburn 5428: sub selfcreation_types {
5429: my %lt = &Apache::lonlocal::texthash (
5430: selfcreate => 'User creates own account',
5431: any => 'Any',
5432: official => 'Institutional only ',
5433: unofficial => 'Non-institutional only',
5434: email => 'E-mail address',
5435: login => 'Institutional Login',
5436: sso => 'SSO',
5437: );
5438: }
5439:
1.28 raeburn 5440: sub authtype_names {
5441: my %lt = &Apache::lonlocal::texthash(
5442: int => 'Internal',
5443: krb4 => 'Kerberos 4',
5444: krb5 => 'Kerberos 5',
5445: loc => 'Local',
5446: );
5447: return %lt;
5448: }
5449:
5450: sub context_names {
5451: my %context_title = &Apache::lonlocal::texthash(
5452: author => 'Creating users when an Author',
5453: course => 'Creating users when in a course',
5454: domain => 'Creating users when a Domain Coordinator',
5455: );
5456: return %context_title;
5457: }
5458:
1.33 raeburn 5459: sub print_usermodification {
5460: my ($position,$dom,$settings,$rowtotal) = @_;
5461: my $numinrow = 4;
5462: my ($context,$datatable,$rowcount);
5463: if ($position eq 'top') {
5464: $rowcount = 0;
5465: $context = 'author';
5466: foreach my $role ('ca','aa') {
5467: $datatable .= &modifiable_userdata_row($context,$role,$settings,
5468: $numinrow,$rowcount);
5469: $$rowtotal ++;
5470: $rowcount ++;
5471: }
1.230 raeburn 5472: } elsif ($position eq 'bottom') {
1.33 raeburn 5473: $context = 'course';
5474: $rowcount = 0;
5475: foreach my $role ('st','ep','ta','in','cr') {
5476: $datatable .= &modifiable_userdata_row($context,$role,$settings,
5477: $numinrow,$rowcount);
5478: $$rowtotal ++;
5479: $rowcount ++;
5480: }
5481: }
5482: return $datatable;
5483: }
5484:
1.43 raeburn 5485: sub print_defaults {
1.236 raeburn 5486: my ($position,$dom,$settings,$rowtotal) = @_;
1.43 raeburn 5487: my $rownum = 0;
5488: my ($datatable,$css_class);
1.236 raeburn 5489: if ($position eq 'top') {
5490: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def',
5491: 'datelocale_def','portal_def');
5492: my %defaults;
5493: if (ref($settings) eq 'HASH') {
5494: %defaults = %{$settings};
1.43 raeburn 5495: } else {
1.236 raeburn 5496: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
5497: foreach my $item (@items) {
5498: $defaults{$item} = $domdefaults{$item};
5499: }
1.43 raeburn 5500: }
1.236 raeburn 5501: my $titles = &defaults_titles($dom);
5502: foreach my $item (@items) {
5503: if ($rownum%2) {
5504: $css_class = '';
5505: } else {
5506: $css_class = ' class="LC_odd_row" ';
5507: }
5508: $datatable .= '<tr'.$css_class.'>'.
5509: '<td><span class="LC_nobreak">'.$titles->{$item}.
5510: '</span></td><td class="LC_right_item" colspan="3">';
5511: if ($item eq 'auth_def') {
5512: my @authtypes = ('internal','krb4','krb5','localauth');
5513: my %shortauth = (
5514: internal => 'int',
5515: krb4 => 'krb4',
5516: krb5 => 'krb5',
5517: localauth => 'loc'
5518: );
5519: my %authnames = &authtype_names();
5520: foreach my $auth (@authtypes) {
5521: my $checked = ' ';
5522: if ($defaults{$item} eq $auth) {
5523: $checked = ' checked="checked" ';
5524: }
5525: $datatable .= '<label><input type="radio" name="'.$item.
5526: '" value="'.$auth.'"'.$checked.'/>'.
5527: $authnames{$shortauth{$auth}}.'</label> ';
5528: }
5529: } elsif ($item eq 'timezone_def') {
5530: my $includeempty = 1;
5531: $datatable .= &Apache::loncommon::select_timezone($item,$defaults{$item},undef,$includeempty);
5532: } elsif ($item eq 'datelocale_def') {
5533: my $includeempty = 1;
5534: $datatable .= &Apache::loncommon::select_datelocale($item,$defaults{$item},undef,$includeempty);
5535: } elsif ($item eq 'lang_def') {
1.263 raeburn 5536: my $includeempty = 1;
5537: $datatable .= &Apache::loncommon::select_language($item,$defaults{$item},$includeempty);
1.236 raeburn 5538: } else {
5539: my $size;
5540: if ($item eq 'portal_def') {
5541: $size = ' size="25"';
5542: }
5543: $datatable .= '<input type="text" name="'.$item.'" value="'.
5544: $defaults{$item}.'"'.$size.' />';
1.43 raeburn 5545: }
1.236 raeburn 5546: $datatable .= '</td></tr>';
5547: $rownum ++;
5548: }
5549: } else {
5550: my (%defaults);
5551: if (ref($settings) eq 'HASH') {
5552: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH') &&
5553: (ref($settings->{'inststatusguest'}) eq 'ARRAY')) {
5554: my $maxnum = @{$settings->{'inststatusorder'}};
5555: for (my $i=0; $i<$maxnum; $i++) {
5556: $css_class = $rownum%2?' class="LC_odd_row"':'';
5557: my $item = $settings->{'inststatusorder'}->[$i];
5558: my $title = $settings->{'inststatustypes'}->{$item};
5559: my $guestok;
5560: if (grep(/^\Q$item\E$/,@{$settings->{'inststatusguest'}})) {
5561: $guestok = 1;
5562: }
5563: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'$item'".');"';
5564: $datatable .= '<tr'.$css_class.'>'.
5565: '<td><span class="LC_nobreak">'.
5566: '<select name="inststatus_pos_'.$item.'"'.$chgstr.'>';
5567: for (my $k=0; $k<=$maxnum; $k++) {
5568: my $vpos = $k+1;
5569: my $selstr;
5570: if ($k == $i) {
5571: $selstr = ' selected="selected" ';
5572: }
5573: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
5574: }
5575: my ($checkedon,$checkedoff);
5576: $checkedoff = ' checked="checked"';
5577: if ($guestok) {
5578: $checkedon = $checkedoff;
5579: $checkedoff = '';
5580: }
5581: $datatable .= '</select> '.&mt('Internal ID:').' <b>'.$item.'</b> '.
5582: '<input type="checkbox" name="inststatus_delete" value="'.$item.'" />'.
5583: &mt('delete').'</span></td>'.
5584: '<td class="LC_left_item"><span class="LC_nobreak">'.&mt('Name displayed:').
5585: '<input type="text" size="20" name="inststatus_title_'.$item.'" value="'.$title.'" />'.
5586: '</span></td>'.
5587: '<td class="LC_right_item"><span class="LC_nobreak">'.
5588: '<label><input type="radio" value="1" name="inststatus_guest_'.$item.'"'.$checkedon.' />'.
5589: &mt('Yes').'</label>'.(' 'x2).
5590: '<label><input type="radio" value="0" name="inststatus_guest_'.$item.'"'.$checkedoff.' />'.
5591: &mt('No').'</label></span></td></tr>';
5592: }
5593: $css_class = $rownum%2?' class="LC_odd_row"':'';
5594: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'addinststatus_pos'".');"';
5595: $datatable .= '<tr '.$css_class.'>'.
5596: '<td><span class="LC_nobreak"><select name="addinststatus_pos"'.$chgstr.'>';
5597: for (my $k=0; $k<=$maxnum; $k++) {
5598: my $vpos = $k+1;
5599: my $selstr;
5600: if ($k == $maxnum) {
5601: $selstr = ' selected="selected" ';
5602: }
5603: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
5604: }
5605: $datatable .= '</select> '.&mt('Internal ID:').
1.263 raeburn 5606: '<input type="text" size="10" name="addinststatus" value="" />'.
1.236 raeburn 5607: ' '.&mt('(new)').
5608: '</span></td><td class="LC_left_item"><span class="LC_nobreak">'.
5609: &mt('Name displayed:').
5610: '<input type="text" size="20" name="addinststatus_title" value="" /></span></td>'.
5611: '<td class="LC_right_item"><span class="LC_nobreak">'.
5612: '<label><input type="radio" value="1" name="addinststatus_guest" />'.
5613: &mt('Yes').'</label>'.(' 'x2).
5614: '<label><input type="radio" value="0" name="addinststatus_guest" />'.
5615: &mt('No').'</label></span></td></tr>';
5616: '</tr>'."\n";
5617: $rownum ++;
1.141 raeburn 5618: }
1.43 raeburn 5619: }
5620: }
5621: $$rowtotal += $rownum;
5622: return $datatable;
5623: }
5624:
1.168 raeburn 5625: sub get_languages_hash {
5626: my %langchoices;
5627: foreach my $id (&Apache::loncommon::languageids()) {
5628: my $code = &Apache::loncommon::supportedlanguagecode($id);
5629: if ($code ne '') {
5630: $langchoices{$code} = &Apache::loncommon::plainlanguagedescription($id);
5631: }
5632: }
5633: return %langchoices;
5634: }
5635:
1.43 raeburn 5636: sub defaults_titles {
1.141 raeburn 5637: my ($dom) = @_;
1.43 raeburn 5638: my %titles = &Apache::lonlocal::texthash (
5639: 'auth_def' => 'Default authentication type',
5640: 'auth_arg_def' => 'Default authentication argument',
5641: 'lang_def' => 'Default language',
1.54 raeburn 5642: 'timezone_def' => 'Default timezone',
1.68 raeburn 5643: 'datelocale_def' => 'Default locale for dates',
1.141 raeburn 5644: 'portal_def' => 'Portal/Default URL',
1.43 raeburn 5645: );
1.141 raeburn 5646: if ($dom) {
5647: my $uprimary_id = &Apache::lonnet::domain($dom,'primary');
5648: my $uint_dom = &Apache::lonnet::internet_dom($uprimary_id);
5649: my $protocol = $Apache::lonnet::protocol{$uprimary_id};
5650: $protocol = 'http' if ($protocol ne 'https');
5651: if ($uint_dom) {
5652: $titles{'portal_def'} .= ' '.&mt('(for example: [_1])',$protocol.'://loncapa.'.
5653: $uint_dom);
5654: }
5655: }
1.43 raeburn 5656: return (\%titles);
5657: }
5658:
1.46 raeburn 5659: sub print_scantronformat {
5660: my ($r,$dom,$confname,$settings,$rowtotal) = @_;
5661: my $itemcount = 1;
1.60 raeburn 5662: my ($datatable,$css_class,$scantronurl,$is_custom,%error,%scantronurls,
5663: %confhash);
1.46 raeburn 5664: my $switchserver = &check_switchserver($dom,$confname);
5665: my %lt = &Apache::lonlocal::texthash (
1.95 www 5666: default => 'Default bubblesheet format file error',
5667: custom => 'Custom bubblesheet format file error',
1.46 raeburn 5668: );
5669: my %scantronfiles = (
5670: default => 'default.tab',
5671: custom => 'custom.tab',
5672: );
5673: foreach my $key (keys(%scantronfiles)) {
5674: $scantronurls{$key} = '/res/'.$dom.'/'.$confname.'/scantron/'
5675: .$scantronfiles{$key};
5676: }
5677: my @defaultinfo = &Apache::lonnet::stat_file($scantronurls{'default'});
5678: if ((!@defaultinfo) || ($defaultinfo[0] eq 'no_such_dir')) {
5679: if (!$switchserver) {
5680: my $servadm = $r->dir_config('lonAdmEMail');
5681: my ($configuserok,$author_ok) = &config_check($dom,$confname,$servadm);
5682: if ($configuserok eq 'ok') {
5683: if ($author_ok eq 'ok') {
5684: my %legacyfile = (
5685: default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab',
5686: custom => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab',
5687: );
5688: my %md5chk;
5689: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 5690: ($md5chk{$type}) = split(/ /,`md5sum $legacyfile{$type}`);
5691: chomp($md5chk{$type});
1.46 raeburn 5692: }
5693: if ($md5chk{'default'} ne $md5chk{'custom'}) {
5694: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 5695: ($scantronurls{$type},my $error) =
1.46 raeburn 5696: &legacy_scantronformat($r,$dom,$confname,
5697: $type,$legacyfile{$type},
5698: $scantronurls{$type},
5699: $scantronfiles{$type});
1.60 raeburn 5700: if ($error ne '') {
5701: $error{$type} = $error;
5702: }
5703: }
5704: if (keys(%error) == 0) {
5705: $is_custom = 1;
5706: $confhash{'scantron'}{'scantronformat'} =
5707: $scantronurls{'custom'};
5708: my $putresult =
5709: &Apache::lonnet::put_dom('configuration',
5710: \%confhash,$dom);
5711: if ($putresult ne 'ok') {
5712: $error{'custom'} =
5713: '<span class="LC_error">'.
5714: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
5715: }
1.46 raeburn 5716: }
5717: } else {
1.60 raeburn 5718: ($scantronurls{'default'},my $error) =
1.46 raeburn 5719: &legacy_scantronformat($r,$dom,$confname,
5720: 'default',$legacyfile{'default'},
5721: $scantronurls{'default'},
5722: $scantronfiles{'default'});
1.60 raeburn 5723: if ($error eq '') {
5724: $confhash{'scantron'}{'scantronformat'} = '';
5725: my $putresult =
5726: &Apache::lonnet::put_dom('configuration',
5727: \%confhash,$dom);
5728: if ($putresult ne 'ok') {
5729: $error{'default'} =
5730: '<span class="LC_error">'.
5731: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
5732: }
5733: } else {
5734: $error{'default'} = $error;
5735: }
1.46 raeburn 5736: }
5737: }
5738: }
5739: } else {
1.95 www 5740: $error{'default'} = &mt("Unable to copy default bubblesheet formatfile to domain's RES space: [_1]",$switchserver);
1.46 raeburn 5741: }
5742: }
5743: if (ref($settings) eq 'HASH') {
5744: if ($settings->{'scantronformat'} eq "/res/$dom/$confname/scantron/custom.tab") {
5745: my @info = &Apache::lonnet::stat_file($settings->{'scantronformat'});
5746: if ((!@info) || ($info[0] eq 'no_such_dir')) {
5747: $scantronurl = '';
5748: } else {
5749: $scantronurl = $settings->{'scantronformat'};
5750: }
5751: $is_custom = 1;
5752: } else {
5753: $scantronurl = $scantronurls{'default'};
5754: }
5755: } else {
1.60 raeburn 5756: if ($is_custom) {
5757: $scantronurl = $scantronurls{'custom'};
5758: } else {
5759: $scantronurl = $scantronurls{'default'};
5760: }
1.46 raeburn 5761: }
5762: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5763: $datatable .= '<tr'.$css_class.'>';
5764: if (!$is_custom) {
1.65 raeburn 5765: $datatable .= '<td>'.&mt('Default in use:').'<br />'.
5766: '<span class="LC_nobreak">';
1.46 raeburn 5767: if ($scantronurl) {
1.199 raeburn 5768: $datatable .= &Apache::loncommon::modal_link($scantronurl,&mt('Default bubblesheet format file'),600,500,
5769: undef,undef,undef,undef,'background-color:#ffffff');
1.46 raeburn 5770: } else {
5771: $datatable = &mt('File unavailable for display');
5772: }
1.65 raeburn 5773: $datatable .= '</span></td>';
1.60 raeburn 5774: if (keys(%error) == 0) {
5775: $datatable .= '<td valign="bottom">';
5776: if (!$switchserver) {
5777: $datatable .= &mt('Upload:').'<br />';
5778: }
5779: } else {
5780: my $errorstr;
5781: foreach my $key (sort(keys(%error))) {
5782: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
5783: }
5784: $datatable .= '<td>'.$errorstr;
5785: }
1.46 raeburn 5786: } else {
5787: if (keys(%error) > 0) {
5788: my $errorstr;
5789: foreach my $key (sort(keys(%error))) {
5790: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
5791: }
1.60 raeburn 5792: $datatable .= '<td>'.$errorstr.'</td><td> ';
1.46 raeburn 5793: } elsif ($scantronurl) {
1.199 raeburn 5794: my $link = &Apache::loncommon::modal_link($scantronurl,&mt('Custom bubblesheet format file'),600,500,
5795: undef,undef,undef,undef,'background-color:#ffffff');
1.65 raeburn 5796: $datatable .= '<td><span class="LC_nobreak">'.
1.199 raeburn 5797: $link.
5798: '<label><input type="checkbox" name="scantronformat_del"'.
5799: ' value="1" />'.&mt('Delete?').'</label></span></td>'.
1.65 raeburn 5800: '<td><span class="LC_nobreak"> '.
5801: &mt('Replace:').'</span><br />';
1.46 raeburn 5802: }
5803: }
5804: if (keys(%error) == 0) {
5805: if ($switchserver) {
5806: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
5807: } else {
1.65 raeburn 5808: $datatable .='<span class="LC_nobreak"> '.
5809: '<input type="file" name="scantronformat" /></span>';
1.46 raeburn 5810: }
5811: }
5812: $datatable .= '</td></tr>';
5813: $$rowtotal ++;
5814: return $datatable;
5815: }
5816:
5817: sub legacy_scantronformat {
5818: my ($r,$dom,$confname,$file,$legacyfile,$newurl,$newfile) = @_;
5819: my ($url,$error);
5820: my @statinfo = &Apache::lonnet::stat_file($newurl);
5821: if ((!@statinfo) || ($statinfo[0] eq 'no_such_dir')) {
5822: (my $result,$url) =
5823: &publishlogo($r,'copy',$legacyfile,$dom,$confname,'scantron',
5824: '','',$newfile);
5825: if ($result ne 'ok') {
1.130 raeburn 5826: $error = &mt("An error occurred publishing the [_1] bubblesheet format file in RES space. Error was: [_2].",$newfile,$result);
1.46 raeburn 5827: }
5828: }
5829: return ($url,$error);
5830: }
1.43 raeburn 5831:
1.49 raeburn 5832: sub print_coursecategories {
1.57 raeburn 5833: my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;
5834: my $datatable;
5835: if ($position eq 'top') {
1.238 raeburn 5836: my (%checked);
5837: my @catitems = ('unauth','auth');
5838: my @cattypes = ('std','domonly','codesrch','none');
5839: $checked{'unauth'} = 'std';
5840: $checked{'auth'} = 'std';
5841: if (ref($settings) eq 'HASH') {
5842: foreach my $type (@cattypes) {
5843: if ($type eq $settings->{'unauth'}) {
5844: $checked{'unauth'} = $type;
5845: }
5846: if ($type eq $settings->{'auth'}) {
5847: $checked{'auth'} = $type;
5848: }
5849: }
5850: }
5851: my %lt = &Apache::lonlocal::texthash (
5852: unauth => 'Catalog type for unauthenticated users',
5853: auth => 'Catalog type for authenticated users',
5854: none => 'No catalog',
5855: std => 'Standard catalog',
5856: domonly => 'Domain-only catalog',
5857: codesrch => "Code search form",
5858: );
5859: my $itemcount = 0;
5860: foreach my $item (@catitems) {
5861: my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
5862: $datatable .= '<tr '.$css_class.'>'.
5863: '<td>'.$lt{$item}.'</td>'.
5864: '<td class="LC_right_item"><span class="LC_nobreak">';
5865: foreach my $type (@cattypes) {
5866: my $ischecked;
5867: if ($checked{$item} eq $type) {
5868: $ischecked=' checked="checked"';
5869: }
5870: $datatable .= '<label>'.
5871: '<input type="radio" name="coursecat_'.$item.'" value="'.$type.'"'.$ischecked.
5872: ' />'.$lt{$type}.'</label> ';
5873: }
5874: $datatable .= '</td></tr>';
5875: $itemcount ++;
5876: }
5877: $$rowtotal += $itemcount;
5878: } elsif ($position eq 'middle') {
1.57 raeburn 5879: my $toggle_cats_crs = ' ';
5880: my $toggle_cats_dom = ' checked="checked" ';
5881: my $can_cat_crs = ' ';
5882: my $can_cat_dom = ' checked="checked" ';
1.120 raeburn 5883: my $toggle_catscomm_comm = ' ';
5884: my $toggle_catscomm_dom = ' checked="checked" ';
5885: my $can_catcomm_comm = ' ';
5886: my $can_catcomm_dom = ' checked="checked" ';
1.272 raeburn 5887: my $toggle_catsplace_place = ' ';
5888: my $toggle_catsplace_dom = ' checked="checked" ';
5889: my $can_catplace_place = ' ';
5890: my $can_catplace_dom = ' checked="checked" ';
1.120 raeburn 5891:
1.57 raeburn 5892: if (ref($settings) eq 'HASH') {
5893: if ($settings->{'togglecats'} eq 'crs') {
5894: $toggle_cats_crs = $toggle_cats_dom;
5895: $toggle_cats_dom = ' ';
5896: }
5897: if ($settings->{'categorize'} eq 'crs') {
5898: $can_cat_crs = $can_cat_dom;
5899: $can_cat_dom = ' ';
5900: }
1.120 raeburn 5901: if ($settings->{'togglecatscomm'} eq 'comm') {
5902: $toggle_catscomm_comm = $toggle_catscomm_dom;
5903: $toggle_catscomm_dom = ' ';
5904: }
5905: if ($settings->{'categorizecomm'} eq 'comm') {
5906: $can_catcomm_comm = $can_catcomm_dom;
5907: $can_catcomm_dom = ' ';
5908: }
1.272 raeburn 5909: if ($settings->{'togglecatsplace'} eq 'place') {
5910: $toggle_catsplace_place = $toggle_catsplace_dom;
5911: $toggle_catsplace_dom = ' ';
5912: }
5913: if ($settings->{'categorizeplace'} eq 'place') {
5914: $can_catplace_place = $can_catplace_dom;
5915: $can_catplace_dom = ' ';
5916: }
1.57 raeburn 5917: }
5918: my %title = &Apache::lonlocal::texthash (
1.272 raeburn 5919: togglecats => 'Show/Hide a course in catalog',
5920: togglecatscomm => 'Show/Hide a community in catalog',
5921: togglecatsplace => 'Show/Hide a placement test in catalog',
5922: categorize => 'Assign a category to a course',
5923: categorizecomm => 'Assign a category to a community',
5924: categorizeplace => 'Assign a category to a placement test',
1.57 raeburn 5925: );
5926: my %level = &Apache::lonlocal::texthash (
1.272 raeburn 5927: dom => 'Set in Domain',
5928: crs => 'Set in Course',
5929: comm => 'Set in Community',
5930: place => 'Set in Placement Test',
1.57 raeburn 5931: );
5932: $datatable = '<tr class="LC_odd_row">'.
5933: '<td>'.$title{'togglecats'}.'</td>'.
5934: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
5935: '<input type="radio" name="togglecats"'.
5936: $toggle_cats_dom.' value="dom" />'.$level{'dom'}.'</label> '.
5937: '<label><input type="radio" name="togglecats"'.
5938: $toggle_cats_crs.' value="crs" />'.$level{'crs'}.'</label></span></td>'.
5939: '</tr><tr>'.
5940: '<td>'.$title{'categorize'}.'</td>'.
5941: '<td class="LC_right_item"><span class="LC_nobreak">'.
5942: '<label><input type="radio" name="categorize"'.
5943: $can_cat_dom.' value="dom" />'.$level{'dom'}.'</label> '.
5944: '<label><input type="radio" name="categorize"'.
5945: $can_cat_crs.'value="crs" />'.$level{'crs'}.'</label></span></td>'.
1.120 raeburn 5946: '</tr><tr class="LC_odd_row">'.
5947: '<td>'.$title{'togglecatscomm'}.'</td>'.
5948: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
5949: '<input type="radio" name="togglecatscomm"'.
5950: $toggle_catscomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
5951: '<label><input type="radio" name="togglecatscomm"'.
5952: $toggle_catscomm_comm.' value="comm" />'.$level{'comm'}.'</label></span></td>'.
5953: '</tr><tr>'.
5954: '<td>'.$title{'categorizecomm'}.'</td>'.
5955: '<td class="LC_right_item"><span class="LC_nobreak">'.
5956: '<label><input type="radio" name="categorizecomm"'.
5957: $can_catcomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
5958: '<label><input type="radio" name="categorizecomm"'.
5959: $can_catcomm_comm.'value="comm" />'.$level{'comm'}.'</label></span></td>'.
1.272 raeburn 5960: '</tr><tr>'.
5961: '<td>'.$title{'togglecatsplace'}.'</td>'.
5962: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
5963: '<input type="radio" name="togglecatsplace"'.
5964: $toggle_catsplace_dom.' value="dom" />'.$level{'dom'}.'</label> '.
5965: '<label><input type="radio" name="togglecatscomm"'.
5966: $toggle_catsplace_place.' value="comm" />'.$level{'place'}.'</label></span></td>'.
5967: '</tr><tr>'.
5968: '<td>'.$title{'categorizeplace'}.'</td>'.
5969: '<td class="LC_right_item"><span class="LC_nobreak">'.
5970: '<label><input type="radio" name="categorizeplace"'.
5971: $can_catplace_dom.' value="dom" />'.$level{'dom'}.'</label> '.
5972: '<label><input type="radio" name="categorizeplace"'.
5973: $can_catplace_place.'value="place" />'.$level{'place'}.'</label></span></td>'.
1.57 raeburn 5974: '</tr>';
1.272 raeburn 5975: $$rowtotal += 6;
1.57 raeburn 5976: } else {
5977: my $css_class;
5978: my $itemcount = 1;
5979: my $cathash;
5980: if (ref($settings) eq 'HASH') {
5981: $cathash = $settings->{'cats'};
5982: }
5983: if (ref($cathash) eq 'HASH') {
5984: my (@cats,@trails,%allitems,%idx,@jsarray);
5985: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
5986: \%allitems,\%idx,\@jsarray);
5987: my $maxdepth = scalar(@cats);
5988: my $colattrib = '';
5989: if ($maxdepth > 2) {
5990: $colattrib = ' colspan="2" ';
5991: }
5992: my @path;
5993: if (@cats > 0) {
5994: if (ref($cats[0]) eq 'ARRAY') {
5995: my $numtop = @{$cats[0]};
5996: my $maxnum = $numtop;
1.120 raeburn 5997: my %default_names = (
5998: instcode => &mt('Official courses'),
5999: communities => &mt('Communities'),
1.272 raeburn 6000: placement => &mt('Placement Tests'),
1.120 raeburn 6001: );
6002:
6003: if ((!grep(/^instcode$/,@{$cats[0]})) ||
6004: ($cathash->{'instcode::0'} eq '') ||
6005: (!grep(/^communities$/,@{$cats[0]})) ||
1.272 raeburn 6006: ($cathash->{'communities::0'} eq '') ||
6007: (!grep(/^placement$/,@{$cats[0]})) ||
6008: ($cathash->{'placement::0'} eq '')) {
1.57 raeburn 6009: $maxnum ++;
6010: }
6011: my $lastidx;
6012: for (my $i=0; $i<$numtop; $i++) {
6013: my $parent = $cats[0][$i];
6014: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6015: my $item = &escape($parent).'::0';
6016: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$item','$idx{$item}'".');"';
6017: $lastidx = $idx{$item};
6018: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
6019: .'<select name="'.$item.'"'.$chgstr.'>';
6020: for (my $k=0; $k<=$maxnum; $k++) {
6021: my $vpos = $k+1;
6022: my $selstr;
6023: if ($k == $i) {
6024: $selstr = ' selected="selected" ';
6025: }
6026: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
6027: }
1.214 raeburn 6028: $datatable .= '</select></span></td><td>';
1.272 raeburn 6029: if ($parent eq 'instcode' || $parent eq 'communities' || $parent eq 'placement') {
1.120 raeburn 6030: $datatable .= '<span class="LC_nobreak">'
6031: .$default_names{$parent}.'</span>';
6032: if ($parent eq 'instcode') {
6033: $datatable .= '<br /><span class="LC_nobreak">('
6034: .&mt('with institutional codes')
6035: .')</span></td><td'.$colattrib.'>';
6036: } else {
6037: $datatable .= '<table><tr><td>';
6038: }
6039: $datatable .= '<span class="LC_nobreak">'
6040: .'<label><input type="radio" name="'
6041: .$parent.'" value="1" checked="checked" />'
6042: .&mt('Display').'</label>';
6043: if ($parent eq 'instcode') {
6044: $datatable .= ' ';
6045: } else {
6046: $datatable .= '</span></td></tr><tr><td>'
6047: .'<span class="LC_nobreak">';
6048: }
6049: $datatable .= '<label><input type="radio" name="'
6050: .$parent.'" value="0" />'
6051: .&mt('Do not display').'</label></span>';
1.272 raeburn 6052: if (($parent eq 'communities') || ($parent eq 'placement')) {
1.120 raeburn 6053: $datatable .= '</td></tr></table>';
6054: }
6055: $datatable .= '</td>';
1.57 raeburn 6056: } else {
6057: $datatable .= $parent
1.214 raeburn 6058: .' <span class="LC_nobreak"><label>'
6059: .'<input type="checkbox" name="deletecategory" '
1.57 raeburn 6060: .'value="'.$item.'" />'.&mt('Delete').'</label></span></td>';
6061: }
6062: my $depth = 1;
6063: push(@path,$parent);
6064: $datatable .= &build_category_rows($itemcount,\@cats,$depth,$parent,\@path,\%idx);
6065: pop(@path);
6066: $datatable .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
6067: $itemcount ++;
6068: }
1.48 raeburn 6069: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.57 raeburn 6070: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','$lastidx'".');"';
6071: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="addcategory_pos"'.$chgstr.'>';
1.48 raeburn 6072: for (my $k=0; $k<=$maxnum; $k++) {
6073: my $vpos = $k+1;
6074: my $selstr;
1.57 raeburn 6075: if ($k == $numtop) {
1.48 raeburn 6076: $selstr = ' selected="selected" ';
6077: }
6078: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
6079: }
1.59 bisitz 6080: $datatable .= '</select></span></td><td colspan="2">'.&mt('Add category:').' '
1.57 raeburn 6081: .'<input type="text" size="20" name="addcategory_name" value="" /></td>'
6082: .'</tr>'."\n";
1.48 raeburn 6083: $itemcount ++;
1.272 raeburn 6084: foreach my $default ('instcode','communities','placement') {
1.120 raeburn 6085: if ((!grep(/^\Q$default\E$/,@{$cats[0]})) || ($cathash->{$default.'::0'} eq '')) {
6086: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6087: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','$lastidx'".');"';
6088: $datatable .= '<tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr><tr '.$css_class.'><td>'.
6089: '<span class="LC_nobreak"><select name="'.$default.'_pos"'.$chgstr.'>';
6090: for (my $k=0; $k<=$maxnum; $k++) {
6091: my $vpos = $k+1;
6092: my $selstr;
6093: if ($k == $maxnum) {
6094: $selstr = ' selected="selected" ';
6095: }
6096: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.57 raeburn 6097: }
1.120 raeburn 6098: $datatable .= '</select></span></td>'.
6099: '<td><span class="LC_nobreak">'.
6100: $default_names{$default}.'</span>';
6101: if ($default eq 'instcode') {
6102: $datatable .= '<br /><span class="LC_nobreak">('
6103: .&mt('with institutional codes').')</span>';
6104: }
6105: $datatable .= '</td>'
6106: .'<td><span class="LC_nobreak"><label><input type="radio" name="'.$default.'" value="1" />'
6107: .&mt('Display').'</label> '
6108: .'<label><input type="radio" name="'.$default.'" value="0" checked="checked"/>'
6109: .&mt('Do not display').'</label></span></td></tr>';
1.48 raeburn 6110: }
6111: }
6112: }
1.57 raeburn 6113: } else {
6114: $datatable .= &initialize_categories($itemcount);
1.48 raeburn 6115: }
6116: } else {
1.238 raeburn 6117: $datatable .= '<td class="LC_right_item">'.$hdritem->{'header'}->[1]->{'col2'}.'</td>'
1.57 raeburn 6118: .&initialize_categories($itemcount);
1.48 raeburn 6119: }
1.57 raeburn 6120: $$rowtotal += $itemcount;
1.48 raeburn 6121: }
6122: return $datatable;
6123: }
6124:
1.69 raeburn 6125: sub print_serverstatuses {
6126: my ($dom,$settings,$rowtotal) = @_;
6127: my $datatable;
6128: my @pages = &serverstatus_pages();
6129: my (%namedaccess,%machineaccess);
6130: foreach my $type (@pages) {
6131: $namedaccess{$type} = '';
6132: $machineaccess{$type}= '';
6133: }
6134: if (ref($settings) eq 'HASH') {
6135: foreach my $type (@pages) {
6136: if (exists($settings->{$type})) {
6137: if (ref($settings->{$type}) eq 'HASH') {
6138: foreach my $key (keys(%{$settings->{$type}})) {
6139: if ($key eq 'namedusers') {
6140: $namedaccess{$type} = $settings->{$type}->{$key};
6141: } elsif ($key eq 'machines') {
6142: $machineaccess{$type} = $settings->{$type}->{$key};
6143: }
6144: }
6145: }
6146: }
6147: }
6148: }
1.81 raeburn 6149: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 6150: my $rownum = 0;
6151: my $css_class;
6152: foreach my $type (@pages) {
6153: $rownum ++;
6154: $css_class = $rownum%2?' class="LC_odd_row"':'';
6155: $datatable .= '<tr'.$css_class.'>'.
6156: '<td><span class="LC_nobreak">'.
6157: $titles->{$type}.'</span></td>'.
6158: '<td class="LC_left_item">'.
6159: '<input type="text" name="'.$type.'_namedusers" '.
6160: 'value="'.$namedaccess{$type}.'" size="30" /></td>'.
6161: '<td class="LC_right_item">'.
6162: '<span class="LC_nobreak">'.
6163: '<input type="text" name="'.$type.'_machines" '.
6164: 'value="'.$machineaccess{$type}.'" size="10" />'.
6165: '</td></tr>'."\n";
6166: }
6167: $$rowtotal += $rownum;
6168: return $datatable;
6169: }
6170:
6171: sub serverstatus_pages {
6172: return ('userstatus','lonstatus','loncron','server-status','codeversions',
1.275 raeburn 6173: 'checksums','clusterstatus','certstatus','metadata_keywords',
6174: 'metadata_harvest','takeoffline','takeonline','showenv','toggledebug',
6175: 'ping','domconf','uniquecodes','diskusage','coursecatalog');
1.69 raeburn 6176: }
6177:
1.236 raeburn 6178: sub defaults_javascript {
6179: my ($settings) = @_;
1.248 raeburn 6180: return unless (ref($settings) eq 'HASH');
1.236 raeburn 6181: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
6182: my $maxnum = scalar(@{$settings->{'inststatusorder'}});
6183: if ($maxnum eq '') {
6184: $maxnum = 0;
6185: }
6186: $maxnum ++;
1.249 raeburn 6187: my $jstext = ' var inststatuses = Array('."'".join("','",@{$settings->{'inststatusorder'}})."'".');';
1.236 raeburn 6188: return <<"ENDSCRIPT";
6189: <script type="text/javascript">
6190: // <![CDATA[
6191: function reorderTypes(form,caller) {
6192: var changedVal;
6193: $jstext
6194: var newpos = 'addinststatus_pos';
6195: var current = new Array;
6196: var maxh = $maxnum;
6197: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
6198: var oldVal;
6199: if (caller == newpos) {
6200: changedVal = newitemVal;
6201: } else {
6202: var curritem = 'inststatus_pos_'+caller;
6203: changedVal = form.elements[curritem].options[form.elements[curritem].selectedIndex].value;
6204: current[newitemVal] = newpos;
6205: }
6206: for (var i=0; i<inststatuses.length; i++) {
6207: if (inststatuses[i] != caller) {
6208: var elementName = 'inststatus_pos_'+inststatuses[i];
6209: if (form.elements[elementName]) {
6210: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
6211: current[currVal] = elementName;
6212: }
6213: }
6214: }
6215: for (var j=0; j<maxh; j++) {
6216: if (current[j] == undefined) {
6217: oldVal = j;
6218: }
6219: }
6220: if (oldVal < changedVal) {
6221: for (var k=oldVal+1; k<=changedVal ; k++) {
6222: var elementName = current[k];
6223: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
6224: }
6225: } else {
6226: for (var k=changedVal; k<oldVal; k++) {
6227: var elementName = current[k];
6228: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
6229: }
6230: }
6231: return;
6232: }
6233:
6234: // ]]>
6235: </script>
6236:
6237: ENDSCRIPT
6238: }
6239: }
6240:
1.49 raeburn 6241: sub coursecategories_javascript {
6242: my ($settings) = @_;
1.57 raeburn 6243: my ($output,$jstext,$cathash);
1.49 raeburn 6244: if (ref($settings) eq 'HASH') {
1.57 raeburn 6245: $cathash = $settings->{'cats'};
6246: }
6247: if (ref($cathash) eq 'HASH') {
1.49 raeburn 6248: my (@cats,@jsarray,%idx);
1.57 raeburn 6249: &Apache::loncommon::gather_categories($cathash,\@cats,\%idx,\@jsarray);
1.49 raeburn 6250: if (@jsarray > 0) {
6251: $jstext = ' var categories = Array('.scalar(@jsarray).');'."\n";
6252: for (my $i=0; $i<@jsarray; $i++) {
6253: if (ref($jsarray[$i]) eq 'ARRAY') {
6254: my $catstr = join('","',@{$jsarray[$i]});
6255: $jstext .= ' categories['.$i.'] = Array("'.$catstr.'");'."\n";
6256: }
6257: }
6258: }
6259: } else {
6260: $jstext = ' var categories = Array(1);'."\n".
6261: ' categories[0] = Array("instcode_pos");'."\n";
6262: }
1.237 bisitz 6263: my $instcode_reserved = &mt('The name: [_1] is a reserved category.','"instcode"');
6264: my $communities_reserved = &mt('The name: [_1] is a reserved category.','"communities"');
1.272 raeburn 6265: my $placement_reserved = &mt('The name: [_1] is a reserved category.','"placement"');
1.265 damieng 6266: my $choose_again = "\n".&mt('Please use a different name for the new top level category.');
6267: &js_escape(\$instcode_reserved);
6268: &js_escape(\$communities_reserved);
1.272 raeburn 6269: &js_escape(\$placement_reserved);
1.265 damieng 6270: &js_escape(\$choose_again);
1.49 raeburn 6271: $output = <<"ENDSCRIPT";
6272: <script type="text/javascript">
1.109 raeburn 6273: // <![CDATA[
1.49 raeburn 6274: function reorderCats(form,parent,item,idx) {
6275: var changedVal;
6276: $jstext
6277: var newpos = 'addcategory_pos';
6278: if (parent == '') {
6279: var has_instcode = 0;
6280: var maxtop = categories[idx].length;
6281: for (var j=0; j<maxtop; j++) {
6282: if (categories[idx][j] == 'instcode::0') {
6283: has_instcode == 1;
6284: }
6285: }
6286: if (has_instcode == 0) {
6287: categories[idx][maxtop] = 'instcode_pos';
6288: }
6289: } else {
6290: newpos += '_'+parent;
6291: }
6292: var maxh = 1 + categories[idx].length;
6293: var current = new Array;
6294: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
6295: if (item == newpos) {
6296: changedVal = newitemVal;
6297: } else {
6298: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
6299: current[newitemVal] = newpos;
6300: }
6301: for (var i=0; i<categories[idx].length; i++) {
6302: var elementName = categories[idx][i];
6303: if (elementName != item) {
6304: if (form.elements[elementName]) {
6305: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
6306: current[currVal] = elementName;
6307: }
6308: }
6309: }
6310: var oldVal;
6311: for (var j=0; j<maxh; j++) {
6312: if (current[j] == undefined) {
6313: oldVal = j;
6314: }
6315: }
6316: if (oldVal < changedVal) {
6317: for (var k=oldVal+1; k<=changedVal ; k++) {
6318: var elementName = current[k];
6319: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
6320: }
6321: } else {
6322: for (var k=changedVal; k<oldVal; k++) {
6323: var elementName = current[k];
6324: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
6325: }
6326: }
6327: return;
6328: }
1.120 raeburn 6329:
6330: function categoryCheck(form) {
6331: if (form.elements['addcategory_name'].value == 'instcode') {
6332: alert('$instcode_reserved\\n$choose_again');
6333: return false;
6334: }
6335: if (form.elements['addcategory_name'].value == 'communities') {
6336: alert('$communities_reserved\\n$choose_again');
6337: return false;
6338: }
1.272 raeburn 6339: if (form.elements['addcategory_name'].value == 'placement') {
6340: alert('$placement_reserved\\n$choose_again');
6341: return false;
6342: }
1.120 raeburn 6343: return true;
6344: }
6345:
1.109 raeburn 6346: // ]]>
1.49 raeburn 6347: </script>
6348:
6349: ENDSCRIPT
6350: return $output;
6351: }
6352:
1.48 raeburn 6353: sub initialize_categories {
6354: my ($itemcount) = @_;
1.120 raeburn 6355: my ($datatable,$css_class,$chgstr);
6356: my %default_names = (
6357: instcode => 'Official courses (with institutional codes)',
6358: communities => 'Communities',
1.272 raeburn 6359: placement => 'Placement Tests',
1.120 raeburn 6360: );
6361: my $select0 = ' selected="selected"';
6362: my $select1 = '';
1.272 raeburn 6363: foreach my $default ('instcode','communities','placement') {
1.120 raeburn 6364: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6365: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'',$default"."_pos','0'".');"';
1.272 raeburn 6366: if (($default eq 'communities') || ($default eq 'placement')) {
1.120 raeburn 6367: $select1 = $select0;
6368: $select0 = '';
6369: }
6370: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
6371: .'<select name="'.$default.'_pos">'
6372: .'<option value="0"'.$select0.'>1</option>'
6373: .'<option value="1"'.$select1.'>2</option>'
6374: .'<option value="2">3</option></select> '
6375: .$default_names{$default}
6376: .'</span></td><td><span class="LC_nobreak">'
6377: .'<label><input type="radio" name="'.$default.'" value="1" checked="checked" />'
6378: .&mt('Display').'</label> <label>'
6379: .'<input type="radio" name="'.$default.'" value="0" />'.&mt('Do not display')
1.48 raeburn 6380: .'</label></span></td></tr>';
1.120 raeburn 6381: $itemcount ++;
6382: }
1.48 raeburn 6383: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.49 raeburn 6384: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','0'".');"';
1.48 raeburn 6385: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.120 raeburn 6386: .'<select name="addcategory_pos"'.$chgstr.'>'
6387: .'<option value="0">1</option>'
6388: .'<option value="1">2</option>'
6389: .'<option value="2" selected="selected">3</option></select> '
1.48 raeburn 6390: .&mt('Add category').'</td><td>'.&mt('Name:')
6391: .' <input type="text" size="20" name="addcategory_name" value="" /></td></tr>';
6392: return $datatable;
6393: }
6394:
6395: sub build_category_rows {
1.49 raeburn 6396: my ($itemcount,$cats,$depth,$parent,$path,$idx) = @_;
6397: my ($text,$name,$item,$chgstr);
1.48 raeburn 6398: if (ref($cats) eq 'ARRAY') {
6399: my $maxdepth = scalar(@{$cats});
6400: if (ref($cats->[$depth]) eq 'HASH') {
6401: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
6402: my $numchildren = @{$cats->[$depth]{$parent}};
6403: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.204 raeburn 6404: $text .= '<td><table class="LC_data_table">';
1.49 raeburn 6405: my ($idxnum,$parent_name,$parent_item);
6406: my $higher = $depth - 1;
6407: if ($higher == 0) {
6408: $parent_name = &escape($parent).'::'.$higher;
6409: } else {
6410: if (ref($path) eq 'ARRAY') {
6411: $parent_name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
6412: }
6413: }
6414: $parent_item = 'addcategory_pos_'.$parent_name;
1.48 raeburn 6415: for (my $j=0; $j<=$numchildren; $j++) {
1.49 raeburn 6416: if ($j < $numchildren) {
1.48 raeburn 6417: $name = $cats->[$depth]{$parent}[$j];
6418: $item = &escape($name).':'.&escape($parent).':'.$depth;
1.49 raeburn 6419: $idxnum = $idx->{$item};
6420: } else {
6421: $name = $parent_name;
6422: $item = $parent_item;
1.48 raeburn 6423: }
1.49 raeburn 6424: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'$parent_name','$item','$idxnum'".');"';
6425: $text .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="'.$item.'"'.$chgstr.'>';
1.48 raeburn 6426: for (my $i=0; $i<=$numchildren; $i++) {
6427: my $vpos = $i+1;
6428: my $selstr;
6429: if ($j == $i) {
6430: $selstr = ' selected="selected" ';
6431: }
6432: $text .= '<option value="'.$i.'"'.$selstr.'>'.$vpos.'</option>';
6433: }
6434: $text .= '</select> ';
6435: if ($j < $numchildren) {
6436: my $deeper = $depth+1;
6437: $text .= $name.' '
6438: .'<label><input type="checkbox" name="deletecategory" value="'
6439: .$item.'" />'.&mt('Delete').'</label></span></td><td>';
6440: if(ref($path) eq 'ARRAY') {
6441: push(@{$path},$name);
1.49 raeburn 6442: $text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path,$idx);
1.48 raeburn 6443: pop(@{$path});
6444: }
6445: } else {
1.59 bisitz 6446: $text .= &mt('Add subcategory:').' </span><input type="textbox" size="20" name="addcategory_name_';
1.48 raeburn 6447: if ($j == $numchildren) {
6448: $text .= $name;
6449: } else {
6450: $text .= $item;
6451: }
6452: $text .= '" value="" />';
6453: }
6454: $text .= '</td></tr>';
6455: }
6456: $text .= '</table></td>';
6457: } else {
6458: my $higher = $depth-1;
6459: if ($higher == 0) {
6460: $name = &escape($parent).'::'.$higher;
6461: } else {
6462: if (ref($path) eq 'ARRAY') {
6463: $name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
6464: }
6465: }
6466: my $colspan;
6467: if ($parent ne 'instcode') {
6468: $colspan = $maxdepth - $depth - 1;
6469: $text .= '<td colspan="'.$colspan.'">'.&mt('Add subcategory:').'<input type="textbox" size="20" name="subcat_'.$name.'" value="" /></td>';
6470: }
6471: }
6472: }
6473: }
6474: return $text;
6475: }
6476:
1.33 raeburn 6477: sub modifiable_userdata_row {
1.228 raeburn 6478: my ($context,$item,$settings,$numinrow,$rowcount,$usertypes,$fieldsref,$titlesref) = @_;
6479: my ($role,$rolename,$statustype);
6480: $role = $item;
1.224 raeburn 6481: if ($context eq 'cancreate') {
1.228 raeburn 6482: if ($item =~ /^emailusername_(.+)$/) {
6483: $statustype = $1;
6484: $role = 'emailusername';
6485: if (ref($usertypes) eq 'HASH') {
6486: if ($usertypes->{$statustype}) {
6487: $rolename = &mt('Data provided by [_1]',$usertypes->{$statustype});
6488: } else {
6489: $rolename = &mt('Data provided by user');
6490: }
6491: }
1.224 raeburn 6492: }
6493: } elsif ($context eq 'selfcreate') {
1.63 raeburn 6494: if (ref($usertypes) eq 'HASH') {
6495: $rolename = $usertypes->{$role};
6496: } else {
6497: $rolename = $role;
6498: }
1.33 raeburn 6499: } else {
1.63 raeburn 6500: if ($role eq 'cr') {
6501: $rolename = &mt('Custom role');
6502: } else {
6503: $rolename = &Apache::lonnet::plaintext($role);
6504: }
1.33 raeburn 6505: }
1.224 raeburn 6506: my (@fields,%fieldtitles);
6507: if (ref($fieldsref) eq 'ARRAY') {
6508: @fields = @{$fieldsref};
6509: } else {
6510: @fields = ('lastname','firstname','middlename','generation',
6511: 'permanentemail','id');
6512: }
6513: if ((ref($titlesref) eq 'HASH')) {
6514: %fieldtitles = %{$titlesref};
6515: } else {
6516: %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
6517: }
1.33 raeburn 6518: my $output;
6519: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
6520: $output = '<tr '.$css_class.'>'.
6521: '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
6522: '<td class="LC_left_item" colspan="2"><table>';
6523: my $rem;
6524: my %checks;
6525: if (ref($settings) eq 'HASH') {
6526: if (ref($settings->{$context}) eq 'HASH') {
6527: if (ref($settings->{$context}->{$role}) eq 'HASH') {
1.228 raeburn 6528: my $hashref = $settings->{$context}->{$role};
6529: if ($role eq 'emailusername') {
6530: if ($statustype) {
6531: if (ref($settings->{$context}->{$role}->{$statustype}) eq 'HASH') {
6532: $hashref = $settings->{$context}->{$role}->{$statustype};
6533: if (ref($hashref) eq 'HASH') {
6534: foreach my $field (@fields) {
6535: if ($hashref->{$field}) {
6536: $checks{$field} = $hashref->{$field};
6537: }
6538: }
6539: }
6540: }
6541: }
6542: } else {
6543: if (ref($hashref) eq 'HASH') {
6544: foreach my $field (@fields) {
6545: if ($hashref->{$field}) {
6546: $checks{$field} = ' checked="checked" ';
6547: }
6548: }
1.33 raeburn 6549: }
6550: }
6551: }
6552: }
6553: }
1.228 raeburn 6554:
1.33 raeburn 6555: for (my $i=0; $i<@fields; $i++) {
6556: my $rem = $i%($numinrow);
6557: if ($rem == 0) {
6558: if ($i > 0) {
6559: $output .= '</tr>';
6560: }
6561: $output .= '<tr>';
6562: }
6563: my $check = ' ';
1.228 raeburn 6564: unless ($role eq 'emailusername') {
6565: if (exists($checks{$fields[$i]})) {
6566: $check = $checks{$fields[$i]}
6567: } else {
6568: if ($role eq 'st') {
6569: if (ref($settings) ne 'HASH') {
6570: $check = ' checked="checked" ';
6571: }
1.33 raeburn 6572: }
6573: }
6574: }
6575: $output .= '<td class="LC_left_item">'.
1.228 raeburn 6576: '<span class="LC_nobreak">';
6577: if ($role eq 'emailusername') {
6578: unless ($checks{$fields[$i]} =~ /^(required|optional)$/) {
6579: $checks{$fields[$i]} = 'omit';
6580: }
6581: foreach my $option ('required','optional','omit') {
6582: my $checked='';
6583: if ($checks{$fields[$i]} eq $option) {
6584: $checked='checked="checked" ';
6585: }
6586: $output .= '<label>'.
6587: '<input type="radio" name="canmodify_'.$item.'_'.$fields[$i].'" value="'.$option.'" '.$checked.'/>'.
6588: &mt($option).'</label>'.(' ' x2);
6589: }
6590: $output .= '<i>'.$fieldtitles{$fields[$i]}.'</i>';
6591: } else {
6592: $output .= '<label>'.
6593: '<input type="checkbox" name="canmodify_'.$role.'" '.
6594: 'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
6595: '</label>';
6596: }
6597: $output .= '</span></td>';
1.33 raeburn 6598: $rem = @fields%($numinrow);
6599: }
6600: my $colsleft = $numinrow - $rem;
6601: if ($colsleft > 1 ) {
6602: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
6603: ' </td>';
6604: } elsif ($colsleft == 1) {
6605: $output .= '<td class="LC_left_item"> </td>';
6606: }
6607: $output .= '</tr></table></td></tr>';
6608: return $output;
6609: }
1.28 raeburn 6610:
1.93 raeburn 6611: sub insttypes_row {
1.224 raeburn 6612: my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle,$context,$rownum) = @_;
1.93 raeburn 6613: my %lt = &Apache::lonlocal::texthash (
6614: cansearch => 'Users allowed to search',
6615: statustocreate => 'Institutional affiliation(s) able to create own account (login/SSO)',
1.131 raeburn 6616: lockablenames => 'User preference to lock name',
1.93 raeburn 6617: );
6618: my $showdom;
6619: if ($context eq 'cansearch') {
6620: $showdom = ' ('.$dom.')';
6621: }
1.165 raeburn 6622: my $class = 'LC_left_item';
6623: if ($context eq 'statustocreate') {
6624: $class = 'LC_right_item';
6625: }
1.224 raeburn 6626: my $css_class = ' class="LC_odd_row"';
6627: if ($rownum ne '') {
6628: $css_class = ($rownum%2? ' class="LC_odd_row"':'');
6629: }
6630: my $output = '<tr'.$css_class.'>'.
6631: '<td>'.$lt{$context}.$showdom.
6632: '</td><td class="'.$class.'" colspan="2"><table>';
1.26 raeburn 6633: my $rem;
6634: if (ref($types) eq 'ARRAY') {
6635: for (my $i=0; $i<@{$types}; $i++) {
6636: if (defined($usertypes->{$types->[$i]})) {
6637: my $rem = $i%($numinrow);
6638: if ($rem == 0) {
6639: if ($i > 0) {
6640: $output .= '</tr>';
6641: }
6642: $output .= '<tr>';
1.23 raeburn 6643: }
1.26 raeburn 6644: my $check = ' ';
1.99 raeburn 6645: if (ref($settings) eq 'HASH') {
6646: if (ref($settings->{$context}) eq 'ARRAY') {
6647: if (grep(/^\Q$types->[$i]\E$/,@{$settings->{$context}})) {
6648: $check = ' checked="checked" ';
6649: }
6650: } elsif ($context eq 'statustocreate') {
1.26 raeburn 6651: $check = ' checked="checked" ';
6652: }
1.23 raeburn 6653: }
1.26 raeburn 6654: $output .= '<td class="LC_left_item">'.
6655: '<span class="LC_nobreak"><label>'.
1.93 raeburn 6656: '<input type="checkbox" name="'.$context.'" '.
1.26 raeburn 6657: 'value="'.$types->[$i].'"'.$check.'/>'.
6658: $usertypes->{$types->[$i]}.'</label></span></td>';
1.23 raeburn 6659: }
6660: }
1.26 raeburn 6661: $rem = @{$types}%($numinrow);
1.23 raeburn 6662: }
6663: my $colsleft = $numinrow - $rem;
1.131 raeburn 6664: if (($rem == 0) && (@{$types} > 0)) {
6665: $output .= '<tr>';
6666: }
1.23 raeburn 6667: if ($colsleft > 1) {
1.25 raeburn 6668: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
1.23 raeburn 6669: } else {
1.25 raeburn 6670: $output .= '<td class="LC_left_item">';
1.23 raeburn 6671: }
6672: my $defcheck = ' ';
1.99 raeburn 6673: if (ref($settings) eq 'HASH') {
6674: if (ref($settings->{$context}) eq 'ARRAY') {
6675: if (grep(/^default$/,@{$settings->{$context}})) {
6676: $defcheck = ' checked="checked" ';
6677: }
6678: } elsif ($context eq 'statustocreate') {
1.26 raeburn 6679: $defcheck = ' checked="checked" ';
6680: }
1.23 raeburn 6681: }
1.25 raeburn 6682: $output .= '<span class="LC_nobreak"><label>'.
1.93 raeburn 6683: '<input type="checkbox" name="'.$context.'" '.
1.25 raeburn 6684: 'value="default"'.$defcheck.'/>'.
6685: $othertitle.'</label></span></td>'.
6686: '</tr></table></td></tr>';
6687: return $output;
1.23 raeburn 6688: }
6689:
6690: sub sorted_searchtitles {
6691: my %searchtitles = &Apache::lonlocal::texthash(
6692: 'uname' => 'username',
6693: 'lastname' => 'last name',
6694: 'lastfirst' => 'last name, first name',
6695: );
6696: my @titleorder = ('uname','lastname','lastfirst');
6697: return (\%searchtitles,\@titleorder);
6698: }
6699:
1.25 raeburn 6700: sub sorted_searchtypes {
6701: my %srchtypes_desc = (
6702: exact => 'is exact match',
6703: contains => 'contains ..',
6704: begins => 'begins with ..',
6705: );
6706: my @srchtypeorder = ('exact','begins','contains');
6707: return (\%srchtypes_desc,\@srchtypeorder);
6708: }
6709:
1.3 raeburn 6710: sub usertype_update_row {
6711: my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
6712: my $datatable;
6713: my $numinrow = 4;
6714: foreach my $type (@{$types}) {
6715: if (defined($usertypes->{$type})) {
6716: $$rownums ++;
6717: my $css_class = $$rownums%2?' class="LC_odd_row"':'';
6718: $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
6719: '</td><td class="LC_left_item"><table>';
6720: for (my $i=0; $i<@{$fields}; $i++) {
6721: my $rem = $i%($numinrow);
6722: if ($rem == 0) {
6723: if ($i > 0) {
6724: $datatable .= '</tr>';
6725: }
6726: $datatable .= '<tr>';
6727: }
6728: my $check = ' ';
1.39 raeburn 6729: if (ref($settings) eq 'HASH') {
6730: if (ref($settings->{'fields'}) eq 'HASH') {
6731: if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
6732: if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
6733: $check = ' checked="checked" ';
6734: }
1.3 raeburn 6735: }
6736: }
6737: }
6738:
6739: if ($i == @{$fields}-1) {
6740: my $colsleft = $numinrow - $rem;
6741: if ($colsleft > 1) {
6742: $datatable .= '<td colspan="'.$colsleft.'">';
6743: } else {
6744: $datatable .= '<td>';
6745: }
6746: } else {
6747: $datatable .= '<td>';
6748: }
1.8 raeburn 6749: $datatable .= '<span class="LC_nobreak"><label>'.
6750: '<input type="checkbox" name="updateable_'.$type.
6751: '_'.$fields->[$i].'" value="1"'.$check.'/>'.
6752: $fieldtitles->{$fields->[$i]}.'</label></span></td>';
1.3 raeburn 6753: }
6754: $datatable .= '</tr></table></td></tr>';
6755: }
6756: }
6757: return $datatable;
1.1 raeburn 6758: }
6759:
6760: sub modify_login {
1.205 raeburn 6761: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.168 raeburn 6762: my ($resulttext,$errors,$colchgtext,%changes,%colchanges,%newfile,%newurl,
6763: %curr_loginvia,%loginhash,@currlangs,@newlangs,$addedfile,%title,@offon);
6764: %title = ( coursecatalog => 'Display course catalog',
6765: adminmail => 'Display administrator E-mail address',
1.188 raeburn 6766: helpdesk => 'Display "Contact Helpdesk" link',
1.168 raeburn 6767: newuser => 'Link for visitors to create a user account',
6768: loginheader => 'Log-in box header');
6769: @offon = ('off','on');
1.112 raeburn 6770: if (ref($domconfig{login}) eq 'HASH') {
6771: if (ref($domconfig{login}{loginvia}) eq 'HASH') {
6772: foreach my $lonhost (keys(%{$domconfig{login}{loginvia}})) {
6773: $curr_loginvia{$lonhost} = $domconfig{login}{loginvia}{$lonhost};
6774: }
6775: }
6776: }
1.9 raeburn 6777: ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
6778: \%domconfig,\%loginhash);
1.188 raeburn 6779: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 6780: foreach my $item (@toggles) {
6781: $loginhash{login}{$item} = $env{'form.'.$item};
6782: }
1.41 raeburn 6783: $loginhash{login}{loginheader} = $env{'form.loginheader'};
1.6 raeburn 6784: if (ref($colchanges{'login'}) eq 'HASH') {
6785: $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
6786: \%loginhash);
6787: }
1.110 raeburn 6788:
1.149 raeburn 6789: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.256 raeburn 6790: my %domservers = &Apache::lonnet::get_servers($dom);
1.128 raeburn 6791: my @loginvia_attribs = ('serverpath','custompath','exempt');
1.110 raeburn 6792: if (keys(%servers) > 1) {
6793: foreach my $lonhost (keys(%servers)) {
1.128 raeburn 6794: next if ($env{'form.'.$lonhost.'_server'} eq $lonhost);
6795: if (ref($curr_loginvia{$lonhost}) eq 'HASH') {
6796: if ($env{'form.'.$lonhost.'_server'} eq $curr_loginvia{$lonhost}{'server'}) {
6797: $loginhash{login}{loginvia}{$lonhost}{'server'} = $curr_loginvia{$lonhost}{'server'};
6798: } elsif ($curr_loginvia{$lonhost}{'server'} ne '') {
6799: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
6800: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
6801: $changes{'loginvia'}{$lonhost} = 1;
6802: } else {
6803: $loginhash{login}{loginvia}{$lonhost}{'server'} = '';
6804: $changes{'loginvia'}{$lonhost} = 1;
6805: }
6806: } else {
6807: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
6808: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
6809: $changes{'loginvia'}{$lonhost} = 1;
6810: }
6811: }
6812: if ($loginhash{login}{loginvia}{$lonhost}{'server'} eq '') {
6813: foreach my $item (@loginvia_attribs) {
6814: $loginhash{login}{loginvia}{$lonhost}{$item} = '';
6815: }
6816: } else {
6817: foreach my $item (@loginvia_attribs) {
6818: my $new = $env{'form.'.$lonhost.'_'.$item};
6819: if (($item eq 'serverpath') && ($new eq 'custom')) {
6820: $env{'form.'.$lonhost.'_custompath'} =~ s/\s+//g;
6821: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
6822: $new = '/';
6823: }
6824: }
6825: if (($item eq 'custompath') &&
6826: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
6827: $new = '';
6828: }
6829: if ($new ne $curr_loginvia{$lonhost}{$item}) {
6830: $changes{'loginvia'}{$lonhost} = 1;
6831: }
6832: if ($item eq 'exempt') {
1.256 raeburn 6833: $new = &check_exempt_addresses($new);
1.128 raeburn 6834: }
6835: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
6836: }
6837: }
1.112 raeburn 6838: } else {
1.128 raeburn 6839: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
6840: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
1.112 raeburn 6841: $changes{'loginvia'}{$lonhost} = 1;
1.128 raeburn 6842: foreach my $item (@loginvia_attribs) {
6843: my $new = $env{'form.'.$lonhost.'_'.$item};
6844: if (($item eq 'serverpath') && ($new eq 'custom')) {
6845: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
6846: $new = '/';
6847: }
6848: }
6849: if (($item eq 'custompath') &&
6850: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
6851: $new = '';
6852: }
6853: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
6854: }
1.110 raeburn 6855: }
6856: }
6857: }
6858: }
1.119 raeburn 6859:
1.168 raeburn 6860: my $servadm = $r->dir_config('lonAdmEMail');
6861: my %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
6862: if (ref($domconfig{'login'}) eq 'HASH') {
6863: if (ref($domconfig{'login'}{'helpurl'}) eq 'HASH') {
6864: foreach my $lang (sort(keys(%{$domconfig{'login'}{'helpurl'}}))) {
6865: if ($lang eq 'nolang') {
6866: push(@currlangs,$lang);
6867: } elsif (defined($langchoices{$lang})) {
6868: push(@currlangs,$lang);
6869: } else {
6870: next;
6871: }
6872: }
6873: }
6874: }
6875: my @delurls = &Apache::loncommon::get_env_multiple('form.loginhelpurl_del');
6876: if (@currlangs > 0) {
6877: foreach my $lang (@currlangs) {
6878: if (grep(/^\Q$lang\E$/,@delurls)) {
6879: $changes{'helpurl'}{$lang} = 1;
6880: } elsif ($env{'form.loginhelpurl_'.$lang.'.filename'}) {
6881: $changes{'helpurl'}{$lang} = 1;
6882: $newfile{$lang} = $env{'form.loginhelpurl_'.$lang.'.filename'};
6883: push(@newlangs,$lang);
6884: } else {
6885: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
6886: }
6887: }
6888: }
6889: unless (grep(/^nolang$/,@currlangs)) {
6890: if ($env{'form.loginhelpurl_nolang.filename'}) {
6891: $changes{'helpurl'}{'nolang'} = 1;
6892: $newfile{'nolang'} = $env{'form.loginhelpurl_nolang.filename'};
6893: push(@newlangs,'nolang');
6894: }
6895: }
6896: if ($env{'form.loginhelpurl_add_lang'}) {
6897: if ((defined($langchoices{$env{'form.loginhelpurl_add_lang'}})) &&
6898: ($env{'form.loginhelpurl_add_file.filename'})) {
6899: $newfile{$env{'form.loginhelpurl_add_lang'}} = $env{'form.loginhelpurl_add_file.filename'};
6900: $addedfile = $env{'form.loginhelpurl_add_lang'};
6901: }
6902: }
6903: if ((@newlangs > 0) || ($addedfile)) {
6904: my $error;
6905: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
6906: if ($configuserok eq 'ok') {
6907: if ($switchserver) {
6908: $error = &mt("Upload of custom help file is not permitted to this server: [_1]",$switchserver);
6909: } elsif ($author_ok eq 'ok') {
6910: my @allnew = @newlangs;
6911: if ($addedfile ne '') {
6912: push(@allnew,$addedfile);
6913: }
6914: foreach my $lang (@allnew) {
6915: my $formelem = 'loginhelpurl_'.$lang;
6916: if ($lang eq $env{'form.loginhelpurl_add_lang'}) {
6917: $formelem = 'loginhelpurl_add_file';
6918: }
6919: (my $result,$newurl{$lang}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
6920: "help/$lang",'','',$newfile{$lang});
6921: if ($result eq 'ok') {
6922: $loginhash{'login'}{'helpurl'}{$lang} = $newurl{$lang};
6923: $changes{'helpurl'}{$lang} = 1;
6924: } else {
6925: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$newfile{$lang},$result);
6926: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
1.210 raeburn 6927: if ((grep(/^\Q$lang\E$/,@currlangs)) &&
1.168 raeburn 6928: (!grep(/^\Q$lang\E$/,@delurls))) {
6929: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
6930: }
6931: }
6932: }
6933: } else {
6934: $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);
6935: }
6936: } else {
6937: $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);
6938: }
6939: if ($error) {
6940: &Apache::lonnet::logthis($error);
6941: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
6942: }
6943: }
1.256 raeburn 6944:
6945: my (%currheadtagurls,%currexempt,@newhosts,%newheadtagurls,%possexempt);
6946: if (ref($domconfig{'login'}) eq 'HASH') {
6947: if (ref($domconfig{'login'}{'headtag'}) eq 'HASH') {
6948: foreach my $lonhost (keys(%{$domconfig{'login'}{'headtag'}})) {
6949: if ($domservers{$lonhost}) {
6950: if (ref($domconfig{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
6951: $currheadtagurls{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'url'};
1.268 raeburn 6952: $currexempt{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'exempt'};
1.256 raeburn 6953: }
6954: }
6955: }
6956: }
6957: }
6958: my @delheadtagurls = &Apache::loncommon::get_env_multiple('form.loginheadtag_del');
6959: foreach my $lonhost (sort(keys(%domservers))) {
6960: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
6961: $changes{'headtag'}{$lonhost} = 1;
6962: } else {
6963: if ($env{'form.loginheadtagexempt_'.$lonhost}) {
6964: $possexempt{$lonhost} = &check_exempt_addresses($env{'form.loginheadtagexempt_'.$lonhost});
6965: }
6966: if ($env{'form.loginheadtag_'.$lonhost.'.filename'}) {
6967: push(@newhosts,$lonhost);
6968: } elsif ($currheadtagurls{$lonhost}) {
6969: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $currheadtagurls{$lonhost};
6970: if ($currexempt{$lonhost}) {
6971: if ((!exists($possexempt{$lonhost})) || ($possexempt{$lonhost} ne $currexempt{$lonhost})) {
6972: $changes{'headtag'}{$lonhost} = 1;
6973: }
6974: } elsif ($possexempt{$lonhost}) {
6975: $changes{'headtag'}{$lonhost} = 1;
6976: }
6977: if ($possexempt{$lonhost}) {
6978: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
6979: }
6980: }
6981: }
6982: }
6983: if (@newhosts) {
6984: my $error;
6985: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
6986: if ($configuserok eq 'ok') {
6987: if ($switchserver) {
6988: $error = &mt("Upload of custom markup is not permitted to this server: [_1]",$switchserver);
6989: } elsif ($author_ok eq 'ok') {
6990: foreach my $lonhost (@newhosts) {
6991: my $formelem = 'loginheadtag_'.$lonhost;
6992: (my $result,$newheadtagurls{$lonhost}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
6993: "login/headtag/$lonhost",'','',
6994: $env{'form.loginheadtag_'.$lonhost.'.filename'});
6995: if ($result eq 'ok') {
6996: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $newheadtagurls{$lonhost};
6997: $changes{'headtag'}{$lonhost} = 1;
6998: if ($possexempt{$lonhost}) {
6999: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
7000: }
7001: } else {
7002: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",
7003: $newheadtagurls{$lonhost},$result);
7004: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
7005: if ((grep(/^\Q$lonhost\E$/,keys(%currheadtagurls))) &&
7006: (!grep(/^\Q$lonhost\E$/,@delheadtagurls))) {
7007: $loginhash{'login'}{'headtag'}{$lonhost} = $currheadtagurls{$lonhost};
7008: }
7009: }
7010: }
7011: } else {
7012: $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);
7013: }
7014: } else {
7015: $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);
7016: }
7017: if ($error) {
7018: &Apache::lonnet::logthis($error);
7019: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
7020: }
7021: }
1.169 raeburn 7022: &process_captcha('login',\%changes,$loginhash{'login'},$domconfig{'login'});
1.168 raeburn 7023:
7024: my $defaulthelpfile = '/adm/loginproblems.html';
7025: my $defaulttext = &mt('Default in use');
7026:
1.1 raeburn 7027: my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
7028: $dom);
7029: if ($putresult eq 'ok') {
1.188 raeburn 7030: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 7031: my %defaultchecked = (
7032: 'coursecatalog' => 'on',
1.188 raeburn 7033: 'helpdesk' => 'on',
1.42 raeburn 7034: 'adminmail' => 'off',
1.43 raeburn 7035: 'newuser' => 'off',
1.42 raeburn 7036: );
1.55 raeburn 7037: if (ref($domconfig{'login'}) eq 'HASH') {
7038: foreach my $item (@toggles) {
7039: if ($defaultchecked{$item} eq 'on') {
7040: if (($domconfig{'login'}{$item} eq '0') &&
7041: ($env{'form.'.$item} eq '1')) {
7042: $changes{$item} = 1;
7043: } elsif (($domconfig{'login'}{$item} eq '' ||
7044: $domconfig{'login'}{$item} eq '1') &&
7045: ($env{'form.'.$item} eq '0')) {
7046: $changes{$item} = 1;
7047: }
7048: } elsif ($defaultchecked{$item} eq 'off') {
7049: if (($domconfig{'login'}{$item} eq '1') &&
7050: ($env{'form.'.$item} eq '0')) {
7051: $changes{$item} = 1;
7052: } elsif (($domconfig{'login'}{$item} eq '' ||
7053: $domconfig{'login'}{$item} eq '0') &&
7054: ($env{'form.'.$item} eq '1')) {
7055: $changes{$item} = 1;
7056: }
1.42 raeburn 7057: }
7058: }
1.41 raeburn 7059: }
1.6 raeburn 7060: if (keys(%changes) > 0 || $colchgtext) {
1.41 raeburn 7061: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 7062: if (ref($lastactref) eq 'HASH') {
7063: $lastactref->{'domainconfig'} = 1;
7064: }
1.1 raeburn 7065: $resulttext = &mt('Changes made:').'<ul>';
7066: foreach my $item (sort(keys(%changes))) {
1.135 bisitz 7067: if ($item eq 'loginvia') {
1.112 raeburn 7068: if (ref($changes{$item}) eq 'HASH') {
7069: $resulttext .= '<li>'.&mt('Log-in page availability:').'<ul>';
7070: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
1.128 raeburn 7071: if (defined($servers{$loginhash{login}{loginvia}{$lonhost}{'server'}})) {
7072: if (ref($loginhash{login}{loginvia}{$lonhost}) eq 'HASH') {
7073: my $protocol = $Apache::lonnet::protocol{$env{'form.'.$lonhost.'_server'}};
7074: $protocol = 'http' if ($protocol ne 'https');
7075: my $target = $protocol.'://'.$servers{$env{'form.'.$lonhost.'_server'}};
7076:
7077: if ($loginhash{login}{loginvia}{$lonhost}{'serverpath'} eq 'custom') {
7078: $target .= $loginhash{login}{loginvia}{$lonhost}{'custompath'};
7079: } else {
7080: $target .= $loginhash{login}{loginvia}{$lonhost}{'serverpath'};
7081: }
7082: $resulttext .= '<li>'.&mt('Server: [_1] log-in page redirects to [_2].',$servers{$lonhost},'<a href="'.$target.'">'.$target.'</a>');
7083: if ($loginhash{login}{loginvia}{$lonhost}{'exempt'} ne '') {
7084: $resulttext .= ' '.&mt('No redirection for clients from following IPs:').' '.$loginhash{login}{loginvia}{$lonhost}{'exempt'};
7085: }
7086: $resulttext .= '</li>';
7087: } else {
7088: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$lonhost).'</li>';
7089: }
1.112 raeburn 7090: } else {
1.128 raeburn 7091: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$servers{$lonhost}).'</li>';
1.112 raeburn 7092: }
7093: }
1.128 raeburn 7094: $resulttext .= '</ul></li>';
1.112 raeburn 7095: }
1.168 raeburn 7096: } elsif ($item eq 'helpurl') {
7097: if (ref($changes{$item}) eq 'HASH') {
7098: foreach my $lang (sort(keys(%{$changes{$item}}))) {
7099: if (grep(/^\Q$lang\E$/,@delurls)) {
7100: my ($chg,$link);
7101: $link = &Apache::loncommon::modal_link($defaulthelpfile,$defaulttext,600,500);
7102: if ($lang eq 'nolang') {
7103: $chg = &mt('custom log-in help file removed for no preferred language; [_1]',$link);
7104: } else {
7105: $chg = &mt('custom log-in help file removed for specific language: [_1]; [_2]',$langchoices{$lang},$link);
7106: }
7107: $resulttext .= '<li>'.$chg.'</li>';
7108: } else {
7109: my $chg;
7110: if ($lang eq 'nolang') {
7111: $chg = &mt('custom log-in help file for no preferred language');
7112: } else {
7113: $chg = &mt('custom log-in help file for specific language: [_1]',$langchoices{$lang});
7114: }
7115: $resulttext .= '<li>'.&Apache::loncommon::modal_link(
7116: $loginhash{'login'}{'helpurl'}{$lang}.
7117: '?inhibitmenu=yes',$chg,600,500).
7118: '</li>';
7119: }
7120: }
7121: }
1.256 raeburn 7122: } elsif ($item eq 'headtag') {
7123: if (ref($changes{$item}) eq 'HASH') {
7124: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
7125: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
7126: $resulttext .= '<li>'.&mt('custom markup file removed for [_1]',$domservers{$lonhost}).'</li>';
7127: } elsif (ref($loginhash{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
7128: $resulttext .= '<li><a href="'.
7129: "javascript:void(open('$loginhash{'login'}{'headtag'}{$lonhost}{'url'}?inhibitmenu=yes','Custom_HeadTag',
7130: 'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
7131: '">'.&mt('custom markup').'</a> '.&mt('(for [_1])',$servers{$lonhost}).' ';
7132: if ($possexempt{$lonhost}) {
7133: $resulttext .= &mt('not included for client IP(s): [_1]',$possexempt{$lonhost});
7134: } else {
7135: $resulttext .= &mt('included for any client IP');
7136: }
7137: $resulttext .= '</li>';
7138: }
7139: }
7140: }
1.169 raeburn 7141: } elsif ($item eq 'captcha') {
7142: if (ref($loginhash{'login'}) eq 'HASH') {
1.210 raeburn 7143: my $chgtxt;
1.169 raeburn 7144: if ($loginhash{'login'}{$item} eq 'notused') {
7145: $chgtxt .= &mt('No CAPTCHA validation in use for helpdesk form.');
7146: } else {
7147: my %captchas = &captcha_phrases();
7148: if ($captchas{$loginhash{'login'}{$item}}) {
7149: $chgtxt .= &mt("Validation for helpdesk form set to $captchas{$loginhash{'login'}{$item}}.");
7150: } else {
7151: $chgtxt .= &mt('Validation for helpdesk form set to unknown type.');
7152: }
7153: }
7154: $resulttext .= '<li>'.$chgtxt.'</li>';
7155: }
7156: } elsif ($item eq 'recaptchakeys') {
7157: if (ref($loginhash{'login'}) eq 'HASH') {
7158: my ($privkey,$pubkey);
7159: if (ref($loginhash{'login'}{$item}) eq 'HASH') {
7160: $pubkey = $loginhash{'login'}{$item}{'public'};
7161: $privkey = $loginhash{'login'}{$item}{'private'};
7162: }
7163: my $chgtxt .= &mt('ReCAPTCHA keys changes').'<ul>';
7164: if (!$pubkey) {
7165: $chgtxt .= '<li>'.&mt('Public key deleted').'</li>';
7166: } else {
7167: $chgtxt .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
7168: }
7169: if (!$privkey) {
7170: $chgtxt .= '<li>'.&mt('Private key deleted').'</li>';
7171: } else {
1.251 raeburn 7172: $chgtxt .= '<li>'.&mt('Private key set to [_1]',$privkey).'</li>';
1.169 raeburn 7173: }
7174: $chgtxt .= '</ul>';
7175: $resulttext .= '<li>'.$chgtxt.'</li>';
7176: }
1.269 raeburn 7177: } elsif ($item eq 'recaptchaversion') {
7178: if (ref($loginhash{'login'}) eq 'HASH') {
7179: if ($loginhash{'login'}{'captcha'} eq 'recaptcha') {
1.270 raeburn 7180: $resulttext .= '<li>'.&mt('ReCAPTCHA for helpdesk form set to version [_1]',$loginhash{'login'}{'recaptchaversion'}).
1.269 raeburn 7181: '</li>';
7182: }
7183: }
1.41 raeburn 7184: } else {
7185: $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
7186: }
1.1 raeburn 7187: }
1.6 raeburn 7188: $resulttext .= $colchgtext.'</ul>';
1.1 raeburn 7189: } else {
7190: $resulttext = &mt('No changes made to log-in page settings');
7191: }
7192: } else {
1.11 albertel 7193: $resulttext = '<span class="LC_error">'.
7194: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 7195: }
1.6 raeburn 7196: if ($errors) {
1.9 raeburn 7197: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.6 raeburn 7198: $errors.'</ul>';
7199: }
7200: return $resulttext;
7201: }
7202:
1.256 raeburn 7203:
7204: sub check_exempt_addresses {
7205: my ($iplist) = @_;
7206: $iplist =~ s/^\s+//;
7207: $iplist =~ s/\s+$//;
7208: my @poss_ips = split(/\s*[,:]\s*/,$iplist);
7209: my (@okips,$new);
7210: foreach my $ip (@poss_ips) {
7211: if ($ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
7212: if (($1 <= 255) && ($2 <= 255) && ($3 <= 255) && ($4 <= 255)) {
7213: push(@okips,$ip);
7214: }
7215: }
7216: }
7217: if (@okips > 0) {
7218: $new = join(',',@okips);
7219: } else {
7220: $new = '';
7221: }
7222: return $new;
7223: }
7224:
1.6 raeburn 7225: sub color_font_choices {
7226: my %choices =
7227: &Apache::lonlocal::texthash (
7228: img => "Header",
7229: bgs => "Background colors",
7230: links => "Link colors",
1.55 raeburn 7231: images => "Images",
1.6 raeburn 7232: font => "Font color",
1.201 raeburn 7233: fontmenu => "Font menu",
1.76 raeburn 7234: pgbg => "Page",
1.6 raeburn 7235: tabbg => "Header",
7236: sidebg => "Border",
7237: link => "Link",
7238: alink => "Active link",
7239: vlink => "Visited link",
7240: );
7241: return %choices;
7242: }
7243:
7244: sub modify_rolecolors {
1.205 raeburn 7245: my ($r,$dom,$confname,$roles,$lastactref,%domconfig) = @_;
1.6 raeburn 7246: my ($resulttext,%rolehash);
7247: $rolehash{'rolecolors'} = {};
1.55 raeburn 7248: if (ref($domconfig{'rolecolors'}) ne 'HASH') {
7249: if ($domconfig{'rolecolors'} eq '') {
7250: $domconfig{'rolecolors'} = {};
7251: }
7252: }
1.9 raeburn 7253: my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
1.6 raeburn 7254: $domconfig{'rolecolors'},$rolehash{'rolecolors'});
7255: my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
7256: $dom);
7257: if ($putresult eq 'ok') {
7258: if (keys(%changes) > 0) {
1.41 raeburn 7259: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 7260: if (ref($lastactref) eq 'HASH') {
7261: $lastactref->{'domainconfig'} = 1;
7262: }
1.6 raeburn 7263: $resulttext = &display_colorchgs($dom,\%changes,$roles,
7264: $rolehash{'rolecolors'});
7265: } else {
7266: $resulttext = &mt('No changes made to default color schemes');
7267: }
7268: } else {
1.11 albertel 7269: $resulttext = '<span class="LC_error">'.
7270: &mt('An error occurred: [_1]',$putresult).'</span>';
1.6 raeburn 7271: }
7272: if ($errors) {
7273: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
7274: $errors.'</ul>';
7275: }
7276: return $resulttext;
7277: }
7278:
7279: sub modify_colors {
1.9 raeburn 7280: my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
1.12 raeburn 7281: my (%changes,%choices);
1.51 raeburn 7282: my @bgs;
1.6 raeburn 7283: my @links = ('link','alink','vlink');
1.41 raeburn 7284: my @logintext;
1.6 raeburn 7285: my @images;
7286: my $servadm = $r->dir_config('lonAdmEMail');
7287: my $errors;
1.200 raeburn 7288: my %defaults;
1.6 raeburn 7289: foreach my $role (@{$roles}) {
7290: if ($role eq 'login') {
1.12 raeburn 7291: %choices = &login_choices();
1.41 raeburn 7292: @logintext = ('textcol','bgcol');
1.12 raeburn 7293: } else {
7294: %choices = &color_font_choices();
7295: }
7296: if ($role eq 'login') {
1.41 raeburn 7297: @images = ('img','logo','domlogo','login');
1.51 raeburn 7298: @bgs = ('pgbg','mainbg','sidebg');
1.6 raeburn 7299: } else {
7300: @images = ('img');
1.200 raeburn 7301: @bgs = ('pgbg','tabbg','sidebg');
7302: }
7303: my %defaults = &role_defaults($role,\@bgs,\@links,\@images,\@logintext);
7304: unless ($env{'form.'.$role.'_font'} eq $defaults{'font'}) {
7305: $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
7306: }
7307: if ($role eq 'login') {
7308: foreach my $item (@logintext) {
1.234 raeburn 7309: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
7310: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
7311: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
7312: }
7313: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'logintext'}{$item})) {
1.200 raeburn 7314: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
7315: }
7316: }
7317: } else {
1.234 raeburn 7318: $env{'form.'.$role.'_fontmenu'} = lc($env{'form.'.$role.'_fontmenu'});
7319: if ($env{'form.'.$role.'_fontmenu'} =~ /^\w+/) {
7320: $env{'form.'.$role.'_fontmenu'} = '#'.$env{'form.'.$role.'_fontmenu'};
7321: }
7322: unless($env{'form.'.$role.'_fontmenu'} eq lc($defaults{'fontmenu'})) {
1.200 raeburn 7323: $confhash->{$role}{'fontmenu'} = $env{'form.'.$role.'_fontmenu'};
7324: }
1.6 raeburn 7325: }
1.200 raeburn 7326: foreach my $item (@bgs) {
1.234 raeburn 7327: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
7328: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
7329: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
7330: }
7331: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'bgs'}{$item})) {
1.200 raeburn 7332: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
7333: }
7334: }
7335: foreach my $item (@links) {
1.234 raeburn 7336: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
7337: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
7338: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
7339: }
7340: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'links'}{$item})) {
1.200 raeburn 7341: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
7342: }
1.6 raeburn 7343: }
1.46 raeburn 7344: my ($configuserok,$author_ok,$switchserver) =
7345: &config_check($dom,$confname,$servadm);
1.9 raeburn 7346: my ($width,$height) = &thumb_dimensions();
1.40 raeburn 7347: if (ref($domconfig->{$role}) ne 'HASH') {
7348: $domconfig->{$role} = {};
7349: }
1.8 raeburn 7350: foreach my $img (@images) {
1.70 raeburn 7351: if (($role eq 'login') && (($img eq 'img') || ($img eq 'logo'))) {
7352: if (defined($env{'form.login_showlogo_'.$img})) {
7353: $confhash->{$role}{'showlogo'}{$img} = 1;
7354: } else {
7355: $confhash->{$role}{'showlogo'}{$img} = 0;
7356: }
7357: }
1.18 albertel 7358: if ( ! $env{'form.'.$role.'_'.$img.'.filename'}
7359: && !defined($domconfig->{$role}{$img})
7360: && !$env{'form.'.$role.'_del_'.$img}
7361: && $env{'form.'.$role.'_import_'.$img}) {
7362: # import the old configured image from the .tab setting
7363: # if they haven't provided a new one
7364: $domconfig->{$role}{$img} =
7365: $env{'form.'.$role.'_import_'.$img};
7366: }
1.6 raeburn 7367: if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
1.9 raeburn 7368: my $error;
1.6 raeburn 7369: if ($configuserok eq 'ok') {
1.9 raeburn 7370: if ($switchserver) {
1.12 raeburn 7371: $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
1.9 raeburn 7372: } else {
7373: if ($author_ok eq 'ok') {
7374: my ($result,$logourl) =
7375: &publishlogo($r,'upload',$role.'_'.$img,
7376: $dom,$confname,$img,$width,$height);
7377: if ($result eq 'ok') {
7378: $confhash->{$role}{$img} = $logourl;
1.12 raeburn 7379: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 7380: } else {
1.12 raeburn 7381: $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 7382: }
7383: } else {
1.46 raeburn 7384: $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 7385: }
7386: }
7387: } else {
1.46 raeburn 7388: $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 7389: }
7390: if ($error) {
1.8 raeburn 7391: &Apache::lonnet::logthis($error);
1.11 albertel 7392: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
1.8 raeburn 7393: }
7394: } elsif ($domconfig->{$role}{$img} ne '') {
1.9 raeburn 7395: if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
7396: my $error;
7397: if ($configuserok eq 'ok') {
7398: # is confname an author?
7399: if ($switchserver eq '') {
7400: if ($author_ok eq 'ok') {
7401: my ($result,$logourl) =
7402: &publishlogo($r,'copy',$domconfig->{$role}{$img},
7403: $dom,$confname,$img,$width,$height);
7404: if ($result eq 'ok') {
7405: $confhash->{$role}{$img} = $logourl;
1.18 albertel 7406: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 7407: }
7408: }
7409: }
7410: }
1.6 raeburn 7411: }
7412: }
7413: }
7414: if (ref($domconfig) eq 'HASH') {
7415: if (ref($domconfig->{$role}) eq 'HASH') {
7416: foreach my $img (@images) {
7417: if ($domconfig->{$role}{$img} ne '') {
7418: if ($env{'form.'.$role.'_del_'.$img}) {
7419: $confhash->{$role}{$img} = '';
1.12 raeburn 7420: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 7421: } else {
1.9 raeburn 7422: if ($confhash->{$role}{$img} eq '') {
7423: $confhash->{$role}{$img} = $domconfig->{$role}{$img};
7424: }
1.6 raeburn 7425: }
7426: } else {
7427: if ($env{'form.'.$role.'_del_'.$img}) {
7428: $confhash->{$role}{$img} = '';
1.12 raeburn 7429: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 7430: }
7431: }
1.70 raeburn 7432: if (($role eq 'login') && (($img eq 'logo') || ($img eq 'img'))) {
7433: if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') {
7434: if ($confhash->{$role}{'showlogo'}{$img} ne
7435: $domconfig->{$role}{'showlogo'}{$img}) {
7436: $changes{$role}{'showlogo'}{$img} = 1;
7437: }
7438: } else {
7439: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
7440: $changes{$role}{'showlogo'}{$img} = 1;
7441: }
7442: }
7443: }
7444: }
1.6 raeburn 7445: if ($domconfig->{$role}{'font'} ne '') {
7446: if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
7447: $changes{$role}{'font'} = 1;
7448: }
7449: } else {
7450: if ($confhash->{$role}{'font'}) {
7451: $changes{$role}{'font'} = 1;
7452: }
7453: }
1.107 raeburn 7454: if ($role ne 'login') {
7455: if ($domconfig->{$role}{'fontmenu'} ne '') {
7456: if ($confhash->{$role}{'fontmenu'} ne $domconfig->{$role}{'fontmenu'}) {
7457: $changes{$role}{'fontmenu'} = 1;
7458: }
7459: } else {
7460: if ($confhash->{$role}{'fontmenu'}) {
7461: $changes{$role}{'fontmenu'} = 1;
7462: }
1.97 tempelho 7463: }
7464: }
1.6 raeburn 7465: foreach my $item (@bgs) {
7466: if ($domconfig->{$role}{$item} ne '') {
7467: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
7468: $changes{$role}{'bgs'}{$item} = 1;
7469: }
7470: } else {
7471: if ($confhash->{$role}{$item}) {
7472: $changes{$role}{'bgs'}{$item} = 1;
7473: }
7474: }
7475: }
7476: foreach my $item (@links) {
7477: if ($domconfig->{$role}{$item} ne '') {
7478: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
7479: $changes{$role}{'links'}{$item} = 1;
7480: }
7481: } else {
7482: if ($confhash->{$role}{$item}) {
7483: $changes{$role}{'links'}{$item} = 1;
7484: }
7485: }
7486: }
1.41 raeburn 7487: foreach my $item (@logintext) {
7488: if ($domconfig->{$role}{$item} ne '') {
7489: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
7490: $changes{$role}{'logintext'}{$item} = 1;
7491: }
7492: } else {
7493: if ($confhash->{$role}{$item}) {
7494: $changes{$role}{'logintext'}{$item} = 1;
7495: }
7496: }
7497: }
1.6 raeburn 7498: } else {
7499: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 7500: \@logintext,$confhash,\%changes);
1.6 raeburn 7501: }
7502: } else {
7503: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 7504: \@logintext,$confhash,\%changes);
1.6 raeburn 7505: }
7506: }
7507: return ($errors,%changes);
7508: }
7509:
1.46 raeburn 7510: sub config_check {
7511: my ($dom,$confname,$servadm) = @_;
7512: my ($configuserok,$author_ok,$switchserver,%currroles);
7513: my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
7514: ($configuserok,%currroles) = &check_configuser($uhome,$dom,
7515: $confname,$servadm);
7516: if ($configuserok eq 'ok') {
7517: $switchserver = &check_switchserver($dom,$confname);
7518: if ($switchserver eq '') {
7519: $author_ok = &check_authorstatus($dom,$confname,%currroles);
7520: }
7521: }
7522: return ($configuserok,$author_ok,$switchserver);
7523: }
7524:
1.6 raeburn 7525: sub default_change_checker {
1.41 raeburn 7526: my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
1.6 raeburn 7527: foreach my $item (@{$links}) {
7528: if ($confhash->{$role}{$item}) {
7529: $changes->{$role}{'links'}{$item} = 1;
7530: }
7531: }
7532: foreach my $item (@{$bgs}) {
7533: if ($confhash->{$role}{$item}) {
7534: $changes->{$role}{'bgs'}{$item} = 1;
7535: }
7536: }
1.41 raeburn 7537: foreach my $item (@{$logintext}) {
7538: if ($confhash->{$role}{$item}) {
7539: $changes->{$role}{'logintext'}{$item} = 1;
7540: }
7541: }
1.6 raeburn 7542: foreach my $img (@{$images}) {
7543: if ($env{'form.'.$role.'_del_'.$img}) {
7544: $confhash->{$role}{$img} = '';
1.12 raeburn 7545: $changes->{$role}{'images'}{$img} = 1;
1.6 raeburn 7546: }
1.70 raeburn 7547: if ($role eq 'login') {
7548: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
7549: $changes->{$role}{'showlogo'}{$img} = 1;
7550: }
7551: }
1.6 raeburn 7552: }
7553: if ($confhash->{$role}{'font'}) {
7554: $changes->{$role}{'font'} = 1;
7555: }
1.48 raeburn 7556: }
1.6 raeburn 7557:
7558: sub display_colorchgs {
7559: my ($dom,$changes,$roles,$confhash) = @_;
7560: my (%choices,$resulttext);
7561: if (!grep(/^login$/,@{$roles})) {
7562: $resulttext = &mt('Changes made:').'<br />';
7563: }
7564: foreach my $role (@{$roles}) {
7565: if ($role eq 'login') {
7566: %choices = &login_choices();
7567: } else {
7568: %choices = &color_font_choices();
7569: }
7570: if (ref($changes->{$role}) eq 'HASH') {
7571: if ($role ne 'login') {
7572: $resulttext .= '<h4>'.&mt($role).'</h4>';
7573: }
7574: foreach my $key (sort(keys(%{$changes->{$role}}))) {
7575: if ($role ne 'login') {
7576: $resulttext .= '<ul>';
7577: }
7578: if (ref($changes->{$role}{$key}) eq 'HASH') {
7579: if ($role ne 'login') {
7580: $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
7581: }
7582: foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
1.70 raeburn 7583: if (($role eq 'login') && ($key eq 'showlogo')) {
7584: if ($confhash->{$role}{$key}{$item}) {
7585: $resulttext .= '<li>'.&mt("$choices{$item} set to be displayed").'</li>';
7586: } else {
7587: $resulttext .= '<li>'.&mt("$choices{$item} set to not be displayed").'</li>';
7588: }
7589: } elsif ($confhash->{$role}{$item} eq '') {
1.6 raeburn 7590: $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
7591: } else {
1.12 raeburn 7592: my $newitem = $confhash->{$role}{$item};
7593: if ($key eq 'images') {
7594: $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" valign="bottom" />';
7595: }
7596: $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
1.6 raeburn 7597: }
7598: }
7599: if ($role ne 'login') {
7600: $resulttext .= '</ul></li>';
7601: }
7602: } else {
7603: if ($confhash->{$role}{$key} eq '') {
7604: $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
7605: } else {
7606: $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
7607: }
7608: }
7609: if ($role ne 'login') {
7610: $resulttext .= '</ul>';
7611: }
7612: }
7613: }
7614: }
1.3 raeburn 7615: return $resulttext;
1.1 raeburn 7616: }
7617:
1.9 raeburn 7618: sub thumb_dimensions {
7619: return ('200','50');
7620: }
7621:
1.16 raeburn 7622: sub check_dimensions {
7623: my ($inputfile) = @_;
7624: my ($fullwidth,$fullheight);
7625: if ($inputfile =~ m|^[/\w.\-]+$|) {
7626: if (open(PIPE,"identify $inputfile 2>&1 |")) {
7627: my $imageinfo = <PIPE>;
7628: if (!close(PIPE)) {
7629: &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
7630: }
7631: chomp($imageinfo);
7632: my ($fullsize) =
1.21 raeburn 7633: ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
1.16 raeburn 7634: if ($fullsize) {
7635: ($fullwidth,$fullheight) = split(/x/,$fullsize);
7636: }
7637: }
7638: }
7639: return ($fullwidth,$fullheight);
7640: }
7641:
1.9 raeburn 7642: sub check_configuser {
7643: my ($uhome,$dom,$confname,$servadm) = @_;
7644: my ($configuserok,%currroles);
7645: if ($uhome eq 'no_host') {
7646: srand( time() ^ ($$ + ($$ << 15)) ); # Seed rand.
7647: my $configpass = &LONCAPA::Enrollment::create_password();
7648: $configuserok =
7649: &Apache::lonnet::modifyuser($dom,$confname,'','internal',
7650: $configpass,'','','','','',undef,$servadm);
7651: } else {
7652: $configuserok = 'ok';
7653: %currroles =
7654: &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
7655: }
7656: return ($configuserok,%currroles);
7657: }
7658:
7659: sub check_authorstatus {
7660: my ($dom,$confname,%currroles) = @_;
7661: my $author_ok;
1.40 raeburn 7662: if (!$currroles{':'.$dom.':au'}) {
1.9 raeburn 7663: my $start = time;
7664: my $end = 0;
7665: $author_ok =
7666: &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
1.47 raeburn 7667: 'au',$end,$start,'','','domconfig');
1.9 raeburn 7668: } else {
7669: $author_ok = 'ok';
7670: }
7671: return $author_ok;
7672: }
7673:
7674: sub publishlogo {
1.46 raeburn 7675: my ($r,$action,$formname,$dom,$confname,$subdir,$thumbwidth,$thumbheight,$savefileas) = @_;
1.267 raeburn 7676: my ($output,$fname,$logourl,$madethumb);
1.9 raeburn 7677: if ($action eq 'upload') {
7678: $fname=$env{'form.'.$formname.'.filename'};
7679: chop($env{'form.'.$formname});
7680: } else {
7681: ($fname) = ($formname =~ /([^\/]+)$/);
7682: }
1.46 raeburn 7683: if ($savefileas ne '') {
7684: $fname = $savefileas;
7685: }
1.9 raeburn 7686: $fname=&Apache::lonnet::clean_filename($fname);
7687: # See if there is anything left
7688: unless ($fname) { return ('error: no uploaded file'); }
7689: $fname="$subdir/$fname";
1.210 raeburn 7690: my $docroot=$r->dir_config('lonDocRoot');
1.164 raeburn 7691: my $filepath="$docroot/priv";
7692: my $relpath = "$dom/$confname";
1.9 raeburn 7693: my ($fnamepath,$file,$fetchthumb);
7694: $file=$fname;
7695: if ($fname=~m|/|) {
7696: ($fnamepath,$file) = ($fname =~ m|^(.*)/([^/]+)$|);
7697: }
1.164 raeburn 7698: my @parts=split(/\//,"$filepath/$relpath/$fnamepath");
1.9 raeburn 7699: my $count;
1.164 raeburn 7700: for ($count=5;$count<=$#parts;$count++) {
1.9 raeburn 7701: $filepath.="/$parts[$count]";
7702: if ((-e $filepath)!=1) {
7703: mkdir($filepath,02770);
7704: }
7705: }
7706: # Check for bad extension and disallow upload
7707: if ($file=~/\.(\w+)$/ &&
7708: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
7709: $output =
1.207 bisitz 7710: &mt('Invalid file extension ([_1]) - reserved for internal use.',$1);
1.9 raeburn 7711: } elsif ($file=~/\.(\w+)$/ &&
7712: !defined(&Apache::loncommon::fileembstyle($1))) {
7713: $output = &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
7714: } elsif ($file=~/\.(\d+)\.(\w+)$/) {
1.195 bisitz 7715: $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 7716: } elsif (-d "$filepath/$file") {
1.195 bisitz 7717: $output = &mt('Filename is a directory name - rename the file and re-upload');
1.9 raeburn 7718: } else {
7719: my $source = $filepath.'/'.$file;
7720: my $logfile;
7721: if (!open($logfile,">>$source".'.log')) {
1.196 raeburn 7722: return (&mt('No write permission to Authoring Space'));
1.9 raeburn 7723: }
7724: print $logfile
7725: "\n================= Publish ".localtime()." ================\n".
7726: $env{'user.name'}.':'.$env{'user.domain'}."\n";
7727: # Save the file
7728: if (!open(FH,'>'.$source)) {
7729: &Apache::lonnet::logthis('Failed to create '.$source);
7730: return (&mt('Failed to create file'));
7731: }
7732: if ($action eq 'upload') {
7733: if (!print FH ($env{'form.'.$formname})) {
7734: &Apache::lonnet::logthis('Failed to write to '.$source);
7735: return (&mt('Failed to write file'));
7736: }
7737: } else {
7738: my $original = &Apache::lonnet::filelocation('',$formname);
7739: if(!copy($original,$source)) {
7740: &Apache::lonnet::logthis('Failed to copy '.$original.' to '.$source);
7741: return (&mt('Failed to write file'));
7742: }
7743: }
7744: close(FH);
7745: chmod(0660, $source); # Permissions to rw-rw---.
7746:
7747: my $targetdir=$docroot.'/res/'.$dom.'/'.$confname .'/'.$fnamepath;
7748: my $copyfile=$targetdir.'/'.$file;
7749:
7750: my @parts=split(/\//,$targetdir);
7751: my $path="/$parts[1]/$parts[2]/$parts[3]/$parts[4]";
7752: for (my $count=5;$count<=$#parts;$count++) {
7753: $path.="/$parts[$count]";
7754: if (!-e $path) {
7755: print $logfile "\nCreating directory ".$path;
7756: mkdir($path,02770);
7757: }
7758: }
7759: my $versionresult;
7760: if (-e $copyfile) {
7761: $versionresult = &logo_versioning($targetdir,$file,$logfile);
7762: } else {
7763: $versionresult = 'ok';
7764: }
7765: if ($versionresult eq 'ok') {
7766: if (copy($source,$copyfile)) {
7767: print $logfile "\nCopied original source to ".$copyfile."\n";
7768: $output = 'ok';
7769: $logourl = '/res/'.$dom.'/'.$confname.'/'.$fname;
1.155 raeburn 7770: push(@{$modified_urls},[$copyfile,$source]);
7771: my $metaoutput =
7772: &write_metadata($dom,$confname,$formname,$targetdir,$file,$logfile);
7773: unless ($registered_cleanup) {
7774: my $handlers = $r->get_handlers('PerlCleanupHandler');
7775: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
7776: $registered_cleanup=1;
7777: }
1.9 raeburn 7778: } else {
7779: print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";
7780: $output = &mt('Failed to copy file to RES space').", $!";
7781: }
7782: if (($thumbwidth =~ /^\d+$/) && ($thumbheight =~ /^\d+$/)) {
7783: my $inputfile = $filepath.'/'.$file;
7784: my $outfile = $filepath.'/'.'tn-'.$file;
1.16 raeburn 7785: my ($fullwidth,$fullheight) = &check_dimensions($inputfile);
7786: if ($fullwidth ne '' && $fullheight ne '') {
7787: if ($fullwidth > $thumbwidth && $fullheight > $thumbheight) {
7788: my $thumbsize = $thumbwidth.'x'.$thumbheight;
7789: system("convert -sample $thumbsize $inputfile $outfile");
7790: chmod(0660, $filepath.'/tn-'.$file);
7791: if (-e $outfile) {
7792: my $copyfile=$targetdir.'/tn-'.$file;
7793: if (copy($outfile,$copyfile)) {
7794: print $logfile "\nCopied source to ".$copyfile."\n";
1.155 raeburn 7795: my $thumb_metaoutput =
7796: &write_metadata($dom,$confname,$formname,
7797: $targetdir,'tn-'.$file,$logfile);
7798: push(@{$modified_urls},[$copyfile,$outfile]);
7799: unless ($registered_cleanup) {
7800: my $handlers = $r->get_handlers('PerlCleanupHandler');
7801: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
7802: $registered_cleanup=1;
7803: }
1.267 raeburn 7804: $madethumb = 1;
1.16 raeburn 7805: } else {
7806: print $logfile "\nUnable to write ".$copyfile.
7807: ':'.$!."\n";
7808: }
7809: }
1.9 raeburn 7810: }
7811: }
7812: }
7813: } else {
7814: $output = $versionresult;
7815: }
7816: }
1.267 raeburn 7817: return ($output,$logourl,$madethumb);
1.9 raeburn 7818: }
7819:
7820: sub logo_versioning {
7821: my ($targetdir,$file,$logfile) = @_;
7822: my $target = $targetdir.'/'.$file;
7823: my ($maxversion,$fn,$extn,$output);
7824: $maxversion = 0;
7825: if ($file =~ /^(.+)\.(\w+)$/) {
7826: $fn=$1;
7827: $extn=$2;
7828: }
7829: opendir(DIR,$targetdir);
7830: while (my $filename=readdir(DIR)) {
7831: if ($filename=~/\Q$fn\E\.(\d+)\.\Q$extn\E$/) {
7832: $maxversion=($1>$maxversion)?$1:$maxversion;
7833: }
7834: }
7835: $maxversion++;
7836: print $logfile "\nCreating old version ".$maxversion."\n";
7837: my $copyfile=$targetdir.'/'.$fn.'.'.$maxversion.'.'.$extn;
7838: if (copy($target,$copyfile)) {
7839: print $logfile "Copied old target to ".$copyfile."\n";
7840: $copyfile=$copyfile.'.meta';
7841: if (copy($target.'.meta',$copyfile)) {
7842: print $logfile "Copied old target metadata to ".$copyfile."\n";
7843: $output = 'ok';
7844: } else {
7845: print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";
7846: $output = &mt('Failed to copy old meta').", $!, ";
7847: }
7848: } else {
7849: print $logfile "Unable to write ".$copyfile.':'.$!."\n";
7850: $output = &mt('Failed to copy old target').", $!, ";
7851: }
7852: return $output;
7853: }
7854:
7855: sub write_metadata {
7856: my ($dom,$confname,$formname,$targetdir,$file,$logfile) = @_;
7857: my (%metadatafields,%metadatakeys,$output);
7858: $metadatafields{'title'}=$formname;
7859: $metadatafields{'creationdate'}=time;
7860: $metadatafields{'lastrevisiondate'}=time;
7861: $metadatafields{'copyright'}='public';
7862: $metadatafields{'modifyinguser'}=$env{'user.name'}.':'.
7863: $env{'user.domain'};
7864: $metadatafields{'authorspace'}=$confname.':'.$dom;
7865: $metadatafields{'domain'}=$dom;
7866: {
7867: print $logfile "\nWrite metadata file for ".$targetdir.'/'.$file;
7868: my $mfh;
1.155 raeburn 7869: if (open($mfh,'>'.$targetdir.'/'.$file.'.meta')) {
1.184 raeburn 7870: foreach (sort(keys(%metadatafields))) {
1.155 raeburn 7871: unless ($_=~/\./) {
7872: my $unikey=$_;
7873: $unikey=~/^([A-Za-z]+)/;
7874: my $tag=$1;
7875: $tag=~tr/A-Z/a-z/;
7876: print $mfh "\n\<$tag";
7877: foreach (split(/\,/,$metadatakeys{$unikey})) {
7878: my $value=$metadatafields{$unikey.'.'.$_};
7879: $value=~s/\"/\'\'/g;
7880: print $mfh ' '.$_.'="'.$value.'"';
7881: }
7882: print $mfh '>'.
7883: &HTML::Entities::encode($metadatafields{$unikey},'<>&"')
7884: .'</'.$tag.'>';
7885: }
7886: }
7887: $output = 'ok';
7888: print $logfile "\nWrote metadata";
7889: close($mfh);
7890: } else {
7891: print $logfile "\nFailed to open metadata file";
1.9 raeburn 7892: $output = &mt('Could not write metadata');
7893: }
7894: }
1.155 raeburn 7895: return $output;
7896: }
7897:
7898: sub notifysubscribed {
7899: foreach my $targetsource (@{$modified_urls}){
7900: next unless (ref($targetsource) eq 'ARRAY');
7901: my ($target,$source)=@{$targetsource};
7902: if ($source ne '') {
7903: if (open(my $logfh,'>>'.$source.'.log')) {
7904: print $logfh "\nCleanup phase: Notifications\n";
7905: my @subscribed=&subscribed_hosts($target);
7906: foreach my $subhost (@subscribed) {
7907: print $logfh "\nNotifying host ".$subhost.':';
7908: my $reply=&Apache::lonnet::critical('update:'.$target,$subhost);
7909: print $logfh $reply;
7910: }
7911: my @subscribedmeta=&subscribed_hosts("$target.meta");
7912: foreach my $subhost (@subscribedmeta) {
7913: print $logfh "\nNotifying host for metadata only ".$subhost.':';
7914: my $reply=&Apache::lonnet::critical('update:'.$target.'.meta',
7915: $subhost);
7916: print $logfh $reply;
7917: }
7918: print $logfh "\n============ Done ============\n";
1.160 raeburn 7919: close($logfh);
1.155 raeburn 7920: }
7921: }
7922: }
7923: return OK;
7924: }
7925:
7926: sub subscribed_hosts {
7927: my ($target) = @_;
7928: my @subscribed;
7929: if (open(my $fh,"<$target.subscription")) {
7930: while (my $subline=<$fh>) {
7931: if ($subline =~ /^($match_lonid):/) {
7932: my $host = $1;
7933: if ($host ne $Apache::lonnet::perlvar{'lonHostID'}) {
7934: unless (grep(/^\Q$host\E$/,@subscribed)) {
7935: push(@subscribed,$host);
7936: }
7937: }
7938: }
7939: }
7940: }
7941: return @subscribed;
1.9 raeburn 7942: }
7943:
7944: sub check_switchserver {
7945: my ($dom,$confname) = @_;
7946: my ($allowed,$switchserver);
7947: my $home = &Apache::lonnet::homeserver($confname,$dom);
7948: if ($home eq 'no_host') {
7949: $home = &Apache::lonnet::domain($dom,'primary');
7950: }
7951: my @ids=&Apache::lonnet::current_machine_ids();
1.10 albertel 7952: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
7953: if (!$allowed) {
1.180 raeburn 7954: $switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role=dc./'.$dom.'/&destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
1.9 raeburn 7955: }
7956: return $switchserver;
7957: }
7958:
1.1 raeburn 7959: sub modify_quotas {
1.216 raeburn 7960: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
1.101 raeburn 7961: my ($context,@usertools,@options,%validations,%titles,%confhash,%toolshash,
1.216 raeburn 7962: %limithash,$toolregexp,%conditions,$resulttext,%changes,$confname,$configuserok,
1.235 raeburn 7963: $author_ok,$switchserver,$errors,$validationitemsref,$validationnamesref,
7964: $validationfieldsref);
1.86 raeburn 7965: if ($action eq 'quotas') {
7966: $context = 'tools';
1.163 raeburn 7967: } else {
1.86 raeburn 7968: $context = $action;
7969: }
7970: if ($context eq 'requestcourses') {
1.271 raeburn 7971: @usertools = ('official','unofficial','community','textbook','placement');
1.106 raeburn 7972: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 7973: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
7974: %titles = &courserequest_titles();
7975: $toolregexp = join('|',@usertools);
7976: %conditions = &courserequest_conditions();
1.216 raeburn 7977: $confname = $dom.'-domainconfig';
7978: my $servadm = $r->dir_config('lonAdmEMail');
7979: ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
1.235 raeburn 7980: ($validationitemsref,$validationnamesref,$validationfieldsref) =
7981: &Apache::loncoursequeueadmin::requestcourses_validation_types();
1.163 raeburn 7982: } elsif ($context eq 'requestauthor') {
7983: @usertools = ('author');
7984: %titles = &authorrequest_titles();
1.86 raeburn 7985: } else {
1.162 raeburn 7986: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 7987: %titles = &tool_titles();
1.86 raeburn 7988: }
1.212 raeburn 7989: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.44 raeburn 7990: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 7991: foreach my $key (keys(%env)) {
1.101 raeburn 7992: if ($context eq 'requestcourses') {
7993: if ($key =~ /^form\.crsreq_($toolregexp)_(.+)$/) {
7994: my $item = $1;
7995: my $type = $2;
7996: if ($type =~ /^limit_(.+)/) {
7997: $limithash{$item}{$1} = $env{$key};
7998: } else {
7999: $confhash{$item}{$type} = $env{$key};
8000: }
8001: }
1.163 raeburn 8002: } elsif ($context eq 'requestauthor') {
8003: if ($key =~ /^\Qform.authorreq_\E(.+)$/) {
8004: $confhash{$1} = $env{$key};
8005: }
1.101 raeburn 8006: } else {
1.86 raeburn 8007: if ($key =~ /^form\.quota_(.+)$/) {
8008: $confhash{'defaultquota'}{$1} = $env{$key};
1.197 raeburn 8009: } elsif ($key =~ /^form\.authorquota_(.+)$/) {
8010: $confhash{'authorquota'}{$1} = $env{$key};
8011: } elsif ($key =~ /^form\.\Q$context\E_(.+)$/) {
1.101 raeburn 8012: @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key);
8013: }
1.72 raeburn 8014: }
8015: }
1.163 raeburn 8016: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.224 raeburn 8017: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.'.$context.'notifyapproval');
1.102 raeburn 8018: @approvalnotify = sort(@approvalnotify);
8019: $confhash{'notify'}{'approval'} = join(',',@approvalnotify);
1.271 raeburn 8020: my @crstypes = ('official','unofficial','community','textbook','placement');
1.218 raeburn 8021: my @hasuniquecode = &Apache::loncommon::get_env_multiple('form.uniquecode');
8022: foreach my $type (@hasuniquecode) {
8023: if (grep(/^\Q$type\E$/,@crstypes)) {
8024: $confhash{'uniquecode'}{$type} = 1;
8025: }
1.216 raeburn 8026: }
1.242 raeburn 8027: my (%newbook,%allpos);
1.216 raeburn 8028: if ($context eq 'requestcourses') {
1.242 raeburn 8029: foreach my $type ('textbooks','templates') {
8030: @{$allpos{$type}} = ();
8031: my $invalid;
8032: if ($type eq 'textbooks') {
8033: $invalid = &mt('Invalid LON-CAPA course for textbook');
8034: } else {
8035: $invalid = &mt('Invalid LON-CAPA course for template');
8036: }
8037: if ($env{'form.'.$type.'_addbook'}) {
8038: if (($env{'form.'.$type.'_addbook_cnum'} =~ /^$match_courseid$/) &&
8039: ($env{'form.'.$type.'_addbook_cdom'} =~ /^$match_domain$/)) {
8040: if (&Apache::lonnet::homeserver($env{'form.'.$type.'_addbook_cnum'},
8041: $env{'form.'.$type.'_addbook_cdom'}) eq 'no_host') {
8042: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
8043: } else {
8044: $newbook{$type} = $env{'form.'.$type.'_addbook_cdom'}.'_'.$env{'form.'.$type.'_addbook_cnum'};
8045: my $position = $env{'form.'.$type.'_addbook_pos'};
8046: $position =~ s/\D+//g;
8047: if ($position ne '') {
8048: $allpos{$type}[$position] = $newbook{$type};
8049: }
1.216 raeburn 8050: }
1.242 raeburn 8051: } else {
8052: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
1.216 raeburn 8053: }
8054: }
1.242 raeburn 8055: }
1.216 raeburn 8056: }
1.102 raeburn 8057: if (ref($domconfig{$action}) eq 'HASH') {
8058: if (ref($domconfig{$action}{'notify'}) eq 'HASH') {
8059: if ($domconfig{$action}{'notify'}{'approval'} ne $confhash{'notify'}{'approval'}) {
8060: $changes{'notify'}{'approval'} = 1;
8061: }
8062: } else {
1.144 raeburn 8063: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 8064: $changes{'notify'}{'approval'} = 1;
8065: }
8066: }
1.218 raeburn 8067: if (ref($domconfig{$action}{'uniquecode'}) eq 'HASH') {
8068: if (ref($confhash{'uniquecode'}) eq 'HASH') {
8069: foreach my $crstype (keys(%{$domconfig{$action}{'uniquecode'}})) {
8070: unless ($confhash{'uniquecode'}{$crstype}) {
8071: $changes{'uniquecode'} = 1;
8072: }
8073: }
8074: unless ($changes{'uniquecode'}) {
8075: foreach my $crstype (keys(%{$confhash{'uniquecode'}})) {
8076: unless ($domconfig{$action}{'uniquecode'}{$crstype}) {
8077: $changes{'uniquecode'} = 1;
8078: }
8079: }
8080: }
8081: } else {
8082: $changes{'uniquecode'} = 1;
8083: }
8084: } elsif (ref($confhash{'uniquecode'}) eq 'HASH') {
8085: $changes{'uniquecode'} = 1;
1.216 raeburn 8086: }
8087: if ($context eq 'requestcourses') {
1.242 raeburn 8088: foreach my $type ('textbooks','templates') {
8089: if (ref($domconfig{$action}{$type}) eq 'HASH') {
8090: my %deletions;
8091: my @todelete = &Apache::loncommon::get_env_multiple('form.'.$type.'_del');
8092: if (@todelete) {
8093: map { $deletions{$_} = 1; } @todelete;
8094: }
8095: my %imgdeletions;
8096: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.'.$type.'_image_del');
8097: if (@todeleteimages) {
8098: map { $imgdeletions{$_} = 1; } @todeleteimages;
8099: }
8100: my $maxnum = $env{'form.'.$type.'_maxnum'};
8101: for (my $i=0; $i<=$maxnum; $i++) {
8102: my $itemid = $env{'form.'.$type.'_id_'.$i};
8103: my ($key) = ($itemid =~ /^\Q$type\E_(\w+)$/);
8104: if (ref($domconfig{$action}{$type}{$key}) eq 'HASH') {
8105: if ($deletions{$key}) {
8106: if ($domconfig{$action}{$type}{$key}{'image'}) {
8107: #FIXME need to obsolete item in RES space
8108: }
8109: next;
8110: } else {
8111: my $newpos = $env{'form.'.$itemid};
8112: $newpos =~ s/\D+//g;
1.243 raeburn 8113: foreach my $item ('subject','title','publisher','author') {
8114: next if ((($item eq 'author') || ($item eq 'publisher')) &&
8115: ($type eq 'templates'));
1.242 raeburn 8116: $confhash{$type}{$key}{$item} = $env{'form.'.$type.'_'.$item.'_'.$i};
8117: if ($domconfig{$action}{$type}{$key}{$item} ne $confhash{$type}{$key}{$item}) {
8118: $changes{$type}{$key} = 1;
8119: }
8120: }
8121: $allpos{$type}[$newpos] = $key;
8122: }
8123: if ($imgdeletions{$key}) {
8124: $changes{$type}{$key} = 1;
1.216 raeburn 8125: #FIXME need to obsolete item in RES space
1.242 raeburn 8126: } elsif ($env{'form.'.$type.'_image_'.$i.'.filename'}) {
8127: my ($cdom,$cnum) = split(/_/,$key);
8128: my ($imgurl,$error) = &process_textbook_image($r,$dom,$confname,$type.'_image_'.$i,
8129: $cdom,$cnum,$type,$configuserok,
8130: $switchserver,$author_ok);
8131: if ($imgurl) {
8132: $confhash{$type}{$key}{'image'} = $imgurl;
8133: $changes{$type}{$key} = 1;
1.216 raeburn 8134: }
1.242 raeburn 8135: if ($error) {
8136: &Apache::lonnet::logthis($error);
8137: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
8138: }
8139: } elsif ($domconfig{$action}{$type}{$key}{'image'}) {
8140: $confhash{$type}{$key}{'image'} =
8141: $domconfig{$action}{$type}{$key}{'image'};
1.216 raeburn 8142: }
8143: }
8144: }
8145: }
8146: }
8147: }
1.102 raeburn 8148: } else {
1.144 raeburn 8149: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 8150: $changes{'notify'}{'approval'} = 1;
8151: }
1.218 raeburn 8152: if (ref($confhash{'uniquecode'} eq 'HASH')) {
1.216 raeburn 8153: $changes{'uniquecode'} = 1;
8154: }
8155: }
8156: if ($context eq 'requestcourses') {
1.242 raeburn 8157: foreach my $type ('textbooks','templates') {
8158: if ($newbook{$type}) {
8159: $changes{$type}{$newbook{$type}} = 1;
1.243 raeburn 8160: foreach my $item ('subject','title','publisher','author') {
8161: next if ((($item eq 'author') || ($item eq 'publisher')) &&
8162: ($type eq 'template'));
1.242 raeburn 8163: $env{'form.'.$type.'_addbook_'.$item} =~ s/(`)/'/g;
8164: if ($env{'form.'.$type.'_addbook_'.$item}) {
8165: $confhash{$type}{$newbook{$type}}{$item} = $env{'form.'.$type.'_addbook_'.$item};
8166: }
8167: }
8168: if ($type eq 'textbooks') {
8169: if ($env{'form.'.$type.'_addbook_image.filename'} ne '') {
8170: my ($cdom,$cnum) = split(/_/,$newbook{$type});
8171: my ($imageurl,$error) =
8172: &process_textbook_image($r,$dom,$confname,$type.'_addbook_image',$cdom,$cnum,$type,
8173: $configuserok,$switchserver,$author_ok);
8174: if ($imageurl) {
8175: $confhash{$type}{$newbook{$type}}{'image'} = $imageurl;
8176: }
8177: if ($error) {
8178: &Apache::lonnet::logthis($error);
8179: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
8180: }
8181: }
1.216 raeburn 8182: }
8183: }
1.242 raeburn 8184: if (@{$allpos{$type}} > 0) {
8185: my $idx = 0;
8186: foreach my $item (@{$allpos{$type}}) {
8187: if ($item ne '') {
8188: $confhash{$type}{$item}{'order'} = $idx;
8189: if (ref($domconfig{$action}) eq 'HASH') {
8190: if (ref($domconfig{$action}{$type}) eq 'HASH') {
8191: if (ref($domconfig{$action}{$type}{$item}) eq 'HASH') {
8192: if ($domconfig{$action}{$type}{$item}{'order'} ne $idx) {
8193: $changes{$type}{$item} = 1;
8194: }
1.216 raeburn 8195: }
8196: }
8197: }
1.242 raeburn 8198: $idx ++;
1.216 raeburn 8199: }
8200: }
8201: }
8202: }
1.235 raeburn 8203: if (ref($validationitemsref) eq 'ARRAY') {
8204: foreach my $item (@{$validationitemsref}) {
8205: if ($item eq 'fields') {
8206: my @changed;
8207: @{$confhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.requestcourses_validation_'.$item);
8208: if (@{$confhash{'validation'}{$item}} > 0) {
8209: @{$confhash{'validation'}{$item}} = sort(@{$confhash{'validation'}{$item}});
8210: }
1.266 raeburn 8211: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
8212: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
8213: if (ref($domconfig{'requestcourses'}{'validation'}{$item}) eq 'ARRAY') {
8214: @changed = &Apache::loncommon::compare_arrays($confhash{'validation'}{$item},
8215: $domconfig{'requestcourses'}{'validation'}{$item});
8216: } else {
8217: @changed = @{$confhash{'validation'}{$item}};
8218: }
1.235 raeburn 8219: } else {
8220: @changed = @{$confhash{'validation'}{$item}};
8221: }
8222: } else {
8223: @changed = @{$confhash{'validation'}{$item}};
8224: }
8225: if (@changed) {
8226: if ($confhash{'validation'}{$item}) {
8227: $changes{'validation'}{$item} = join(', ',@{$confhash{'validation'}{$item}});
8228: } else {
8229: $changes{'validation'}{$item} = &mt('None');
8230: }
8231: }
8232: } else {
8233: $confhash{'validation'}{$item} = $env{'form.requestcourses_validation_'.$item};
8234: if ($item eq 'markup') {
8235: if ($env{'form.requestcourses_validation_'.$item}) {
8236: $env{'form.requestcourses_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
8237: }
8238: }
1.266 raeburn 8239: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
8240: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
8241: if ($domconfig{'requestcourses'}{'validation'}{$item} ne $confhash{'validation'}{$item}) {
8242: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
8243: }
8244: } else {
8245: if ($confhash{'validation'}{$item} ne '') {
8246: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
8247: }
1.235 raeburn 8248: }
8249: } else {
8250: if ($confhash{'validation'}{$item} ne '') {
8251: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
8252: }
8253: }
8254: }
8255: }
8256: }
8257: if ($env{'form.validationdc'}) {
8258: my $newval = $env{'form.validationdc'};
8259: my %domcoords = &get_active_dcs($dom);
8260: if (exists($domcoords{$newval})) {
8261: $confhash{'validation'}{'dc'} = $newval;
8262: }
8263: }
8264: if (ref($confhash{'validation'}) eq 'HASH') {
1.266 raeburn 8265: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
8266: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
8267: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
8268: unless ($confhash{'validation'}{'dc'} eq $domconfig{'requestcourses'}{'validation'}{'dc'}) {
8269: if ($confhash{'validation'}{'dc'} eq '') {
8270: $changes{'validation'}{'dc'} = &mt('None');
8271: } else {
8272: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
8273: }
1.235 raeburn 8274: }
1.266 raeburn 8275: } elsif ($confhash{'validation'}{'dc'} ne '') {
8276: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
1.235 raeburn 8277: }
8278: } elsif ($confhash{'validation'}{'dc'} ne '') {
8279: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
8280: }
8281: } elsif ($confhash{'validation'}{'dc'} ne '') {
8282: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
1.266 raeburn 8283: }
8284: } else {
8285: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
8286: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
8287: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
8288: $changes{'validation'}{'dc'} = &mt('None');
8289: }
8290: }
1.235 raeburn 8291: }
8292: }
1.102 raeburn 8293: }
8294: } else {
1.86 raeburn 8295: $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
1.197 raeburn 8296: $confhash{'authorquota'}{'default'} = $env{'form.authorquota'};
1.86 raeburn 8297: }
1.72 raeburn 8298: foreach my $item (@usertools) {
8299: foreach my $type (@{$types},'default','_LC_adv') {
1.104 raeburn 8300: my $unset;
1.101 raeburn 8301: if ($context eq 'requestcourses') {
1.104 raeburn 8302: $unset = '0';
8303: if ($type eq '_LC_adv') {
8304: $unset = '';
8305: }
1.101 raeburn 8306: if ($confhash{$item}{$type} eq 'autolimit') {
8307: $confhash{$item}{$type} .= '=';
8308: unless ($limithash{$item}{$type} =~ /\D/) {
8309: $confhash{$item}{$type} .= $limithash{$item}{$type};
8310: }
8311: }
1.163 raeburn 8312: } elsif ($context eq 'requestauthor') {
8313: $unset = '0';
8314: if ($type eq '_LC_adv') {
8315: $unset = '';
8316: }
1.72 raeburn 8317: } else {
1.101 raeburn 8318: if (grep(/^\Q$type\E$/,@{$toolshash{$item}})) {
8319: $confhash{$item}{$type} = 1;
8320: } else {
8321: $confhash{$item}{$type} = 0;
8322: }
1.72 raeburn 8323: }
1.86 raeburn 8324: if (ref($domconfig{$action}) eq 'HASH') {
1.163 raeburn 8325: if ($action eq 'requestauthor') {
8326: if ($domconfig{$action}{$type} ne $confhash{$type}) {
8327: $changes{$type} = 1;
8328: }
8329: } elsif (ref($domconfig{$action}{$item}) eq 'HASH') {
1.86 raeburn 8330: if ($domconfig{$action}{$item}{$type} ne $confhash{$item}{$type}) {
8331: $changes{$item}{$type} = 1;
8332: }
8333: } else {
8334: if ($context eq 'requestcourses') {
1.104 raeburn 8335: if ($confhash{$item}{$type} ne $unset) {
1.86 raeburn 8336: $changes{$item}{$type} = 1;
8337: }
8338: } else {
8339: if (!$confhash{$item}{$type}) {
8340: $changes{$item}{$type} = 1;
8341: }
8342: }
8343: }
8344: } else {
8345: if ($context eq 'requestcourses') {
1.104 raeburn 8346: if ($confhash{$item}{$type} ne $unset) {
1.72 raeburn 8347: $changes{$item}{$type} = 1;
8348: }
1.163 raeburn 8349: } elsif ($context eq 'requestauthor') {
8350: if ($confhash{$type} ne $unset) {
8351: $changes{$type} = 1;
8352: }
1.72 raeburn 8353: } else {
8354: if (!$confhash{$item}{$type}) {
8355: $changes{$item}{$type} = 1;
8356: }
8357: }
8358: }
1.1 raeburn 8359: }
8360: }
1.163 raeburn 8361: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 8362: if (ref($domconfig{'quotas'}) eq 'HASH') {
8363: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
8364: foreach my $key (keys(%{$domconfig{'quotas'}{'defaultquota'}})) {
8365: if (exists($confhash{'defaultquota'}{$key})) {
8366: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{'defaultquota'}{$key}) {
8367: $changes{'defaultquota'}{$key} = 1;
8368: }
8369: } else {
8370: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{'defaultquota'}{$key};
1.72 raeburn 8371: }
8372: }
1.86 raeburn 8373: } else {
8374: foreach my $key (keys(%{$domconfig{'quotas'}})) {
8375: if (exists($confhash{'defaultquota'}{$key})) {
8376: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{$key}) {
8377: $changes{'defaultquota'}{$key} = 1;
8378: }
8379: } else {
8380: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{$key};
1.72 raeburn 8381: }
1.1 raeburn 8382: }
8383: }
1.197 raeburn 8384: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
8385: foreach my $key (keys(%{$domconfig{'quotas'}{'authorquota'}})) {
8386: if (exists($confhash{'authorquota'}{$key})) {
8387: if ($confhash{'authorquota'}{$key} ne $domconfig{'quotas'}{'authorquota'}{$key}) {
8388: $changes{'authorquota'}{$key} = 1;
8389: }
8390: } else {
8391: $confhash{'authorquota'}{$key} = $domconfig{'quotas'}{'authorquota'}{$key};
8392: }
8393: }
8394: }
1.1 raeburn 8395: }
1.86 raeburn 8396: if (ref($confhash{'defaultquota'}) eq 'HASH') {
8397: foreach my $key (keys(%{$confhash{'defaultquota'}})) {
8398: if (ref($domconfig{'quotas'}) eq 'HASH') {
8399: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
8400: if (!exists($domconfig{'quotas'}{'defaultquota'}{$key})) {
8401: $changes{'defaultquota'}{$key} = 1;
8402: }
8403: } else {
8404: if (!exists($domconfig{'quotas'}{$key})) {
8405: $changes{'defaultquota'}{$key} = 1;
8406: }
1.72 raeburn 8407: }
8408: } else {
1.86 raeburn 8409: $changes{'defaultquota'}{$key} = 1;
1.55 raeburn 8410: }
1.1 raeburn 8411: }
8412: }
1.197 raeburn 8413: if (ref($confhash{'authorquota'}) eq 'HASH') {
8414: foreach my $key (keys(%{$confhash{'authorquota'}})) {
8415: if (ref($domconfig{'quotas'}) eq 'HASH') {
8416: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
8417: if (!exists($domconfig{'quotas'}{'authorquota'}{$key})) {
8418: $changes{'authorquota'}{$key} = 1;
8419: }
8420: } else {
8421: $changes{'authorquota'}{$key} = 1;
8422: }
8423: } else {
8424: $changes{'authorquota'}{$key} = 1;
8425: }
8426: }
8427: }
1.1 raeburn 8428: }
1.72 raeburn 8429:
1.163 raeburn 8430: if ($context eq 'requestauthor') {
8431: $domdefaults{'requestauthor'} = \%confhash;
8432: } else {
8433: foreach my $key (keys(%confhash)) {
1.242 raeburn 8434: unless (($context eq 'requestcourses') && (($key eq 'textbooks') || ($key eq 'templates'))) {
1.216 raeburn 8435: $domdefaults{$key} = $confhash{$key};
8436: }
1.163 raeburn 8437: }
1.72 raeburn 8438: }
1.163 raeburn 8439:
1.1 raeburn 8440: my %quotahash = (
1.86 raeburn 8441: $action => { %confhash }
1.1 raeburn 8442: );
8443: my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
8444: $dom);
8445: if ($putresult eq 'ok') {
8446: if (keys(%changes) > 0) {
1.72 raeburn 8447: my $cachetime = 24*60*60;
8448: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 8449: if (ref($lastactref) eq 'HASH') {
8450: $lastactref->{'domdefaults'} = 1;
8451: }
1.1 raeburn 8452: $resulttext = &mt('Changes made:').'<ul>';
1.210 raeburn 8453: unless (($context eq 'requestcourses') ||
1.163 raeburn 8454: ($context eq 'requestauthor')) {
1.86 raeburn 8455: if (ref($changes{'defaultquota'}) eq 'HASH') {
8456: $resulttext .= '<li>'.&mt('Portfolio default quotas').'<ul>';
8457: foreach my $type (@{$types},'default') {
8458: if (defined($changes{'defaultquota'}{$type})) {
8459: my $typetitle = $usertypes->{$type};
8460: if ($type eq 'default') {
8461: $typetitle = $othertitle;
8462: }
1.213 raeburn 8463: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'defaultquota'}{$type}).'</li>';
1.72 raeburn 8464: }
8465: }
1.86 raeburn 8466: $resulttext .= '</ul></li>';
1.72 raeburn 8467: }
1.197 raeburn 8468: if (ref($changes{'authorquota'}) eq 'HASH') {
1.223 bisitz 8469: $resulttext .= '<li>'.&mt('Authoring Space default quotas').'<ul>';
1.197 raeburn 8470: foreach my $type (@{$types},'default') {
8471: if (defined($changes{'authorquota'}{$type})) {
8472: my $typetitle = $usertypes->{$type};
8473: if ($type eq 'default') {
8474: $typetitle = $othertitle;
8475: }
1.213 raeburn 8476: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'authorquota'}{$type}).'</li>';
1.197 raeburn 8477: }
8478: }
8479: $resulttext .= '</ul></li>';
8480: }
1.72 raeburn 8481: }
1.80 raeburn 8482: my %newenv;
1.72 raeburn 8483: foreach my $item (@usertools) {
1.163 raeburn 8484: my (%haschgs,%inconf);
8485: if ($context eq 'requestauthor') {
8486: %haschgs = %changes;
1.210 raeburn 8487: %inconf = %confhash;
1.163 raeburn 8488: } else {
8489: if (ref($changes{$item}) eq 'HASH') {
8490: %haschgs = %{$changes{$item}};
8491: }
8492: if (ref($confhash{$item}) eq 'HASH') {
8493: %inconf = %{$confhash{$item}};
8494: }
8495: }
8496: if (keys(%haschgs) > 0) {
1.80 raeburn 8497: my $newacc =
8498: &Apache::lonnet::usertools_access($env{'user.name'},
8499: $env{'user.domain'},
1.86 raeburn 8500: $item,'reload',$context);
1.210 raeburn 8501: if (($context eq 'requestcourses') ||
1.163 raeburn 8502: ($context eq 'requestauthor')) {
1.108 raeburn 8503: if ($env{'environment.canrequest.'.$item} ne $newacc) {
8504: $newenv{'environment.canrequest.'.$item} = $newacc;
1.86 raeburn 8505: }
8506: } else {
8507: if ($env{'environment.availabletools.'.$item} ne $newacc) {
8508: $newenv{'environment.availabletools.'.$item} = $newacc;
8509: }
1.80 raeburn 8510: }
1.163 raeburn 8511: unless ($context eq 'requestauthor') {
8512: $resulttext .= '<li>'.$titles{$item}.'<ul>';
8513: }
1.72 raeburn 8514: foreach my $type (@{$types},'default','_LC_adv') {
1.163 raeburn 8515: if ($haschgs{$type}) {
1.72 raeburn 8516: my $typetitle = $usertypes->{$type};
8517: if ($type eq 'default') {
8518: $typetitle = $othertitle;
8519: } elsif ($type eq '_LC_adv') {
8520: $typetitle = 'LON-CAPA Advanced Users';
8521: }
1.163 raeburn 8522: if ($inconf{$type}) {
1.101 raeburn 8523: if ($context eq 'requestcourses') {
8524: my $cond;
1.163 raeburn 8525: if ($inconf{$type} =~ /^autolimit=(\d*)$/) {
1.101 raeburn 8526: if ($1 eq '') {
8527: $cond = &mt('(Automatic processing of any request).');
8528: } else {
8529: $cond = &mt('(Automatic processing of requests up to limit of [quant,_1,request] per user).',$1);
8530: }
8531: } else {
1.163 raeburn 8532: $cond = $conditions{$inconf{$type}};
1.101 raeburn 8533: }
8534: $resulttext .= '<li>'.&mt('Set to be available to [_1].',$typetitle).' '.$cond.'</li>';
1.172 raeburn 8535: } elsif ($context eq 'requestauthor') {
8536: $resulttext .= '<li>'.&mt('Set to "[_1]" for "[_2]".',
8537: $titles{$inconf{$type}},$typetitle);
8538:
1.101 raeburn 8539: } else {
8540: $resulttext .= '<li>'.&mt('Set to be available to [_1]',$typetitle).'</li>';
8541: }
1.72 raeburn 8542: } else {
1.104 raeburn 8543: if ($type eq '_LC_adv') {
1.163 raeburn 8544: if ($inconf{$type} eq '0') {
1.104 raeburn 8545: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
8546: } else {
8547: $resulttext .= '<li>'.&mt('No override set for [_1]',$typetitle).'</li>';
8548: }
8549: } else {
8550: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
8551: }
1.72 raeburn 8552: }
8553: }
1.26 raeburn 8554: }
1.163 raeburn 8555: unless ($context eq 'requestauthor') {
8556: $resulttext .= '</ul></li>';
8557: }
1.26 raeburn 8558: }
1.1 raeburn 8559: }
1.163 raeburn 8560: if (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.102 raeburn 8561: if (ref($changes{'notify'}) eq 'HASH') {
8562: if ($changes{'notify'}{'approval'}) {
8563: if (ref($confhash{'notify'}) eq 'HASH') {
8564: if ($confhash{'notify'}{'approval'}) {
8565: $resulttext .= '<li>'.&mt('Notification of requests requiring approval will be sent to: ').$confhash{'notify'}{'approval'}.'</li>';
8566: } else {
1.163 raeburn 8567: $resulttext .= '<li>'.&mt('No Domain Coordinators will receive notification of requests requiring approval.').'</li>';
1.102 raeburn 8568: }
8569: }
8570: }
8571: }
8572: }
1.216 raeburn 8573: if ($action eq 'requestcourses') {
8574: my @offon = ('off','on');
8575: if ($changes{'uniquecode'}) {
1.218 raeburn 8576: if (ref($confhash{'uniquecode'}) eq 'HASH') {
8577: my $codestr = join(' ',map{ &mt($_); } sort(keys(%{$confhash{'uniquecode'}})));
8578: $resulttext .= '<li>'.
8579: &mt('Generation of six character code as course identifier for distribution to students set to on for: [_1].','<b>'.$codestr.'</b>').
8580: '</li>';
8581: } else {
8582: $resulttext .= '<li>'.&mt('Generation of six character code as course identifier for distribution to students set to off.').
8583: '</li>';
8584: }
1.216 raeburn 8585: }
1.242 raeburn 8586: foreach my $type ('textbooks','templates') {
8587: if (ref($changes{$type}) eq 'HASH') {
8588: $resulttext .= '<li>'.&mt("Available $type updated").'<ul>';
8589: foreach my $key (sort(keys(%{$changes{$type}}))) {
8590: my %coursehash = &Apache::lonnet::coursedescription($key);
8591: my $coursetitle = $coursehash{'description'};
8592: my $position = $confhash{$type}{$key}{'order'} + 1;
8593: $resulttext .= '<li>';
1.243 raeburn 8594: foreach my $item ('subject','title','publisher','author') {
8595: next if ((($item eq 'author') || ($item eq 'publisher')) &&
8596: ($type eq 'templates'));
1.242 raeburn 8597: my $name = $item.':';
8598: $name =~ s/^(\w)/\U$1/;
8599: $resulttext .= &mt($name).' '.$confhash{$type}{$key}{$item}.'<br />';
8600: }
8601: $resulttext .= ' '.&mt('Order: [_1]',$position).'<br />';
8602: if ($type eq 'textbooks') {
8603: if ($confhash{$type}{$key}{'image'}) {
8604: $resulttext .= ' '.&mt('Image: [_1]',
8605: '<img src="'.$confhash{$type}{$key}{'image'}.'"'.
8606: ' alt="Textbook cover" />').'<br />';
8607: }
8608: }
8609: $resulttext .= ' '.&mt('LON-CAPA Course: [_1]',$coursetitle).'</li>';
1.216 raeburn 8610: }
1.242 raeburn 8611: $resulttext .= '</ul></li>';
1.216 raeburn 8612: }
8613: }
1.235 raeburn 8614: if (ref($changes{'validation'}) eq 'HASH') {
8615: if ((ref($validationitemsref) eq 'ARRAY') && (ref($validationnamesref) eq 'HASH')) {
8616: $resulttext .= '<li>'.&mt('Validation of courses/communities updated').'<ul>';
8617: foreach my $item (@{$validationitemsref}) {
8618: if (exists($changes{'validation'}{$item})) {
8619: if ($item eq 'markup') {
8620: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
8621: '<br /><pre>'.$changes{'validation'}{$item}.'</pre>').'</li>';
8622: } else {
8623: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
8624: '<b>'.$changes{'validation'}{$item}.'</b>').'</li>';
8625: }
8626: }
8627: }
8628: if (exists($changes{'validation'}{'dc'})) {
8629: $resulttext .= '<li>'.&mt('Validated course requests identified as processed by: [_1]',
8630: '<b>'.$changes{'validation'}{'dc'}.'</b>').'</li>';
8631: }
8632: }
8633: }
1.216 raeburn 8634: }
1.1 raeburn 8635: $resulttext .= '</ul>';
1.80 raeburn 8636: if (keys(%newenv)) {
8637: &Apache::lonnet::appenv(\%newenv);
8638: }
1.1 raeburn 8639: } else {
1.86 raeburn 8640: if ($context eq 'requestcourses') {
8641: $resulttext = &mt('No changes made to rights to request creation of courses.');
1.163 raeburn 8642: } elsif ($context eq 'requestauthor') {
8643: $resulttext = &mt('No changes made to rights to request author space.');
1.86 raeburn 8644: } else {
1.90 weissno 8645: $resulttext = &mt('No changes made to availability of personal information pages, blogs, portfolios or default quotas');
1.86 raeburn 8646: }
1.1 raeburn 8647: }
8648: } else {
1.11 albertel 8649: $resulttext = '<span class="LC_error">'.
8650: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 8651: }
1.216 raeburn 8652: if ($errors) {
8653: $resulttext .= '<p>'.&mt('The following errors occurred when modifying Textbook settings.').
8654: '<ul>'.$errors.'</ul></p>';
8655: }
1.3 raeburn 8656: return $resulttext;
1.1 raeburn 8657: }
8658:
1.216 raeburn 8659: sub process_textbook_image {
1.242 raeburn 8660: my ($r,$dom,$confname,$caller,$cdom,$cnum,$type,$configuserok,$switchserver,$author_ok) = @_;
1.216 raeburn 8661: my $filename = $env{'form.'.$caller.'.filename'};
8662: my ($error,$url);
8663: my ($width,$height) = (50,50);
8664: if ($configuserok eq 'ok') {
8665: if ($switchserver) {
8666: $error = &mt('Upload of textbook image is not permitted to this server: [_1]',
8667: $switchserver);
8668: } elsif ($author_ok eq 'ok') {
8669: my ($result,$imageurl) =
8670: &publishlogo($r,'upload',$caller,$dom,$confname,
1.242 raeburn 8671: "$type/$dom/$cnum/cover",$width,$height);
1.216 raeburn 8672: if ($result eq 'ok') {
8673: $url = $imageurl;
8674: } else {
8675: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
8676: }
8677: } else {
8678: $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);
8679: }
8680: } else {
8681: $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);
8682: }
8683: return ($url,$error);
8684: }
8685:
1.267 raeburn 8686: sub modify_ltitools {
8687: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
8688: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
8689: my ($newid,@allpos,%changes,%confhash,$errors,$resulttext);
8690: my $confname = $dom.'-domainconfig';
8691: my $servadm = $r->dir_config('lonAdmEMail');
8692: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
8693: my (%posslti,%possfield);
8694: my @courseroles = ('cc','in','ta','ep','st');
8695: my @ltiroles = qw(Instructor ContentDeveloper TeachingAssistant Learner);
8696: map { $posslti{$_} = 1; } @ltiroles;
8697: my @allfields = ('fullname','firstname','lastname','email','user','roles');
8698: map { $possfield{$_} = 1; } @allfields;
8699: my %lt = <itools_names();
8700: if ($env{'form.ltitools_add'}) {
8701: my $title = $env{'form.ltitools_add_title'};
8702: $title =~ s/(`)/'/g;
8703: ($newid,my $error) = &get_ltitools_id($dom,$title);
8704: if ($newid) {
8705: my $position = $env{'form.ltitools_add_pos'};
8706: $position =~ s/\D+//g;
8707: if ($position ne '') {
8708: $allpos[$position] = $newid;
8709: }
8710: $changes{$newid} = 1;
8711: foreach my $item ('title','url','key','secret') {
8712: $env{'form.ltitools_add_'.$item} =~ s/(`)/'/g;
8713: if ($env{'form.ltitools_add_'.$item}) {
8714: $confhash{$newid}{$item} = $env{'form.ltitools_add_'.$item};
8715: }
8716: }
8717: if ($env{'form.ltitools_add_version'} eq 'LTI-1p0') {
8718: $confhash{$newid}{'version'} = $env{'form.ltitools_add_version'};
8719: }
8720: if ($env{'form.ltitools_add_msgtype'} eq 'basic-lti-launch-request') {
8721: $confhash{$newid}{'msgtype'} = $env{'form.ltitools_add_msgtype'};
8722: }
8723: foreach my $item ('width','height') {
8724: $env{'form.ltitools_add_'.$item} =~ s/^\s+//;
8725: $env{'form.ltitools_add_'.$item} =~ s/\s+$//;
8726: if ($env{'form.ltitools_add_'.$item} =~ /^\d+$/) {
8727: $confhash{$newid}{'display'}{$item} = $env{'form.ltitools_add_'.$item};
8728: }
8729: }
8730: if ($env{'form.ltitools_add_target'} eq 'window') {
8731: $confhash{$newid}{'display'}{'target'} = $env{'form.ltitools_add_target'};
8732: } else {
8733: $confhash{$newid}{'display'}{'target'} = 'iframe';
8734: }
8735: foreach my $item ('passback','roster') {
8736: if ($env{'form.ltitools_add_'.$item}) {
8737: $confhash{$newid}{$item} = 1;
8738: }
8739: }
8740: if ($env{'form.ltitools_add_image.filename'} ne '') {
8741: my ($imageurl,$error) =
8742: &process_ltitools_image($r,$dom,$confname,'ltitools_add_image',$dom,
8743: $configuserok,$switchserver,$author_ok);
8744: if ($imageurl) {
8745: $confhash{$newid}{'image'} = $imageurl;
8746: }
8747: if ($error) {
8748: &Apache::lonnet::logthis($error);
8749: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
8750: }
8751: }
8752: my @fields = &Apache::loncommon::get_env_multiple('form.ltitools_add_fields');
8753: foreach my $field (@fields) {
8754: if ($possfield{$field}) {
8755: if ($field eq 'roles') {
8756: foreach my $role (@courseroles) {
8757: my $choice = $env{'form.ltitools_add_roles_'.$role};
8758: if (($choice ne '') && ($posslti{$choice})) {
8759: $confhash{$newid}{'roles'}{$role} = $choice;
8760: if ($role eq 'cc') {
8761: $confhash{$newid}{'roles'}{'co'} = $choice;
8762: }
8763: }
8764: }
8765: } else {
8766: $confhash{$newid}{'fields'}{$field} = 1;
8767: }
8768: }
8769: }
1.273 raeburn 8770: my @courseconfig = &Apache::loncommon::get_env_multiple('form.ltitools_courseconfig');
8771: foreach my $item (@courseconfig) {
8772: $confhash{$newid}{'crsconf'}{$item} = 1;
8773: }
1.267 raeburn 8774: if ($env{'form.ltitools_add_custom'}) {
8775: my $name = $env{'form.ltitools_add_custom_name'};
8776: my $value = $env{'form.ltitools_add_custom_value'};
8777: $value =~ s/(`)/'/g;
8778: $name =~ s/(`)/'/g;
8779: $confhash{$newid}{'custom'}{$name} = $value;
8780: }
8781: } else {
8782: my $error = &mt('Failed to acquire unique ID for new external tool');
8783: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
8784: }
8785: }
8786: if (ref($domconfig{$action}) eq 'HASH') {
8787: my %deletions;
8788: my @todelete = &Apache::loncommon::get_env_multiple('form.ltitools_del');
8789: if (@todelete) {
8790: map { $deletions{$_} = 1; } @todelete;
8791: }
8792: my %customadds;
8793: my @newcustom = &Apache::loncommon::get_env_multiple('form.ltitools_customadd');
8794: if (@newcustom) {
8795: map { $customadds{$_} = 1; } @newcustom;
8796: }
8797: my %imgdeletions;
8798: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.ltitools_image_del');
8799: if (@todeleteimages) {
8800: map { $imgdeletions{$_} = 1; } @todeleteimages;
8801: }
8802: my $maxnum = $env{'form.ltitools_maxnum'};
8803: for (my $i=0; $i<=$maxnum; $i++) {
8804: my $itemid = $env{'form.ltitools_id_'.$i};
8805: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
8806: if ($deletions{$itemid}) {
8807: if ($domconfig{$action}{$itemid}{'image'}) {
8808: #FIXME need to obsolete item in RES space
8809: }
8810: $changes{$itemid} = $domconfig{$action}{$itemid}{'title'};
8811: next;
8812: } else {
8813: my $newpos = $env{'form.ltitools_'.$itemid};
8814: $newpos =~ s/\D+//g;
8815: foreach my $item ('title','url','key','secret') {
8816: $confhash{$itemid}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
8817: if ($domconfig{$action}{$itemid}{$item} ne $confhash{$itemid}{$item}) {
8818: $changes{$itemid} = 1;
8819: }
8820: }
8821: if ($env{'form.ltitools_version_'.$i} eq 'LTI-1p0') {
8822: $confhash{$itemid}{'version'} = $env{'form.ltitools_version_'.$i};
8823: }
8824: if ($env{'form.ltitools_msgtype_'.$i} eq 'basic-lti-launch-request') {
8825: $confhash{$itemid}{'msgtype'} = $env{'form.ltitools_msgtype_'.$i};
8826: }
8827: foreach my $size ('width','height') {
8828: $env{'form.ltitools_'.$size.'_'.$i} =~ s/^\s+//;
8829: $env{'form.ltitools_'.$size.'_'.$i} =~ s/\s+$//;
8830: if ($env{'form.ltitools_'.$size.'_'.$i} =~ /^\d+$/) {
8831: $confhash{$itemid}{'display'}{$size} = $env{'form.ltitools_'.$size.'_'.$i};
8832: if (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
8833: if ($domconfig{$action}{$itemid}{'display'}{$size} ne $confhash{$itemid}{'display'}{$size}) {
8834: $changes{$itemid} = 1;
8835: }
8836: } else {
8837: $changes{$itemid} = 1;
8838: }
8839: }
8840: }
8841: if ($env{'form.ltitools_target_'.$i} eq 'window') {
8842: $confhash{$itemid}{'display'}{'target'} = $env{'form.ltitools_target_'.$i};
8843: } else {
8844: $confhash{$itemid}{'display'}{'target'} = 'iframe';
8845: }
8846: if (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
8847: if ($domconfig{$action}{$itemid}{'display'}{'target'} ne $confhash{$itemid}{'display'}{'target'}) {
8848: $changes{$itemid} = 1;
8849: }
8850: } else {
8851: $changes{$itemid} = 1;
8852: }
8853: foreach my $extra ('passback','roster') {
8854: if ($env{'form.ltitools_'.$extra.'_'.$i}) {
8855: $confhash{$itemid}{$extra} = 1;
8856: }
8857: if ($domconfig{$action}{$itemid}{$extra} ne $confhash{$itemid}{$extra}) {
8858: $changes{$itemid} = 1;
8859: }
8860: }
1.273 raeburn 8861: my @courseconfig = &Apache::loncommon::get_env_multiple('form.ltitools_courseconfig_'.$i);
8862: foreach my $item ('label','title','target') {
8863: if (grep(/^\Q$item\E$/,@courseconfig)) {
8864: $confhash{$itemid}{'crsconf'}{$item} = 1;
8865: if (ref($domconfig{$action}{$itemid}{'crsconf'}) eq 'HASH') {
8866: if ($domconfig{$action}{$itemid}{'crsconf'}{$item} ne $confhash{$itemid}{'crsconf'}{$item}) {
8867: $changes{$itemid} = 1;
8868: }
8869: } else {
8870: $changes{$itemid} = 1;
8871: }
8872: }
8873: }
1.267 raeburn 8874: my @fields = &Apache::loncommon::get_env_multiple('form.ltitools_fields_'.$i);
8875: foreach my $field (@fields) {
8876: if ($possfield{$field}) {
8877: if ($field eq 'roles') {
8878: foreach my $role (@courseroles) {
8879: my $choice = $env{'form.ltitools_roles_'.$role.'_'.$i};
8880: if (($choice ne '') && ($posslti{$choice})) {
8881: $confhash{$itemid}{'roles'}{$role} = $choice;
8882: if ($role eq 'cc') {
8883: $confhash{$itemid}{'roles'}{'co'} = $choice;
8884: }
8885: }
8886: if (ref($domconfig{$action}{$itemid}{'roles'}) eq 'HASH') {
8887: if ($domconfig{$action}{$itemid}{'roles'}{$role} ne $confhash{$itemid}{'roles'}{$role}) {
8888: $changes{$itemid} = 1;
8889: }
8890: } elsif ($confhash{$itemid}{'roles'}{$role}) {
8891: $changes{$itemid} = 1;
8892: }
8893: }
8894: } else {
8895: $confhash{$itemid}{'fields'}{$field} = 1;
8896: if (ref($domconfig{$action}{$itemid}{'fields'}) eq 'HASH') {
8897: if ($domconfig{$action}{$itemid}{'fields'}{$field} ne $confhash{$itemid}{'fields'}{$field}) {
8898: $changes{$itemid} = 1;
8899: }
8900: } else {
8901: $changes{$itemid} = 1;
8902: }
8903: }
8904: }
8905: }
8906: $allpos[$newpos] = $itemid;
8907: }
8908: if ($imgdeletions{$itemid}) {
8909: $changes{$itemid} = 1;
8910: #FIXME need to obsolete item in RES space
8911: } elsif ($env{'form.ltitools_image_'.$i.'.filename'}) {
8912: my ($imgurl,$error) = &process_ltitools_image($r,$dom,$confname,'ltitools_image_'.$i,
8913: $itemid,$configuserok,$switchserver,
8914: $author_ok);
8915: if ($imgurl) {
8916: $confhash{$itemid}{'image'} = $imgurl;
8917: $changes{$itemid} = 1;
8918: }
8919: if ($error) {
8920: &Apache::lonnet::logthis($error);
8921: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
8922: }
8923: } elsif ($domconfig{$action}{$itemid}{'image'}) {
8924: $confhash{$itemid}{'image'} =
8925: $domconfig{$action}{$itemid}{'image'};
8926: }
8927: if ($customadds{$i}) {
8928: my $name = $env{'form.ltitools_custom_name_'.$i};
8929: $name =~ s/(`)/'/g;
8930: $name =~ s/^\s+//;
8931: $name =~ s/\s+$//;
8932: my $value = $env{'form.ltitools_custom_value_'.$i};
8933: $value =~ s/(`)/'/g;
8934: $value =~ s/^\s+//;
8935: $value =~ s/\s+$//;
8936: if ($name ne '') {
8937: $confhash{$itemid}{'custom'}{$name} = $value;
8938: $changes{$itemid} = 1;
8939: }
8940: }
8941: my %customdels;
8942: my @customdeletions = &Apache::loncommon::get_env_multiple('form.ltitools_customdel_'.$i);
8943: if (@customdeletions) {
8944: $changes{$itemid} = 1;
8945: }
8946: map { $customdels{$_} = 1; } @customdeletions;
8947: if (ref($domconfig{$action}{$itemid}{'custom'}) eq 'HASH') {
8948: foreach my $key (keys(%{$domconfig{$action}{$itemid}{'custom'}})) {
8949: unless ($customdels{$key}) {
8950: if ($env{'form.ltitools_customval_'.$key.'_'.$i} ne '') {
8951: $confhash{$itemid}{'custom'}{$key} = $env{'form.ltitools_customval_'.$key.'_'.$i};
8952: }
8953: if ($domconfig{$action}{$itemid}{'custom'}{$key} ne $env{'form.ltitools_customval_'.$key.'_'.$i}) {
8954: $changes{$itemid} = 1;
8955: }
8956: }
8957: }
8958: }
8959: unless ($changes{$itemid}) {
8960: foreach my $key (keys(%{$domconfig{$action}{$itemid}})) {
8961: if (ref($domconfig{$action}{$itemid}{$key}) eq 'HASH') {
8962: if (ref($confhash{$itemid}{$key}) eq 'HASH') {
8963: foreach my $innerkey (keys(%{$domconfig{$action}{$itemid}{$key}})) {
8964: unless (exists($confhash{$itemid}{$key}{$innerkey})) {
8965: $changes{$itemid} = 1;
8966: last;
8967: }
8968: }
8969: } elsif (keys(%{$domconfig{$action}{$itemid}{$key}}) > 0) {
8970: $changes{$itemid} = 1;
8971: }
8972: }
8973: last if ($changes{$itemid});
8974: }
8975: }
8976: }
8977: }
8978: }
8979: if (@allpos > 0) {
8980: my $idx = 0;
8981: foreach my $itemid (@allpos) {
8982: if ($itemid ne '') {
8983: $confhash{$itemid}{'order'} = $idx;
8984: if (ref($domconfig{$action}) eq 'HASH') {
8985: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
8986: if ($domconfig{$action}{$itemid}{'order'} ne $idx) {
8987: $changes{$itemid} = 1;
8988: }
8989: }
8990: }
8991: $idx ++;
8992: }
8993: }
8994: }
8995: my %ltitoolshash = (
8996: $action => { %confhash }
8997: );
8998: my $putresult = &Apache::lonnet::put_dom('configuration',\%ltitoolshash,
8999: $dom);
9000: if ($putresult eq 'ok') {
9001: if (keys(%changes) > 0) {
9002: my $cachetime = 24*60*60;
9003: &Apache::lonnet::do_cache_new('ltitools',$dom,\%confhash,$cachetime);
9004: if (ref($lastactref) eq 'HASH') {
9005: $lastactref->{'ltitools'} = 1;
9006: }
9007: $resulttext = &mt('Changes made:').'<ul>';
9008: my %bynum;
9009: foreach my $itemid (sort(keys(%changes))) {
9010: my $position = $confhash{$itemid}{'order'};
9011: $bynum{$position} = $itemid;
9012: }
9013: foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
9014: my $itemid = $bynum{$pos};
9015: if (ref($confhash{$itemid}) ne 'HASH') {
9016: $resulttext .= '<li>'.&mt('Deleted: [_1]',$changes{$itemid}).'</li>';
9017: } else {
9018: $resulttext .= '<li><b>'.$confhash{$itemid}{'title'}.'</b>';
9019: if ($confhash{$itemid}{'image'}) {
9020: $resulttext .= ' '.
9021: '<img src="'.$confhash{$itemid}{'image'}.'"'.
9022: ' alt="'.&mt('Tool Provider icon').'" />';
9023: }
9024: $resulttext .= '</li><ul>';
9025: my $position = $pos + 1;
9026: $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
9027: foreach my $item ('version','msgtype','url','key') {
9028: if ($confhash{$itemid}{$item} ne '') {
9029: $resulttext .= '<li>'.$lt{$item}.': '.$confhash{$itemid}{$item}.'</li>';
9030: }
9031: }
9032: if ($confhash{$itemid}{'secret'} ne '') {
9033: $resulttext .= '<li>'.$lt{'secret'}.': ';
9034: my $num = length($confhash{$itemid}{'secret'});
9035: $resulttext .= ('*'x$num).'</li>';
9036: }
1.273 raeburn 9037: $resulttext .= '<li>'.&mt('Configurable in course:');
9038: my @possconfig = ('label','title','target');
9039: my $numconfig = 0;
9040: if (ref($confhash{$itemid}{'crsconf'}) eq 'HASH') {
9041: foreach my $item (@possconfig) {
9042: if ($confhash{$itemid}{'crsconf'}{$item}) {
9043: $numconfig ++;
9044: $resulttext .= ' '.$lt{'crs'.$item};
9045: }
9046: }
9047: }
9048: if (!$numconfig) {
9049: $resulttext .= &mt('None');
9050: }
9051: $resulttext .= '</li>';
1.267 raeburn 9052: foreach my $item ('passback','roster') {
9053: $resulttext .= '<li>'.$lt{$item}.' ';
9054: if ($confhash{$itemid}{$item}) {
9055: $resulttext .= &mt('Yes');
9056: } else {
9057: $resulttext .= &mt('No');
9058: }
9059: $resulttext .= '</li>';
9060: }
9061: if (ref($confhash{$itemid}{'display'}) eq 'HASH') {
9062: my $displaylist;
9063: if ($confhash{$itemid}{'display'}{'target'}) {
9064: $displaylist = &mt('Display target').': '.
9065: $confhash{$itemid}{'display'}{'target'}.',';
9066: }
9067: foreach my $size ('width','height') {
9068: if ($confhash{$itemid}{'display'}{$size}) {
9069: $displaylist .= (' 'x2).$lt{$size}.': '.
9070: $confhash{$itemid}{'display'}{$size}.',';
9071: }
9072: }
9073: if ($displaylist) {
9074: $displaylist =~ s/,$//;
9075: $resulttext .= '<li>'.$displaylist.'</li>';
9076: }
9077: }
9078: if (ref($confhash{$itemid}{'fields'}) eq 'HASH') {
9079: my $fieldlist;
9080: foreach my $field (@allfields) {
9081: if ($confhash{$itemid}{'fields'}{$field}) {
9082: $fieldlist .= (' 'x2).$lt{$field}.',';
9083: }
9084: }
9085: if ($fieldlist) {
9086: $fieldlist =~ s/,$//;
9087: $resulttext .= '<li>'.&mt('Data sent').':'.$fieldlist.'</li>';
9088: }
9089: }
9090: if (ref($confhash{$itemid}{'roles'}) eq 'HASH') {
9091: my $rolemaps;
9092: foreach my $role (@courseroles) {
9093: if ($confhash{$itemid}{'roles'}{$role}) {
9094: $rolemaps .= (' 'x2).&Apache::lonnet::plaintext($role,'Course').'='.
9095: $confhash{$itemid}{'roles'}{$role}.',';
9096: }
9097: }
9098: if ($rolemaps) {
9099: $rolemaps =~ s/,$//;
9100: $resulttext .= '<li>'.&mt('Role mapping:').$rolemaps.'</li>';
9101: }
9102: }
9103: if (ref($confhash{$itemid}{'custom'}) eq 'HASH') {
9104: my $customlist;
9105: if (keys(%{$confhash{$itemid}{'custom'}})) {
9106: foreach my $key (sort(keys(%{$confhash{$itemid}{'custom'}}))) {
9107: $customlist .= $key.':'.$confhash{$itemid}{'custom'}{$key}.(' 'x2);
9108: }
9109: }
9110: if ($customlist) {
9111: $resulttext .= '<li>'.&mt('Custom items').':'.$customlist.'</li>';
9112: }
9113: }
9114: $resulttext .= '</ul></li>';
9115: }
9116: }
9117: $resulttext .= '</ul>';
9118: } else {
9119: $resulttext = &mt('No changes made.');
9120: }
9121: } else {
9122: $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
9123: }
9124: if ($errors) {
9125: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
9126: $errors.'</ul>';
9127: }
9128: return $resulttext;
9129: }
9130:
9131: sub process_ltitools_image {
9132: my ($r,$dom,$confname,$caller,$itemid,$configuserok,$switchserver,$author_ok) = @_;
9133: my $filename = $env{'form.'.$caller.'.filename'};
9134: my ($error,$url);
9135: my ($width,$height) = (21,21);
9136: if ($configuserok eq 'ok') {
9137: if ($switchserver) {
9138: $error = &mt('Upload of Tool Provider (LTI) icon is not permitted to this server: [_1]',
9139: $switchserver);
9140: } elsif ($author_ok eq 'ok') {
9141: my ($result,$imageurl,$madethumb) =
9142: &publishlogo($r,'upload',$caller,$dom,$confname,
9143: "ltitools/$itemid/icon",$width,$height);
9144: if ($result eq 'ok') {
9145: if ($madethumb) {
9146: my ($path,$imagefile) = ($imageurl =~ m{^(.+)/([^/]+)$});
9147: my $imagethumb = "$path/tn-".$imagefile;
9148: $url = $imagethumb;
9149: } else {
9150: $url = $imageurl;
9151: }
9152: } else {
9153: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
9154: }
9155: } else {
9156: $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);
9157: }
9158: } else {
9159: $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);
9160: }
9161: return ($url,$error);
9162: }
9163:
9164: sub get_ltitools_id {
9165: my ($cdom,$title) = @_;
9166: # get lock on ltitools db
9167: my $lockhash = {
9168: lock => $env{'user.name'}.
9169: ':'.$env{'user.domain'},
9170: };
9171: my $tries = 0;
9172: my $gotlock = &Apache::lonnet::newput_dom('ltitools',$lockhash,$cdom);
9173: my ($id,$error);
9174:
9175: while (($gotlock ne 'ok') && ($tries<10)) {
9176: $tries ++;
9177: sleep (0.1);
9178: $gotlock = &Apache::lonnet::newput_dom('ltitools',$lockhash,$cdom);
9179: }
9180: if ($gotlock eq 'ok') {
9181: my %currids = &Apache::lonnet::dump_dom('ltitools',$cdom);
9182: if ($currids{'lock'}) {
9183: delete($currids{'lock'});
9184: if (keys(%currids)) {
9185: my @curr = sort { $a <=> $b } keys(%currids);
9186: if ($curr[-1] =~ /^\d+$/) {
9187: $id = 1 + $curr[-1];
9188: }
9189: } else {
9190: $id = 1;
9191: }
9192: if ($id) {
9193: unless (&Apache::lonnet::newput_dom('ltitools',{ $id => $title },$cdom) eq 'ok') {
9194: $error = 'nostore';
9195: }
9196: } else {
9197: $error = 'nonumber';
9198: }
9199: }
9200: my $dellockoutcome = &Apache::lonnet::del_dom('ltitools',['lock'],$cdom);
9201: } else {
9202: $error = 'nolock';
9203: }
9204: return ($id,$error);
9205: }
9206:
1.3 raeburn 9207: sub modify_autoenroll {
1.205 raeburn 9208: my ($dom,$lastactref,%domconfig) = @_;
1.1 raeburn 9209: my ($resulttext,%changes);
9210: my %currautoenroll;
9211: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
9212: foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
9213: $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
9214: }
9215: }
9216: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
9217: my %title = ( run => 'Auto-enrollment active',
1.129 raeburn 9218: sender => 'Sender for notification messages',
1.274 raeburn 9219: coowners => 'Automatic assignment of co-ownership to instructors of record (institutional data)',
9220: failsafe => 'Failsafe for no drops if institutional data missing for a section');
1.1 raeburn 9221: my @offon = ('off','on');
1.17 raeburn 9222: my $sender_uname = $env{'form.sender_uname'};
9223: my $sender_domain = $env{'form.sender_domain'};
9224: if ($sender_domain eq '') {
9225: $sender_uname = '';
9226: } elsif ($sender_uname eq '') {
9227: $sender_domain = '';
9228: }
1.129 raeburn 9229: my $coowners = $env{'form.autoassign_coowners'};
1.274 raeburn 9230: my $failsafe = $env{'form.autoenroll_failsafe'};
9231: $failsafe =~ s{^\s+|\s+$}{}g;
9232: if ($failsafe =~ /\D/) {
9233: undef($failsafe);
9234: }
1.1 raeburn 9235: my %autoenrollhash = (
1.129 raeburn 9236: autoenroll => { 'run' => $env{'form.autoenroll_run'},
9237: 'sender_uname' => $sender_uname,
9238: 'sender_domain' => $sender_domain,
9239: 'co-owners' => $coowners,
1.274 raeburn 9240: 'autofailsafe' => $failsafe,
1.1 raeburn 9241: }
9242: );
1.4 raeburn 9243: my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
9244: $dom);
1.1 raeburn 9245: if ($putresult eq 'ok') {
9246: if (exists($currautoenroll{'run'})) {
9247: if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
9248: $changes{'run'} = 1;
9249: }
9250: } elsif ($autorun) {
9251: if ($env{'form.autoenroll_run'} ne '1') {
1.23 raeburn 9252: $changes{'run'} = 1;
1.1 raeburn 9253: }
9254: }
1.17 raeburn 9255: if ($currautoenroll{'sender_uname'} ne $sender_uname) {
1.1 raeburn 9256: $changes{'sender'} = 1;
9257: }
1.17 raeburn 9258: if ($currautoenroll{'sender_domain'} ne $sender_domain) {
1.1 raeburn 9259: $changes{'sender'} = 1;
9260: }
1.129 raeburn 9261: if ($currautoenroll{'co-owners'} ne '') {
9262: if ($currautoenroll{'co-owners'} ne $coowners) {
9263: $changes{'coowners'} = 1;
9264: }
9265: } elsif ($coowners) {
9266: $changes{'coowners'} = 1;
1.274 raeburn 9267: }
9268: if ($currautoenroll{'autofailsafe'} ne $failsafe) {
9269: $changes{'autofailsafe'} = 1;
9270: }
1.1 raeburn 9271: if (keys(%changes) > 0) {
9272: $resulttext = &mt('Changes made:').'<ul>';
1.3 raeburn 9273: if ($changes{'run'}) {
1.1 raeburn 9274: $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
9275: }
9276: if ($changes{'sender'}) {
1.17 raeburn 9277: if ($sender_uname eq '' || $sender_domain eq '') {
9278: $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
9279: } else {
9280: $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
9281: }
1.1 raeburn 9282: }
1.129 raeburn 9283: if ($changes{'coowners'}) {
9284: $resulttext .= '<li>'.&mt("$title{'coowners'} set to $offon[$env{'form.autoassign_coowners'}]").'</li>';
9285: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 9286: if (ref($lastactref) eq 'HASH') {
9287: $lastactref->{'domainconfig'} = 1;
9288: }
1.129 raeburn 9289: }
1.274 raeburn 9290: if ($changes{'autofailsafe'}) {
9291: if ($failsafe ne '') {
9292: $resulttext .= '<li>'.&mt("$title{'failsafe'} set to [_1]",$failsafe).'</li>';
9293: } else {
9294: $resulttext .= '<li>'.&mt("$title{'failsafe'} deleted");
9295: }
9296: &Apache::lonnet::get_domain_defaults($dom,1);
9297: if (ref($lastactref) eq 'HASH') {
9298: $lastactref->{'domdefaults'} = 1;
9299: }
9300: }
1.1 raeburn 9301: $resulttext .= '</ul>';
9302: } else {
9303: $resulttext = &mt('No changes made to auto-enrollment settings');
9304: }
9305: } else {
1.11 albertel 9306: $resulttext = '<span class="LC_error">'.
9307: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 9308: }
1.3 raeburn 9309: return $resulttext;
1.1 raeburn 9310: }
9311:
9312: sub modify_autoupdate {
1.3 raeburn 9313: my ($dom,%domconfig) = @_;
1.1 raeburn 9314: my ($resulttext,%currautoupdate,%fields,%changes);
9315: if (ref($domconfig{'autoupdate'}) eq 'HASH') {
9316: foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
9317: $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
9318: }
9319: }
9320: my @offon = ('off','on');
9321: my %title = &Apache::lonlocal::texthash (
9322: run => 'Auto-update:',
9323: classlists => 'Updates to user information in classlists?'
9324: );
1.44 raeburn 9325: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 9326: my %fieldtitles = &Apache::lonlocal::texthash (
9327: id => 'Student/Employee ID',
1.20 raeburn 9328: permanentemail => 'E-mail address',
1.1 raeburn 9329: lastname => 'Last Name',
9330: firstname => 'First Name',
9331: middlename => 'Middle Name',
1.132 raeburn 9332: generation => 'Generation',
1.1 raeburn 9333: );
1.142 raeburn 9334: $othertitle = &mt('All users');
1.1 raeburn 9335: if (keys(%{$usertypes}) > 0) {
1.26 raeburn 9336: $othertitle = &mt('Other users');
1.1 raeburn 9337: }
9338: foreach my $key (keys(%env)) {
9339: if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
1.132 raeburn 9340: my ($usertype,$item) = ($1,$2);
9341: if (grep(/^\Q$item\E$/,keys(%fieldtitles))) {
9342: if ($usertype eq 'default') {
9343: push(@{$fields{$1}},$2);
9344: } elsif (ref($types) eq 'ARRAY') {
9345: if (grep(/^\Q$usertype\E$/,@{$types})) {
9346: push(@{$fields{$1}},$2);
9347: }
9348: }
9349: }
1.1 raeburn 9350: }
9351: }
1.131 raeburn 9352: my @lockablenames = &Apache::loncommon::get_env_multiple('form.lockablenames');
9353: @lockablenames = sort(@lockablenames);
9354: if (ref($currautoupdate{'lockablenames'}) eq 'ARRAY') {
9355: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
9356: if (@changed) {
9357: $changes{'lockablenames'} = 1;
9358: }
9359: } else {
9360: if (@lockablenames) {
9361: $changes{'lockablenames'} = 1;
9362: }
9363: }
1.1 raeburn 9364: my %updatehash = (
9365: autoupdate => { run => $env{'form.autoupdate_run'},
9366: classlists => $env{'form.classlists'},
9367: fields => {%fields},
1.131 raeburn 9368: lockablenames => \@lockablenames,
1.1 raeburn 9369: }
9370: );
9371: foreach my $key (keys(%currautoupdate)) {
9372: if (($key eq 'run') || ($key eq 'classlists')) {
9373: if (exists($updatehash{autoupdate}{$key})) {
9374: if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
9375: $changes{$key} = 1;
9376: }
9377: }
9378: } elsif ($key eq 'fields') {
9379: if (ref($currautoupdate{$key}) eq 'HASH') {
1.26 raeburn 9380: foreach my $item (@{$types},'default') {
1.1 raeburn 9381: if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
9382: my $change = 0;
9383: foreach my $type (@{$currautoupdate{$key}{$item}}) {
9384: if (!exists($fields{$item})) {
9385: $change = 1;
1.132 raeburn 9386: last;
1.1 raeburn 9387: } elsif (ref($fields{$item}) eq 'ARRAY') {
1.26 raeburn 9388: if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
1.1 raeburn 9389: $change = 1;
1.132 raeburn 9390: last;
1.1 raeburn 9391: }
9392: }
9393: }
9394: if ($change) {
9395: push(@{$changes{$key}},$item);
9396: }
1.26 raeburn 9397: }
1.1 raeburn 9398: }
9399: }
1.131 raeburn 9400: } elsif ($key eq 'lockablenames') {
9401: if (ref($currautoupdate{$key}) eq 'ARRAY') {
9402: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
9403: if (@changed) {
9404: $changes{'lockablenames'} = 1;
9405: }
9406: } else {
9407: if (@lockablenames) {
9408: $changes{'lockablenames'} = 1;
9409: }
9410: }
9411: }
9412: }
9413: unless (grep(/^\Qlockablenames\E$/,keys(%currautoupdate))) {
9414: if (@lockablenames) {
9415: $changes{'lockablenames'} = 1;
1.1 raeburn 9416: }
9417: }
1.26 raeburn 9418: foreach my $item (@{$types},'default') {
9419: if (defined($fields{$item})) {
9420: if (ref($currautoupdate{'fields'}) eq 'HASH') {
1.132 raeburn 9421: if (ref($currautoupdate{'fields'}{$item}) eq 'ARRAY') {
9422: my $change = 0;
9423: if (ref($fields{$item}) eq 'ARRAY') {
9424: foreach my $type (@{$fields{$item}}) {
9425: if (!grep(/^\Q$type\E$/,@{$currautoupdate{'fields'}{$item}})) {
9426: $change = 1;
9427: last;
9428: }
9429: }
9430: }
9431: if ($change) {
9432: push(@{$changes{'fields'}},$item);
9433: }
9434: } else {
1.26 raeburn 9435: push(@{$changes{'fields'}},$item);
9436: }
9437: } else {
9438: push(@{$changes{'fields'}},$item);
1.1 raeburn 9439: }
9440: }
9441: }
9442: my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
9443: $dom);
9444: if ($putresult eq 'ok') {
9445: if (keys(%changes) > 0) {
9446: $resulttext = &mt('Changes made:').'<ul>';
9447: foreach my $key (sort(keys(%changes))) {
1.131 raeburn 9448: if ($key eq 'lockablenames') {
9449: $resulttext .= '<li>';
9450: if (@lockablenames) {
9451: $usertypes->{'default'} = $othertitle;
9452: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update), available for the following affiliations:").' '.
9453: join(', ', map { $usertypes->{$_}; } @lockablenames).'</li>';
9454: } else {
9455: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update) is unavailable.");
9456: }
9457: $resulttext .= '</li>';
9458: } elsif (ref($changes{$key}) eq 'ARRAY') {
1.1 raeburn 9459: foreach my $item (@{$changes{$key}}) {
9460: my @newvalues;
9461: foreach my $type (@{$fields{$item}}) {
9462: push(@newvalues,$fieldtitles{$type});
9463: }
1.3 raeburn 9464: my $newvaluestr;
9465: if (@newvalues > 0) {
9466: $newvaluestr = join(', ',@newvalues);
9467: } else {
9468: $newvaluestr = &mt('none');
1.6 raeburn 9469: }
1.1 raeburn 9470: if ($item eq 'default') {
1.26 raeburn 9471: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
1.1 raeburn 9472: } else {
1.26 raeburn 9473: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
1.1 raeburn 9474: }
9475: }
9476: } else {
9477: my $newvalue;
9478: if ($key eq 'run') {
9479: $newvalue = $offon[$env{'form.autoupdate_run'}];
9480: } else {
9481: $newvalue = $offon[$env{'form.'.$key}];
1.3 raeburn 9482: }
1.1 raeburn 9483: $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
9484: }
9485: }
9486: $resulttext .= '</ul>';
9487: } else {
1.3 raeburn 9488: $resulttext = &mt('No changes made to autoupdates');
1.1 raeburn 9489: }
9490: } else {
1.11 albertel 9491: $resulttext = '<span class="LC_error">'.
9492: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 9493: }
1.3 raeburn 9494: return $resulttext;
1.1 raeburn 9495: }
9496:
1.125 raeburn 9497: sub modify_autocreate {
9498: my ($dom,%domconfig) = @_;
9499: my ($resulttext,%changes,%currautocreate,%newvals,%autocreatehash);
9500: if (ref($domconfig{'autocreate'}) eq 'HASH') {
9501: foreach my $key (keys(%{$domconfig{'autocreate'}})) {
9502: $currautocreate{$key} = $domconfig{'autocreate'}{$key};
9503: }
9504: }
9505: my %title= ( xml => 'Auto-creation of courses in XML course description files',
9506: req => 'Auto-creation of validated requests for official courses',
9507: xmldc => 'Identity of course creator of courses from XML files',
9508: );
9509: my @types = ('xml','req');
9510: foreach my $item (@types) {
9511: $newvals{$item} = $env{'form.autocreate_'.$item};
9512: $newvals{$item} =~ s/\D//g;
9513: $newvals{$item} = 0 if ($newvals{$item} eq '');
9514: }
9515: $newvals{'xmldc'} = $env{'form.autocreate_xmldc'};
9516: my %domcoords = &get_active_dcs($dom);
9517: unless (exists($domcoords{$newvals{'xmldc'}})) {
9518: $newvals{'xmldc'} = '';
9519: }
9520: %autocreatehash = (
9521: autocreate => { xml => $newvals{'xml'},
9522: req => $newvals{'req'},
9523: }
9524: );
9525: if ($newvals{'xmldc'} ne '') {
9526: $autocreatehash{'autocreate'}{'xmldc'} = $newvals{'xmldc'};
9527: }
9528: my $putresult = &Apache::lonnet::put_dom('configuration',\%autocreatehash,
9529: $dom);
9530: if ($putresult eq 'ok') {
9531: my @items = @types;
9532: if ($newvals{'xml'}) {
9533: push(@items,'xmldc');
9534: }
9535: foreach my $item (@items) {
9536: if (exists($currautocreate{$item})) {
9537: if ($currautocreate{$item} ne $newvals{$item}) {
9538: $changes{$item} = 1;
9539: }
9540: } elsif ($newvals{$item}) {
9541: $changes{$item} = 1;
9542: }
9543: }
9544: if (keys(%changes) > 0) {
9545: my @offon = ('off','on');
9546: $resulttext = &mt('Changes made:').'<ul>';
9547: foreach my $item (@types) {
9548: if ($changes{$item}) {
9549: my $newtxt = $offon[$newvals{$item}];
1.178 raeburn 9550: $resulttext .= '<li>'.
9551: &mt("$title{$item} set to [_1]$newtxt [_2]",
9552: '<b>','</b>').
9553: '</li>';
1.125 raeburn 9554: }
9555: }
9556: if ($changes{'xmldc'}) {
9557: my ($dcname,$dcdom) = split(':',$newvals{'xmldc'});
9558: my $newtxt = &Apache::loncommon::plainname($dcname,$dcdom);
1.178 raeburn 9559: $resulttext .= '<li>'.&mt("$title{'xmldc'} set to [_1]",'<b>'.$newtxt.'</b>').'</li>';
1.125 raeburn 9560: }
9561: $resulttext .= '</ul>';
9562: } else {
9563: $resulttext = &mt('No changes made to auto-creation settings');
9564: }
9565: } else {
9566: $resulttext = '<span class="LC_error">'.
9567: &mt('An error occurred: [_1]',$putresult).'</span>';
9568: }
9569: return $resulttext;
9570: }
9571:
1.23 raeburn 9572: sub modify_directorysrch {
9573: my ($dom,%domconfig) = @_;
9574: my ($resulttext,%changes);
9575: my %currdirsrch;
9576: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
9577: foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
9578: $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
9579: }
9580: }
1.277 raeburn 9581: my %title = ( available => 'Institutional directory search available',
9582: localonly => 'Other domains can search institution',
9583: lcavailable => 'LON-CAPA directory search available',
9584: lclocalonly => 'Other domains can search LON-CAPA domain',
1.23 raeburn 9585: searchby => 'Search types',
9586: searchtypes => 'Search latitude');
9587: my @offon = ('off','on');
1.24 raeburn 9588: my @otherdoms = ('Yes','No');
1.23 raeburn 9589:
1.25 raeburn 9590: my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');
1.23 raeburn 9591: my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
9592: my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
9593:
1.44 raeburn 9594: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.26 raeburn 9595: if (keys(%{$usertypes}) == 0) {
9596: @cansearch = ('default');
9597: } else {
9598: if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
9599: foreach my $type (@{$currdirsrch{'cansearch'}}) {
9600: if (!grep(/^\Q$type\E$/,@cansearch)) {
9601: push(@{$changes{'cansearch'}},$type);
9602: }
1.23 raeburn 9603: }
1.26 raeburn 9604: foreach my $type (@cansearch) {
9605: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
9606: push(@{$changes{'cansearch'}},$type);
9607: }
1.23 raeburn 9608: }
1.26 raeburn 9609: } else {
9610: push(@{$changes{'cansearch'}},@cansearch);
1.23 raeburn 9611: }
9612: }
9613:
9614: if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
9615: foreach my $by (@{$currdirsrch{'searchby'}}) {
9616: if (!grep(/^\Q$by\E$/,@searchby)) {
9617: push(@{$changes{'searchby'}},$by);
9618: }
9619: }
9620: foreach my $by (@searchby) {
9621: if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
9622: push(@{$changes{'searchby'}},$by);
9623: }
9624: }
9625: } else {
9626: push(@{$changes{'searchby'}},@searchby);
9627: }
1.25 raeburn 9628:
9629: if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
9630: foreach my $type (@{$currdirsrch{'searchtypes'}}) {
9631: if (!grep(/^\Q$type\E$/,@searchtypes)) {
9632: push(@{$changes{'searchtypes'}},$type);
9633: }
9634: }
9635: foreach my $type (@searchtypes) {
9636: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
9637: push(@{$changes{'searchtypes'}},$type);
9638: }
9639: }
9640: } else {
9641: if (exists($currdirsrch{'searchtypes'})) {
9642: foreach my $type (@searchtypes) {
9643: if ($type ne $currdirsrch{'searchtypes'}) {
9644: push(@{$changes{'searchtypes'}},$type);
9645: }
9646: }
9647: if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
9648: push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
9649: }
9650: } else {
9651: push(@{$changes{'searchtypes'}},@searchtypes);
9652: }
9653: }
9654:
1.23 raeburn 9655: my %dirsrch_hash = (
9656: directorysrch => { available => $env{'form.dirsrch_available'},
9657: cansearch => \@cansearch,
1.277 raeburn 9658: localonly => $env{'form.dirsrch_instlocalonly'},
9659: lclocalonly => $env{'form.dirsrch_domlocalonly'},
9660: lcavailable => $env{'form.dirsrch_domavailable'},
1.23 raeburn 9661: searchby => \@searchby,
1.25 raeburn 9662: searchtypes => \@searchtypes,
1.23 raeburn 9663: }
9664: );
9665: my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
9666: $dom);
9667: if ($putresult eq 'ok') {
9668: if (exists($currdirsrch{'available'})) {
9669: if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
9670: $changes{'available'} = 1;
9671: }
9672: } else {
9673: if ($env{'form.dirsrch_available'} eq '1') {
9674: $changes{'available'} = 1;
9675: }
9676: }
1.277 raeburn 9677: if (exists($currdirsrch{'lcavailable'})) {
9678: if ($currdirsrch{'lcavailable'} ne $env{'form.dirsrch_domavailable'}) {
9679: $changes{'lcavailable'} = 1;
9680: }
9681: } else {
9682: if ($env{'form.dirsrch_lcavailable'} eq '1') {
9683: $changes{'lcavailable'} = 1;
9684: }
9685: }
1.24 raeburn 9686: if (exists($currdirsrch{'localonly'})) {
1.277 raeburn 9687: if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_instlocalonly'}) {
1.24 raeburn 9688: $changes{'localonly'} = 1;
9689: }
9690: } else {
1.277 raeburn 9691: if ($env{'form.dirsrch_instlocalonly'} eq '1') {
1.24 raeburn 9692: $changes{'localonly'} = 1;
9693: }
9694: }
1.277 raeburn 9695: if (exists($currdirsrch{'lclocalonly'})) {
9696: if ($currdirsrch{'lclocalonly'} ne $env{'form.dirsrch_domlocalonly'}) {
9697: $changes{'lclocalonly'} = 1;
9698: }
9699: } else {
9700: if ($env{'form.dirsrch_domlocalonly'} eq '1') {
9701: $changes{'lclocalonly'} = 1;
9702: }
9703: }
1.23 raeburn 9704: if (keys(%changes) > 0) {
9705: $resulttext = &mt('Changes made:').'<ul>';
9706: if ($changes{'available'}) {
9707: $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
9708: }
1.277 raeburn 9709: if ($changes{'lcavailable'}) {
9710: $resulttext .= '<li>'.&mt("$title{'lcavailable'} set to: $offon[$env{'form.dirsrch_domavailable'}]").'</li>';
9711: }
1.24 raeburn 9712: if ($changes{'localonly'}) {
1.277 raeburn 9713: $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_instlocalonly'}]").'</li>';
1.24 raeburn 9714: }
1.277 raeburn 9715: if ($changes{'lclocalonly'}) {
9716: $resulttext .= '<li>'.&mt("$title{'lclocalonly'} set to: $otherdoms[$env{'form.dirsrch_domlocalonly'}]").'</li>';
9717: }
1.23 raeburn 9718: if (ref($changes{'cansearch'}) eq 'ARRAY') {
9719: my $chgtext;
1.26 raeburn 9720: if (ref($usertypes) eq 'HASH') {
9721: if (keys(%{$usertypes}) > 0) {
9722: foreach my $type (@{$types}) {
9723: if (grep(/^\Q$type\E$/,@cansearch)) {
9724: $chgtext .= $usertypes->{$type}.'; ';
9725: }
9726: }
9727: if (grep(/^default$/,@cansearch)) {
9728: $chgtext .= $othertitle;
9729: } else {
9730: $chgtext =~ s/\; $//;
9731: }
1.210 raeburn 9732: $resulttext .=
1.178 raeburn 9733: '<li>'.
9734: &mt("Users from domain '[_1]' permitted to search the institutional directory set to: [_2]",
9735: '<span class="LC_cusr_emph">'.$dom.'</span>',$chgtext).
9736: '</li>';
1.23 raeburn 9737: }
9738: }
9739: }
9740: if (ref($changes{'searchby'}) eq 'ARRAY') {
9741: my ($searchtitles,$titleorder) = &sorted_searchtitles();
9742: my $chgtext;
9743: foreach my $type (@{$titleorder}) {
9744: if (grep(/^\Q$type\E$/,@searchby)) {
9745: if (defined($searchtitles->{$type})) {
9746: $chgtext .= $searchtitles->{$type}.'; ';
9747: }
9748: }
9749: }
9750: $chgtext =~ s/\; $//;
9751: $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
9752: }
1.25 raeburn 9753: if (ref($changes{'searchtypes'}) eq 'ARRAY') {
9754: my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes();
9755: my $chgtext;
9756: foreach my $type (@{$srchtypeorder}) {
9757: if (grep(/^\Q$type\E$/,@searchtypes)) {
9758: if (defined($srchtypes_desc->{$type})) {
9759: $chgtext .= $srchtypes_desc->{$type}.'; ';
9760: }
9761: }
9762: }
9763: $chgtext =~ s/\; $//;
1.178 raeburn 9764: $resulttext .= '<li>'.&mt($title{'searchtypes'}.' set to: "[_1]"',$chgtext).'</li>';
1.23 raeburn 9765: }
9766: $resulttext .= '</ul>';
9767: } else {
1.277 raeburn 9768: $resulttext = &mt('No changes made to directory search settings');
1.23 raeburn 9769: }
9770: } else {
9771: $resulttext = '<span class="LC_error">'.
1.27 raeburn 9772: &mt('An error occurred: [_1]',$putresult).'</span>';
9773: }
9774: return $resulttext;
9775: }
9776:
1.28 raeburn 9777: sub modify_contacts {
1.205 raeburn 9778: my ($dom,$lastactref,%domconfig) = @_;
1.28 raeburn 9779: my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
9780: if (ref($domconfig{'contacts'}) eq 'HASH') {
9781: foreach my $key (keys(%{$domconfig{'contacts'}})) {
9782: $currsetting{$key} = $domconfig{'contacts'}{$key};
9783: }
9784: }
1.134 raeburn 9785: my (%others,%to,%bcc);
1.28 raeburn 9786: my @contacts = ('supportemail','adminemail');
1.102 raeburn 9787: my @mailings = ('errormail','packagesmail','helpdeskmail','lonstatusmail',
1.203 raeburn 9788: 'requestsmail','updatesmail','idconflictsmail');
9789: my @toggles = ('reporterrors','reportupdates');
1.28 raeburn 9790: foreach my $type (@mailings) {
9791: @{$newsetting{$type}} =
9792: &Apache::loncommon::get_env_multiple('form.'.$type);
9793: foreach my $item (@contacts) {
9794: if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
9795: $contacts_hash{contacts}{$type}{$item} = 1;
9796: } else {
9797: $contacts_hash{contacts}{$type}{$item} = 0;
9798: }
9799: }
9800: $others{$type} = $env{'form.'.$type.'_others'};
9801: $contacts_hash{contacts}{$type}{'others'} = $others{$type};
1.134 raeburn 9802: if ($type eq 'helpdeskmail') {
9803: $bcc{$type} = $env{'form.'.$type.'_bcc'};
9804: $contacts_hash{contacts}{$type}{'bcc'} = $bcc{$type};
9805: }
1.28 raeburn 9806: }
9807: foreach my $item (@contacts) {
9808: $to{$item} = $env{'form.'.$item};
9809: $contacts_hash{'contacts'}{$item} = $to{$item};
9810: }
1.203 raeburn 9811: foreach my $item (@toggles) {
9812: if ($env{'form.'.$item} =~ /^(0|1)$/) {
9813: $contacts_hash{'contacts'}{$item} = $env{'form.'.$item};
9814: }
9815: }
1.28 raeburn 9816: if (keys(%currsetting) > 0) {
9817: foreach my $item (@contacts) {
9818: if ($to{$item} ne $currsetting{$item}) {
9819: $changes{$item} = 1;
9820: }
9821: }
9822: foreach my $type (@mailings) {
9823: foreach my $item (@contacts) {
9824: if (ref($currsetting{$type}) eq 'HASH') {
9825: if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
9826: push(@{$changes{$type}},$item);
9827: }
9828: } else {
9829: push(@{$changes{$type}},@{$newsetting{$type}});
9830: }
9831: }
9832: if ($others{$type} ne $currsetting{$type}{'others'}) {
9833: push(@{$changes{$type}},'others');
9834: }
1.134 raeburn 9835: if ($type eq 'helpdeskmail') {
9836: if ($bcc{$type} ne $currsetting{$type}{'bcc'}) {
9837: push(@{$changes{$type}},'bcc');
9838: }
9839: }
1.28 raeburn 9840: }
9841: } else {
9842: my %default;
9843: $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
9844: $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
9845: $default{'errormail'} = 'adminemail';
9846: $default{'packagesmail'} = 'adminemail';
9847: $default{'helpdeskmail'} = 'supportemail';
1.89 raeburn 9848: $default{'lonstatusmail'} = 'adminemail';
1.102 raeburn 9849: $default{'requestsmail'} = 'adminemail';
1.190 raeburn 9850: $default{'updatesmail'} = 'adminemail';
1.28 raeburn 9851: foreach my $item (@contacts) {
9852: if ($to{$item} ne $default{$item}) {
9853: $changes{$item} = 1;
1.203 raeburn 9854: }
1.28 raeburn 9855: }
9856: foreach my $type (@mailings) {
9857: if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
9858:
9859: push(@{$changes{$type}},@{$newsetting{$type}});
9860: }
9861: if ($others{$type} ne '') {
9862: push(@{$changes{$type}},'others');
1.134 raeburn 9863: }
9864: if ($type eq 'helpdeskmail') {
9865: if ($bcc{$type} ne '') {
9866: push(@{$changes{$type}},'bcc');
9867: }
9868: }
1.28 raeburn 9869: }
9870: }
1.203 raeburn 9871: foreach my $item (@toggles) {
9872: if (($env{'form.'.$item} == 1) && ($currsetting{$item} == 0)) {
9873: $changes{$item} = 1;
9874: } elsif ((!$env{'form.'.$item}) &&
9875: (($currsetting{$item} eq '') || ($currsetting{$item} == 1))) {
9876: $changes{$item} = 1;
9877: }
9878: }
1.28 raeburn 9879: my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
9880: $dom);
9881: if ($putresult eq 'ok') {
9882: if (keys(%changes) > 0) {
1.205 raeburn 9883: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 9884: if (ref($lastactref) eq 'HASH') {
9885: $lastactref->{'domainconfig'} = 1;
9886: }
1.28 raeburn 9887: my ($titles,$short_titles) = &contact_titles();
9888: $resulttext = &mt('Changes made:').'<ul>';
9889: foreach my $item (@contacts) {
9890: if ($changes{$item}) {
9891: $resulttext .= '<li>'.$titles->{$item}.
9892: &mt(' set to: ').
9893: '<span class="LC_cusr_emph">'.
9894: $to{$item}.'</span></li>';
9895: }
9896: }
9897: foreach my $type (@mailings) {
9898: if (ref($changes{$type}) eq 'ARRAY') {
9899: $resulttext .= '<li>'.$titles->{$type}.': ';
9900: my @text;
9901: foreach my $item (@{$newsetting{$type}}) {
9902: push(@text,$short_titles->{$item});
9903: }
9904: if ($others{$type} ne '') {
9905: push(@text,$others{$type});
9906: }
9907: $resulttext .= '<span class="LC_cusr_emph">'.
1.134 raeburn 9908: join(', ',@text).'</span>';
9909: if ($type eq 'helpdeskmail') {
9910: if ($bcc{$type} ne '') {
9911: $resulttext .= ' '.&mt('with Bcc to').': <span class="LC_cusr_emph">'.$bcc{$type}.'</span>';
9912: }
9913: }
9914: $resulttext .= '</li>';
1.28 raeburn 9915: }
9916: }
1.203 raeburn 9917: my @offon = ('off','on');
9918: if ($changes{'reporterrors'}) {
9919: $resulttext .= '<li>'.
9920: &mt('E-mail error reports to [_1] set to "'.
9921: $offon[$env{'form.reporterrors'}].'".',
9922: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
9923: &mt('LON-CAPA core group - MSU'),600,500)).
9924: '</li>';
9925: }
9926: if ($changes{'reportupdates'}) {
9927: $resulttext .= '<li>'.
9928: &mt('E-mail record of completed LON-CAPA updates to [_1] set to "'.
9929: $offon[$env{'form.reportupdates'}].'".',
9930: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
9931: &mt('LON-CAPA core group - MSU'),600,500)).
9932: '</li>';
9933: }
1.28 raeburn 9934: $resulttext .= '</ul>';
9935: } else {
1.34 raeburn 9936: $resulttext = &mt('No changes made to contact information');
1.28 raeburn 9937: }
9938: } else {
9939: $resulttext = '<span class="LC_error">'.
9940: &mt('An error occurred: [_1].',$putresult).'</span>';
9941: }
9942: return $resulttext;
9943: }
9944:
9945: sub modify_usercreation {
1.27 raeburn 9946: my ($dom,%domconfig) = @_;
1.224 raeburn 9947: my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate,%save_usercreate);
1.43 raeburn 9948: my $warningmsg;
1.27 raeburn 9949: if (ref($domconfig{'usercreation'}) eq 'HASH') {
9950: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
1.224 raeburn 9951: if ($key eq 'cancreate') {
9952: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
9953: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
9954: if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
1.269 raeburn 9955: ($item eq 'captcha') || ($item eq 'recaptchakeys') ||
9956: ($item eq 'recaptchaversion')) {
1.224 raeburn 9957: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
9958: } else {
9959: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
9960: }
9961: }
9962: }
9963: } elsif ($key eq 'email_rule') {
9964: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
9965: } else {
9966: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
9967: }
1.27 raeburn 9968: }
9969: }
9970: my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
1.32 raeburn 9971: my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
1.224 raeburn 9972: my @contexts = ('author','course','requestcrs');
1.34 raeburn 9973: foreach my $item(@contexts) {
1.224 raeburn 9974: $cancreate{$item} = $env{'form.can_createuser_'.$item};
1.93 raeburn 9975: }
1.34 raeburn 9976: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
9977: foreach my $item (@contexts) {
1.224 raeburn 9978: if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
9979: push(@{$changes{'cancreate'}},$item);
1.50 raeburn 9980: }
1.27 raeburn 9981: }
1.34 raeburn 9982: } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
9983: foreach my $item (@contexts) {
1.43 raeburn 9984: if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
1.34 raeburn 9985: if ($cancreate{$item} ne 'any') {
9986: push(@{$changes{'cancreate'}},$item);
9987: }
9988: } else {
9989: if ($cancreate{$item} ne 'none') {
9990: push(@{$changes{'cancreate'}},$item);
9991: }
1.27 raeburn 9992: }
9993: }
9994: } else {
1.43 raeburn 9995: foreach my $item (@contexts) {
1.34 raeburn 9996: push(@{$changes{'cancreate'}},$item);
9997: }
1.27 raeburn 9998: }
1.34 raeburn 9999:
1.27 raeburn 10000: if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
10001: foreach my $type (@{$curr_usercreation{'username_rule'}}) {
10002: if (!grep(/^\Q$type\E$/,@username_rule)) {
10003: push(@{$changes{'username_rule'}},$type);
10004: }
10005: }
10006: foreach my $type (@username_rule) {
10007: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
10008: push(@{$changes{'username_rule'}},$type);
10009: }
10010: }
10011: } else {
10012: push(@{$changes{'username_rule'}},@username_rule);
10013: }
10014:
1.32 raeburn 10015: if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
10016: foreach my $type (@{$curr_usercreation{'id_rule'}}) {
10017: if (!grep(/^\Q$type\E$/,@id_rule)) {
10018: push(@{$changes{'id_rule'}},$type);
10019: }
10020: }
10021: foreach my $type (@id_rule) {
10022: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
10023: push(@{$changes{'id_rule'}},$type);
10024: }
10025: }
10026: } else {
10027: push(@{$changes{'id_rule'}},@id_rule);
10028: }
10029:
1.43 raeburn 10030: my @authen_contexts = ('author','course','domain');
1.28 raeburn 10031: my @authtypes = ('int','krb4','krb5','loc');
10032: my %authhash;
1.43 raeburn 10033: foreach my $item (@authen_contexts) {
1.28 raeburn 10034: my @authallowed = &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
10035: foreach my $auth (@authtypes) {
10036: if (grep(/^\Q$auth\E$/,@authallowed)) {
10037: $authhash{$item}{$auth} = 1;
10038: } else {
10039: $authhash{$item}{$auth} = 0;
10040: }
10041: }
10042: }
10043: if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
1.43 raeburn 10044: foreach my $item (@authen_contexts) {
1.28 raeburn 10045: if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
10046: foreach my $auth (@authtypes) {
10047: if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
10048: push(@{$changes{'authtypes'}},$item);
10049: last;
10050: }
10051: }
10052: }
10053: }
10054: } else {
1.43 raeburn 10055: foreach my $item (@authen_contexts) {
1.28 raeburn 10056: push(@{$changes{'authtypes'}},$item);
10057: }
10058: }
10059:
1.224 raeburn 10060: $save_usercreate{'cancreate'}{'course'} = $cancreate{'course'};
10061: $save_usercreate{'cancreate'}{'author'} = $cancreate{'author'};
10062: $save_usercreate{'cancreate'}{'requestcrs'} = $cancreate{'requestcrs'};
10063: $save_usercreate{'id_rule'} = \@id_rule;
10064: $save_usercreate{'username_rule'} = \@username_rule,
10065: $save_usercreate{'authtypes'} = \%authhash;
10066:
1.27 raeburn 10067: my %usercreation_hash = (
1.224 raeburn 10068: usercreation => \%save_usercreate,
10069: );
1.27 raeburn 10070:
10071: my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
10072: $dom);
1.50 raeburn 10073:
1.224 raeburn 10074: if ($putresult eq 'ok') {
10075: if (keys(%changes) > 0) {
10076: $resulttext = &mt('Changes made:').'<ul>';
10077: if (ref($changes{'cancreate'}) eq 'ARRAY') {
10078: my %lt = &usercreation_types();
10079: foreach my $type (@{$changes{'cancreate'}}) {
10080: my $chgtext = $lt{$type}.', ';
10081: if ($cancreate{$type} eq 'none') {
10082: $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
10083: } elsif ($cancreate{$type} eq 'any') {
10084: $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
10085: } elsif ($cancreate{$type} eq 'official') {
10086: $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
10087: } elsif ($cancreate{$type} eq 'unofficial') {
10088: $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
10089: }
10090: $resulttext .= '<li>'.$chgtext.'</li>';
10091: }
10092: }
10093: if (ref($changes{'username_rule'}) eq 'ARRAY') {
10094: my ($rules,$ruleorder) =
10095: &Apache::lonnet::inst_userrules($dom,'username');
10096: my $chgtext = '<ul>';
10097: foreach my $type (@username_rule) {
10098: if (ref($rules->{$type}) eq 'HASH') {
10099: $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
10100: }
10101: }
10102: $chgtext .= '</ul>';
10103: if (@username_rule > 0) {
10104: $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
10105: } else {
10106: $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>';
10107: }
10108: }
10109: if (ref($changes{'id_rule'}) eq 'ARRAY') {
10110: my ($idrules,$idruleorder) =
10111: &Apache::lonnet::inst_userrules($dom,'id');
10112: my $chgtext = '<ul>';
10113: foreach my $type (@id_rule) {
10114: if (ref($idrules->{$type}) eq 'HASH') {
10115: $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
10116: }
10117: }
10118: $chgtext .= '</ul>';
10119: if (@id_rule > 0) {
10120: $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
10121: } else {
10122: $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
10123: }
10124: }
10125: my %authname = &authtype_names();
10126: my %context_title = &context_names();
10127: if (ref($changes{'authtypes'}) eq 'ARRAY') {
10128: my $chgtext = '<ul>';
10129: foreach my $type (@{$changes{'authtypes'}}) {
10130: my @allowed;
10131: $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
10132: foreach my $auth (@authtypes) {
10133: if ($authhash{$type}{$auth}) {
10134: push(@allowed,$authname{$auth});
10135: }
10136: }
10137: if (@allowed > 0) {
10138: $chgtext .= join(', ',@allowed).'</li>';
10139: } else {
10140: $chgtext .= &mt('none').'</li>';
10141: }
10142: }
10143: $chgtext .= '</ul>';
10144: $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
10145: $resulttext .= '</li>';
10146: }
10147: $resulttext .= '</ul>';
10148: } else {
10149: $resulttext = &mt('No changes made to user creation settings');
10150: }
10151: } else {
10152: $resulttext = '<span class="LC_error">'.
10153: &mt('An error occurred: [_1]',$putresult).'</span>';
10154: }
10155: if ($warningmsg ne '') {
10156: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
10157: }
10158: return $resulttext;
10159: }
10160:
10161: sub modify_selfcreation {
10162: my ($dom,%domconfig) = @_;
10163: my ($resulttext,$warningmsg,%curr_usercreation,%curr_usermodify,%changes,%cancreate);
10164: my (%save_usercreate,%save_usermodify);
1.228 raeburn 10165: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
10166: if (ref($types) eq 'ARRAY') {
10167: $usertypes->{'default'} = $othertitle;
10168: push(@{$types},'default');
10169: }
1.224 raeburn 10170: #
10171: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usercreation'}.
10172: #
10173: if (ref($domconfig{'usercreation'}) eq 'HASH') {
10174: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
10175: if ($key eq 'cancreate') {
10176: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
10177: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
10178: if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
10179: ($item eq 'captcha') || ($item eq 'recaptchakeys') ||
1.269 raeburn 10180: ($item eq 'recaptchaversion') ||
1.236 raeburn 10181: ($item eq 'emailusername') || ($item eq 'notify') ||
1.240 raeburn 10182: ($item eq 'selfcreateprocessing') || ($item eq 'shibenv')) {
1.224 raeburn 10183: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
10184: } else {
10185: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
10186: }
10187: }
10188: }
10189: } elsif ($key eq 'email_rule') {
10190: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
10191: } else {
10192: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
10193: }
10194: }
10195: }
10196: #
10197: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usermodification'}.
10198: #
10199: if (ref($domconfig{'usermodification'}) eq 'HASH') {
10200: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
10201: if ($key eq 'selfcreate') {
10202: $curr_usermodify{$key} = $domconfig{'usermodification'}{$key};
10203: } else {
10204: $save_usermodify{$key} = $domconfig{'usermodification'}{$key};
10205: }
10206: }
10207: }
10208:
10209: my @contexts = ('selfcreate');
10210: @{$cancreate{'selfcreate'}} = ();
10211: %{$cancreate{'emailusername'}} = ();
10212: @{$cancreate{'statustocreate'}} = ();
1.236 raeburn 10213: %{$cancreate{'selfcreateprocessing'}} = ();
1.240 raeburn 10214: %{$cancreate{'shibenv'}} = ();
1.50 raeburn 10215: my %selfcreatetypes = (
10216: sso => 'users authenticated by institutional single sign on',
10217: login => 'users authenticated by institutional log-in',
1.236 raeburn 10218: email => 'users who provide a valid e-mail address for use as username',
1.50 raeburn 10219: );
1.224 raeburn 10220: #
10221: # Populate $cancreate{'selfcreate'} array reference with types of user, for which self-creation of user accounts
10222: # is permitted.
10223: #
1.236 raeburn 10224:
10225: my @statuses;
10226: if (ref($domconfig{'inststatus'}) eq 'HASH') {
10227: if (ref($domconfig{'inststatus'}{'inststatusguest'}) eq 'ARRAY') {
10228: @statuses = @{$domconfig{'inststatus'}{'inststatusguest'}};
10229: }
10230: }
10231: push(@statuses,'default');
10232:
1.228 raeburn 10233: foreach my $item ('login','sso','email') {
1.224 raeburn 10234: if ($item eq 'email') {
1.236 raeburn 10235: if ($env{'form.cancreate_email'}) {
1.224 raeburn 10236: push(@{$cancreate{'selfcreate'}},'email');
1.236 raeburn 10237: push(@contexts,'selfcreateprocessing');
10238: foreach my $type (@statuses) {
10239: if ($type eq 'default') {
10240: $cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess'};
10241: } else {
10242: $cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess_'.$type};
10243: }
10244: }
1.224 raeburn 10245: }
10246: } else {
10247: if ($env{'form.cancreate_'.$item}) {
10248: push(@{$cancreate{'selfcreate'}},$item);
10249: }
10250: }
10251: }
10252: my (@email_rule,%userinfo,%savecaptcha);
10253: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
10254: #
1.228 raeburn 10255: # Populate $cancreate{'emailusername'}{$type} hash ref with information fields (if new user will provide data
10256: # value set to one), if self-creation with e-mail address permitted, where $type is user type: faculty, staff, student etc.
1.224 raeburn 10257: #
1.236 raeburn 10258:
1.244 raeburn 10259: if ($env{'form.cancreate_email'}) {
1.228 raeburn 10260: push(@contexts,'emailusername');
10261: if (ref($types) eq 'ARRAY') {
10262: foreach my $type (@{$types}) {
10263: if (ref($infofields) eq 'ARRAY') {
10264: foreach my $field (@{$infofields}) {
10265: if ($env{'form.canmodify_emailusername_'.$type.'_'.$field} =~ /^(required|optional)$/) {
10266: $cancreate{'emailusername'}{$type}{$field} = $1;
10267: }
10268: }
1.224 raeburn 10269: }
10270: }
10271: }
10272: #
10273: # Populate $cancreate{'notify'} hash ref with names of Domain Coordinators who are to be notified of
10274: # queued requests for self-creation of account using e-mail address as username
10275: #
10276:
10277: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.selfcreationnotifyapproval');
10278: @approvalnotify = sort(@approvalnotify);
10279: $cancreate{'notify'}{'approval'} = join(',',@approvalnotify);
10280: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
10281: if (ref($curr_usercreation{'cancreate'}{'notify'}) eq 'HASH') {
10282: if ($curr_usercreation{'cancreate'}{'notify'}{'approval'} ne $cancreate{'notify'}{'approval'}) {
10283: push(@{$changes{'cancreate'}},'notify');
10284: }
10285: } else {
10286: if ($cancreate{'notify'}{'approval'}) {
10287: push(@{$changes{'cancreate'}},'notify');
10288: }
10289: }
10290: } elsif ($cancreate{'notify'}{'approval'}) {
10291: push(@{$changes{'cancreate'}},'notify');
10292: }
10293:
10294: #
10295: # Retrieve rules (if any) governing types of e-mail address which may be used as a username
10296: #
10297: @email_rule = &Apache::loncommon::get_env_multiple('form.email_rule');
10298: &process_captcha('cancreate',\%changes,\%savecaptcha,$curr_usercreation{'cancreate'});
10299: if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
10300: if (@{$curr_usercreation{'email_rule'}} > 0) {
10301: foreach my $type (@{$curr_usercreation{'email_rule'}}) {
10302: if (!grep(/^\Q$type\E$/,@email_rule)) {
10303: push(@{$changes{'email_rule'}},$type);
10304: }
10305: }
10306: }
10307: if (@email_rule > 0) {
10308: foreach my $type (@email_rule) {
10309: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'email_rule'}})) {
10310: push(@{$changes{'email_rule'}},$type);
10311: }
10312: }
10313: }
10314: } elsif (@email_rule > 0) {
10315: push(@{$changes{'email_rule'}},@email_rule);
10316: }
10317: }
10318: #
1.236 raeburn 10319: # Check if domain default is set appropriately, if self-creation of accounts is to be available for
1.224 raeburn 10320: # institutional log-in.
10321: #
10322: if (grep(/^login$/,@{$cancreate{'selfcreate'}})) {
10323: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
10324: if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) ||
10325: ($domdefaults{'auth_def'} eq 'localauth'))) {
10326: $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.').' '.
10327: &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.');
10328: }
10329: }
10330: my @fields = ('lastname','firstname','middlename','generation',
10331: 'permanentemail','id');
1.240 raeburn 10332: my @shibfields = (@fields,'inststatus');
1.224 raeburn 10333: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
10334: #
10335: # Where usernames may created for institutional log-in and/or institutional single sign on:
10336: # (a) populate $cancreate{'statustocreate'} array reference with institutional status types who
10337: # may self-create accounts
10338: # (b) populate $save_usermodify{'selfcreate'} hash reference with status types, and information fields
10339: # which the user may supply, if institutional data is unavailable.
10340: #
10341: if (($env{'form.cancreate_login'}) || ($env{'form.cancreate_sso'})) {
10342: if (ref($types) eq 'ARRAY') {
1.228 raeburn 10343: if (@{$types} > 1) {
1.224 raeburn 10344: @{$cancreate{'statustocreate'}} = &Apache::loncommon::get_env_multiple('form.statustocreate');
10345: push(@contexts,'statustocreate');
10346: } else {
10347: undef($cancreate{'statustocreate'});
10348: }
10349: foreach my $type (@{$types}) {
10350: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$type);
10351: foreach my $field (@fields) {
10352: if (grep(/^\Q$field\E$/,@modifiable)) {
10353: $save_usermodify{'selfcreate'}{$type}{$field} = 1;
10354: } else {
10355: $save_usermodify{'selfcreate'}{$type}{$field} = 0;
10356: }
10357: }
10358: }
10359: if (ref($curr_usermodify{'selfcreate'}) eq 'HASH') {
10360: foreach my $type (@{$types}) {
10361: if (ref($curr_usermodify{'selfcreate'}{$type}) eq 'HASH') {
10362: foreach my $field (@fields) {
10363: if ($save_usermodify{'selfcreate'}{$type}{$field} ne
10364: $curr_usermodify{'selfcreate'}{$type}{$field}) {
10365: push(@{$changes{'selfcreate'}},$type);
10366: last;
10367: }
10368: }
10369: }
10370: }
10371: } else {
10372: foreach my $type (@{$types}) {
10373: push(@{$changes{'selfcreate'}},$type);
10374: }
10375: }
10376: }
1.240 raeburn 10377: foreach my $field (@shibfields) {
10378: if ($env{'form.shibenv_'.$field} ne '') {
10379: $cancreate{'shibenv'}{$field} = $env{'form.shibenv_'.$field};
10380: }
10381: }
10382: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
10383: if (ref($curr_usercreation{'cancreate'}{'shibenv'}) eq 'HASH') {
10384: foreach my $field (@shibfields) {
10385: if ($env{'form.shibenv_'.$field} ne $curr_usercreation{'cancreate'}{'shibenv'}{$field}) {
10386: push(@{$changes{'cancreate'}},'shibenv');
10387: }
10388: }
10389: } else {
10390: foreach my $field (@shibfields) {
10391: if ($env{'form.shibenv_'.$field}) {
10392: push(@{$changes{'cancreate'}},'shibenv');
10393: last;
10394: }
10395: }
10396: }
10397: }
1.224 raeburn 10398: }
10399: foreach my $item (@contexts) {
10400: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
10401: foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
10402: if (ref($cancreate{$item}) eq 'ARRAY') {
10403: if (!grep(/^$curr$/,@{$cancreate{$item}})) {
10404: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
10405: push(@{$changes{'cancreate'}},$item);
10406: }
10407: }
10408: }
10409: }
10410: if (ref($cancreate{$item}) eq 'ARRAY') {
10411: foreach my $type (@{$cancreate{$item}}) {
10412: if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
10413: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
10414: push(@{$changes{'cancreate'}},$item);
10415: }
10416: }
10417: }
10418: }
10419: } elsif (ref($curr_usercreation{'cancreate'}{$item}) eq 'HASH') {
10420: if (ref($cancreate{$item}) eq 'HASH') {
10421: foreach my $curr (keys(%{$curr_usercreation{'cancreate'}{$item}})) {
1.228 raeburn 10422: if (ref($curr_usercreation{'cancreate'}{$item}{$curr}) eq 'HASH') {
10423: foreach my $field (keys(%{$curr_usercreation{'cancreate'}{$item}{$curr}})) {
10424: unless ($curr_usercreation{'cancreate'}{$item}{$curr}{$field} eq $cancreate{$item}{$curr}{$field}) {
10425: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
10426: push(@{$changes{'cancreate'}},$item);
10427: }
10428: }
10429: }
1.236 raeburn 10430: } elsif ($item eq 'selfcreateprocessing') {
10431: if ($cancreate{$item}{$curr} ne $curr_usercreation{'cancreate'}{$item}{$curr}) {
10432: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
10433: push(@{$changes{'cancreate'}},$item);
10434: }
10435: }
1.228 raeburn 10436: } else {
10437: if (!$cancreate{$item}{$curr}) {
10438: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
10439: push(@{$changes{'cancreate'}},$item);
10440: }
1.224 raeburn 10441: }
10442: }
10443: }
10444: foreach my $field (keys(%{$cancreate{$item}})) {
1.228 raeburn 10445: if (ref($cancreate{$item}{$field}) eq 'HASH') {
10446: foreach my $inner (keys(%{$cancreate{$item}{$field}})) {
10447: if (ref($curr_usercreation{'cancreate'}{$item}{$field}) eq 'HASH') {
10448: unless ($curr_usercreation{'cancreate'}{$item}{$field}{$inner} eq $cancreate{$item}{$field}{$inner}) {
10449: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
10450: push(@{$changes{'cancreate'}},$item);
10451: }
10452: }
10453: } else {
10454: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
10455: push(@{$changes{'cancreate'}},$item);
10456: }
10457: }
10458: }
1.236 raeburn 10459: } elsif ($item eq 'selfcreateprocessing') {
10460: if ($cancreate{$item}{$field} ne $curr_usercreation{'cancreate'}{$item}{$field}) {
10461: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
10462: push(@{$changes{'cancreate'}},$item);
10463: }
10464: }
1.228 raeburn 10465: } else {
10466: if (!$curr_usercreation{'cancreate'}{$item}{$field}) {
10467: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
10468: push(@{$changes{'cancreate'}},$item);
10469: }
1.224 raeburn 10470: }
10471: }
10472: }
10473: }
10474: } elsif ($curr_usercreation{'cancreate'}{$item}) {
10475: if (ref($cancreate{$item}) eq 'ARRAY') {
10476: if (!grep(/^\Q$curr_usercreation{'cancreate'}{$item}\E$/,@{$cancreate{$item}})) {
10477: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
10478: push(@{$changes{'cancreate'}},$item);
10479: }
10480: }
10481: } elsif (ref($cancreate{$item}) eq 'HASH') {
10482: if (!$cancreate{$item}{$curr_usercreation{'cancreate'}{$item}}) {
10483: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
10484: push(@{$changes{'cancreate'}},$item);
10485: }
10486: }
10487: }
10488: } elsif ($item eq 'emailusername') {
1.228 raeburn 10489: if (ref($cancreate{$item}) eq 'HASH') {
10490: foreach my $type (keys(%{$cancreate{$item}})) {
10491: if (ref($cancreate{$item}{$type}) eq 'HASH') {
10492: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
10493: if ($cancreate{$item}{$type}{$field}) {
10494: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
10495: push(@{$changes{'cancreate'}},$item);
10496: }
10497: last;
10498: }
10499: }
10500: }
10501: }
1.224 raeburn 10502: }
10503: }
10504: }
10505: #
10506: # Populate %save_usercreate hash with updates to self-creation configuration.
10507: #
10508: $save_usercreate{'cancreate'}{'captcha'} = $savecaptcha{'captcha'};
10509: $save_usercreate{'cancreate'}{'recaptchakeys'} = $savecaptcha{'recaptchakeys'};
1.269 raeburn 10510: $save_usercreate{'cancreate'}{'recaptchaversion'} = $savecaptcha{'recaptchaversion'};
1.224 raeburn 10511: $save_usercreate{'cancreate'}{'selfcreate'} = $cancreate{'selfcreate'};
10512: if (ref($cancreate{'notify'}) eq 'HASH') {
10513: $save_usercreate{'cancreate'}{'notify'} = $cancreate{'notify'};
10514: }
1.236 raeburn 10515: if (ref($cancreate{'selfcreateprocessing'}) eq 'HASH') {
10516: $save_usercreate{'cancreate'}{'selfcreateprocessing'} = $cancreate{'selfcreateprocessing'};
10517: }
1.224 raeburn 10518: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
10519: $save_usercreate{'cancreate'}{'statustocreate'} = $cancreate{'statustocreate'};
10520: }
1.240 raeburn 10521: if (ref($cancreate{'shibenv'}) eq 'HASH') {
10522: $save_usercreate{'cancreate'}{'shibenv'} = $cancreate{'shibenv'};
10523: }
1.224 raeburn 10524: $save_usercreate{'cancreate'}{'emailusername'} = $cancreate{'emailusername'};
10525: $save_usercreate{'emailrule'} = \@email_rule;
10526:
10527: my %userconfig_hash = (
10528: usercreation => \%save_usercreate,
10529: usermodification => \%save_usermodify,
10530: );
10531: my $putresult = &Apache::lonnet::put_dom('configuration',\%userconfig_hash,
10532: $dom);
10533: #
10534: # Accumulate details of changes to domain cofiguration for self-creation of usernames in $resulttext
10535: #
1.27 raeburn 10536: if ($putresult eq 'ok') {
10537: if (keys(%changes) > 0) {
10538: $resulttext = &mt('Changes made:').'<ul>';
10539: if (ref($changes{'cancreate'}) eq 'ARRAY') {
1.224 raeburn 10540: my %lt = &selfcreation_types();
1.34 raeburn 10541: foreach my $type (@{$changes{'cancreate'}}) {
1.100 raeburn 10542: my $chgtext;
1.45 raeburn 10543: if ($type eq 'selfcreate') {
1.50 raeburn 10544: if (@{$cancreate{$type}} == 0) {
1.224 raeburn 10545: $chgtext .= &mt('Self creation of a new user account is not permitted.');
1.50 raeburn 10546: } else {
1.224 raeburn 10547: $chgtext .= &mt('Self-creation of a new account is permitted for:').
10548: '<ul>';
1.50 raeburn 10549: foreach my $case (@{$cancreate{$type}}) {
10550: $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
10551: }
10552: $chgtext .= '</ul>';
1.100 raeburn 10553: if (ref($cancreate{$type}) eq 'ARRAY') {
10554: if (grep(/^(login|sso)$/,@{$cancreate{$type}})) {
10555: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
10556: if (@{$cancreate{'statustocreate'}} == 0) {
1.224 raeburn 10557: $chgtext .= '<br />'.
10558: '<span class="LC_warning">'.
10559: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
10560: '</span>';
1.100 raeburn 10561: }
10562: }
10563: }
10564: }
1.43 raeburn 10565: }
1.240 raeburn 10566: } elsif ($type eq 'shibenv') {
10567: if (keys(%{$cancreate{$type}}) == 0) {
10568: $chgtext .= &mt('Shibboleth-autheticated user does not use environment variables to set user information');
10569: } else {
10570: $chgtext .= &mt('Shibboleth-autheticated user information set from environment variables, as follows:').
10571: '<ul>';
10572: foreach my $field (@shibfields) {
10573: next if ($cancreate{$type}{$field} eq '');
10574: if ($field eq 'inststatus') {
10575: $chgtext .= '<li>'.&mt('Institutional status').' -- '.$cancreate{$type}{$field}.'</li>';
10576: } else {
10577: $chgtext .= '<li>'.$fieldtitles{$field}.' -- '.$cancreate{$type}{$field}.'</li>';
10578: }
10579: }
10580: $chgtext .= '</ul>';
10581: }
1.93 raeburn 10582: } elsif ($type eq 'statustocreate') {
1.96 raeburn 10583: if ((ref($cancreate{'selfcreate'}) eq 'ARRAY') &&
10584: (ref($cancreate{'statustocreate'}) eq 'ARRAY')) {
10585: if (@{$cancreate{'selfcreate'}} > 0) {
10586: if (@{$cancreate{'statustocreate'}} == 0) {
1.100 raeburn 10587: $chgtext .= &mt("Institutional affiliations permitted to create accounts set to 'None'.");
1.96 raeburn 10588: if (!grep(/^email$/,@{$cancreate{'selfcreate'}})) {
1.224 raeburn 10589: $chgtext .= '<br />'.
10590: '<span class="LC_warning">'.
10591: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
10592: '</span>';
10593: }
1.96 raeburn 10594: } elsif (ref($usertypes) eq 'HASH') {
10595: if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.100 raeburn 10596: $chgtext .= &mt('Creation of a new account for an institutional user is restricted to the following institutional affiliation(s):');
10597: } else {
10598: $chgtext .= &mt('Institutional affiliations permitted to create accounts with institutional authentication were set as follows:');
10599: }
10600: $chgtext .= '<ul>';
10601: foreach my $case (@{$cancreate{$type}}) {
10602: if ($case eq 'default') {
10603: $chgtext .= '<li>'.$othertitle.'</li>';
10604: } else {
10605: $chgtext .= '<li>'.$usertypes->{$case}.'</li>';
1.93 raeburn 10606: }
10607: }
1.100 raeburn 10608: $chgtext .= '</ul>';
10609: if (!grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.224 raeburn 10610: $chgtext .= '<br /><span class="LC_warning">'.
10611: &mt('However, users authenticated by institutional login/single sign on are not currently permitted to create accounts.').
10612: '</span>';
1.100 raeburn 10613: }
10614: }
10615: } else {
10616: if (@{$cancreate{$type}} == 0) {
10617: $chgtext .= &mt("Institutional affiliations permitted to create accounts were set to 'none'.");
10618: } else {
10619: $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 10620: }
10621: }
10622: }
1.236 raeburn 10623: } elsif ($type eq 'selfcreateprocessing') {
10624: my %choices = &Apache::lonlocal::texthash (
10625: automatic => 'Automatic approval',
10626: approval => 'Queued for approval',
10627: );
10628: if (@statuses > 1) {
10629: $chgtext .= &mt('Processing of requests to create account with e-mail address as username set as follows:').
10630: '<ul>';
10631: foreach my $type (@statuses) {
10632: if ($type eq 'default') {
10633: $chgtext .= '<li>'.$othertitle.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$type}}.'</li>';
10634: } else {
10635: $chgtext .= '<li>'.$usertypes->{$type}.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$type}}.'</li>';
10636: }
10637: }
10638: $chgtext .= '</ul>';
10639: } else {
10640: $chgtext .= &mt('Processing of requests to create account with e-mail address as username set to: "[_1]"',
10641: $choices{$cancreate{'selfcreateprocessing'}{'default'}});
10642: }
1.165 raeburn 10643: } elsif ($type eq 'captcha') {
1.224 raeburn 10644: if ($savecaptcha{$type} eq 'notused') {
1.165 raeburn 10645: $chgtext .= &mt('No CAPTCHA validation in use for self-creation screen.');
10646: } else {
10647: my %captchas = &captcha_phrases();
1.224 raeburn 10648: if ($captchas{$savecaptcha{$type}}) {
10649: $chgtext .= &mt("Validation for self-creation screen set to $captchas{$savecaptcha{$type}}.");
1.165 raeburn 10650: } else {
1.210 raeburn 10651: $chgtext .= &mt('Validation for self-creation screen set to unknown type.');
1.165 raeburn 10652: }
10653: }
10654: } elsif ($type eq 'recaptchakeys') {
10655: my ($privkey,$pubkey);
1.224 raeburn 10656: if (ref($savecaptcha{$type}) eq 'HASH') {
10657: $pubkey = $savecaptcha{$type}{'public'};
10658: $privkey = $savecaptcha{$type}{'private'};
1.165 raeburn 10659: }
10660: $chgtext .= &mt('ReCAPTCHA keys changes').'<ul>';
10661: if (!$pubkey) {
10662: $chgtext .= '<li>'.&mt('Public key deleted').'</li>';
10663: } else {
10664: $chgtext .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
10665: }
10666: if (!$privkey) {
10667: $chgtext .= '<li>'.&mt('Private key deleted').'</li>';
10668: } else {
10669: $chgtext .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
10670: }
10671: $chgtext .= '</ul>';
1.269 raeburn 10672: } elsif ($type eq 'recaptchaversion') {
10673: if ($savecaptcha{'captcha'} eq 'recaptcha') {
1.270 raeburn 10674: $chgtext .= &mt('ReCAPTCHA set to version [_1]',$savecaptcha{$type});
1.269 raeburn 10675: }
1.224 raeburn 10676: } elsif ($type eq 'emailusername') {
10677: if (ref($cancreate{'emailusername'}) eq 'HASH') {
1.228 raeburn 10678: if (ref($types) eq 'ARRAY') {
10679: foreach my $type (@{$types}) {
10680: if (ref($cancreate{'emailusername'}{$type}) eq 'HASH') {
10681: if (keys(%{$cancreate{'emailusername'}{$type}}) > 0) {
1.245 raeburn 10682: $chgtext .= &mt('When self-creating account with e-mail as username, the following information will be provided by [_1]:',"'$usertypes->{$type}'").
1.228 raeburn 10683: '<ul>';
10684: foreach my $field (@{$infofields}) {
10685: if ($cancreate{'emailusername'}{$type}{$field}) {
10686: $chgtext .= '<li>'.$infotitles->{$field}.'</li>';
10687: }
10688: }
1.245 raeburn 10689: $chgtext .= '</ul>';
10690: } else {
10691: $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 10692: }
10693: } else {
1.245 raeburn 10694: $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 10695: }
10696: }
10697: }
10698: }
10699: } elsif ($type eq 'notify') {
10700: $chgtext = &mt('No Domain Coordinators will receive notification of username requests requiring approval.');
10701: if (ref($changes{'cancreate'}) eq 'ARRAY') {
10702: if ((grep(/^notify$/,@{$changes{'cancreate'}})) && (ref($cancreate{'notify'}) eq 'HASH')) {
10703: if ($cancreate{'notify'}{'approval'}) {
10704: $chgtext = &mt('Notification of username requests requiring approval will be sent to: ').$cancreate{'notify'}{'approval'};
10705: }
10706: }
1.43 raeburn 10707: }
1.34 raeburn 10708: }
1.224 raeburn 10709: if ($chgtext) {
10710: $resulttext .= '<li>'.$chgtext.'</li>';
1.32 raeburn 10711: }
10712: }
10713: }
1.43 raeburn 10714: if (ref($changes{'email_rule'}) eq 'ARRAY') {
10715: my ($emailrules,$emailruleorder) =
10716: &Apache::lonnet::inst_userrules($dom,'email');
10717: my $chgtext = '<ul>';
10718: foreach my $type (@email_rule) {
10719: if (ref($emailrules->{$type}) eq 'HASH') {
10720: $chgtext .= '<li>'.$emailrules->{$type}{'name'}.'</li>';
10721: }
10722: }
10723: $chgtext .= '</ul>';
10724: if (@email_rule > 0) {
1.224 raeburn 10725: $resulttext .= '<li>'.
10726: &mt('Accounts may not be created by users self-enrolling with e-mail addresses of the following types: ').
10727: $chgtext.
10728: '</li>';
1.43 raeburn 10729: } else {
1.224 raeburn 10730: $resulttext .= '<li>'.
10731: &mt('There are now no restrictions on e-mail addresses which may be used as a username when self-enrolling.').
10732: '</li>';
1.43 raeburn 10733: }
10734: }
1.224 raeburn 10735: if (ref($changes{'selfcreate'}) eq 'ARRAY') {
10736: $resulttext .= '<li>'.&mt('When self-creating institutional account:').'<ul>';
10737: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
10738: foreach my $type (@{$changes{'selfcreate'}}) {
10739: my $typename = $type;
10740: if (ref($usertypes) eq 'HASH') {
10741: if ($usertypes->{$type} ne '') {
10742: $typename = $usertypes->{$type};
10743: }
10744: }
10745: my @modifiable;
10746: $resulttext .= '<li>'.
10747: &mt('Self-creation of account by users with status: [_1]',
10748: '<span class="LC_cusr_emph">'.$typename.'</span>').
10749: ' - '.&mt('modifiable fields (if institutional data blank): ');
10750: foreach my $field (@fields) {
10751: if ($save_usermodify{'selfcreate'}{$type}{$field}) {
10752: push(@modifiable,'<b>'.$fieldtitles{$field}.'</b>');
1.28 raeburn 10753: }
10754: }
1.224 raeburn 10755: if (@modifiable > 0) {
10756: $resulttext .= join(', ',@modifiable);
1.43 raeburn 10757: } else {
1.224 raeburn 10758: $resulttext .= &mt('none');
1.43 raeburn 10759: }
1.224 raeburn 10760: $resulttext .= '</li>';
1.28 raeburn 10761: }
1.224 raeburn 10762: $resulttext .= '</ul></li>';
1.28 raeburn 10763: }
1.27 raeburn 10764: $resulttext .= '</ul>';
10765: } else {
1.224 raeburn 10766: $resulttext = &mt('No changes made to self-creation settings');
1.27 raeburn 10767: }
10768: } else {
10769: $resulttext = '<span class="LC_error">'.
1.23 raeburn 10770: &mt('An error occurred: [_1]',$putresult).'</span>';
10771: }
1.43 raeburn 10772: if ($warningmsg ne '') {
10773: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
10774: }
1.23 raeburn 10775: return $resulttext;
10776: }
10777:
1.165 raeburn 10778: sub process_captcha {
10779: my ($container,$changes,$newsettings,$current) = @_;
10780: return unless ((ref($changes) eq 'HASH') && (ref($newsettings) eq 'HASH') || (ref($current) eq 'HASH'));
10781: $newsettings->{'captcha'} = $env{'form.'.$container.'_captcha'};
10782: unless ($newsettings->{'captcha'} eq 'recaptcha' || $newsettings->{'captcha'} eq 'notused') {
10783: $newsettings->{'captcha'} = 'original';
10784: }
10785: if ($current->{'captcha'} ne $newsettings->{'captcha'}) {
1.210 raeburn 10786: if ($container eq 'cancreate') {
1.169 raeburn 10787: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
10788: push(@{$changes->{'cancreate'}},'captcha');
10789: } elsif (!defined($changes->{'cancreate'})) {
10790: $changes->{'cancreate'} = ['captcha'];
10791: }
10792: } else {
10793: $changes->{'captcha'} = 1;
1.165 raeburn 10794: }
10795: }
1.269 raeburn 10796: my ($newpub,$newpriv,$currpub,$currpriv,$newversion,$currversion);
1.165 raeburn 10797: if ($newsettings->{'captcha'} eq 'recaptcha') {
10798: $newpub = $env{'form.'.$container.'_recaptchapub'};
10799: $newpriv = $env{'form.'.$container.'_recaptchapriv'};
1.250 raeburn 10800: $newpub =~ s/[^\w\-]//g;
10801: $newpriv =~ s/[^\w\-]//g;
1.169 raeburn 10802: $newsettings->{'recaptchakeys'} = {
10803: public => $newpub,
10804: private => $newpriv,
10805: };
1.269 raeburn 10806: $newversion = $env{'form.'.$container.'_recaptchaversion'};
10807: $newversion =~ s/\D//g;
10808: if ($newversion ne '2') {
10809: $newversion = 1;
10810: }
10811: $newsettings->{'recaptchaversion'} = $newversion;
1.165 raeburn 10812: }
10813: if (ref($current->{'recaptchakeys'}) eq 'HASH') {
10814: $currpub = $current->{'recaptchakeys'}{'public'};
10815: $currpriv = $current->{'recaptchakeys'}{'private'};
1.179 raeburn 10816: unless ($newsettings->{'captcha'} eq 'recaptcha') {
10817: $newsettings->{'recaptchakeys'} = {
10818: public => '',
10819: private => '',
10820: }
10821: }
1.165 raeburn 10822: }
1.269 raeburn 10823: if ($current->{'captcha'} eq 'recaptcha') {
10824: $currversion = $current->{'recaptchaversion'};
10825: if ($currversion ne '2') {
10826: $currversion = 1;
10827: }
10828: }
10829: if ($currversion ne $newversion) {
10830: if ($container eq 'cancreate') {
10831: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
10832: push(@{$changes->{'cancreate'}},'recaptchaversion');
10833: } elsif (!defined($changes->{'cancreate'})) {
10834: $changes->{'cancreate'} = ['recaptchaversion'];
10835: }
10836: } else {
10837: $changes->{'recaptchaversion'} = 1;
10838: }
10839: }
1.165 raeburn 10840: if (($newpub ne $currpub) || ($newpriv ne $currpriv)) {
1.169 raeburn 10841: if ($container eq 'cancreate') {
10842: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
10843: push(@{$changes->{'cancreate'}},'recaptchakeys');
10844: } elsif (!defined($changes->{'cancreate'})) {
10845: $changes->{'cancreate'} = ['recaptchakeys'];
10846: }
10847: } else {
1.210 raeburn 10848: $changes->{'recaptchakeys'} = 1;
1.165 raeburn 10849: }
10850: }
10851: return;
10852: }
10853:
1.33 raeburn 10854: sub modify_usermodification {
10855: my ($dom,%domconfig) = @_;
1.224 raeburn 10856: my ($resulttext,%curr_usermodification,%changes,%modifyhash);
1.33 raeburn 10857: if (ref($domconfig{'usermodification'}) eq 'HASH') {
10858: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
1.224 raeburn 10859: if ($key eq 'selfcreate') {
10860: $modifyhash{$key} = $domconfig{'usermodification'}{$key};
10861: } else {
10862: $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
10863: }
1.33 raeburn 10864: }
10865: }
1.224 raeburn 10866: my @contexts = ('author','course');
1.33 raeburn 10867: my %context_title = (
10868: author => 'In author context',
10869: course => 'In course context',
10870: );
10871: my @fields = ('lastname','firstname','middlename','generation',
10872: 'permanentemail','id');
10873: my %roles = (
10874: author => ['ca','aa'],
10875: course => ['st','ep','ta','in','cr'],
10876: );
10877: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
10878: foreach my $context (@contexts) {
10879: foreach my $role (@{$roles{$context}}) {
10880: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$role);
10881: foreach my $item (@fields) {
10882: if (grep(/^\Q$item\E$/,@modifiable)) {
10883: $modifyhash{$context}{$role}{$item} = 1;
10884: } else {
10885: $modifyhash{$context}{$role}{$item} = 0;
10886: }
10887: }
10888: }
10889: if (ref($curr_usermodification{$context}) eq 'HASH') {
10890: foreach my $role (@{$roles{$context}}) {
10891: if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
10892: foreach my $field (@fields) {
10893: if ($modifyhash{$context}{$role}{$field} ne
10894: $curr_usermodification{$context}{$role}{$field}) {
10895: push(@{$changes{$context}},$role);
10896: last;
10897: }
10898: }
10899: }
10900: }
10901: } else {
10902: foreach my $context (@contexts) {
10903: foreach my $role (@{$roles{$context}}) {
10904: push(@{$changes{$context}},$role);
10905: }
10906: }
10907: }
10908: }
10909: my %usermodification_hash = (
10910: usermodification => \%modifyhash,
10911: );
10912: my $putresult = &Apache::lonnet::put_dom('configuration',
10913: \%usermodification_hash,$dom);
10914: if ($putresult eq 'ok') {
10915: if (keys(%changes) > 0) {
10916: $resulttext = &mt('Changes made: ').'<ul>';
10917: foreach my $context (@contexts) {
10918: if (ref($changes{$context}) eq 'ARRAY') {
10919: $resulttext .= '<li>'.$context_title{$context}.':<ul>';
10920: if (ref($changes{$context}) eq 'ARRAY') {
10921: foreach my $role (@{$changes{$context}}) {
10922: my $rolename;
1.224 raeburn 10923: if ($role eq 'cr') {
10924: $rolename = &mt('Custom');
1.33 raeburn 10925: } else {
1.224 raeburn 10926: $rolename = &Apache::lonnet::plaintext($role);
1.33 raeburn 10927: }
10928: my @modifiable;
1.224 raeburn 10929: $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
1.33 raeburn 10930: foreach my $field (@fields) {
10931: if ($modifyhash{$context}{$role}{$field}) {
10932: push(@modifiable,$fieldtitles{$field});
10933: }
10934: }
10935: if (@modifiable > 0) {
10936: $resulttext .= join(', ',@modifiable);
10937: } else {
10938: $resulttext .= &mt('none');
10939: }
10940: $resulttext .= '</li>';
10941: }
10942: $resulttext .= '</ul></li>';
10943: }
10944: }
10945: }
10946: $resulttext .= '</ul>';
10947: } else {
10948: $resulttext = &mt('No changes made to user modification settings');
10949: }
10950: } else {
10951: $resulttext = '<span class="LC_error">'.
10952: &mt('An error occurred: [_1]',$putresult).'</span>';
10953: }
10954: return $resulttext;
10955: }
10956:
1.43 raeburn 10957: sub modify_defaults {
1.212 raeburn 10958: my ($dom,$lastactref,%domconfig) = @_;
1.43 raeburn 10959: my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
1.212 raeburn 10960: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.141 raeburn 10961: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def','portal_def');
1.43 raeburn 10962: my @authtypes = ('internal','krb4','krb5','localauth');
10963: foreach my $item (@items) {
10964: $newvalues{$item} = $env{'form.'.$item};
10965: if ($item eq 'auth_def') {
10966: if ($newvalues{$item} ne '') {
10967: if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
10968: push(@errors,$item);
10969: }
10970: }
10971: } elsif ($item eq 'lang_def') {
10972: if ($newvalues{$item} ne '') {
10973: if ($newvalues{$item} =~ /^(\w+)/) {
10974: my $langcode = $1;
1.103 raeburn 10975: if ($langcode ne 'x_chef') {
10976: if (code2language($langcode) eq '') {
10977: push(@errors,$item);
10978: }
1.43 raeburn 10979: }
10980: } else {
10981: push(@errors,$item);
10982: }
10983: }
1.54 raeburn 10984: } elsif ($item eq 'timezone_def') {
10985: if ($newvalues{$item} ne '') {
1.62 raeburn 10986: if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
1.54 raeburn 10987: push(@errors,$item);
10988: }
10989: }
1.68 raeburn 10990: } elsif ($item eq 'datelocale_def') {
10991: if ($newvalues{$item} ne '') {
10992: my @datelocale_ids = DateTime::Locale->ids();
10993: if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
10994: push(@errors,$item);
10995: }
10996: }
1.141 raeburn 10997: } elsif ($item eq 'portal_def') {
10998: if ($newvalues{$item} ne '') {
10999: 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])\/?$/) {
11000: push(@errors,$item);
11001: }
11002: }
1.43 raeburn 11003: }
11004: if (grep(/^\Q$item\E$/,@errors)) {
11005: $newvalues{$item} = $domdefaults{$item};
11006: } elsif ($domdefaults{$item} ne $newvalues{$item}) {
11007: $changes{$item} = 1;
11008: }
1.72 raeburn 11009: $domdefaults{$item} = $newvalues{$item};
1.43 raeburn 11010: }
11011: my %defaults_hash = (
1.72 raeburn 11012: defaults => \%newvalues,
11013: );
1.43 raeburn 11014: my $title = &defaults_titles();
1.236 raeburn 11015:
11016: my $currinststatus;
11017: if (ref($domconfig{'inststatus'}) eq 'HASH') {
11018: $currinststatus = $domconfig{'inststatus'};
11019: } else {
11020: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
11021: $currinststatus = {
11022: inststatustypes => $usertypes,
11023: inststatusorder => $types,
11024: inststatusguest => [],
11025: };
11026: }
11027: my @todelete = &Apache::loncommon::get_env_multiple('form.inststatus_delete');
11028: my @allpos;
11029: my %guests;
11030: my %alltypes;
11031: my ($currtitles,$currguests,$currorder);
11032: if (ref($currinststatus) eq 'HASH') {
11033: if (ref($currinststatus->{'inststatusorder'}) eq 'ARRAY') {
11034: foreach my $type (@{$currinststatus->{'inststatusorder'}}) {
11035: if (ref($currinststatus->{inststatustypes}) eq 'HASH') {
11036: if ($currinststatus->{inststatustypes}->{$type} ne '') {
11037: $currtitles .= $currinststatus->{inststatustypes}->{$type}.',';
11038: }
11039: }
11040: unless (grep(/^\Q$type\E$/,@todelete)) {
11041: my $position = $env{'form.inststatus_pos_'.$type};
11042: $position =~ s/\D+//g;
11043: $allpos[$position] = $type;
11044: $alltypes{$type} = $env{'form.inststatus_title_'.$type};
11045: $alltypes{$type} =~ s/`//g;
11046: if ($env{'form.inststatus_guest_'.$type}) {
11047: $guests{$type} = 1;
11048: }
11049: }
11050: }
11051: if (ref($currinststatus->{'inststatusguest'}) eq 'ARRAY') {
11052: $currguests = join(',',@{$currinststatus->{'inststatusguest'}});
11053: }
11054: $currorder = join(',',@{$currinststatus->{'inststatusorder'}});
11055: $currtitles =~ s/,$//;
11056: }
11057: }
11058: if ($env{'form.addinststatus'}) {
11059: my $newtype = $env{'form.addinststatus'};
11060: $newtype =~ s/\W//g;
11061: unless (exists($alltypes{$newtype})) {
11062: if ($env{'form.addinststatus_guest'}) {
11063: $guests{$newtype} = 1;
11064: }
11065: $alltypes{$newtype} = $env{'form.addinststatus_title'};
11066: $alltypes{$newtype} =~ s/`//g;
11067: my $position = $env{'form.addinststatus_pos'};
11068: $position =~ s/\D+//g;
11069: if ($position ne '') {
11070: $allpos[$position] = $newtype;
11071: }
11072: }
11073: }
11074: my (@orderedstatus,@orderedguests);
11075: foreach my $type (@allpos) {
11076: unless (($type eq '') || (grep(/^\Q$type\E$/,@orderedstatus))) {
11077: push(@orderedstatus,$type);
11078: if ($guests{$type}) {
11079: push(@orderedguests,$type);
11080: }
11081: }
11082: }
11083: foreach my $type (keys(%alltypes)) {
11084: unless (grep(/^\Q$type\E$/,@orderedstatus)) {
11085: delete($alltypes{$type});
11086: }
11087: }
11088: $defaults_hash{'inststatus'} = {
11089: inststatustypes => \%alltypes,
11090: inststatusorder => \@orderedstatus,
11091: inststatusguest => \@orderedguests,
11092: };
11093: if (ref($defaults_hash{'inststatus'}) eq 'HASH') {
11094: foreach my $item ('inststatustypes','inststatusorder','inststatusguest') {
11095: $domdefaults{$item} = $defaults_hash{'inststatus'}{$item};
11096: }
11097: }
11098: if ($currorder ne join(',',@orderedstatus)) {
11099: $changes{'inststatus'}{'inststatusorder'} = 1;
11100: }
11101: if ($currguests ne join(',',@orderedguests)) {
11102: $changes{'inststatus'}{'inststatusguest'} = 1;
11103: }
11104: my $newtitles;
11105: foreach my $item (@orderedstatus) {
11106: $newtitles .= $alltypes{$item}.',';
11107: }
11108: $newtitles =~ s/,$//;
11109: if ($currtitles ne $newtitles) {
11110: $changes{'inststatus'}{'inststatustypes'} = 1;
11111: }
1.43 raeburn 11112: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
11113: $dom);
11114: if ($putresult eq 'ok') {
11115: if (keys(%changes) > 0) {
11116: $resulttext = &mt('Changes made:').'<ul>';
1.212 raeburn 11117: my $version = &Apache::lonnet::get_server_loncaparev($dom);
1.43 raeburn 11118: 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";
11119: foreach my $item (sort(keys(%changes))) {
1.236 raeburn 11120: if ($item eq 'inststatus') {
11121: if (ref($changes{'inststatus'}) eq 'HASH') {
11122: if (($changes{'inststatus'}{'inststatustypes'}) || $changes{'inststatus'}{'inststatusorder'}) {
11123: $resulttext .= '<li>'.&mt('Institutional user status types set to:').' ';
11124: foreach my $type (@orderedstatus) {
11125: $resulttext .= $alltypes{$type}.', ';
11126: }
11127: $resulttext =~ s/, $//;
11128: $resulttext .= '</li>';
11129: }
11130: if ($changes{'inststatus'}{'inststatusguest'}) {
11131: $resulttext .= '<li>';
11132: if (@orderedguests) {
11133: $resulttext .= &mt('Types assignable to "non-institutional" usernames set to:').' ';
11134: foreach my $type (@orderedguests) {
11135: $resulttext .= $alltypes{$type}.', ';
11136: }
11137: $resulttext =~ s/, $//;
11138: } else {
11139: $resulttext .= &mt('Types assignable to "non-institutional" usernames set to none.');
11140: }
11141: $resulttext .= '</li>';
11142: }
11143: }
11144: } else {
11145: my $value = $env{'form.'.$item};
11146: if ($value eq '') {
11147: $value = &mt('none');
11148: } elsif ($item eq 'auth_def') {
11149: my %authnames = &authtype_names();
11150: my %shortauth = (
11151: internal => 'int',
11152: krb4 => 'krb4',
11153: krb5 => 'krb5',
11154: localauth => 'loc',
11155: );
11156: $value = $authnames{$shortauth{$value}};
11157: }
11158: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
11159: $mailmsgtext .= "$title->{$item} set to $value\n";
1.43 raeburn 11160: }
11161: }
11162: $resulttext .= '</ul>';
11163: $mailmsgtext .= "\n";
11164: my $cachetime = 24*60*60;
1.72 raeburn 11165: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 11166: if (ref($lastactref) eq 'HASH') {
11167: $lastactref->{'domdefaults'} = 1;
11168: }
1.68 raeburn 11169: if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
1.203 raeburn 11170: my $notify = 1;
11171: if (ref($domconfig{'contacts'}) eq 'HASH') {
11172: if ($domconfig{'contacts'}{'reportupdates'} == 0) {
11173: $notify = 0;
11174: }
11175: }
11176: if ($notify) {
11177: &Apache::lonmsg::sendemail('installrecord@loncapa.org',
11178: "LON-CAPA Domain Settings Change - $dom",
11179: $mailmsgtext);
11180: }
1.54 raeburn 11181: }
1.43 raeburn 11182: } else {
1.54 raeburn 11183: $resulttext = &mt('No changes made to default authentication/language/timezone settings');
1.43 raeburn 11184: }
11185: } else {
11186: $resulttext = '<span class="LC_error">'.
11187: &mt('An error occurred: [_1]',$putresult).'</span>';
11188: }
11189: if (@errors > 0) {
11190: $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
11191: foreach my $item (@errors) {
11192: $resulttext .= ' "'.$title->{$item}.'",';
11193: }
11194: $resulttext =~ s/,$//;
11195: }
11196: return $resulttext;
11197: }
11198:
1.46 raeburn 11199: sub modify_scantron {
1.205 raeburn 11200: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.46 raeburn 11201: my ($resulttext,%confhash,%changes,$errors);
11202: my $custom = 'custom.tab';
11203: my $default = 'default.tab';
11204: my $servadm = $r->dir_config('lonAdmEMail');
11205: my ($configuserok,$author_ok,$switchserver) =
11206: &config_check($dom,$confname,$servadm);
11207: if ($env{'form.scantronformat.filename'} ne '') {
11208: my $error;
11209: if ($configuserok eq 'ok') {
11210: if ($switchserver) {
1.130 raeburn 11211: $error = &mt("Upload of bubblesheet format file is not permitted to this server: [_1]",$switchserver);
1.46 raeburn 11212: } else {
11213: if ($author_ok eq 'ok') {
11214: my ($result,$scantronurl) =
11215: &publishlogo($r,'upload','scantronformat',$dom,
11216: $confname,'scantron','','',$custom);
11217: if ($result eq 'ok') {
11218: $confhash{'scantron'}{'scantronformat'} = $scantronurl;
1.48 raeburn 11219: $changes{'scantronformat'} = 1;
1.46 raeburn 11220: } else {
11221: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
11222: }
11223: } else {
11224: $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);
11225: }
11226: }
11227: } else {
11228: $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);
11229: }
11230: if ($error) {
11231: &Apache::lonnet::logthis($error);
11232: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
11233: }
11234: }
1.48 raeburn 11235: if (ref($domconfig{'scantron'}) eq 'HASH') {
11236: if ($domconfig{'scantron'}{'scantronformat'} ne '') {
11237: if ($env{'form.scantronformat_del'}) {
11238: $confhash{'scantron'}{'scantronformat'} = '';
11239: $changes{'scantronformat'} = 1;
1.46 raeburn 11240: }
11241: }
11242: }
11243: if (keys(%confhash) > 0) {
11244: my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
11245: $dom);
11246: if ($putresult eq 'ok') {
11247: if (keys(%changes) > 0) {
1.48 raeburn 11248: if (ref($confhash{'scantron'}) eq 'HASH') {
11249: $resulttext = &mt('Changes made:').'<ul>';
11250: if ($confhash{'scantron'}{'scantronformat'} eq '') {
1.130 raeburn 11251: $resulttext .= '<li>'.&mt('[_1] bubblesheet format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
1.48 raeburn 11252: } else {
1.130 raeburn 11253: $resulttext .= '<li>'.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
1.46 raeburn 11254: }
1.48 raeburn 11255: $resulttext .= '</ul>';
11256: } else {
1.130 raeburn 11257: $resulttext = &mt('Changes made to bubblesheet format file.');
1.46 raeburn 11258: }
11259: $resulttext .= '</ul>';
11260: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 11261: if (ref($lastactref) eq 'HASH') {
11262: $lastactref->{'domainconfig'} = 1;
11263: }
1.46 raeburn 11264: } else {
1.130 raeburn 11265: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 11266: }
11267: } else {
11268: $resulttext = '<span class="LC_error">'.
11269: &mt('An error occurred: [_1]',$putresult).'</span>';
11270: }
11271: } else {
1.130 raeburn 11272: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 11273: }
11274: if ($errors) {
11275: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
11276: $errors.'</ul>';
11277: }
11278: return $resulttext;
11279: }
11280:
1.48 raeburn 11281: sub modify_coursecategories {
1.239 raeburn 11282: my ($dom,$lastactref,%domconfig) = @_;
1.57 raeburn 11283: my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
11284: $cathash);
1.48 raeburn 11285: my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
1.238 raeburn 11286: my @catitems = ('unauth','auth');
11287: my @cattypes = ('std','domonly','codesrch','none');
1.55 raeburn 11288: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
1.57 raeburn 11289: $cathash = $domconfig{'coursecategories'}{'cats'};
11290: if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
11291: $changes{'togglecats'} = 1;
11292: $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
11293: }
11294: if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
11295: $changes{'categorize'} = 1;
11296: $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
11297: }
1.120 raeburn 11298: if ($domconfig{'coursecategories'}{'togglecatscomm'} ne $env{'form.togglecatscomm'}) {
11299: $changes{'togglecatscomm'} = 1;
11300: $domconfig{'coursecategories'}{'togglecatscomm'} = $env{'form.togglecatscomm'};
11301: }
11302: if ($domconfig{'coursecategories'}{'categorizecomm'} ne $env{'form.categorizecomm'}) {
11303: $changes{'categorizecomm'} = 1;
11304: $domconfig{'coursecategories'}{'categorizecomm'} = $env{'form.categorizecomm'};
1.272 raeburn 11305:
11306: }
11307: if ($domconfig{'coursecategories'}{'togglecatsplace'} ne $env{'form.togglecatsplace'}) {
11308: $changes{'togglecatsplace'} = 1;
11309: $domconfig{'coursecategories'}{'togglecatsplace'} = $env{'form.togglecatsplace'};
11310: }
11311: if ($domconfig{'coursecategories'}{'categorizeplace'} ne $env{'form.categorizeplace'}) {
11312: $changes{'categorizeplace'} = 1;
11313: $domconfig{'coursecategories'}{'categorizeplace'} = $env{'form.categorizeplace'};
1.120 raeburn 11314: }
1.238 raeburn 11315: foreach my $item (@catitems) {
11316: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
11317: if ($domconfig{'coursecategories'}{$item} ne $env{'form.coursecat_'.$item}) {
11318: $changes{$item} = 1;
11319: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
11320: }
11321: }
11322: }
1.57 raeburn 11323: } else {
11324: $changes{'togglecats'} = 1;
11325: $changes{'categorize'} = 1;
1.124 raeburn 11326: $changes{'togglecatscomm'} = 1;
11327: $changes{'categorizecomm'} = 1;
1.272 raeburn 11328: $changes{'togglecatsplace'} = 1;
11329: $changes{'categorizeplace'} = 1;
1.87 raeburn 11330: $domconfig{'coursecategories'} = {
11331: togglecats => $env{'form.togglecats'},
11332: categorize => $env{'form.categorize'},
1.124 raeburn 11333: togglecatscomm => $env{'form.togglecatscomm'},
11334: categorizecomm => $env{'form.categorizecomm'},
1.272 raeburn 11335: togglecatsplace => $env{'form.togglecatsplace'},
11336: categorizeplace => $env{'form.categorizeplace'},
1.120 raeburn 11337: };
1.238 raeburn 11338: foreach my $item (@catitems) {
11339: if ($env{'form.coursecat_'.$item} ne 'std') {
11340: $changes{$item} = 1;
11341: }
11342: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
11343: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
11344: }
11345: }
1.57 raeburn 11346: }
11347: if (ref($cathash) eq 'HASH') {
11348: if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '') && ($env{'form.instcode'} == 0)) {
1.55 raeburn 11349: push (@deletecategory,'instcode::0');
11350: }
1.120 raeburn 11351: if (($domconfig{'coursecategories'}{'cats'}{'communities::0'} ne '') && ($env{'form.communities'} == 0)) {
11352: push(@deletecategory,'communities::0');
11353: }
1.272 raeburn 11354: if (($domconfig{'coursecategories'}{'cats'}{'placement::0'} ne '') && ($env{'form.placement'} == 0)) {
11355: push(@deletecategory,'placement::0');
11356: }
1.48 raeburn 11357: }
1.57 raeburn 11358: my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
11359: if (ref($cathash) eq 'HASH') {
1.48 raeburn 11360: if (@deletecategory > 0) {
11361: #FIXME Need to remove category from all courses using a deleted category
1.57 raeburn 11362: &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
1.48 raeburn 11363: foreach my $item (@deletecategory) {
1.57 raeburn 11364: if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
11365: delete($domconfig{'coursecategories'}{'cats'}{$item});
1.48 raeburn 11366: $deletions{$item} = 1;
1.57 raeburn 11367: &recurse_cat_deletes($item,$cathash,\%deletions);
1.48 raeburn 11368: }
11369: }
11370: }
1.57 raeburn 11371: foreach my $item (keys(%{$cathash})) {
1.48 raeburn 11372: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
1.57 raeburn 11373: if ($cathash->{$item} ne $env{'form.'.$item}) {
1.48 raeburn 11374: $reorderings{$item} = 1;
1.57 raeburn 11375: $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
1.48 raeburn 11376: }
11377: if ($env{'form.addcategory_name_'.$item} ne '') {
11378: my $newcat = $env{'form.addcategory_name_'.$item};
11379: my $newdepth = $depth+1;
11380: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 11381: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
1.48 raeburn 11382: $adds{$newitem} = 1;
11383: }
11384: if ($env{'form.subcat_'.$item} ne '') {
11385: my $newcat = $env{'form.subcat_'.$item};
11386: my $newdepth = $depth+1;
11387: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 11388: $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
1.48 raeburn 11389: $adds{$newitem} = 1;
11390: }
11391: }
11392: }
11393: if ($env{'form.instcode'} eq '1') {
1.57 raeburn 11394: if (ref($cathash) eq 'HASH') {
1.48 raeburn 11395: my $newitem = 'instcode::0';
1.57 raeburn 11396: if ($cathash->{$newitem} eq '') {
11397: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 11398: $adds{$newitem} = 1;
11399: }
11400: } else {
11401: my $newitem = 'instcode::0';
1.57 raeburn 11402: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 11403: $adds{$newitem} = 1;
11404: }
11405: }
1.120 raeburn 11406: if ($env{'form.communities'} eq '1') {
11407: if (ref($cathash) eq 'HASH') {
11408: my $newitem = 'communities::0';
11409: if ($cathash->{$newitem} eq '') {
11410: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
11411: $adds{$newitem} = 1;
11412: }
11413: } else {
11414: my $newitem = 'communities::0';
11415: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
11416: $adds{$newitem} = 1;
11417: }
11418: }
1.272 raeburn 11419: if ($env{'form.placement'} eq '1') {
11420: if (ref($cathash) eq 'HASH') {
11421: my $newitem = 'placement::0';
11422: if ($cathash->{$newitem} eq '') {
11423: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.placement_pos'};
11424: $adds{$newitem} = 1;
11425: }
11426: } else {
11427: my $newitem = 'placement::0';
11428: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.placement_pos'};
11429: $adds{$newitem} = 1;
11430: }
11431: }
1.48 raeburn 11432: if ($env{'form.addcategory_name'} ne '') {
1.120 raeburn 11433: if (($env{'form.addcategory_name'} ne 'instcode') &&
1.272 raeburn 11434: ($env{'form.addcategory_name'} ne 'communities') &&
11435: ($env{'form.addcategory_name'} ne 'placement')) {
1.120 raeburn 11436: my $newitem = &escape($env{'form.addcategory_name'}).'::0';
11437: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
11438: $adds{$newitem} = 1;
11439: }
1.48 raeburn 11440: }
1.57 raeburn 11441: my $putresult;
1.48 raeburn 11442: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
11443: if (keys(%deletions) > 0) {
11444: foreach my $key (keys(%deletions)) {
11445: if ($predelallitems{$key} ne '') {
11446: $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
11447: }
11448: }
11449: }
11450: my (@chkcats,@chktrails,%chkallitems);
1.57 raeburn 11451: &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
1.48 raeburn 11452: if (ref($chkcats[0]) eq 'ARRAY') {
11453: my $depth = 0;
11454: my $chg = 0;
11455: for (my $i=0; $i<@{$chkcats[0]}; $i++) {
11456: my $name = $chkcats[0][$i];
11457: my $item;
11458: if ($name eq '') {
11459: $chg ++;
11460: } else {
11461: $item = &escape($name).'::0';
11462: if ($chg) {
1.57 raeburn 11463: $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
1.48 raeburn 11464: }
11465: $depth ++;
1.57 raeburn 11466: &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
1.48 raeburn 11467: $depth --;
11468: }
11469: }
11470: }
1.57 raeburn 11471: }
11472: if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
11473: $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
1.48 raeburn 11474: if ($putresult eq 'ok') {
1.57 raeburn 11475: my %title = (
1.120 raeburn 11476: togglecats => 'Show/Hide a course in catalog',
11477: categorize => 'Assign a category to a course',
11478: togglecatscomm => 'Show/Hide a community in catalog',
11479: categorizecomm => 'Assign a category to a community',
1.57 raeburn 11480: );
11481: my %level = (
1.120 raeburn 11482: dom => 'set in Domain ("Modify Course/Community")',
11483: crs => 'set in Course ("Course Configuration")',
11484: comm => 'set in Community ("Community Configuration")',
1.238 raeburn 11485: none => 'No catalog',
11486: std => 'Standard catalog',
11487: domonly => 'Domain-only catalog',
11488: codesrch => 'Code search form',
1.57 raeburn 11489: );
1.48 raeburn 11490: $resulttext = &mt('Changes made:').'<ul>';
1.57 raeburn 11491: if ($changes{'togglecats'}) {
11492: $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>';
11493: }
11494: if ($changes{'categorize'}) {
11495: $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
1.48 raeburn 11496: }
1.120 raeburn 11497: if ($changes{'togglecatscomm'}) {
11498: $resulttext .= '<li>'.&mt("$title{'togglecatscomm'} $level{$env{'form.togglecatscomm'}}").'</li>';
11499: }
11500: if ($changes{'categorizecomm'}) {
11501: $resulttext .= '<li>'.&mt("$title{'categorizecomm'} $level{$env{'form.categorizecomm'}}").'</li>';
11502: }
1.238 raeburn 11503: if ($changes{'unauth'}) {
11504: $resulttext .= '<li>'.&mt('Catalog type for unauthenticated users set to "'.$level{$env{'form.coursecat_unauth'}}.'"').'</li>';
11505: }
11506: if ($changes{'auth'}) {
11507: $resulttext .= '<li>'.&mt('Catalog type for authenticated users set to "'.$level{$env{'form.coursecat_auth'}}.'"').'</li>';
11508: }
1.57 raeburn 11509: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
11510: my $cathash;
11511: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
11512: $cathash = $domconfig{'coursecategories'}{'cats'};
11513: } else {
11514: $cathash = {};
11515: }
11516: my (@cats,@trails,%allitems);
11517: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
11518: if (keys(%deletions) > 0) {
11519: $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
11520: foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) {
11521: $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
11522: }
11523: $resulttext .= '</ul></li>';
11524: }
11525: if (keys(%reorderings) > 0) {
11526: my %sort_by_trail;
11527: $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
11528: foreach my $key (keys(%reorderings)) {
11529: if ($allitems{$key} ne '') {
11530: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
11531: }
1.48 raeburn 11532: }
1.57 raeburn 11533: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
11534: $resulttext .= '<li>'.$trails[$trail].'</li>';
11535: }
11536: $resulttext .= '</ul></li>';
1.48 raeburn 11537: }
1.57 raeburn 11538: if (keys(%adds) > 0) {
11539: my %sort_by_trail;
11540: $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
11541: foreach my $key (keys(%adds)) {
11542: if ($allitems{$key} ne '') {
11543: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
11544: }
11545: }
11546: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
11547: $resulttext .= '<li>'.$trails[$trail].'</li>';
1.48 raeburn 11548: }
1.57 raeburn 11549: $resulttext .= '</ul></li>';
1.48 raeburn 11550: }
11551: }
11552: $resulttext .= '</ul>';
1.239 raeburn 11553: if ($changes{'unauth'} || $changes{'auth'}) {
1.246 raeburn 11554: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
11555: if ($changes{'auth'}) {
11556: $domdefaults{'catauth'} = $domconfig{'coursecategories'}{'auth'};
11557: }
11558: if ($changes{'unauth'}) {
11559: $domdefaults{'catunauth'} = $domconfig{'coursecategories'}{'unauth'};
11560: }
11561: my $cachetime = 24*60*60;
11562: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.239 raeburn 11563: if (ref($lastactref) eq 'HASH') {
1.246 raeburn 11564: $lastactref->{'domdefaults'} = 1;
1.239 raeburn 11565: }
11566: }
1.48 raeburn 11567: } else {
11568: $resulttext = '<span class="LC_error">'.
1.57 raeburn 11569: &mt('An error occurred: [_1]',$putresult).'</span>';
1.48 raeburn 11570: }
11571: } else {
1.120 raeburn 11572: $resulttext = &mt('No changes made to course and community categories');
1.48 raeburn 11573: }
11574: return $resulttext;
11575: }
11576:
1.69 raeburn 11577: sub modify_serverstatuses {
11578: my ($dom,%domconfig) = @_;
11579: my ($resulttext,%changes,%currserverstatus,%newserverstatus);
11580: if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
11581: %currserverstatus = %{$domconfig{'serverstatuses'}};
11582: }
11583: my @pages = &serverstatus_pages();
11584: foreach my $type (@pages) {
11585: $newserverstatus{$type}{'namedusers'} = '';
11586: $newserverstatus{$type}{'machines'} = '';
11587: if (defined($env{'form.'.$type.'_namedusers'})) {
11588: my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
11589: my @okusers;
11590: foreach my $user (@users) {
11591: my ($uname,$udom) = split(/:/,$user);
11592: if (($udom =~ /^$match_domain$/) &&
11593: (&Apache::lonnet::domain($udom)) &&
11594: ($uname =~ /^$match_username$/)) {
11595: if (!grep(/^\Q$user\E/,@okusers)) {
11596: push(@okusers,$user);
11597: }
11598: }
11599: }
11600: if (@okusers > 0) {
11601: @okusers = sort(@okusers);
11602: $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
11603: }
11604: }
11605: if (defined($env{'form.'.$type.'_machines'})) {
11606: my @machines = split(/,/,$env{'form.'.$type.'_machines'});
11607: my @okmachines;
11608: foreach my $ip (@machines) {
11609: my @parts = split(/\./,$ip);
11610: next if (@parts < 4);
11611: my $badip = 0;
11612: for (my $i=0; $i<4; $i++) {
11613: if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
11614: $badip = 1;
11615: last;
11616: }
11617: }
11618: if (!$badip) {
11619: push(@okmachines,$ip);
11620: }
11621: }
11622: @okmachines = sort(@okmachines);
11623: $newserverstatus{$type}{'machines'} = join(',',@okmachines);
11624: }
11625: }
11626: my %serverstatushash = (
11627: serverstatuses => \%newserverstatus,
11628: );
11629: foreach my $type (@pages) {
1.83 raeburn 11630: foreach my $setting ('namedusers','machines') {
1.84 raeburn 11631: my (@current,@new);
1.83 raeburn 11632: if (ref($currserverstatus{$type}) eq 'HASH') {
1.84 raeburn 11633: if ($currserverstatus{$type}{$setting} ne '') {
11634: @current = split(/,/,$currserverstatus{$type}{$setting});
11635: }
11636: }
11637: if ($newserverstatus{$type}{$setting} ne '') {
11638: @new = split(/,/,$newserverstatus{$type}{$setting});
1.83 raeburn 11639: }
11640: if (@current > 0) {
11641: if (@new > 0) {
11642: foreach my $item (@current) {
11643: if (!grep(/^\Q$item\E$/,@new)) {
11644: $changes{$type}{$setting} = 1;
1.82 raeburn 11645: last;
11646: }
11647: }
1.84 raeburn 11648: foreach my $item (@new) {
11649: if (!grep(/^\Q$item\E$/,@current)) {
11650: $changes{$type}{$setting} = 1;
11651: last;
1.82 raeburn 11652: }
11653: }
11654: } else {
1.83 raeburn 11655: $changes{$type}{$setting} = 1;
1.69 raeburn 11656: }
1.83 raeburn 11657: } elsif (@new > 0) {
11658: $changes{$type}{$setting} = 1;
1.69 raeburn 11659: }
11660: }
11661: }
11662: if (keys(%changes) > 0) {
1.81 raeburn 11663: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 11664: my $putresult = &Apache::lonnet::put_dom('configuration',
11665: \%serverstatushash,$dom);
11666: if ($putresult eq 'ok') {
11667: $resulttext .= &mt('Changes made:').'<ul>';
11668: foreach my $type (@pages) {
1.84 raeburn 11669: if (ref($changes{$type}) eq 'HASH') {
1.69 raeburn 11670: $resulttext .= '<li>'.$titles->{$type}.'<ul>';
1.84 raeburn 11671: if ($changes{$type}{'namedusers'}) {
1.69 raeburn 11672: if ($newserverstatus{$type}{'namedusers'} eq '') {
11673: $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n";
11674: } else {
11675: $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n";
11676: }
1.84 raeburn 11677: }
11678: if ($changes{$type}{'machines'}) {
1.69 raeburn 11679: if ($newserverstatus{$type}{'machines'} eq '') {
11680: $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n";
11681: } else {
11682: $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n";
11683: }
11684:
11685: }
11686: $resulttext .= '</ul></li>';
11687: }
11688: }
11689: $resulttext .= '</ul>';
11690: } else {
11691: $resulttext = '<span class="LC_error">'.
11692: &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>';
11693:
11694: }
11695: } else {
11696: $resulttext = &mt('No changes made to access to server status pages');
11697: }
11698: return $resulttext;
11699: }
11700:
1.118 jms 11701: sub modify_helpsettings {
1.122 jms 11702: my ($r,$dom,$confname,%domconfig) = @_;
1.166 raeburn 11703: my ($resulttext,$errors,%changes,%helphash);
11704: my %defaultchecked = ('submitbugs' => 'on');
11705: my @offon = ('off','on');
1.118 jms 11706: my @toggles = ('submitbugs');
11707: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
11708: foreach my $item (@toggles) {
1.166 raeburn 11709: if ($defaultchecked{$item} eq 'on') {
11710: if ($domconfig{'helpsettings'}{$item} eq '') {
11711: if ($env{'form.'.$item} eq '0') {
11712: $changes{$item} = 1;
11713: }
11714: } elsif ($domconfig{'helpsettings'}{$item} ne $env{'form.'.$item}) {
11715: $changes{$item} = 1;
11716: }
11717: } elsif ($defaultchecked{$item} eq 'off') {
11718: if ($domconfig{'helpsettings'}{$item} eq '') {
11719: if ($env{'form.'.$item} eq '1') {
11720: $changes{$item} = 1;
11721: }
11722: } elsif ($domconfig{'helpsettings'}{$item} ne $env{'form.'.$item}) {
11723: $changes{$item} = 1;
11724: }
11725: }
1.210 raeburn 11726: if (($env{'form.'.$item} eq '0') || ($env{'form.'.$item} eq '1')) {
1.166 raeburn 11727: $helphash{'helpsettings'}{$item} = $env{'form.'.$item};
11728: }
11729: }
1.118 jms 11730: }
1.123 jms 11731: my $putresult;
11732: if (keys(%changes) > 0) {
1.166 raeburn 11733: $putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom);
1.168 raeburn 11734: if ($putresult eq 'ok') {
1.166 raeburn 11735: $resulttext = &mt('Changes made:').'<ul>';
11736: foreach my $item (sort(keys(%changes))) {
11737: if ($item eq 'submitbugs') {
11738: $resulttext .= '<li>'.&mt('Display link to: [_1] set to "'.$offon[$env{'form.'.$item}].'".',
11739: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
11740: &mt('LON-CAPA bug tracker'),600,500)).'</li>';
11741: }
11742: }
11743: $resulttext .= '</ul>';
11744: } else {
11745: $resulttext = &mt('No changes made to help settings');
1.168 raeburn 11746: $errors .= '<li><span class="LC_error">'.
11747: &mt('An error occurred storing the settings: [_1]',
11748: $putresult).'</span></li>';
1.166 raeburn 11749: }
1.118 jms 11750: }
11751: if ($errors) {
1.168 raeburn 11752: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.118 jms 11753: $errors.'</ul>';
11754: }
11755: return $resulttext;
11756: }
11757:
1.121 raeburn 11758: sub modify_coursedefaults {
1.212 raeburn 11759: my ($dom,$lastactref,%domconfig) = @_;
1.121 raeburn 11760: my ($resulttext,$errors,%changes,%defaultshash);
1.257 raeburn 11761: my %defaultchecked = (
11762: 'canuse_pdfforms' => 'off',
11763: 'uselcmath' => 'on',
11764: 'usejsme' => 'on'
11765: );
11766: my @toggles = ('canuse_pdfforms','uselcmath','usejsme');
1.198 raeburn 11767: my @numbers = ('anonsurvey_threshold','uploadquota_official','uploadquota_unofficial',
1.276 raeburn 11768: 'uploadquota_community','uploadquota_textbook','uploadquota_placement',
11769: 'mysqltables_official','mysqltables_unofficial','mysqltables_community',
11770: 'mysqltables_textbook','mysqltables_placement');
1.271 raeburn 11771: my @types = ('official','unofficial','community','textbook','placement');
1.198 raeburn 11772: my %staticdefaults = (
11773: anonsurvey_threshold => 10,
11774: uploadquota => 500,
1.257 raeburn 11775: postsubmit => 60,
1.276 raeburn 11776: mysqltables => 172800,
1.198 raeburn 11777: );
1.121 raeburn 11778:
11779: $defaultshash{'coursedefaults'} = {};
11780:
11781: if (ref($domconfig{'coursedefaults'}) ne 'HASH') {
11782: if ($domconfig{'coursedefaults'} eq '') {
11783: $domconfig{'coursedefaults'} = {};
11784: }
11785: }
11786:
11787: if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
11788: foreach my $item (@toggles) {
11789: if ($defaultchecked{$item} eq 'on') {
11790: if (($domconfig{'coursedefaults'}{$item} eq '') &&
11791: ($env{'form.'.$item} eq '0')) {
11792: $changes{$item} = 1;
1.192 raeburn 11793: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
1.121 raeburn 11794: $changes{$item} = 1;
11795: }
11796: } elsif ($defaultchecked{$item} eq 'off') {
11797: if (($domconfig{'coursedefaults'}{$item} eq '') &&
11798: ($env{'form.'.$item} eq '1')) {
11799: $changes{$item} = 1;
11800: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
11801: $changes{$item} = 1;
11802: }
11803: }
11804: $defaultshash{'coursedefaults'}{$item} = $env{'form.'.$item};
11805: }
1.198 raeburn 11806: foreach my $item (@numbers) {
11807: my ($currdef,$newdef);
1.208 raeburn 11808: $newdef = $env{'form.'.$item};
1.198 raeburn 11809: if ($item eq 'anonsurvey_threshold') {
11810: $currdef = $domconfig{'coursedefaults'}{$item};
11811: $newdef =~ s/\D//g;
11812: if ($newdef eq '' || $newdef < 1) {
11813: $newdef = 1;
11814: }
11815: $defaultshash{'coursedefaults'}{$item} = $newdef;
11816: } else {
1.276 raeburn 11817: my ($setting,$type) = ($item =~ /^(uploadquota|mysqltables)_(\w+)$/);
11818: if (ref($domconfig{'coursedefaults'}{$setting}) eq 'HASH') {
11819: $currdef = $domconfig{'coursedefaults'}{$setting}{$type};
1.198 raeburn 11820: }
11821: $newdef =~ s/[^\w.\-]//g;
1.276 raeburn 11822: $defaultshash{'coursedefaults'}{$setting}{$type} = $newdef;
1.198 raeburn 11823: }
11824: if ($currdef ne $newdef) {
11825: my $staticdef;
11826: if ($item eq 'anonsurvey_threshold') {
11827: unless (($currdef eq '') && ($newdef == $staticdefaults{$item})) {
11828: $changes{$item} = 1;
11829: }
1.276 raeburn 11830: } elsif ($item =~ /^(uploadquota|mysqltables)_/) {
11831: my $setting = $1;
11832: unless (($currdef eq '') && ($newdef == $staticdefaults{$setting})) {
11833: $changes{$setting} = 1;
1.198 raeburn 11834: }
11835: }
1.139 raeburn 11836: }
11837: }
1.264 raeburn 11838: my $currclone = $domconfig{'coursedefaults'}{'canclone'};
11839: my @currclonecode;
11840: if (ref($currclone) eq 'HASH') {
11841: if (ref($currclone->{'instcode'}) eq 'ARRAY') {
11842: @currclonecode = @{$currclone->{'instcode'}};
11843: }
11844: }
11845: my $newclone;
11846: if ($env{'form.canclone'} =~ /^(none|domain|instcode)$/) {
11847: $newclone = $env{'form.canclone'};
11848: }
11849: if ($newclone eq 'instcode') {
11850: my @newcodes = &Apache::loncommon::get_env_multiple('form.clonecode');
11851: my (%codedefaults,@code_order,@clonecode);
11852: &Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
11853: \@code_order);
11854: foreach my $item (@code_order) {
11855: if (grep(/^\Q$item\E$/,@newcodes)) {
11856: push(@clonecode,$item);
11857: }
11858: }
11859: if (@clonecode) {
11860: $defaultshash{'coursedefaults'}{'canclone'} = { $newclone => \@clonecode };
11861: my @diffs = &Apache::loncommon::compare_arrays(\@currclonecode,\@clonecode);
11862: if (@diffs) {
11863: $changes{'canclone'} = 1;
11864: }
11865: } else {
11866: $newclone eq '';
11867: }
11868: } elsif ($newclone ne '') {
11869: $defaultshash{'coursedefaults'}{'canclone'} = $newclone;
11870: }
11871: if ($newclone ne $currclone) {
11872: $changes{'canclone'} = 1;
11873: }
1.257 raeburn 11874: my %credits;
11875: foreach my $type (@types) {
11876: unless ($type eq 'community') {
11877: $credits{$type} = $env{'form.'.$type.'_credits'};
11878: $credits{$type} =~ s/[^\d.]+//g;
11879: }
11880: }
11881: if ((ref($domconfig{'coursedefaults'}{'coursecredits'}) ne 'HASH') &&
11882: ($env{'form.coursecredits'} eq '1')) {
11883: $changes{'coursecredits'} = 1;
11884: foreach my $type (keys(%credits)) {
11885: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
11886: }
11887: } else {
11888: if ($env{'form.coursecredits'} eq '1') {
11889: foreach my $type (@types) {
11890: unless ($type eq 'community') {
11891: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type} ne $credits{$type}) {
11892: $changes{'coursecredits'} = 1;
11893: }
11894: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
11895: }
11896: }
11897: } elsif (ref($domconfig{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
11898: foreach my $type (@types) {
11899: unless ($type eq 'community') {
11900: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type}) {
11901: $changes{'coursecredits'} = 1;
11902: last;
11903: }
11904: }
11905: }
11906: }
11907: }
11908: if ($env{'form.postsubmit'} eq '1') {
11909: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'on';
11910: my %currtimeout;
11911: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
11912: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'off') {
11913: $changes{'postsubmit'} = 1;
11914: }
11915: if (ref($domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
11916: %currtimeout = %{$domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}};
11917: }
11918: } else {
11919: $changes{'postsubmit'} = 1;
11920: }
11921: foreach my $type (@types) {
11922: my $timeout = $env{'form.'.$type.'_timeout'};
11923: $timeout =~ s/\D//g;
11924: if ($timeout == $staticdefaults{'postsubmit'}) {
11925: $timeout = '';
11926: } elsif (($timeout eq '') || ($timeout =~ /^0+$/)) {
11927: $timeout = '0';
11928: }
11929: unless ($timeout eq '') {
11930: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type} = $timeout;
11931: }
11932: if (exists($currtimeout{$type})) {
11933: if ($timeout ne $currtimeout{$type}) {
11934: $changes{'postsubmit'} = 1;
11935: }
11936: } elsif ($timeout ne '') {
11937: $changes{'postsubmit'} = 1;
11938: }
11939: }
11940: } else {
11941: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'off';
11942: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
11943: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'on') {
11944: $changes{'postsubmit'} = 1;
11945: }
11946: } else {
11947: $changes{'postsubmit'} = 1;
11948: }
1.192 raeburn 11949: }
1.121 raeburn 11950: }
11951: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
11952: $dom);
11953: if ($putresult eq 'ok') {
11954: if (keys(%changes) > 0) {
1.213 raeburn 11955: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.257 raeburn 11956: if (($changes{'canuse_pdfforms'}) || ($changes{'uploadquota'}) || ($changes{'postsubmit'}) ||
1.264 raeburn 11957: ($changes{'coursecredits'}) || ($changes{'uselcmath'}) || ($changes{'usejsme'}) ||
1.276 raeburn 11958: ($changes{'canclone'}) || ($changes{'mysqltables'})) {
1.257 raeburn 11959: foreach my $item ('canuse_pdfforms','uselcmath','usejsme') {
11960: if ($changes{$item}) {
11961: $domdefaults{$item}=$defaultshash{'coursedefaults'}{$item};
11962: }
11963: }
1.192 raeburn 11964: if ($changes{'coursecredits'}) {
11965: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
1.257 raeburn 11966: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'coursecredits'}})) {
11967: $domdefaults{$type.'credits'} =
11968: $defaultshash{'coursedefaults'}{'coursecredits'}{$type};
11969: }
11970: }
11971: }
11972: if ($changes{'postsubmit'}) {
11973: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
11974: $domdefaults{'postsubmit'} = $defaultshash{'coursedefaults'}{'postsubmit'}{'client'};
11975: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
11976: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}})) {
11977: $domdefaults{$type.'postsubtimeout'} =
11978: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
11979: }
11980: }
1.192 raeburn 11981: }
11982: }
1.198 raeburn 11983: if ($changes{'uploadquota'}) {
11984: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
11985: foreach my $type (@types) {
11986: $domdefaults{$type.'quota'}=$defaultshash{'coursedefaults'}{'uploadquota'}{$type};
11987: }
11988: }
11989: }
1.264 raeburn 11990: if ($changes{'canclone'}) {
11991: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
11992: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
11993: my @clonecodes = @{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}};
11994: if (@clonecodes) {
11995: $domdefaults{'canclone'} = join('+',@clonecodes);
11996: }
11997: }
11998: } else {
11999: $domdefaults{'canclone'}=$defaultshash{'coursedefaults'}{'canclone'};
12000: }
12001: }
1.121 raeburn 12002: my $cachetime = 24*60*60;
12003: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 12004: if (ref($lastactref) eq 'HASH') {
12005: $lastactref->{'domdefaults'} = 1;
12006: }
1.121 raeburn 12007: }
12008: $resulttext = &mt('Changes made:').'<ul>';
12009: foreach my $item (sort(keys(%changes))) {
12010: if ($item eq 'canuse_pdfforms') {
12011: if ($env{'form.'.$item} eq '1') {
12012: $resulttext .= '<li>'.&mt("Course/Community users can create/upload PDF forms set to 'on'").'</li>';
12013: } else {
12014: $resulttext .= '<li>'.&mt('Course/Community users can create/upload PDF forms set to "off"').'</li>';
12015: }
1.257 raeburn 12016: } elsif ($item eq 'uselcmath') {
12017: if ($env{'form.'.$item} eq '1') {
12018: $resulttext .= '<li>'.&mt('Math preview uses LON-CAPA previewer (javascript), if supported by browser.').'</li>';
12019: } else {
12020: $resulttext .= '<li>'.&mt('Math preview uses DragMath (Java), if supported by client OS.').'</li>';
12021: }
12022: } elsif ($item eq 'usejsme') {
12023: if ($env{'form.'.$item} eq '1') {
12024: $resulttext .= '<li>'.&mt('Molecule editor uses JSME (HTML5), if supported by browser.').'</li>';
12025: } else {
12026: $resulttext .= '<li>'.&mt('Molecule editor uses JME (Java), if supported by client OS.').'</li>';
12027: }
1.139 raeburn 12028: } elsif ($item eq 'anonsurvey_threshold') {
1.192 raeburn 12029: $resulttext .= '<li>'.&mt('Responder count required for display of anonymous survey submissions set to [_1].',$defaultshash{'coursedefaults'}{'anonsurvey_threshold'}).'</li>';
1.198 raeburn 12030: } elsif ($item eq 'uploadquota') {
12031: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
12032: $resulttext .= '<li>'.&mt('Default quota for content uploaded to a course/community via Course Editor set as follows:').'<ul>'.
12033: '<li>'.&mt('Official courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'official'}.'</b>').'</li>'.
12034: '<li>'.&mt('Unofficial courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'unofficial'}.'</b>').'</li>'.
1.216 raeburn 12035: '<li>'.&mt('Textbook courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'textbook'}.'</b>').'</li>'.
1.271 raeburn 12036: '<li>'.&mt('Placement tests: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'placement'}.'</b>').'</li>'.
1.198 raeburn 12037: '<li>'.&mt('Communities: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'community'}.'</b>').'</li>'.
12038: '</ul>'.
12039: '</li>';
12040: } else {
12041: $resulttext .= '<li>'.&mt('Default quota for content uploaded via Course Editor remains default: [_1] MB',$staticdefaults{'uploadquota'}).'</li>';
12042: }
1.276 raeburn 12043: } elsif ($item eq 'mysqltables') {
12044: if (ref($defaultshash{'coursedefaults'}{'mysqltables'}) eq 'HASH') {
12045: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver').'<ul>'.
12046: '<li>'.&mt('Official courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'official'}.'</b>').'</li>'.
12047: '<li>'.&mt('Unofficial courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'unofficial'}.'</b>').'</li>'.
12048: '<li>'.&mt('Textbook courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'textbook'}.'</b>').'</li>'.
12049: '<li>'.&mt('Placement tests: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'placement'}.'</b>').'</li>'.
12050: '<li>'.&mt('Communities: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'community'}.'</b>').'</li>'.
12051: '</ul>'.
12052: '</li>';
12053: } else {
12054: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver remains default: [_1] s',$staticdefaults{'uploadquota'}).'</li>';
12055: }
1.257 raeburn 12056: } elsif ($item eq 'postsubmit') {
12057: if ($domdefaults{'postsubmit'} eq 'off') {
12058: $resulttext .= '<li>'.&mt('Submit button(s) remain enabled on page after student makes submission.');
12059: } else {
12060: $resulttext .= '<li>'.&mt('Submit button(s) disabled on page after student makes submission').'; ';
12061: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
12062: $resulttext .= &mt('durations:').'<ul>';
12063: foreach my $type (@types) {
12064: $resulttext .= '<li>';
12065: my $timeout;
12066: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
12067: $timeout = $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
12068: }
12069: my $display;
12070: if ($timeout eq '0') {
12071: $display = &mt('unlimited');
12072: } elsif ($timeout eq '') {
12073: $display = &mt('[quant,_1,second] (default)',$staticdefaults{'postsubmit'});
12074: } else {
12075: $display = &mt('[quant,_1,second]',$timeout);
12076: }
12077: if ($type eq 'community') {
12078: $resulttext .= &mt('Communities');
12079: } elsif ($type eq 'official') {
12080: $resulttext .= &mt('Official courses');
12081: } elsif ($type eq 'unofficial') {
12082: $resulttext .= &mt('Unofficial courses');
12083: } elsif ($type eq 'textbook') {
12084: $resulttext .= &mt('Textbook courses');
1.271 raeburn 12085: } elsif ($type eq 'placement') {
12086: $resulttext .= &mt('Placement tests');
1.257 raeburn 12087: }
12088: $resulttext .= ' -- '.$display.'</li>';
12089: }
12090: $resulttext .= '</ul>';
12091: }
12092: $resulttext .= '</li>';
12093: }
1.192 raeburn 12094: } elsif ($item eq 'coursecredits') {
12095: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
12096: if (($domdefaults{'officialcredits'} eq '') &&
1.216 raeburn 12097: ($domdefaults{'unofficialcredits'} eq '') &&
12098: ($domdefaults{'textbookcredits'} eq '')) {
1.192 raeburn 12099: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
12100: } else {
12101: $resulttext .= '<li>'.&mt('Student credits can be set per course by a Domain Coordinator, with the following defaults applying:').'<ul>'.
12102: '<li>'.&mt('Official courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'official'}).'</li>'.
12103: '<li>'.&mt('Unofficial courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'}).'</li>'.
1.216 raeburn 12104: '<li>'.&mt('Textbook courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'textbook'}).'</li>'.
1.192 raeburn 12105: '</ul>'.
12106: '</li>';
12107: }
12108: } else {
12109: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
12110: }
1.264 raeburn 12111: } elsif ($item eq 'canclone') {
12112: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
12113: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
12114: my $clonecodes = join(' '.&mt('and').' ',@{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}});
12115: $resulttext .= '<li>'.&mt('By default, official courses can be cloned from existing courses with the same: [_1]','<b>'.$clonecodes.'</b>').'</li>';
12116: }
12117: } elsif ($defaultshash{'coursedefaults'}{'canclone'} eq 'domain') {
12118: $resulttext .= '<li>'.&mt('By default, a course requester can clone any course from his/her domain.').'</li>';
12119: } else {
12120: $resulttext .= '<li>'.&mt('By default, only course owner and coordinators may clone a course.').'</li>';
12121: }
1.140 raeburn 12122: }
1.121 raeburn 12123: }
12124: $resulttext .= '</ul>';
12125: } else {
12126: $resulttext = &mt('No changes made to course defaults');
12127: }
12128: } else {
12129: $resulttext = '<span class="LC_error">'.
12130: &mt('An error occurred: [_1]',$putresult).'</span>';
12131: }
12132: return $resulttext;
12133: }
12134:
1.231 raeburn 12135: sub modify_selfenrollment {
12136: my ($dom,$lastactref,%domconfig) = @_;
12137: my ($resulttext,$errors,%changes,%selfenrollhash,%ordered);
1.271 raeburn 12138: my @types = ('official','unofficial','community','textbook','placement');
1.231 raeburn 12139: my %titles = &tool_titles();
1.232 raeburn 12140: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
12141: ($ordered{'admin'},my $titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
1.231 raeburn 12142: $ordered{'default'} = ['types','registered','approval','limit'];
12143:
12144: my (%roles,%shown,%toplevel);
12145: $roles{'0'} = &Apache::lonnet::plaintext('dc');
12146:
12147: if (ref($domconfig{'selfenrollment'}) ne 'HASH') {
12148: if ($domconfig{'selfenrollment'} eq '') {
12149: $domconfig{'selfenrollment'} = {};
12150: }
12151: }
12152: %toplevel = (
12153: admin => 'Configuration Rights',
12154: default => 'Default settings',
12155: validation => 'Validation of self-enrollment requests',
12156: );
1.233 raeburn 12157: my ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
1.231 raeburn 12158:
12159: if (ref($ordered{'admin'}) eq 'ARRAY') {
12160: foreach my $item (@{$ordered{'admin'}}) {
12161: foreach my $type (@types) {
12162: if ($env{'form.selfenrolladmin_'.$item.'_'.$type}) {
12163: $selfenrollhash{'admin'}{$type}{$item} = 1;
12164: } else {
12165: $selfenrollhash{'admin'}{$type}{$item} = 0;
12166: }
12167: if (ref($domconfig{'selfenrollment'}{'admin'}) eq 'HASH') {
12168: if (ref($domconfig{'selfenrollment'}{'admin'}{$type}) eq 'HASH') {
12169: if ($selfenrollhash{'admin'}{$type}{$item} ne
12170: $domconfig{'selfenrollment'}{'admin'}{$type}{$item}) {
12171: push(@{$changes{'admin'}{$type}},$item);
12172: }
12173: } else {
12174: if (!$selfenrollhash{'admin'}{$type}{$item}) {
12175: push(@{$changes{'admin'}{$type}},$item);
12176: }
12177: }
12178: } elsif (!$selfenrollhash{'admin'}{$type}{$item}) {
12179: push(@{$changes{'admin'}{$type}},$item);
12180: }
12181: }
12182: }
12183: }
12184:
12185: foreach my $item (@{$ordered{'default'}}) {
12186: foreach my $type (@types) {
12187: my $value = $env{'form.selfenrolldefault_'.$item.'_'.$type};
12188: if ($item eq 'types') {
12189: unless (($value eq 'all') || ($value eq 'dom')) {
12190: $value = '';
12191: }
12192: } elsif ($item eq 'registered') {
12193: unless ($value eq '1') {
12194: $value = 0;
12195: }
12196: } elsif ($item eq 'approval') {
12197: unless ($value =~ /^[012]$/) {
12198: $value = 0;
12199: }
12200: } else {
12201: unless (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
12202: $value = 'none';
12203: }
12204: }
12205: $selfenrollhash{'default'}{$type}{$item} = $value;
12206: if (ref($domconfig{'selfenrollment'}{'default'}) eq 'HASH') {
12207: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
12208: if ($selfenrollhash{'default'}{$type}{$item} ne
12209: $domconfig{'selfenrollment'}{'default'}{$type}{$item}) {
12210: push(@{$changes{'default'}{$type}},$item);
12211: }
12212: } else {
12213: push(@{$changes{'default'}{$type}},$item);
12214: }
12215: } else {
12216: push(@{$changes{'default'}{$type}},$item);
12217: }
12218: if ($item eq 'limit') {
12219: if (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
12220: $env{'form.selfenrolldefault_cap_'.$type} =~ s/\D//g;
12221: if ($env{'form.selfenrolldefault_cap_'.$type} ne '') {
12222: $selfenrollhash{'default'}{$type}{'cap'} = $env{'form.selfenrolldefault_cap_'.$type};
12223: }
12224: } else {
12225: $selfenrollhash{'default'}{$type}{'cap'} = '';
12226: }
12227: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
12228: if ($selfenrollhash{'default'}{$type}{'cap'} ne
12229: $domconfig{'selfenrollment'}{'admin'}{$type}{'cap'}) {
12230: push(@{$changes{'default'}{$type}},'cap');
12231: }
12232: } elsif ($selfenrollhash{'default'}{$type}{'cap'} ne '') {
12233: push(@{$changes{'default'}{$type}},'cap');
12234: }
12235: }
12236: }
12237: }
12238:
12239: foreach my $item (@{$itemsref}) {
12240: if ($item eq 'fields') {
12241: my @changed;
12242: @{$selfenrollhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.selfenroll_validation_'.$item);
12243: if (@{$selfenrollhash{'validation'}{$item}} > 0) {
12244: @{$selfenrollhash{'validation'}{$item}} = sort(@{$selfenrollhash{'validation'}{$item}});
12245: }
12246: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
12247: if (ref($domconfig{'selfenrollment'}{'validation'}{$item}) eq 'ARRAY') {
12248: @changed = &Apache::loncommon::compare_arrays($selfenrollhash{'validation'}{$item},
12249: $domconfig{'selfenrollment'}{'validation'}{$item});
12250: } else {
12251: @changed = @{$selfenrollhash{'validation'}{$item}};
12252: }
12253: } else {
12254: @changed = @{$selfenrollhash{'validation'}{$item}};
12255: }
12256: if (@changed) {
12257: if ($selfenrollhash{'validation'}{$item}) {
12258: $changes{'validation'}{$item} = join(', ',@{$selfenrollhash{'validation'}{$item}});
12259: } else {
12260: $changes{'validation'}{$item} = &mt('None');
12261: }
12262: }
12263: } else {
12264: $selfenrollhash{'validation'}{$item} = $env{'form.selfenroll_validation_'.$item};
12265: if ($item eq 'markup') {
12266: if ($env{'form.selfenroll_validation_'.$item}) {
12267: $env{'form.selfenroll_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
12268: }
12269: }
12270: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
12271: if ($domconfig{'selfenrollment'}{'validation'}{$item} ne $selfenrollhash{'validation'}{$item}) {
12272: $changes{'validation'}{$item} = $selfenrollhash{'validation'}{$item};
12273: }
12274: }
12275: }
12276: }
12277:
12278: my $putresult = &Apache::lonnet::put_dom('configuration',{'selfenrollment' => \%selfenrollhash},
12279: $dom);
12280: if ($putresult eq 'ok') {
12281: if (keys(%changes) > 0) {
12282: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
12283: $resulttext = &mt('Changes made:').'<ul>';
12284: foreach my $key ('admin','default','validation') {
12285: if (ref($changes{$key}) eq 'HASH') {
12286: $resulttext .= '<li>'.$toplevel{$key}.'<ul>';
12287: if ($key eq 'validation') {
12288: foreach my $item (@{$itemsref}) {
12289: if (exists($changes{$key}{$item})) {
12290: if ($item eq 'markup') {
12291: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
12292: '<br /><pre>'.$changes{$key}{$item}.'</pre>').'</li>';
12293: } else {
12294: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
12295: '<b>'.$changes{$key}{$item}.'</b>').'</li>';
12296: }
12297: }
12298: }
12299: } else {
12300: foreach my $type (@types) {
12301: if ($type eq 'community') {
12302: $roles{'1'} = &mt('Community personnel');
12303: } else {
12304: $roles{'1'} = &mt('Course personnel');
12305: }
12306: if (ref($changes{$key}{$type}) eq 'ARRAY') {
1.232 raeburn 12307: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
12308: if ($key eq 'admin') {
12309: my @mgrdc = ();
12310: if (ref($ordered{$key}) eq 'ARRAY') {
12311: foreach my $item (@{$ordered{'admin'}}) {
12312: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
12313: if ($selfenrollhash{$key}{$type}{$item} eq '0') {
12314: push(@mgrdc,$item);
12315: }
12316: }
12317: }
12318: if (@mgrdc) {
12319: $domdefaults{$type.'selfenrolladmdc'} = join(',',@mgrdc);
12320: } else {
12321: delete($domdefaults{$type.'selfenrolladmdc'});
12322: }
12323: }
12324: } else {
12325: if (ref($ordered{$key}) eq 'ARRAY') {
12326: foreach my $item (@{$ordered{$key}}) {
12327: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
12328: $domdefaults{$type.'selfenroll'.$item} =
12329: $selfenrollhash{$key}{$type}{$item};
12330: }
12331: }
12332: }
12333: }
12334: }
1.231 raeburn 12335: $resulttext .= '<li>'.$titles{$type}.'<ul>';
12336: foreach my $item (@{$ordered{$key}}) {
12337: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
12338: $resulttext .= '<li>';
12339: if ($key eq 'admin') {
12340: $resulttext .= &mt('[_1] -- management by: [_2]',$titlesref->{$item},
12341: '<b>'.$roles{$selfenrollhash{'admin'}{$type}{$item}}.'</b>');
12342: } else {
12343: $resulttext .= &mt('[_1] set to: [_2]',$titlesref->{$item},
12344: '<b>'.$descs{$item}{$selfenrollhash{'default'}{$type}{$item}}.'</b>');
12345: }
12346: $resulttext .= '</li>';
12347: }
12348: }
12349: $resulttext .= '</ul></li>';
12350: }
12351: }
12352: $resulttext .= '</ul></li>';
12353: }
12354: }
1.232 raeburn 12355: if ((exists($changes{'admin'})) || (exists($changes{'default'}))) {
12356: my $cachetime = 24*60*60;
12357: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
12358: if (ref($lastactref) eq 'HASH') {
12359: $lastactref->{'domdefaults'} = 1;
12360: }
12361: }
1.231 raeburn 12362: }
12363: $resulttext .= '</ul>';
12364: } else {
12365: $resulttext = &mt('No changes made to self-enrollment settings');
12366: }
12367: } else {
12368: $resulttext = '<span class="LC_error">'.
12369: &mt('An error occurred: [_1]',$putresult).'</span>';
12370: }
12371: return $resulttext;
12372: }
12373:
1.137 raeburn 12374: sub modify_usersessions {
1.212 raeburn 12375: my ($dom,$lastactref,%domconfig) = @_;
1.145 raeburn 12376: my @hostingtypes = ('version','excludedomain','includedomain');
12377: my @offloadtypes = ('primary','default');
12378: my %types = (
12379: remote => \@hostingtypes,
12380: hosted => \@hostingtypes,
12381: spares => \@offloadtypes,
12382: );
12383: my @prefixes = ('remote','hosted','spares');
1.137 raeburn 12384: my @lcversions = &Apache::lonnet::all_loncaparevs();
1.275 raeburn 12385: my (%by_ip,%by_location,@intdoms,@instdoms);
12386: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
1.138 raeburn 12387: my @locations = sort(keys(%by_location));
1.137 raeburn 12388: my (%defaultshash,%changes);
12389: foreach my $prefix (@prefixes) {
12390: $defaultshash{'usersessions'}{$prefix} = {};
12391: }
1.212 raeburn 12392: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.137 raeburn 12393: my $resulttext;
1.138 raeburn 12394: my %iphost = &Apache::lonnet::get_iphost();
1.137 raeburn 12395: foreach my $prefix (@prefixes) {
1.145 raeburn 12396: next if ($prefix eq 'spares');
12397: foreach my $type (@{$types{$prefix}}) {
1.137 raeburn 12398: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
12399: if ($type eq 'version') {
12400: my $value = $env{'form.'.$prefix.'_'.$type};
12401: my $okvalue;
12402: if ($value ne '') {
12403: if (grep(/^\Q$value\E$/,@lcversions)) {
12404: $okvalue = $value;
12405: }
12406: }
12407: if (ref($domconfig{'usersessions'}) eq 'HASH') {
12408: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
12409: if ($domconfig{'usersessions'}{$prefix}{$type} ne '') {
12410: if ($inuse == 0) {
12411: $changes{$prefix}{$type} = 1;
12412: } else {
12413: if ($okvalue ne $domconfig{'usersessions'}{$prefix}{$type}) {
12414: $changes{$prefix}{$type} = 1;
12415: }
12416: if ($okvalue ne '') {
12417: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
12418: }
12419: }
12420: } else {
12421: if (($inuse == 1) && ($okvalue ne '')) {
12422: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
12423: $changes{$prefix}{$type} = 1;
12424: }
12425: }
12426: } else {
12427: if (($inuse == 1) && ($okvalue ne '')) {
12428: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
12429: $changes{$prefix}{$type} = 1;
12430: }
12431: }
12432: } else {
12433: if (($inuse == 1) && ($okvalue ne '')) {
12434: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
12435: $changes{$prefix}{$type} = 1;
12436: }
12437: }
12438: } else {
12439: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
12440: my @okvals;
12441: foreach my $val (@vals) {
1.138 raeburn 12442: if ($val =~ /:/) {
12443: my @items = split(/:/,$val);
12444: foreach my $item (@items) {
12445: if (ref($by_location{$item}) eq 'ARRAY') {
12446: push(@okvals,$item);
12447: }
12448: }
12449: } else {
12450: if (ref($by_location{$val}) eq 'ARRAY') {
12451: push(@okvals,$val);
12452: }
1.137 raeburn 12453: }
12454: }
12455: @okvals = sort(@okvals);
12456: if (ref($domconfig{'usersessions'}) eq 'HASH') {
12457: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
12458: if (ref($domconfig{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
12459: if ($inuse == 0) {
12460: $changes{$prefix}{$type} = 1;
12461: } else {
12462: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
12463: my @changed = &Apache::loncommon::compare_arrays($domconfig{'usersessions'}{$prefix}{$type},$defaultshash{'usersessions'}{$prefix}{$type});
12464: if (@changed > 0) {
12465: $changes{$prefix}{$type} = 1;
12466: }
12467: }
12468: } else {
12469: if ($inuse == 1) {
12470: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
12471: $changes{$prefix}{$type} = 1;
12472: }
12473: }
12474: } else {
12475: if ($inuse == 1) {
12476: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
12477: $changes{$prefix}{$type} = 1;
12478: }
12479: }
12480: } else {
12481: if ($inuse == 1) {
12482: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
12483: $changes{$prefix}{$type} = 1;
12484: }
12485: }
12486: }
12487: }
12488: }
1.145 raeburn 12489:
12490: my @alldoms = &Apache::lonnet::all_domains();
1.149 raeburn 12491: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.145 raeburn 12492: my %spareid = ¤t_offloads_to($dom,$domconfig{'usersessions'},\%servers);
12493: my $savespares;
12494:
12495: foreach my $lonhost (sort(keys(%servers))) {
12496: my $serverhomeID =
12497: &Apache::lonnet::get_server_homeID($servers{$lonhost});
1.152 raeburn 12498: my $serverhostname = &Apache::lonnet::hostname($lonhost);
1.145 raeburn 12499: $defaultshash{'usersessions'}{'spares'}{$lonhost} = {};
12500: my %spareschg;
12501: foreach my $type (@{$types{'spares'}}) {
12502: my @okspares;
12503: my @checked = &Apache::loncommon::get_env_multiple('form.spare_'.$type.'_'.$lonhost);
12504: foreach my $server (@checked) {
1.152 raeburn 12505: if (&Apache::lonnet::hostname($server) ne '') {
12506: unless (&Apache::lonnet::hostname($server) eq $serverhostname) {
12507: unless (grep(/^\Q$server\E$/,@okspares)) {
12508: push(@okspares,$server);
12509: }
1.145 raeburn 12510: }
12511: }
12512: }
12513: my $new = $env{'form.newspare_'.$type.'_'.$lonhost};
12514: my $newspare;
1.152 raeburn 12515: if (($new ne '') && (&Apache::lonnet::hostname($new))) {
12516: unless (&Apache::lonnet::hostname($new) eq $serverhostname) {
1.145 raeburn 12517: $newspare = $new;
12518: }
12519: }
1.152 raeburn 12520: my @spares;
12521: if (($newspare ne '') && (!grep(/^\Q$newspare\E$/,@okspares))) {
12522: @spares = sort(@okspares,$newspare);
12523: } else {
12524: @spares = sort(@okspares);
12525: }
12526: $defaultshash{'usersessions'}{'spares'}{$lonhost}{$type} = \@spares;
1.145 raeburn 12527: if (ref($spareid{$lonhost}) eq 'HASH') {
12528: if (ref($spareid{$lonhost}{$type}) eq 'ARRAY') {
1.152 raeburn 12529: my @diffs = &Apache::loncommon::compare_arrays($spareid{$lonhost}{$type},\@spares);
1.145 raeburn 12530: if (@diffs > 0) {
12531: $spareschg{$type} = 1;
12532: }
12533: }
12534: }
12535: }
12536: if (keys(%spareschg) > 0) {
12537: $changes{'spares'}{$lonhost} = \%spareschg;
12538: }
12539: }
1.261 raeburn 12540: $defaultshash{'usersessions'}{'offloadnow'} = {};
12541: my @offloadnow = &Apache::loncommon::get_env_multiple('form.offloadnow');
12542: my @okoffload;
12543: if (@offloadnow) {
12544: foreach my $server (@offloadnow) {
12545: if (&Apache::lonnet::hostname($server) ne '') {
12546: unless (grep(/^\Q$server\E$/,@okoffload)) {
12547: push(@okoffload,$server);
12548: }
12549: }
12550: }
12551: if (@okoffload) {
12552: foreach my $lonhost (@okoffload) {
12553: $defaultshash{'usersessions'}{'offloadnow'}{$lonhost} = 1;
12554: }
12555: }
12556: }
1.145 raeburn 12557: if (ref($domconfig{'usersessions'}) eq 'HASH') {
12558: if (ref($domconfig{'usersessions'}{'spares'}) eq 'HASH') {
12559: if (ref($changes{'spares'}) eq 'HASH') {
12560: if (keys(%{$changes{'spares'}}) > 0) {
12561: $savespares = 1;
12562: }
12563: }
12564: } else {
12565: $savespares = 1;
12566: }
1.261 raeburn 12567: if (ref($domconfig{'usersessions'}{'offloadnow'}) eq 'HASH') {
12568: foreach my $lonhost (keys(%{$domconfig{'usersessions'}{'offloadnow'}})) {
12569: unless ($defaultshash{'usersessions'}{'offloadnow'}{$lonhost}) {
12570: $changes{'offloadnow'} = 1;
12571: last;
12572: }
12573: }
12574: unless ($changes{'offloadnow'}) {
12575: foreach my $lonhost (keys(%{$defaultshash{'usersessions'}{'offloadnow'}})) {
12576: unless ($domconfig{'usersessions'}{'offloadnow'}{$lonhost}) {
12577: $changes{'offloadnow'} = 1;
12578: last;
12579: }
12580: }
12581: }
12582: } elsif (@okoffload) {
12583: $changes{'offloadnow'} = 1;
12584: }
12585: } elsif (@okoffload) {
12586: $changes{'offloadnow'} = 1;
1.145 raeburn 12587: }
1.147 raeburn 12588: my $nochgmsg = &mt('No changes made to settings for user session hosting/offloading.');
12589: if ((keys(%changes) > 0) || ($savespares)) {
1.137 raeburn 12590: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
12591: $dom);
12592: if ($putresult eq 'ok') {
12593: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
12594: if (ref($defaultshash{'usersessions'}{'remote'}) eq 'HASH') {
12595: $domdefaults{'remotesessions'} = $defaultshash{'usersessions'}{'remote'};
12596: }
12597: if (ref($defaultshash{'usersessions'}{'hosted'}) eq 'HASH') {
12598: $domdefaults{'hostedsessions'} = $defaultshash{'usersessions'}{'hosted'};
12599: }
1.261 raeburn 12600: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
12601: $domdefaults{'offloadnow'} = $defaultshash{'usersessions'}{'offloadnow'};
12602: }
1.137 raeburn 12603: }
12604: my $cachetime = 24*60*60;
12605: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 12606: if (ref($lastactref) eq 'HASH') {
12607: $lastactref->{'domdefaults'} = 1;
12608: }
1.147 raeburn 12609: if (keys(%changes) > 0) {
12610: my %lt = &usersession_titles();
12611: $resulttext = &mt('Changes made:').'<ul>';
12612: foreach my $prefix (@prefixes) {
12613: if (ref($changes{$prefix}) eq 'HASH') {
12614: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
12615: if ($prefix eq 'spares') {
12616: if (ref($changes{$prefix}) eq 'HASH') {
12617: foreach my $lonhost (sort(keys(%{$changes{$prefix}}))) {
12618: $resulttext .= '<li><b>'.$lonhost.'</b> ';
1.148 raeburn 12619: my $lonhostdom = &Apache::lonnet::host_domain($lonhost);
1.211 raeburn 12620: my $cachekey = &escape('spares').':'.&escape($lonhostdom);
12621: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
1.147 raeburn 12622: if (ref($changes{$prefix}{$lonhost}) eq 'HASH') {
12623: foreach my $type (@{$types{$prefix}}) {
12624: if ($changes{$prefix}{$lonhost}{$type}) {
12625: my $offloadto = &mt('None');
12626: if (ref($defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}) eq 'ARRAY') {
12627: if (@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}} > 0) {
12628: $offloadto = join(', ',@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}});
12629: }
1.145 raeburn 12630: }
1.147 raeburn 12631: $resulttext .= &mt('[_1] set to: [_2].','<i>'.$lt{$type}.'</i>',$offloadto).(' 'x3);
1.145 raeburn 12632: }
1.137 raeburn 12633: }
12634: }
1.147 raeburn 12635: $resulttext .= '</li>';
1.137 raeburn 12636: }
12637: }
1.147 raeburn 12638: } else {
12639: foreach my $type (@{$types{$prefix}}) {
12640: if (defined($changes{$prefix}{$type})) {
12641: my $newvalue;
12642: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
12643: if (ref($defaultshash{'usersessions'}{$prefix})) {
12644: if ($type eq 'version') {
12645: $newvalue = $defaultshash{'usersessions'}{$prefix}{$type};
12646: } elsif (ref($defaultshash{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
12647: if (@{$defaultshash{'usersessions'}{$prefix}{$type}} > 0) {
12648: $newvalue = join(', ',@{$defaultshash{'usersessions'}{$prefix}{$type}});
12649: }
1.145 raeburn 12650: }
12651: }
12652: }
1.147 raeburn 12653: if ($newvalue eq '') {
12654: if ($type eq 'version') {
12655: $resulttext .= '<li>'.&mt('[_1] set to: off',$lt{$type}).'</li>';
12656: } else {
12657: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
12658: }
1.145 raeburn 12659: } else {
1.147 raeburn 12660: if ($type eq 'version') {
12661: $newvalue .= ' '.&mt('(or later)');
12662: }
12663: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
1.145 raeburn 12664: }
1.137 raeburn 12665: }
12666: }
12667: }
1.147 raeburn 12668: $resulttext .= '</ul>';
1.137 raeburn 12669: }
12670: }
1.261 raeburn 12671: if ($changes{'offloadnow'}) {
12672: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
12673: if (keys(%{$defaultshash{'usersessions'}{'offloadnow'}}) > 0) {
12674: $resulttext .= '<li>'.&mt('Switch active users on next access, for server(s):').'<ul>';
12675: foreach my $lonhost (sort(keys(%{$defaultshash{'usersessions'}{'offloadnow'}}))) {
12676: $resulttext .= '<li>'.$lonhost.'</li>';
12677: }
12678: $resulttext .= '</ul>';
12679: } else {
12680: $resulttext .= '<li>'.&mt('No servers now set to switch active users on next access.');
12681: }
12682: } else {
12683: $resulttext .= '<li>'.&mt('No servers now set to switch active users on next access.').'</li>';
12684: }
12685: }
1.147 raeburn 12686: $resulttext .= '</ul>';
12687: } else {
12688: $resulttext = $nochgmsg;
1.137 raeburn 12689: }
12690: } else {
12691: $resulttext = '<span class="LC_error">'.
12692: &mt('An error occurred: [_1]',$putresult).'</span>';
12693: }
12694: } else {
1.147 raeburn 12695: $resulttext = $nochgmsg;
1.137 raeburn 12696: }
12697: return $resulttext;
12698: }
12699:
1.275 raeburn 12700: sub modify_ssl {
12701: my ($dom,$lastactref,%domconfig) = @_;
12702: my (%by_ip,%by_location,@intdoms,@instdoms);
12703: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
12704: my @locations = sort(keys(%by_location));
12705: my %servers = &Apache::lonnet::internet_dom_servers($dom);
12706: my (%defaultshash,%changes);
12707: my $action = 'ssl';
12708: my @prefixes = ('connect','replication');
12709: foreach my $prefix (@prefixes) {
12710: $defaultshash{$action}{$prefix} = {};
12711: }
12712: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
12713: my $resulttext;
12714: my %iphost = &Apache::lonnet::get_iphost();
12715: my @reptypes = ('certreq','nocertreq');
12716: my @connecttypes = ('dom','intdom','other');
12717: my %types = (
12718: connect => \@connecttypes,
12719: replication => \@reptypes,
12720: );
12721: foreach my $prefix (sort(keys(%types))) {
12722: foreach my $type (@{$types{$prefix}}) {
12723: if ($prefix eq 'connect') {
12724: my $value = 'yes';
12725: if ($env{'form.'.$prefix.'_'.$type} =~ /^(no|req)$/) {
12726: $value = $env{'form.'.$prefix.'_'.$type};
12727: }
12728: if (ref($domconfig{$action}{$prefix}) eq 'HASH') {
12729: if ($domconfig{$action}{$prefix}{$type} ne '') {
12730: if ($value ne $domconfig{$action}{$prefix}{$type}) {
12731: $changes{$prefix}{$type} = 1;
12732: }
12733: $defaultshash{$action}{$prefix}{$type} = $value;
12734: } else {
12735: $defaultshash{$action}{$prefix}{$type} = $value;
12736: $changes{$prefix}{$type} = 1;
12737: }
12738: } else {
12739: $defaultshash{$action}{$prefix}{$type} = $value;
12740: $changes{$prefix}{$type} = 1;
12741: }
12742: if (($type eq 'dom') && (keys(%servers) == 1)) {
12743: delete($changes{$prefix}{$type});
12744: } elsif (($type eq 'intdom') && (@instdoms == 1)) {
12745: delete($changes{$prefix}{$type});
12746: } elsif (($type eq 'other') && (keys(%by_location) == 0)) {
12747: delete($changes{$prefix}{$type});
12748: }
12749: } elsif ($prefix eq 'replication') {
12750: if (@locations > 0) {
12751: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
12752: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
12753: my @okvals;
12754: foreach my $val (@vals) {
12755: if ($val =~ /:/) {
12756: my @items = split(/:/,$val);
12757: foreach my $item (@items) {
12758: if (ref($by_location{$item}) eq 'ARRAY') {
12759: push(@okvals,$item);
12760: }
12761: }
12762: } else {
12763: if (ref($by_location{$val}) eq 'ARRAY') {
12764: push(@okvals,$val);
12765: }
12766: }
12767: }
12768: @okvals = sort(@okvals);
12769: if (ref($domconfig{$action}) eq 'HASH') {
12770: if (ref($domconfig{$action}{$prefix}) eq 'HASH') {
12771: if (ref($domconfig{$action}{$prefix}{$type}) eq 'ARRAY') {
12772: if ($inuse == 0) {
12773: $changes{$prefix}{$type} = 1;
12774: } else {
12775: $defaultshash{$action}{$prefix}{$type} = \@okvals;
12776: my @changed = &Apache::loncommon::compare_arrays($domconfig{$action}{$prefix}{$type},$defaultshash{$action}{$prefix}{$type});
12777: if (@changed > 0) {
12778: $changes{$prefix}{$type} = 1;
12779: }
12780: }
12781: } else {
12782: if ($inuse == 1) {
12783: $defaultshash{$action}{$prefix}{$type} = \@okvals;
12784: $changes{$prefix}{$type} = 1;
12785: }
12786: }
12787: } else {
12788: if ($inuse == 1) {
12789: $defaultshash{$action}{$prefix}{$type} = \@okvals;
12790: $changes{$prefix}{$type} = 1;
12791: }
12792: }
12793: } else {
12794: if ($inuse == 1) {
12795: $defaultshash{$action}{$prefix}{$type} = \@okvals;
12796: $changes{$prefix}{$type} = 1;
12797: }
12798: }
12799: }
12800: }
12801: }
12802: }
12803: my $nochgmsg = &mt('No changes made to LON-CAPA SSL settings');
12804: if (keys(%changes) > 0) {
12805: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
12806: $dom);
12807: if ($putresult eq 'ok') {
12808: if (ref($defaultshash{$action}) eq 'HASH') {
12809: if (ref($defaultshash{$action}{'replication'}) eq 'HASH') {
12810: $domdefaults{'replication'} = $defaultshash{$action}{'replication'};
12811: }
12812: if (ref($defaultshash{$action}{'connect'}) eq 'HASH') {
12813: $domdefaults{'connect'} = $domconfig{$action}{'connect'};
12814: }
12815: }
12816: my $cachetime = 24*60*60;
12817: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
12818: if (ref($lastactref) eq 'HASH') {
12819: $lastactref->{'domdefaults'} = 1;
12820: }
12821: if (keys(%changes) > 0) {
12822: my %titles = &ssl_titles();
12823: $resulttext = &mt('Changes made:').'<ul>';
12824: foreach my $prefix (@prefixes) {
12825: if (ref($changes{$prefix}) eq 'HASH') {
12826: $resulttext .= '<li>'.$titles{$prefix}.'<ul>';
12827: foreach my $type (@{$types{$prefix}}) {
12828: if (defined($changes{$prefix}{$type})) {
12829: my $newvalue;
12830: if (ref($defaultshash{$action}) eq 'HASH') {
12831: if (ref($defaultshash{$action}{$prefix})) {
12832: if ($prefix eq 'connect') {
12833: $newvalue = $titles{$defaultshash{$action}{$prefix}{$type}};
12834: } elsif (ref($defaultshash{$action}{$prefix}{$type}) eq 'ARRAY') {
12835: if (@{$defaultshash{$action}{$prefix}{$type}} > 0) {
12836: $newvalue = join(', ',@{$defaultshash{$action}{$prefix}{$type}});
12837: }
12838: }
12839: }
12840: if ($newvalue eq '') {
12841: $resulttext .= '<li>'.&mt('[_1] set to: none',$titles{$type}).'</li>';
12842: } else {
12843: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$titles{$type},$newvalue).'</li>';
12844: }
12845: }
12846: }
12847: }
12848: $resulttext .= '</ul>';
12849: }
12850: }
12851: } else {
12852: $resulttext = $nochgmsg;
12853: }
12854: } else {
12855: $resulttext = '<span class="LC_error">'.
12856: &mt('An error occurred: [_1]',$putresult).'</span>';
12857: }
12858: } else {
12859: $resulttext = $nochgmsg;
12860: }
12861: return $resulttext;
12862: }
12863:
1.279 raeburn 12864: sub modify_trust {
12865: my ($dom,$lastactref,%domconfig) = @_;
12866: my (%by_ip,%by_location,@intdoms,@instdoms);
12867: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
12868: my @locations = sort(keys(%by_location));
12869: my @prefixes = qw(content shared enroll othcoau coaurem domroles catalog reqcrs msg);
12870: my @types = ('exc','inc');
12871: my (%defaultshash,%changes);
12872: foreach my $prefix (@prefixes) {
12873: $defaultshash{'trust'}{$prefix} = {};
12874: }
12875: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
12876: my $resulttext;
12877: foreach my $prefix (@prefixes) {
12878: foreach my $type (@types) {
12879: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
12880: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
12881: my @okvals;
12882: foreach my $val (@vals) {
12883: if ($val =~ /:/) {
12884: my @items = split(/:/,$val);
12885: foreach my $item (@items) {
12886: if (ref($by_location{$item}) eq 'ARRAY') {
12887: push(@okvals,$item);
12888: }
12889: }
12890: } else {
12891: if (ref($by_location{$val}) eq 'ARRAY') {
12892: push(@okvals,$val);
12893: }
12894: }
12895: }
12896: @okvals = sort(@okvals);
12897: if (ref($domconfig{'trust'}) eq 'HASH') {
12898: if (ref($domconfig{'trust'}{$prefix}) eq 'HASH') {
12899: if (ref($domconfig{'trust'}{$prefix}{$type}) eq 'ARRAY') {
12900: if ($inuse == 0) {
12901: $changes{$prefix}{$type} = 1;
12902: } else {
12903: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
12904: my @changed = &Apache::loncommon::compare_arrays($domconfig{'trust'}{$prefix}{$type},$defaultshash{'trust'}{$prefix}{$type});
12905: if (@changed > 0) {
12906: $changes{$prefix}{$type} = 1;
12907: }
12908: }
12909: } else {
12910: if ($inuse == 1) {
12911: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
12912: $changes{$prefix}{$type} = 1;
12913: }
12914: }
12915: } else {
12916: if ($inuse == 1) {
12917: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
12918: $changes{$prefix}{$type} = 1;
12919: }
12920: }
12921: } else {
12922: if ($inuse == 1) {
12923: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
12924: $changes{$prefix}{$type} = 1;
12925: }
12926: }
12927: }
12928: }
12929: my $nochgmsg = &mt('No changes made to trust settings.');
12930: if (keys(%changes) > 0) {
12931: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
12932: $dom);
12933: if ($putresult eq 'ok') {
12934: if (ref($defaultshash{'trust'}) eq 'HASH') {
12935: foreach my $prefix (@prefixes) {
12936: if (ref($defaultshash{'trust'}{$prefix}) eq 'HASH') {
12937: $domdefaults{'trust'.$prefix} = $defaultshash{'trust'}{$prefix};
12938: }
12939: }
12940: }
12941: my $cachetime = 24*60*60;
12942: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
12943: if (ref($lastactref) eq 'HASH') {
12944: $lastactref->{'domdefaults'} = 1;
12945: }
12946: if (keys(%changes) > 0) {
12947: my %lt = &trust_titles();
12948: $resulttext = &mt('Changes made:').'<ul>';
12949: foreach my $prefix (@prefixes) {
12950: if (ref($changes{$prefix}) eq 'HASH') {
12951: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
12952: foreach my $type (@types) {
12953: if (defined($changes{$prefix}{$type})) {
12954: my $newvalue;
12955: if (ref($defaultshash{'trust'}) eq 'HASH') {
12956: if (ref($defaultshash{'trust'}{$prefix})) {
12957: if (ref($defaultshash{'trust'}{$prefix}{$type}) eq 'ARRAY') {
12958: if (@{$defaultshash{'trust'}{$prefix}{$type}} > 0) {
12959: $newvalue = join(', ',@{$defaultshash{'trust'}{$prefix}{$type}});
12960: }
12961: }
12962: }
12963: }
12964: if ($newvalue eq '') {
12965: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
12966: } else {
12967: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
12968: }
12969: }
12970: }
12971: $resulttext .= '</ul>';
12972: }
12973: }
12974: $resulttext .= '</ul>';
12975: } else {
12976: $resulttext = $nochgmsg;
12977: }
12978: } else {
12979: $resulttext = '<span class="LC_error">'.
12980: &mt('An error occurred: [_1]',$putresult).'</span>';
12981: }
12982: } else {
12983: $resulttext = $nochgmsg;
12984: }
12985: return $resulttext;
12986: }
12987:
1.150 raeburn 12988: sub modify_loadbalancing {
12989: my ($dom,%domconfig) = @_;
12990: my $primary_id = &Apache::lonnet::domain($dom,'primary');
12991: my $intdom = &Apache::lonnet::internet_dom($primary_id);
12992: my ($othertitle,$usertypes,$types) =
12993: &Apache::loncommon::sorted_inst_types($dom);
12994: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.253 raeburn 12995: my %libraryservers = &Apache::lonnet::get_servers($dom,'library');
1.150 raeburn 12996: my @sparestypes = ('primary','default');
12997: my %typetitles = &sparestype_titles();
12998: my $resulttext;
1.171 raeburn 12999: my (%currbalancer,%currtargets,%currrules,%existing);
13000: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
13001: %existing = %{$domconfig{'loadbalancing'}};
13002: }
13003: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
13004: \%currtargets,\%currrules);
13005: my ($saveloadbalancing,%defaultshash,%changes);
13006: my ($alltypes,$othertypes,$titles) =
13007: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
13008: my %ruletitles = &offloadtype_text();
13009: my @deletions = &Apache::loncommon::get_env_multiple('form.loadbalancing_delete');
13010: for (my $i=0; $i<$env{'form.loadbalancing_total'}; $i++) {
13011: my $balancer = $env{'form.loadbalancing_lonhost_'.$i};
13012: if ($balancer eq '') {
13013: next;
13014: }
1.210 raeburn 13015: if (!exists($servers{$balancer})) {
1.171 raeburn 13016: if (exists($currbalancer{$balancer})) {
13017: push(@{$changes{'delete'}},$balancer);
1.150 raeburn 13018: }
1.171 raeburn 13019: next;
13020: }
13021: if ((@deletions > 0) && (grep(/^\Q$i\E$/,@deletions))) {
13022: push(@{$changes{'delete'}},$balancer);
13023: next;
13024: }
13025: if (!exists($currbalancer{$balancer})) {
13026: push(@{$changes{'add'}},$balancer);
13027: }
13028: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'} = [];
13029: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'default'} = [];
13030: $defaultshash{'loadbalancing'}{$balancer}{'rules'} = {};
13031: unless (ref($domconfig{'loadbalancing'}) eq 'HASH') {
13032: $saveloadbalancing = 1;
13033: }
13034: foreach my $sparetype (@sparestypes) {
13035: my @targets = &Apache::loncommon::get_env_multiple('form.loadbalancing_target_'.$i.'_'.$sparetype);
13036: my @offloadto;
13037: foreach my $target (@targets) {
13038: if (($servers{$target}) && ($target ne $balancer)) {
13039: if ($sparetype eq 'default') {
13040: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}) eq 'ARRAY') {
13041: next if (grep(/^\Q$target\E$/,@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}}));
1.150 raeburn 13042: }
13043: }
1.171 raeburn 13044: unless(grep(/^\Q$target\E$/,@offloadto)) {
13045: push(@offloadto,$target);
13046: }
1.150 raeburn 13047: }
1.171 raeburn 13048: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype} = \@offloadto;
1.150 raeburn 13049: }
13050: }
1.171 raeburn 13051: if (ref($currtargets{$balancer}) eq 'HASH') {
1.150 raeburn 13052: foreach my $sparetype (@sparestypes) {
1.171 raeburn 13053: if (ref($currtargets{$balancer}{$sparetype}) eq 'ARRAY') {
13054: my @targetdiffs = &Apache::loncommon::compare_arrays($currtargets{$balancer}{$sparetype},$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype});
1.150 raeburn 13055: if (@targetdiffs > 0) {
1.171 raeburn 13056: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 13057: }
1.171 raeburn 13058: } elsif (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
13059: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
13060: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 13061: }
13062: }
13063: }
13064: } else {
1.171 raeburn 13065: if (ref($defaultshash{'loadbalancing'}{$balancer}) eq 'HASH') {
1.210 raeburn 13066: foreach my $sparetype (@sparestypes) {
1.171 raeburn 13067: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
13068: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
13069: $changes{'curr'}{$balancer}{'targets'} = 1;
13070: }
1.150 raeburn 13071: }
13072: }
1.210 raeburn 13073: }
1.150 raeburn 13074: }
13075: my $ishomedom;
1.171 raeburn 13076: if (&Apache::lonnet::host_domain($balancer) eq $dom) {
13077: $ishomedom = 1;
1.150 raeburn 13078: }
13079: if (ref($alltypes) eq 'ARRAY') {
13080: foreach my $type (@{$alltypes}) {
13081: my $rule;
1.210 raeburn 13082: unless ((($type eq '_LC_external') || ($type eq '_LC_internetdom')) &&
1.150 raeburn 13083: (!$ishomedom)) {
1.171 raeburn 13084: $rule = $env{'form.loadbalancing_rules_'.$i.'_'.$type};
13085: }
13086: if ($rule eq 'specific') {
1.255 raeburn 13087: my $specifiedhost = $env{'form.loadbalancing_singleserver_'.$i.'_'.$type};
13088: if (exists($servers{$specifiedhost})) {
13089: $rule = $specifiedhost;
13090: }
1.150 raeburn 13091: }
1.171 raeburn 13092: $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type} = $rule;
13093: if (ref($currrules{$balancer}) eq 'HASH') {
13094: if ($rule ne $currrules{$balancer}{$type}) {
13095: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 13096: }
13097: } elsif ($rule ne '') {
1.171 raeburn 13098: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 13099: }
13100: }
13101: }
1.171 raeburn 13102: }
13103: my $nochgmsg = &mt('No changes made to Load Balancer settings.');
13104: if ((keys(%changes) > 0) || ($saveloadbalancing)) {
13105: unless (ref($defaultshash{'loadbalancing'}) eq 'HASH') {
13106: $defaultshash{'loadbalancing'} = {};
13107: }
13108: my $putresult = &Apache::lonnet::put_dom('configuration',
13109: \%defaultshash,$dom);
13110: if ($putresult eq 'ok') {
13111: if (keys(%changes) > 0) {
1.252 raeburn 13112: my %toupdate;
1.171 raeburn 13113: if (ref($changes{'delete'}) eq 'ARRAY') {
13114: foreach my $balancer (sort(@{$changes{'delete'}})) {
13115: $resulttext .= '<li>'.&mt('Load Balancing discontinued for: [_1]',$balancer).'</li>';
1.252 raeburn 13116: $toupdate{$balancer} = 1;
1.150 raeburn 13117: }
1.171 raeburn 13118: }
13119: if (ref($changes{'add'}) eq 'ARRAY') {
1.210 raeburn 13120: foreach my $balancer (sort(@{$changes{'add'}})) {
1.171 raeburn 13121: $resulttext .= '<li>'.&mt('Load Balancing enabled for: [_1]',$balancer);
1.252 raeburn 13122: $toupdate{$balancer} = 1;
1.171 raeburn 13123: }
13124: }
13125: if (ref($changes{'curr'}) eq 'HASH') {
13126: foreach my $balancer (sort(keys(%{$changes{'curr'}}))) {
1.253 raeburn 13127: $toupdate{$balancer} = 1;
1.171 raeburn 13128: if (ref($changes{'curr'}{$balancer}) eq 'HASH') {
13129: if ($changes{'curr'}{$balancer}{'targets'}) {
13130: my %offloadstr;
13131: foreach my $sparetype (@sparestypes) {
13132: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
13133: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
13134: $offloadstr{$sparetype} = join(', ',@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
13135: }
13136: }
1.150 raeburn 13137: }
1.171 raeburn 13138: if (keys(%offloadstr) == 0) {
13139: $resulttext .= '<li>'.&mt("Servers to which Load Balance server offloads set to 'None', by default").'</li>';
1.150 raeburn 13140: } else {
1.171 raeburn 13141: my $showoffload;
13142: foreach my $sparetype (@sparestypes) {
13143: $showoffload .= '<i>'.$typetitles{$sparetype}.'</i>: ';
13144: if (defined($offloadstr{$sparetype})) {
13145: $showoffload .= $offloadstr{$sparetype};
13146: } else {
13147: $showoffload .= &mt('None');
13148: }
13149: $showoffload .= (' 'x3);
13150: }
13151: $resulttext .= '<li>'.&mt('By default, Load Balancer: [_1] set to offload to - [_2]',$balancer,$showoffload).'</li>';
1.150 raeburn 13152: }
13153: }
13154: }
1.171 raeburn 13155: if (ref($changes{'curr'}{$balancer}{'rules'}) eq 'HASH') {
13156: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
13157: foreach my $type (@{$alltypes}) {
13158: if ($changes{'curr'}{$balancer}{'rules'}{$type}) {
13159: my $rule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
13160: my $balancetext;
13161: if ($rule eq '') {
13162: $balancetext = $ruletitles{'default'};
1.209 raeburn 13163: } elsif (($rule eq 'homeserver') || ($rule eq 'externalbalancer') ||
1.254 raeburn 13164: ($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
13165: if (($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
1.252 raeburn 13166: foreach my $sparetype (@sparestypes) {
13167: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
13168: map { $toupdate{$_} = 1; } (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
13169: }
13170: }
1.253 raeburn 13171: foreach my $item (@{$alltypes}) {
13172: next if ($item =~ /^_LC_ipchange/);
13173: my $hasrule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$item};
13174: if ($hasrule eq 'homeserver') {
13175: map { $toupdate{$_} = 1; } (keys(%libraryservers));
13176: } else {
13177: unless (($hasrule eq 'default') || ($hasrule eq 'none') || ($hasrule eq 'externalbalancer')) {
13178: if ($servers{$hasrule}) {
13179: $toupdate{$hasrule} = 1;
13180: }
13181: }
13182: }
13183: }
1.254 raeburn 13184: if (($rule eq 'balancer') || ($rule eq 'offloadedto')) {
13185: $balancetext = $ruletitles{$rule};
13186: } else {
13187: my $receiver = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
13188: $balancetext = $ruletitles{'particular'}.' '.$receiver;
13189: if ($receiver) {
13190: $toupdate{$receiver};
13191: }
13192: }
13193: } else {
13194: $balancetext = $ruletitles{$rule};
1.252 raeburn 13195: }
1.171 raeburn 13196: } else {
13197: $balancetext = &mt('offload to [_1]',$defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type});
13198: }
1.210 raeburn 13199: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- balancing for [_2] set to - "[_3]"',$balancer,$titles->{$type},$balancetext).'</li>';
1.150 raeburn 13200: }
13201: }
13202: }
13203: }
1.252 raeburn 13204: if (keys(%toupdate)) {
13205: my %thismachine;
13206: my $updatedhere;
13207: my $cachetime = 60*60*24;
13208: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
13209: foreach my $lonhost (keys(%toupdate)) {
13210: if ($thismachine{$lonhost}) {
13211: unless ($updatedhere) {
13212: &Apache::lonnet::do_cache_new('loadbalancing',$dom,
13213: $defaultshash{'loadbalancing'},
13214: $cachetime);
13215: $updatedhere = 1;
13216: }
13217: } else {
13218: my $cachekey = &escape('loadbalancing').':'.&escape($dom);
13219: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
13220: }
13221: }
13222: }
1.150 raeburn 13223: }
1.171 raeburn 13224: }
13225: if ($resulttext ne '') {
13226: $resulttext = &mt('Changes made:').'<ul>'.$resulttext.'</ul>';
1.150 raeburn 13227: } else {
13228: $resulttext = $nochgmsg;
13229: }
13230: } else {
1.171 raeburn 13231: $resulttext = $nochgmsg;
1.150 raeburn 13232: }
13233: } else {
1.171 raeburn 13234: $resulttext = '<span class="LC_error">'.
13235: &mt('An error occurred: [_1]',$putresult).'</span>';
1.150 raeburn 13236: }
13237: } else {
1.171 raeburn 13238: $resulttext = $nochgmsg;
1.150 raeburn 13239: }
13240: return $resulttext;
13241: }
13242:
1.48 raeburn 13243: sub recurse_check {
13244: my ($chkcats,$categories,$depth,$name) = @_;
13245: if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
13246: my $chg = 0;
13247: for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
13248: my $category = $chkcats->[$depth]{$name}[$j];
13249: my $item;
13250: if ($category eq '') {
13251: $chg ++;
13252: } else {
13253: my $deeper = $depth + 1;
13254: $item = &escape($category).':'.&escape($name).':'.$depth;
13255: if ($chg) {
13256: $categories->{$item} -= $chg;
13257: }
13258: &recurse_check($chkcats,$categories,$deeper,$category);
13259: $deeper --;
13260: }
13261: }
13262: }
13263: return;
13264: }
13265:
13266: sub recurse_cat_deletes {
13267: my ($item,$coursecategories,$deletions) = @_;
13268: my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
13269: my $subdepth = $depth + 1;
13270: if (ref($coursecategories) eq 'HASH') {
13271: foreach my $subitem (keys(%{$coursecategories})) {
13272: my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
13273: if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
13274: delete($coursecategories->{$subitem});
13275: $deletions->{$subitem} = 1;
13276: &recurse_cat_deletes($subitem,$coursecategories,$deletions);
1.168 raeburn 13277: }
1.48 raeburn 13278: }
13279: }
13280: return;
13281: }
13282:
1.125 raeburn 13283: sub get_active_dcs {
13284: my ($dom) = @_;
1.191 raeburn 13285: my $now = time;
13286: my %dompersonnel = &Apache::lonnet::get_domain_roles($dom,['dc'],$now,$now);
1.125 raeburn 13287: my %domcoords;
13288: my $numdcs = 0;
13289: foreach my $server (keys(%dompersonnel)) {
13290: foreach my $user (sort(keys(%{$dompersonnel{$server}}))) {
13291: my ($trole,$uname,$udom,$runame,$rudom,$rsec) = split(/:/,$user);
1.191 raeburn 13292: $domcoords{$uname.':'.$udom} = $dompersonnel{$server}{$user};
1.125 raeburn 13293: }
13294: }
13295: return %domcoords;
13296: }
13297:
13298: sub active_dc_picker {
1.191 raeburn 13299: my ($dom,$numinrow,$inputtype,$name,%currhash) = @_;
1.235 raeburn 13300: my %domcoords = &get_active_dcs($dom);
1.191 raeburn 13301: my @domcoord = keys(%domcoords);
13302: if (keys(%currhash)) {
13303: foreach my $dc (keys(%currhash)) {
13304: unless (exists($domcoords{$dc})) {
13305: push(@domcoord,$dc);
13306: }
13307: }
13308: }
13309: @domcoord = sort(@domcoord);
1.210 raeburn 13310: my $numdcs = scalar(@domcoord);
1.191 raeburn 13311: my $rows = 0;
13312: my $table;
1.125 raeburn 13313: if ($numdcs > 1) {
1.191 raeburn 13314: $table = '<table>';
13315: for (my $i=0; $i<@domcoord; $i++) {
1.125 raeburn 13316: my $rem = $i%($numinrow);
13317: if ($rem == 0) {
13318: if ($i > 0) {
1.191 raeburn 13319: $table .= '</tr>';
1.125 raeburn 13320: }
1.191 raeburn 13321: $table .= '<tr>';
13322: $rows ++;
1.125 raeburn 13323: }
1.191 raeburn 13324: my $check = '';
13325: if ($inputtype eq 'radio') {
13326: if (keys(%currhash) == 0) {
13327: if (!$i) {
13328: $check = ' checked="checked"';
13329: }
13330: } elsif (exists($currhash{$domcoord[$i]})) {
13331: $check = ' checked="checked"';
13332: }
13333: } else {
13334: if (exists($currhash{$domcoord[$i]})) {
13335: $check = ' checked="checked"';
1.125 raeburn 13336: }
13337: }
1.191 raeburn 13338: if ($i == @domcoord - 1) {
1.125 raeburn 13339: my $colsleft = $numinrow - $rem;
13340: if ($colsleft > 1) {
1.191 raeburn 13341: $table .= '<td class="LC_left_item" colspan="'.$colsleft.'">';
1.125 raeburn 13342: } else {
1.191 raeburn 13343: $table .= '<td class="LC_left_item">';
1.125 raeburn 13344: }
13345: } else {
1.191 raeburn 13346: $table .= '<td class="LC_left_item">';
13347: }
13348: my ($dcname,$dcdom) = split(':',$domcoord[$i]);
13349: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
13350: $table .= '<span class="LC_nobreak"><label>'.
13351: '<input type="'.$inputtype.'" name="'.$name.'"'.
13352: ' value="'.$domcoord[$i].'"'.$check.' />'.$user;
13353: if ($user ne $dcname.':'.$dcdom) {
1.219 raeburn 13354: $table .= ' ('.$dcname.':'.$dcdom.')';
1.191 raeburn 13355: }
1.219 raeburn 13356: $table .= '</label></span></td>';
1.191 raeburn 13357: }
13358: $table .= '</tr></table>';
13359: } elsif ($numdcs == 1) {
1.219 raeburn 13360: my ($dcname,$dcdom) = split(':',$domcoord[0]);
13361: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
1.191 raeburn 13362: if ($inputtype eq 'radio') {
1.247 raeburn 13363: $table = '<input type="hidden" name="'.$name.'" value="'.$domcoord[0].'" />'.$user;
1.219 raeburn 13364: if ($user ne $dcname.':'.$dcdom) {
13365: $table .= ' ('.$dcname.':'.$dcdom.')';
13366: }
1.191 raeburn 13367: } else {
13368: my $check;
13369: if (exists($currhash{$domcoord[0]})) {
13370: $check = ' checked="checked"';
1.125 raeburn 13371: }
1.247 raeburn 13372: $table = '<span class="LC_nobreak"><label>'.
13373: '<input type="checkbox" name="'.$name.'" '.
13374: 'value="'.$domcoord[0].'"'.$check.' />'.$user;
1.219 raeburn 13375: if ($user ne $dcname.':'.$dcdom) {
1.220 raeburn 13376: $table .= ' ('.$dcname.':'.$dcdom.')';
1.219 raeburn 13377: }
1.220 raeburn 13378: $table .= '</label></span>';
1.191 raeburn 13379: $rows ++;
1.125 raeburn 13380: }
13381: }
1.191 raeburn 13382: return ($numdcs,$table,$rows);
1.125 raeburn 13383: }
13384:
1.137 raeburn 13385: sub usersession_titles {
13386: return &Apache::lonlocal::texthash(
13387: hosted => 'Hosting of sessions for users from other domains on servers in this domain',
13388: remote => 'Hosting of sessions for users in this domain on servers in other domains',
1.145 raeburn 13389: spares => 'Servers offloaded to, when busy',
1.137 raeburn 13390: version => 'LON-CAPA version requirement',
1.138 raeburn 13391: excludedomain => 'Allow all, but exclude specific domains',
13392: includedomain => 'Deny all, but include specific domains',
1.145 raeburn 13393: primary => 'Primary (checked first)',
1.154 raeburn 13394: default => 'Default',
1.137 raeburn 13395: );
13396: }
13397:
1.152 raeburn 13398: sub id_for_thisdom {
13399: my (%servers) = @_;
13400: my %altids;
13401: foreach my $server (keys(%servers)) {
13402: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
13403: if ($serverhome ne $server) {
13404: $altids{$serverhome} = $server;
13405: }
13406: }
13407: return %altids;
13408: }
13409:
1.150 raeburn 13410: sub count_servers {
13411: my ($currbalancer,%servers) = @_;
13412: my (@spares,$numspares);
13413: foreach my $lonhost (sort(keys(%servers))) {
13414: next if ($currbalancer eq $lonhost);
13415: push(@spares,$lonhost);
13416: }
13417: if ($currbalancer) {
13418: $numspares = scalar(@spares);
13419: } else {
13420: $numspares = scalar(@spares) - 1;
13421: }
13422: return ($numspares,@spares);
13423: }
13424:
13425: sub lonbalance_targets_js {
1.171 raeburn 13426: my ($dom,$types,$servers,$settings) = @_;
1.150 raeburn 13427: my $select = &mt('Select');
13428: my ($alltargets,$allishome,$allinsttypes,@alltypes);
13429: if (ref($servers) eq 'HASH') {
13430: $alltargets = join("','",sort(keys(%{$servers})));
13431: my @homedoms;
13432: foreach my $server (sort(keys(%{$servers}))) {
13433: if (&Apache::lonnet::host_domain($server) eq $dom) {
13434: push(@homedoms,'1');
13435: } else {
13436: push(@homedoms,'0');
13437: }
13438: }
13439: $allishome = join("','",@homedoms);
13440: }
13441: if (ref($types) eq 'ARRAY') {
13442: if (@{$types} > 0) {
13443: @alltypes = @{$types};
13444: }
13445: }
13446: push(@alltypes,'default','_LC_adv','_LC_author','_LC_internetdom','_LC_external');
13447: $allinsttypes = join("','",@alltypes);
1.171 raeburn 13448: my (%currbalancer,%currtargets,%currrules,%existing);
13449: if (ref($settings) eq 'HASH') {
13450: %existing = %{$settings};
13451: }
13452: &get_loadbalancers_config($servers,\%existing,\%currbalancer,
13453: \%currtargets,\%currrules);
1.210 raeburn 13454: my $balancers = join("','",sort(keys(%currbalancer)));
1.150 raeburn 13455: return <<"END";
13456:
13457: <script type="text/javascript">
13458: // <![CDATA[
13459:
1.171 raeburn 13460: currBalancers = new Array('$balancers');
13461:
13462: function toggleTargets(balnum) {
13463: var lonhostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
13464: var prevhostitem = document.getElementById('loadbalancing_prevlonhost_'+balnum);
13465: var balancer = lonhostitem.options[lonhostitem.selectedIndex].value;
13466: var prevbalancer = prevhostitem.value;
13467: var baltotal = document.getElementById('loadbalancing_total').value;
13468: prevhostitem.value = balancer;
13469: if (prevbalancer != '') {
13470: var prevIdx = currBalancers.indexOf(prevbalancer);
13471: if (prevIdx != -1) {
13472: currBalancers.splice(prevIdx,1);
13473: }
13474: }
1.150 raeburn 13475: if (balancer == '') {
1.171 raeburn 13476: hideSpares(balnum);
1.150 raeburn 13477: } else {
1.171 raeburn 13478: var currIdx = currBalancers.indexOf(balancer);
13479: if (currIdx == -1) {
13480: currBalancers.push(balancer);
13481: }
1.150 raeburn 13482: var homedoms = new Array('$allishome');
1.171 raeburn 13483: var ishomedom = homedoms[lonhostitem.selectedIndex];
13484: showSpares(balancer,ishomedom,balnum);
1.150 raeburn 13485: }
1.171 raeburn 13486: balancerChange(balnum,baltotal,'change',prevbalancer,balancer);
1.150 raeburn 13487: return;
13488: }
13489:
1.171 raeburn 13490: function showSpares(balancer,ishomedom,balnum) {
1.150 raeburn 13491: var alltargets = new Array('$alltargets');
13492: var insttypes = new Array('$allinsttypes');
1.151 raeburn 13493: var offloadtypes = new Array('primary','default');
13494:
1.171 raeburn 13495: document.getElementById('loadbalancing_targets_'+balnum).style.display='block';
13496: document.getElementById('loadbalancing_disabled_'+balnum).style.display='none';
1.152 raeburn 13497:
1.151 raeburn 13498: for (var i=0; i<offloadtypes.length; i++) {
13499: var count = 0;
13500: for (var j=0; j<alltargets.length; j++) {
13501: if (alltargets[j] != balancer) {
1.171 raeburn 13502: var item = document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+count);
13503: item.value = alltargets[j];
13504: item.style.textAlign='left';
13505: item.style.textFace='normal';
13506: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+count).innerHTML = alltargets[j];
13507: if (currBalancers.indexOf(alltargets[j]) == -1) {
13508: item.disabled = '';
13509: } else {
13510: item.disabled = 'disabled';
13511: item.checked = false;
13512: }
1.151 raeburn 13513: count ++;
13514: }
1.150 raeburn 13515: }
13516: }
1.151 raeburn 13517: for (var k=0; k<insttypes.length; k++) {
13518: if ((insttypes[k] == '_LC_external') || (insttypes[k] == '_LC_internetdom')) {
1.150 raeburn 13519: if (ishomedom == 1) {
1.171 raeburn 13520: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
13521: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 13522: } else {
1.171 raeburn 13523: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
13524: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.150 raeburn 13525: }
13526: } else {
1.171 raeburn 13527: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
13528: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 13529: }
1.151 raeburn 13530: if ((insttypes[k] != '_LC_external') &&
13531: ((insttypes[k] != '_LC_internetdom') ||
13532: ((insttypes[k] == '_LC_internetdom') && (ishomedom == 1)))) {
1.171 raeburn 13533: var item = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]);
13534: item.options.length = 0;
13535: item.options[0] = new Option("","",true,true);
1.210 raeburn 13536: var idx = 0;
1.151 raeburn 13537: for (var m=0; m<alltargets.length; m++) {
1.171 raeburn 13538: if ((currBalancers.indexOf(alltargets[m]) == -1) && (alltargets[m] != balancer)) {
13539: idx ++;
13540: item.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
1.150 raeburn 13541: }
13542: }
13543: }
13544: }
13545: return;
13546: }
13547:
1.171 raeburn 13548: function hideSpares(balnum) {
1.150 raeburn 13549: var alltargets = new Array('$alltargets');
13550: var insttypes = new Array('$allinsttypes');
13551: var offloadtypes = new Array('primary','default');
13552:
1.171 raeburn 13553: document.getElementById('loadbalancing_targets_'+balnum).style.display='none';
13554: document.getElementById('loadbalancing_disabled_'+balnum).style.display='block';
1.150 raeburn 13555:
13556: var total = alltargets.length - 1;
13557: for (var i=0; i<offloadtypes; i++) {
13558: for (var j=0; j<total; j++) {
1.171 raeburn 13559: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).checked = false;
13560: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).value = '';
13561: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+j).innerHTML = '';
1.151 raeburn 13562: }
1.150 raeburn 13563: }
13564: for (var k=0; k<insttypes.length; k++) {
1.171 raeburn 13565: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
13566: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.151 raeburn 13567: if (insttypes[k] != '_LC_external') {
1.171 raeburn 13568: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).length = 0;
13569: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).options[0] = new Option("","",true,true);
1.150 raeburn 13570: }
13571: }
13572: return;
13573: }
13574:
1.171 raeburn 13575: function checkOffloads(item,balnum,type) {
1.150 raeburn 13576: var alltargets = new Array('$alltargets');
13577: var offloadtypes = new Array('primary','default');
13578: if (item.checked) {
13579: var total = alltargets.length - 1;
13580: var other;
13581: if (type == offloadtypes[0]) {
1.151 raeburn 13582: other = offloadtypes[1];
1.150 raeburn 13583: } else {
1.151 raeburn 13584: other = offloadtypes[0];
1.150 raeburn 13585: }
13586: for (var i=0; i<total; i++) {
1.171 raeburn 13587: var server = document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).value;
1.150 raeburn 13588: if (server == item.value) {
1.171 raeburn 13589: if (document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked) {
13590: document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked = false;
1.150 raeburn 13591: }
13592: }
13593: }
13594: }
13595: return;
13596: }
13597:
1.171 raeburn 13598: function singleServerToggle(balnum,type) {
13599: var offloadtoSelIdx = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex;
1.150 raeburn 13600: if (offloadtoSelIdx == 0) {
1.171 raeburn 13601: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_0').checked = true;
13602: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 13603:
13604: } else {
1.171 raeburn 13605: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_2').checked = true;
13606: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
1.150 raeburn 13607: }
13608: return;
13609: }
13610:
1.171 raeburn 13611: function balanceruleChange(formname,balnum,type) {
1.150 raeburn 13612: if (type == '_LC_external') {
1.171 raeburn 13613: return;
1.150 raeburn 13614: }
1.171 raeburn 13615: var typesRules = getIndicesByName(formname,'loadbalancing_rules_'+balnum+'_'+type);
1.150 raeburn 13616: for (var i=0; i<typesRules.length; i++) {
13617: if (formname.elements[typesRules[i]].checked) {
13618: if (formname.elements[typesRules[i]].value != 'specific') {
1.171 raeburn 13619: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex = 0;
13620: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 13621: } else {
1.171 raeburn 13622: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
13623: }
13624: }
13625: }
13626: return;
13627: }
13628:
13629: function balancerDeleteChange(balnum) {
13630: var hostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
13631: var baltotal = document.getElementById('loadbalancing_total').value;
13632: var addtarget;
13633: var removetarget;
13634: var action = 'delete';
13635: if (document.getElementById('loadbalancing_delete_'+balnum)) {
13636: var lonhost = hostitem.value;
13637: var currIdx = currBalancers.indexOf(lonhost);
13638: if (document.getElementById('loadbalancing_delete_'+balnum).checked) {
13639: if (currIdx != -1) {
13640: currBalancers.splice(currIdx,1);
13641: }
13642: addtarget = lonhost;
13643: } else {
13644: if (currIdx == -1) {
13645: currBalancers.push(lonhost);
13646: }
13647: removetarget = lonhost;
13648: action = 'undelete';
13649: }
13650: balancerChange(balnum,baltotal,action,addtarget,removetarget);
13651: }
13652: return;
13653: }
13654:
13655: function balancerChange(balnum,baltotal,action,addtarget,removetarget) {
13656: if (baltotal > 1) {
13657: var offloadtypes = new Array('primary','default');
13658: var alltargets = new Array('$alltargets');
13659: var insttypes = new Array('$allinsttypes');
13660: for (var i=0; i<baltotal; i++) {
13661: if (i != balnum) {
13662: for (var j=0; j<offloadtypes.length; j++) {
13663: var total = alltargets.length - 1;
13664: for (var k=0; k<total; k++) {
13665: var serveritem = document.getElementById('loadbalancing_target_'+i+'_'+offloadtypes[j]+'_'+k);
13666: var server = serveritem.value;
13667: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
13668: if (server == addtarget) {
13669: serveritem.disabled = '';
13670: }
13671: }
13672: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
13673: if (server == removetarget) {
13674: serveritem.disabled = 'disabled';
13675: serveritem.checked = false;
13676: }
13677: }
13678: }
13679: }
13680: for (var j=0; j<insttypes.length; j++) {
13681: if (insttypes[j] != '_LC_external') {
13682: if (document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j])) {
13683: var singleserver = document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j]);
13684: var currSel = singleserver.selectedIndex;
13685: var currVal = singleserver.options[currSel].value;
13686: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
13687: var numoptions = singleserver.options.length;
13688: var needsnew = 1;
13689: for (var k=0; k<numoptions; k++) {
13690: if (singleserver.options[k] == addtarget) {
13691: needsnew = 0;
13692: break;
13693: }
13694: }
13695: if (needsnew == 1) {
13696: singleserver.options[numoptions] = new Option(addtarget,addtarget,false,false);
13697: }
13698: }
13699: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
13700: singleserver.options.length = 0;
13701: if ((currVal) && (currVal != removetarget)) {
13702: singleserver.options[0] = new Option("","",false,false);
13703: } else {
13704: singleserver.options[0] = new Option("","",true,true);
13705: }
13706: var idx = 0;
13707: for (var m=0; m<alltargets.length; m++) {
13708: if (currBalancers.indexOf(alltargets[m]) == -1) {
13709: idx ++;
13710: if (currVal == alltargets[m]) {
13711: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],true,true);
13712: } else {
13713: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
13714: }
13715: }
13716: }
13717: }
13718: }
13719: }
13720: }
1.150 raeburn 13721: }
13722: }
13723: }
13724: return;
13725: }
13726:
1.152 raeburn 13727: // ]]>
13728: </script>
13729:
13730: END
13731: }
13732:
13733: sub new_spares_js {
13734: my @sparestypes = ('primary','default');
13735: my $types = join("','",@sparestypes);
13736: my $select = &mt('Select');
13737: return <<"END";
13738:
13739: <script type="text/javascript">
13740: // <![CDATA[
13741:
13742: function updateNewSpares(formname,lonhost) {
13743: var types = new Array('$types');
13744: var include = new Array();
13745: var exclude = new Array();
13746: for (var i=0; i<types.length; i++) {
13747: var spareboxes = getIndicesByName(formname,'spare_'+types[i]+'_'+lonhost);
13748: for (var j=0; j<spareboxes.length; j++) {
13749: if (formname.elements[spareboxes[j]].checked) {
13750: exclude.push(formname.elements[spareboxes[j]].value);
13751: } else {
13752: include.push(formname.elements[spareboxes[j]].value);
13753: }
13754: }
13755: }
13756: for (var i=0; i<types.length; i++) {
13757: var newSpare = document.getElementById('newspare_'+types[i]+'_'+lonhost);
13758: var selIdx = newSpare.selectedIndex;
13759: var currnew = newSpare.options[selIdx].value;
13760: var okSpares = new Array();
13761: for (var j=0; j<newSpare.options.length; j++) {
13762: var possible = newSpare.options[j].value;
13763: if (possible != '') {
13764: if (exclude.indexOf(possible) == -1) {
13765: okSpares.push(possible);
13766: } else {
13767: if (currnew == possible) {
13768: selIdx = 0;
13769: }
13770: }
13771: }
13772: }
13773: for (var k=0; k<include.length; k++) {
13774: if (okSpares.indexOf(include[k]) == -1) {
13775: okSpares.push(include[k]);
13776: }
13777: }
13778: okSpares.sort();
13779: newSpare.options.length = 0;
13780: if (selIdx == 0) {
13781: newSpare.options[0] = new Option("$select","",true,true);
13782: } else {
13783: newSpare.options[0] = new Option("$select","",false,false);
13784: }
13785: for (var m=0; m<okSpares.length; m++) {
13786: var idx = m+1;
13787: var selThis = 0;
13788: if (selIdx != 0) {
13789: if (okSpares[m] == currnew) {
13790: selThis = 1;
13791: }
13792: }
13793: if (selThis == 1) {
13794: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],true,true);
13795: } else {
13796: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],false,false);
13797: }
13798: }
13799: }
13800: return;
13801: }
13802:
13803: function checkNewSpares(lonhost,type) {
13804: var newSpare = document.getElementById('newspare_'+type+'_'+lonhost);
13805: var chosen = newSpare.options[newSpare.selectedIndex].value;
13806: if (chosen != '') {
13807: var othertype;
13808: var othernewSpare;
13809: if (type == 'primary') {
13810: othernewSpare = document.getElementById('newspare_default_'+lonhost);
13811: }
13812: if (type == 'default') {
13813: othernewSpare = document.getElementById('newspare_primary_'+lonhost);
13814: }
13815: if (othernewSpare.options[othernewSpare.selectedIndex].value == chosen) {
13816: othernewSpare.selectedIndex = 0;
13817: }
13818: }
13819: return;
13820: }
13821:
13822: // ]]>
13823: </script>
13824:
13825: END
13826:
13827: }
13828:
13829: sub common_domprefs_js {
13830: return <<"END";
13831:
13832: <script type="text/javascript">
13833: // <![CDATA[
13834:
1.150 raeburn 13835: function getIndicesByName(formname,item) {
1.152 raeburn 13836: var group = new Array();
1.150 raeburn 13837: for (var i=0;i<formname.elements.length;i++) {
13838: if (formname.elements[i].name == item) {
1.152 raeburn 13839: group.push(formname.elements[i].id);
1.150 raeburn 13840: }
13841: }
1.152 raeburn 13842: return group;
1.150 raeburn 13843: }
13844:
13845: // ]]>
13846: </script>
13847:
13848: END
1.152 raeburn 13849:
1.150 raeburn 13850: }
13851:
1.165 raeburn 13852: sub recaptcha_js {
13853: my %lt = &captcha_phrases();
13854: return <<"END";
13855:
13856: <script type="text/javascript">
13857: // <![CDATA[
13858:
13859: function updateCaptcha(caller,context) {
13860: var privitem;
13861: var pubitem;
13862: var privtext;
13863: var pubtext;
1.269 raeburn 13864: var versionitem;
13865: var versiontext;
1.165 raeburn 13866: if (document.getElementById(context+'_recaptchapub')) {
13867: pubitem = document.getElementById(context+'_recaptchapub');
13868: } else {
13869: return;
13870: }
13871: if (document.getElementById(context+'_recaptchapriv')) {
13872: privitem = document.getElementById(context+'_recaptchapriv');
13873: } else {
13874: return;
13875: }
13876: if (document.getElementById(context+'_recaptchapubtxt')) {
13877: pubtext = document.getElementById(context+'_recaptchapubtxt');
13878: } else {
13879: return;
13880: }
13881: if (document.getElementById(context+'_recaptchaprivtxt')) {
13882: privtext = document.getElementById(context+'_recaptchaprivtxt');
13883: } else {
13884: return;
13885: }
1.269 raeburn 13886: if (document.getElementById(context+'_recaptchaversion')) {
13887: versionitem = document.getElementById(context+'_recaptchaversion');
13888: } else {
13889: return;
13890: }
13891: if (document.getElementById(context+'_recaptchavertxt')) {
13892: versiontext = document.getElementById(context+'_recaptchavertxt');
13893: } else {
13894: return;
13895: }
1.165 raeburn 13896: if (caller.checked) {
13897: if (caller.value == 'recaptcha') {
13898: pubitem.type = 'text';
13899: privitem.type = 'text';
13900: pubitem.size = '40';
13901: privitem.size = '40';
13902: pubtext.innerHTML = "$lt{'pub'}";
13903: privtext.innerHTML = "$lt{'priv'}";
1.269 raeburn 13904: versionitem.type = 'text';
13905: versionitem.size = '3';
13906: versiontext.innerHTML = "$lt{'ver'}";
1.165 raeburn 13907: } else {
13908: pubitem.type = 'hidden';
13909: privitem.type = 'hidden';
1.269 raeburn 13910: versionitem.type = 'hidden';
1.165 raeburn 13911: pubtext.innerHTML = '';
13912: privtext.innerHTML = '';
1.269 raeburn 13913: versiontext.innerHTML = '';
1.165 raeburn 13914: }
13915: }
13916: return;
13917: }
13918:
13919: // ]]>
13920: </script>
13921:
13922: END
13923:
13924: }
13925:
1.236 raeburn 13926: sub toggle_display_js {
1.192 raeburn 13927: return <<"END";
13928:
13929: <script type="text/javascript">
13930: // <![CDATA[
13931:
1.236 raeburn 13932: function toggleDisplay(domForm,caller) {
13933: if (document.getElementById(caller)) {
13934: var divitem = document.getElementById(caller);
13935: var optionsElement = domForm.coursecredits;
1.264 raeburn 13936: var checkval = 1;
13937: var dispval = 'block';
1.236 raeburn 13938: if (caller == 'emailoptions') {
13939: optionsElement = domForm.cancreate_email;
13940: }
1.257 raeburn 13941: if (caller == 'studentsubmission') {
13942: optionsElement = domForm.postsubmit;
13943: }
1.264 raeburn 13944: if (caller == 'cloneinstcode') {
13945: optionsElement = domForm.canclone;
13946: checkval = 'instcode';
13947: }
1.236 raeburn 13948: if (optionsElement.length) {
1.192 raeburn 13949: var currval;
1.236 raeburn 13950: for (var i=0; i<optionsElement.length; i++) {
13951: if (optionsElement[i].checked) {
13952: currval = optionsElement[i].value;
1.192 raeburn 13953: }
13954: }
1.264 raeburn 13955: if (currval == checkval) {
13956: divitem.style.display = dispval;
1.192 raeburn 13957: } else {
1.236 raeburn 13958: divitem.style.display = 'none';
1.192 raeburn 13959: }
13960: }
13961: }
13962: return;
13963: }
13964:
13965: // ]]>
13966: </script>
13967:
13968: END
13969:
13970: }
13971:
1.165 raeburn 13972: sub captcha_phrases {
13973: return &Apache::lonlocal::texthash (
13974: priv => 'Private key',
13975: pub => 'Public key',
13976: original => 'original (CAPTCHA)',
13977: recaptcha => 'successor (ReCAPTCHA)',
13978: notused => 'unused',
1.269 raeburn 13979: ver => 'ReCAPTCHA version (1 or 2)',
1.165 raeburn 13980: );
13981: }
13982:
1.205 raeburn 13983: sub devalidate_remote_domconfs {
1.212 raeburn 13984: my ($dom,$cachekeys) = @_;
13985: return unless (ref($cachekeys) eq 'HASH');
1.205 raeburn 13986: my %servers = &Apache::lonnet::internet_dom_servers($dom);
13987: my %thismachine;
13988: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
1.267 raeburn 13989: my @posscached = ('domainconfig','domdefaults','ltitools');
1.260 raeburn 13990: if (keys(%servers)) {
1.205 raeburn 13991: foreach my $server (keys(%servers)) {
13992: next if ($thismachine{$server});
1.212 raeburn 13993: my @cached;
13994: foreach my $name (@posscached) {
13995: if ($cachekeys->{$name}) {
13996: push(@cached,&escape($name).':'.&escape($dom));
13997: }
13998: }
13999: if (@cached) {
14000: &Apache::lonnet::remote_devalidate_cache($server,\@cached);
14001: }
1.205 raeburn 14002: }
14003: }
14004: return;
14005: }
14006:
1.3 raeburn 14007: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>