Annotation of loncom/interface/domainprefs.pm, revision 1.278
1.1 raeburn 1: # The LearningOnline Network with CAPA
2: # Handler to set domain-wide configuration settings
3: #
1.278 ! raeburn 4: # $Id: domainprefs.pm,v 1.277 2016/09/05 01:46:07 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.275 raeburn 221: 'ltitools','ssl'],$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.275 raeburn 227: 'ltitools','selfenrollment','usersessions','ssl');
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.150 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.267 raeburn 480: 'ltitools' =>
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.275 raeburn 488: 'ssl' =>
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.3 raeburn 500: );
1.110 raeburn 501: if (keys(%servers) > 1) {
502: $prefs{'login'} = { text => 'Log-in page options',
503: help => 'Domain_Configuration_Login_Page',
504: header => [{col1 => 'Log-in Service',
505: col2 => 'Server Setting',},
506: {col1 => 'Log-in Page Items',
1.168 raeburn 507: col2 => ''},
508: {col1 => 'Log-in Help',
1.256 raeburn 509: col2 => 'Value'},
510: {col1 => 'Custom HTML in document head',
1.168 raeburn 511: col2 => 'Value'}],
1.230 raeburn 512: print => \&print_login,
513: modify => \&modify_login,
1.110 raeburn 514: };
515: }
1.174 foxr 516:
1.6 raeburn 517: my @roles = ('student','coordinator','author','admin');
1.30 raeburn 518: my @actions = &Apache::loncommon::get_env_multiple('form.actions');
1.3 raeburn 519: &Apache::lonhtmlcommon::add_breadcrumb
1.30 raeburn 520: ({href=>"javascript:changePage(document.$phase,'pickactions')",
1.133 raeburn 521: text=>"Settings to display/modify"});
1.9 raeburn 522: my $confname = $dom.'-domainconfig';
1.174 foxr 523:
1.3 raeburn 524: if ($phase eq 'process') {
1.212 raeburn 525: my $result = &Apache::lonconfigsettings::make_changes($r,$dom,$phase,$context,\@prefs_order,
526: \%prefs,\%domconfig,$confname,\@roles);
1.224 raeburn 527: if ((ref($result) eq 'HASH') && (keys(%{$result}))) {
1.205 raeburn 528: $r->rflush();
1.212 raeburn 529: &devalidate_remote_domconfs($dom,$result);
1.205 raeburn 530: }
1.30 raeburn 531: } elsif ($phase eq 'display') {
1.192 raeburn 532: my $js = &recaptcha_js().
1.236 raeburn 533: &toggle_display_js();
1.171 raeburn 534: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
1.152 raeburn 535: my ($othertitle,$usertypes,$types) =
536: &Apache::loncommon::sorted_inst_types($dom);
1.171 raeburn 537: $js .= &lonbalance_targets_js($dom,$types,\%servers,
538: $domconfig{'loadbalancing'}).
1.170 raeburn 539: &new_spares_js().
540: &common_domprefs_js().
541: &Apache::loncommon::javascript_array_indexof();
1.152 raeburn 542: }
1.216 raeburn 543: if (grep(/^requestcourses$/,@actions)) {
544: my $javascript_validations;
545: my $coursebrowserjs=&Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'});
546: $js .= <<END;
547: <script type="text/javascript">
548: $javascript_validations
549: </script>
550: $coursebrowserjs
551: END
552: }
1.150 raeburn 553: &Apache::lonconfigsettings::display_settings($r,$dom,$phase,$context,\@prefs_order,\%prefs,\%domconfig,$confname,$js);
1.1 raeburn 554: } else {
1.180 raeburn 555: # check if domconfig user exists for the domain.
556: my $servadm = $r->dir_config('lonAdmEMail');
557: my ($configuserok,$author_ok,$switchserver) =
558: &config_check($dom,$confname,$servadm);
559: unless ($configuserok eq 'ok') {
1.181 raeburn 560: &Apache::lonconfigsettings::print_header($r,$phase,$context);
561: $r->print(&mt('The domain configuration user "[_1]" has yet to be created.',
1.210 raeburn 562: $confname).
1.181 raeburn 563: '<br />'
564: );
1.180 raeburn 565: if ($switchserver) {
1.181 raeburn 566: $r->print(&mt('Ordinarily, that domain configuration user is created when the ./UPDATE script is run to install LON-CAPA for the first time.').
567: '<br />'.
568: &mt('However, that does not apply when new domains are added to a multi-domain server, and ./UPDATE has not been run recently.').
569: '<br />'.
570: &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).
571: '<br />'.
572: &mt('To do that now, use the following link: [_1]',$switchserver)
573: );
574: } else {
575: $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.').
576: '<br />'.
577: &mt('Once that is done, you will be able to use the web-based "Set domain configuration" to configure the domain')
578: );
1.180 raeburn 579: }
580: $r->print(&Apache::loncommon::end_page());
581: return OK;
582: }
1.21 raeburn 583: if (keys(%domconfig) == 0) {
584: my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
1.29 raeburn 585: my @ids=&Apache::lonnet::current_machine_ids();
586: if (!grep(/^\Q$primarylibserv\E$/,@ids)) {
1.21 raeburn 587: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.41 raeburn 588: my @loginimages = ('img','logo','domlogo','login');
1.21 raeburn 589: my $custom_img_count = 0;
590: foreach my $img (@loginimages) {
591: if ($designhash{$dom.'.login.'.$img} ne '') {
592: $custom_img_count ++;
593: }
594: }
595: foreach my $role (@roles) {
596: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
597: $custom_img_count ++;
598: }
599: }
600: if ($custom_img_count > 0) {
1.94 raeburn 601: &Apache::lonconfigsettings::print_header($r,$phase,$context);
1.21 raeburn 602: my $switch_server = &check_switchserver($dom,$confname);
1.29 raeburn 603: $r->print(
604: &mt('Domain configuration settings have yet to be saved for this domain via the web-based domain preferences interface.').'<br />'.
605: &mt("While this remains so, you must switch to the domain's primary library server in order to update settings.").'<br /><br />'.
606: &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 />'.
607: &mt("However, you will still need to switch to the domain's primary library server to upload new images or logos.").'<br /><br />');
608: if ($switch_server) {
1.30 raeburn 609: $r->print($switch_server.' '.&mt('to primary library server for domain: [_1]',$dom));
1.29 raeburn 610: }
1.91 raeburn 611: $r->print(&Apache::loncommon::end_page());
1.21 raeburn 612: return OK;
613: }
614: }
615: }
1.91 raeburn 616: &Apache::lonconfigsettings::display_choices($r,$phase,$context,\@prefs_order,\%prefs);
1.3 raeburn 617: }
618: return OK;
619: }
620:
621: sub process_changes {
1.205 raeburn 622: my ($r,$dom,$confname,$action,$roles,$values,$lastactref) = @_;
1.92 raeburn 623: my %domconfig;
624: if (ref($values) eq 'HASH') {
625: %domconfig = %{$values};
626: }
1.3 raeburn 627: my $output;
628: if ($action eq 'login') {
1.205 raeburn 629: $output = &modify_login($r,$dom,$confname,$lastactref,%domconfig);
1.6 raeburn 630: } elsif ($action eq 'rolecolors') {
1.9 raeburn 631: $output = &modify_rolecolors($r,$dom,$confname,$roles,
1.205 raeburn 632: $lastactref,%domconfig);
1.3 raeburn 633: } elsif ($action eq 'quotas') {
1.216 raeburn 634: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.3 raeburn 635: } elsif ($action eq 'autoenroll') {
1.205 raeburn 636: $output = &modify_autoenroll($dom,$lastactref,%domconfig);
1.3 raeburn 637: } elsif ($action eq 'autoupdate') {
638: $output = &modify_autoupdate($dom,%domconfig);
1.125 raeburn 639: } elsif ($action eq 'autocreate') {
640: $output = &modify_autocreate($dom,%domconfig);
1.23 raeburn 641: } elsif ($action eq 'directorysrch') {
642: $output = &modify_directorysrch($dom,%domconfig);
1.27 raeburn 643: } elsif ($action eq 'usercreation') {
1.28 raeburn 644: $output = &modify_usercreation($dom,%domconfig);
1.224 raeburn 645: } elsif ($action eq 'selfcreation') {
646: $output = &modify_selfcreation($dom,%domconfig);
1.33 raeburn 647: } elsif ($action eq 'usermodification') {
648: $output = &modify_usermodification($dom,%domconfig);
1.28 raeburn 649: } elsif ($action eq 'contacts') {
1.205 raeburn 650: $output = &modify_contacts($dom,$lastactref,%domconfig);
1.43 raeburn 651: } elsif ($action eq 'defaults') {
1.212 raeburn 652: $output = &modify_defaults($dom,$lastactref,%domconfig);
1.46 raeburn 653: } elsif ($action eq 'scantron') {
1.205 raeburn 654: $output = &modify_scantron($r,$dom,$confname,$lastactref,%domconfig);
1.48 raeburn 655: } elsif ($action eq 'coursecategories') {
1.239 raeburn 656: $output = &modify_coursecategories($dom,$lastactref,%domconfig);
1.69 raeburn 657: } elsif ($action eq 'serverstatuses') {
658: $output = &modify_serverstatuses($dom,%domconfig);
1.86 raeburn 659: } elsif ($action eq 'requestcourses') {
1.216 raeburn 660: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.163 raeburn 661: } elsif ($action eq 'requestauthor') {
1.216 raeburn 662: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.118 jms 663: } elsif ($action eq 'helpsettings') {
1.122 jms 664: $output = &modify_helpsettings($r,$dom,$confname,%domconfig);
1.121 raeburn 665: } elsif ($action eq 'coursedefaults') {
1.212 raeburn 666: $output = &modify_coursedefaults($dom,$lastactref,%domconfig);
1.231 raeburn 667: } elsif ($action eq 'selfenrollment') {
668: $output = &modify_selfenrollment($dom,$lastactref,%domconfig)
1.137 raeburn 669: } elsif ($action eq 'usersessions') {
1.212 raeburn 670: $output = &modify_usersessions($dom,$lastactref,%domconfig);
1.150 raeburn 671: } elsif ($action eq 'loadbalancing') {
672: $output = &modify_loadbalancing($dom,%domconfig);
1.267 raeburn 673: } elsif ($action eq 'ltitools') {
674: $output = &modify_ltitools($r,$dom,$action,$lastactref,%domconfig);
1.275 raeburn 675: } elsif ($action eq 'ssl') {
676: $output = &modify_ssl($dom,$lastactref,%domconfig);
1.3 raeburn 677: }
678: return $output;
679: }
680:
681: sub print_config_box {
1.9 raeburn 682: my ($r,$dom,$confname,$phase,$action,$item,$settings) = @_;
1.30 raeburn 683: my $rowtotal = 0;
1.49 raeburn 684: my $output;
685: if ($action eq 'coursecategories') {
686: $output = &coursecategories_javascript($settings);
1.236 raeburn 687: } elsif ($action eq 'defaults') {
688: $output = &defaults_javascript($settings);
1.91 raeburn 689: }
1.236 raeburn 690: $output .=
1.30 raeburn 691: '<table class="LC_nested_outer">
1.3 raeburn 692: <tr>
1.66 raeburn 693: <th align="left" valign="middle"><span class="LC_nobreak">'.
694: &mt($item->{text}).' '.
695: &Apache::loncommon::help_open_topic($item->{'help'}).'</span></th>'."\n".
696: '</tr>';
1.30 raeburn 697: $rowtotal ++;
1.110 raeburn 698: my $numheaders = 1;
699: if (ref($item->{'header'}) eq 'ARRAY') {
700: $numheaders = scalar(@{$item->{'header'}});
701: }
702: if ($numheaders > 1) {
1.64 raeburn 703: my $colspan = '';
1.145 raeburn 704: my $rightcolspan = '';
1.238 raeburn 705: if (($action eq 'rolecolors') || ($action eq 'defaults') ||
1.277 raeburn 706: ($action eq 'directorysrch') ||
1.256 raeburn 707: (($action eq 'login') && ($numheaders < 4))) {
1.64 raeburn 708: $colspan = ' colspan="2"';
709: }
1.145 raeburn 710: if ($action eq 'usersessions') {
711: $rightcolspan = ' colspan="3"';
712: }
1.30 raeburn 713: $output .= '
1.3 raeburn 714: <tr>
715: <td>
716: <table class="LC_nested">
717: <tr class="LC_info_row">
1.59 bisitz 718: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[0]->{'col1'}).'</td>
1.145 raeburn 719: <td class="LC_right_item"'.$rightcolspan.'>'.&mt($item->{'header'}->[0]->{'col2'}).'</td>
1.30 raeburn 720: </tr>';
1.69 raeburn 721: $rowtotal ++;
1.230 raeburn 722: if (($action eq 'autoupdate') || ($action eq 'usercreation') || ($action eq 'selfcreation') ||
1.236 raeburn 723: ($action eq 'usermodification') || ($action eq 'defaults') || ($action eq 'coursedefaults') ||
1.277 raeburn 724: ($action eq 'selfenrollment') || ($action eq 'usersessions') || ($action eq 'ssl') ||
725: ($action eq 'directorysrch')) {
1.230 raeburn 726: $output .= $item->{'print'}->('top',$dom,$settings,\$rowtotal);
1.57 raeburn 727: } elsif ($action eq 'coursecategories') {
1.230 raeburn 728: $output .= $item->{'print'}->('top',$dom,$item,$settings,\$rowtotal);
1.110 raeburn 729: } elsif ($action eq 'login') {
1.256 raeburn 730: if ($numheaders == 4) {
1.168 raeburn 731: $colspan = ' colspan="2"';
732: $output .= &print_login('service',$dom,$confname,$phase,$settings,\$rowtotal);
733: } else {
734: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal);
735: }
1.230 raeburn 736: } elsif (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.163 raeburn 737: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.122 jms 738: } elsif ($action eq 'rolecolors') {
1.30 raeburn 739: $output .= &print_rolecolors($phase,'student',$dom,$confname,$settings,\$rowtotal);
1.6 raeburn 740: }
1.30 raeburn 741: $output .= '
1.6 raeburn 742: </table>
743: </td>
744: </tr>
745: <tr>
746: <td>
747: <table class="LC_nested">
748: <tr class="LC_info_row">
1.230 raeburn 749: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col1'}).'</td>
1.59 bisitz 750: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col2'}).'</td>
1.30 raeburn 751: </tr>';
752: $rowtotal ++;
1.230 raeburn 753: if (($action eq 'autoupdate') || ($action eq 'usercreation') ||
754: ($action eq 'selfcreation') || ($action eq 'selfenrollment') ||
1.275 raeburn 755: ($action eq 'usersessions') || ($action eq 'coursecategories') ||
756: ($action eq 'ssl')) {
1.238 raeburn 757: if ($action eq 'coursecategories') {
758: $output .= &print_coursecategories('middle',$dom,$item,$settings,\$rowtotal);
759: $colspan = ' colspan="2"';
760: } else {
761: $output .= $item->{'print'}->('middle',$dom,$settings,\$rowtotal);
762: }
763: $output .= '
1.63 raeburn 764: </table>
765: </td>
766: </tr>
767: <tr>
768: <td>
769: <table class="LC_nested">
770: <tr class="LC_info_row">
771: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1.224 raeburn 772: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
1.238 raeburn 773: </tr>'."\n";
774: if ($action eq 'coursecategories') {
775: $output .= &print_coursecategories('bottom',$dom,$item,$settings,\$rowtotal);
776: } else {
777: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
778: }
1.63 raeburn 779: $rowtotal ++;
1.236 raeburn 780: } elsif (($action eq 'usermodification') || ($action eq 'coursedefaults') ||
1.277 raeburn 781: ($action eq 'defaults') || ($action eq 'directorysrch')) {
1.230 raeburn 782: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1.110 raeburn 783: } elsif ($action eq 'login') {
1.256 raeburn 784: if ($numheaders == 4) {
1.168 raeburn 785: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal).'
786: </table>
787: </td>
788: </tr>
789: <tr>
790: <td>
791: <table class="LC_nested">
792: <tr class="LC_info_row">
793: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1.216 raeburn 794: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td></tr>'.
1.168 raeburn 795: &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
796: $rowtotal ++;
797: } else {
798: $output .= &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
799: }
1.256 raeburn 800: $output .= '
801: </table>
802: </td>
803: </tr>
804: <tr>
805: <td>
806: <table class="LC_nested">
807: <tr class="LC_info_row">';
808: if ($numheaders == 4) {
809: $output .= '
810: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
811: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
812: </tr>';
813: } else {
814: $output .= '
815: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
816: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
817: </tr>';
818: }
819: $rowtotal ++;
820: $output .= &print_login('headtag',$dom,$confname,$phase,$settings,\$rowtotal);
1.102 raeburn 821: } elsif ($action eq 'requestcourses') {
1.247 raeburn 822: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
823: $rowtotal ++;
824: $output .= &print_studentcode($settings,\$rowtotal).'
1.216 raeburn 825: </table>
826: </td>
827: </tr>
828: <tr>
829: <td>
830: <table class="LC_nested">
831: <tr class="LC_info_row">
832: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
833: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
1.242 raeburn 834: &textbookcourses_javascript($settings).
835: &print_textbookcourses($dom,'textbooks',$settings,\$rowtotal).'
836: </table>
837: </td>
838: </tr>
839: <tr>
840: <td>
841: <table class="LC_nested">
842: <tr class="LC_info_row">
843: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
844: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td> </tr>'.
845: &print_textbookcourses($dom,'templates',$settings,\$rowtotal).'
1.235 raeburn 846: </table>
847: </td>
848: </tr>
849: <tr>
850: <td>
851: <table class="LC_nested">
852: <tr class="LC_info_row">
1.242 raeburn 853: <td class="LC_left_item"'.$colspan.' valign="top">'.&mt($item->{'header'}->[4]->{'col1'}).'</td>
854: <td class="LC_right_item" valign="top">'.&mt($item->{'header'}->[4]->{'col2'}).'</td>
1.235 raeburn 855: </tr>'.
856: &print_validation_rows('requestcourses',$dom,$settings,\$rowtotal);
1.163 raeburn 857: } elsif ($action eq 'requestauthor') {
858: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
1.247 raeburn 859: $rowtotal ++;
1.122 jms 860: } elsif ($action eq 'rolecolors') {
1.30 raeburn 861: $output .= &print_rolecolors($phase,'coordinator',$dom,$confname,$settings,\$rowtotal).'
1.6 raeburn 862: </table>
863: </td>
864: </tr>
865: <tr>
866: <td>
867: <table class="LC_nested">
868: <tr class="LC_info_row">
1.69 raeburn 869: <td class="LC_left_item"'.$colspan.' valign="top">'.
870: &mt($item->{'header'}->[2]->{'col1'}).'</td>
871: <td class="LC_right_item" valign="top">'.
872: &mt($item->{'header'}->[2]->{'col2'}).'</td>
1.3 raeburn 873: </tr>'.
1.30 raeburn 874: &print_rolecolors($phase,'author',$dom,$confname,$settings,\$rowtotal).'
1.3 raeburn 875: </table>
876: </td>
877: </tr>
878: <tr>
879: <td>
880: <table class="LC_nested">
881: <tr class="LC_info_row">
1.59 bisitz 882: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
883: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
1.3 raeburn 884: </tr>'.
1.30 raeburn 885: &print_rolecolors($phase,'admin',$dom,$confname,$settings,\$rowtotal);
886: $rowtotal += 2;
1.6 raeburn 887: }
1.3 raeburn 888: } else {
1.30 raeburn 889: $output .= '
1.3 raeburn 890: <tr>
891: <td>
892: <table class="LC_nested">
1.30 raeburn 893: <tr class="LC_info_row">';
1.277 raeburn 894: if ($action eq 'login') {
1.30 raeburn 895: $output .= '
1.59 bisitz 896: <td class="LC_left_item" colspan="2">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
1.69 raeburn 897: } elsif ($action eq 'serverstatuses') {
898: $output .= '
899: <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).
900: '<br />('.&mt('Automatic access for Dom. Coords.').')</td>';
901:
1.6 raeburn 902: } else {
1.30 raeburn 903: $output .= '
1.69 raeburn 904: <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
905: }
1.72 raeburn 906: if (defined($item->{'header'}->[0]->{'col3'})) {
907: $output .= '<td class="LC_left_item" valign="top">'.
908: &mt($item->{'header'}->[0]->{'col2'});
909: if ($action eq 'serverstatuses') {
910: $output .= '<br />(<tt>'.&mt('user1:domain1,user2:domain2 etc.').'</tt>)';
911: }
1.69 raeburn 912: } else {
913: $output .= '<td class="LC_right_item" valign="top">'.
914: &mt($item->{'header'}->[0]->{'col2'});
915: }
916: $output .= '</td>';
917: if ($item->{'header'}->[0]->{'col3'}) {
1.150 raeburn 918: if (defined($item->{'header'}->[0]->{'col4'})) {
919: $output .= '<td class="LC_left_item" valign="top">'.
920: &mt($item->{'header'}->[0]->{'col3'});
921: } else {
922: $output .= '<td class="LC_right_item" valign="top">'.
923: &mt($item->{'header'}->[0]->{'col3'});
924: }
1.69 raeburn 925: if ($action eq 'serverstatuses') {
926: $output .= '<br />(<tt>'.&mt('IP1,IP2 etc.').'</tt>)';
927: }
928: $output .= '</td>';
1.6 raeburn 929: }
1.150 raeburn 930: if ($item->{'header'}->[0]->{'col4'}) {
931: $output .= '<td class="LC_right_item" valign="top">'.
932: &mt($item->{'header'}->[0]->{'col4'});
933: }
1.69 raeburn 934: $output .= '</tr>';
1.48 raeburn 935: $rowtotal ++;
1.168 raeburn 936: if ($action eq 'quotas') {
1.86 raeburn 937: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.277 raeburn 938: } elsif (($action eq 'autoenroll') || ($action eq 'autocreate') ||
939: ($action eq 'contacts') || ($action eq 'serverstatuses') ||
940: ($action eq 'loadbalancing') || ($action eq 'ltitools')) {
1.230 raeburn 941: $output .= $item->{'print'}->($dom,$settings,\$rowtotal);
1.46 raeburn 942: } elsif ($action eq 'scantron') {
943: $output .= &print_scantronformat($r,$dom,$confname,$settings,\$rowtotal);
1.118 jms 944: } elsif ($action eq 'helpsettings') {
1.168 raeburn 945: $output .= &print_helpsettings($dom,$confname,$settings,\$rowtotal);
1.121 raeburn 946: }
1.3 raeburn 947: }
1.30 raeburn 948: $output .= '
1.3 raeburn 949: </table>
950: </td>
951: </tr>
1.30 raeburn 952: </table><br />';
953: return ($output,$rowtotal);
1.1 raeburn 954: }
955:
1.3 raeburn 956: sub print_login {
1.168 raeburn 957: my ($caller,$dom,$confname,$phase,$settings,$rowtotal) = @_;
1.110 raeburn 958: my ($css_class,$datatable);
1.6 raeburn 959: my %choices = &login_choices();
1.110 raeburn 960:
1.168 raeburn 961: if ($caller eq 'service') {
1.149 raeburn 962: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.110 raeburn 963: my $choice = $choices{'disallowlogin'};
964: $css_class = ' class="LC_odd_row"';
1.128 raeburn 965: $datatable .= '<tr'.$css_class.'><td>'.$choice.'</td>'.
1.110 raeburn 966: '<td align="right"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1.128 raeburn 967: '<th>'.$choices{'server'}.'</th>'.
968: '<th>'.$choices{'serverpath'}.'</th>'.
969: '<th>'.$choices{'custompath'}.'</th>'.
970: '<th><span class="LC_nobreak">'.$choices{'exempt'}.'</span></th></tr>'."\n";
1.110 raeburn 971: my %disallowed;
972: if (ref($settings) eq 'HASH') {
973: if (ref($settings->{'loginvia'}) eq 'HASH') {
974: %disallowed = %{$settings->{'loginvia'}};
975: }
976: }
977: foreach my $lonhost (sort(keys(%servers))) {
978: my $direct = 'selected="selected"';
1.128 raeburn 979: if (ref($disallowed{$lonhost}) eq 'HASH') {
980: if ($disallowed{$lonhost}{'server'} ne '') {
981: $direct = '';
982: }
1.110 raeburn 983: }
1.115 raeburn 984: $datatable .= '<tr><td>'.$servers{$lonhost}.'</td>'.
1.128 raeburn 985: '<td><select name="'.$lonhost.'_server">'.
1.110 raeburn 986: '<option value=""'.$direct.'>'.$choices{'directlogin'}.
987: '</option>';
1.184 raeburn 988: foreach my $hostid (sort(keys(%servers))) {
1.115 raeburn 989: next if ($servers{$hostid} eq $servers{$lonhost});
1.110 raeburn 990: my $selected = '';
1.128 raeburn 991: if (ref($disallowed{$lonhost}) eq 'HASH') {
992: if ($hostid eq $disallowed{$lonhost}{'server'}) {
993: $selected = 'selected="selected"';
994: }
1.110 raeburn 995: }
996: $datatable .= '<option value="'.$hostid.'"'.$selected.'>'.
997: $servers{$hostid}.'</option>';
998: }
1.128 raeburn 999: $datatable .= '</select></td>'.
1000: '<td><select name="'.$lonhost.'_serverpath">';
1001: foreach my $path ('','/','/adm/login','/adm/roles','custom') {
1002: my $pathname = $path;
1003: if ($path eq 'custom') {
1004: $pathname = &mt('Custom Path').' ->';
1005: }
1006: my $selected = '';
1007: if (ref($disallowed{$lonhost}) eq 'HASH') {
1008: if ($path eq $disallowed{$lonhost}{'serverpath'}) {
1009: $selected = 'selected="selected"';
1010: }
1011: } elsif ($path eq '') {
1012: $selected = 'selected="selected"';
1013: }
1014: $datatable .= '<option value="'.$path.'"'.$selected.'>'.$pathname.'</option>';
1015: }
1016: $datatable .= '</select></td>';
1017: my ($custom,$exempt);
1018: if (ref($disallowed{$lonhost}) eq 'HASH') {
1019: $custom = $disallowed{$lonhost}{'custompath'};
1020: $exempt = $disallowed{$lonhost}{'exempt'};
1021: }
1022: $datatable .= '<td><input type="text" name="'.$lonhost.'_custompath" size="6" value="'.$custom.'" /></td>'.
1023: '<td><input type="text" name="'.$lonhost.'_exempt" size="8" value="'.$exempt.'" /></td>'.
1024: '</tr>';
1.110 raeburn 1025: }
1026: $datatable .= '</table></td></tr>';
1027: return $datatable;
1.168 raeburn 1028: } elsif ($caller eq 'page') {
1029: my %defaultchecked = (
1030: 'coursecatalog' => 'on',
1.188 raeburn 1031: 'helpdesk' => 'on',
1.168 raeburn 1032: 'adminmail' => 'off',
1033: 'newuser' => 'off',
1034: );
1.188 raeburn 1035: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.168 raeburn 1036: my (%checkedon,%checkedoff);
1.42 raeburn 1037: foreach my $item (@toggles) {
1.168 raeburn 1038: if ($defaultchecked{$item} eq 'on') {
1039: $checkedon{$item} = ' checked="checked" ';
1.42 raeburn 1040: $checkedoff{$item} = ' ';
1.168 raeburn 1041: } elsif ($defaultchecked{$item} eq 'off') {
1042: $checkedoff{$item} = ' checked="checked" ';
1.42 raeburn 1043: $checkedon{$item} = ' ';
1044: }
1.1 raeburn 1045: }
1.168 raeburn 1046: my @images = ('img','logo','domlogo','login');
1047: my @logintext = ('textcol','bgcol');
1048: my @bgs = ('pgbg','mainbg','sidebg');
1049: my @links = ('link','alink','vlink');
1050: my %designhash = &Apache::loncommon::get_domainconf($dom);
1051: my %defaultdesign = %Apache::loncommon::defaultdesign;
1052: my (%is_custom,%designs);
1053: my %defaults = (
1054: font => $defaultdesign{'login.font'},
1055: );
1.6 raeburn 1056: foreach my $item (@images) {
1.168 raeburn 1057: $defaults{$item} = $defaultdesign{'login.'.$item};
1058: $defaults{'showlogo'}{$item} = 1;
1059: }
1060: foreach my $item (@bgs) {
1061: $defaults{'bgs'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 1062: }
1.41 raeburn 1063: foreach my $item (@logintext) {
1.168 raeburn 1064: $defaults{'logintext'}{$item} = $defaultdesign{'login.'.$item};
1.41 raeburn 1065: }
1.168 raeburn 1066: foreach my $item (@links) {
1067: $defaults{'links'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 1068: }
1.168 raeburn 1069: if (ref($settings) eq 'HASH') {
1070: foreach my $item (@toggles) {
1071: if ($settings->{$item} eq '1') {
1072: $checkedon{$item} = ' checked="checked" ';
1073: $checkedoff{$item} = ' ';
1074: } elsif ($settings->{$item} eq '0') {
1075: $checkedoff{$item} = ' checked="checked" ';
1076: $checkedon{$item} = ' ';
1077: }
1078: }
1079: foreach my $item (@images) {
1080: if (defined($settings->{$item})) {
1081: $designs{$item} = $settings->{$item};
1082: $is_custom{$item} = 1;
1083: }
1084: if (defined($settings->{'showlogo'}{$item})) {
1085: $designs{'showlogo'}{$item} = $settings->{'showlogo'}{$item};
1086: }
1087: }
1088: foreach my $item (@logintext) {
1089: if ($settings->{$item} ne '') {
1090: $designs{'logintext'}{$item} = $settings->{$item};
1091: $is_custom{$item} = 1;
1092: }
1093: }
1094: if ($settings->{'font'} ne '') {
1095: $designs{'font'} = $settings->{'font'};
1096: $is_custom{'font'} = 1;
1097: }
1098: foreach my $item (@bgs) {
1099: if ($settings->{$item} ne '') {
1100: $designs{'bgs'}{$item} = $settings->{$item};
1101: $is_custom{$item} = 1;
1102: }
1103: }
1104: foreach my $item (@links) {
1105: if ($settings->{$item} ne '') {
1106: $designs{'links'}{$item} = $settings->{$item};
1107: $is_custom{$item} = 1;
1108: }
1109: }
1110: } else {
1111: if ($designhash{$dom.'.login.font'} ne '') {
1112: $designs{'font'} = $designhash{$dom.'.login.font'};
1113: $is_custom{'font'} = 1;
1114: }
1115: foreach my $item (@images) {
1116: if ($designhash{$dom.'.login.'.$item} ne '') {
1117: $designs{$item} = $designhash{$dom.'.login.'.$item};
1118: $is_custom{$item} = 1;
1119: }
1120: }
1121: foreach my $item (@bgs) {
1122: if ($designhash{$dom.'.login.'.$item} ne '') {
1123: $designs{'bgs'}{$item} = $designhash{$dom.'.login.'.$item};
1124: $is_custom{$item} = 1;
1125: }
1.6 raeburn 1126: }
1.168 raeburn 1127: foreach my $item (@links) {
1128: if ($designhash{$dom.'.login.'.$item} ne '') {
1129: $designs{'links'}{$item} = $designhash{$dom.'.login.'.$item};
1130: $is_custom{$item} = 1;
1131: }
1.6 raeburn 1132: }
1133: }
1.168 raeburn 1134: my %alt_text = &Apache::lonlocal::texthash ( img => 'Log-in banner',
1135: logo => 'Institution Logo',
1136: domlogo => 'Domain Logo',
1137: login => 'Login box');
1138: my $itemcount = 1;
1139: foreach my $item (@toggles) {
1140: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1141: $datatable .=
1142: '<tr'.$css_class.'><td colspan="2">'.$choices{$item}.
1143: '</td><td>'.
1144: '<span class="LC_nobreak"><label><input type="radio" name="'.
1145: $item.'"'.$checkedon{$item}.' value="1" />'.&mt('Yes').
1146: '</label> <label><input type="radio" name="'.$item.'"'.
1147: $checkedoff{$item}.' value="0" />'.&mt('No').'</label></span></td>'.
1148: '</tr>';
1149: $itemcount ++;
1.6 raeburn 1150: }
1.168 raeburn 1151: $datatable .= &display_color_options($dom,$confname,$phase,'login',$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal,\@logintext);
1152: $datatable .= '</tr></table></td></tr>';
1153: } elsif ($caller eq 'help') {
1154: my ($defaulturl,$defaulttype,%url,%type,%lt,%langchoices);
1155: my $switchserver = &check_switchserver($dom,$confname);
1156: my $itemcount = 1;
1157: $defaulturl = '/adm/loginproblems.html';
1158: $defaulttype = 'default';
1159: %lt = &Apache::lonlocal::texthash (
1160: del => 'Delete?',
1161: rep => 'Replace:',
1162: upl => 'Upload:',
1163: default => 'Default',
1164: custom => 'Custom',
1165: );
1166: %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
1167: my @currlangs;
1168: if (ref($settings) eq 'HASH') {
1169: if (ref($settings->{'helpurl'}) eq 'HASH') {
1170: foreach my $key (sort(keys(%{$settings->{'helpurl'}}))) {
1171: next if ($settings->{'helpurl'}{$key} eq '');
1172: $url{$key} = $settings->{'helpurl'}{$key}.'?inhibitmenu=yes';
1173: $type{$key} = 'custom';
1174: unless ($key eq 'nolang') {
1175: push(@currlangs,$key);
1176: }
1177: }
1178: } elsif ($settings->{'helpurl'} ne '') {
1179: $type{'nolang'} = 'custom';
1180: $url{'nolang'} = $settings->{'helpurl'}.'?inhibitmenu=yes';
1.8 raeburn 1181: }
1182: }
1.168 raeburn 1183: foreach my $lang ('nolang',sort(@currlangs)) {
1184: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1185: $datatable .= '<tr'.$css_class.'>';
1186: if ($url{$lang} eq '') {
1187: $url{$lang} = $defaulturl;
1188: }
1189: if ($type{$lang} eq '') {
1190: $type{$lang} = $defaulttype;
1191: }
1192: $datatable .= '<td colspan="2"><span class="LC_nobreak">';
1193: if ($lang eq 'nolang') {
1194: $datatable .= &mt('Log-in help page if no specific language file: [_1]',
1195: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1196: } else {
1197: $datatable .= &mt('Log-in help page for language: [_1] is [_2]',
1198: $langchoices{$lang},
1199: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1200: }
1201: $datatable .= '</span></td>'."\n".
1202: '<td class="LC_left_item">';
1203: if ($type{$lang} eq 'custom') {
1204: $datatable .= '<span class="LC_nobreak"><label>'.
1205: '<input type="checkbox" name="loginhelpurl_del" value="'.$lang.'" />'.
1206: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1207: } else {
1208: $datatable .= $lt{'upl'};
1209: }
1210: $datatable .='<br />';
1211: if ($switchserver) {
1212: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1213: } else {
1214: $datatable .= '<input type="file" name="loginhelpurl_'.$lang.'" />';
1.6 raeburn 1215: }
1.168 raeburn 1216: $datatable .= '</td></tr>';
1217: $itemcount ++;
1.6 raeburn 1218: }
1.168 raeburn 1219: my @addlangs;
1220: foreach my $lang (sort(keys(%langchoices))) {
1221: next if ((grep(/^\Q$lang\E$/,@currlangs)) || ($lang eq 'x_chef'));
1222: push(@addlangs,$lang);
1223: }
1224: if (@addlangs > 0) {
1225: my %toadd;
1226: map { $toadd{$_} = $langchoices{$_} ; } @addlangs;
1227: $toadd{''} = &mt('Select');
1228: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1229: $datatable .= '<tr'.$css_class.'><td class="LC_left_item" colspan="2">'.
1230: &mt('Add log-in help page for a specific language:').' '.
1231: &Apache::loncommon::select_form('','loginhelpurl_add_lang',\%toadd).
1232: '</td><td class="LC_left_item">'.$lt{'upl'}.'<br />';
1233: if ($switchserver) {
1234: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1235: } else {
1236: $datatable .= '<input type="file" name="loginhelpurl_add_file" />';
1.6 raeburn 1237: }
1.168 raeburn 1238: $datatable .= '</td></tr>';
1.169 raeburn 1239: $itemcount ++;
1.6 raeburn 1240: }
1.169 raeburn 1241: $datatable .= &captcha_choice('login',$settings,$itemcount);
1.256 raeburn 1242: } elsif ($caller eq 'headtag') {
1243: my %domservers = &Apache::lonnet::get_servers($dom);
1244: my $choice = $choices{'headtag'};
1245: $css_class = ' class="LC_odd_row"';
1246: $datatable .= '<tr'.$css_class.'><td colspan="2">'.$choice.'</td>'.
1247: '<td align="left"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1248: '<th>'.$choices{'current'}.'</th>'.
1249: '<th>'.$choices{'action'}.'</th>'.
1250: '<th>'.$choices{'exempt'}.'</th></tr>'."\n";
1251: my (%currurls,%currexempt);
1252: if (ref($settings) eq 'HASH') {
1253: if (ref($settings->{'headtag'}) eq 'HASH') {
1254: foreach my $lonhost (keys(%{$settings->{'headtag'}})) {
1255: if (ref($settings->{'headtag'}{$lonhost}) eq 'HASH') {
1256: $currurls{$lonhost} = $settings->{'headtag'}{$lonhost}{'url'};
1257: $currexempt{$lonhost} = $settings->{'headtag'}{$lonhost}{'exempt'};
1258: }
1259: }
1260: }
1261: }
1262: my %lt = &Apache::lonlocal::texthash(
1263: del => 'Delete?',
1264: rep => 'Replace:',
1265: upl => 'Upload:',
1266: curr => 'View contents',
1267: none => 'None',
1268: );
1269: my $switchserver = &check_switchserver($dom,$confname);
1270: foreach my $lonhost (sort(keys(%domservers))) {
1271: my $exempt = &check_exempt_addresses($currexempt{$lonhost});
1272: $datatable .= '<tr><td>'.$domservers{$lonhost}.'</td>';
1273: if ($currurls{$lonhost}) {
1274: $datatable .= '<td class="LC_right_item"><a href="'.
1275: "javascript:void(open('$currurls{$lonhost}?inhibitmenu=yes','Custom_HeadTag',
1276: 'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
1277: '">'.$lt{'curr'}.'</a></td>'.
1278: '<td><span class="LC_nobreak"><label>'.
1279: '<input type="checkbox" name="loginheadtag_del" value="'.$lonhost.'" />'.
1280: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1281: } else {
1282: $datatable .= '<td class="LC_right_item">'.$lt{'none'}.'</td><td>'.$lt{'upl'};
1283: }
1284: $datatable .='<br />';
1285: if ($switchserver) {
1286: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1287: } else {
1288: $datatable .= '<input type="file" name="loginheadtag_'.$lonhost.'" />';
1289: }
1290: $datatable .= '</td><td><input type="textbox" name="loginheadtagexempt_'.$lonhost.'" value="'.$exempt.'" /></td></tr>';
1291: }
1292: $datatable .= '</table></td></tr>';
1.1 raeburn 1293: }
1.6 raeburn 1294: return $datatable;
1295: }
1296:
1297: sub login_choices {
1298: my %choices =
1299: &Apache::lonlocal::texthash (
1.116 bisitz 1300: coursecatalog => 'Display Course/Community Catalog link?',
1.110 raeburn 1301: adminmail => "Display Administrator's E-mail Address?",
1.188 raeburn 1302: helpdesk => 'Display "Contact Helpdesk" link',
1.110 raeburn 1303: disallowlogin => "Login page requests redirected",
1304: hostid => "Server",
1.128 raeburn 1305: server => "Redirect to:",
1306: serverpath => "Path",
1307: custompath => "Custom",
1308: exempt => "Exempt IP(s)",
1.110 raeburn 1309: directlogin => "No redirect",
1310: newuser => "Link to create a user account",
1311: img => "Header",
1312: logo => "Main Logo",
1313: domlogo => "Domain Logo",
1314: login => "Log-in Header",
1315: textcol => "Text color",
1316: bgcol => "Box color",
1317: bgs => "Background colors",
1318: links => "Link colors",
1319: font => "Font color",
1320: pgbg => "Header",
1321: mainbg => "Page",
1322: sidebg => "Login box",
1323: link => "Link",
1324: alink => "Active link",
1325: vlink => "Visited link",
1.256 raeburn 1326: headtag => "Custom markup",
1327: action => "Action",
1328: current => "Current",
1.6 raeburn 1329: );
1330: return %choices;
1331: }
1332:
1333: sub print_rolecolors {
1.30 raeburn 1334: my ($phase,$role,$dom,$confname,$settings,$rowtotal) = @_;
1.6 raeburn 1335: my %choices = &color_font_choices();
1336: my @bgs = ('pgbg','tabbg','sidebg');
1337: my @links = ('link','alink','vlink');
1338: my @images = ('img');
1339: my %alt_text = &Apache::lonlocal::texthash(img => "Banner for $role role");
1.7 albertel 1340: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.6 raeburn 1341: my %defaultdesign = %Apache::loncommon::defaultdesign;
1342: my (%is_custom,%designs);
1.200 raeburn 1343: my %defaults = &role_defaults($role,\@bgs,\@links,\@images);
1.6 raeburn 1344: if (ref($settings) eq 'HASH') {
1345: if (ref($settings->{$role}) eq 'HASH') {
1346: if ($settings->{$role}->{'img'} ne '') {
1347: $designs{'img'} = $settings->{$role}->{'img'};
1348: $is_custom{'img'} = 1;
1349: }
1350: if ($settings->{$role}->{'font'} ne '') {
1351: $designs{'font'} = $settings->{$role}->{'font'};
1352: $is_custom{'font'} = 1;
1353: }
1.97 tempelho 1354: if ($settings->{$role}->{'fontmenu'} ne '') {
1355: $designs{'fontmenu'} = $settings->{$role}->{'fontmenu'};
1356: $is_custom{'fontmenu'} = 1;
1357: }
1.6 raeburn 1358: foreach my $item (@bgs) {
1359: if ($settings->{$role}->{$item} ne '') {
1360: $designs{'bgs'}{$item} = $settings->{$role}->{$item};
1361: $is_custom{$item} = 1;
1362: }
1363: }
1364: foreach my $item (@links) {
1365: if ($settings->{$role}->{$item} ne '') {
1366: $designs{'links'}{$item} = $settings->{$role}->{$item};
1367: $is_custom{$item} = 1;
1368: }
1369: }
1370: }
1371: } else {
1372: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
1373: $designs{img} = $designhash{$dom.'.'.$role.'.img'};
1374: $is_custom{'img'} = 1;
1375: }
1.97 tempelho 1376: if ($designhash{$dom.'.'.$role.'.fontmenu'} ne '') {
1377: $designs{fontmenu} = $designhash{$dom.'.'.$role.'.fontmenu'};
1378: $is_custom{'fontmenu'} = 1;
1379: }
1.6 raeburn 1380: if ($designhash{$dom.'.'.$role.'.font'} ne '') {
1381: $designs{font} = $designhash{$dom.'.'.$role.'.font'};
1382: $is_custom{'font'} = 1;
1383: }
1384: foreach my $item (@bgs) {
1385: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1386: $designs{'bgs'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1387: $is_custom{$item} = 1;
1388:
1389: }
1390: }
1391: foreach my $item (@links) {
1392: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1393: $designs{'links'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1394: $is_custom{$item} = 1;
1395: }
1396: }
1397: }
1398: my $itemcount = 1;
1.30 raeburn 1399: my $datatable = &display_color_options($dom,$confname,$phase,$role,$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal);
1.6 raeburn 1400: $datatable .= '</tr></table></td></tr>';
1401: return $datatable;
1402: }
1403:
1.200 raeburn 1404: sub role_defaults {
1405: my ($role,$bgs,$links,$images,$logintext) = @_;
1.202 raeburn 1406: my %defaults;
1407: unless ((ref($bgs) eq 'ARRAY') && (ref($links) eq 'ARRAY') && (ref($images) eq 'ARRAY')) {
1.200 raeburn 1408: return %defaults;
1409: }
1410: my %defaultdesign = %Apache::loncommon::defaultdesign;
1411: if ($role eq 'login') {
1412: %defaults = (
1413: font => $defaultdesign{$role.'.font'},
1414: );
1415: if (ref($logintext) eq 'ARRAY') {
1416: foreach my $item (@{$logintext}) {
1417: $defaults{'logintext'}{$item} = $defaultdesign{$role.'.'.$item};
1418: }
1419: }
1420: foreach my $item (@{$images}) {
1421: $defaults{'showlogo'}{$item} = 1;
1422: }
1423: } else {
1424: %defaults = (
1425: img => $defaultdesign{$role.'.img'},
1426: font => $defaultdesign{$role.'.font'},
1427: fontmenu => $defaultdesign{$role.'.fontmenu'},
1428: );
1429: }
1430: foreach my $item (@{$bgs}) {
1431: $defaults{'bgs'}{$item} = $defaultdesign{$role.'.'.$item};
1432: }
1433: foreach my $item (@{$links}) {
1434: $defaults{'links'}{$item} = $defaultdesign{$role.'.'.$item};
1435: }
1436: foreach my $item (@{$images}) {
1437: $defaults{$item} = $defaultdesign{$role.'.'.$item};
1438: }
1439: return %defaults;
1440: }
1441:
1.6 raeburn 1442: sub display_color_options {
1.9 raeburn 1443: my ($dom,$confname,$phase,$role,$itemcount,$choices,$is_custom,$defaults,$designs,
1.135 bisitz 1444: $images,$bgs,$links,$alt_text,$rowtotal,$logintext) = @_;
1.159 raeburn 1445: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.6 raeburn 1446: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.176 raeburn 1447: my $datatable = '<tr'.$css_class.'>'.
1.6 raeburn 1448: '<td>'.$choices->{'font'}.'</td>';
1449: if (!$is_custom->{'font'}) {
1.30 raeburn 1450: $datatable .= '<td>'.&mt('Default in use:').' <span id="css_default_'.$role.'_font" style="color: '.$defaults->{'font'}.';">'.$defaults->{'font'}.'</span></td>';
1.6 raeburn 1451: } else {
1452: $datatable .= '<td> </td>';
1453: }
1.174 foxr 1454: my $current_color = $designs->{'font'} ? $designs->{'font'} : $defaults->{'font'};
1455:
1.8 raeburn 1456: $datatable .= '<td><span class="LC_nobreak">'.
1.174 foxr 1457: '<input type="text" class="colorchooser" size="10" name="'.$role.'_font"'.
1.202 raeburn 1458: ' value="'.$current_color.'" /> '.
1.174 foxr 1459: ' </td></tr>';
1.107 raeburn 1460: unless ($role eq 'login') {
1461: $datatable .= '<tr'.$css_class.'>'.
1462: '<td>'.$choices->{'fontmenu'}.'</td>';
1463: if (!$is_custom->{'fontmenu'}) {
1464: $datatable .= '<td>'.&mt('Default in use:').' <span id="css_default_'.$role.'_font" style="color: '.$defaults->{'fontmenu'}.';">'.$defaults->{'fontmenu'}.'</span></td>';
1465: } else {
1466: $datatable .= '<td> </td>';
1467: }
1.202 raeburn 1468: $current_color = $designs->{'fontmenu'} ?
1.174 foxr 1469: $designs->{'fontmenu'} : $defaults->{'fontmenu'};
1.107 raeburn 1470: $datatable .= '<td><span class="LC_nobreak">'.
1.174 foxr 1471: '<input class="colorchooser" type="text" size="10" name="'
1472: .$role.'_fontmenu"'.
1473: ' value="'.$current_color.'" /> '.
1474: ' </td></tr>';
1.97 tempelho 1475: }
1.9 raeburn 1476: my $switchserver = &check_switchserver($dom,$confname);
1.6 raeburn 1477: foreach my $img (@{$images}) {
1.18 albertel 1478: $itemcount ++;
1.6 raeburn 1479: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.8 raeburn 1480: $datatable .= '<tr'.$css_class.'>'.
1.70 raeburn 1481: '<td>'.$choices->{$img};
1.41 raeburn 1482: my ($imgfile,$img_import,$login_hdr_pick,$logincolors);
1.70 raeburn 1483: if ($role eq 'login') {
1484: if ($img eq 'login') {
1485: $login_hdr_pick =
1.135 bisitz 1486: &login_header_options($img,$role,$defaults,$is_custom,$choices);
1.70 raeburn 1487: $logincolors =
1488: &login_text_colors($img,$role,$logintext,$phase,$choices,
1.201 raeburn 1489: $designs,$defaults);
1.70 raeburn 1490: } elsif ($img ne 'domlogo') {
1491: $datatable.= &logo_display_options($img,$defaults,$designs);
1492: }
1493: }
1494: $datatable .= '</td>';
1.6 raeburn 1495: if ($designs->{$img} ne '') {
1496: $imgfile = $designs->{$img};
1.18 albertel 1497: $img_import = ($imgfile =~ m{^/adm/});
1.6 raeburn 1498: } else {
1499: $imgfile = $defaults->{$img};
1500: }
1501: if ($imgfile) {
1.9 raeburn 1502: my ($showfile,$fullsize);
1503: if ($imgfile =~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
1.6 raeburn 1504: my $urldir = $1;
1505: my $filename = $2;
1506: my @info = &Apache::lonnet::stat_file($designs->{$img});
1507: if (@info) {
1508: my $thumbfile = 'tn-'.$filename;
1509: my @thumb=&Apache::lonnet::stat_file($urldir.'/'.$thumbfile);
1510: if (@thumb) {
1511: $showfile = $urldir.'/'.$thumbfile;
1512: } else {
1513: $showfile = $imgfile;
1514: }
1515: } else {
1516: $showfile = '';
1517: }
1518: } elsif ($imgfile =~ m-^/(adm/[^/]+)/([^/]+)$-) {
1.16 raeburn 1519: $showfile = $imgfile;
1.6 raeburn 1520: my $imgdir = $1;
1521: my $filename = $2;
1.159 raeburn 1522: if (-e "$londocroot/$imgdir/tn-".$filename) {
1.6 raeburn 1523: $showfile = "/$imgdir/tn-".$filename;
1524: } else {
1.159 raeburn 1525: my $input = $londocroot.$imgfile;
1526: my $output = "$londocroot/$imgdir/tn-".$filename;
1.6 raeburn 1527: if (!-e $output) {
1.9 raeburn 1528: my ($width,$height) = &thumb_dimensions();
1.16 raeburn 1529: my ($fullwidth,$fullheight) = &check_dimensions($input);
1530: if ($fullwidth ne '' && $fullheight ne '') {
1531: if ($fullwidth > $width && $fullheight > $height) {
1532: my $size = $width.'x'.$height;
1533: system("convert -sample $size $input $output");
1.159 raeburn 1534: $showfile = "/$imgdir/tn-".$filename;
1.16 raeburn 1535: }
1536: }
1.6 raeburn 1537: }
1538: }
1.16 raeburn 1539: }
1.6 raeburn 1540: if ($showfile) {
1.40 raeburn 1541: if ($showfile =~ m{^/(adm|res)/}) {
1542: if ($showfile =~ m{^/res/}) {
1543: my $local_showfile =
1544: &Apache::lonnet::filelocation('',$showfile);
1545: &Apache::lonnet::repcopy($local_showfile);
1546: }
1547: $showfile = &Apache::loncommon::lonhttpdurl($showfile);
1548: }
1549: if ($imgfile) {
1550: if ($imgfile =~ m{^/(adm|res)/}) {
1551: if ($imgfile =~ m{^/res/}) {
1552: my $local_imgfile =
1553: &Apache::lonnet::filelocation('',$imgfile);
1554: &Apache::lonnet::repcopy($local_imgfile);
1555: }
1556: $fullsize = &Apache::loncommon::lonhttpdurl($imgfile);
1557: } else {
1558: $fullsize = $imgfile;
1559: }
1560: }
1.41 raeburn 1561: $datatable .= '<td>';
1562: if ($img eq 'login') {
1.135 bisitz 1563: $datatable .= $login_hdr_pick;
1564: }
1.41 raeburn 1565: $datatable .= &image_changes($is_custom->{$img},$alt_text->{$img},$img_import,
1566: $showfile,$fullsize,$role,$img,$imgfile,$logincolors);
1.6 raeburn 1567: } else {
1.201 raeburn 1568: $datatable .= '<td> </td><td class="LC_left_item">'.
1569: &mt('Upload:').'<br />';
1.6 raeburn 1570: }
1571: } else {
1.201 raeburn 1572: $datatable .= '<td> </td><td class="LC_left_item">'.
1573: &mt('Upload:').'<br />';
1.6 raeburn 1574: }
1.9 raeburn 1575: if ($switchserver) {
1576: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1577: } else {
1.135 bisitz 1578: if ($img ne 'login') { # suppress file selection for Log-in header
1579: $datatable .=' <input type="file" name="'.$role.'_'.$img.'" />';
1580: }
1.9 raeburn 1581: }
1582: $datatable .= '</td></tr>';
1.6 raeburn 1583: }
1584: $itemcount ++;
1585: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1586: $datatable .= '<tr'.$css_class.'>'.
1587: '<td>'.$choices->{'bgs'}.'</td>';
1588: my $bgs_def;
1589: foreach my $item (@{$bgs}) {
1590: if (!$is_custom->{$item}) {
1.70 raeburn 1591: $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 1592: }
1593: }
1594: if ($bgs_def) {
1.8 raeburn 1595: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$bgs_def.'</tr></table></td>';
1.6 raeburn 1596: } else {
1597: $datatable .= '<td> </td>';
1598: }
1599: $datatable .= '<td class="LC_right_item">'.
1600: '<table border="0"><tr>';
1.174 foxr 1601:
1.6 raeburn 1602: foreach my $item (@{$bgs}) {
1.201 raeburn 1603: $datatable .= '<td align="center">'.$choices->{$item};
1.174 foxr 1604: my $color = $designs->{'bgs'}{$item} ? $designs->{'bgs'}{$item} : $defaults->{'bgs'}{$item};
1.6 raeburn 1605: if ($designs->{'bgs'}{$item}) {
1.174 foxr 1606: $datatable .= ' ';
1.6 raeburn 1607: }
1.174 foxr 1608: $datatable .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1.41 raeburn 1609: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.6 raeburn 1610: }
1611: $datatable .= '</tr></table></td></tr>';
1612: $itemcount ++;
1613: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1614: $datatable .= '<tr'.$css_class.'>'.
1615: '<td>'.$choices->{'links'}.'</td>';
1616: my $links_def;
1617: foreach my $item (@{$links}) {
1618: if (!$is_custom->{$item}) {
1.30 raeburn 1619: $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 1620: }
1621: }
1622: if ($links_def) {
1.8 raeburn 1623: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$links_def.'</tr></table></td>';
1.6 raeburn 1624: } else {
1625: $datatable .= '<td> </td>';
1626: }
1627: $datatable .= '<td class="LC_right_item">'.
1628: '<table border="0"><tr>';
1629: foreach my $item (@{$links}) {
1.234 raeburn 1630: my $color = $designs->{'links'}{$item} ? $designs->{'links'}{$item} : $defaults->{'links'}{$item};
1.201 raeburn 1631: $datatable .= '<td align="center">'.$choices->{$item}."\n";
1.6 raeburn 1632: if ($designs->{'links'}{$item}) {
1.174 foxr 1633: $datatable.=' ';
1.6 raeburn 1634: }
1.174 foxr 1635: $datatable .= '<br /><input type="text" size="8" class="colorchooser" name="'.$role.'_'.$item.'" value="'.$color.
1.6 raeburn 1636: '" /></td>';
1637: }
1.30 raeburn 1638: $$rowtotal += $itemcount;
1.3 raeburn 1639: return $datatable;
1640: }
1641:
1.70 raeburn 1642: sub logo_display_options {
1643: my ($img,$defaults,$designs) = @_;
1644: my $checkedon;
1645: if (ref($defaults) eq 'HASH') {
1646: if (ref($defaults->{'showlogo'}) eq 'HASH') {
1647: if ($defaults->{'showlogo'}{$img}) {
1648: $checkedon = 'checked="checked" ';
1649: }
1650: }
1651: }
1652: if (ref($designs) eq 'HASH') {
1653: if (ref($designs->{'showlogo'}) eq 'HASH') {
1654: if (defined($designs->{'showlogo'}{$img})) {
1655: if ($designs->{'showlogo'}{$img} == 0) {
1656: $checkedon = '';
1657: } elsif ($designs->{'showlogo'}{$img} == 1) {
1658: $checkedon = 'checked="checked" ';
1659: }
1660: }
1661: }
1662: }
1663: return '<br /><label> <input type="checkbox" name="'.
1664: 'login_showlogo_'.$img.'" value="1" '.$checkedon.'/>'.
1665: &mt('show').'</label>'."\n";
1666: }
1667:
1.41 raeburn 1668: sub login_header_options {
1.135 bisitz 1669: my ($img,$role,$defaults,$is_custom,$choices) = @_;
1670: my $output = '';
1.41 raeburn 1671: if ((!$is_custom->{'textcol'}) || (!$is_custom->{'bgcol'})) {
1.135 bisitz 1672: $output .= &mt('Text default(s):').'<br />';
1.41 raeburn 1673: if (!$is_custom->{'textcol'}) {
1674: $output .= $choices->{'textcol'}.': '.$defaults->{'logintext'}{'textcol'}.
1675: ' ';
1676: }
1677: if (!$is_custom->{'bgcol'}) {
1678: $output .= $choices->{'bgcol'}.': '.
1679: '<span id="css_'.$role.'_font" style="background-color: '.
1680: $defaults->{'logintext'}{'bgcol'}.';"> </span>';
1681: }
1682: $output .= '<br />';
1683: }
1684: $output .='<br />';
1685: return $output;
1686: }
1687:
1688: sub login_text_colors {
1.201 raeburn 1689: my ($img,$role,$logintext,$phase,$choices,$designs,$defaults) = @_;
1.41 raeburn 1690: my $color_menu = '<table border="0"><tr>';
1691: foreach my $item (@{$logintext}) {
1.201 raeburn 1692: $color_menu .= '<td align="center">'.$choices->{$item};
1693: my $color = $designs->{'logintext'}{$item} ? $designs->{'logintext'}{$item} : $defaults->{'logintext'}{$item};
1694: $color_menu .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1695: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.41 raeburn 1696: }
1697: $color_menu .= '</tr></table><br />';
1698: return $color_menu;
1699: }
1700:
1701: sub image_changes {
1702: my ($is_custom,$alt_text,$img_import,$showfile,$fullsize,$role,$img,$imgfile,$logincolors) = @_;
1703: my $output;
1.135 bisitz 1704: if ($img eq 'login') {
1705: # suppress image for Log-in header
1706: } elsif (!$is_custom) {
1.70 raeburn 1707: if ($img ne 'domlogo') {
1.41 raeburn 1708: $output .= &mt('Default image:').'<br />';
1709: } else {
1710: $output .= &mt('Default in use:').'<br />';
1711: }
1712: }
1.135 bisitz 1713: if ($img eq 'login') { # suppress image for Log-in header
1714: $output .= '<td>'.$logincolors;
1.41 raeburn 1715: } else {
1.135 bisitz 1716: if ($img_import) {
1717: $output .= '<input type="hidden" name="'.$role.'_import_'.$img.'" value="'.$imgfile.'" />';
1718: }
1719: $output .= '<a href="'.$fullsize.'" target="_blank"><img src="'.
1720: $showfile.'" alt="'.$alt_text.'" border="0" /></a></td>';
1721: if ($is_custom) {
1722: $output .= '<td>'.$logincolors.'<span class="LC_nobreak"><label>'.
1723: '<input type="checkbox" name="'.
1724: $role.'_del_'.$img.'" value="1" />'.&mt('Delete?').
1725: '</label> '.&mt('Replace:').'</span><br />';
1726: } else {
1.201 raeburn 1727: $output .= '<td valign="middle">'.$logincolors.&mt('Upload:').'<br />';
1.135 bisitz 1728: }
1.41 raeburn 1729: }
1730: return $output;
1731: }
1732:
1.3 raeburn 1733: sub print_quotas {
1.86 raeburn 1734: my ($dom,$settings,$rowtotal,$action) = @_;
1735: my $context;
1736: if ($action eq 'quotas') {
1737: $context = 'tools';
1738: } else {
1739: $context = $action;
1740: }
1.197 raeburn 1741: my ($datatable,$defaultquota,$authorquota,@usertools,@options,%validations);
1.44 raeburn 1742: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.3 raeburn 1743: my $typecount = 0;
1.101 raeburn 1744: my ($css_class,%titles);
1.86 raeburn 1745: if ($context eq 'requestcourses') {
1.271 raeburn 1746: @usertools = ('official','unofficial','community','textbook','placement');
1.106 raeburn 1747: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 1748: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
1749: %titles = &courserequest_titles();
1.163 raeburn 1750: } elsif ($context eq 'requestauthor') {
1751: @usertools = ('author');
1752: @options = ('norequest','approval','automatic');
1.210 raeburn 1753: %titles = &authorrequest_titles();
1.86 raeburn 1754: } else {
1.162 raeburn 1755: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 1756: %titles = &tool_titles();
1.86 raeburn 1757: }
1.26 raeburn 1758: if (ref($types) eq 'ARRAY') {
1.23 raeburn 1759: foreach my $type (@{$types}) {
1.197 raeburn 1760: my ($currdefquota,$currauthorquota);
1.163 raeburn 1761: unless (($context eq 'requestcourses') ||
1762: ($context eq 'requestauthor')) {
1.86 raeburn 1763: if (ref($settings) eq 'HASH') {
1764: if (ref($settings->{defaultquota}) eq 'HASH') {
1.197 raeburn 1765: $currdefquota = $settings->{defaultquota}->{$type};
1.86 raeburn 1766: } else {
1767: $currdefquota = $settings->{$type};
1768: }
1.197 raeburn 1769: if (ref($settings->{authorquota}) eq 'HASH') {
1770: $currauthorquota = $settings->{authorquota}->{$type};
1771: }
1.78 raeburn 1772: }
1.72 raeburn 1773: }
1.3 raeburn 1774: if (defined($usertypes->{$type})) {
1775: $typecount ++;
1776: $css_class = $typecount%2?' class="LC_odd_row"':'';
1.72 raeburn 1777: $datatable .= '<tr'.$css_class.'>'.
1.3 raeburn 1778: '<td>'.$usertypes->{$type}.'</td>'.
1.72 raeburn 1779: '<td class="LC_left_item">';
1.101 raeburn 1780: if ($context eq 'requestcourses') {
1781: $datatable .= '<table><tr>';
1782: }
1783: my %cell;
1.72 raeburn 1784: foreach my $item (@usertools) {
1.101 raeburn 1785: if ($context eq 'requestcourses') {
1786: my ($curroption,$currlimit);
1787: if (ref($settings) eq 'HASH') {
1788: if (ref($settings->{$item}) eq 'HASH') {
1789: $curroption = $settings->{$item}->{$type};
1790: if ($curroption =~ /^autolimit=(\d*)$/) {
1791: $currlimit = $1;
1792: }
1793: }
1794: }
1795: if (!$curroption) {
1796: $curroption = 'norequest';
1797: }
1798: $datatable .= '<th>'.$titles{$item}.'</th>';
1799: foreach my $option (@options) {
1800: my $val = $option;
1801: if ($option eq 'norequest') {
1802: $val = 0;
1803: }
1804: if ($option eq 'validate') {
1805: my $canvalidate = 0;
1806: if (ref($validations{$item}) eq 'HASH') {
1807: if ($validations{$item}{$type}) {
1808: $canvalidate = 1;
1809: }
1810: }
1811: next if (!$canvalidate);
1812: }
1813: my $checked = '';
1814: if ($option eq $curroption) {
1815: $checked = ' checked="checked"';
1816: } elsif ($option eq 'autolimit') {
1817: if ($curroption =~ /^autolimit/) {
1818: $checked = ' checked="checked"';
1819: }
1820: }
1821: $cell{$item} .= '<span class="LC_nobreak"><label>'.
1822: '<input type="radio" name="crsreq_'.$item.
1823: '_'.$type.'" value="'.$val.'"'.$checked.' />'.
1.127 raeburn 1824: $titles{$option}.'</label>';
1.101 raeburn 1825: if ($option eq 'autolimit') {
1.127 raeburn 1826: $cell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 1827: $item.'_limit_'.$type.'" size="1" '.
1.103 raeburn 1828: 'value="'.$currlimit.'" />';
1.101 raeburn 1829: }
1.127 raeburn 1830: $cell{$item} .= '</span> ';
1.103 raeburn 1831: if ($option eq 'autolimit') {
1.127 raeburn 1832: $cell{$item} .= $titles{'unlimited'};
1.103 raeburn 1833: }
1.101 raeburn 1834: }
1.163 raeburn 1835: } elsif ($context eq 'requestauthor') {
1836: my $curroption;
1837: if (ref($settings) eq 'HASH') {
1838: $curroption = $settings->{$type};
1839: }
1840: if (!$curroption) {
1841: $curroption = 'norequest';
1842: }
1843: foreach my $option (@options) {
1844: my $val = $option;
1845: if ($option eq 'norequest') {
1846: $val = 0;
1847: }
1848: my $checked = '';
1849: if ($option eq $curroption) {
1850: $checked = ' checked="checked"';
1851: }
1852: $datatable .= '<span class="LC_nobreak"><label>'.
1853: '<input type="radio" name="authorreq_'.$type.
1854: '" value="'.$val.'"'.$checked.' />'.
1855: $titles{$option}.'</label></span> ';
1856: }
1.101 raeburn 1857: } else {
1858: my $checked = 'checked="checked" ';
1859: if (ref($settings) eq 'HASH') {
1860: if (ref($settings->{$item}) eq 'HASH') {
1861: if ($settings->{$item}->{$type} == 0) {
1862: $checked = '';
1863: } elsif ($settings->{$item}->{$type} == 1) {
1864: $checked = 'checked="checked" ';
1865: }
1.78 raeburn 1866: }
1.72 raeburn 1867: }
1.101 raeburn 1868: $datatable .= '<span class="LC_nobreak"><label>'.
1869: '<input type="checkbox" name="'.$context.'_'.$item.
1870: '" value="'.$type.'" '.$checked.'/>'.$titles{$item}.
1871: '</label></span> ';
1.72 raeburn 1872: }
1.101 raeburn 1873: }
1874: if ($context eq 'requestcourses') {
1875: $datatable .= '</tr><tr>';
1876: foreach my $item (@usertools) {
1.106 raeburn 1877: $datatable .= '<td style="vertical-align: top">'.$cell{$item}.'</td>';
1.101 raeburn 1878: }
1879: $datatable .= '</tr></table>';
1.72 raeburn 1880: }
1.86 raeburn 1881: $datatable .= '</td>';
1.163 raeburn 1882: unless (($context eq 'requestcourses') ||
1883: ($context eq 'requestauthor')) {
1.86 raeburn 1884: $datatable .=
1.197 raeburn 1885: '<td class="LC_right_item">'.
1886: '<span class="LC_nobreak">'.&mt('Portfolio').': '.
1.3 raeburn 1887: '<input type="text" name="quota_'.$type.
1.72 raeburn 1888: '" value="'.$currdefquota.
1.197 raeburn 1889: '" size="5" /></span>'.(' ' x 2).
1890: '<span class="LC_nobreak">'.&mt('Authoring').': '.
1891: '<input type="text" name="authorquota_'.$type.
1892: '" value="'.$currauthorquota.
1893: '" size="5" /></span></td>';
1.86 raeburn 1894: }
1895: $datatable .= '</tr>';
1.3 raeburn 1896: }
1897: }
1898: }
1.163 raeburn 1899: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 1900: $defaultquota = '20';
1.197 raeburn 1901: $authorquota = '500';
1.86 raeburn 1902: if (ref($settings) eq 'HASH') {
1903: if (ref($settings->{'defaultquota'}) eq 'HASH') {
1904: $defaultquota = $settings->{'defaultquota'}->{'default'};
1905: } elsif (defined($settings->{'default'})) {
1906: $defaultquota = $settings->{'default'};
1907: }
1.197 raeburn 1908: if (ref($settings->{'authorquota'}) eq 'HASH') {
1909: $authorquota = $settings->{'authorquota'}->{'default'};
1910: }
1.3 raeburn 1911: }
1912: }
1913: $typecount ++;
1914: $css_class = $typecount%2?' class="LC_odd_row"':'';
1915: $datatable .= '<tr'.$css_class.'>'.
1.26 raeburn 1916: '<td>'.$othertitle.'</td>'.
1.72 raeburn 1917: '<td class="LC_left_item">';
1.101 raeburn 1918: if ($context eq 'requestcourses') {
1919: $datatable .= '<table><tr>';
1920: }
1921: my %defcell;
1.72 raeburn 1922: foreach my $item (@usertools) {
1.101 raeburn 1923: if ($context eq 'requestcourses') {
1924: my ($curroption,$currlimit);
1925: if (ref($settings) eq 'HASH') {
1926: if (ref($settings->{$item}) eq 'HASH') {
1927: $curroption = $settings->{$item}->{'default'};
1928: if ($curroption =~ /^autolimit=(\d*)$/) {
1929: $currlimit = $1;
1930: }
1931: }
1932: }
1933: if (!$curroption) {
1934: $curroption = 'norequest';
1935: }
1936: $datatable .= '<th>'.$titles{$item}.'</th>';
1937: foreach my $option (@options) {
1938: my $val = $option;
1939: if ($option eq 'norequest') {
1940: $val = 0;
1941: }
1942: if ($option eq 'validate') {
1943: my $canvalidate = 0;
1944: if (ref($validations{$item}) eq 'HASH') {
1945: if ($validations{$item}{'default'}) {
1946: $canvalidate = 1;
1947: }
1948: }
1949: next if (!$canvalidate);
1950: }
1951: my $checked = '';
1952: if ($option eq $curroption) {
1953: $checked = ' checked="checked"';
1954: } elsif ($option eq 'autolimit') {
1955: if ($curroption =~ /^autolimit/) {
1956: $checked = ' checked="checked"';
1957: }
1958: }
1959: $defcell{$item} .= '<span class="LC_nobreak"><label>'.
1960: '<input type="radio" name="crsreq_'.$item.
1961: '_default" value="'.$val.'"'.$checked.' />'.
1962: $titles{$option}.'</label>';
1963: if ($option eq 'autolimit') {
1.127 raeburn 1964: $defcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 1965: $item.'_limit_default" size="1" '.
1966: 'value="'.$currlimit.'" />';
1967: }
1.127 raeburn 1968: $defcell{$item} .= '</span> ';
1.104 raeburn 1969: if ($option eq 'autolimit') {
1.127 raeburn 1970: $defcell{$item} .= $titles{'unlimited'};
1.104 raeburn 1971: }
1.101 raeburn 1972: }
1.163 raeburn 1973: } elsif ($context eq 'requestauthor') {
1974: my $curroption;
1975: if (ref($settings) eq 'HASH') {
1.172 raeburn 1976: $curroption = $settings->{'default'};
1.163 raeburn 1977: }
1978: if (!$curroption) {
1979: $curroption = 'norequest';
1980: }
1981: foreach my $option (@options) {
1982: my $val = $option;
1983: if ($option eq 'norequest') {
1984: $val = 0;
1985: }
1986: my $checked = '';
1987: if ($option eq $curroption) {
1988: $checked = ' checked="checked"';
1989: }
1990: $datatable .= '<span class="LC_nobreak"><label>'.
1991: '<input type="radio" name="authorreq_default"'.
1992: ' value="'.$val.'"'.$checked.' />'.
1993: $titles{$option}.'</label></span> ';
1994: }
1.101 raeburn 1995: } else {
1996: my $checked = 'checked="checked" ';
1997: if (ref($settings) eq 'HASH') {
1998: if (ref($settings->{$item}) eq 'HASH') {
1999: if ($settings->{$item}->{'default'} == 0) {
2000: $checked = '';
2001: } elsif ($settings->{$item}->{'default'} == 1) {
2002: $checked = 'checked="checked" ';
2003: }
1.78 raeburn 2004: }
1.72 raeburn 2005: }
1.101 raeburn 2006: $datatable .= '<span class="LC_nobreak"><label>'.
2007: '<input type="checkbox" name="'.$context.'_'.$item.
2008: '" value="default" '.$checked.'/>'.$titles{$item}.
2009: '</label></span> ';
2010: }
2011: }
2012: if ($context eq 'requestcourses') {
2013: $datatable .= '</tr><tr>';
2014: foreach my $item (@usertools) {
1.106 raeburn 2015: $datatable .= '<td style="vertical-align: top">'.$defcell{$item}.'</td>';
1.72 raeburn 2016: }
1.101 raeburn 2017: $datatable .= '</tr></table>';
1.72 raeburn 2018: }
1.86 raeburn 2019: $datatable .= '</td>';
1.163 raeburn 2020: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.197 raeburn 2021: $datatable .= '<td class="LC_right_item">'.
2022: '<span class="LC_nobreak">'.&mt('Portfolio').': '.
1.86 raeburn 2023: '<input type="text" name="defaultquota" value="'.
1.197 raeburn 2024: $defaultquota.'" size="5" /></span>'.(' ' x2).
2025: '<span class="LC_nobreak">'.&mt('Authoring').': '.
2026: '<input type="text" name="authorquota" value="'.
2027: $authorquota.'" size="5" /></span></td>';
1.86 raeburn 2028: }
2029: $datatable .= '</tr>';
1.72 raeburn 2030: $typecount ++;
2031: $css_class = $typecount%2?' class="LC_odd_row"':'';
2032: $datatable .= '<tr'.$css_class.'>'.
1.197 raeburn 2033: '<td>'.&mt('LON-CAPA Advanced Users').'<br />';
1.104 raeburn 2034: if ($context eq 'requestcourses') {
1.109 raeburn 2035: $datatable .= &mt('(overrides affiliation, if set)').
2036: '</td>'.
2037: '<td class="LC_left_item">'.
2038: '<table><tr>';
1.101 raeburn 2039: } else {
1.109 raeburn 2040: $datatable .= &mt('(overrides affiliation, if checked)').
2041: '</td>'.
2042: '<td class="LC_left_item" colspan="2">'.
2043: '<br />';
1.101 raeburn 2044: }
2045: my %advcell;
1.72 raeburn 2046: foreach my $item (@usertools) {
1.101 raeburn 2047: if ($context eq 'requestcourses') {
2048: my ($curroption,$currlimit);
2049: if (ref($settings) eq 'HASH') {
2050: if (ref($settings->{$item}) eq 'HASH') {
2051: $curroption = $settings->{$item}->{'_LC_adv'};
2052: if ($curroption =~ /^autolimit=(\d*)$/) {
2053: $currlimit = $1;
2054: }
2055: }
2056: }
2057: $datatable .= '<th>'.$titles{$item}.'</th>';
1.104 raeburn 2058: my $checked = '';
2059: if ($curroption eq '') {
2060: $checked = ' checked="checked"';
2061: }
2062: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
2063: '<input type="radio" name="crsreq_'.$item.
2064: '__LC_adv" value=""'.$checked.' />'.
2065: &mt('No override set').'</label></span> ';
1.101 raeburn 2066: foreach my $option (@options) {
2067: my $val = $option;
2068: if ($option eq 'norequest') {
2069: $val = 0;
2070: }
2071: if ($option eq 'validate') {
2072: my $canvalidate = 0;
2073: if (ref($validations{$item}) eq 'HASH') {
2074: if ($validations{$item}{'_LC_adv'}) {
2075: $canvalidate = 1;
2076: }
2077: }
2078: next if (!$canvalidate);
2079: }
2080: my $checked = '';
1.104 raeburn 2081: if ($val eq $curroption) {
1.101 raeburn 2082: $checked = ' checked="checked"';
2083: } elsif ($option eq 'autolimit') {
2084: if ($curroption =~ /^autolimit/) {
2085: $checked = ' checked="checked"';
2086: }
2087: }
2088: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
2089: '<input type="radio" name="crsreq_'.$item.
2090: '__LC_adv" value="'.$val.'"'.$checked.' />'.
2091: $titles{$option}.'</label>';
2092: if ($option eq 'autolimit') {
1.127 raeburn 2093: $advcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 2094: $item.'_limit__LC_adv" size="1" '.
2095: 'value="'.$currlimit.'" />';
2096: }
1.127 raeburn 2097: $advcell{$item} .= '</span> ';
1.104 raeburn 2098: if ($option eq 'autolimit') {
1.127 raeburn 2099: $advcell{$item} .= $titles{'unlimited'};
1.104 raeburn 2100: }
1.101 raeburn 2101: }
1.163 raeburn 2102: } elsif ($context eq 'requestauthor') {
2103: my $curroption;
2104: if (ref($settings) eq 'HASH') {
2105: $curroption = $settings->{'_LC_adv'};
2106: }
2107: my $checked = '';
2108: if ($curroption eq '') {
2109: $checked = ' checked="checked"';
2110: }
2111: $datatable .= '<span class="LC_nobreak"><label>'.
2112: '<input type="radio" name="authorreq__LC_adv"'.
2113: ' value=""'.$checked.' />'.
2114: &mt('No override set').'</label></span> ';
2115: foreach my $option (@options) {
2116: my $val = $option;
2117: if ($option eq 'norequest') {
2118: $val = 0;
2119: }
2120: my $checked = '';
2121: if ($val eq $curroption) {
2122: $checked = ' checked="checked"';
2123: }
2124: $datatable .= '<span class="LC_nobreak"><label>'.
1.173 raeburn 2125: '<input type="radio" name="authorreq__LC_adv"'.
2126: ' value="'.$val.'"'.$checked.' />'.
1.163 raeburn 2127: $titles{$option}.'</label></span> ';
2128: }
1.101 raeburn 2129: } else {
2130: my $checked = 'checked="checked" ';
2131: if (ref($settings) eq 'HASH') {
2132: if (ref($settings->{$item}) eq 'HASH') {
2133: if ($settings->{$item}->{'_LC_adv'} == 0) {
2134: $checked = '';
2135: } elsif ($settings->{$item}->{'_LC_adv'} == 1) {
2136: $checked = 'checked="checked" ';
2137: }
1.79 raeburn 2138: }
1.72 raeburn 2139: }
1.101 raeburn 2140: $datatable .= '<span class="LC_nobreak"><label>'.
2141: '<input type="checkbox" name="'.$context.'_'.$item.
2142: '" value="_LC_adv" '.$checked.'/>'.$titles{$item}.
2143: '</label></span> ';
2144: }
2145: }
2146: if ($context eq 'requestcourses') {
2147: $datatable .= '</tr><tr>';
2148: foreach my $item (@usertools) {
1.106 raeburn 2149: $datatable .= '<td style="vertical-align: top">'.$advcell{$item}.'</td>';
1.72 raeburn 2150: }
1.101 raeburn 2151: $datatable .= '</tr></table>';
1.72 raeburn 2152: }
1.98 raeburn 2153: $datatable .= '</td></tr>';
1.30 raeburn 2154: $$rowtotal += $typecount;
1.3 raeburn 2155: return $datatable;
2156: }
2157:
1.163 raeburn 2158: sub print_requestmail {
2159: my ($dom,$action,$settings,$rowtotal) = @_;
1.208 raeburn 2160: my ($now,$datatable,%currapp);
1.102 raeburn 2161: $now = time;
2162: if (ref($settings) eq 'HASH') {
2163: if (ref($settings->{'notify'}) eq 'HASH') {
2164: if ($settings->{'notify'}{'approval'} ne '') {
1.224 raeburn 2165: map {$currapp{$_}=1;} split(/,/,$settings->{'notify'}{'approval'});
1.102 raeburn 2166: }
2167: }
2168: }
1.191 raeburn 2169: my $numinrow = 2;
1.224 raeburn 2170: my $css_class;
2171: $css_class = ($$rowtotal%2? ' class="LC_odd_row"':'');
1.163 raeburn 2172: my $text;
2173: if ($action eq 'requestcourses') {
2174: $text = &mt('Receive notification of course requests requiring approval');
1.224 raeburn 2175: } elsif ($action eq 'requestauthor') {
2176: $text = &mt('Receive notification of Authoring Space requests requiring approval');
1.163 raeburn 2177: } else {
1.224 raeburn 2178: $text = &mt('Receive notification of queued requests for self-created user accounts requiring approval');
1.163 raeburn 2179: }
1.224 raeburn 2180: $datatable = '<tr'.$css_class.'>'.
1.163 raeburn 2181: ' <td>'.$text.'</td>'.
1.102 raeburn 2182: ' <td class="LC_left_item">';
1.191 raeburn 2183: my ($numdc,$table,$rows) = &active_dc_picker($dom,$numinrow,'checkbox',
1.224 raeburn 2184: $action.'notifyapproval',%currapp);
1.191 raeburn 2185: if ($numdc > 0) {
2186: $datatable .= $table;
1.102 raeburn 2187: } else {
2188: $datatable .= &mt('There are no active Domain Coordinators');
2189: }
2190: $datatable .='</td></tr>';
2191: return $datatable;
2192: }
2193:
1.216 raeburn 2194: sub print_studentcode {
2195: my ($settings,$rowtotal) = @_;
2196: my $rownum = 0;
1.218 raeburn 2197: my ($output,%current);
1.271 raeburn 2198: my @crstypes = ('official','unofficial','community','textbook','placement');
1.248 raeburn 2199: if (ref($settings) eq 'HASH') {
2200: if (ref($settings->{'uniquecode'}) eq 'HASH') {
2201: foreach my $type (@crstypes) {
2202: $current{$type} = $settings->{'uniquecode'}{$type};
2203: }
1.218 raeburn 2204: }
2205: }
2206: $output .= '<tr>'.
2207: '<td class="LC_left_item">'.&mt('Generate unique six character code as course identifier?').'</td>'.
2208: '<td class="LC_left_item">';
2209: foreach my $type (@crstypes) {
2210: my $check = ' ';
2211: if ($current{$type}) {
2212: $check = ' checked="checked" ';
2213: }
2214: $output .= '<span class="LC_nobreak"><label>'.
2215: '<input type="checkbox" name="uniquecode" value="'.$type.'"'.$check.'/>'.
2216: &mt($type).'</label></span>'.(' 'x2).' ';
2217: }
2218: $output .= '</td></tr>';
2219: $$rowtotal ++;
2220: return $output;
1.216 raeburn 2221: }
2222:
2223: sub print_textbookcourses {
1.242 raeburn 2224: my ($dom,$type,$settings,$rowtotal) = @_;
1.216 raeburn 2225: my $rownum = 0;
2226: my $css_class;
2227: my $itemcount = 1;
2228: my $maxnum = 0;
2229: my $bookshash;
2230: if (ref($settings) eq 'HASH') {
1.242 raeburn 2231: $bookshash = $settings->{$type};
1.216 raeburn 2232: }
2233: my %ordered;
2234: if (ref($bookshash) eq 'HASH') {
2235: foreach my $item (keys(%{$bookshash})) {
2236: if (ref($bookshash->{$item}) eq 'HASH') {
2237: my $num = $bookshash->{$item}{'order'};
2238: $ordered{$num} = $item;
2239: }
2240: }
2241: }
2242: my $confname = $dom.'-domainconfig';
2243: my $switchserver = &check_switchserver($dom,$confname);
1.242 raeburn 2244: my $maxnum = scalar(keys(%ordered));
2245: my $datatable;
1.216 raeburn 2246: if (keys(%ordered)) {
2247: my @items = sort { $a <=> $b } keys(%ordered);
2248: for (my $i=0; $i<@items; $i++) {
2249: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2250: my $key = $ordered{$items[$i]};
2251: my %coursehash=&Apache::lonnet::coursedescription($key);
2252: my $coursetitle = $coursehash{'description'};
1.243 raeburn 2253: my ($subject,$title,$author,$publisher,$image,$imgsrc,$cdom,$cnum);
1.216 raeburn 2254: if (ref($bookshash->{$key}) eq 'HASH') {
2255: $subject = $bookshash->{$key}->{'subject'};
2256: $title = $bookshash->{$key}->{'title'};
1.242 raeburn 2257: if ($type eq 'textbooks') {
1.243 raeburn 2258: $publisher = $bookshash->{$key}->{'publisher'};
1.242 raeburn 2259: $author = $bookshash->{$key}->{'author'};
2260: $image = $bookshash->{$key}->{'image'};
2261: if ($image ne '') {
2262: my ($path,$imagefile) = ($image =~ m{^(.+)/([^/]+)$});
2263: my $imagethumb = "$path/tn-".$imagefile;
2264: $imgsrc = '<img src="'.$imagethumb.'" alt="'.&mt('Textbook image').'" />';
2265: }
1.216 raeburn 2266: }
2267: }
1.242 raeburn 2268: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type".'_'."$key','$type'".');"';
1.216 raeburn 2269: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.242 raeburn 2270: .'<select name="'.$type.'_'.$key.'"'.$chgstr.'>';
1.216 raeburn 2271: for (my $k=0; $k<=$maxnum; $k++) {
2272: my $vpos = $k+1;
2273: my $selstr;
2274: if ($k == $i) {
2275: $selstr = ' selected="selected" ';
2276: }
2277: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2278: }
2279: $datatable .= '</select>'.(' 'x2).
1.242 raeburn 2280: '<label><input type="checkbox" name="'.$type.'_del" value="'.$key.'" />'.
1.216 raeburn 2281: &mt('Delete?').'</label></span></td>'.
2282: '<td colspan="2">'.
1.242 raeburn 2283: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_subject_'.$i.'" value="'.$subject.'" /></span> '.
1.216 raeburn 2284: (' 'x2).
1.242 raeburn 2285: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_title_'.$i.'" value="'.$title.'" /></span> ';
2286: if ($type eq 'textbooks') {
2287: $datatable .= (' 'x2).
1.243 raeburn 2288: '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_publisher_'.$i.'" value="'.$publisher.'" /></span> '.
2289: (' 'x2).
1.242 raeburn 2290: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_author_'.$i.'" value="'.$author.'" /></span> '.
2291: (' 'x2).
2292: '<span class="LC_nobreak">'.&mt('Thumbnail:');
2293: if ($image) {
1.267 raeburn 2294: $datatable .= $imgsrc.
1.242 raeburn 2295: '<label><input type="checkbox" name="'.$type.'_image_del"'.
2296: ' value="'.$key.'" />'.&mt('Delete?').'</label></span> '.
2297: '<span class="LC_nobreak"> '.&mt('Replace:').' ';
2298: }
2299: if ($switchserver) {
2300: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2301: } else {
2302: $datatable .= '<input type="file" name="'.$type.'_image_'.$i.'" value="" />';
2303: }
1.216 raeburn 2304: }
1.242 raeburn 2305: $datatable .= '<input type="hidden" name="'.$type.'_id_'.$i.'" value="'.$type.'_'.$key.'" /></span> '.
1.216 raeburn 2306: '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
2307: $coursetitle.'</span></td></tr>'."\n";
2308: $itemcount ++;
2309: }
2310: }
2311: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.242 raeburn 2312: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type"."_addbook_pos','$type'".');"';
1.216 raeburn 2313: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
1.242 raeburn 2314: '<input type="hidden" name="'.$type.'_maxnum" value="'.$maxnum.'" />'."\n".
2315: '<select name="'.$type.'_addbook_pos"'.$chgstr.'>';
1.216 raeburn 2316: for (my $k=0; $k<$maxnum+1; $k++) {
2317: my $vpos = $k+1;
2318: my $selstr;
2319: if ($k == $maxnum) {
2320: $selstr = ' selected="selected" ';
2321: }
2322: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2323: }
2324: $datatable .= '</select> '."\n".
1.242 raeburn 2325: '<input type="checkbox" name="'.$type.'_addbook" value="1" />'.&mt('Add').'</td>'."\n".
1.216 raeburn 2326: '<td colspan="2">'.
1.242 raeburn 2327: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_addbook_subject" value="" /></span> '."\n".
1.216 raeburn 2328: (' 'x2).
1.242 raeburn 2329: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_addbook_title" value="" /></span> '."\n".
2330: (' 'x2);
2331: if ($type eq 'textbooks') {
1.243 raeburn 2332: $datatable .= '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_addbook_publisher" value="" /></span> '."\n".
2333: (' 'x2).
2334: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_addbook_author" value="" /></span> '."\n".
1.242 raeburn 2335: (' 'x2).
2336: '<span class="LC_nobreak">'.&mt('Image:').' ';
2337: if ($switchserver) {
2338: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2339: } else {
2340: $datatable .= '<input type="file" name="'.$type.'_addbook_image" value="" />';
2341: }
1.216 raeburn 2342: }
2343: $datatable .= '</span>'."\n".
2344: '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
1.242 raeburn 2345: &Apache::loncommon::select_dom_form($env{'request.role.domain'},$type.'_addbook_cdom').
2346: '<input type="text" size="25" name="'.$type.'_addbook_cnum" value="" />'.
1.216 raeburn 2347: &Apache::loncommon::selectcourse_link
1.242 raeburn 2348: ('display',$type.'_addbook_cnum',$type.'_addbook_cdom',undef,undef,undef,'Course');
1.216 raeburn 2349: '</span></td>'."\n".
2350: '</tr>'."\n";
2351: $itemcount ++;
2352: return $datatable;
2353: }
2354:
1.217 raeburn 2355: sub textbookcourses_javascript {
1.242 raeburn 2356: my ($settings) = @_;
2357: return unless(ref($settings) eq 'HASH');
2358: my (%ordered,%total,%jstext);
2359: foreach my $type ('textbooks','templates') {
2360: $total{$type} = 0;
2361: if (ref($settings->{$type}) eq 'HASH') {
2362: foreach my $item (keys(%{$settings->{$type}})) {
2363: if (ref($settings->{$type}->{$item}) eq 'HASH') {
2364: my $num = $settings->{$type}->{$item}{'order'};
2365: $ordered{$type}{$num} = $item;
2366: }
2367: }
2368: $total{$type} = scalar(keys(%{$settings->{$type}}));
2369: }
2370: my @jsarray = ();
2371: foreach my $item (sort {$a <=> $b } (keys(%{$ordered{$type}}))) {
2372: push(@jsarray,$ordered{$type}{$item});
2373: }
2374: $jstext{$type} = ' var '.$type.' = Array('."'".join("','",@jsarray)."'".');'."\n";
1.217 raeburn 2375: }
2376: return <<"ENDSCRIPT";
2377: <script type="text/javascript">
2378: // <![CDATA[
1.242 raeburn 2379: function reorderBooks(form,item,caller) {
1.217 raeburn 2380: var changedVal;
1.242 raeburn 2381: $jstext{'textbooks'};
2382: $jstext{'templates'};
2383: var newpos;
2384: var maxh;
2385: if (caller == 'textbooks') {
2386: newpos = 'textbooks_addbook_pos';
2387: maxh = 1 + $total{'textbooks'};
2388: } else {
2389: newpos = 'templates_addbook_pos';
2390: maxh = 1 + $total{'templates'};
2391: }
1.217 raeburn 2392: var current = new Array;
2393: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
2394: if (item == newpos) {
2395: changedVal = newitemVal;
2396: } else {
2397: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
2398: current[newitemVal] = newpos;
2399: }
1.242 raeburn 2400: if (caller == 'textbooks') {
2401: for (var i=0; i<textbooks.length; i++) {
2402: var elementName = 'textbooks_'+textbooks[i];
2403: if (elementName != item) {
2404: if (form.elements[elementName]) {
2405: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2406: current[currVal] = elementName;
2407: }
2408: }
2409: }
2410: }
2411: if (caller == 'templates') {
2412: for (var i=0; i<templates.length; i++) {
2413: var elementName = 'templates_'+templates[i];
2414: if (elementName != item) {
2415: if (form.elements[elementName]) {
2416: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2417: current[currVal] = elementName;
2418: }
1.217 raeburn 2419: }
2420: }
2421: }
2422: var oldVal;
2423: for (var j=0; j<maxh; j++) {
2424: if (current[j] == undefined) {
2425: oldVal = j;
2426: }
2427: }
2428: if (oldVal < changedVal) {
2429: for (var k=oldVal+1; k<=changedVal ; k++) {
2430: var elementName = current[k];
2431: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
2432: }
2433: } else {
2434: for (var k=changedVal; k<oldVal; k++) {
2435: var elementName = current[k];
2436: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
2437: }
2438: }
2439: return;
2440: }
2441:
2442: // ]]>
2443: </script>
2444:
2445: ENDSCRIPT
2446: }
2447:
1.267 raeburn 2448: sub ltitools_javascript {
2449: my ($settings) = @_;
2450: return unless(ref($settings) eq 'HASH');
2451: my (%ordered,$total,%jstext);
2452: $total = 0;
2453: foreach my $item (keys(%{$settings})) {
2454: if (ref($settings->{$item}) eq 'HASH') {
2455: my $num = $settings->{$item}{'order'};
2456: $ordered{$num} = $item;
2457: }
2458: }
2459: $total = scalar(keys(%{$settings}));
2460: my @jsarray = ();
2461: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
2462: push(@jsarray,$ordered{$item});
2463: }
2464: my $jstext = ' var ltitools = Array('."'".join("','",@jsarray)."'".');'."\n";
2465: return <<"ENDSCRIPT";
2466: <script type="text/javascript">
2467: // <![CDATA[
2468: function reorderLTI(form,item) {
2469: var changedVal;
2470: $jstext
2471: var newpos = 'ltitools_add_pos';
2472: var maxh = 1 + $total;
2473: var current = new Array;
2474: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
2475: if (item == newpos) {
2476: changedVal = newitemVal;
2477: } else {
2478: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
2479: current[newitemVal] = newpos;
2480: }
2481: for (var i=0; i<ltitools.length; i++) {
2482: var elementName = 'ltitools_'+ltitools[i];
2483: if (elementName != item) {
2484: if (form.elements[elementName]) {
2485: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2486: current[currVal] = elementName;
2487: }
2488: }
2489: }
2490: var oldVal;
2491: for (var j=0; j<maxh; j++) {
2492: if (current[j] == undefined) {
2493: oldVal = j;
2494: }
2495: }
2496: if (oldVal < changedVal) {
2497: for (var k=oldVal+1; k<=changedVal ; k++) {
2498: var elementName = current[k];
2499: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
2500: }
2501: } else {
2502: for (var k=changedVal; k<oldVal; k++) {
2503: var elementName = current[k];
2504: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
2505: }
2506: }
2507: return;
2508: }
2509:
2510: // ]]>
2511: </script>
2512:
2513: ENDSCRIPT
2514: }
2515:
1.3 raeburn 2516: sub print_autoenroll {
1.30 raeburn 2517: my ($dom,$settings,$rowtotal) = @_;
1.3 raeburn 2518: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
1.274 raeburn 2519: my ($defdom,$runon,$runoff,$coownerson,$coownersoff,$failsafe);
1.3 raeburn 2520: if (ref($settings) eq 'HASH') {
2521: if (exists($settings->{'run'})) {
2522: if ($settings->{'run'} eq '0') {
2523: $runoff = ' checked="checked" ';
2524: $runon = ' ';
2525: } else {
2526: $runon = ' checked="checked" ';
2527: $runoff = ' ';
2528: }
2529: } else {
2530: if ($autorun) {
2531: $runon = ' checked="checked" ';
2532: $runoff = ' ';
2533: } else {
2534: $runoff = ' checked="checked" ';
2535: $runon = ' ';
2536: }
2537: }
1.129 raeburn 2538: if (exists($settings->{'co-owners'})) {
2539: if ($settings->{'co-owners'} eq '0') {
2540: $coownersoff = ' checked="checked" ';
2541: $coownerson = ' ';
2542: } else {
2543: $coownerson = ' checked="checked" ';
2544: $coownersoff = ' ';
2545: }
2546: } else {
2547: $coownersoff = ' checked="checked" ';
2548: $coownerson = ' ';
2549: }
1.3 raeburn 2550: if (exists($settings->{'sender_domain'})) {
2551: $defdom = $settings->{'sender_domain'};
2552: }
1.274 raeburn 2553: if (exists($settings->{'autofailsafe'})) {
2554: $failsafe = $settings->{'autofailsafe'};
2555: }
1.14 raeburn 2556: } else {
2557: if ($autorun) {
2558: $runon = ' checked="checked" ';
2559: $runoff = ' ';
2560: } else {
2561: $runoff = ' checked="checked" ';
2562: $runon = ' ';
2563: }
1.3 raeburn 2564: }
2565: my $domform = &Apache::loncommon::select_dom_form($defdom,'sender_domain',1);
1.39 raeburn 2566: my $notif_sender;
2567: if (ref($settings) eq 'HASH') {
2568: $notif_sender = $settings->{'sender_uname'};
2569: }
1.3 raeburn 2570: my $datatable='<tr class="LC_odd_row">'.
2571: '<td>'.&mt('Auto-enrollment active?').'</td>'.
1.8 raeburn 2572: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 2573: '<input type="radio" name="autoenroll_run"'.
1.8 raeburn 2574: $runon.' value="1" />'.&mt('Yes').'</label> '.
2575: '<label><input type="radio" name="autoenroll_run"'.
1.14 raeburn 2576: $runoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 2577: '</tr><tr>'.
2578: '<td>'.&mt('Notification messages - sender').
1.8 raeburn 2579: '</td><td class="LC_right_item"><span class="LC_nobreak">'.
1.3 raeburn 2580: &mt('username').': '.
2581: '<input type="text" name="sender_uname" value="'.
1.39 raeburn 2582: $notif_sender.'" size="10" /> '.&mt('domain').
1.129 raeburn 2583: ': '.$domform.'</span></td></tr>'.
2584: '<tr class="LC_odd_row">'.
2585: '<td>'.&mt('Automatically assign co-ownership').'</td>'.
2586: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2587: '<input type="radio" name="autoassign_coowners"'.
2588: $coownerson.' value="1" />'.&mt('Yes').'</label> '.
2589: '<label><input type="radio" name="autoassign_coowners"'.
2590: $coownersoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.274 raeburn 2591: '</tr><tr>'.
2592: '<td>'.&mt('Failsafe for no drops when institutional data missing').'</td>'.
2593: '<td class="LC_right_item"><span class="LC_nobreak">'.
2594: '<input type="text" name="autoenroll_failsafe"'.
2595: ' value="'.$failsafe.'" size="4" /></td></tr>';
2596: $$rowtotal += 4;
1.3 raeburn 2597: return $datatable;
2598: }
2599:
2600: sub print_autoupdate {
1.30 raeburn 2601: my ($position,$dom,$settings,$rowtotal) = @_;
1.3 raeburn 2602: my $datatable;
2603: if ($position eq 'top') {
2604: my $updateon = ' ';
2605: my $updateoff = ' checked="checked" ';
2606: my $classlistson = ' ';
2607: my $classlistsoff = ' checked="checked" ';
2608: if (ref($settings) eq 'HASH') {
2609: if ($settings->{'run'} eq '1') {
2610: $updateon = $updateoff;
2611: $updateoff = ' ';
2612: }
2613: if ($settings->{'classlists'} eq '1') {
2614: $classlistson = $classlistsoff;
2615: $classlistsoff = ' ';
2616: }
2617: }
2618: my %title = (
2619: run => 'Auto-update active?',
2620: classlists => 'Update information in classlists?',
2621: );
2622: $datatable = '<tr class="LC_odd_row">'.
2623: '<td>'.&mt($title{'run'}).'</td>'.
1.8 raeburn 2624: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 2625: '<input type="radio" name="autoupdate_run"'.
1.8 raeburn 2626: $updateon.' value="1" />'.&mt('Yes').'</label> '.
2627: '<label><input type="radio" name="autoupdate_run"'.
2628: $updateoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 2629: '</tr><tr>'.
2630: '<td>'.&mt($title{'classlists'}).'</td>'.
1.8 raeburn 2631: '<td class="LC_right_item"><span class="LC_nobreak">'.
2632: '<label><input type="radio" name="classlists"'.
2633: $classlistson.' value="1" />'.&mt('Yes').'</label> '.
2634: '<label><input type="radio" name="classlists"'.
2635: $classlistsoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 2636: '</tr>';
1.30 raeburn 2637: $$rowtotal += 2;
1.131 raeburn 2638: } elsif ($position eq 'middle') {
2639: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
2640: my $numinrow = 3;
2641: my $locknamesettings;
2642: $datatable .= &insttypes_row($settings,$types,$usertypes,
2643: $dom,$numinrow,$othertitle,
2644: 'lockablenames');
2645: $$rowtotal ++;
1.3 raeburn 2646: } else {
1.44 raeburn 2647: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.132 raeburn 2648: my @fields = ('lastname','firstname','middlename','generation',
1.20 raeburn 2649: 'permanentemail','id');
1.33 raeburn 2650: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1.3 raeburn 2651: my $numrows = 0;
1.26 raeburn 2652: if (ref($types) eq 'ARRAY') {
2653: if (@{$types} > 0) {
2654: $datatable =
2655: &usertype_update_row($settings,$usertypes,\%fieldtitles,
2656: \@fields,$types,\$numrows);
1.30 raeburn 2657: $$rowtotal += @{$types};
1.26 raeburn 2658: }
1.3 raeburn 2659: }
2660: $datatable .=
2661: &usertype_update_row($settings,{'default' => $othertitle},
2662: \%fieldtitles,\@fields,['default'],
2663: \$numrows);
1.30 raeburn 2664: $$rowtotal ++;
1.3 raeburn 2665: }
2666: return $datatable;
2667: }
2668:
1.125 raeburn 2669: sub print_autocreate {
2670: my ($dom,$settings,$rowtotal) = @_;
1.191 raeburn 2671: my (%createon,%createoff,%currhash);
1.125 raeburn 2672: my @types = ('xml','req');
2673: if (ref($settings) eq 'HASH') {
2674: foreach my $item (@types) {
2675: $createoff{$item} = ' checked="checked" ';
2676: $createon{$item} = ' ';
2677: if (exists($settings->{$item})) {
2678: if ($settings->{$item}) {
2679: $createon{$item} = ' checked="checked" ';
2680: $createoff{$item} = ' ';
2681: }
2682: }
2683: }
1.210 raeburn 2684: if ($settings->{'xmldc'} ne '') {
1.191 raeburn 2685: $currhash{$settings->{'xmldc'}} = 1;
2686: }
1.125 raeburn 2687: } else {
2688: foreach my $item (@types) {
2689: $createoff{$item} = ' checked="checked" ';
2690: $createon{$item} = ' ';
2691: }
2692: }
2693: $$rowtotal += 2;
1.191 raeburn 2694: my $numinrow = 2;
1.125 raeburn 2695: my $datatable='<tr class="LC_odd_row">'.
2696: '<td>'.&mt('Create pending official courses from XML files').'</td>'.
2697: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2698: '<input type="radio" name="autocreate_xml"'.
2699: $createon{'xml'}.' value="1" />'.&mt('Yes').'</label> '.
2700: '<label><input type="radio" name="autocreate_xml"'.
1.143 raeburn 2701: $createoff{'xml'}.' value="0" />'.&mt('No').'</label></span>'.
2702: '</td></tr><tr>'.
2703: '<td>'.&mt('Create pending requests for official courses (if validated)').'</td>'.
2704: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2705: '<input type="radio" name="autocreate_req"'.
2706: $createon{'req'}.' value="1" />'.&mt('Yes').'</label> '.
2707: '<label><input type="radio" name="autocreate_req"'.
2708: $createoff{'req'}.' value="0" />'.&mt('No').'</label></span>';
1.191 raeburn 2709: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
2710: 'autocreate_xmldc',%currhash);
1.247 raeburn 2711: $datatable .= '</td></tr><tr class="LC_odd_row"><td>';
1.125 raeburn 2712: if ($numdc > 1) {
1.247 raeburn 2713: $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)').
2714: '</td><td class="LC_left_item">';
1.125 raeburn 2715: } else {
1.247 raeburn 2716: $datatable .= &mt('Course creation processed as:').
2717: '</td><td class="LC_right_item">';
1.125 raeburn 2718: }
1.247 raeburn 2719: $datatable .= $dctable.'</td></tr>';
1.191 raeburn 2720: $$rowtotal += $rows;
1.125 raeburn 2721: return $datatable;
2722: }
2723:
1.23 raeburn 2724: sub print_directorysrch {
1.277 raeburn 2725: my ($position,$dom,$settings,$rowtotal) = @_;
2726: my $datatable;
2727: if ($position eq 'top') {
2728: my $instsrchon = ' ';
2729: my $instsrchoff = ' checked="checked" ';
2730: my ($exacton,$containson,$beginson);
2731: my $instlocalon = ' ';
2732: my $instlocaloff = ' checked="checked" ';
2733: if (ref($settings) eq 'HASH') {
2734: if ($settings->{'available'} eq '1') {
2735: $instsrchon = $instsrchoff;
2736: $instsrchoff = ' ';
2737: }
2738: if ($settings->{'localonly'} eq '1') {
2739: $instlocalon = $instlocaloff;
2740: $instlocaloff = ' ';
2741: }
2742: if (ref($settings->{'searchtypes'}) eq 'ARRAY') {
2743: foreach my $type (@{$settings->{'searchtypes'}}) {
2744: if ($type eq 'exact') {
2745: $exacton = ' checked="checked" ';
2746: } elsif ($type eq 'contains') {
2747: $containson = ' checked="checked" ';
2748: } elsif ($type eq 'begins') {
2749: $beginson = ' checked="checked" ';
2750: }
2751: }
2752: } else {
2753: if ($settings->{'searchtypes'} eq 'exact') {
2754: $exacton = ' checked="checked" ';
2755: } elsif ($settings->{'searchtypes'} eq 'contains') {
2756: $containson = ' checked="checked" ';
2757: } elsif ($settings->{'searchtypes'} eq 'specify') {
1.25 raeburn 2758: $exacton = ' checked="checked" ';
2759: $containson = ' checked="checked" ';
2760: }
2761: }
1.277 raeburn 2762: }
2763: my ($searchtitles,$titleorder) = &sorted_searchtitles();
2764: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
2765:
2766: my $numinrow = 4;
2767: my $cansrchrow = 0;
2768: $datatable='<tr class="LC_odd_row">'.
2769: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Institutional directory search available?').'</span></td>'.
2770: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2771: '<input type="radio" name="dirsrch_available"'.
2772: $instsrchon.' value="1" />'.&mt('Yes').'</label> '.
2773: '<label><input type="radio" name="dirsrch_available"'.
2774: $instsrchoff.' value="0" />'.&mt('No').'</label></span></td>'.
2775: '</tr><tr>'.
2776: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search institution?').'</span></td>'.
2777: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2778: '<input type="radio" name="dirsrch_instlocalonly"'.
2779: $instlocaloff.' value="0" />'.&mt('Yes').'</label> '.
2780: '<label><input type="radio" name="dirsrch_instlocalonly"'.
2781: $instlocalon.' value="1" />'.&mt('No').'</label></span></td>'.
2782: '</tr>';
2783: $$rowtotal += 2;
2784: if (ref($usertypes) eq 'HASH') {
2785: if (keys(%{$usertypes}) > 0) {
2786: $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
2787: $numinrow,$othertitle,'cansearch');
2788: $cansrchrow = 1;
1.25 raeburn 2789: }
1.23 raeburn 2790: }
1.277 raeburn 2791: if ($cansrchrow) {
2792: $$rowtotal ++;
2793: $datatable .= '<tr>';
2794: } else {
2795: $datatable .= '<tr class="LC_odd_row">';
1.26 raeburn 2796: }
1.277 raeburn 2797: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Supported search methods').
2798: '</span></td><td class="LC_left_item" colspan="2"><table><tr>';
2799: foreach my $title (@{$titleorder}) {
2800: if (defined($searchtitles->{$title})) {
2801: my $check = ' ';
2802: if (ref($settings) eq 'HASH') {
2803: if (ref($settings->{'searchby'}) eq 'ARRAY') {
2804: if (grep(/^\Q$title\E$/,@{$settings->{'searchby'}})) {
2805: $check = ' checked="checked" ';
2806: }
1.39 raeburn 2807: }
1.25 raeburn 2808: }
1.277 raeburn 2809: $datatable .= '<td class="LC_left_item">'.
2810: '<span class="LC_nobreak"><label>'.
2811: '<input type="checkbox" name="searchby" '.
2812: 'value="'.$title.'"'.$check.'/>'.
2813: $searchtitles->{$title}.'</label></span></td>';
1.25 raeburn 2814: }
2815: }
1.277 raeburn 2816: $datatable .= '</tr></table></td></tr>';
2817: $$rowtotal ++;
2818: if ($cansrchrow) {
2819: $datatable .= '<tr class="LC_odd_row">';
2820: } else {
2821: $datatable .= '<tr>';
2822: }
2823: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Search latitude').'</span></td>'.
2824: '<td class="LC_left_item" colspan="2">'.
2825: '<span class="LC_nobreak"><label>'.
2826: '<input type="checkbox" name="searchtypes" '.
2827: $exacton.' value="exact" />'.&mt('Exact match').
2828: '</label> '.
2829: '<label><input type="checkbox" name="searchtypes" '.
2830: $beginson.' value="begins" />'.&mt('Begins with').
2831: '</label> '.
2832: '<label><input type="checkbox" name="searchtypes" '.
2833: $containson.' value="contains" />'.&mt('Contains').
2834: '</label></span></td></tr>';
2835: $$rowtotal ++;
1.26 raeburn 2836: } else {
1.277 raeburn 2837: my $domsrchon = ' checked="checked" ';
2838: my $domsrchoff = ' ';
2839: my $domlocalon = ' ';
2840: my $domlocaloff = ' checked="checked" ';
2841: if (ref($settings) eq 'HASH') {
2842: if ($settings->{'lclocalonly'} eq '1') {
2843: $domlocalon = $domlocaloff;
2844: $domlocaloff = ' ';
2845: }
2846: if ($settings->{'lcavailable'} eq '0') {
2847: $domsrchoff = $domsrchon;
2848: $domsrchon = ' ';
2849: }
2850: }
2851: $datatable='<tr class="LC_odd_row">'.
2852: '<td colspan="2"><span class ="LC_nobreak">'.&mt('LON-CAPA directory search available?').'</span></td>'.
2853: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2854: '<input type="radio" name="dirsrch_domavailable"'.
2855: $domsrchon.' value="1" />'.&mt('Yes').'</label> '.
2856: '<label><input type="radio" name="dirsrch_domavailable"'.
2857: $domsrchoff.' value="0" />'.&mt('No').'</label></span></td>'.
2858: '</tr><tr>'.
2859: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search LON-CAPA domain?').'</span></td>'.
2860: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2861: '<input type="radio" name="dirsrch_domlocalonly"'.
2862: $domlocaloff.' value="0" />'.&mt('Yes').'</label> '.
2863: '<label><input type="radio" name="dirsrch_domlocalonly"'.
2864: $domlocalon.' value="1" />'.&mt('No').'</label></span></td>'.
2865: '</tr>';
2866: $$rowtotal += 2;
1.26 raeburn 2867: }
1.25 raeburn 2868: return $datatable;
2869: }
2870:
1.28 raeburn 2871: sub print_contacts {
1.30 raeburn 2872: my ($dom,$settings,$rowtotal) = @_;
1.28 raeburn 2873: my $datatable;
2874: my @contacts = ('adminemail','supportemail');
1.134 raeburn 2875: my (%checked,%to,%otheremails,%bccemails);
1.102 raeburn 2876: my @mailings = ('errormail','packagesmail','lonstatusmail','helpdeskmail',
1.203 raeburn 2877: 'requestsmail','updatesmail','idconflictsmail');
1.28 raeburn 2878: foreach my $type (@mailings) {
2879: $otheremails{$type} = '';
2880: }
1.134 raeburn 2881: $bccemails{'helpdeskmail'} = '';
1.28 raeburn 2882: if (ref($settings) eq 'HASH') {
2883: foreach my $item (@contacts) {
2884: if (exists($settings->{$item})) {
2885: $to{$item} = $settings->{$item};
2886: }
2887: }
2888: foreach my $type (@mailings) {
2889: if (exists($settings->{$type})) {
2890: if (ref($settings->{$type}) eq 'HASH') {
2891: foreach my $item (@contacts) {
2892: if ($settings->{$type}{$item}) {
2893: $checked{$type}{$item} = ' checked="checked" ';
2894: }
2895: }
2896: $otheremails{$type} = $settings->{$type}{'others'};
1.134 raeburn 2897: if ($type eq 'helpdeskmail') {
2898: $bccemails{$type} = $settings->{$type}{'bcc'};
2899: }
1.28 raeburn 2900: }
1.89 raeburn 2901: } elsif ($type eq 'lonstatusmail') {
2902: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
1.28 raeburn 2903: }
2904: }
2905: } else {
2906: $to{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
2907: $to{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
2908: $checked{'errormail'}{'adminemail'} = ' checked="checked" ';
2909: $checked{'packagesmail'}{'adminemail'} = ' checked="checked" ';
1.89 raeburn 2910: $checked{'helpdeskmail'}{'supportemail'} = ' checked="checked" ';
2911: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
1.102 raeburn 2912: $checked{'requestsmail'}{'adminemail'} = ' checked="checked" ';
1.190 raeburn 2913: $checked{'updatesmail'}{'adminemail'} = ' checked="checked" ';
1.203 raeburn 2914: $checked{'idconflictsmail'}{'adminemail'} = ' checked="checked" ';
1.28 raeburn 2915: }
2916: my ($titles,$short_titles) = &contact_titles();
2917: my $rownum = 0;
2918: my $css_class;
2919: foreach my $item (@contacts) {
1.69 raeburn 2920: $css_class = $rownum%2?' class="LC_odd_row"':'';
1.30 raeburn 2921: $datatable .= '<tr'.$css_class.'>'.
2922: '<td><span class="LC_nobreak">'.$titles->{$item}.
2923: '</span></td><td class="LC_right_item">'.
1.28 raeburn 2924: '<input type="text" name="'.$item.'" value="'.
2925: $to{$item}.'" /></td></tr>';
1.203 raeburn 2926: $rownum ++;
1.28 raeburn 2927: }
2928: foreach my $type (@mailings) {
1.69 raeburn 2929: $css_class = $rownum%2?' class="LC_odd_row"':'';
1.28 raeburn 2930: $datatable .= '<tr'.$css_class.'>'.
1.30 raeburn 2931: '<td><span class="LC_nobreak">'.
2932: $titles->{$type}.': </span></td>'.
1.28 raeburn 2933: '<td class="LC_left_item">'.
2934: '<span class="LC_nobreak">';
2935: foreach my $item (@contacts) {
2936: $datatable .= '<label>'.
2937: '<input type="checkbox" name="'.$type.'"'.
2938: $checked{$type}{$item}.
2939: ' value="'.$item.'" />'.$short_titles->{$item}.
2940: '</label> ';
2941: }
2942: $datatable .= '</span><br />'.&mt('Others').': '.
2943: '<input type="text" name="'.$type.'_others" '.
1.134 raeburn 2944: 'value="'.$otheremails{$type}.'" />';
2945: if ($type eq 'helpdeskmail') {
1.136 raeburn 2946: $datatable .= '<br />'.&mt('Bcc:').(' 'x6).
1.134 raeburn 2947: '<input type="text" name="'.$type.'_bcc" '.
2948: 'value="'.$bccemails{$type}.'" />';
2949: }
2950: $datatable .= '</td></tr>'."\n";
1.203 raeburn 2951: $rownum ++;
1.28 raeburn 2952: }
1.203 raeburn 2953: my %choices;
2954: $choices{'reporterrors'} = &mt('E-mail error reports to [_1]',
2955: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
2956: &mt('LON-CAPA core group - MSU'),600,500));
2957: $choices{'reportupdates'} = &mt('E-mail record of completed LON-CAPA updates to [_1]',
2958: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
2959: &mt('LON-CAPA core group - MSU'),600,500));
2960: my @toggles = ('reporterrors','reportupdates');
2961: my %defaultchecked = ('reporterrors' => 'on',
2962: 'reportupdates' => 'on');
2963: (my $reports,$rownum) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
2964: \%choices,$rownum);
2965: $datatable .= $reports;
1.30 raeburn 2966: $$rowtotal += $rownum;
1.28 raeburn 2967: return $datatable;
2968: }
2969:
1.118 jms 2970: sub print_helpsettings {
1.168 raeburn 2971: my ($dom,$confname,$settings,$rowtotal) = @_;
2972: my ($datatable,$itemcount);
1.166 raeburn 2973: $itemcount = 1;
1.168 raeburn 2974: my (%choices,%defaultchecked,@toggles);
2975: $choices{'submitbugs'} = &mt('Display link to: [_1]?',
2976: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
2977: &mt('LON-CAPA bug tracker'),600,500));
2978: %defaultchecked = ('submitbugs' => 'on');
2979: @toggles = ('submitbugs',);
1.166 raeburn 2980:
1.168 raeburn 2981: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
2982: \%choices,$itemcount);
1.166 raeburn 2983: return $datatable;
1.121 raeburn 2984: }
2985:
2986: sub radiobutton_prefs {
1.192 raeburn 2987: my ($settings,$toggles,$defaultchecked,$choices,$itemcount,$onclick,
1.257 raeburn 2988: $additional,$align) = @_;
1.121 raeburn 2989: return unless ((ref($toggles) eq 'ARRAY') && (ref($defaultchecked) eq 'HASH') &&
2990: (ref($choices) eq 'HASH'));
2991:
1.170 raeburn 2992: my (%checkedon,%checkedoff,$datatable,$css_class);
1.121 raeburn 2993:
2994: foreach my $item (@{$toggles}) {
2995: if ($defaultchecked->{$item} eq 'on') {
1.118 jms 2996: $checkedon{$item} = ' checked="checked" ';
2997: $checkedoff{$item} = ' ';
1.121 raeburn 2998: } elsif ($defaultchecked->{$item} eq 'off') {
1.118 jms 2999: $checkedoff{$item} = ' checked="checked" ';
3000: $checkedon{$item} = ' ';
3001: }
3002: }
3003: if (ref($settings) eq 'HASH') {
1.121 raeburn 3004: foreach my $item (@{$toggles}) {
1.118 jms 3005: if ($settings->{$item} eq '1') {
3006: $checkedon{$item} = ' checked="checked" ';
3007: $checkedoff{$item} = ' ';
3008: } elsif ($settings->{$item} eq '0') {
3009: $checkedoff{$item} = ' checked="checked" ';
3010: $checkedon{$item} = ' ';
3011: }
3012: }
1.121 raeburn 3013: }
1.192 raeburn 3014: if ($onclick) {
3015: $onclick = ' onclick="'.$onclick.'"';
3016: }
1.121 raeburn 3017: foreach my $item (@{$toggles}) {
1.118 jms 3018: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.121 raeburn 3019: $datatable .=
1.192 raeburn 3020: '<tr'.$css_class.'><td valign="top">'.
3021: '<span class="LC_nobreak">'.$choices->{$item}.
1.257 raeburn 3022: '</span></td>';
3023: if ($align eq 'left') {
3024: $datatable .= '<td class="LC_left_item">';
3025: } else {
3026: $datatable .= '<td class="LC_right_item">';
3027: }
3028: $datatable .=
3029: '<span class="LC_nobreak">'.
1.118 jms 3030: '<label><input type="radio" name="'.
1.192 raeburn 3031: $item.'" '.$checkedon{$item}.' value="1"'.$onclick.' />'.&mt('Yes').
1.118 jms 3032: '</label> <label><input type="radio" name="'.$item.'" '.
1.192 raeburn 3033: $checkedoff{$item}.' value="0"'.$onclick.' />'.&mt('No').'</label>'.
3034: '</span>'.$additional.
3035: '</td>'.
1.118 jms 3036: '</tr>';
3037: $itemcount ++;
1.121 raeburn 3038: }
3039: return ($datatable,$itemcount);
3040: }
3041:
1.267 raeburn 3042: sub print_ltitools {
3043: my ($dom,$settings,$rowtotal) = @_;
3044: my $rownum = 0;
3045: my $css_class;
3046: my $itemcount = 1;
3047: my $maxnum = 0;
3048: my %ordered;
3049: if (ref($settings) eq 'HASH') {
3050: foreach my $item (keys(%{$settings})) {
3051: if (ref($settings->{$item}) eq 'HASH') {
3052: my $num = $settings->{$item}{'order'};
3053: $ordered{$num} = $item;
3054: }
3055: }
3056: }
3057: my $confname = $dom.'-domainconfig';
3058: my $switchserver = &check_switchserver($dom,$confname);
3059: my $maxnum = scalar(keys(%ordered));
3060: my $datatable = <itools_javascript($settings);
3061: my %lt = <itools_names();
3062: my @courseroles = ('cc','in','ta','ep','st');
3063: my @ltiroles = qw(Instructor ContentDeveloper TeachingAssistant Learner);
3064: my @fields = ('fullname','firstname','lastname','email','user','roles');
3065: if (keys(%ordered)) {
3066: my @items = sort { $a <=> $b } keys(%ordered);
3067: for (my $i=0; $i<@items; $i++) {
3068: $css_class = $itemcount%2?' class="LC_odd_row"':'';
3069: my $item = $ordered{$items[$i]};
3070: my ($title,$key,$secret,$url,$imgsrc,$version);
3071: if (ref($settings->{$item}) eq 'HASH') {
3072: $title = $settings->{$item}->{'title'};
3073: $url = $settings->{$item}->{'url'};
3074: $key = $settings->{$item}->{'key'};
3075: $secret = $settings->{$item}->{'secret'};
3076: my $image = $settings->{$item}->{'image'};
3077: if ($image ne '') {
3078: $imgsrc = '<img src="'.$image.'" alt="'.&mt('Tool Provider icon').'" />';
3079: }
3080: }
3081: my $chgstr = ' onchange="javascript:reorderLTI(this.form,'."'ltitools_".$item."'".');"';
3082: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
3083: .'<select name="ltitools_'.$item.'"'.$chgstr.'>';
3084: for (my $k=0; $k<=$maxnum; $k++) {
3085: my $vpos = $k+1;
3086: my $selstr;
3087: if ($k == $i) {
3088: $selstr = ' selected="selected" ';
3089: }
3090: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
3091: }
3092: $datatable .= '</select>'.(' 'x2).
3093: '<label><input type="checkbox" name="ltitools_del" value="'.$item.'" />'.
3094: &mt('Delete?').'</label></span></td>'.
3095: '<td colspan="2">'.
3096: '<fieldset><legend>'.&mt('Required settings').'</legend>'.
3097: '<span class="LC_nobreak">'.$lt{'title'}.':<input type="text" size="30" name="ltitools_title_'.$i.'" value="'.$title.'" /></span> '.
3098: (' 'x2).
3099: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="ltitools_version_'.$i.'">'.
3100: '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '.
3101: (' 'x2).
3102: '<span class="LC_nobreak">'.$lt{'msgtype'}.':<select name="ltitools_msgtype_'.$i.'">'.
3103: '<option value="basic-lti-launch-request" selected="selected">Launch</option></select></span> '.
3104: '<br /><br />'.
3105: '<span class="LC_nobreak">'.$lt{'url'}.':<input type="text" size="30" name="ltitools_url_'.$i.'"'.
3106: ' value="'.$url.'" /></span>'.
3107: (' 'x2).
3108: '<span class="LC_nobreak">'.$lt{'key'}.
3109: '<input type="text" size="25" name="ltitools_key_'.$i.'" value="'.$key.'" /></span> '.
3110: (' 'x2).
3111: '<span class="LC_nobreak">'.$lt{'secret'}.':'.
3112: '<input type="password" size="20" name="ltitools_secret_'.$i.'" value="'.$secret.'" />'.
3113: '<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>'.
3114: '<input type="hidden" name="ltitools_id_'.$i.'" value="'.$item.'" /></span>'.
3115: '</fieldset>'.
3116: '<fieldset><legend>'.&mt('Optional settings').'</legend>'.
3117: '<span class="LC_nobreak">'.&mt('Display target:');
3118: my %currdisp;
3119: if (ref($settings->{$item}->{'display'}) eq 'HASH') {
3120: if ($settings->{$item}->{'display'}->{'target'} eq 'window') {
3121: $currdisp{'window'} = ' checked="checked"';
3122: } else {
3123: $currdisp{'iframe'} = ' checked="checked"';
3124: }
3125: if ($settings->{$item}->{'display'}->{'width'} =~ /^(\d+)$/) {
3126: $currdisp{'width'} = $1;
3127: }
3128: if ($settings->{$item}->{'display'}->{'height'} =~ /^(\d+)$/) {
3129: $currdisp{'height'} = $1;
3130: }
3131: } else {
3132: $currdisp{'iframe'} = ' checked="checked"';
3133: }
3134: foreach my $disp ('iframe','window') {
3135: $datatable .= '<label><input type="radio" name="ltitools_target_'.$i.'" value="'.$disp.'"'.$currdisp{$disp}.' />'.
3136: $lt{$disp}.'</label>'.(' 'x2);
3137: }
3138: $datatable .= (' 'x4);
3139: foreach my $dimen ('width','height') {
3140: $datatable .= '<label>'.$lt{$dimen}.' '.
3141: '<input type="text" name="ltitools_'.$dimen.'_'.$i.'" size="5" value="'.$currdisp{$dimen}.'" /></label>'.
3142: (' 'x2);
3143: }
3144: $datatable .= '<br />';
3145: foreach my $extra ('passback','roster') {
3146: my $checkedon = '';
3147: my $checkedoff = ' checked="checked"';
3148: if ($settings->{$item}->{$extra}) {
3149: $checkedon = $checkedoff;
3150: $checkedoff = '';
3151: }
3152: $datatable .= $lt{$extra}.' '.
3153: '<label><input type="radio" name="ltitools_'.$extra.'_'.$i.'" value="1"'.$checkedon.' />'.
3154: &mt('Yes').'</label>'.(' 'x2).
3155: '<label><input type="radio" name="ltitools_'.$extra.'_'.$i.'" value="0"'.$checkedoff.' />'.
3156: &mt('No').'</label>'.(' 'x4);
3157: }
3158: $datatable .= '<br /><br /><span class="LC_nobreak">'.$lt{'icon'}.': ';
3159: if ($imgsrc) {
3160: $datatable .= $imgsrc.
3161: '<label><input type="checkbox" name="ltitools_image_del"'.
3162: ' value="'.$item.'" />'.&mt('Delete?').'</label></span> '.
3163: '<span class="LC_nobreak"> '.&mt('Replace:').' ';
3164: } else {
3165: $datatable .= '('.&mt('if larger than 21x21 pixels, image will be scaled').') ';
3166: }
3167: if ($switchserver) {
3168: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
3169: } else {
3170: $datatable .= '<input type="file" name="ltitools_image_'.$i.'" value="" />';
3171: }
3172: $datatable .= '</span></fieldset>';
3173: my (%checkedfields,%rolemaps);
3174: if (ref($settings->{$item}) eq 'HASH') {
3175: if (ref($settings->{$item}->{'fields'}) eq 'HASH') {
3176: %checkedfields = %{$settings->{$item}->{'fields'}};
3177: }
3178: if (ref($settings->{$item}->{'roles'}) eq 'HASH') {
3179: %rolemaps = %{$settings->{$item}->{'roles'}};
3180: $checkedfields{'roles'} = 1;
3181: }
3182: }
3183: $datatable .= '<fieldset><legend>'.&mt('User data sent on launch').'</legend>'.
3184: '<span class="LC_nobreak">';
3185: foreach my $field (@fields) {
3186: my $checked;
3187: if ($checkedfields{$field}) {
3188: $checked = ' checked="checked"';
3189: }
3190: $datatable .= '<label>'.
3191: '<input type="checkbox" name="ltitools_fields_'.$i.'" value="'.$field.'"'.$checked.' />'.
3192: $lt{$field}.'</label>'.(' ' x2);
3193: }
3194: $datatable .= '</span></fieldset>'.
3195: '<fieldset><legend>'.&mt('Role mapping').'</legend><table><tr>';
3196: foreach my $role (@courseroles) {
3197: my ($selected,$selectnone);
3198: if (!$rolemaps{$role}) {
3199: $selectnone = ' selected="selected"';
3200: }
3201: $datatable .= '<td align="center">'.
3202: &Apache::lonnet::plaintext($role,'Course').'<br />'.
3203: '<select name="ltitools_roles_'.$role.'_'.$i.'">'.
3204: '<option value=""'.$selectnone.'>'.&mt('Select').'</option>';
3205: foreach my $ltirole (@ltiroles) {
3206: unless ($selectnone) {
3207: if ($rolemaps{$role} eq $ltirole) {
3208: $selected = ' selected="selected"';
3209: } else {
3210: $selected = '';
3211: }
3212: }
3213: $datatable .= '<option value="'.$ltirole.'"'.$selected.'>'.$ltirole.'</option>';
3214: }
3215: $datatable .= '</select></td>';
3216: }
1.273 raeburn 3217: $datatable .= '</tr></table></fieldset>';
3218: my %courseconfig;
3219: if (ref($settings->{$item}) eq 'HASH') {
3220: if (ref($settings->{$item}->{'crsconf'}) eq 'HASH') {
3221: %courseconfig = %{$settings->{$item}->{'crsconf'}};
3222: }
3223: }
3224: $datatable .= '<fieldset><legend>'.&mt('Configurable in course').'</legend><span class="LC_nobreak">';
3225: foreach my $item ('label','title','target') {
3226: my $checked;
3227: if ($courseconfig{$item}) {
3228: $checked = ' checked="checked"';
3229: }
3230: $datatable .= '<label>'.
3231: '<input type="checkbox" name="ltitools_courseconfig_'.$i.'" value="'.$item.'"'.$checked.' />'.
3232: $lt{'crs'.$item}.'</label>'.(' ' x2)."\n";
3233: }
3234: $datatable .= '</span></fieldset>'.
1.267 raeburn 3235: '<fieldset><legend>'.&mt('Custom items sent on launch').'</legend>'.
3236: '<table><tr><th>'.&mt('Action').'</th><th>'.&mt('Name').'</th><th>'.&mt('Value').'</th></tr>';
3237: if (ref($settings->{$item}->{'custom'}) eq 'HASH') {
3238: my %custom = %{$settings->{$item}->{'custom'}};
3239: if (keys(%custom) > 0) {
3240: foreach my $key (sort(keys(%custom))) {
3241: $datatable .= '<tr><td><span class="LC_nobreak">'.
3242: '<label><input type="checkbox" name="ltitools_customdel_'.$i.'" value="'.
3243: $key.'" />'.&mt('Delete').'</label></span></td><td>'.$key.'</td>'.
3244: '<td><input type="text" name="ltitools_customval_'.$key.'_'.$i.'"'.
3245: ' value="'.$custom{$key}.'" /></td></tr>';
3246: }
3247: }
3248: }
3249: $datatable .= '<tr><td><span class="LC_nobreak">'.
3250: '<label><input type="checkbox" name="ltitools_customadd" value="'.$i.'" />'.
3251: &mt('Add').'</label></span></td><td><input type="text" name="ltitools_custom_name_'.$i.'" />'.
3252: '</td><td><input type="text" name="ltitools_custom_value_'.$i.'" /></td></tr>';
3253: $datatable .= '</table></fieldset></td></tr>'."\n";
3254: $itemcount ++;
3255: }
3256: }
3257: $css_class = $itemcount%2?' class="LC_odd_row"':'';
3258: my $chgstr = ' onchange="javascript:reorderLTI(this.form,'."'ltitools_add_pos'".');"';
3259: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
3260: '<input type="hidden" name="ltitools_maxnum" value="'.$maxnum.'" />'."\n".
3261: '<select name="ltitools_add_pos"'.$chgstr.'>';
3262: for (my $k=0; $k<$maxnum+1; $k++) {
3263: my $vpos = $k+1;
3264: my $selstr;
3265: if ($k == $maxnum) {
3266: $selstr = ' selected="selected" ';
3267: }
3268: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
3269: }
3270: $datatable .= '</select> '."\n".
3271: '<input type="checkbox" name="ltitools_add" value="1" />'.&mt('Add').'</td>'."\n".
3272: '<td colspan="2">'.
3273: '<fieldset><legend>'.&mt('Required settings').'</legend>'.
3274: '<span class="LC_nobreak">'.$lt{'title'}.':<input type="text" size="30" name="ltitools_add_title" value="" /></span> '."\n".
3275: (' 'x2).
3276: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="ltitools_add_version">'.
3277: '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '."\n".
3278: (' 'x2).
3279: '<span class="LC_nobreak">'.$lt{'msgtype'}.':<select name="ltitools_add_msgtype">'.
3280: '<option value="basic-lti-launch-request" selected="selected">Launch</option></select></span> '.
3281: '<br />'.
3282: '<span class="LC_nobreak">'.$lt{'url'}.':<input type="text" size="30" name="ltitools_add_url" value="" /></span> '."\n".
3283: (' 'x2).
3284: '<span class="LC_nobreak">'.$lt{'key'}.':<input type="text" size="25" name="ltitools_add_key" value="" /></span> '."\n".
3285: (' 'x2).
3286: '<span class="LC_nobreak">'.$lt{'secret'}.':<input type="password" size="20" name="ltitools_add_secret" value="" />'.
3287: '<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".
3288: '</fieldset>'.
3289: '<fieldset><legend>'.&mt('Optional settings').'</legend>'.
3290: '<span class="LC_nobreak">'.&mt('Display target:');
3291: my %defaultdisp;
3292: $defaultdisp{'iframe'} = ' checked="checked"';
3293: foreach my $disp ('iframe','window') {
3294: $datatable .= '<label><input type="radio" name="ltitools_add_target" value="'.$disp.'"'.$defaultdisp{$disp}.' />'.
3295: $lt{$disp}.'</label>'.(' 'x2);
3296: }
3297: $datatable .= (' 'x4);
3298: foreach my $dimen ('width','height') {
3299: $datatable .= '<label>'.$lt{$dimen}.' '.
3300: '<input type="text" name="ltitools_add_'.$dimen.'" size="5" /></label>'.
3301: (' 'x2);
3302: }
3303: $datatable .= '<br />';
3304: foreach my $extra ('passback','roster') {
3305: $datatable .= $lt{$extra}.' '.
3306: '<label><input type="radio" name="ltitools_add_'.$extra.'" value="1" />'.
3307: &mt('Yes').'</label>'.(' 'x2).
3308: '<label><input type="radio" name="ltitools_add_'.$extra.'" value="0" checked="checked" />'.
3309: &mt('No').'</label>'.(' 'x4);
3310: }
3311: $datatable .= '<br /><br /><span class="LC_nobreak">'.$lt{'icon'}.': '.
3312: '('.&mt('if larger than 21x21 pixels, image will be scaled').') ';
3313: if ($switchserver) {
3314: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
3315: } else {
3316: $datatable .= '<input type="file" name="ltitools_add_image" value="" />';
3317: }
3318: $datatable .= '</span></fieldset>'.
3319: '<fieldset><legend>'.&mt('User data sent on launch').'</legend>'.
3320: '<span class="LC_nobreak">';
3321: foreach my $field (@fields) {
3322: $datatable .= '<label>'.
3323: '<input type="checkbox" name="ltitools_add_fields" value="'.$field.'" />'.
3324: $lt{$field}.'</label>'.(' ' x2);
3325: }
3326: $datatable .= '</span></fieldset>'.
3327: '<fieldset><legend>'.&mt('Role mapping').'</legend><table><tr>';
3328: foreach my $role (@courseroles) {
3329: my ($checked,$checkednone);
3330: $datatable .= '<td align="center">'.
3331: &Apache::lonnet::plaintext($role,'Course').'<br />'.
3332: '<select name="ltitools_add_roles_'.$role.'">'.
3333: '<option value="" selected="selected">'.&mt('Select').'</option>';
3334: foreach my $ltirole (@ltiroles) {
3335: $datatable .= '<option value="'.$ltirole.'">'.$ltirole.'</option>';
3336: }
3337: $datatable .= '</select></td>';
3338: }
3339: $datatable .= '</tr></table></fieldset>'.
1.273 raeburn 3340: '<fieldset><legend>'.&mt('Configurable in course').'</legend><span class="LC_nobreak">';
3341: foreach my $item ('label','title','target') {
3342: $datatable .= '<label>'.
3343: '<input type="checkbox" name="ltitools_courseconfig" value="'.$item.'" checked="checked" />'.
3344: $lt{'crs'.$item}.'</label>'.(' ' x2)."\n";
3345: }
3346: $datatable .= '</span></fieldset>'.
1.267 raeburn 3347: '<fieldset><legend>'.&mt('Custom items sent on launch').'</legend>'.
3348: '<table><tr><th>'.&mt('Action').'</th><th>'.&mt('Name').'</th><th>'.&mt('Value').'</th></tr>'.
3349: '<tr><td><span class="LC_nobreak">'.
3350: '<label><input type="checkbox" name="ltitools_add_custom" value="1" />'.
3351: &mt('Add').'</label></span></td><td><input type="text" name="ltitools_add_custom_name" />'.
3352: '</td><td><input type="text" name="ltitools_add_custom_value" /></td></tr>'.
3353: '</table></fieldset></td></tr>'."\n".
3354: '</td>'."\n".
3355: '</tr>'."\n";
3356: $itemcount ++;
3357: return $datatable;
3358: }
3359:
3360: sub ltitools_names {
3361: my %lt = &Apache::lonlocal::texthash(
3362: 'title' => 'Title',
3363: 'version' => 'Version',
3364: 'msgtype' => 'Message Type',
3365: 'url' => 'URL',
3366: 'key' => 'Key',
3367: 'secret' => 'Secret',
3368: 'icon' => 'Icon',
3369: 'user' => 'Username:domain',
3370: 'fullname' => 'Full Name',
3371: 'firstname' => 'First Name',
3372: 'lastname' => 'Last Name',
3373: 'email' => 'E-mail',
3374: 'roles' => 'Role',
3375: 'window' => 'Window/Tab',
3376: 'iframe' => 'iFrame',
3377: 'height' => 'Height',
3378: 'width' => 'Width',
3379: 'passback' => 'Tool can return grades:',
3380: 'roster' => 'Tool can retrieve roster:',
1.273 raeburn 3381: 'crstarget' => 'Display target',
3382: 'crslabel' => 'Course label',
3383: 'crstitle' => 'Course title',
1.267 raeburn 3384: );
3385: return %lt;
3386: }
3387:
1.121 raeburn 3388: sub print_coursedefaults {
1.139 raeburn 3389: my ($position,$dom,$settings,$rowtotal) = @_;
1.192 raeburn 3390: my ($css_class,$datatable,%checkedon,%checkedoff,%defaultchecked,@toggles);
1.121 raeburn 3391: my $itemcount = 1;
1.192 raeburn 3392: my %choices = &Apache::lonlocal::texthash (
3393: canuse_pdfforms => 'Course/Community users can create/upload PDF forms',
1.198 raeburn 3394: uploadquota => 'Default quota for files uploaded directly to course/community using Course Editor (MB)',
1.192 raeburn 3395: anonsurvey_threshold => 'Responder count needed before showing submissions for anonymous surveys',
3396: coursecredits => 'Credits can be specified for courses',
1.257 raeburn 3397: uselcmath => 'Math preview uses LON-CAPA previewer (javascript) in place of DragMath (Java)',
3398: usejsme => 'Molecule editor uses JSME (HTML5) in place of JME (Java)',
3399: postsubmit => 'Disable submit button/keypress following student submission',
1.276 raeburn 3400: canclone => "People who may clone a course (besides course's owner and coordinators)",
3401: mysqltables => 'Lifetime (s) of "Temporary" MySQL tables (student performance data) on homeserver',
1.192 raeburn 3402: );
1.198 raeburn 3403: my %staticdefaults = (
3404: anonsurvey_threshold => 10,
3405: uploadquota => 500,
1.257 raeburn 3406: postsubmit => 60,
1.276 raeburn 3407: mysqltables => 172800,
1.198 raeburn 3408: );
1.139 raeburn 3409: if ($position eq 'top') {
1.257 raeburn 3410: %defaultchecked = (
3411: 'canuse_pdfforms' => 'off',
3412: 'uselcmath' => 'on',
3413: 'usejsme' => 'on',
1.264 raeburn 3414: 'canclone' => 'none',
1.257 raeburn 3415: );
3416: @toggles = ('canuse_pdfforms','uselcmath','usejsme');
1.139 raeburn 3417: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
1.257 raeburn 3418: \%choices,$itemcount);
1.264 raeburn 3419: $css_class = $itemcount%2?' class="LC_odd_row"':'';
3420: $datatable .=
3421: '<tr'.$css_class.'><td valign="top">'.
3422: '<span class="LC_nobreak">'.$choices{'canclone'}.
3423: '</span></td><td class="LC_left_item">';
3424: my $currcanclone = 'none';
3425: my $onclick;
3426: my @cloneoptions = ('none','domain');
3427: my %clonetitles = (
3428: none => 'No additional course requesters',
3429: domain => "Any course requester in course's domain",
3430: instcode => 'Course requests for official courses ...',
3431: );
3432: my (%codedefaults,@code_order,@posscodes);
3433: if (&Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
3434: \@code_order) eq 'ok') {
3435: if (@code_order > 0) {
3436: push(@cloneoptions,'instcode');
3437: $onclick = ' onclick="toggleDisplay(this.form,'."'cloneinstcode'".');"';
3438: }
3439: }
3440: if (ref($settings) eq 'HASH') {
3441: if ($settings->{'canclone'}) {
3442: if (ref($settings->{'canclone'}) eq 'HASH') {
3443: if (ref($settings->{'canclone'}{'instcode'}) eq 'ARRAY') {
3444: if (@code_order > 0) {
3445: $currcanclone = 'instcode';
3446: @posscodes = @{$settings->{'canclone'}{'instcode'}};
3447: }
3448: }
3449: } elsif ($settings->{'canclone'} eq 'domain') {
3450: $currcanclone = $settings->{'canclone'};
3451: }
3452: }
3453: }
3454: foreach my $option (@cloneoptions) {
3455: my ($checked,$additional);
3456: if ($currcanclone eq $option) {
3457: $checked = ' checked="checked"';
3458: }
3459: if ($option eq 'instcode') {
3460: if (@code_order) {
3461: my $show = 'none';
3462: if ($checked) {
3463: $show = 'block';
3464: }
3465: $additional = '<div id="cloneinstcode" style="display:'.$show.'" />'.
3466: &mt('Institutional codes for new and cloned course have identical:').
3467: '<br />';
3468: foreach my $item (@code_order) {
3469: my $codechk;
3470: if ($checked) {
3471: if (grep(/^\Q$item\E$/,@posscodes)) {
3472: $codechk = ' checked="checked"';
3473: }
3474: }
3475: $additional .= '<label>'.
3476: '<input type="checkbox" name="clonecode" value="'.$item.'"'.$codechk.' />'.
3477: $item.'</label>';
3478: }
3479: $additional .= (' 'x2).'('.&mt('check as many as needed').')</div>';
3480: }
3481: }
3482: $datatable .=
3483: '<span class="LC_nobreak"><label><input type="radio" name="canclone"'.$checked.
3484: ' value="'.$option.'"'.$onclick.' />'.$clonetitles{$option}.
3485: '</label> '.$additional.'</span><br />';
3486: }
3487: $datatable .= '</td>'.
3488: '</tr>';
3489: $itemcount ++;
1.139 raeburn 3490: } else {
3491: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.276 raeburn 3492: my ($currdefresponder,%defcredits,%curruploadquota,%deftimeout,%currmysql);
1.192 raeburn 3493: my $currusecredits = 0;
1.257 raeburn 3494: my $postsubmitclient = 1;
1.271 raeburn 3495: my @types = ('official','unofficial','community','textbook','placement');
1.139 raeburn 3496: if (ref($settings) eq 'HASH') {
3497: $currdefresponder = $settings->{'anonsurvey_threshold'};
1.198 raeburn 3498: if (ref($settings->{'uploadquota'}) eq 'HASH') {
3499: foreach my $type (keys(%{$settings->{'uploadquota'}})) {
3500: $curruploadquota{$type} = $settings->{'uploadquota'}{$type};
3501: }
3502: }
1.192 raeburn 3503: if (ref($settings->{'coursecredits'}) eq 'HASH') {
1.257 raeburn 3504: foreach my $type (@types) {
3505: next if ($type eq 'community');
3506: $defcredits{$type} = $settings->{'coursecredits'}->{$type};
3507: if ($defcredits{$type} ne '') {
3508: $currusecredits = 1;
3509: }
3510: }
3511: }
3512: if (ref($settings->{'postsubmit'}) eq 'HASH') {
3513: if ($settings->{'postsubmit'}->{'client'} eq 'off') {
3514: $postsubmitclient = 0;
3515: foreach my $type (@types) {
3516: $deftimeout{$type} = $staticdefaults{'postsubmit'};
3517: }
3518: } else {
3519: foreach my $type (@types) {
3520: if (ref($settings->{'postsubmit'}->{'timeout'}) eq 'HASH') {
3521: if ($settings->{'postsubmit'}->{'timeout'}->{$type} =~ /^\d+$/) {
3522: $deftimeout{$type} = $settings->{'postsubmit'}->{'timeout'}->{$type};
3523: } else {
3524: $deftimeout{$type} = $staticdefaults{'postsubmit'};
3525: }
3526: } else {
3527: $deftimeout{$type} = $staticdefaults{'postsubmit'};
3528: }
3529: }
3530: }
3531: } else {
3532: foreach my $type (@types) {
3533: $deftimeout{$type} = $staticdefaults{'postsubmit'};
1.192 raeburn 3534: }
3535: }
1.276 raeburn 3536: if (ref($settings->{'mysqltables'}) eq 'HASH') {
3537: foreach my $type (keys(%{$settings->{'mysqltables'}})) {
3538: $currmysql{$type} = $settings->{'mysqltables'}{$type};
3539: }
3540: } else {
3541: foreach my $type (@types) {
3542: $currmysql{$type} = $staticdefaults{'mysqltables'};
3543: }
3544: }
1.258 raeburn 3545: } else {
3546: foreach my $type (@types) {
3547: $deftimeout{$type} = $staticdefaults{'postsubmit'};
3548: }
1.139 raeburn 3549: }
3550: if (!$currdefresponder) {
1.198 raeburn 3551: $currdefresponder = $staticdefaults{'anonsurvey_threshold'};
1.139 raeburn 3552: } elsif ($currdefresponder < 1) {
3553: $currdefresponder = 1;
3554: }
1.198 raeburn 3555: foreach my $type (@types) {
3556: if ($curruploadquota{$type} eq '') {
3557: $curruploadquota{$type} = $staticdefaults{'uploadquota'};
3558: }
3559: }
1.139 raeburn 3560: $datatable .=
1.192 raeburn 3561: '<tr'.$css_class.'><td><span class="LC_nobreak">'.
3562: $choices{'anonsurvey_threshold'}.
1.139 raeburn 3563: '</span></td>'.
3564: '<td class="LC_right_item"><span class="LC_nobreak">'.
3565: '<input type="text" name="anonsurvey_threshold"'.
3566: ' value="'.$currdefresponder.'" size="5" /></span>'.
1.230 raeburn 3567: '</td></tr>'."\n";
3568: $itemcount ++;
3569: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
3570: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
3571: $choices{'uploadquota'}.
3572: '</span></td>'.
3573: '<td align="right" class="LC_right_item">'.
3574: '<table><tr>';
1.198 raeburn 3575: foreach my $type (@types) {
3576: $datatable .= '<td align="center">'.&mt($type).'<br />'.
3577: '<input type="text" name="uploadquota_'.$type.'"'.
3578: ' value="'.$curruploadquota{$type}.'" size="5" /></td>';
3579: }
3580: $datatable .= '</tr></table></td></tr>'."\n";
1.230 raeburn 3581: $itemcount ++;
1.236 raeburn 3582: my $onclick = "toggleDisplay(this.form,'credits');";
1.210 raeburn 3583: my $display = 'none';
1.192 raeburn 3584: if ($currusecredits) {
3585: $display = 'block';
3586: }
3587: my $additional = '<div id="credits" style="display: '.$display.'">'.
1.257 raeburn 3588: '<i>'.&mt('Default credits').'</i><br /><table><tr>';
3589: foreach my $type (@types) {
3590: next if ($type eq 'community');
3591: $additional .= '<td align="center">'.&mt($type).'<br />'.
3592: '<input type="text" name="'.$type.'_credits"'.
1.258 raeburn 3593: ' value="'.$defcredits{$type}.'" size="3" /></td>';
1.257 raeburn 3594: }
3595: $additional .= '</tr></table></div>'."\n";
1.192 raeburn 3596: %defaultchecked = ('coursecredits' => 'off');
3597: @toggles = ('coursecredits');
3598: my $current = {
3599: 'coursecredits' => $currusecredits,
3600: };
3601: (my $table,$itemcount) =
3602: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
1.257 raeburn 3603: \%choices,$itemcount,$onclick,$additional,'left');
3604: $datatable .= $table;
3605: $onclick = "toggleDisplay(this.form,'studentsubmission');";
3606: my $display = 'none';
3607: if ($postsubmitclient) {
3608: $display = 'block';
3609: }
3610: $additional = '<div id="studentsubmission" style="display: '.$display.'">'.
1.259 raeburn 3611: &mt('Number of seconds submit is disabled').'<br />'.
3612: '<i>'.&mt('Enter 0 to remain disabled until page reload.').'</i><br />'.
3613: '<table><tr>';
1.257 raeburn 3614: foreach my $type (@types) {
3615: $additional .= '<td align="center">'.&mt($type).'<br />'.
3616: '<input type="text" name="'.$type.'_timeout" value="'.
3617: $deftimeout{$type}.'" size="5" /></td>';
3618: }
3619: $additional .= '</tr></table></div>'."\n";
3620: %defaultchecked = ('postsubmit' => 'on');
3621: @toggles = ('postsubmit');
3622: my $current = {
3623: 'postsubmit' => $postsubmitclient,
3624: };
3625: ($table,$itemcount) =
3626: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
3627: \%choices,$itemcount,$onclick,$additional,'left');
1.192 raeburn 3628: $datatable .= $table;
1.276 raeburn 3629: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
3630: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
3631: $choices{'mysqltables'}.
3632: '</span></td>'.
3633: '<td align="right" class="LC_right_item">'.
3634: '<table><tr>';
3635: foreach my $type (@types) {
3636: $datatable .= '<td align="center">'.&mt($type).'<br />'.
3637: '<input type="text" name="mysqltables_'.$type.'"'.
3638: ' value="'.$currmysql{$type}.'" size="5" /></td>';
3639: }
3640: $datatable .= '</tr></table></td></tr>'."\n";
3641: $itemcount ++;
3642:
1.139 raeburn 3643: }
1.192 raeburn 3644: $$rowtotal += $itemcount;
1.121 raeburn 3645: return $datatable;
1.118 jms 3646: }
3647:
1.231 raeburn 3648: sub print_selfenrollment {
3649: my ($position,$dom,$settings,$rowtotal) = @_;
3650: my ($css_class,$datatable);
3651: my $itemcount = 1;
1.271 raeburn 3652: my @types = ('official','unofficial','community','textbook','placement');
1.231 raeburn 3653: if (($position eq 'top') || ($position eq 'middle')) {
1.232 raeburn 3654: my ($rowsref,$titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
3655: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
1.231 raeburn 3656: my @rows;
3657: my $key;
3658: if ($position eq 'top') {
3659: $key = 'admin';
3660: if (ref($rowsref) eq 'ARRAY') {
3661: @rows = @{$rowsref};
3662: }
3663: } elsif ($position eq 'middle') {
3664: $key = 'default';
3665: @rows = ('types','registered','approval','limit');
3666: }
3667: foreach my $row (@rows) {
3668: if (defined($titlesref->{$row})) {
3669: $itemcount ++;
3670: $css_class = $itemcount%2?' class="LC_odd_row"':'';
3671: $datatable .= '<tr'.$css_class.'>'.
3672: '<td>'.$titlesref->{$row}.'</td>'.
3673: '<td class="LC_left_item">'.
3674: '<table><tr>';
3675: my (%current,%currentcap);
3676: if (ref($settings) eq 'HASH') {
3677: if (ref($settings->{$key}) eq 'HASH') {
3678: foreach my $type (@types) {
3679: if (ref($settings->{$key}->{$type}) eq 'HASH') {
3680: $current{$type} = $settings->{$key}->{$type}->{$row};
3681: }
3682: if (($row eq 'limit') && ($key eq 'default')) {
3683: if (ref($settings->{$key}->{$type}) eq 'HASH') {
3684: $currentcap{$type} = $settings->{$key}->{$type}->{'cap'};
3685: }
3686: }
3687: }
3688: }
3689: }
3690: my %roles = (
3691: '0' => &Apache::lonnet::plaintext('dc'),
3692: );
3693:
3694: foreach my $type (@types) {
3695: unless (($row eq 'registered') && ($key eq 'default')) {
3696: $datatable .= '<th>'.&mt($type).'</th>';
3697: }
3698: }
3699: unless (($row eq 'registered') && ($key eq 'default')) {
3700: $datatable .= '</tr><tr>';
3701: }
3702: foreach my $type (@types) {
3703: if ($type eq 'community') {
3704: $roles{'1'} = &mt('Community personnel');
3705: } else {
3706: $roles{'1'} = &mt('Course personnel');
3707: }
3708: $datatable .= '<td style="vertical-align: top">';
3709: if ($position eq 'top') {
3710: my %checked;
3711: if ($current{$type} eq '0') {
3712: $checked{'0'} = ' checked="checked"';
3713: } else {
3714: $checked{'1'} = ' checked="checked"';
3715: }
3716: foreach my $role ('1','0') {
3717: $datatable .= '<span class="LC_nobreak"><label>'.
3718: '<input type="radio" name="selfenrolladmin_'.$row.'_'.$type.'" '.
3719: 'value="'.$role.'"'.$checked{$role}.' />'.
3720: $roles{$role}.'</label></span> ';
3721: }
3722: } else {
3723: if ($row eq 'types') {
3724: my %checked;
3725: if ($current{$type} =~ /^(all|dom)$/) {
3726: $checked{$1} = ' checked="checked"';
3727: } else {
3728: $checked{''} = ' checked="checked"';
3729: }
3730: foreach my $val ('','dom','all') {
3731: $datatable .= '<span class="LC_nobreak"><label>'.
3732: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
3733: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
3734: }
3735: } elsif ($row eq 'registered') {
3736: my %checked;
3737: if ($current{$type} eq '1') {
3738: $checked{'1'} = ' checked="checked"';
3739: } else {
3740: $checked{'0'} = ' checked="checked"';
3741: }
3742: foreach my $val ('0','1') {
3743: $datatable .= '<span class="LC_nobreak"><label>'.
3744: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
3745: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
3746: }
3747: } elsif ($row eq 'approval') {
3748: my %checked;
3749: if ($current{$type} =~ /^([12])$/) {
3750: $checked{$1} = ' checked="checked"';
3751: } else {
3752: $checked{'0'} = ' checked="checked"';
3753: }
3754: for my $val (0..2) {
3755: $datatable .= '<span class="LC_nobreak"><label>'.
3756: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
3757: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
3758: }
3759: } elsif ($row eq 'limit') {
3760: my %checked;
3761: if ($current{$type} =~ /^(allstudents|selfenrolled)$/) {
3762: $checked{$1} = ' checked="checked"';
3763: } else {
3764: $checked{'none'} = ' checked="checked"';
3765: }
3766: my $cap;
3767: if ($currentcap{$type} =~ /^\d+$/) {
3768: $cap = $currentcap{$type};
3769: }
3770: foreach my $val ('none','allstudents','selfenrolled') {
3771: $datatable .= '<span class="LC_nobreak"><label>'.
3772: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
3773: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
3774: }
3775: $datatable .= '<br />'.
3776: '<span class="LC_nobreak">'.&mt('Maximum allowed: ').
3777: '<input type="text" name="selfenrolldefault_cap_'.$type.'" size = "5" value="'.$cap.'" />'.
3778: '</span>';
3779: }
3780: }
3781: $datatable .= '</td>';
3782: }
3783: $datatable .= '</tr>';
3784: }
3785: $datatable .= '</table></td></tr>';
3786: }
3787: } elsif ($position eq 'bottom') {
1.235 raeburn 3788: $datatable .= &print_validation_rows('selfenroll',$dom,$settings,\$itemcount);
3789: }
3790: $$rowtotal += $itemcount;
3791: return $datatable;
3792: }
3793:
3794: sub print_validation_rows {
3795: my ($caller,$dom,$settings,$rowtotal) = @_;
3796: my ($itemsref,$namesref,$fieldsref);
3797: if ($caller eq 'selfenroll') {
3798: ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
3799: } elsif ($caller eq 'requestcourses') {
3800: ($itemsref,$namesref,$fieldsref) = &Apache::loncoursequeueadmin::requestcourses_validation_types();
3801: }
3802: my %currvalidation;
3803: if (ref($settings) eq 'HASH') {
3804: if (ref($settings->{'validation'}) eq 'HASH') {
3805: %currvalidation = %{$settings->{'validation'}};
1.231 raeburn 3806: }
1.235 raeburn 3807: }
3808: my $datatable;
3809: my $itemcount = 0;
3810: foreach my $item (@{$itemsref}) {
3811: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
3812: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
3813: $namesref->{$item}.
3814: '</span></td>'.
3815: '<td class="LC_left_item">';
3816: if (($item eq 'url') || ($item eq 'button')) {
3817: $datatable .= '<span class="LC_nobreak">'.
3818: '<input type="text" name="'.$caller.'_validation_'.$item.'"'.
3819: ' value="'.$currvalidation{$item}.'" size="50" /></span>';
3820: } elsif ($item eq 'fields') {
3821: my @currfields;
3822: if (ref($currvalidation{$item}) eq 'ARRAY') {
3823: @currfields = @{$currvalidation{$item}};
3824: }
3825: foreach my $field (@{$fieldsref}) {
3826: my $check = '';
3827: if (grep(/^\Q$field\E$/,@currfields)) {
3828: $check = ' checked="checked"';
3829: }
3830: $datatable .= '<span class="LC_nobreak"><label>'.
3831: '<input type="checkbox" name="'.$caller.'_validation_fields"'.
3832: ' value="'.$field.'"'.$check.' />'.$field.
3833: '</label></span> ';
3834: }
3835: } elsif ($item eq 'markup') {
3836: $datatable .= '<textarea name="'.$caller.'_validation_markup" cols="50" rows="5" wrap="soft">'.
3837: $currvalidation{$item}.
1.231 raeburn 3838: '</textarea>';
1.235 raeburn 3839: }
3840: $datatable .= '</td></tr>'."\n";
3841: if (ref($rowtotal)) {
1.231 raeburn 3842: $itemcount ++;
3843: }
3844: }
1.235 raeburn 3845: if ($caller eq 'requestcourses') {
3846: my %currhash;
1.248 raeburn 3847: if (ref($settings) eq 'HASH') {
3848: if (ref($settings->{'validation'}) eq 'HASH') {
3849: if ($settings->{'validation'}{'dc'} ne '') {
3850: $currhash{$settings->{'validation'}{'dc'}} = 1;
3851: }
1.235 raeburn 3852: }
3853: }
3854: my $numinrow = 2;
3855: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
3856: 'validationdc',%currhash);
1.247 raeburn 3857: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
3858: $datatable .= '</td></tr><tr'.$css_class.'><td>';
1.235 raeburn 3859: if ($numdc > 1) {
1.247 raeburn 3860: $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)');
1.235 raeburn 3861: } else {
1.247 raeburn 3862: $datatable .= &mt('Course creation processed as: ');
1.235 raeburn 3863: }
1.247 raeburn 3864: $datatable .= '</td><td class="LC_left_item">'.$dctable.'</td></tr>';
1.235 raeburn 3865: $itemcount ++;
3866: }
3867: if (ref($rowtotal)) {
3868: $$rowtotal += $itemcount;
3869: }
1.231 raeburn 3870: return $datatable;
3871: }
3872:
1.137 raeburn 3873: sub print_usersessions {
3874: my ($position,$dom,$settings,$rowtotal) = @_;
3875: my ($css_class,$datatable,%checked,%choices);
1.275 raeburn 3876: my (%by_ip,%by_location,@intdoms,@instdoms);
3877: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
1.145 raeburn 3878:
3879: my @alldoms = &Apache::lonnet::all_domains();
1.152 raeburn 3880: my %serverhomes = %Apache::lonnet::serverhomeIDs;
1.149 raeburn 3881: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.152 raeburn 3882: my %altids = &id_for_thisdom(%servers);
1.145 raeburn 3883: my $itemcount = 1;
3884: if ($position eq 'top') {
1.152 raeburn 3885: if (keys(%serverhomes) > 1) {
1.145 raeburn 3886: my %spareid = ¤t_offloads_to($dom,$settings,\%servers);
1.261 raeburn 3887: my $curroffloadnow;
3888: if (ref($settings) eq 'HASH') {
3889: if (ref($settings->{'offloadnow'}) eq 'HASH') {
3890: $curroffloadnow = $settings->{'offloadnow'};
3891: }
3892: }
3893: $datatable .= &spares_row($dom,\%servers,\%spareid,\%serverhomes,\%altids,$curroffloadnow,$rowtotal);
1.145 raeburn 3894: } else {
1.140 raeburn 3895: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.150 raeburn 3896: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one server.');
1.140 raeburn 3897: }
1.137 raeburn 3898: } else {
1.145 raeburn 3899: if (keys(%by_location) == 0) {
3900: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.150 raeburn 3901: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one institution.');
1.145 raeburn 3902: } else {
3903: my %lt = &usersession_titles();
3904: my $numinrow = 5;
3905: my $prefix;
3906: my @types;
3907: if ($position eq 'bottom') {
3908: $prefix = 'remote';
3909: @types = ('version','excludedomain','includedomain');
3910: } else {
3911: $prefix = 'hosted';
3912: @types = ('excludedomain','includedomain');
3913: }
3914: my (%current,%checkedon,%checkedoff);
3915: my @lcversions = &Apache::lonnet::all_loncaparevs();
3916: my @locations = sort(keys(%by_location));
3917: foreach my $type (@types) {
3918: $checkedon{$type} = '';
3919: $checkedoff{$type} = ' checked="checked"';
3920: }
3921: if (ref($settings) eq 'HASH') {
3922: if (ref($settings->{$prefix}) eq 'HASH') {
3923: foreach my $key (keys(%{$settings->{$prefix}})) {
3924: $current{$key} = $settings->{$prefix}{$key};
3925: if ($key eq 'version') {
3926: if ($current{$key} ne '') {
3927: $checkedon{$key} = ' checked="checked"';
3928: $checkedoff{$key} = '';
3929: }
3930: } elsif (ref($current{$key}) eq 'ARRAY') {
3931: $checkedon{$key} = ' checked="checked"';
3932: $checkedoff{$key} = '';
3933: }
1.137 raeburn 3934: }
3935: }
3936: }
1.145 raeburn 3937: foreach my $type (@types) {
3938: next if ($type ne 'version' && !@locations);
3939: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
3940: $datatable .= '<tr'.$css_class.'>
3941: <td><span class="LC_nobreak">'.$lt{$type}.'</span><br />
3942: <span class="LC_nobreak">
3943: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedoff{$type}.' value="0" />'.&mt('Not in use').'</label>
3944: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedon{$type}.' value="1" />'.&mt('In use').'</label></span></td><td>';
3945: if ($type eq 'version') {
3946: my $selector = '<select name="'.$prefix.'_version">';
3947: foreach my $version (@lcversions) {
3948: my $selected = '';
3949: if ($current{'version'} eq $version) {
3950: $selected = ' selected="selected"';
3951: }
3952: $selector .= ' <option value="'.$version.'"'.
3953: $selected.'>'.$version.'</option>';
3954: }
3955: $selector .= '</select> ';
3956: $datatable .= &mt('remote server must be version: [_1] or later',$selector);
3957: } else {
3958: $datatable.= '<div><input type="button" value="'.&mt('check all').'" '.
3959: 'onclick="javascript:checkAll(document.display.'.$prefix.'_'.$type.')"'.
3960: ' />'.(' 'x2).
3961: '<input type="button" value="'.&mt('uncheck all').'" '.
3962: 'onclick="javascript:uncheckAll(document.display.'.$prefix.'_'.$type.')" />'.
3963: "\n".
3964: '</div><div><table>';
3965: my $rem;
3966: for (my $i=0; $i<@locations; $i++) {
3967: my ($showloc,$value,$checkedtype);
3968: if (ref($by_location{$locations[$i]}) eq 'ARRAY') {
3969: my $ip = $by_location{$locations[$i]}->[0];
3970: if (ref($by_ip{$ip}) eq 'ARRAY') {
3971: $value = join(':',@{$by_ip{$ip}});
3972: $showloc = join(', ',@{$by_ip{$ip}});
3973: if (ref($current{$type}) eq 'ARRAY') {
3974: foreach my $loc (@{$by_ip{$ip}}) {
3975: if (grep(/^\Q$loc\E$/,@{$current{$type}})) {
3976: $checkedtype = ' checked="checked"';
3977: last;
3978: }
3979: }
1.138 raeburn 3980: }
3981: }
3982: }
1.145 raeburn 3983: $rem = $i%($numinrow);
3984: if ($rem == 0) {
3985: if ($i > 0) {
3986: $datatable .= '</tr>';
3987: }
3988: $datatable .= '<tr>';
3989: }
3990: $datatable .= '<td class="LC_left_item">'.
3991: '<span class="LC_nobreak"><label>'.
3992: '<input type="checkbox" name="'.$prefix.'_'.$type.
3993: '" value="'.$value.'"'.$checkedtype.' />'.$showloc.
3994: '</label></span></td>';
1.137 raeburn 3995: }
1.145 raeburn 3996: $rem = @locations%($numinrow);
3997: my $colsleft = $numinrow - $rem;
3998: if ($colsleft > 1 ) {
3999: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
4000: ' </td>';
4001: } elsif ($colsleft == 1) {
4002: $datatable .= '<td class="LC_left_item"> </td>';
1.137 raeburn 4003: }
1.145 raeburn 4004: $datatable .= '</tr></table>';
1.137 raeburn 4005: }
1.145 raeburn 4006: $datatable .= '</td></tr>';
4007: $itemcount ++;
1.137 raeburn 4008: }
4009: }
4010: }
4011: $$rowtotal += $itemcount;
4012: return $datatable;
4013: }
4014:
1.275 raeburn 4015: sub print_ssl {
4016: my ($position,$dom,$settings,$rowtotal) = @_;
4017: my ($css_class,$datatable);
4018: my $lonhost = '';
4019: my $itemcount = 1;
4020: if ($position eq 'top') {
4021: my %domservers = &Apache::lonnet::get_servers($dom);
4022: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4023: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
4024: &LONCAPA::SSL::print_certstatus(\%domservers,'web','domprefs').
4025: '</td></tr>';
4026: $itemcount ++;
4027: } else {
4028: my %titles = &ssl_titles();
4029: my (%by_ip,%by_location,@intdoms,@instdoms);
4030: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
4031: my @alldoms = &Apache::lonnet::all_domains();
4032: my %serverhomes = %Apache::lonnet::serverhomeIDs;
4033: my @domservers = &Apache::lonnet::get_servers($dom);
4034: my %servers = &Apache::lonnet::internet_dom_servers($dom);
4035: my %altids = &id_for_thisdom(%servers);
4036: if ($position eq 'middle') {
4037: foreach my $type ('dom','intdom','other') {
4038: my %checked;
4039: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4040: $datatable .= '<tr'.$css_class.'><td>'.$titles{$type}.'</td>'.
4041: '<td class="LC_right_item">';
4042: my $skip;
4043: if ($type eq 'dom') {
4044: unless (keys(%servers) > 1) {
4045: $datatable .= &mt('Nothing to set here, as there are no other servers/VMs');
4046: $skip = 1;
4047: }
4048: }
4049: if ($type eq 'intdom') {
4050: unless (@instdoms > 1) {
4051: $datatable .= &mt('Nothing to set here, as there are no other domains for this institution');
4052: $skip = 1;
4053: }
4054: } elsif ($type eq 'other') {
4055: if (keys(%by_location) == 0) {
4056: $datatable .= &mt('Nothing to set here, as there are no other institutions');
4057: $skip = 1;
4058: }
4059: }
4060: unless ($skip) {
4061: $checked{'yes'} = ' checked="checked"';
4062: if (ref($settings) eq 'HASH') {
4063: if (ref($settings->{'connect'}) eq 'HASH') {
4064: if ($settings->{'connect'}->{$type} =~ /^(no|req)$/) {
4065: $checked{$1} = $checked{'yes'};
4066: delete($checked{'yes'});
4067: }
4068: }
4069: }
4070: foreach my $option ('no','yes','req') {
4071: $datatable .= '<span class="LC_nobreak"><label>'.
4072: '<input type="radio" name="connect_'.$type.'" '.
4073: 'value="'.$option.'"'.$checked{$option}.' />'.$titles{$option}.
4074: '</label></span>'.(' 'x2);
4075: }
4076: }
4077: $datatable .= '</td></tr>';
4078: $itemcount ++;
4079: }
4080: } else {
4081: my $numinrow = 5;
4082: my $prefix = 'replication';
4083: my @types = ('certreq','nocertreq');
4084: my (%current,%checkedon,%checkedoff);
4085: my @locations = sort(keys(%by_location));
4086: foreach my $type (@types) {
4087: $checkedon{$type} = '';
4088: $checkedoff{$type} = ' checked="checked"';
4089: }
4090: if (ref($settings) eq 'HASH') {
4091: if (ref($settings->{$prefix}) eq 'HASH') {
4092: foreach my $key (keys(%{$settings->{$prefix}})) {
4093: $current{$key} = $settings->{$prefix}{$key};
4094: if (ref($current{$key}) eq 'ARRAY') {
4095: $checkedon{$key} = ' checked="checked"';
4096: $checkedoff{$key} = '';
4097: }
4098: }
4099: }
4100: }
4101: if (@locations > 0) {
4102: foreach my $type (@types) {
4103: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4104: $datatable .= '<tr'.$css_class.'>
4105: <td><span class="LC_nobreak LC_right_item">'.$titles{$type}.'</span><br />
4106: <span class="LC_nobreak">
4107: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedoff{$type}.' value="0" />'.&mt('Not in use').'</label>
4108: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedon{$type}.' value="1" />'.&mt('In use').'</label></span></td><td>
4109: <div><input type="button" value="'.&mt('check all').'" '.
4110: 'onclick="javascript:checkAll(document.display.'.$prefix.'_'.$type.')"'.
4111: ' />'.(' 'x2)."\n".
4112: '<input type="button" value="'.&mt('uncheck all').'" '.
4113: 'onclick="javascript:uncheckAll(document.display.'.$prefix.'_'.$type.')" />'.
4114: "\n".
4115: '</div><div><table>';
4116: my $rem;
4117: for (my $i=0; $i<@locations; $i++) {
4118: my ($showloc,$value,$checkedtype);
4119: if (ref($by_location{$locations[$i]}) eq 'ARRAY') {
4120: my $ip = $by_location{$locations[$i]}->[0];
4121: if (ref($by_ip{$ip}) eq 'ARRAY') {
4122: $value = join(':',@{$by_ip{$ip}});
4123: $showloc = join(', ',@{$by_ip{$ip}});
4124: if (ref($current{$type}) eq 'ARRAY') {
4125: foreach my $loc (@{$by_ip{$ip}}) {
4126: if (grep(/^\Q$loc\E$/,@{$current{$type}})) {
4127: $checkedtype = ' checked="checked"';
4128: last;
4129: }
4130: }
4131: }
4132: }
4133: }
4134: $rem = $i%($numinrow);
4135: if ($rem == 0) {
4136: if ($i > 0) {
4137: $datatable .= '</tr>';
4138: }
4139: $datatable .= '<tr>';
4140: }
4141: $datatable .= '<td class="LC_left_item">'.
4142: '<span class="LC_nobreak"><label>'.
4143: '<input type="checkbox" name="'.$prefix.'_'.$type.
4144: '" value="'.$value.'"'.$checkedtype.' />'.$showloc.
4145: '</label></span></td>';
4146: }
4147: $rem = @locations%($numinrow);
4148: my $colsleft = $numinrow - $rem;
4149: if ($colsleft > 1 ) {
4150: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
4151: ' </td>';
4152: } elsif ($colsleft == 1) {
4153: $datatable .= '<td class="LC_left_item"> </td>';
4154: }
4155: $datatable .= '</tr></table></td></tr>';
4156: $itemcount ++;
4157: }
4158: } else {
4159: $datatable .= '<tr'.$css_class.'><td>'.&mt('Nothing to set here, as there are no other institutions').'</td></tr>';
4160: $itemcount ++;
4161: }
4162: }
4163: }
4164: $$rowtotal += $itemcount;
4165: return $datatable;
4166: }
4167:
4168: sub ssl_titles {
4169: return &Apache::lonlocal::texthash (
4170: dom => 'LON-CAPA servers/VMs from same domain',
4171: intdom => 'LON-CAPA servers/VMs from same "internet" domain',
4172: other => 'External LON-CAPA servers/VMs',
4173: connect => 'Connections to other servers',
4174: replication => 'Replicating content to other institutions',
4175: certreq => 'Client certificate required, but specific domains exempt',
4176: nocertreq => 'No client certificate required, except for specific domains',
4177: no => 'SSL not used',
4178: yes => 'SSL Optional (used if available)',
4179: req => 'SSL Required',
4180: );
4181: }
4182:
1.138 raeburn 4183: sub build_location_hashes {
1.275 raeburn 4184: my ($intdoms,$by_ip,$by_location,$instdoms) = @_;
1.138 raeburn 4185: return unless((ref($intdoms) eq 'ARRAY') && (ref($by_ip) eq 'HASH') &&
1.275 raeburn 4186: (ref($by_location) eq 'HASH') && (ref($instdoms) eq 'ARRAY'));
1.138 raeburn 4187: my %iphost = &Apache::lonnet::get_iphost();
4188: my $primary_id = &Apache::lonnet::domain($env{'request.role.domain'},'primary');
4189: my $primary_ip = &Apache::lonnet::get_host_ip($primary_id);
4190: if (ref($iphost{$primary_ip}) eq 'ARRAY') {
4191: foreach my $id (@{$iphost{$primary_ip}}) {
4192: my $intdom = &Apache::lonnet::internet_dom($id);
4193: unless(grep(/^\Q$intdom\E$/,@{$intdoms})) {
4194: push(@{$intdoms},$intdom);
4195: }
4196: }
4197: }
4198: foreach my $ip (keys(%iphost)) {
4199: if (ref($iphost{$ip}) eq 'ARRAY') {
4200: foreach my $id (@{$iphost{$ip}}) {
4201: my $location = &Apache::lonnet::internet_dom($id);
4202: if ($location) {
1.275 raeburn 4203: if (grep(/^\Q$location\E$/,@{$intdoms})) {
4204: my $dom = &Apache::lonnet::host_domain($id);
4205: unless (grep(/^\Q$dom\E/,@{$instdoms})) {
4206: push(@{$instdoms},$dom);
4207: }
4208: next;
4209: }
1.138 raeburn 4210: if (ref($by_ip->{$ip}) eq 'ARRAY') {
4211: unless(grep(/^\Q$location\E$/,@{$by_ip->{$ip}})) {
4212: push(@{$by_ip->{$ip}},$location);
4213: }
4214: } else {
4215: $by_ip->{$ip} = [$location];
4216: }
4217: }
4218: }
4219: }
4220: }
4221: foreach my $ip (sort(keys(%{$by_ip}))) {
4222: if (ref($by_ip->{$ip}) eq 'ARRAY') {
4223: @{$by_ip->{$ip}} = sort(@{$by_ip->{$ip}});
4224: my $first = $by_ip->{$ip}->[0];
4225: if (ref($by_location->{$first}) eq 'ARRAY') {
4226: unless (grep(/^\Q$ip\E$/,@{$by_location->{$first}})) {
4227: push(@{$by_location->{$first}},$ip);
4228: }
4229: } else {
4230: $by_location->{$first} = [$ip];
4231: }
4232: }
4233: }
4234: return;
4235: }
4236:
1.145 raeburn 4237: sub current_offloads_to {
4238: my ($dom,$settings,$servers) = @_;
4239: my (%spareid,%otherdomconfigs);
1.152 raeburn 4240: if (ref($servers) eq 'HASH') {
1.145 raeburn 4241: foreach my $lonhost (sort(keys(%{$servers}))) {
4242: my $gotspares;
1.152 raeburn 4243: if (ref($settings) eq 'HASH') {
4244: if (ref($settings->{'spares'}) eq 'HASH') {
4245: if (ref($settings->{'spares'}{$lonhost}) eq 'HASH') {
4246: $spareid{$lonhost}{'primary'} = $settings->{'spares'}{$lonhost}{'primary'};
4247: $spareid{$lonhost}{'default'} = $settings->{'spares'}{$lonhost}{'default'};
4248: $gotspares = 1;
4249: }
1.145 raeburn 4250: }
4251: }
4252: unless ($gotspares) {
4253: my $gotspares;
4254: my $serverhomeID =
4255: &Apache::lonnet::get_server_homeID($servers->{$lonhost});
4256: my $serverhomedom =
4257: &Apache::lonnet::host_domain($serverhomeID);
4258: if ($serverhomedom ne $dom) {
4259: if (ref($otherdomconfigs{$serverhomedom} eq 'HASH')) {
4260: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
4261: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
4262: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
4263: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
4264: $gotspares = 1;
4265: }
4266: }
4267: } else {
4268: $otherdomconfigs{$serverhomedom} =
4269: &Apache::lonnet::get_dom('configuration',['usersessions'],$serverhomedom);
4270: if (ref($otherdomconfigs{$serverhomedom}) eq 'HASH') {
4271: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
4272: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
4273: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{$lonhost}) eq 'HASH') {
4274: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
4275: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
4276: $gotspares = 1;
4277: }
4278: }
4279: }
4280: }
4281: }
4282: }
4283: }
4284: unless ($gotspares) {
4285: if ($lonhost eq $Apache::lonnet::perlvar{'lonHostID'}) {
4286: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
4287: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
4288: } else {
4289: my $server_hostname = &Apache::lonnet::hostname($lonhost);
4290: my $server_homeID = &Apache::lonnet::get_server_homeID($server_hostname);
4291: if ($server_homeID eq $Apache::lonnet::perlvar{'lonHostID'}) {
4292: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
4293: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
4294: } else {
1.150 raeburn 4295: my %what = (
4296: spareid => 1,
4297: );
4298: my ($result,$returnhash) =
4299: &Apache::lonnet::get_remote_globals($lonhost,\%what);
4300: if ($result eq 'ok') {
4301: if (ref($returnhash) eq 'HASH') {
4302: if (ref($returnhash->{'spareid'}) eq 'HASH') {
4303: $spareid{$lonhost}{'primary'} = $returnhash->{'spareid'}->{'primary'};
4304: $spareid{$lonhost}{'default'} = $returnhash->{'spareid'}->{'default'};
4305: }
4306: }
1.145 raeburn 4307: }
4308: }
4309: }
4310: }
4311: }
4312: }
4313: return %spareid;
4314: }
4315:
4316: sub spares_row {
1.261 raeburn 4317: my ($dom,$servers,$spareid,$serverhomes,$altids,$curroffloadnow,$rowtotal) = @_;
1.145 raeburn 4318: my $css_class;
4319: my $numinrow = 4;
4320: my $itemcount = 1;
4321: my $datatable;
1.152 raeburn 4322: my %typetitles = &sparestype_titles();
4323: if ((ref($servers) eq 'HASH') && (ref($spareid) eq 'HASH') && (ref($altids) eq 'HASH')) {
1.145 raeburn 4324: foreach my $server (sort(keys(%{$servers}))) {
1.152 raeburn 4325: my $serverhome = &Apache::lonnet::get_server_homeID($servers->{$server});
4326: my ($othercontrol,$serverdom);
4327: if ($serverhome ne $server) {
4328: $serverdom = &Apache::lonnet::host_domain($serverhome);
4329: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
4330: } else {
4331: $serverdom = &Apache::lonnet::host_domain($server);
4332: if ($serverdom ne $dom) {
4333: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
4334: }
4335: }
4336: next unless (ref($spareid->{$server}) eq 'HASH');
1.261 raeburn 4337: my $checkednow;
4338: if (ref($curroffloadnow) eq 'HASH') {
4339: if ($curroffloadnow->{$server}) {
4340: $checkednow = ' checked="checked"';
4341: }
4342: }
1.145 raeburn 4343: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
4344: $datatable .= '<tr'.$css_class.'>
4345: <td rowspan="2">
1.183 bisitz 4346: <span class="LC_nobreak">'.
4347: &mt('[_1] when busy, offloads to:'
1.261 raeburn 4348: ,'<b>'.$server.'</b>').'</span><br />'.
4349: '<span class="LC_nobreak">'."\n".
4350: '<label><input type="checkbox" name="offloadnow" value="'.$server.'"'.$checkednow.' />'.
4351: ' '.&mt('Switch active users on next access').'</label></span>'.
1.183 bisitz 4352: "\n";
1.145 raeburn 4353: my (%current,%canselect);
1.152 raeburn 4354: my @choices =
4355: &possible_newspares($server,$spareid->{$server},$serverhomes,$altids);
4356: foreach my $type ('primary','default') {
4357: if (ref($spareid->{$server}) eq 'HASH') {
1.145 raeburn 4358: if (ref($spareid->{$server}{$type}) eq 'ARRAY') {
4359: my @spares = @{$spareid->{$server}{$type}};
4360: if (@spares > 0) {
1.152 raeburn 4361: if ($othercontrol) {
4362: $current{$type} = join(', ',@spares);
4363: } else {
4364: $current{$type} .= '<table>';
4365: my $numspares = scalar(@spares);
4366: for (my $i=0; $i<@spares; $i++) {
4367: my $rem = $i%($numinrow);
4368: if ($rem == 0) {
4369: if ($i > 0) {
4370: $current{$type} .= '</tr>';
4371: }
4372: $current{$type} .= '<tr>';
1.145 raeburn 4373: }
1.152 raeburn 4374: $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'".');" /> '.
4375: $spareid->{$server}{$type}[$i].
4376: '</label></td>'."\n";
4377: }
4378: my $rem = @spares%($numinrow);
4379: my $colsleft = $numinrow - $rem;
4380: if ($colsleft > 1 ) {
4381: $current{$type} .= '<td colspan="'.$colsleft.
4382: '" class="LC_left_item">'.
4383: ' </td>';
4384: } elsif ($colsleft == 1) {
4385: $current{$type} .= '<td class="LC_left_item"> </td>'."\n";
1.145 raeburn 4386: }
1.152 raeburn 4387: $current{$type} .= '</tr></table>';
1.150 raeburn 4388: }
1.145 raeburn 4389: }
4390: }
4391: if ($current{$type} eq '') {
4392: $current{$type} = &mt('None specified');
4393: }
1.152 raeburn 4394: if ($othercontrol) {
4395: if ($type eq 'primary') {
4396: $canselect{$type} = $othercontrol;
4397: }
4398: } else {
4399: $canselect{$type} =
4400: &mt('Add new [_1]'.$type.'[_2]:','<i>','</i>').' '.
4401: '<select name="newspare_'.$type.'_'.$server.'" '.
4402: 'id="newspare_'.$type.'_'.$server.'" onchange="checkNewSpares('."'$server','$type'".');">'."\n".
4403: '<option value="" selected ="selected">'.&mt('Select').'</option>'."\n";
4404: if (@choices > 0) {
4405: foreach my $lonhost (@choices) {
4406: $canselect{$type} .= '<option value="'.$lonhost.'">'.$lonhost.'</option>'."\n";
4407: }
4408: }
4409: $canselect{$type} .= '</select>'."\n";
4410: }
4411: } else {
4412: $current{$type} = &mt('Could not be determined');
4413: if ($type eq 'primary') {
4414: $canselect{$type} = $othercontrol;
4415: }
1.145 raeburn 4416: }
1.152 raeburn 4417: if ($type eq 'default') {
4418: $datatable .= '<tr'.$css_class.'>';
4419: }
4420: $datatable .= '<td><i>'.$typetitles{$type}.'</i></td>'."\n".
4421: '<td>'.$current{$type}.'</td>'."\n".
4422: '<td>'.$canselect{$type}.'</td></tr>'."\n";
1.145 raeburn 4423: }
4424: $itemcount ++;
4425: }
4426: }
4427: $$rowtotal += $itemcount;
4428: return $datatable;
4429: }
4430:
1.152 raeburn 4431: sub possible_newspares {
4432: my ($server,$currspares,$serverhomes,$altids) = @_;
4433: my $serverhostname = &Apache::lonnet::hostname($server);
4434: my %excluded;
4435: if ($serverhostname ne '') {
4436: %excluded = (
4437: $serverhostname => 1,
4438: );
4439: }
4440: if (ref($currspares) eq 'HASH') {
4441: foreach my $type (keys(%{$currspares})) {
4442: if (ref($currspares->{$type}) eq 'ARRAY') {
4443: if (@{$currspares->{$type}} > 0) {
4444: foreach my $curr (@{$currspares->{$type}}) {
4445: my $hostname = &Apache::lonnet::hostname($curr);
4446: $excluded{$hostname} = 1;
4447: }
4448: }
4449: }
4450: }
4451: }
4452: my @choices;
4453: if ((ref($serverhomes) eq 'HASH') && (ref($altids) eq 'HASH')) {
4454: if (keys(%{$serverhomes}) > 1) {
4455: foreach my $name (sort(keys(%{$serverhomes}))) {
4456: unless ($excluded{$name}) {
4457: if (exists($altids->{$serverhomes->{$name}})) {
4458: push(@choices,$altids->{$serverhomes->{$name}});
4459: } else {
4460: push(@choices,$serverhomes->{$name});
1.145 raeburn 4461: }
4462: }
4463: }
4464: }
4465: }
1.152 raeburn 4466: return sort(@choices);
1.145 raeburn 4467: }
4468:
1.150 raeburn 4469: sub print_loadbalancing {
4470: my ($dom,$settings,$rowtotal) = @_;
4471: my $primary_id = &Apache::lonnet::domain($dom,'primary');
4472: my $intdom = &Apache::lonnet::internet_dom($primary_id);
4473: my $numinrow = 1;
4474: my $datatable;
4475: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.171 raeburn 4476: my (%currbalancer,%currtargets,%currrules,%existing);
4477: if (ref($settings) eq 'HASH') {
4478: %existing = %{$settings};
4479: }
4480: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
4481: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
4482: \%currtargets,\%currrules);
1.150 raeburn 4483: } else {
4484: return;
4485: }
4486: my ($othertitle,$usertypes,$types) =
4487: &Apache::loncommon::sorted_inst_types($dom);
1.209 raeburn 4488: my $rownum = 8;
1.150 raeburn 4489: if (ref($types) eq 'ARRAY') {
4490: $rownum += scalar(@{$types});
4491: }
1.171 raeburn 4492: my @css_class = ('LC_odd_row','LC_even_row');
4493: my $balnum = 0;
4494: my $islast;
4495: my (@toshow,$disabledtext);
4496: if (keys(%currbalancer) > 0) {
4497: @toshow = sort(keys(%currbalancer));
4498: if (scalar(@toshow) < scalar(keys(%servers)) + 1) {
4499: push(@toshow,'');
4500: }
4501: } else {
4502: @toshow = ('');
4503: $disabledtext = &mt('No existing load balancer');
4504: }
4505: foreach my $lonhost (@toshow) {
4506: if ($balnum == scalar(@toshow)-1) {
4507: $islast = 1;
4508: } else {
4509: $islast = 0;
4510: }
4511: my $cssidx = $balnum%2;
4512: my $targets_div_style = 'display: none';
4513: my $disabled_div_style = 'display: block';
4514: my $homedom_div_style = 'display: none';
4515: $datatable .= '<tr class="'.$css_class[$cssidx].'">'.
4516: '<td rowspan="'.$rownum.'" valign="top">'.
4517: '<p>';
4518: if ($lonhost eq '') {
1.210 raeburn 4519: $datatable .= '<span class="LC_nobreak">';
1.171 raeburn 4520: if (keys(%currbalancer) > 0) {
4521: $datatable .= &mt('Add balancer:');
4522: } else {
4523: $datatable .= &mt('Enable balancer:');
4524: }
4525: $datatable .= ' '.
4526: '<select name="loadbalancing_lonhost_'.$balnum.'"'.
4527: ' id="loadbalancing_lonhost_'.$balnum.'"'.
4528: ' onchange="toggleTargets('."'$balnum'".');">'."\n".
4529: '<option value="" selected="selected">'.&mt('None').
4530: '</option>'."\n";
4531: foreach my $server (sort(keys(%servers))) {
4532: next if ($currbalancer{$server});
4533: $datatable .= '<option value="'.$server.'">'.$server.'</option>'."\n";
4534: }
1.210 raeburn 4535: $datatable .=
1.171 raeburn 4536: '</select>'."\n".
4537: '<input type="hidden" name="loadbalancing_prevlonhost_'.$balnum.'" id="loadbalancing_prevlonhost_'.$balnum.'" value="" /> </span>'."\n";
4538: } else {
4539: $datatable .= '<i>'.$lonhost.'</i><br /><span class="LC_nobreak">'.
4540: '<label><input type="checkbox" name="loadbalancing_delete" value="'.$balnum.'" id="loadbalancing_delete_'.$balnum.'" onclick="javascript:balancerDeleteChange('."'$balnum'".');" /> '.
4541: &mt('Stop balancing').'</label>'.
4542: '<input type="hidden" name="loadbalancing_lonhost_'.$balnum.'" value="'.$lonhost.'" id="loadbalancing_lonhost_'.$balnum.'" /></span>';
4543: $targets_div_style = 'display: block';
4544: $disabled_div_style = 'display: none';
4545: if ($dom eq &Apache::lonnet::host_domain($lonhost)) {
4546: $homedom_div_style = 'display: block';
4547: }
4548: }
4549: $datatable .= '</p></td><td rowspan="'.$rownum.'" valign="top">'.
4550: '<div id="loadbalancing_disabled_'.$balnum.'" style="'.
4551: $disabled_div_style.'">'.$disabledtext.'</div>'."\n".
4552: '<div id="loadbalancing_targets_'.$balnum.'" style="'.$targets_div_style.'">'.&mt('Offloads to:').'<br />';
4553: my ($numspares,@spares) = &count_servers($lonhost,%servers);
4554: my @sparestypes = ('primary','default');
4555: my %typetitles = &sparestype_titles();
4556: foreach my $sparetype (@sparestypes) {
4557: my $targettable;
4558: for (my $i=0; $i<$numspares; $i++) {
4559: my $checked;
4560: if (ref($currtargets{$lonhost}) eq 'HASH') {
4561: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
4562: if (grep(/^\Q$spares[$i]\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
4563: $checked = ' checked="checked"';
4564: }
4565: }
4566: }
4567: my ($chkboxval,$disabled);
4568: if (($lonhost ne '') && (exists($servers{$lonhost}))) {
4569: $chkboxval = $spares[$i];
4570: }
4571: if (exists($currbalancer{$spares[$i]})) {
4572: $disabled = ' disabled="disabled"';
4573: }
1.210 raeburn 4574: $targettable .=
1.253 raeburn 4575: '<td><span class="LC_nobreak"><label>'.
4576: '<input type="checkbox" name="loadbalancing_target_'.$balnum.'_'.$sparetype.'"'.
1.171 raeburn 4577: $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 4578: '</span></label></span></td>';
1.171 raeburn 4579: my $rem = $i%($numinrow);
4580: if ($rem == 0) {
4581: if (($i > 0) && ($i < $numspares-1)) {
4582: $targettable .= '</tr>';
4583: }
4584: if ($i < $numspares-1) {
4585: $targettable .= '<tr>';
1.150 raeburn 4586: }
4587: }
4588: }
1.171 raeburn 4589: if ($targettable ne '') {
4590: my $rem = $numspares%($numinrow);
4591: my $colsleft = $numinrow - $rem;
4592: if ($colsleft > 1 ) {
4593: $targettable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
4594: ' </td>';
4595: } elsif ($colsleft == 1) {
4596: $targettable .= '<td class="LC_left_item"> </td>';
4597: }
4598: $datatable .= '<i>'.$typetitles{$sparetype}.'</i><br />'.
4599: '<table><tr>'.$targettable.'</tr></table><br />';
4600: }
4601: }
4602: $datatable .= '</div></td></tr>'.
4603: &loadbalancing_rules($dom,$intdom,$currrules{$lonhost},
4604: $othertitle,$usertypes,$types,\%servers,
4605: \%currbalancer,$lonhost,
4606: $targets_div_style,$homedom_div_style,
4607: $css_class[$cssidx],$balnum,$islast);
4608: $$rowtotal += $rownum;
4609: $balnum ++;
4610: }
4611: $datatable .= '<input type="hidden" name="loadbalancing_total" id="loadbalancing_total" value="'.$balnum.'" />';
4612: return $datatable;
4613: }
4614:
4615: sub get_loadbalancers_config {
4616: my ($servers,$existing,$currbalancer,$currtargets,$currrules) = @_;
4617: return unless ((ref($servers) eq 'HASH') &&
4618: (ref($existing) eq 'HASH') && (ref($currbalancer) eq 'HASH') &&
4619: (ref($currtargets) eq 'HASH') && (ref($currrules) eq 'HASH'));
4620: if (keys(%{$existing}) > 0) {
4621: my $oldlonhost;
4622: foreach my $key (sort(keys(%{$existing}))) {
4623: if ($key eq 'lonhost') {
4624: $oldlonhost = $existing->{'lonhost'};
4625: $currbalancer->{$oldlonhost} = 1;
4626: } elsif ($key eq 'targets') {
4627: if ($oldlonhost) {
4628: $currtargets->{$oldlonhost} = $existing->{'targets'};
4629: }
4630: } elsif ($key eq 'rules') {
4631: if ($oldlonhost) {
4632: $currrules->{$oldlonhost} = $existing->{'rules'};
4633: }
4634: } elsif (ref($existing->{$key}) eq 'HASH') {
4635: $currbalancer->{$key} = 1;
4636: $currtargets->{$key} = $existing->{$key}{'targets'};
4637: $currrules->{$key} = $existing->{$key}{'rules'};
1.150 raeburn 4638: }
4639: }
1.171 raeburn 4640: } else {
4641: my ($balancerref,$targetsref) =
4642: &Apache::lonnet::get_lonbalancer_config($servers);
4643: if ((ref($balancerref) eq 'HASH') && (ref($targetsref) eq 'HASH')) {
4644: foreach my $server (sort(keys(%{$balancerref}))) {
4645: $currbalancer->{$server} = 1;
4646: $currtargets->{$server} = $targetsref->{$server};
1.150 raeburn 4647: }
4648: }
4649: }
1.171 raeburn 4650: return;
1.150 raeburn 4651: }
4652:
4653: sub loadbalancing_rules {
4654: my ($dom,$intdom,$currrules,$othertitle,$usertypes,$types,$servers,
1.171 raeburn 4655: $currbalancer,$lonhost,$targets_div_style,$homedom_div_style,
4656: $css_class,$balnum,$islast) = @_;
1.150 raeburn 4657: my $output;
1.171 raeburn 4658: my $num = 0;
1.210 raeburn 4659: my ($alltypes,$othertypes,$titles) =
1.150 raeburn 4660: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
4661: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
4662: foreach my $type (@{$alltypes}) {
1.171 raeburn 4663: $num ++;
1.150 raeburn 4664: my $current;
4665: if (ref($currrules) eq 'HASH') {
4666: $current = $currrules->{$type};
4667: }
1.253 raeburn 4668: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.171 raeburn 4669: if ($dom ne &Apache::lonnet::host_domain($lonhost)) {
1.150 raeburn 4670: $current = '';
4671: }
4672: }
4673: $output .= &loadbalance_rule_row($type,$titles->{$type},$current,
1.171 raeburn 4674: $servers,$currbalancer,$lonhost,$dom,
4675: $targets_div_style,$homedom_div_style,
4676: $css_class,$balnum,$num,$islast);
1.150 raeburn 4677: }
4678: }
4679: return $output;
4680: }
4681:
4682: sub loadbalancing_titles {
4683: my ($dom,$intdom,$usertypes,$types) = @_;
4684: my %othertypes = (
4685: '_LC_adv' => &mt('Advanced users from [_1]',$dom),
4686: '_LC_author' => &mt('Users from [_1] with author role',$dom),
4687: '_LC_internetdom' => &mt('Users not from [_1], but from [_2]',$dom,$intdom),
4688: '_LC_external' => &mt('Users not from [_1]',$intdom),
1.209 raeburn 4689: '_LC_ipchangesso' => &mt('SSO users from [_1], with IP mismatch',$dom),
4690: '_LC_ipchange' => &mt('Non-SSO users with IP mismatch'),
1.150 raeburn 4691: );
1.209 raeburn 4692: my @alltypes = ('_LC_adv','_LC_author','_LC_internetdom','_LC_external','_LC_ipchangesso','_LC_ipchange');
1.150 raeburn 4693: if (ref($types) eq 'ARRAY') {
4694: unshift(@alltypes,@{$types},'default');
4695: }
4696: my %titles;
4697: foreach my $type (@alltypes) {
4698: if ($type =~ /^_LC_/) {
4699: $titles{$type} = $othertypes{$type};
4700: } elsif ($type eq 'default') {
4701: $titles{$type} = &mt('All users from [_1]',$dom);
4702: if (ref($types) eq 'ARRAY') {
4703: if (@{$types} > 0) {
4704: $titles{$type} = &mt('Other users from [_1]',$dom);
4705: }
4706: }
4707: } elsif (ref($usertypes) eq 'HASH') {
4708: $titles{$type} = $usertypes->{$type};
4709: }
4710: }
4711: return (\@alltypes,\%othertypes,\%titles);
4712: }
4713:
4714: sub loadbalance_rule_row {
1.171 raeburn 4715: my ($type,$title,$current,$servers,$currbalancer,$lonhost,$dom,
4716: $targets_div_style,$homedom_div_style,$css_class,$balnum,$num,$islast) = @_;
1.209 raeburn 4717: my @rulenames;
1.150 raeburn 4718: my %ruletitles = &offloadtype_text();
1.209 raeburn 4719: if (($type eq '_LC_ipchangesso') || ($type eq '_LC_ipchange')) {
1.254 raeburn 4720: @rulenames = ('balancer','offloadedto','specific');
1.150 raeburn 4721: } else {
1.209 raeburn 4722: @rulenames = ('default','homeserver');
4723: if ($type eq '_LC_external') {
4724: push(@rulenames,'externalbalancer');
4725: } else {
4726: push(@rulenames,'specific');
4727: }
4728: push(@rulenames,'none');
1.150 raeburn 4729: }
4730: my $style = $targets_div_style;
1.253 raeburn 4731: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.150 raeburn 4732: $style = $homedom_div_style;
4733: }
1.171 raeburn 4734: my $space;
4735: if ($islast && $num == 1) {
4736: $space = '<div display="inline-block"> </div>';
4737: }
1.210 raeburn 4738: my $output =
1.171 raeburn 4739: '<tr class="'.$css_class.'" id="balanceruletr_'.$balnum.'_'.$num.'"><td valign="top">'.$space.
4740: '<div id="balanceruletitle_'.$balnum.'_'.$type.'" style="'.$style.'">'.$title.'</div></td>'."\n".
4741: '<td valaign="top">'.$space.
4742: '<div id="balancerule_'.$balnum.'_'.$type.'" style="'.$style.'">'."\n";
1.150 raeburn 4743: for (my $i=0; $i<@rulenames; $i++) {
4744: my $rule = $rulenames[$i];
4745: my ($checked,$extra);
4746: if ($rulenames[$i] eq 'default') {
4747: $rule = '';
4748: }
4749: if ($rulenames[$i] eq 'specific') {
4750: if (ref($servers) eq 'HASH') {
4751: my $default;
4752: if (($current ne '') && (exists($servers->{$current}))) {
4753: $checked = ' checked="checked"';
4754: }
4755: unless ($checked) {
4756: $default = ' selected="selected"';
4757: }
1.210 raeburn 4758: $extra =
1.171 raeburn 4759: ': <select name="loadbalancing_singleserver_'.$balnum.'_'.$type.
4760: '" id="loadbalancing_singleserver_'.$balnum.'_'.$type.
4761: '" onchange="singleServerToggle('."'$balnum','$type'".')">'."\n".
4762: '<option value=""'.$default.'></option>'."\n";
4763: foreach my $server (sort(keys(%{$servers}))) {
4764: if (ref($currbalancer) eq 'HASH') {
4765: next if (exists($currbalancer->{$server}));
4766: }
1.150 raeburn 4767: my $selected;
1.171 raeburn 4768: if ($server eq $current) {
1.150 raeburn 4769: $selected = ' selected="selected"';
4770: }
1.171 raeburn 4771: $extra .= '<option value="'.$server.'"'.$selected.'>'.$server.'</option>';
1.150 raeburn 4772: }
4773: $extra .= '</select>';
4774: }
4775: } elsif ($rule eq $current) {
4776: $checked = ' checked="checked"';
4777: }
4778: $output .= '<span class="LC_nobreak"><label>'.
1.171 raeburn 4779: '<input type="radio" name="loadbalancing_rules_'.$balnum.'_'.$type.
4780: '" id="loadbalancing_rules_'.$balnum.'_'.$type.'_'.$i.'" value="'.
4781: $rule.'" onclick="balanceruleChange('."this.form,'$balnum','$type'".
1.254 raeburn 4782: ')"'.$checked.' /> ';
4783: if (($rulenames[$i] eq 'specific') && ($type =~ /^_LC_ipchange/)) {
4784: $output .= $ruletitles{'particular'};
4785: } else {
4786: $output .= $ruletitles{$rulenames[$i]};
4787: }
4788: $output .= '</label>'.$extra.'</span><br />'."\n";
1.150 raeburn 4789: }
4790: $output .= '</div></td></tr>'."\n";
4791: return $output;
4792: }
4793:
4794: sub offloadtype_text {
4795: my %ruletitles = &Apache::lonlocal::texthash (
4796: 'default' => 'Offloads to default destinations',
4797: 'homeserver' => "Offloads to user's home server",
4798: 'externalbalancer' => "Offloads to Load Balancer in user's domain",
4799: 'specific' => 'Offloads to specific server',
1.161 raeburn 4800: 'none' => 'No offload',
1.209 raeburn 4801: 'balancer' => 'Session hosted on Load Balancer, after re-authentication',
4802: 'offloadedto' => 'Session hosted on offload server, after re-authentication',
1.254 raeburn 4803: 'particular' => 'Session hosted (after re-auth) on server:',
1.150 raeburn 4804: );
4805: return %ruletitles;
4806: }
4807:
4808: sub sparestype_titles {
4809: my %typestitles = &Apache::lonlocal::texthash (
4810: 'primary' => 'primary',
4811: 'default' => 'default',
4812: );
4813: return %typestitles;
4814: }
4815:
1.28 raeburn 4816: sub contact_titles {
4817: my %titles = &Apache::lonlocal::texthash (
4818: 'supportemail' => 'Support E-mail address',
1.69 raeburn 4819: 'adminemail' => 'Default Server Admin E-mail address',
1.28 raeburn 4820: 'errormail' => 'Error reports to be e-mailed to',
4821: 'packagesmail' => 'Package update alerts to be e-mailed to',
1.89 raeburn 4822: 'helpdeskmail' => 'Helpdesk requests to be e-mailed to',
4823: 'lonstatusmail' => 'E-mail from nightly status check (warnings/errors)',
1.102 raeburn 4824: 'requestsmail' => 'E-mail from course requests requiring approval',
1.190 raeburn 4825: 'updatesmail' => 'E-mail from nightly check of LON-CAPA module integrity/updates',
1.203 raeburn 4826: 'idconflictsmail' => 'E-mail from bi-nightly check for multiple users sharing same student/employee ID',
1.28 raeburn 4827: );
4828: my %short_titles = &Apache::lonlocal::texthash (
4829: adminemail => 'Admin E-mail address',
4830: supportemail => 'Support E-mail',
4831: );
4832: return (\%titles,\%short_titles);
4833: }
4834:
1.72 raeburn 4835: sub tool_titles {
4836: my %titles = &Apache::lonlocal::texthash (
1.162 raeburn 4837: aboutme => 'Personal web page',
1.86 raeburn 4838: blog => 'Blog',
1.162 raeburn 4839: webdav => 'WebDAV',
1.86 raeburn 4840: portfolio => 'Portfolio',
1.88 bisitz 4841: official => 'Official courses (with institutional codes)',
4842: unofficial => 'Unofficial courses',
1.98 raeburn 4843: community => 'Communities',
1.216 raeburn 4844: textbook => 'Textbook courses',
1.271 raeburn 4845: placement => 'Placement tests',
1.86 raeburn 4846: );
1.72 raeburn 4847: return %titles;
4848: }
4849:
1.101 raeburn 4850: sub courserequest_titles {
4851: my %titles = &Apache::lonlocal::texthash (
4852: official => 'Official',
4853: unofficial => 'Unofficial',
4854: community => 'Communities',
1.216 raeburn 4855: textbook => 'Textbook',
1.271 raeburn 4856: placement => 'Placement tests',
1.101 raeburn 4857: norequest => 'Not allowed',
1.104 raeburn 4858: approval => 'Approval by Dom. Coord.',
1.101 raeburn 4859: validate => 'With validation',
4860: autolimit => 'Numerical limit',
1.103 raeburn 4861: unlimited => '(blank for unlimited)',
1.101 raeburn 4862: );
4863: return %titles;
4864: }
4865:
1.163 raeburn 4866: sub authorrequest_titles {
4867: my %titles = &Apache::lonlocal::texthash (
4868: norequest => 'Not allowed',
4869: approval => 'Approval by Dom. Coord.',
4870: automatic => 'Automatic approval',
4871: );
4872: return %titles;
1.210 raeburn 4873: }
1.163 raeburn 4874:
1.101 raeburn 4875: sub courserequest_conditions {
4876: my %conditions = &Apache::lonlocal::texthash (
1.104 raeburn 4877: approval => '(Processing of request subject to approval by Domain Coordinator).',
1.193 bisitz 4878: validate => '(Processing of request subject to institutional validation).',
1.101 raeburn 4879: );
4880: return %conditions;
4881: }
4882:
4883:
1.27 raeburn 4884: sub print_usercreation {
1.30 raeburn 4885: my ($position,$dom,$settings,$rowtotal) = @_;
1.27 raeburn 4886: my $numinrow = 4;
1.28 raeburn 4887: my $datatable;
4888: if ($position eq 'top') {
1.30 raeburn 4889: $$rowtotal ++;
1.34 raeburn 4890: my $rowcount = 0;
1.32 raeburn 4891: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username');
1.28 raeburn 4892: if (ref($rules) eq 'HASH') {
4893: if (keys(%{$rules}) > 0) {
1.32 raeburn 4894: $datatable .= &user_formats_row('username',$settings,$rules,
4895: $ruleorder,$numinrow,$rowcount);
1.30 raeburn 4896: $$rowtotal ++;
1.32 raeburn 4897: $rowcount ++;
4898: }
4899: }
4900: my ($idrules,$idruleorder) = &Apache::lonnet::inst_userrules($dom,'id');
4901: if (ref($idrules) eq 'HASH') {
4902: if (keys(%{$idrules}) > 0) {
4903: $datatable .= &user_formats_row('id',$settings,$idrules,
4904: $idruleorder,$numinrow,$rowcount);
4905: $$rowtotal ++;
4906: $rowcount ++;
1.28 raeburn 4907: }
4908: }
1.39 raeburn 4909: if ($rowcount == 0) {
4910: $datatable .= '<tr><td colspan="2">'.&mt('No format rules have been defined for usernames or IDs in this domain.').'</td></tr>';
4911: $$rowtotal ++;
4912: $rowcount ++;
4913: }
1.34 raeburn 4914: } elsif ($position eq 'middle') {
1.224 raeburn 4915: my @creators = ('author','course','requestcrs');
1.37 raeburn 4916: my ($rules,$ruleorder) =
4917: &Apache::lonnet::inst_userrules($dom,'username');
1.34 raeburn 4918: my %lt = &usercreation_types();
4919: my %checked;
4920: if (ref($settings) eq 'HASH') {
4921: if (ref($settings->{'cancreate'}) eq 'HASH') {
4922: foreach my $item (@creators) {
4923: $checked{$item} = $settings->{'cancreate'}{$item};
4924: }
4925: } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {
4926: foreach my $item (@creators) {
4927: if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {
4928: $checked{$item} = 'none';
4929: }
4930: }
4931: }
4932: }
4933: my $rownum = 0;
4934: foreach my $item (@creators) {
4935: $rownum ++;
1.224 raeburn 4936: if ($checked{$item} eq '') {
4937: $checked{$item} = 'any';
1.34 raeburn 4938: }
4939: my $css_class;
4940: if ($rownum%2) {
4941: $css_class = '';
4942: } else {
4943: $css_class = ' class="LC_odd_row" ';
4944: }
4945: $datatable .= '<tr'.$css_class.'>'.
4946: '<td><span class="LC_nobreak">'.$lt{$item}.
4947: '</span></td><td align="right">';
1.224 raeburn 4948: my @options = ('any');
4949: if (ref($rules) eq 'HASH') {
4950: if (keys(%{$rules}) > 0) {
4951: push(@options,('official','unofficial'));
1.37 raeburn 4952: }
4953: }
1.224 raeburn 4954: push(@options,'none');
1.37 raeburn 4955: foreach my $option (@options) {
1.50 raeburn 4956: my $type = 'radio';
1.34 raeburn 4957: my $check = ' ';
1.224 raeburn 4958: if ($checked{$item} eq $option) {
4959: $check = ' checked="checked" ';
1.34 raeburn 4960: }
4961: $datatable .= '<span class="LC_nobreak"><label>'.
1.50 raeburn 4962: '<input type="'.$type.'" name="can_createuser_'.
1.34 raeburn 4963: $item.'" value="'.$option.'"'.$check.'/> '.
4964: $lt{$option}.'</label> </span>';
4965: }
4966: $datatable .= '</td></tr>';
4967: }
1.28 raeburn 4968: } else {
4969: my @contexts = ('author','course','domain');
4970: my @authtypes = ('int','krb4','krb5','loc');
4971: my %checked;
4972: if (ref($settings) eq 'HASH') {
4973: if (ref($settings->{'authtypes'}) eq 'HASH') {
4974: foreach my $item (@contexts) {
4975: if (ref($settings->{'authtypes'}{$item}) eq 'HASH') {
4976: foreach my $auth (@authtypes) {
4977: if ($settings->{'authtypes'}{$item}{$auth}) {
4978: $checked{$item}{$auth} = ' checked="checked" ';
4979: }
4980: }
4981: }
4982: }
1.27 raeburn 4983: }
1.35 raeburn 4984: } else {
4985: foreach my $item (@contexts) {
1.36 raeburn 4986: foreach my $auth (@authtypes) {
1.35 raeburn 4987: $checked{$item}{$auth} = ' checked="checked" ';
4988: }
4989: }
1.27 raeburn 4990: }
1.28 raeburn 4991: my %title = &context_names();
4992: my %authname = &authtype_names();
4993: my $rownum = 0;
4994: my $css_class;
4995: foreach my $item (@contexts) {
4996: if ($rownum%2) {
4997: $css_class = '';
4998: } else {
4999: $css_class = ' class="LC_odd_row" ';
5000: }
1.30 raeburn 5001: $datatable .= '<tr'.$css_class.'>'.
1.28 raeburn 5002: '<td>'.$title{$item}.
5003: '</td><td class="LC_left_item">'.
5004: '<span class="LC_nobreak">';
5005: foreach my $auth (@authtypes) {
5006: $datatable .= '<label>'.
5007: '<input type="checkbox" name="'.$item.'_auth" '.
5008: $checked{$item}{$auth}.' value="'.$auth.'" />'.
5009: $authname{$auth}.'</label> ';
5010: }
5011: $datatable .= '</span></td></tr>';
5012: $rownum ++;
1.27 raeburn 5013: }
1.30 raeburn 5014: $$rowtotal += $rownum;
1.27 raeburn 5015: }
5016: return $datatable;
5017: }
5018:
1.224 raeburn 5019: sub print_selfcreation {
5020: my ($position,$dom,$settings,$rowtotal) = @_;
1.236 raeburn 5021: my (@selfcreate,$createsettings,$processing,$datatable);
1.224 raeburn 5022: if (ref($settings) eq 'HASH') {
5023: if (ref($settings->{'cancreate'}) eq 'HASH') {
5024: $createsettings = $settings->{'cancreate'};
1.236 raeburn 5025: if (ref($createsettings) eq 'HASH') {
5026: if (ref($createsettings->{'selfcreate'}) eq 'ARRAY') {
5027: @selfcreate = @{$createsettings->{'selfcreate'}};
5028: } elsif ($createsettings->{'selfcreate'} ne '') {
5029: if ($settings->{'cancreate'}{'selfcreate'} eq 'any') {
5030: @selfcreate = ('email','login','sso');
5031: } elsif ($createsettings->{'selfcreate'} ne 'none') {
5032: @selfcreate = ($createsettings->{'selfcreate'});
5033: }
5034: }
5035: if (ref($createsettings->{'selfcreateprocessing'}) eq 'HASH') {
5036: $processing = $createsettings->{'selfcreateprocessing'};
1.224 raeburn 5037: }
5038: }
5039: }
5040: }
5041: my %radiohash;
5042: my $numinrow = 4;
5043: map { $radiohash{'cancreate_'.$_} = 1; } @selfcreate;
5044: if ($position eq 'top') {
5045: my %choices = &Apache::lonlocal::texthash (
5046: cancreate_login => 'Institutional Login',
5047: cancreate_sso => 'Institutional Single Sign On',
5048: );
5049: my @toggles = sort(keys(%choices));
5050: my %defaultchecked = (
5051: 'cancreate_login' => 'off',
5052: 'cancreate_sso' => 'off',
5053: );
1.228 raeburn 5054: my ($onclick,$itemcount);
1.224 raeburn 5055: ($datatable,$itemcount) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
5056: \%choices,$itemcount,$onclick);
1.228 raeburn 5057: $$rowtotal += $itemcount;
5058:
1.224 raeburn 5059: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
5060:
5061: if (ref($usertypes) eq 'HASH') {
5062: if (keys(%{$usertypes}) > 0) {
5063: $datatable .= &insttypes_row($createsettings,$types,$usertypes,
5064: $dom,$numinrow,$othertitle,
1.228 raeburn 5065: 'statustocreate',$$rowtotal);
1.224 raeburn 5066: $$rowtotal ++;
5067: }
5068: }
1.240 raeburn 5069: my @fields = ('lastname','firstname','middlename','permanentemail','id','inststatus');
5070: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
5071: $fieldtitles{'inststatus'} = &mt('Institutional status');
5072: my $rem;
5073: my $numperrow = 2;
5074: my $css_class = $$rowtotal%2?' class="LC_odd_row"':'';
5075: $datatable .= '<tr'.$css_class.'>'.
1.241 raeburn 5076: '<td class="LC_left_item">'.&mt('Mapping of Shibboleth environment variable names to user data fields (SSO auth)').'</td>'.
1.240 raeburn 5077: '<td class="LC_left_item">'."\n".
5078: '<table><tr><td>'."\n";
5079: for (my $i=0; $i<@fields; $i++) {
5080: $rem = $i%($numperrow);
5081: if ($rem == 0) {
5082: if ($i > 0) {
5083: $datatable .= '</tr>';
5084: }
5085: $datatable .= '<tr>';
5086: }
5087: my $currval;
1.248 raeburn 5088: if (ref($createsettings) eq 'HASH') {
5089: if (ref($createsettings->{'shibenv'}) eq 'HASH') {
5090: $currval = $createsettings->{'shibenv'}{$fields[$i]};
5091: }
1.240 raeburn 5092: }
5093: $datatable .= '<td class="LC_left_item">'.
5094: '<span class="LC_nobreak">'.
5095: '<input type="text" name="shibenv_'.$fields[$i].'" '.
5096: 'value="'.$currval.'" size="10" /> '.
5097: $fieldtitles{$fields[$i]}.'</span></td>';
5098: }
5099: my $colsleft = $numperrow - $rem;
5100: if ($colsleft > 1 ) {
5101: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
5102: ' </td>';
5103: } elsif ($colsleft == 1) {
5104: $datatable .= '<td class="LC_left_item"> </td>';
5105: }
5106: $datatable .= '</tr></table></td></tr>';
5107: $$rowtotal ++;
1.224 raeburn 5108: } elsif ($position eq 'middle') {
5109: my %domconf = &Apache::lonnet::get_dom('configuration',['usermodification'],$dom);
5110: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
5111: $usertypes->{'default'} = $othertitle;
5112: if (ref($types) eq 'ARRAY') {
5113: push(@{$types},'default');
5114: $usertypes->{'default'} = $othertitle;
5115: foreach my $status (@{$types}) {
5116: $datatable .= &modifiable_userdata_row('selfcreate',$status,$domconf{'usermodification'},
1.228 raeburn 5117: $numinrow,$$rowtotal,$usertypes);
1.240 raeburn 5118: $$rowtotal ++;
1.224 raeburn 5119: }
5120: }
5121: } else {
1.236 raeburn 5122: my %choices = &Apache::lonlocal::texthash (
5123: cancreate_email => 'E-mail address as username',
5124: );
5125: my @toggles = sort(keys(%choices));
5126: my %defaultchecked = (
5127: 'cancreate_email' => 'off',
5128: );
5129: my $itemcount = 0;
5130: my $display = 'none';
5131: if (grep(/^\Qemail\E$/,@selfcreate)) {
5132: $display = 'block';
5133: }
5134: my $onclick = "toggleDisplay(this.form,'emailoptions');";
5135: my $additional = '<div id="emailoptions" style="display: '.$display.'">';
5136: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
5137: my $usertypes = {};
5138: my $order = [];
5139: if ((ref($domdefaults{'inststatustypes'}) eq 'HASH') && (ref($domdefaults{'inststatusguest'}) eq 'ARRAY')) {
5140: $usertypes = $domdefaults{'inststatustypes'};
5141: $order = $domdefaults{'inststatusguest'};
5142: }
5143: if (ref($order) eq 'ARRAY') {
5144: push(@{$order},'default');
5145: if (@{$order} > 1) {
5146: $usertypes->{'default'} = &mt('Other users');
5147: $additional .= '<table><tr>';
5148: foreach my $status (@{$order}) {
5149: $additional .= '<th>'.$usertypes->{$status}.'</th>';
5150: }
5151: $additional .= '</tr><tr>';
5152: foreach my $status (@{$order}) {
5153: $additional .= '<td>'.&email_as_username($rowtotal,$processing,$status).'</td>';
1.224 raeburn 5154: }
1.236 raeburn 5155: $additional .= '</tr></table>';
1.224 raeburn 5156: } else {
1.236 raeburn 5157: $usertypes->{'default'} = &mt('All users');
5158: $additional .= &email_as_username($rowtotal,$processing);
1.224 raeburn 5159: }
5160: }
1.236 raeburn 5161: $additional .= '</div>'."\n";
5162:
5163: ($datatable,$itemcount) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
1.240 raeburn 5164: \%choices,$$rowtotal,$onclick,$additional);
5165: $$rowtotal ++;
1.236 raeburn 5166: $datatable .= &print_requestmail($dom,'selfcreation',$createsettings,$rowtotal);
1.228 raeburn 5167: $$rowtotal ++;
1.224 raeburn 5168: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
1.228 raeburn 5169: $numinrow = 1;
1.236 raeburn 5170: if (ref($order) eq 'ARRAY') {
5171: foreach my $status (@{$order}) {
1.228 raeburn 5172: $datatable .= &modifiable_userdata_row('cancreate','emailusername_'.$status,$settings,
5173: $numinrow,$$rowtotal,$usertypes,$infofields,$infotitles);
5174: $$rowtotal ++;
5175: }
5176: }
1.224 raeburn 5177: my ($emailrules,$emailruleorder) =
5178: &Apache::lonnet::inst_userrules($dom,'email');
5179: if (ref($emailrules) eq 'HASH') {
5180: if (keys(%{$emailrules}) > 0) {
5181: $datatable .= &user_formats_row('email',$settings,$emailrules,
1.228 raeburn 5182: $emailruleorder,$numinrow,$$rowtotal);
1.224 raeburn 5183: $$rowtotal ++;
5184: }
5185: }
1.228 raeburn 5186: $datatable .= &captcha_choice('cancreate',$createsettings,$$rowtotal);
1.224 raeburn 5187: }
5188: return $datatable;
5189: }
5190:
1.236 raeburn 5191: sub email_as_username {
5192: my ($rowtotal,$processing,$type) = @_;
5193: my %choices =
5194: &Apache::lonlocal::texthash (
5195: automatic => 'Automatic approval',
5196: approval => 'Queued for approval',
5197: );
5198: my $output;
5199: foreach my $option ('automatic','approval') {
5200: my $checked;
5201: if (ref($processing) eq 'HASH') {
5202: if ($type eq '') {
5203: if (!exists($processing->{'default'})) {
5204: if ($option eq 'automatic') {
5205: $checked = ' checked="checked"';
5206: }
5207: } else {
5208: if ($processing->{'default'} eq $option) {
5209: $checked = ' checked="checked"';
5210: }
5211: }
5212: } else {
5213: if (!exists($processing->{$type})) {
5214: if ($option eq 'automatic') {
5215: $checked = ' checked="checked"';
5216: }
5217: } else {
5218: if ($processing->{$type} eq $option) {
5219: $checked = ' checked="checked"';
5220: }
5221: }
5222: }
5223: } elsif ($option eq 'automatic') {
5224: $checked = ' checked="checked"';
5225: }
5226: my $name = 'cancreate_emailprocess';
5227: if (($type ne '') && ($type ne 'default')) {
5228: $name .= '_'.$type;
5229: }
5230: $output .= '<span class="LC_nobreak"><label>'.
5231: '<input type="radio" name="'.$name.'"'.
5232: $checked.' value="'.$option.'" />'.
5233: $choices{$option}.'</label></span>';
5234: if ($type eq '') {
5235: $output .= ' ';
5236: } else {
5237: $output .= '<br />';
5238: }
5239: }
5240: $$rowtotal ++;
5241: return $output;
5242: }
5243:
1.165 raeburn 5244: sub captcha_choice {
1.169 raeburn 5245: my ($context,$settings,$itemcount) = @_;
1.269 raeburn 5246: my ($keyentry,$currpub,$currpriv,%checked,$rowname,$pubtext,$privtext,
5247: $vertext,$currver);
1.165 raeburn 5248: my %lt = &captcha_phrases();
5249: $keyentry = 'hidden';
5250: if ($context eq 'cancreate') {
1.224 raeburn 5251: $rowname = &mt('CAPTCHA validation');
1.169 raeburn 5252: } elsif ($context eq 'login') {
5253: $rowname = &mt('"Contact helpdesk" CAPTCHA validation');
1.165 raeburn 5254: }
5255: if (ref($settings) eq 'HASH') {
5256: if ($settings->{'captcha'}) {
5257: $checked{$settings->{'captcha'}} = ' checked="checked"';
5258: } else {
5259: $checked{'original'} = ' checked="checked"';
5260: }
5261: if ($settings->{'captcha'} eq 'recaptcha') {
5262: $pubtext = $lt{'pub'};
5263: $privtext = $lt{'priv'};
5264: $keyentry = 'text';
1.269 raeburn 5265: $vertext = $lt{'ver'};
5266: $currver = $settings->{'recaptchaversion'};
5267: if ($currver ne '2') {
5268: $currver = 1;
5269: }
1.165 raeburn 5270: }
5271: if (ref($settings->{'recaptchakeys'}) eq 'HASH') {
5272: $currpub = $settings->{'recaptchakeys'}{'public'};
5273: $currpriv = $settings->{'recaptchakeys'}{'private'};
5274: }
5275: } else {
5276: $checked{'original'} = ' checked="checked"';
5277: }
1.169 raeburn 5278: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
5279: my $output = '<tr'.$css_class.'>'.
5280: '<td class="LC_left_item">'.$rowname.'</td><td class="LC_left_item" colspan="2">'."\n".
1.165 raeburn 5281: '<table><tr><td>'."\n";
5282: foreach my $option ('original','recaptcha','notused') {
5283: $output .= '<span class="LC_nobreak"><label><input type="radio" name="'.$context.'_captcha" value="'.
5284: $option.'" '.$checked{$option}.' onchange="javascript:updateCaptcha('."this,'$context'".');" />'.
5285: $lt{$option}.'</label></span>';
5286: unless ($option eq 'notused') {
5287: $output .= (' 'x2)."\n";
5288: }
5289: }
5290: #
5291: # Note: If reCAPTCHA is to be used for LON-CAPA servers in a domain, a domain coordinator should visit:
5292: # https://www.google.com/recaptcha and generate a Public and Private key. For domains with multiple
1.210 raeburn 5293: # servers a single key pair will be used for all servers, so the internet domain (e.g., yourcollege.edu)
1.165 raeburn 5294: # specified for use with the key should be broad enough to accommodate all servers in the LON-CAPA domain.
1.210 raeburn 5295: #
1.165 raeburn 5296: $output .= '</td></tr>'."\n".
5297: '<tr><td>'."\n".
5298: '<span class="LC_nobreak"><span id="'.$context.'_recaptchapubtxt">'.$pubtext.'</span> '."\n".
5299: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapub" name="'.$context.'_recaptchapub" value="'.
5300: $currpub.'" size="40" /></span><br />'."\n".
5301: '<span class="LC_nobreak"><span id="'.$context.'_recaptchaprivtxt">'.$privtext.'</span> '."\n".
5302: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapriv" name="'.$context.'_recaptchapriv" value="'.
1.269 raeburn 5303: $currpriv.'" size="40" /></span><br />'.
5304: '<span class="LC_nobreak"><span id="'.$context.'_recaptchavertxt">'.$vertext.'</span> '."\n".
5305: '<input type="'.$keyentry.'" id="'.$context.'_recaptchaversion" name="'.$context.'_recaptchaversion" value="'.
5306: $currver.'" size="3" /></span><br />'.
5307: '</td></tr></table>'."\n".
1.165 raeburn 5308: '</td></tr>';
5309: return $output;
5310: }
5311:
1.32 raeburn 5312: sub user_formats_row {
5313: my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount) = @_;
5314: my $output;
5315: my %text = (
5316: 'username' => 'new usernames',
5317: 'id' => 'IDs',
1.45 raeburn 5318: 'email' => 'self-created accounts (e-mail)',
1.32 raeburn 5319: );
5320: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
5321: $output = '<tr '.$css_class.'>'.
1.63 raeburn 5322: '<td><span class="LC_nobreak">';
5323: if ($type eq 'email') {
5324: $output .= &mt("Formats disallowed for $text{$type}: ");
5325: } else {
5326: $output .= &mt("Format rules to check for $text{$type}: ");
5327: }
5328: $output .= '</span></td>'.
5329: '<td class="LC_left_item" colspan="2"><table>';
1.27 raeburn 5330: my $rem;
5331: if (ref($ruleorder) eq 'ARRAY') {
5332: for (my $i=0; $i<@{$ruleorder}; $i++) {
5333: if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
5334: my $rem = $i%($numinrow);
5335: if ($rem == 0) {
5336: if ($i > 0) {
5337: $output .= '</tr>';
5338: }
5339: $output .= '<tr>';
5340: }
5341: my $check = ' ';
1.39 raeburn 5342: if (ref($settings) eq 'HASH') {
5343: if (ref($settings->{$type.'_rule'}) eq 'ARRAY') {
5344: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) {
5345: $check = ' checked="checked" ';
5346: }
1.27 raeburn 5347: }
5348: }
5349: $output .= '<td class="LC_left_item">'.
5350: '<span class="LC_nobreak"><label>'.
1.32 raeburn 5351: '<input type="checkbox" name="'.$type.'_rule" '.
1.27 raeburn 5352: 'value="'.$ruleorder->[$i].'"'.$check.'/>'.
5353: $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
5354: }
5355: }
5356: $rem = @{$ruleorder}%($numinrow);
5357: }
5358: my $colsleft = $numinrow - $rem;
5359: if ($colsleft > 1 ) {
5360: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
5361: ' </td>';
5362: } elsif ($colsleft == 1) {
5363: $output .= '<td class="LC_left_item"> </td>';
5364: }
5365: $output .= '</tr></table></td></tr>';
5366: return $output;
5367: }
5368:
1.34 raeburn 5369: sub usercreation_types {
5370: my %lt = &Apache::lonlocal::texthash (
5371: author => 'When adding a co-author',
5372: course => 'When adding a user to a course',
1.100 raeburn 5373: requestcrs => 'When requesting a course',
1.34 raeburn 5374: any => 'Any',
5375: official => 'Institutional only ',
5376: unofficial => 'Non-institutional only',
5377: none => 'None',
5378: );
5379: return %lt;
1.48 raeburn 5380: }
1.34 raeburn 5381:
1.224 raeburn 5382: sub selfcreation_types {
5383: my %lt = &Apache::lonlocal::texthash (
5384: selfcreate => 'User creates own account',
5385: any => 'Any',
5386: official => 'Institutional only ',
5387: unofficial => 'Non-institutional only',
5388: email => 'E-mail address',
5389: login => 'Institutional Login',
5390: sso => 'SSO',
5391: );
5392: }
5393:
1.28 raeburn 5394: sub authtype_names {
5395: my %lt = &Apache::lonlocal::texthash(
5396: int => 'Internal',
5397: krb4 => 'Kerberos 4',
5398: krb5 => 'Kerberos 5',
5399: loc => 'Local',
5400: );
5401: return %lt;
5402: }
5403:
5404: sub context_names {
5405: my %context_title = &Apache::lonlocal::texthash(
5406: author => 'Creating users when an Author',
5407: course => 'Creating users when in a course',
5408: domain => 'Creating users when a Domain Coordinator',
5409: );
5410: return %context_title;
5411: }
5412:
1.33 raeburn 5413: sub print_usermodification {
5414: my ($position,$dom,$settings,$rowtotal) = @_;
5415: my $numinrow = 4;
5416: my ($context,$datatable,$rowcount);
5417: if ($position eq 'top') {
5418: $rowcount = 0;
5419: $context = 'author';
5420: foreach my $role ('ca','aa') {
5421: $datatable .= &modifiable_userdata_row($context,$role,$settings,
5422: $numinrow,$rowcount);
5423: $$rowtotal ++;
5424: $rowcount ++;
5425: }
1.230 raeburn 5426: } elsif ($position eq 'bottom') {
1.33 raeburn 5427: $context = 'course';
5428: $rowcount = 0;
5429: foreach my $role ('st','ep','ta','in','cr') {
5430: $datatable .= &modifiable_userdata_row($context,$role,$settings,
5431: $numinrow,$rowcount);
5432: $$rowtotal ++;
5433: $rowcount ++;
5434: }
5435: }
5436: return $datatable;
5437: }
5438:
1.43 raeburn 5439: sub print_defaults {
1.236 raeburn 5440: my ($position,$dom,$settings,$rowtotal) = @_;
1.43 raeburn 5441: my $rownum = 0;
5442: my ($datatable,$css_class);
1.236 raeburn 5443: if ($position eq 'top') {
5444: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def',
5445: 'datelocale_def','portal_def');
5446: my %defaults;
5447: if (ref($settings) eq 'HASH') {
5448: %defaults = %{$settings};
1.43 raeburn 5449: } else {
1.236 raeburn 5450: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
5451: foreach my $item (@items) {
5452: $defaults{$item} = $domdefaults{$item};
5453: }
1.43 raeburn 5454: }
1.236 raeburn 5455: my $titles = &defaults_titles($dom);
5456: foreach my $item (@items) {
5457: if ($rownum%2) {
5458: $css_class = '';
5459: } else {
5460: $css_class = ' class="LC_odd_row" ';
5461: }
5462: $datatable .= '<tr'.$css_class.'>'.
5463: '<td><span class="LC_nobreak">'.$titles->{$item}.
5464: '</span></td><td class="LC_right_item" colspan="3">';
5465: if ($item eq 'auth_def') {
5466: my @authtypes = ('internal','krb4','krb5','localauth');
5467: my %shortauth = (
5468: internal => 'int',
5469: krb4 => 'krb4',
5470: krb5 => 'krb5',
5471: localauth => 'loc'
5472: );
5473: my %authnames = &authtype_names();
5474: foreach my $auth (@authtypes) {
5475: my $checked = ' ';
5476: if ($defaults{$item} eq $auth) {
5477: $checked = ' checked="checked" ';
5478: }
5479: $datatable .= '<label><input type="radio" name="'.$item.
5480: '" value="'.$auth.'"'.$checked.'/>'.
5481: $authnames{$shortauth{$auth}}.'</label> ';
5482: }
5483: } elsif ($item eq 'timezone_def') {
5484: my $includeempty = 1;
5485: $datatable .= &Apache::loncommon::select_timezone($item,$defaults{$item},undef,$includeempty);
5486: } elsif ($item eq 'datelocale_def') {
5487: my $includeempty = 1;
5488: $datatable .= &Apache::loncommon::select_datelocale($item,$defaults{$item},undef,$includeempty);
5489: } elsif ($item eq 'lang_def') {
1.263 raeburn 5490: my $includeempty = 1;
5491: $datatable .= &Apache::loncommon::select_language($item,$defaults{$item},$includeempty);
1.236 raeburn 5492: } else {
5493: my $size;
5494: if ($item eq 'portal_def') {
5495: $size = ' size="25"';
5496: }
5497: $datatable .= '<input type="text" name="'.$item.'" value="'.
5498: $defaults{$item}.'"'.$size.' />';
1.43 raeburn 5499: }
1.236 raeburn 5500: $datatable .= '</td></tr>';
5501: $rownum ++;
5502: }
5503: } else {
5504: my (%defaults);
5505: if (ref($settings) eq 'HASH') {
5506: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH') &&
5507: (ref($settings->{'inststatusguest'}) eq 'ARRAY')) {
5508: my $maxnum = @{$settings->{'inststatusorder'}};
5509: for (my $i=0; $i<$maxnum; $i++) {
5510: $css_class = $rownum%2?' class="LC_odd_row"':'';
5511: my $item = $settings->{'inststatusorder'}->[$i];
5512: my $title = $settings->{'inststatustypes'}->{$item};
5513: my $guestok;
5514: if (grep(/^\Q$item\E$/,@{$settings->{'inststatusguest'}})) {
5515: $guestok = 1;
5516: }
5517: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'$item'".');"';
5518: $datatable .= '<tr'.$css_class.'>'.
5519: '<td><span class="LC_nobreak">'.
5520: '<select name="inststatus_pos_'.$item.'"'.$chgstr.'>';
5521: for (my $k=0; $k<=$maxnum; $k++) {
5522: my $vpos = $k+1;
5523: my $selstr;
5524: if ($k == $i) {
5525: $selstr = ' selected="selected" ';
5526: }
5527: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
5528: }
5529: my ($checkedon,$checkedoff);
5530: $checkedoff = ' checked="checked"';
5531: if ($guestok) {
5532: $checkedon = $checkedoff;
5533: $checkedoff = '';
5534: }
5535: $datatable .= '</select> '.&mt('Internal ID:').' <b>'.$item.'</b> '.
5536: '<input type="checkbox" name="inststatus_delete" value="'.$item.'" />'.
5537: &mt('delete').'</span></td>'.
5538: '<td class="LC_left_item"><span class="LC_nobreak">'.&mt('Name displayed:').
5539: '<input type="text" size="20" name="inststatus_title_'.$item.'" value="'.$title.'" />'.
5540: '</span></td>'.
5541: '<td class="LC_right_item"><span class="LC_nobreak">'.
5542: '<label><input type="radio" value="1" name="inststatus_guest_'.$item.'"'.$checkedon.' />'.
5543: &mt('Yes').'</label>'.(' 'x2).
5544: '<label><input type="radio" value="0" name="inststatus_guest_'.$item.'"'.$checkedoff.' />'.
5545: &mt('No').'</label></span></td></tr>';
5546: }
5547: $css_class = $rownum%2?' class="LC_odd_row"':'';
5548: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'addinststatus_pos'".');"';
5549: $datatable .= '<tr '.$css_class.'>'.
5550: '<td><span class="LC_nobreak"><select name="addinststatus_pos"'.$chgstr.'>';
5551: for (my $k=0; $k<=$maxnum; $k++) {
5552: my $vpos = $k+1;
5553: my $selstr;
5554: if ($k == $maxnum) {
5555: $selstr = ' selected="selected" ';
5556: }
5557: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
5558: }
5559: $datatable .= '</select> '.&mt('Internal ID:').
1.263 raeburn 5560: '<input type="text" size="10" name="addinststatus" value="" />'.
1.236 raeburn 5561: ' '.&mt('(new)').
5562: '</span></td><td class="LC_left_item"><span class="LC_nobreak">'.
5563: &mt('Name displayed:').
5564: '<input type="text" size="20" name="addinststatus_title" value="" /></span></td>'.
5565: '<td class="LC_right_item"><span class="LC_nobreak">'.
5566: '<label><input type="radio" value="1" name="addinststatus_guest" />'.
5567: &mt('Yes').'</label>'.(' 'x2).
5568: '<label><input type="radio" value="0" name="addinststatus_guest" />'.
5569: &mt('No').'</label></span></td></tr>';
5570: '</tr>'."\n";
5571: $rownum ++;
1.141 raeburn 5572: }
1.43 raeburn 5573: }
5574: }
5575: $$rowtotal += $rownum;
5576: return $datatable;
5577: }
5578:
1.168 raeburn 5579: sub get_languages_hash {
5580: my %langchoices;
5581: foreach my $id (&Apache::loncommon::languageids()) {
5582: my $code = &Apache::loncommon::supportedlanguagecode($id);
5583: if ($code ne '') {
5584: $langchoices{$code} = &Apache::loncommon::plainlanguagedescription($id);
5585: }
5586: }
5587: return %langchoices;
5588: }
5589:
1.43 raeburn 5590: sub defaults_titles {
1.141 raeburn 5591: my ($dom) = @_;
1.43 raeburn 5592: my %titles = &Apache::lonlocal::texthash (
5593: 'auth_def' => 'Default authentication type',
5594: 'auth_arg_def' => 'Default authentication argument',
5595: 'lang_def' => 'Default language',
1.54 raeburn 5596: 'timezone_def' => 'Default timezone',
1.68 raeburn 5597: 'datelocale_def' => 'Default locale for dates',
1.141 raeburn 5598: 'portal_def' => 'Portal/Default URL',
1.43 raeburn 5599: );
1.141 raeburn 5600: if ($dom) {
5601: my $uprimary_id = &Apache::lonnet::domain($dom,'primary');
5602: my $uint_dom = &Apache::lonnet::internet_dom($uprimary_id);
5603: my $protocol = $Apache::lonnet::protocol{$uprimary_id};
5604: $protocol = 'http' if ($protocol ne 'https');
5605: if ($uint_dom) {
5606: $titles{'portal_def'} .= ' '.&mt('(for example: [_1])',$protocol.'://loncapa.'.
5607: $uint_dom);
5608: }
5609: }
1.43 raeburn 5610: return (\%titles);
5611: }
5612:
1.46 raeburn 5613: sub print_scantronformat {
5614: my ($r,$dom,$confname,$settings,$rowtotal) = @_;
5615: my $itemcount = 1;
1.60 raeburn 5616: my ($datatable,$css_class,$scantronurl,$is_custom,%error,%scantronurls,
5617: %confhash);
1.46 raeburn 5618: my $switchserver = &check_switchserver($dom,$confname);
5619: my %lt = &Apache::lonlocal::texthash (
1.95 www 5620: default => 'Default bubblesheet format file error',
5621: custom => 'Custom bubblesheet format file error',
1.46 raeburn 5622: );
5623: my %scantronfiles = (
5624: default => 'default.tab',
5625: custom => 'custom.tab',
5626: );
5627: foreach my $key (keys(%scantronfiles)) {
5628: $scantronurls{$key} = '/res/'.$dom.'/'.$confname.'/scantron/'
5629: .$scantronfiles{$key};
5630: }
5631: my @defaultinfo = &Apache::lonnet::stat_file($scantronurls{'default'});
5632: if ((!@defaultinfo) || ($defaultinfo[0] eq 'no_such_dir')) {
5633: if (!$switchserver) {
5634: my $servadm = $r->dir_config('lonAdmEMail');
5635: my ($configuserok,$author_ok) = &config_check($dom,$confname,$servadm);
5636: if ($configuserok eq 'ok') {
5637: if ($author_ok eq 'ok') {
5638: my %legacyfile = (
5639: default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab',
5640: custom => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab',
5641: );
5642: my %md5chk;
5643: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 5644: ($md5chk{$type}) = split(/ /,`md5sum $legacyfile{$type}`);
5645: chomp($md5chk{$type});
1.46 raeburn 5646: }
5647: if ($md5chk{'default'} ne $md5chk{'custom'}) {
5648: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 5649: ($scantronurls{$type},my $error) =
1.46 raeburn 5650: &legacy_scantronformat($r,$dom,$confname,
5651: $type,$legacyfile{$type},
5652: $scantronurls{$type},
5653: $scantronfiles{$type});
1.60 raeburn 5654: if ($error ne '') {
5655: $error{$type} = $error;
5656: }
5657: }
5658: if (keys(%error) == 0) {
5659: $is_custom = 1;
5660: $confhash{'scantron'}{'scantronformat'} =
5661: $scantronurls{'custom'};
5662: my $putresult =
5663: &Apache::lonnet::put_dom('configuration',
5664: \%confhash,$dom);
5665: if ($putresult ne 'ok') {
5666: $error{'custom'} =
5667: '<span class="LC_error">'.
5668: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
5669: }
1.46 raeburn 5670: }
5671: } else {
1.60 raeburn 5672: ($scantronurls{'default'},my $error) =
1.46 raeburn 5673: &legacy_scantronformat($r,$dom,$confname,
5674: 'default',$legacyfile{'default'},
5675: $scantronurls{'default'},
5676: $scantronfiles{'default'});
1.60 raeburn 5677: if ($error eq '') {
5678: $confhash{'scantron'}{'scantronformat'} = '';
5679: my $putresult =
5680: &Apache::lonnet::put_dom('configuration',
5681: \%confhash,$dom);
5682: if ($putresult ne 'ok') {
5683: $error{'default'} =
5684: '<span class="LC_error">'.
5685: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
5686: }
5687: } else {
5688: $error{'default'} = $error;
5689: }
1.46 raeburn 5690: }
5691: }
5692: }
5693: } else {
1.95 www 5694: $error{'default'} = &mt("Unable to copy default bubblesheet formatfile to domain's RES space: [_1]",$switchserver);
1.46 raeburn 5695: }
5696: }
5697: if (ref($settings) eq 'HASH') {
5698: if ($settings->{'scantronformat'} eq "/res/$dom/$confname/scantron/custom.tab") {
5699: my @info = &Apache::lonnet::stat_file($settings->{'scantronformat'});
5700: if ((!@info) || ($info[0] eq 'no_such_dir')) {
5701: $scantronurl = '';
5702: } else {
5703: $scantronurl = $settings->{'scantronformat'};
5704: }
5705: $is_custom = 1;
5706: } else {
5707: $scantronurl = $scantronurls{'default'};
5708: }
5709: } else {
1.60 raeburn 5710: if ($is_custom) {
5711: $scantronurl = $scantronurls{'custom'};
5712: } else {
5713: $scantronurl = $scantronurls{'default'};
5714: }
1.46 raeburn 5715: }
5716: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5717: $datatable .= '<tr'.$css_class.'>';
5718: if (!$is_custom) {
1.65 raeburn 5719: $datatable .= '<td>'.&mt('Default in use:').'<br />'.
5720: '<span class="LC_nobreak">';
1.46 raeburn 5721: if ($scantronurl) {
1.199 raeburn 5722: $datatable .= &Apache::loncommon::modal_link($scantronurl,&mt('Default bubblesheet format file'),600,500,
5723: undef,undef,undef,undef,'background-color:#ffffff');
1.46 raeburn 5724: } else {
5725: $datatable = &mt('File unavailable for display');
5726: }
1.65 raeburn 5727: $datatable .= '</span></td>';
1.60 raeburn 5728: if (keys(%error) == 0) {
5729: $datatable .= '<td valign="bottom">';
5730: if (!$switchserver) {
5731: $datatable .= &mt('Upload:').'<br />';
5732: }
5733: } else {
5734: my $errorstr;
5735: foreach my $key (sort(keys(%error))) {
5736: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
5737: }
5738: $datatable .= '<td>'.$errorstr;
5739: }
1.46 raeburn 5740: } else {
5741: if (keys(%error) > 0) {
5742: my $errorstr;
5743: foreach my $key (sort(keys(%error))) {
5744: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
5745: }
1.60 raeburn 5746: $datatable .= '<td>'.$errorstr.'</td><td> ';
1.46 raeburn 5747: } elsif ($scantronurl) {
1.199 raeburn 5748: my $link = &Apache::loncommon::modal_link($scantronurl,&mt('Custom bubblesheet format file'),600,500,
5749: undef,undef,undef,undef,'background-color:#ffffff');
1.65 raeburn 5750: $datatable .= '<td><span class="LC_nobreak">'.
1.199 raeburn 5751: $link.
5752: '<label><input type="checkbox" name="scantronformat_del"'.
5753: ' value="1" />'.&mt('Delete?').'</label></span></td>'.
1.65 raeburn 5754: '<td><span class="LC_nobreak"> '.
5755: &mt('Replace:').'</span><br />';
1.46 raeburn 5756: }
5757: }
5758: if (keys(%error) == 0) {
5759: if ($switchserver) {
5760: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
5761: } else {
1.65 raeburn 5762: $datatable .='<span class="LC_nobreak"> '.
5763: '<input type="file" name="scantronformat" /></span>';
1.46 raeburn 5764: }
5765: }
5766: $datatable .= '</td></tr>';
5767: $$rowtotal ++;
5768: return $datatable;
5769: }
5770:
5771: sub legacy_scantronformat {
5772: my ($r,$dom,$confname,$file,$legacyfile,$newurl,$newfile) = @_;
5773: my ($url,$error);
5774: my @statinfo = &Apache::lonnet::stat_file($newurl);
5775: if ((!@statinfo) || ($statinfo[0] eq 'no_such_dir')) {
5776: (my $result,$url) =
5777: &publishlogo($r,'copy',$legacyfile,$dom,$confname,'scantron',
5778: '','',$newfile);
5779: if ($result ne 'ok') {
1.130 raeburn 5780: $error = &mt("An error occurred publishing the [_1] bubblesheet format file in RES space. Error was: [_2].",$newfile,$result);
1.46 raeburn 5781: }
5782: }
5783: return ($url,$error);
5784: }
1.43 raeburn 5785:
1.49 raeburn 5786: sub print_coursecategories {
1.57 raeburn 5787: my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;
5788: my $datatable;
5789: if ($position eq 'top') {
1.238 raeburn 5790: my (%checked);
5791: my @catitems = ('unauth','auth');
5792: my @cattypes = ('std','domonly','codesrch','none');
5793: $checked{'unauth'} = 'std';
5794: $checked{'auth'} = 'std';
5795: if (ref($settings) eq 'HASH') {
5796: foreach my $type (@cattypes) {
5797: if ($type eq $settings->{'unauth'}) {
5798: $checked{'unauth'} = $type;
5799: }
5800: if ($type eq $settings->{'auth'}) {
5801: $checked{'auth'} = $type;
5802: }
5803: }
5804: }
5805: my %lt = &Apache::lonlocal::texthash (
5806: unauth => 'Catalog type for unauthenticated users',
5807: auth => 'Catalog type for authenticated users',
5808: none => 'No catalog',
5809: std => 'Standard catalog',
5810: domonly => 'Domain-only catalog',
5811: codesrch => "Code search form",
5812: );
5813: my $itemcount = 0;
5814: foreach my $item (@catitems) {
5815: my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
5816: $datatable .= '<tr '.$css_class.'>'.
5817: '<td>'.$lt{$item}.'</td>'.
5818: '<td class="LC_right_item"><span class="LC_nobreak">';
5819: foreach my $type (@cattypes) {
5820: my $ischecked;
5821: if ($checked{$item} eq $type) {
5822: $ischecked=' checked="checked"';
5823: }
5824: $datatable .= '<label>'.
5825: '<input type="radio" name="coursecat_'.$item.'" value="'.$type.'"'.$ischecked.
5826: ' />'.$lt{$type}.'</label> ';
5827: }
5828: $datatable .= '</td></tr>';
5829: $itemcount ++;
5830: }
5831: $$rowtotal += $itemcount;
5832: } elsif ($position eq 'middle') {
1.57 raeburn 5833: my $toggle_cats_crs = ' ';
5834: my $toggle_cats_dom = ' checked="checked" ';
5835: my $can_cat_crs = ' ';
5836: my $can_cat_dom = ' checked="checked" ';
1.120 raeburn 5837: my $toggle_catscomm_comm = ' ';
5838: my $toggle_catscomm_dom = ' checked="checked" ';
5839: my $can_catcomm_comm = ' ';
5840: my $can_catcomm_dom = ' checked="checked" ';
1.272 raeburn 5841: my $toggle_catsplace_place = ' ';
5842: my $toggle_catsplace_dom = ' checked="checked" ';
5843: my $can_catplace_place = ' ';
5844: my $can_catplace_dom = ' checked="checked" ';
1.120 raeburn 5845:
1.57 raeburn 5846: if (ref($settings) eq 'HASH') {
5847: if ($settings->{'togglecats'} eq 'crs') {
5848: $toggle_cats_crs = $toggle_cats_dom;
5849: $toggle_cats_dom = ' ';
5850: }
5851: if ($settings->{'categorize'} eq 'crs') {
5852: $can_cat_crs = $can_cat_dom;
5853: $can_cat_dom = ' ';
5854: }
1.120 raeburn 5855: if ($settings->{'togglecatscomm'} eq 'comm') {
5856: $toggle_catscomm_comm = $toggle_catscomm_dom;
5857: $toggle_catscomm_dom = ' ';
5858: }
5859: if ($settings->{'categorizecomm'} eq 'comm') {
5860: $can_catcomm_comm = $can_catcomm_dom;
5861: $can_catcomm_dom = ' ';
5862: }
1.272 raeburn 5863: if ($settings->{'togglecatsplace'} eq 'place') {
5864: $toggle_catsplace_place = $toggle_catsplace_dom;
5865: $toggle_catsplace_dom = ' ';
5866: }
5867: if ($settings->{'categorizeplace'} eq 'place') {
5868: $can_catplace_place = $can_catplace_dom;
5869: $can_catplace_dom = ' ';
5870: }
1.57 raeburn 5871: }
5872: my %title = &Apache::lonlocal::texthash (
1.272 raeburn 5873: togglecats => 'Show/Hide a course in catalog',
5874: togglecatscomm => 'Show/Hide a community in catalog',
5875: togglecatsplace => 'Show/Hide a placement test in catalog',
5876: categorize => 'Assign a category to a course',
5877: categorizecomm => 'Assign a category to a community',
5878: categorizeplace => 'Assign a category to a placement test',
1.57 raeburn 5879: );
5880: my %level = &Apache::lonlocal::texthash (
1.272 raeburn 5881: dom => 'Set in Domain',
5882: crs => 'Set in Course',
5883: comm => 'Set in Community',
5884: place => 'Set in Placement Test',
1.57 raeburn 5885: );
5886: $datatable = '<tr class="LC_odd_row">'.
5887: '<td>'.$title{'togglecats'}.'</td>'.
5888: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
5889: '<input type="radio" name="togglecats"'.
5890: $toggle_cats_dom.' value="dom" />'.$level{'dom'}.'</label> '.
5891: '<label><input type="radio" name="togglecats"'.
5892: $toggle_cats_crs.' value="crs" />'.$level{'crs'}.'</label></span></td>'.
5893: '</tr><tr>'.
5894: '<td>'.$title{'categorize'}.'</td>'.
5895: '<td class="LC_right_item"><span class="LC_nobreak">'.
5896: '<label><input type="radio" name="categorize"'.
5897: $can_cat_dom.' value="dom" />'.$level{'dom'}.'</label> '.
5898: '<label><input type="radio" name="categorize"'.
5899: $can_cat_crs.'value="crs" />'.$level{'crs'}.'</label></span></td>'.
1.120 raeburn 5900: '</tr><tr class="LC_odd_row">'.
5901: '<td>'.$title{'togglecatscomm'}.'</td>'.
5902: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
5903: '<input type="radio" name="togglecatscomm"'.
5904: $toggle_catscomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
5905: '<label><input type="radio" name="togglecatscomm"'.
5906: $toggle_catscomm_comm.' value="comm" />'.$level{'comm'}.'</label></span></td>'.
5907: '</tr><tr>'.
5908: '<td>'.$title{'categorizecomm'}.'</td>'.
5909: '<td class="LC_right_item"><span class="LC_nobreak">'.
5910: '<label><input type="radio" name="categorizecomm"'.
5911: $can_catcomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
5912: '<label><input type="radio" name="categorizecomm"'.
5913: $can_catcomm_comm.'value="comm" />'.$level{'comm'}.'</label></span></td>'.
1.272 raeburn 5914: '</tr><tr>'.
5915: '<td>'.$title{'togglecatsplace'}.'</td>'.
5916: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
5917: '<input type="radio" name="togglecatsplace"'.
5918: $toggle_catsplace_dom.' value="dom" />'.$level{'dom'}.'</label> '.
5919: '<label><input type="radio" name="togglecatscomm"'.
5920: $toggle_catsplace_place.' value="comm" />'.$level{'place'}.'</label></span></td>'.
5921: '</tr><tr>'.
5922: '<td>'.$title{'categorizeplace'}.'</td>'.
5923: '<td class="LC_right_item"><span class="LC_nobreak">'.
5924: '<label><input type="radio" name="categorizeplace"'.
5925: $can_catplace_dom.' value="dom" />'.$level{'dom'}.'</label> '.
5926: '<label><input type="radio" name="categorizeplace"'.
5927: $can_catplace_place.'value="place" />'.$level{'place'}.'</label></span></td>'.
1.57 raeburn 5928: '</tr>';
1.272 raeburn 5929: $$rowtotal += 6;
1.57 raeburn 5930: } else {
5931: my $css_class;
5932: my $itemcount = 1;
5933: my $cathash;
5934: if (ref($settings) eq 'HASH') {
5935: $cathash = $settings->{'cats'};
5936: }
5937: if (ref($cathash) eq 'HASH') {
5938: my (@cats,@trails,%allitems,%idx,@jsarray);
5939: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
5940: \%allitems,\%idx,\@jsarray);
5941: my $maxdepth = scalar(@cats);
5942: my $colattrib = '';
5943: if ($maxdepth > 2) {
5944: $colattrib = ' colspan="2" ';
5945: }
5946: my @path;
5947: if (@cats > 0) {
5948: if (ref($cats[0]) eq 'ARRAY') {
5949: my $numtop = @{$cats[0]};
5950: my $maxnum = $numtop;
1.120 raeburn 5951: my %default_names = (
5952: instcode => &mt('Official courses'),
5953: communities => &mt('Communities'),
1.272 raeburn 5954: placement => &mt('Placement Tests'),
1.120 raeburn 5955: );
5956:
5957: if ((!grep(/^instcode$/,@{$cats[0]})) ||
5958: ($cathash->{'instcode::0'} eq '') ||
5959: (!grep(/^communities$/,@{$cats[0]})) ||
1.272 raeburn 5960: ($cathash->{'communities::0'} eq '') ||
5961: (!grep(/^placement$/,@{$cats[0]})) ||
5962: ($cathash->{'placement::0'} eq '')) {
1.57 raeburn 5963: $maxnum ++;
5964: }
5965: my $lastidx;
5966: for (my $i=0; $i<$numtop; $i++) {
5967: my $parent = $cats[0][$i];
5968: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5969: my $item = &escape($parent).'::0';
5970: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$item','$idx{$item}'".');"';
5971: $lastidx = $idx{$item};
5972: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
5973: .'<select name="'.$item.'"'.$chgstr.'>';
5974: for (my $k=0; $k<=$maxnum; $k++) {
5975: my $vpos = $k+1;
5976: my $selstr;
5977: if ($k == $i) {
5978: $selstr = ' selected="selected" ';
5979: }
5980: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
5981: }
1.214 raeburn 5982: $datatable .= '</select></span></td><td>';
1.272 raeburn 5983: if ($parent eq 'instcode' || $parent eq 'communities' || $parent eq 'placement') {
1.120 raeburn 5984: $datatable .= '<span class="LC_nobreak">'
5985: .$default_names{$parent}.'</span>';
5986: if ($parent eq 'instcode') {
5987: $datatable .= '<br /><span class="LC_nobreak">('
5988: .&mt('with institutional codes')
5989: .')</span></td><td'.$colattrib.'>';
5990: } else {
5991: $datatable .= '<table><tr><td>';
5992: }
5993: $datatable .= '<span class="LC_nobreak">'
5994: .'<label><input type="radio" name="'
5995: .$parent.'" value="1" checked="checked" />'
5996: .&mt('Display').'</label>';
5997: if ($parent eq 'instcode') {
5998: $datatable .= ' ';
5999: } else {
6000: $datatable .= '</span></td></tr><tr><td>'
6001: .'<span class="LC_nobreak">';
6002: }
6003: $datatable .= '<label><input type="radio" name="'
6004: .$parent.'" value="0" />'
6005: .&mt('Do not display').'</label></span>';
1.272 raeburn 6006: if (($parent eq 'communities') || ($parent eq 'placement')) {
1.120 raeburn 6007: $datatable .= '</td></tr></table>';
6008: }
6009: $datatable .= '</td>';
1.57 raeburn 6010: } else {
6011: $datatable .= $parent
1.214 raeburn 6012: .' <span class="LC_nobreak"><label>'
6013: .'<input type="checkbox" name="deletecategory" '
1.57 raeburn 6014: .'value="'.$item.'" />'.&mt('Delete').'</label></span></td>';
6015: }
6016: my $depth = 1;
6017: push(@path,$parent);
6018: $datatable .= &build_category_rows($itemcount,\@cats,$depth,$parent,\@path,\%idx);
6019: pop(@path);
6020: $datatable .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
6021: $itemcount ++;
6022: }
1.48 raeburn 6023: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.57 raeburn 6024: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','$lastidx'".');"';
6025: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="addcategory_pos"'.$chgstr.'>';
1.48 raeburn 6026: for (my $k=0; $k<=$maxnum; $k++) {
6027: my $vpos = $k+1;
6028: my $selstr;
1.57 raeburn 6029: if ($k == $numtop) {
1.48 raeburn 6030: $selstr = ' selected="selected" ';
6031: }
6032: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
6033: }
1.59 bisitz 6034: $datatable .= '</select></span></td><td colspan="2">'.&mt('Add category:').' '
1.57 raeburn 6035: .'<input type="text" size="20" name="addcategory_name" value="" /></td>'
6036: .'</tr>'."\n";
1.48 raeburn 6037: $itemcount ++;
1.272 raeburn 6038: foreach my $default ('instcode','communities','placement') {
1.120 raeburn 6039: if ((!grep(/^\Q$default\E$/,@{$cats[0]})) || ($cathash->{$default.'::0'} eq '')) {
6040: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6041: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','$lastidx'".');"';
6042: $datatable .= '<tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr><tr '.$css_class.'><td>'.
6043: '<span class="LC_nobreak"><select name="'.$default.'_pos"'.$chgstr.'>';
6044: for (my $k=0; $k<=$maxnum; $k++) {
6045: my $vpos = $k+1;
6046: my $selstr;
6047: if ($k == $maxnum) {
6048: $selstr = ' selected="selected" ';
6049: }
6050: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.57 raeburn 6051: }
1.120 raeburn 6052: $datatable .= '</select></span></td>'.
6053: '<td><span class="LC_nobreak">'.
6054: $default_names{$default}.'</span>';
6055: if ($default eq 'instcode') {
6056: $datatable .= '<br /><span class="LC_nobreak">('
6057: .&mt('with institutional codes').')</span>';
6058: }
6059: $datatable .= '</td>'
6060: .'<td><span class="LC_nobreak"><label><input type="radio" name="'.$default.'" value="1" />'
6061: .&mt('Display').'</label> '
6062: .'<label><input type="radio" name="'.$default.'" value="0" checked="checked"/>'
6063: .&mt('Do not display').'</label></span></td></tr>';
1.48 raeburn 6064: }
6065: }
6066: }
1.57 raeburn 6067: } else {
6068: $datatable .= &initialize_categories($itemcount);
1.48 raeburn 6069: }
6070: } else {
1.238 raeburn 6071: $datatable .= '<td class="LC_right_item">'.$hdritem->{'header'}->[1]->{'col2'}.'</td>'
1.57 raeburn 6072: .&initialize_categories($itemcount);
1.48 raeburn 6073: }
1.57 raeburn 6074: $$rowtotal += $itemcount;
1.48 raeburn 6075: }
6076: return $datatable;
6077: }
6078:
1.69 raeburn 6079: sub print_serverstatuses {
6080: my ($dom,$settings,$rowtotal) = @_;
6081: my $datatable;
6082: my @pages = &serverstatus_pages();
6083: my (%namedaccess,%machineaccess);
6084: foreach my $type (@pages) {
6085: $namedaccess{$type} = '';
6086: $machineaccess{$type}= '';
6087: }
6088: if (ref($settings) eq 'HASH') {
6089: foreach my $type (@pages) {
6090: if (exists($settings->{$type})) {
6091: if (ref($settings->{$type}) eq 'HASH') {
6092: foreach my $key (keys(%{$settings->{$type}})) {
6093: if ($key eq 'namedusers') {
6094: $namedaccess{$type} = $settings->{$type}->{$key};
6095: } elsif ($key eq 'machines') {
6096: $machineaccess{$type} = $settings->{$type}->{$key};
6097: }
6098: }
6099: }
6100: }
6101: }
6102: }
1.81 raeburn 6103: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 6104: my $rownum = 0;
6105: my $css_class;
6106: foreach my $type (@pages) {
6107: $rownum ++;
6108: $css_class = $rownum%2?' class="LC_odd_row"':'';
6109: $datatable .= '<tr'.$css_class.'>'.
6110: '<td><span class="LC_nobreak">'.
6111: $titles->{$type}.'</span></td>'.
6112: '<td class="LC_left_item">'.
6113: '<input type="text" name="'.$type.'_namedusers" '.
6114: 'value="'.$namedaccess{$type}.'" size="30" /></td>'.
6115: '<td class="LC_right_item">'.
6116: '<span class="LC_nobreak">'.
6117: '<input type="text" name="'.$type.'_machines" '.
6118: 'value="'.$machineaccess{$type}.'" size="10" />'.
6119: '</td></tr>'."\n";
6120: }
6121: $$rowtotal += $rownum;
6122: return $datatable;
6123: }
6124:
6125: sub serverstatus_pages {
6126: return ('userstatus','lonstatus','loncron','server-status','codeversions',
1.275 raeburn 6127: 'checksums','clusterstatus','certstatus','metadata_keywords',
6128: 'metadata_harvest','takeoffline','takeonline','showenv','toggledebug',
6129: 'ping','domconf','uniquecodes','diskusage','coursecatalog');
1.69 raeburn 6130: }
6131:
1.236 raeburn 6132: sub defaults_javascript {
6133: my ($settings) = @_;
1.248 raeburn 6134: return unless (ref($settings) eq 'HASH');
1.236 raeburn 6135: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
6136: my $maxnum = scalar(@{$settings->{'inststatusorder'}});
6137: if ($maxnum eq '') {
6138: $maxnum = 0;
6139: }
6140: $maxnum ++;
1.249 raeburn 6141: my $jstext = ' var inststatuses = Array('."'".join("','",@{$settings->{'inststatusorder'}})."'".');';
1.236 raeburn 6142: return <<"ENDSCRIPT";
6143: <script type="text/javascript">
6144: // <![CDATA[
6145: function reorderTypes(form,caller) {
6146: var changedVal;
6147: $jstext
6148: var newpos = 'addinststatus_pos';
6149: var current = new Array;
6150: var maxh = $maxnum;
6151: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
6152: var oldVal;
6153: if (caller == newpos) {
6154: changedVal = newitemVal;
6155: } else {
6156: var curritem = 'inststatus_pos_'+caller;
6157: changedVal = form.elements[curritem].options[form.elements[curritem].selectedIndex].value;
6158: current[newitemVal] = newpos;
6159: }
6160: for (var i=0; i<inststatuses.length; i++) {
6161: if (inststatuses[i] != caller) {
6162: var elementName = 'inststatus_pos_'+inststatuses[i];
6163: if (form.elements[elementName]) {
6164: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
6165: current[currVal] = elementName;
6166: }
6167: }
6168: }
6169: for (var j=0; j<maxh; j++) {
6170: if (current[j] == undefined) {
6171: oldVal = j;
6172: }
6173: }
6174: if (oldVal < changedVal) {
6175: for (var k=oldVal+1; k<=changedVal ; k++) {
6176: var elementName = current[k];
6177: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
6178: }
6179: } else {
6180: for (var k=changedVal; k<oldVal; k++) {
6181: var elementName = current[k];
6182: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
6183: }
6184: }
6185: return;
6186: }
6187:
6188: // ]]>
6189: </script>
6190:
6191: ENDSCRIPT
6192: }
6193: }
6194:
1.49 raeburn 6195: sub coursecategories_javascript {
6196: my ($settings) = @_;
1.57 raeburn 6197: my ($output,$jstext,$cathash);
1.49 raeburn 6198: if (ref($settings) eq 'HASH') {
1.57 raeburn 6199: $cathash = $settings->{'cats'};
6200: }
6201: if (ref($cathash) eq 'HASH') {
1.49 raeburn 6202: my (@cats,@jsarray,%idx);
1.57 raeburn 6203: &Apache::loncommon::gather_categories($cathash,\@cats,\%idx,\@jsarray);
1.49 raeburn 6204: if (@jsarray > 0) {
6205: $jstext = ' var categories = Array('.scalar(@jsarray).');'."\n";
6206: for (my $i=0; $i<@jsarray; $i++) {
6207: if (ref($jsarray[$i]) eq 'ARRAY') {
6208: my $catstr = join('","',@{$jsarray[$i]});
6209: $jstext .= ' categories['.$i.'] = Array("'.$catstr.'");'."\n";
6210: }
6211: }
6212: }
6213: } else {
6214: $jstext = ' var categories = Array(1);'."\n".
6215: ' categories[0] = Array("instcode_pos");'."\n";
6216: }
1.237 bisitz 6217: my $instcode_reserved = &mt('The name: [_1] is a reserved category.','"instcode"');
6218: my $communities_reserved = &mt('The name: [_1] is a reserved category.','"communities"');
1.272 raeburn 6219: my $placement_reserved = &mt('The name: [_1] is a reserved category.','"placement"');
1.265 damieng 6220: my $choose_again = "\n".&mt('Please use a different name for the new top level category.');
6221: &js_escape(\$instcode_reserved);
6222: &js_escape(\$communities_reserved);
1.272 raeburn 6223: &js_escape(\$placement_reserved);
1.265 damieng 6224: &js_escape(\$choose_again);
1.49 raeburn 6225: $output = <<"ENDSCRIPT";
6226: <script type="text/javascript">
1.109 raeburn 6227: // <![CDATA[
1.49 raeburn 6228: function reorderCats(form,parent,item,idx) {
6229: var changedVal;
6230: $jstext
6231: var newpos = 'addcategory_pos';
6232: if (parent == '') {
6233: var has_instcode = 0;
6234: var maxtop = categories[idx].length;
6235: for (var j=0; j<maxtop; j++) {
6236: if (categories[idx][j] == 'instcode::0') {
6237: has_instcode == 1;
6238: }
6239: }
6240: if (has_instcode == 0) {
6241: categories[idx][maxtop] = 'instcode_pos';
6242: }
6243: } else {
6244: newpos += '_'+parent;
6245: }
6246: var maxh = 1 + categories[idx].length;
6247: var current = new Array;
6248: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
6249: if (item == newpos) {
6250: changedVal = newitemVal;
6251: } else {
6252: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
6253: current[newitemVal] = newpos;
6254: }
6255: for (var i=0; i<categories[idx].length; i++) {
6256: var elementName = categories[idx][i];
6257: if (elementName != item) {
6258: if (form.elements[elementName]) {
6259: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
6260: current[currVal] = elementName;
6261: }
6262: }
6263: }
6264: var oldVal;
6265: for (var j=0; j<maxh; j++) {
6266: if (current[j] == undefined) {
6267: oldVal = j;
6268: }
6269: }
6270: if (oldVal < changedVal) {
6271: for (var k=oldVal+1; k<=changedVal ; k++) {
6272: var elementName = current[k];
6273: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
6274: }
6275: } else {
6276: for (var k=changedVal; k<oldVal; k++) {
6277: var elementName = current[k];
6278: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
6279: }
6280: }
6281: return;
6282: }
1.120 raeburn 6283:
6284: function categoryCheck(form) {
6285: if (form.elements['addcategory_name'].value == 'instcode') {
6286: alert('$instcode_reserved\\n$choose_again');
6287: return false;
6288: }
6289: if (form.elements['addcategory_name'].value == 'communities') {
6290: alert('$communities_reserved\\n$choose_again');
6291: return false;
6292: }
1.272 raeburn 6293: if (form.elements['addcategory_name'].value == 'placement') {
6294: alert('$placement_reserved\\n$choose_again');
6295: return false;
6296: }
1.120 raeburn 6297: return true;
6298: }
6299:
1.109 raeburn 6300: // ]]>
1.49 raeburn 6301: </script>
6302:
6303: ENDSCRIPT
6304: return $output;
6305: }
6306:
1.48 raeburn 6307: sub initialize_categories {
6308: my ($itemcount) = @_;
1.120 raeburn 6309: my ($datatable,$css_class,$chgstr);
6310: my %default_names = (
6311: instcode => 'Official courses (with institutional codes)',
6312: communities => 'Communities',
1.272 raeburn 6313: placement => 'Placement Tests',
1.120 raeburn 6314: );
6315: my $select0 = ' selected="selected"';
6316: my $select1 = '';
1.272 raeburn 6317: foreach my $default ('instcode','communities','placement') {
1.120 raeburn 6318: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6319: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'',$default"."_pos','0'".');"';
1.272 raeburn 6320: if (($default eq 'communities') || ($default eq 'placement')) {
1.120 raeburn 6321: $select1 = $select0;
6322: $select0 = '';
6323: }
6324: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
6325: .'<select name="'.$default.'_pos">'
6326: .'<option value="0"'.$select0.'>1</option>'
6327: .'<option value="1"'.$select1.'>2</option>'
6328: .'<option value="2">3</option></select> '
6329: .$default_names{$default}
6330: .'</span></td><td><span class="LC_nobreak">'
6331: .'<label><input type="radio" name="'.$default.'" value="1" checked="checked" />'
6332: .&mt('Display').'</label> <label>'
6333: .'<input type="radio" name="'.$default.'" value="0" />'.&mt('Do not display')
1.48 raeburn 6334: .'</label></span></td></tr>';
1.120 raeburn 6335: $itemcount ++;
6336: }
1.48 raeburn 6337: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.49 raeburn 6338: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','0'".');"';
1.48 raeburn 6339: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.120 raeburn 6340: .'<select name="addcategory_pos"'.$chgstr.'>'
6341: .'<option value="0">1</option>'
6342: .'<option value="1">2</option>'
6343: .'<option value="2" selected="selected">3</option></select> '
1.48 raeburn 6344: .&mt('Add category').'</td><td>'.&mt('Name:')
6345: .' <input type="text" size="20" name="addcategory_name" value="" /></td></tr>';
6346: return $datatable;
6347: }
6348:
6349: sub build_category_rows {
1.49 raeburn 6350: my ($itemcount,$cats,$depth,$parent,$path,$idx) = @_;
6351: my ($text,$name,$item,$chgstr);
1.48 raeburn 6352: if (ref($cats) eq 'ARRAY') {
6353: my $maxdepth = scalar(@{$cats});
6354: if (ref($cats->[$depth]) eq 'HASH') {
6355: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
6356: my $numchildren = @{$cats->[$depth]{$parent}};
6357: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.204 raeburn 6358: $text .= '<td><table class="LC_data_table">';
1.49 raeburn 6359: my ($idxnum,$parent_name,$parent_item);
6360: my $higher = $depth - 1;
6361: if ($higher == 0) {
6362: $parent_name = &escape($parent).'::'.$higher;
6363: } else {
6364: if (ref($path) eq 'ARRAY') {
6365: $parent_name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
6366: }
6367: }
6368: $parent_item = 'addcategory_pos_'.$parent_name;
1.48 raeburn 6369: for (my $j=0; $j<=$numchildren; $j++) {
1.49 raeburn 6370: if ($j < $numchildren) {
1.48 raeburn 6371: $name = $cats->[$depth]{$parent}[$j];
6372: $item = &escape($name).':'.&escape($parent).':'.$depth;
1.49 raeburn 6373: $idxnum = $idx->{$item};
6374: } else {
6375: $name = $parent_name;
6376: $item = $parent_item;
1.48 raeburn 6377: }
1.49 raeburn 6378: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'$parent_name','$item','$idxnum'".');"';
6379: $text .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="'.$item.'"'.$chgstr.'>';
1.48 raeburn 6380: for (my $i=0; $i<=$numchildren; $i++) {
6381: my $vpos = $i+1;
6382: my $selstr;
6383: if ($j == $i) {
6384: $selstr = ' selected="selected" ';
6385: }
6386: $text .= '<option value="'.$i.'"'.$selstr.'>'.$vpos.'</option>';
6387: }
6388: $text .= '</select> ';
6389: if ($j < $numchildren) {
6390: my $deeper = $depth+1;
6391: $text .= $name.' '
6392: .'<label><input type="checkbox" name="deletecategory" value="'
6393: .$item.'" />'.&mt('Delete').'</label></span></td><td>';
6394: if(ref($path) eq 'ARRAY') {
6395: push(@{$path},$name);
1.49 raeburn 6396: $text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path,$idx);
1.48 raeburn 6397: pop(@{$path});
6398: }
6399: } else {
1.59 bisitz 6400: $text .= &mt('Add subcategory:').' </span><input type="textbox" size="20" name="addcategory_name_';
1.48 raeburn 6401: if ($j == $numchildren) {
6402: $text .= $name;
6403: } else {
6404: $text .= $item;
6405: }
6406: $text .= '" value="" />';
6407: }
6408: $text .= '</td></tr>';
6409: }
6410: $text .= '</table></td>';
6411: } else {
6412: my $higher = $depth-1;
6413: if ($higher == 0) {
6414: $name = &escape($parent).'::'.$higher;
6415: } else {
6416: if (ref($path) eq 'ARRAY') {
6417: $name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
6418: }
6419: }
6420: my $colspan;
6421: if ($parent ne 'instcode') {
6422: $colspan = $maxdepth - $depth - 1;
6423: $text .= '<td colspan="'.$colspan.'">'.&mt('Add subcategory:').'<input type="textbox" size="20" name="subcat_'.$name.'" value="" /></td>';
6424: }
6425: }
6426: }
6427: }
6428: return $text;
6429: }
6430:
1.33 raeburn 6431: sub modifiable_userdata_row {
1.228 raeburn 6432: my ($context,$item,$settings,$numinrow,$rowcount,$usertypes,$fieldsref,$titlesref) = @_;
6433: my ($role,$rolename,$statustype);
6434: $role = $item;
1.224 raeburn 6435: if ($context eq 'cancreate') {
1.228 raeburn 6436: if ($item =~ /^emailusername_(.+)$/) {
6437: $statustype = $1;
6438: $role = 'emailusername';
6439: if (ref($usertypes) eq 'HASH') {
6440: if ($usertypes->{$statustype}) {
6441: $rolename = &mt('Data provided by [_1]',$usertypes->{$statustype});
6442: } else {
6443: $rolename = &mt('Data provided by user');
6444: }
6445: }
1.224 raeburn 6446: }
6447: } elsif ($context eq 'selfcreate') {
1.63 raeburn 6448: if (ref($usertypes) eq 'HASH') {
6449: $rolename = $usertypes->{$role};
6450: } else {
6451: $rolename = $role;
6452: }
1.33 raeburn 6453: } else {
1.63 raeburn 6454: if ($role eq 'cr') {
6455: $rolename = &mt('Custom role');
6456: } else {
6457: $rolename = &Apache::lonnet::plaintext($role);
6458: }
1.33 raeburn 6459: }
1.224 raeburn 6460: my (@fields,%fieldtitles);
6461: if (ref($fieldsref) eq 'ARRAY') {
6462: @fields = @{$fieldsref};
6463: } else {
6464: @fields = ('lastname','firstname','middlename','generation',
6465: 'permanentemail','id');
6466: }
6467: if ((ref($titlesref) eq 'HASH')) {
6468: %fieldtitles = %{$titlesref};
6469: } else {
6470: %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
6471: }
1.33 raeburn 6472: my $output;
6473: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
6474: $output = '<tr '.$css_class.'>'.
6475: '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
6476: '<td class="LC_left_item" colspan="2"><table>';
6477: my $rem;
6478: my %checks;
6479: if (ref($settings) eq 'HASH') {
6480: if (ref($settings->{$context}) eq 'HASH') {
6481: if (ref($settings->{$context}->{$role}) eq 'HASH') {
1.228 raeburn 6482: my $hashref = $settings->{$context}->{$role};
6483: if ($role eq 'emailusername') {
6484: if ($statustype) {
6485: if (ref($settings->{$context}->{$role}->{$statustype}) eq 'HASH') {
6486: $hashref = $settings->{$context}->{$role}->{$statustype};
6487: if (ref($hashref) eq 'HASH') {
6488: foreach my $field (@fields) {
6489: if ($hashref->{$field}) {
6490: $checks{$field} = $hashref->{$field};
6491: }
6492: }
6493: }
6494: }
6495: }
6496: } else {
6497: if (ref($hashref) eq 'HASH') {
6498: foreach my $field (@fields) {
6499: if ($hashref->{$field}) {
6500: $checks{$field} = ' checked="checked" ';
6501: }
6502: }
1.33 raeburn 6503: }
6504: }
6505: }
6506: }
6507: }
1.228 raeburn 6508:
1.33 raeburn 6509: for (my $i=0; $i<@fields; $i++) {
6510: my $rem = $i%($numinrow);
6511: if ($rem == 0) {
6512: if ($i > 0) {
6513: $output .= '</tr>';
6514: }
6515: $output .= '<tr>';
6516: }
6517: my $check = ' ';
1.228 raeburn 6518: unless ($role eq 'emailusername') {
6519: if (exists($checks{$fields[$i]})) {
6520: $check = $checks{$fields[$i]}
6521: } else {
6522: if ($role eq 'st') {
6523: if (ref($settings) ne 'HASH') {
6524: $check = ' checked="checked" ';
6525: }
1.33 raeburn 6526: }
6527: }
6528: }
6529: $output .= '<td class="LC_left_item">'.
1.228 raeburn 6530: '<span class="LC_nobreak">';
6531: if ($role eq 'emailusername') {
6532: unless ($checks{$fields[$i]} =~ /^(required|optional)$/) {
6533: $checks{$fields[$i]} = 'omit';
6534: }
6535: foreach my $option ('required','optional','omit') {
6536: my $checked='';
6537: if ($checks{$fields[$i]} eq $option) {
6538: $checked='checked="checked" ';
6539: }
6540: $output .= '<label>'.
6541: '<input type="radio" name="canmodify_'.$item.'_'.$fields[$i].'" value="'.$option.'" '.$checked.'/>'.
6542: &mt($option).'</label>'.(' ' x2);
6543: }
6544: $output .= '<i>'.$fieldtitles{$fields[$i]}.'</i>';
6545: } else {
6546: $output .= '<label>'.
6547: '<input type="checkbox" name="canmodify_'.$role.'" '.
6548: 'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
6549: '</label>';
6550: }
6551: $output .= '</span></td>';
1.33 raeburn 6552: $rem = @fields%($numinrow);
6553: }
6554: my $colsleft = $numinrow - $rem;
6555: if ($colsleft > 1 ) {
6556: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
6557: ' </td>';
6558: } elsif ($colsleft == 1) {
6559: $output .= '<td class="LC_left_item"> </td>';
6560: }
6561: $output .= '</tr></table></td></tr>';
6562: return $output;
6563: }
1.28 raeburn 6564:
1.93 raeburn 6565: sub insttypes_row {
1.224 raeburn 6566: my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle,$context,$rownum) = @_;
1.93 raeburn 6567: my %lt = &Apache::lonlocal::texthash (
6568: cansearch => 'Users allowed to search',
6569: statustocreate => 'Institutional affiliation(s) able to create own account (login/SSO)',
1.131 raeburn 6570: lockablenames => 'User preference to lock name',
1.93 raeburn 6571: );
6572: my $showdom;
6573: if ($context eq 'cansearch') {
6574: $showdom = ' ('.$dom.')';
6575: }
1.165 raeburn 6576: my $class = 'LC_left_item';
6577: if ($context eq 'statustocreate') {
6578: $class = 'LC_right_item';
6579: }
1.224 raeburn 6580: my $css_class = ' class="LC_odd_row"';
6581: if ($rownum ne '') {
6582: $css_class = ($rownum%2? ' class="LC_odd_row"':'');
6583: }
6584: my $output = '<tr'.$css_class.'>'.
6585: '<td>'.$lt{$context}.$showdom.
6586: '</td><td class="'.$class.'" colspan="2"><table>';
1.26 raeburn 6587: my $rem;
6588: if (ref($types) eq 'ARRAY') {
6589: for (my $i=0; $i<@{$types}; $i++) {
6590: if (defined($usertypes->{$types->[$i]})) {
6591: my $rem = $i%($numinrow);
6592: if ($rem == 0) {
6593: if ($i > 0) {
6594: $output .= '</tr>';
6595: }
6596: $output .= '<tr>';
1.23 raeburn 6597: }
1.26 raeburn 6598: my $check = ' ';
1.99 raeburn 6599: if (ref($settings) eq 'HASH') {
6600: if (ref($settings->{$context}) eq 'ARRAY') {
6601: if (grep(/^\Q$types->[$i]\E$/,@{$settings->{$context}})) {
6602: $check = ' checked="checked" ';
6603: }
6604: } elsif ($context eq 'statustocreate') {
1.26 raeburn 6605: $check = ' checked="checked" ';
6606: }
1.23 raeburn 6607: }
1.26 raeburn 6608: $output .= '<td class="LC_left_item">'.
6609: '<span class="LC_nobreak"><label>'.
1.93 raeburn 6610: '<input type="checkbox" name="'.$context.'" '.
1.26 raeburn 6611: 'value="'.$types->[$i].'"'.$check.'/>'.
6612: $usertypes->{$types->[$i]}.'</label></span></td>';
1.23 raeburn 6613: }
6614: }
1.26 raeburn 6615: $rem = @{$types}%($numinrow);
1.23 raeburn 6616: }
6617: my $colsleft = $numinrow - $rem;
1.131 raeburn 6618: if (($rem == 0) && (@{$types} > 0)) {
6619: $output .= '<tr>';
6620: }
1.23 raeburn 6621: if ($colsleft > 1) {
1.25 raeburn 6622: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
1.23 raeburn 6623: } else {
1.25 raeburn 6624: $output .= '<td class="LC_left_item">';
1.23 raeburn 6625: }
6626: my $defcheck = ' ';
1.99 raeburn 6627: if (ref($settings) eq 'HASH') {
6628: if (ref($settings->{$context}) eq 'ARRAY') {
6629: if (grep(/^default$/,@{$settings->{$context}})) {
6630: $defcheck = ' checked="checked" ';
6631: }
6632: } elsif ($context eq 'statustocreate') {
1.26 raeburn 6633: $defcheck = ' checked="checked" ';
6634: }
1.23 raeburn 6635: }
1.25 raeburn 6636: $output .= '<span class="LC_nobreak"><label>'.
1.93 raeburn 6637: '<input type="checkbox" name="'.$context.'" '.
1.25 raeburn 6638: 'value="default"'.$defcheck.'/>'.
6639: $othertitle.'</label></span></td>'.
6640: '</tr></table></td></tr>';
6641: return $output;
1.23 raeburn 6642: }
6643:
6644: sub sorted_searchtitles {
6645: my %searchtitles = &Apache::lonlocal::texthash(
6646: 'uname' => 'username',
6647: 'lastname' => 'last name',
6648: 'lastfirst' => 'last name, first name',
6649: );
6650: my @titleorder = ('uname','lastname','lastfirst');
6651: return (\%searchtitles,\@titleorder);
6652: }
6653:
1.25 raeburn 6654: sub sorted_searchtypes {
6655: my %srchtypes_desc = (
6656: exact => 'is exact match',
6657: contains => 'contains ..',
6658: begins => 'begins with ..',
6659: );
6660: my @srchtypeorder = ('exact','begins','contains');
6661: return (\%srchtypes_desc,\@srchtypeorder);
6662: }
6663:
1.3 raeburn 6664: sub usertype_update_row {
6665: my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
6666: my $datatable;
6667: my $numinrow = 4;
6668: foreach my $type (@{$types}) {
6669: if (defined($usertypes->{$type})) {
6670: $$rownums ++;
6671: my $css_class = $$rownums%2?' class="LC_odd_row"':'';
6672: $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
6673: '</td><td class="LC_left_item"><table>';
6674: for (my $i=0; $i<@{$fields}; $i++) {
6675: my $rem = $i%($numinrow);
6676: if ($rem == 0) {
6677: if ($i > 0) {
6678: $datatable .= '</tr>';
6679: }
6680: $datatable .= '<tr>';
6681: }
6682: my $check = ' ';
1.39 raeburn 6683: if (ref($settings) eq 'HASH') {
6684: if (ref($settings->{'fields'}) eq 'HASH') {
6685: if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
6686: if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
6687: $check = ' checked="checked" ';
6688: }
1.3 raeburn 6689: }
6690: }
6691: }
6692:
6693: if ($i == @{$fields}-1) {
6694: my $colsleft = $numinrow - $rem;
6695: if ($colsleft > 1) {
6696: $datatable .= '<td colspan="'.$colsleft.'">';
6697: } else {
6698: $datatable .= '<td>';
6699: }
6700: } else {
6701: $datatable .= '<td>';
6702: }
1.8 raeburn 6703: $datatable .= '<span class="LC_nobreak"><label>'.
6704: '<input type="checkbox" name="updateable_'.$type.
6705: '_'.$fields->[$i].'" value="1"'.$check.'/>'.
6706: $fieldtitles->{$fields->[$i]}.'</label></span></td>';
1.3 raeburn 6707: }
6708: $datatable .= '</tr></table></td></tr>';
6709: }
6710: }
6711: return $datatable;
1.1 raeburn 6712: }
6713:
6714: sub modify_login {
1.205 raeburn 6715: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.168 raeburn 6716: my ($resulttext,$errors,$colchgtext,%changes,%colchanges,%newfile,%newurl,
6717: %curr_loginvia,%loginhash,@currlangs,@newlangs,$addedfile,%title,@offon);
6718: %title = ( coursecatalog => 'Display course catalog',
6719: adminmail => 'Display administrator E-mail address',
1.188 raeburn 6720: helpdesk => 'Display "Contact Helpdesk" link',
1.168 raeburn 6721: newuser => 'Link for visitors to create a user account',
6722: loginheader => 'Log-in box header');
6723: @offon = ('off','on');
1.112 raeburn 6724: if (ref($domconfig{login}) eq 'HASH') {
6725: if (ref($domconfig{login}{loginvia}) eq 'HASH') {
6726: foreach my $lonhost (keys(%{$domconfig{login}{loginvia}})) {
6727: $curr_loginvia{$lonhost} = $domconfig{login}{loginvia}{$lonhost};
6728: }
6729: }
6730: }
1.9 raeburn 6731: ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
6732: \%domconfig,\%loginhash);
1.188 raeburn 6733: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 6734: foreach my $item (@toggles) {
6735: $loginhash{login}{$item} = $env{'form.'.$item};
6736: }
1.41 raeburn 6737: $loginhash{login}{loginheader} = $env{'form.loginheader'};
1.6 raeburn 6738: if (ref($colchanges{'login'}) eq 'HASH') {
6739: $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
6740: \%loginhash);
6741: }
1.110 raeburn 6742:
1.149 raeburn 6743: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.256 raeburn 6744: my %domservers = &Apache::lonnet::get_servers($dom);
1.128 raeburn 6745: my @loginvia_attribs = ('serverpath','custompath','exempt');
1.110 raeburn 6746: if (keys(%servers) > 1) {
6747: foreach my $lonhost (keys(%servers)) {
1.128 raeburn 6748: next if ($env{'form.'.$lonhost.'_server'} eq $lonhost);
6749: if (ref($curr_loginvia{$lonhost}) eq 'HASH') {
6750: if ($env{'form.'.$lonhost.'_server'} eq $curr_loginvia{$lonhost}{'server'}) {
6751: $loginhash{login}{loginvia}{$lonhost}{'server'} = $curr_loginvia{$lonhost}{'server'};
6752: } elsif ($curr_loginvia{$lonhost}{'server'} ne '') {
6753: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
6754: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
6755: $changes{'loginvia'}{$lonhost} = 1;
6756: } else {
6757: $loginhash{login}{loginvia}{$lonhost}{'server'} = '';
6758: $changes{'loginvia'}{$lonhost} = 1;
6759: }
6760: } else {
6761: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
6762: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
6763: $changes{'loginvia'}{$lonhost} = 1;
6764: }
6765: }
6766: if ($loginhash{login}{loginvia}{$lonhost}{'server'} eq '') {
6767: foreach my $item (@loginvia_attribs) {
6768: $loginhash{login}{loginvia}{$lonhost}{$item} = '';
6769: }
6770: } else {
6771: foreach my $item (@loginvia_attribs) {
6772: my $new = $env{'form.'.$lonhost.'_'.$item};
6773: if (($item eq 'serverpath') && ($new eq 'custom')) {
6774: $env{'form.'.$lonhost.'_custompath'} =~ s/\s+//g;
6775: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
6776: $new = '/';
6777: }
6778: }
6779: if (($item eq 'custompath') &&
6780: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
6781: $new = '';
6782: }
6783: if ($new ne $curr_loginvia{$lonhost}{$item}) {
6784: $changes{'loginvia'}{$lonhost} = 1;
6785: }
6786: if ($item eq 'exempt') {
1.256 raeburn 6787: $new = &check_exempt_addresses($new);
1.128 raeburn 6788: }
6789: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
6790: }
6791: }
1.112 raeburn 6792: } else {
1.128 raeburn 6793: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
6794: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
1.112 raeburn 6795: $changes{'loginvia'}{$lonhost} = 1;
1.128 raeburn 6796: foreach my $item (@loginvia_attribs) {
6797: my $new = $env{'form.'.$lonhost.'_'.$item};
6798: if (($item eq 'serverpath') && ($new eq 'custom')) {
6799: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
6800: $new = '/';
6801: }
6802: }
6803: if (($item eq 'custompath') &&
6804: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
6805: $new = '';
6806: }
6807: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
6808: }
1.110 raeburn 6809: }
6810: }
6811: }
6812: }
1.119 raeburn 6813:
1.168 raeburn 6814: my $servadm = $r->dir_config('lonAdmEMail');
6815: my %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
6816: if (ref($domconfig{'login'}) eq 'HASH') {
6817: if (ref($domconfig{'login'}{'helpurl'}) eq 'HASH') {
6818: foreach my $lang (sort(keys(%{$domconfig{'login'}{'helpurl'}}))) {
6819: if ($lang eq 'nolang') {
6820: push(@currlangs,$lang);
6821: } elsif (defined($langchoices{$lang})) {
6822: push(@currlangs,$lang);
6823: } else {
6824: next;
6825: }
6826: }
6827: }
6828: }
6829: my @delurls = &Apache::loncommon::get_env_multiple('form.loginhelpurl_del');
6830: if (@currlangs > 0) {
6831: foreach my $lang (@currlangs) {
6832: if (grep(/^\Q$lang\E$/,@delurls)) {
6833: $changes{'helpurl'}{$lang} = 1;
6834: } elsif ($env{'form.loginhelpurl_'.$lang.'.filename'}) {
6835: $changes{'helpurl'}{$lang} = 1;
6836: $newfile{$lang} = $env{'form.loginhelpurl_'.$lang.'.filename'};
6837: push(@newlangs,$lang);
6838: } else {
6839: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
6840: }
6841: }
6842: }
6843: unless (grep(/^nolang$/,@currlangs)) {
6844: if ($env{'form.loginhelpurl_nolang.filename'}) {
6845: $changes{'helpurl'}{'nolang'} = 1;
6846: $newfile{'nolang'} = $env{'form.loginhelpurl_nolang.filename'};
6847: push(@newlangs,'nolang');
6848: }
6849: }
6850: if ($env{'form.loginhelpurl_add_lang'}) {
6851: if ((defined($langchoices{$env{'form.loginhelpurl_add_lang'}})) &&
6852: ($env{'form.loginhelpurl_add_file.filename'})) {
6853: $newfile{$env{'form.loginhelpurl_add_lang'}} = $env{'form.loginhelpurl_add_file.filename'};
6854: $addedfile = $env{'form.loginhelpurl_add_lang'};
6855: }
6856: }
6857: if ((@newlangs > 0) || ($addedfile)) {
6858: my $error;
6859: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
6860: if ($configuserok eq 'ok') {
6861: if ($switchserver) {
6862: $error = &mt("Upload of custom help file is not permitted to this server: [_1]",$switchserver);
6863: } elsif ($author_ok eq 'ok') {
6864: my @allnew = @newlangs;
6865: if ($addedfile ne '') {
6866: push(@allnew,$addedfile);
6867: }
6868: foreach my $lang (@allnew) {
6869: my $formelem = 'loginhelpurl_'.$lang;
6870: if ($lang eq $env{'form.loginhelpurl_add_lang'}) {
6871: $formelem = 'loginhelpurl_add_file';
6872: }
6873: (my $result,$newurl{$lang}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
6874: "help/$lang",'','',$newfile{$lang});
6875: if ($result eq 'ok') {
6876: $loginhash{'login'}{'helpurl'}{$lang} = $newurl{$lang};
6877: $changes{'helpurl'}{$lang} = 1;
6878: } else {
6879: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$newfile{$lang},$result);
6880: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
1.210 raeburn 6881: if ((grep(/^\Q$lang\E$/,@currlangs)) &&
1.168 raeburn 6882: (!grep(/^\Q$lang\E$/,@delurls))) {
6883: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
6884: }
6885: }
6886: }
6887: } else {
6888: $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);
6889: }
6890: } else {
6891: $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);
6892: }
6893: if ($error) {
6894: &Apache::lonnet::logthis($error);
6895: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
6896: }
6897: }
1.256 raeburn 6898:
6899: my (%currheadtagurls,%currexempt,@newhosts,%newheadtagurls,%possexempt);
6900: if (ref($domconfig{'login'}) eq 'HASH') {
6901: if (ref($domconfig{'login'}{'headtag'}) eq 'HASH') {
6902: foreach my $lonhost (keys(%{$domconfig{'login'}{'headtag'}})) {
6903: if ($domservers{$lonhost}) {
6904: if (ref($domconfig{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
6905: $currheadtagurls{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'url'};
1.268 raeburn 6906: $currexempt{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'exempt'};
1.256 raeburn 6907: }
6908: }
6909: }
6910: }
6911: }
6912: my @delheadtagurls = &Apache::loncommon::get_env_multiple('form.loginheadtag_del');
6913: foreach my $lonhost (sort(keys(%domservers))) {
6914: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
6915: $changes{'headtag'}{$lonhost} = 1;
6916: } else {
6917: if ($env{'form.loginheadtagexempt_'.$lonhost}) {
6918: $possexempt{$lonhost} = &check_exempt_addresses($env{'form.loginheadtagexempt_'.$lonhost});
6919: }
6920: if ($env{'form.loginheadtag_'.$lonhost.'.filename'}) {
6921: push(@newhosts,$lonhost);
6922: } elsif ($currheadtagurls{$lonhost}) {
6923: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $currheadtagurls{$lonhost};
6924: if ($currexempt{$lonhost}) {
6925: if ((!exists($possexempt{$lonhost})) || ($possexempt{$lonhost} ne $currexempt{$lonhost})) {
6926: $changes{'headtag'}{$lonhost} = 1;
6927: }
6928: } elsif ($possexempt{$lonhost}) {
6929: $changes{'headtag'}{$lonhost} = 1;
6930: }
6931: if ($possexempt{$lonhost}) {
6932: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
6933: }
6934: }
6935: }
6936: }
6937: if (@newhosts) {
6938: my $error;
6939: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
6940: if ($configuserok eq 'ok') {
6941: if ($switchserver) {
6942: $error = &mt("Upload of custom markup is not permitted to this server: [_1]",$switchserver);
6943: } elsif ($author_ok eq 'ok') {
6944: foreach my $lonhost (@newhosts) {
6945: my $formelem = 'loginheadtag_'.$lonhost;
6946: (my $result,$newheadtagurls{$lonhost}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
6947: "login/headtag/$lonhost",'','',
6948: $env{'form.loginheadtag_'.$lonhost.'.filename'});
6949: if ($result eq 'ok') {
6950: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $newheadtagurls{$lonhost};
6951: $changes{'headtag'}{$lonhost} = 1;
6952: if ($possexempt{$lonhost}) {
6953: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
6954: }
6955: } else {
6956: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",
6957: $newheadtagurls{$lonhost},$result);
6958: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
6959: if ((grep(/^\Q$lonhost\E$/,keys(%currheadtagurls))) &&
6960: (!grep(/^\Q$lonhost\E$/,@delheadtagurls))) {
6961: $loginhash{'login'}{'headtag'}{$lonhost} = $currheadtagurls{$lonhost};
6962: }
6963: }
6964: }
6965: } else {
6966: $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);
6967: }
6968: } else {
6969: $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);
6970: }
6971: if ($error) {
6972: &Apache::lonnet::logthis($error);
6973: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
6974: }
6975: }
1.169 raeburn 6976: &process_captcha('login',\%changes,$loginhash{'login'},$domconfig{'login'});
1.168 raeburn 6977:
6978: my $defaulthelpfile = '/adm/loginproblems.html';
6979: my $defaulttext = &mt('Default in use');
6980:
1.1 raeburn 6981: my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
6982: $dom);
6983: if ($putresult eq 'ok') {
1.188 raeburn 6984: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 6985: my %defaultchecked = (
6986: 'coursecatalog' => 'on',
1.188 raeburn 6987: 'helpdesk' => 'on',
1.42 raeburn 6988: 'adminmail' => 'off',
1.43 raeburn 6989: 'newuser' => 'off',
1.42 raeburn 6990: );
1.55 raeburn 6991: if (ref($domconfig{'login'}) eq 'HASH') {
6992: foreach my $item (@toggles) {
6993: if ($defaultchecked{$item} eq 'on') {
6994: if (($domconfig{'login'}{$item} eq '0') &&
6995: ($env{'form.'.$item} eq '1')) {
6996: $changes{$item} = 1;
6997: } elsif (($domconfig{'login'}{$item} eq '' ||
6998: $domconfig{'login'}{$item} eq '1') &&
6999: ($env{'form.'.$item} eq '0')) {
7000: $changes{$item} = 1;
7001: }
7002: } elsif ($defaultchecked{$item} eq 'off') {
7003: if (($domconfig{'login'}{$item} eq '1') &&
7004: ($env{'form.'.$item} eq '0')) {
7005: $changes{$item} = 1;
7006: } elsif (($domconfig{'login'}{$item} eq '' ||
7007: $domconfig{'login'}{$item} eq '0') &&
7008: ($env{'form.'.$item} eq '1')) {
7009: $changes{$item} = 1;
7010: }
1.42 raeburn 7011: }
7012: }
1.41 raeburn 7013: }
1.6 raeburn 7014: if (keys(%changes) > 0 || $colchgtext) {
1.41 raeburn 7015: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 7016: if (ref($lastactref) eq 'HASH') {
7017: $lastactref->{'domainconfig'} = 1;
7018: }
1.1 raeburn 7019: $resulttext = &mt('Changes made:').'<ul>';
7020: foreach my $item (sort(keys(%changes))) {
1.135 bisitz 7021: if ($item eq 'loginvia') {
1.112 raeburn 7022: if (ref($changes{$item}) eq 'HASH') {
7023: $resulttext .= '<li>'.&mt('Log-in page availability:').'<ul>';
7024: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
1.128 raeburn 7025: if (defined($servers{$loginhash{login}{loginvia}{$lonhost}{'server'}})) {
7026: if (ref($loginhash{login}{loginvia}{$lonhost}) eq 'HASH') {
7027: my $protocol = $Apache::lonnet::protocol{$env{'form.'.$lonhost.'_server'}};
7028: $protocol = 'http' if ($protocol ne 'https');
7029: my $target = $protocol.'://'.$servers{$env{'form.'.$lonhost.'_server'}};
7030:
7031: if ($loginhash{login}{loginvia}{$lonhost}{'serverpath'} eq 'custom') {
7032: $target .= $loginhash{login}{loginvia}{$lonhost}{'custompath'};
7033: } else {
7034: $target .= $loginhash{login}{loginvia}{$lonhost}{'serverpath'};
7035: }
7036: $resulttext .= '<li>'.&mt('Server: [_1] log-in page redirects to [_2].',$servers{$lonhost},'<a href="'.$target.'">'.$target.'</a>');
7037: if ($loginhash{login}{loginvia}{$lonhost}{'exempt'} ne '') {
7038: $resulttext .= ' '.&mt('No redirection for clients from following IPs:').' '.$loginhash{login}{loginvia}{$lonhost}{'exempt'};
7039: }
7040: $resulttext .= '</li>';
7041: } else {
7042: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$lonhost).'</li>';
7043: }
1.112 raeburn 7044: } else {
1.128 raeburn 7045: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$servers{$lonhost}).'</li>';
1.112 raeburn 7046: }
7047: }
1.128 raeburn 7048: $resulttext .= '</ul></li>';
1.112 raeburn 7049: }
1.168 raeburn 7050: } elsif ($item eq 'helpurl') {
7051: if (ref($changes{$item}) eq 'HASH') {
7052: foreach my $lang (sort(keys(%{$changes{$item}}))) {
7053: if (grep(/^\Q$lang\E$/,@delurls)) {
7054: my ($chg,$link);
7055: $link = &Apache::loncommon::modal_link($defaulthelpfile,$defaulttext,600,500);
7056: if ($lang eq 'nolang') {
7057: $chg = &mt('custom log-in help file removed for no preferred language; [_1]',$link);
7058: } else {
7059: $chg = &mt('custom log-in help file removed for specific language: [_1]; [_2]',$langchoices{$lang},$link);
7060: }
7061: $resulttext .= '<li>'.$chg.'</li>';
7062: } else {
7063: my $chg;
7064: if ($lang eq 'nolang') {
7065: $chg = &mt('custom log-in help file for no preferred language');
7066: } else {
7067: $chg = &mt('custom log-in help file for specific language: [_1]',$langchoices{$lang});
7068: }
7069: $resulttext .= '<li>'.&Apache::loncommon::modal_link(
7070: $loginhash{'login'}{'helpurl'}{$lang}.
7071: '?inhibitmenu=yes',$chg,600,500).
7072: '</li>';
7073: }
7074: }
7075: }
1.256 raeburn 7076: } elsif ($item eq 'headtag') {
7077: if (ref($changes{$item}) eq 'HASH') {
7078: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
7079: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
7080: $resulttext .= '<li>'.&mt('custom markup file removed for [_1]',$domservers{$lonhost}).'</li>';
7081: } elsif (ref($loginhash{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
7082: $resulttext .= '<li><a href="'.
7083: "javascript:void(open('$loginhash{'login'}{'headtag'}{$lonhost}{'url'}?inhibitmenu=yes','Custom_HeadTag',
7084: 'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
7085: '">'.&mt('custom markup').'</a> '.&mt('(for [_1])',$servers{$lonhost}).' ';
7086: if ($possexempt{$lonhost}) {
7087: $resulttext .= &mt('not included for client IP(s): [_1]',$possexempt{$lonhost});
7088: } else {
7089: $resulttext .= &mt('included for any client IP');
7090: }
7091: $resulttext .= '</li>';
7092: }
7093: }
7094: }
1.169 raeburn 7095: } elsif ($item eq 'captcha') {
7096: if (ref($loginhash{'login'}) eq 'HASH') {
1.210 raeburn 7097: my $chgtxt;
1.169 raeburn 7098: if ($loginhash{'login'}{$item} eq 'notused') {
7099: $chgtxt .= &mt('No CAPTCHA validation in use for helpdesk form.');
7100: } else {
7101: my %captchas = &captcha_phrases();
7102: if ($captchas{$loginhash{'login'}{$item}}) {
7103: $chgtxt .= &mt("Validation for helpdesk form set to $captchas{$loginhash{'login'}{$item}}.");
7104: } else {
7105: $chgtxt .= &mt('Validation for helpdesk form set to unknown type.');
7106: }
7107: }
7108: $resulttext .= '<li>'.$chgtxt.'</li>';
7109: }
7110: } elsif ($item eq 'recaptchakeys') {
7111: if (ref($loginhash{'login'}) eq 'HASH') {
7112: my ($privkey,$pubkey);
7113: if (ref($loginhash{'login'}{$item}) eq 'HASH') {
7114: $pubkey = $loginhash{'login'}{$item}{'public'};
7115: $privkey = $loginhash{'login'}{$item}{'private'};
7116: }
7117: my $chgtxt .= &mt('ReCAPTCHA keys changes').'<ul>';
7118: if (!$pubkey) {
7119: $chgtxt .= '<li>'.&mt('Public key deleted').'</li>';
7120: } else {
7121: $chgtxt .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
7122: }
7123: if (!$privkey) {
7124: $chgtxt .= '<li>'.&mt('Private key deleted').'</li>';
7125: } else {
1.251 raeburn 7126: $chgtxt .= '<li>'.&mt('Private key set to [_1]',$privkey).'</li>';
1.169 raeburn 7127: }
7128: $chgtxt .= '</ul>';
7129: $resulttext .= '<li>'.$chgtxt.'</li>';
7130: }
1.269 raeburn 7131: } elsif ($item eq 'recaptchaversion') {
7132: if (ref($loginhash{'login'}) eq 'HASH') {
7133: if ($loginhash{'login'}{'captcha'} eq 'recaptcha') {
1.270 raeburn 7134: $resulttext .= '<li>'.&mt('ReCAPTCHA for helpdesk form set to version [_1]',$loginhash{'login'}{'recaptchaversion'}).
1.269 raeburn 7135: '</li>';
7136: }
7137: }
1.41 raeburn 7138: } else {
7139: $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
7140: }
1.1 raeburn 7141: }
1.6 raeburn 7142: $resulttext .= $colchgtext.'</ul>';
1.1 raeburn 7143: } else {
7144: $resulttext = &mt('No changes made to log-in page settings');
7145: }
7146: } else {
1.11 albertel 7147: $resulttext = '<span class="LC_error">'.
7148: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 7149: }
1.6 raeburn 7150: if ($errors) {
1.9 raeburn 7151: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.6 raeburn 7152: $errors.'</ul>';
7153: }
7154: return $resulttext;
7155: }
7156:
1.256 raeburn 7157:
7158: sub check_exempt_addresses {
7159: my ($iplist) = @_;
7160: $iplist =~ s/^\s+//;
7161: $iplist =~ s/\s+$//;
7162: my @poss_ips = split(/\s*[,:]\s*/,$iplist);
7163: my (@okips,$new);
7164: foreach my $ip (@poss_ips) {
7165: if ($ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
7166: if (($1 <= 255) && ($2 <= 255) && ($3 <= 255) && ($4 <= 255)) {
7167: push(@okips,$ip);
7168: }
7169: }
7170: }
7171: if (@okips > 0) {
7172: $new = join(',',@okips);
7173: } else {
7174: $new = '';
7175: }
7176: return $new;
7177: }
7178:
1.6 raeburn 7179: sub color_font_choices {
7180: my %choices =
7181: &Apache::lonlocal::texthash (
7182: img => "Header",
7183: bgs => "Background colors",
7184: links => "Link colors",
1.55 raeburn 7185: images => "Images",
1.6 raeburn 7186: font => "Font color",
1.201 raeburn 7187: fontmenu => "Font menu",
1.76 raeburn 7188: pgbg => "Page",
1.6 raeburn 7189: tabbg => "Header",
7190: sidebg => "Border",
7191: link => "Link",
7192: alink => "Active link",
7193: vlink => "Visited link",
7194: );
7195: return %choices;
7196: }
7197:
7198: sub modify_rolecolors {
1.205 raeburn 7199: my ($r,$dom,$confname,$roles,$lastactref,%domconfig) = @_;
1.6 raeburn 7200: my ($resulttext,%rolehash);
7201: $rolehash{'rolecolors'} = {};
1.55 raeburn 7202: if (ref($domconfig{'rolecolors'}) ne 'HASH') {
7203: if ($domconfig{'rolecolors'} eq '') {
7204: $domconfig{'rolecolors'} = {};
7205: }
7206: }
1.9 raeburn 7207: my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
1.6 raeburn 7208: $domconfig{'rolecolors'},$rolehash{'rolecolors'});
7209: my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
7210: $dom);
7211: if ($putresult eq 'ok') {
7212: if (keys(%changes) > 0) {
1.41 raeburn 7213: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 7214: if (ref($lastactref) eq 'HASH') {
7215: $lastactref->{'domainconfig'} = 1;
7216: }
1.6 raeburn 7217: $resulttext = &display_colorchgs($dom,\%changes,$roles,
7218: $rolehash{'rolecolors'});
7219: } else {
7220: $resulttext = &mt('No changes made to default color schemes');
7221: }
7222: } else {
1.11 albertel 7223: $resulttext = '<span class="LC_error">'.
7224: &mt('An error occurred: [_1]',$putresult).'</span>';
1.6 raeburn 7225: }
7226: if ($errors) {
7227: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
7228: $errors.'</ul>';
7229: }
7230: return $resulttext;
7231: }
7232:
7233: sub modify_colors {
1.9 raeburn 7234: my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
1.12 raeburn 7235: my (%changes,%choices);
1.51 raeburn 7236: my @bgs;
1.6 raeburn 7237: my @links = ('link','alink','vlink');
1.41 raeburn 7238: my @logintext;
1.6 raeburn 7239: my @images;
7240: my $servadm = $r->dir_config('lonAdmEMail');
7241: my $errors;
1.200 raeburn 7242: my %defaults;
1.6 raeburn 7243: foreach my $role (@{$roles}) {
7244: if ($role eq 'login') {
1.12 raeburn 7245: %choices = &login_choices();
1.41 raeburn 7246: @logintext = ('textcol','bgcol');
1.12 raeburn 7247: } else {
7248: %choices = &color_font_choices();
7249: }
7250: if ($role eq 'login') {
1.41 raeburn 7251: @images = ('img','logo','domlogo','login');
1.51 raeburn 7252: @bgs = ('pgbg','mainbg','sidebg');
1.6 raeburn 7253: } else {
7254: @images = ('img');
1.200 raeburn 7255: @bgs = ('pgbg','tabbg','sidebg');
7256: }
7257: my %defaults = &role_defaults($role,\@bgs,\@links,\@images,\@logintext);
7258: unless ($env{'form.'.$role.'_font'} eq $defaults{'font'}) {
7259: $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
7260: }
7261: if ($role eq 'login') {
7262: foreach my $item (@logintext) {
1.234 raeburn 7263: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
7264: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
7265: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
7266: }
7267: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'logintext'}{$item})) {
1.200 raeburn 7268: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
7269: }
7270: }
7271: } else {
1.234 raeburn 7272: $env{'form.'.$role.'_fontmenu'} = lc($env{'form.'.$role.'_fontmenu'});
7273: if ($env{'form.'.$role.'_fontmenu'} =~ /^\w+/) {
7274: $env{'form.'.$role.'_fontmenu'} = '#'.$env{'form.'.$role.'_fontmenu'};
7275: }
7276: unless($env{'form.'.$role.'_fontmenu'} eq lc($defaults{'fontmenu'})) {
1.200 raeburn 7277: $confhash->{$role}{'fontmenu'} = $env{'form.'.$role.'_fontmenu'};
7278: }
1.6 raeburn 7279: }
1.200 raeburn 7280: foreach my $item (@bgs) {
1.234 raeburn 7281: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
7282: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
7283: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
7284: }
7285: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'bgs'}{$item})) {
1.200 raeburn 7286: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
7287: }
7288: }
7289: foreach my $item (@links) {
1.234 raeburn 7290: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
7291: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
7292: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
7293: }
7294: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'links'}{$item})) {
1.200 raeburn 7295: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
7296: }
1.6 raeburn 7297: }
1.46 raeburn 7298: my ($configuserok,$author_ok,$switchserver) =
7299: &config_check($dom,$confname,$servadm);
1.9 raeburn 7300: my ($width,$height) = &thumb_dimensions();
1.40 raeburn 7301: if (ref($domconfig->{$role}) ne 'HASH') {
7302: $domconfig->{$role} = {};
7303: }
1.8 raeburn 7304: foreach my $img (@images) {
1.70 raeburn 7305: if (($role eq 'login') && (($img eq 'img') || ($img eq 'logo'))) {
7306: if (defined($env{'form.login_showlogo_'.$img})) {
7307: $confhash->{$role}{'showlogo'}{$img} = 1;
7308: } else {
7309: $confhash->{$role}{'showlogo'}{$img} = 0;
7310: }
7311: }
1.18 albertel 7312: if ( ! $env{'form.'.$role.'_'.$img.'.filename'}
7313: && !defined($domconfig->{$role}{$img})
7314: && !$env{'form.'.$role.'_del_'.$img}
7315: && $env{'form.'.$role.'_import_'.$img}) {
7316: # import the old configured image from the .tab setting
7317: # if they haven't provided a new one
7318: $domconfig->{$role}{$img} =
7319: $env{'form.'.$role.'_import_'.$img};
7320: }
1.6 raeburn 7321: if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
1.9 raeburn 7322: my $error;
1.6 raeburn 7323: if ($configuserok eq 'ok') {
1.9 raeburn 7324: if ($switchserver) {
1.12 raeburn 7325: $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
1.9 raeburn 7326: } else {
7327: if ($author_ok eq 'ok') {
7328: my ($result,$logourl) =
7329: &publishlogo($r,'upload',$role.'_'.$img,
7330: $dom,$confname,$img,$width,$height);
7331: if ($result eq 'ok') {
7332: $confhash->{$role}{$img} = $logourl;
1.12 raeburn 7333: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 7334: } else {
1.12 raeburn 7335: $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 7336: }
7337: } else {
1.46 raeburn 7338: $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 7339: }
7340: }
7341: } else {
1.46 raeburn 7342: $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 7343: }
7344: if ($error) {
1.8 raeburn 7345: &Apache::lonnet::logthis($error);
1.11 albertel 7346: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
1.8 raeburn 7347: }
7348: } elsif ($domconfig->{$role}{$img} ne '') {
1.9 raeburn 7349: if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
7350: my $error;
7351: if ($configuserok eq 'ok') {
7352: # is confname an author?
7353: if ($switchserver eq '') {
7354: if ($author_ok eq 'ok') {
7355: my ($result,$logourl) =
7356: &publishlogo($r,'copy',$domconfig->{$role}{$img},
7357: $dom,$confname,$img,$width,$height);
7358: if ($result eq 'ok') {
7359: $confhash->{$role}{$img} = $logourl;
1.18 albertel 7360: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 7361: }
7362: }
7363: }
7364: }
1.6 raeburn 7365: }
7366: }
7367: }
7368: if (ref($domconfig) eq 'HASH') {
7369: if (ref($domconfig->{$role}) eq 'HASH') {
7370: foreach my $img (@images) {
7371: if ($domconfig->{$role}{$img} ne '') {
7372: if ($env{'form.'.$role.'_del_'.$img}) {
7373: $confhash->{$role}{$img} = '';
1.12 raeburn 7374: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 7375: } else {
1.9 raeburn 7376: if ($confhash->{$role}{$img} eq '') {
7377: $confhash->{$role}{$img} = $domconfig->{$role}{$img};
7378: }
1.6 raeburn 7379: }
7380: } else {
7381: if ($env{'form.'.$role.'_del_'.$img}) {
7382: $confhash->{$role}{$img} = '';
1.12 raeburn 7383: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 7384: }
7385: }
1.70 raeburn 7386: if (($role eq 'login') && (($img eq 'logo') || ($img eq 'img'))) {
7387: if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') {
7388: if ($confhash->{$role}{'showlogo'}{$img} ne
7389: $domconfig->{$role}{'showlogo'}{$img}) {
7390: $changes{$role}{'showlogo'}{$img} = 1;
7391: }
7392: } else {
7393: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
7394: $changes{$role}{'showlogo'}{$img} = 1;
7395: }
7396: }
7397: }
7398: }
1.6 raeburn 7399: if ($domconfig->{$role}{'font'} ne '') {
7400: if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
7401: $changes{$role}{'font'} = 1;
7402: }
7403: } else {
7404: if ($confhash->{$role}{'font'}) {
7405: $changes{$role}{'font'} = 1;
7406: }
7407: }
1.107 raeburn 7408: if ($role ne 'login') {
7409: if ($domconfig->{$role}{'fontmenu'} ne '') {
7410: if ($confhash->{$role}{'fontmenu'} ne $domconfig->{$role}{'fontmenu'}) {
7411: $changes{$role}{'fontmenu'} = 1;
7412: }
7413: } else {
7414: if ($confhash->{$role}{'fontmenu'}) {
7415: $changes{$role}{'fontmenu'} = 1;
7416: }
1.97 tempelho 7417: }
7418: }
1.6 raeburn 7419: foreach my $item (@bgs) {
7420: if ($domconfig->{$role}{$item} ne '') {
7421: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
7422: $changes{$role}{'bgs'}{$item} = 1;
7423: }
7424: } else {
7425: if ($confhash->{$role}{$item}) {
7426: $changes{$role}{'bgs'}{$item} = 1;
7427: }
7428: }
7429: }
7430: foreach my $item (@links) {
7431: if ($domconfig->{$role}{$item} ne '') {
7432: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
7433: $changes{$role}{'links'}{$item} = 1;
7434: }
7435: } else {
7436: if ($confhash->{$role}{$item}) {
7437: $changes{$role}{'links'}{$item} = 1;
7438: }
7439: }
7440: }
1.41 raeburn 7441: foreach my $item (@logintext) {
7442: if ($domconfig->{$role}{$item} ne '') {
7443: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
7444: $changes{$role}{'logintext'}{$item} = 1;
7445: }
7446: } else {
7447: if ($confhash->{$role}{$item}) {
7448: $changes{$role}{'logintext'}{$item} = 1;
7449: }
7450: }
7451: }
1.6 raeburn 7452: } else {
7453: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 7454: \@logintext,$confhash,\%changes);
1.6 raeburn 7455: }
7456: } else {
7457: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 7458: \@logintext,$confhash,\%changes);
1.6 raeburn 7459: }
7460: }
7461: return ($errors,%changes);
7462: }
7463:
1.46 raeburn 7464: sub config_check {
7465: my ($dom,$confname,$servadm) = @_;
7466: my ($configuserok,$author_ok,$switchserver,%currroles);
7467: my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
7468: ($configuserok,%currroles) = &check_configuser($uhome,$dom,
7469: $confname,$servadm);
7470: if ($configuserok eq 'ok') {
7471: $switchserver = &check_switchserver($dom,$confname);
7472: if ($switchserver eq '') {
7473: $author_ok = &check_authorstatus($dom,$confname,%currroles);
7474: }
7475: }
7476: return ($configuserok,$author_ok,$switchserver);
7477: }
7478:
1.6 raeburn 7479: sub default_change_checker {
1.41 raeburn 7480: my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
1.6 raeburn 7481: foreach my $item (@{$links}) {
7482: if ($confhash->{$role}{$item}) {
7483: $changes->{$role}{'links'}{$item} = 1;
7484: }
7485: }
7486: foreach my $item (@{$bgs}) {
7487: if ($confhash->{$role}{$item}) {
7488: $changes->{$role}{'bgs'}{$item} = 1;
7489: }
7490: }
1.41 raeburn 7491: foreach my $item (@{$logintext}) {
7492: if ($confhash->{$role}{$item}) {
7493: $changes->{$role}{'logintext'}{$item} = 1;
7494: }
7495: }
1.6 raeburn 7496: foreach my $img (@{$images}) {
7497: if ($env{'form.'.$role.'_del_'.$img}) {
7498: $confhash->{$role}{$img} = '';
1.12 raeburn 7499: $changes->{$role}{'images'}{$img} = 1;
1.6 raeburn 7500: }
1.70 raeburn 7501: if ($role eq 'login') {
7502: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
7503: $changes->{$role}{'showlogo'}{$img} = 1;
7504: }
7505: }
1.6 raeburn 7506: }
7507: if ($confhash->{$role}{'font'}) {
7508: $changes->{$role}{'font'} = 1;
7509: }
1.48 raeburn 7510: }
1.6 raeburn 7511:
7512: sub display_colorchgs {
7513: my ($dom,$changes,$roles,$confhash) = @_;
7514: my (%choices,$resulttext);
7515: if (!grep(/^login$/,@{$roles})) {
7516: $resulttext = &mt('Changes made:').'<br />';
7517: }
7518: foreach my $role (@{$roles}) {
7519: if ($role eq 'login') {
7520: %choices = &login_choices();
7521: } else {
7522: %choices = &color_font_choices();
7523: }
7524: if (ref($changes->{$role}) eq 'HASH') {
7525: if ($role ne 'login') {
7526: $resulttext .= '<h4>'.&mt($role).'</h4>';
7527: }
7528: foreach my $key (sort(keys(%{$changes->{$role}}))) {
7529: if ($role ne 'login') {
7530: $resulttext .= '<ul>';
7531: }
7532: if (ref($changes->{$role}{$key}) eq 'HASH') {
7533: if ($role ne 'login') {
7534: $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
7535: }
7536: foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
1.70 raeburn 7537: if (($role eq 'login') && ($key eq 'showlogo')) {
7538: if ($confhash->{$role}{$key}{$item}) {
7539: $resulttext .= '<li>'.&mt("$choices{$item} set to be displayed").'</li>';
7540: } else {
7541: $resulttext .= '<li>'.&mt("$choices{$item} set to not be displayed").'</li>';
7542: }
7543: } elsif ($confhash->{$role}{$item} eq '') {
1.6 raeburn 7544: $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
7545: } else {
1.12 raeburn 7546: my $newitem = $confhash->{$role}{$item};
7547: if ($key eq 'images') {
7548: $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" valign="bottom" />';
7549: }
7550: $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
1.6 raeburn 7551: }
7552: }
7553: if ($role ne 'login') {
7554: $resulttext .= '</ul></li>';
7555: }
7556: } else {
7557: if ($confhash->{$role}{$key} eq '') {
7558: $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
7559: } else {
7560: $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
7561: }
7562: }
7563: if ($role ne 'login') {
7564: $resulttext .= '</ul>';
7565: }
7566: }
7567: }
7568: }
1.3 raeburn 7569: return $resulttext;
1.1 raeburn 7570: }
7571:
1.9 raeburn 7572: sub thumb_dimensions {
7573: return ('200','50');
7574: }
7575:
1.16 raeburn 7576: sub check_dimensions {
7577: my ($inputfile) = @_;
7578: my ($fullwidth,$fullheight);
7579: if ($inputfile =~ m|^[/\w.\-]+$|) {
7580: if (open(PIPE,"identify $inputfile 2>&1 |")) {
7581: my $imageinfo = <PIPE>;
7582: if (!close(PIPE)) {
7583: &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
7584: }
7585: chomp($imageinfo);
7586: my ($fullsize) =
1.21 raeburn 7587: ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
1.16 raeburn 7588: if ($fullsize) {
7589: ($fullwidth,$fullheight) = split(/x/,$fullsize);
7590: }
7591: }
7592: }
7593: return ($fullwidth,$fullheight);
7594: }
7595:
1.9 raeburn 7596: sub check_configuser {
7597: my ($uhome,$dom,$confname,$servadm) = @_;
7598: my ($configuserok,%currroles);
7599: if ($uhome eq 'no_host') {
7600: srand( time() ^ ($$ + ($$ << 15)) ); # Seed rand.
7601: my $configpass = &LONCAPA::Enrollment::create_password();
7602: $configuserok =
7603: &Apache::lonnet::modifyuser($dom,$confname,'','internal',
7604: $configpass,'','','','','',undef,$servadm);
7605: } else {
7606: $configuserok = 'ok';
7607: %currroles =
7608: &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
7609: }
7610: return ($configuserok,%currroles);
7611: }
7612:
7613: sub check_authorstatus {
7614: my ($dom,$confname,%currroles) = @_;
7615: my $author_ok;
1.40 raeburn 7616: if (!$currroles{':'.$dom.':au'}) {
1.9 raeburn 7617: my $start = time;
7618: my $end = 0;
7619: $author_ok =
7620: &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
1.47 raeburn 7621: 'au',$end,$start,'','','domconfig');
1.9 raeburn 7622: } else {
7623: $author_ok = 'ok';
7624: }
7625: return $author_ok;
7626: }
7627:
7628: sub publishlogo {
1.46 raeburn 7629: my ($r,$action,$formname,$dom,$confname,$subdir,$thumbwidth,$thumbheight,$savefileas) = @_;
1.267 raeburn 7630: my ($output,$fname,$logourl,$madethumb);
1.9 raeburn 7631: if ($action eq 'upload') {
7632: $fname=$env{'form.'.$formname.'.filename'};
7633: chop($env{'form.'.$formname});
7634: } else {
7635: ($fname) = ($formname =~ /([^\/]+)$/);
7636: }
1.46 raeburn 7637: if ($savefileas ne '') {
7638: $fname = $savefileas;
7639: }
1.9 raeburn 7640: $fname=&Apache::lonnet::clean_filename($fname);
7641: # See if there is anything left
7642: unless ($fname) { return ('error: no uploaded file'); }
7643: $fname="$subdir/$fname";
1.210 raeburn 7644: my $docroot=$r->dir_config('lonDocRoot');
1.164 raeburn 7645: my $filepath="$docroot/priv";
7646: my $relpath = "$dom/$confname";
1.9 raeburn 7647: my ($fnamepath,$file,$fetchthumb);
7648: $file=$fname;
7649: if ($fname=~m|/|) {
7650: ($fnamepath,$file) = ($fname =~ m|^(.*)/([^/]+)$|);
7651: }
1.164 raeburn 7652: my @parts=split(/\//,"$filepath/$relpath/$fnamepath");
1.9 raeburn 7653: my $count;
1.164 raeburn 7654: for ($count=5;$count<=$#parts;$count++) {
1.9 raeburn 7655: $filepath.="/$parts[$count]";
7656: if ((-e $filepath)!=1) {
7657: mkdir($filepath,02770);
7658: }
7659: }
7660: # Check for bad extension and disallow upload
7661: if ($file=~/\.(\w+)$/ &&
7662: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
7663: $output =
1.207 bisitz 7664: &mt('Invalid file extension ([_1]) - reserved for internal use.',$1);
1.9 raeburn 7665: } elsif ($file=~/\.(\w+)$/ &&
7666: !defined(&Apache::loncommon::fileembstyle($1))) {
7667: $output = &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
7668: } elsif ($file=~/\.(\d+)\.(\w+)$/) {
1.195 bisitz 7669: $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 7670: } elsif (-d "$filepath/$file") {
1.195 bisitz 7671: $output = &mt('Filename is a directory name - rename the file and re-upload');
1.9 raeburn 7672: } else {
7673: my $source = $filepath.'/'.$file;
7674: my $logfile;
7675: if (!open($logfile,">>$source".'.log')) {
1.196 raeburn 7676: return (&mt('No write permission to Authoring Space'));
1.9 raeburn 7677: }
7678: print $logfile
7679: "\n================= Publish ".localtime()." ================\n".
7680: $env{'user.name'}.':'.$env{'user.domain'}."\n";
7681: # Save the file
7682: if (!open(FH,'>'.$source)) {
7683: &Apache::lonnet::logthis('Failed to create '.$source);
7684: return (&mt('Failed to create file'));
7685: }
7686: if ($action eq 'upload') {
7687: if (!print FH ($env{'form.'.$formname})) {
7688: &Apache::lonnet::logthis('Failed to write to '.$source);
7689: return (&mt('Failed to write file'));
7690: }
7691: } else {
7692: my $original = &Apache::lonnet::filelocation('',$formname);
7693: if(!copy($original,$source)) {
7694: &Apache::lonnet::logthis('Failed to copy '.$original.' to '.$source);
7695: return (&mt('Failed to write file'));
7696: }
7697: }
7698: close(FH);
7699: chmod(0660, $source); # Permissions to rw-rw---.
7700:
7701: my $targetdir=$docroot.'/res/'.$dom.'/'.$confname .'/'.$fnamepath;
7702: my $copyfile=$targetdir.'/'.$file;
7703:
7704: my @parts=split(/\//,$targetdir);
7705: my $path="/$parts[1]/$parts[2]/$parts[3]/$parts[4]";
7706: for (my $count=5;$count<=$#parts;$count++) {
7707: $path.="/$parts[$count]";
7708: if (!-e $path) {
7709: print $logfile "\nCreating directory ".$path;
7710: mkdir($path,02770);
7711: }
7712: }
7713: my $versionresult;
7714: if (-e $copyfile) {
7715: $versionresult = &logo_versioning($targetdir,$file,$logfile);
7716: } else {
7717: $versionresult = 'ok';
7718: }
7719: if ($versionresult eq 'ok') {
7720: if (copy($source,$copyfile)) {
7721: print $logfile "\nCopied original source to ".$copyfile."\n";
7722: $output = 'ok';
7723: $logourl = '/res/'.$dom.'/'.$confname.'/'.$fname;
1.155 raeburn 7724: push(@{$modified_urls},[$copyfile,$source]);
7725: my $metaoutput =
7726: &write_metadata($dom,$confname,$formname,$targetdir,$file,$logfile);
7727: unless ($registered_cleanup) {
7728: my $handlers = $r->get_handlers('PerlCleanupHandler');
7729: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
7730: $registered_cleanup=1;
7731: }
1.9 raeburn 7732: } else {
7733: print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";
7734: $output = &mt('Failed to copy file to RES space').", $!";
7735: }
7736: if (($thumbwidth =~ /^\d+$/) && ($thumbheight =~ /^\d+$/)) {
7737: my $inputfile = $filepath.'/'.$file;
7738: my $outfile = $filepath.'/'.'tn-'.$file;
1.16 raeburn 7739: my ($fullwidth,$fullheight) = &check_dimensions($inputfile);
7740: if ($fullwidth ne '' && $fullheight ne '') {
7741: if ($fullwidth > $thumbwidth && $fullheight > $thumbheight) {
7742: my $thumbsize = $thumbwidth.'x'.$thumbheight;
7743: system("convert -sample $thumbsize $inputfile $outfile");
7744: chmod(0660, $filepath.'/tn-'.$file);
7745: if (-e $outfile) {
7746: my $copyfile=$targetdir.'/tn-'.$file;
7747: if (copy($outfile,$copyfile)) {
7748: print $logfile "\nCopied source to ".$copyfile."\n";
1.155 raeburn 7749: my $thumb_metaoutput =
7750: &write_metadata($dom,$confname,$formname,
7751: $targetdir,'tn-'.$file,$logfile);
7752: push(@{$modified_urls},[$copyfile,$outfile]);
7753: unless ($registered_cleanup) {
7754: my $handlers = $r->get_handlers('PerlCleanupHandler');
7755: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
7756: $registered_cleanup=1;
7757: }
1.267 raeburn 7758: $madethumb = 1;
1.16 raeburn 7759: } else {
7760: print $logfile "\nUnable to write ".$copyfile.
7761: ':'.$!."\n";
7762: }
7763: }
1.9 raeburn 7764: }
7765: }
7766: }
7767: } else {
7768: $output = $versionresult;
7769: }
7770: }
1.267 raeburn 7771: return ($output,$logourl,$madethumb);
1.9 raeburn 7772: }
7773:
7774: sub logo_versioning {
7775: my ($targetdir,$file,$logfile) = @_;
7776: my $target = $targetdir.'/'.$file;
7777: my ($maxversion,$fn,$extn,$output);
7778: $maxversion = 0;
7779: if ($file =~ /^(.+)\.(\w+)$/) {
7780: $fn=$1;
7781: $extn=$2;
7782: }
7783: opendir(DIR,$targetdir);
7784: while (my $filename=readdir(DIR)) {
7785: if ($filename=~/\Q$fn\E\.(\d+)\.\Q$extn\E$/) {
7786: $maxversion=($1>$maxversion)?$1:$maxversion;
7787: }
7788: }
7789: $maxversion++;
7790: print $logfile "\nCreating old version ".$maxversion."\n";
7791: my $copyfile=$targetdir.'/'.$fn.'.'.$maxversion.'.'.$extn;
7792: if (copy($target,$copyfile)) {
7793: print $logfile "Copied old target to ".$copyfile."\n";
7794: $copyfile=$copyfile.'.meta';
7795: if (copy($target.'.meta',$copyfile)) {
7796: print $logfile "Copied old target metadata to ".$copyfile."\n";
7797: $output = 'ok';
7798: } else {
7799: print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";
7800: $output = &mt('Failed to copy old meta').", $!, ";
7801: }
7802: } else {
7803: print $logfile "Unable to write ".$copyfile.':'.$!."\n";
7804: $output = &mt('Failed to copy old target').", $!, ";
7805: }
7806: return $output;
7807: }
7808:
7809: sub write_metadata {
7810: my ($dom,$confname,$formname,$targetdir,$file,$logfile) = @_;
7811: my (%metadatafields,%metadatakeys,$output);
7812: $metadatafields{'title'}=$formname;
7813: $metadatafields{'creationdate'}=time;
7814: $metadatafields{'lastrevisiondate'}=time;
7815: $metadatafields{'copyright'}='public';
7816: $metadatafields{'modifyinguser'}=$env{'user.name'}.':'.
7817: $env{'user.domain'};
7818: $metadatafields{'authorspace'}=$confname.':'.$dom;
7819: $metadatafields{'domain'}=$dom;
7820: {
7821: print $logfile "\nWrite metadata file for ".$targetdir.'/'.$file;
7822: my $mfh;
1.155 raeburn 7823: if (open($mfh,'>'.$targetdir.'/'.$file.'.meta')) {
1.184 raeburn 7824: foreach (sort(keys(%metadatafields))) {
1.155 raeburn 7825: unless ($_=~/\./) {
7826: my $unikey=$_;
7827: $unikey=~/^([A-Za-z]+)/;
7828: my $tag=$1;
7829: $tag=~tr/A-Z/a-z/;
7830: print $mfh "\n\<$tag";
7831: foreach (split(/\,/,$metadatakeys{$unikey})) {
7832: my $value=$metadatafields{$unikey.'.'.$_};
7833: $value=~s/\"/\'\'/g;
7834: print $mfh ' '.$_.'="'.$value.'"';
7835: }
7836: print $mfh '>'.
7837: &HTML::Entities::encode($metadatafields{$unikey},'<>&"')
7838: .'</'.$tag.'>';
7839: }
7840: }
7841: $output = 'ok';
7842: print $logfile "\nWrote metadata";
7843: close($mfh);
7844: } else {
7845: print $logfile "\nFailed to open metadata file";
1.9 raeburn 7846: $output = &mt('Could not write metadata');
7847: }
7848: }
1.155 raeburn 7849: return $output;
7850: }
7851:
7852: sub notifysubscribed {
7853: foreach my $targetsource (@{$modified_urls}){
7854: next unless (ref($targetsource) eq 'ARRAY');
7855: my ($target,$source)=@{$targetsource};
7856: if ($source ne '') {
7857: if (open(my $logfh,'>>'.$source.'.log')) {
7858: print $logfh "\nCleanup phase: Notifications\n";
7859: my @subscribed=&subscribed_hosts($target);
7860: foreach my $subhost (@subscribed) {
7861: print $logfh "\nNotifying host ".$subhost.':';
7862: my $reply=&Apache::lonnet::critical('update:'.$target,$subhost);
7863: print $logfh $reply;
7864: }
7865: my @subscribedmeta=&subscribed_hosts("$target.meta");
7866: foreach my $subhost (@subscribedmeta) {
7867: print $logfh "\nNotifying host for metadata only ".$subhost.':';
7868: my $reply=&Apache::lonnet::critical('update:'.$target.'.meta',
7869: $subhost);
7870: print $logfh $reply;
7871: }
7872: print $logfh "\n============ Done ============\n";
1.160 raeburn 7873: close($logfh);
1.155 raeburn 7874: }
7875: }
7876: }
7877: return OK;
7878: }
7879:
7880: sub subscribed_hosts {
7881: my ($target) = @_;
7882: my @subscribed;
7883: if (open(my $fh,"<$target.subscription")) {
7884: while (my $subline=<$fh>) {
7885: if ($subline =~ /^($match_lonid):/) {
7886: my $host = $1;
7887: if ($host ne $Apache::lonnet::perlvar{'lonHostID'}) {
7888: unless (grep(/^\Q$host\E$/,@subscribed)) {
7889: push(@subscribed,$host);
7890: }
7891: }
7892: }
7893: }
7894: }
7895: return @subscribed;
1.9 raeburn 7896: }
7897:
7898: sub check_switchserver {
7899: my ($dom,$confname) = @_;
7900: my ($allowed,$switchserver);
7901: my $home = &Apache::lonnet::homeserver($confname,$dom);
7902: if ($home eq 'no_host') {
7903: $home = &Apache::lonnet::domain($dom,'primary');
7904: }
7905: my @ids=&Apache::lonnet::current_machine_ids();
1.10 albertel 7906: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
7907: if (!$allowed) {
1.180 raeburn 7908: $switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role=dc./'.$dom.'/&destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
1.9 raeburn 7909: }
7910: return $switchserver;
7911: }
7912:
1.1 raeburn 7913: sub modify_quotas {
1.216 raeburn 7914: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
1.101 raeburn 7915: my ($context,@usertools,@options,%validations,%titles,%confhash,%toolshash,
1.216 raeburn 7916: %limithash,$toolregexp,%conditions,$resulttext,%changes,$confname,$configuserok,
1.235 raeburn 7917: $author_ok,$switchserver,$errors,$validationitemsref,$validationnamesref,
7918: $validationfieldsref);
1.86 raeburn 7919: if ($action eq 'quotas') {
7920: $context = 'tools';
1.163 raeburn 7921: } else {
1.86 raeburn 7922: $context = $action;
7923: }
7924: if ($context eq 'requestcourses') {
1.271 raeburn 7925: @usertools = ('official','unofficial','community','textbook','placement');
1.106 raeburn 7926: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 7927: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
7928: %titles = &courserequest_titles();
7929: $toolregexp = join('|',@usertools);
7930: %conditions = &courserequest_conditions();
1.216 raeburn 7931: $confname = $dom.'-domainconfig';
7932: my $servadm = $r->dir_config('lonAdmEMail');
7933: ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
1.235 raeburn 7934: ($validationitemsref,$validationnamesref,$validationfieldsref) =
7935: &Apache::loncoursequeueadmin::requestcourses_validation_types();
1.163 raeburn 7936: } elsif ($context eq 'requestauthor') {
7937: @usertools = ('author');
7938: %titles = &authorrequest_titles();
1.86 raeburn 7939: } else {
1.162 raeburn 7940: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 7941: %titles = &tool_titles();
1.86 raeburn 7942: }
1.212 raeburn 7943: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.44 raeburn 7944: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 7945: foreach my $key (keys(%env)) {
1.101 raeburn 7946: if ($context eq 'requestcourses') {
7947: if ($key =~ /^form\.crsreq_($toolregexp)_(.+)$/) {
7948: my $item = $1;
7949: my $type = $2;
7950: if ($type =~ /^limit_(.+)/) {
7951: $limithash{$item}{$1} = $env{$key};
7952: } else {
7953: $confhash{$item}{$type} = $env{$key};
7954: }
7955: }
1.163 raeburn 7956: } elsif ($context eq 'requestauthor') {
7957: if ($key =~ /^\Qform.authorreq_\E(.+)$/) {
7958: $confhash{$1} = $env{$key};
7959: }
1.101 raeburn 7960: } else {
1.86 raeburn 7961: if ($key =~ /^form\.quota_(.+)$/) {
7962: $confhash{'defaultquota'}{$1} = $env{$key};
1.197 raeburn 7963: } elsif ($key =~ /^form\.authorquota_(.+)$/) {
7964: $confhash{'authorquota'}{$1} = $env{$key};
7965: } elsif ($key =~ /^form\.\Q$context\E_(.+)$/) {
1.101 raeburn 7966: @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key);
7967: }
1.72 raeburn 7968: }
7969: }
1.163 raeburn 7970: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.224 raeburn 7971: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.'.$context.'notifyapproval');
1.102 raeburn 7972: @approvalnotify = sort(@approvalnotify);
7973: $confhash{'notify'}{'approval'} = join(',',@approvalnotify);
1.271 raeburn 7974: my @crstypes = ('official','unofficial','community','textbook','placement');
1.218 raeburn 7975: my @hasuniquecode = &Apache::loncommon::get_env_multiple('form.uniquecode');
7976: foreach my $type (@hasuniquecode) {
7977: if (grep(/^\Q$type\E$/,@crstypes)) {
7978: $confhash{'uniquecode'}{$type} = 1;
7979: }
1.216 raeburn 7980: }
1.242 raeburn 7981: my (%newbook,%allpos);
1.216 raeburn 7982: if ($context eq 'requestcourses') {
1.242 raeburn 7983: foreach my $type ('textbooks','templates') {
7984: @{$allpos{$type}} = ();
7985: my $invalid;
7986: if ($type eq 'textbooks') {
7987: $invalid = &mt('Invalid LON-CAPA course for textbook');
7988: } else {
7989: $invalid = &mt('Invalid LON-CAPA course for template');
7990: }
7991: if ($env{'form.'.$type.'_addbook'}) {
7992: if (($env{'form.'.$type.'_addbook_cnum'} =~ /^$match_courseid$/) &&
7993: ($env{'form.'.$type.'_addbook_cdom'} =~ /^$match_domain$/)) {
7994: if (&Apache::lonnet::homeserver($env{'form.'.$type.'_addbook_cnum'},
7995: $env{'form.'.$type.'_addbook_cdom'}) eq 'no_host') {
7996: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
7997: } else {
7998: $newbook{$type} = $env{'form.'.$type.'_addbook_cdom'}.'_'.$env{'form.'.$type.'_addbook_cnum'};
7999: my $position = $env{'form.'.$type.'_addbook_pos'};
8000: $position =~ s/\D+//g;
8001: if ($position ne '') {
8002: $allpos{$type}[$position] = $newbook{$type};
8003: }
1.216 raeburn 8004: }
1.242 raeburn 8005: } else {
8006: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
1.216 raeburn 8007: }
8008: }
1.242 raeburn 8009: }
1.216 raeburn 8010: }
1.102 raeburn 8011: if (ref($domconfig{$action}) eq 'HASH') {
8012: if (ref($domconfig{$action}{'notify'}) eq 'HASH') {
8013: if ($domconfig{$action}{'notify'}{'approval'} ne $confhash{'notify'}{'approval'}) {
8014: $changes{'notify'}{'approval'} = 1;
8015: }
8016: } else {
1.144 raeburn 8017: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 8018: $changes{'notify'}{'approval'} = 1;
8019: }
8020: }
1.218 raeburn 8021: if (ref($domconfig{$action}{'uniquecode'}) eq 'HASH') {
8022: if (ref($confhash{'uniquecode'}) eq 'HASH') {
8023: foreach my $crstype (keys(%{$domconfig{$action}{'uniquecode'}})) {
8024: unless ($confhash{'uniquecode'}{$crstype}) {
8025: $changes{'uniquecode'} = 1;
8026: }
8027: }
8028: unless ($changes{'uniquecode'}) {
8029: foreach my $crstype (keys(%{$confhash{'uniquecode'}})) {
8030: unless ($domconfig{$action}{'uniquecode'}{$crstype}) {
8031: $changes{'uniquecode'} = 1;
8032: }
8033: }
8034: }
8035: } else {
8036: $changes{'uniquecode'} = 1;
8037: }
8038: } elsif (ref($confhash{'uniquecode'}) eq 'HASH') {
8039: $changes{'uniquecode'} = 1;
1.216 raeburn 8040: }
8041: if ($context eq 'requestcourses') {
1.242 raeburn 8042: foreach my $type ('textbooks','templates') {
8043: if (ref($domconfig{$action}{$type}) eq 'HASH') {
8044: my %deletions;
8045: my @todelete = &Apache::loncommon::get_env_multiple('form.'.$type.'_del');
8046: if (@todelete) {
8047: map { $deletions{$_} = 1; } @todelete;
8048: }
8049: my %imgdeletions;
8050: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.'.$type.'_image_del');
8051: if (@todeleteimages) {
8052: map { $imgdeletions{$_} = 1; } @todeleteimages;
8053: }
8054: my $maxnum = $env{'form.'.$type.'_maxnum'};
8055: for (my $i=0; $i<=$maxnum; $i++) {
8056: my $itemid = $env{'form.'.$type.'_id_'.$i};
8057: my ($key) = ($itemid =~ /^\Q$type\E_(\w+)$/);
8058: if (ref($domconfig{$action}{$type}{$key}) eq 'HASH') {
8059: if ($deletions{$key}) {
8060: if ($domconfig{$action}{$type}{$key}{'image'}) {
8061: #FIXME need to obsolete item in RES space
8062: }
8063: next;
8064: } else {
8065: my $newpos = $env{'form.'.$itemid};
8066: $newpos =~ s/\D+//g;
1.243 raeburn 8067: foreach my $item ('subject','title','publisher','author') {
8068: next if ((($item eq 'author') || ($item eq 'publisher')) &&
8069: ($type eq 'templates'));
1.242 raeburn 8070: $confhash{$type}{$key}{$item} = $env{'form.'.$type.'_'.$item.'_'.$i};
8071: if ($domconfig{$action}{$type}{$key}{$item} ne $confhash{$type}{$key}{$item}) {
8072: $changes{$type}{$key} = 1;
8073: }
8074: }
8075: $allpos{$type}[$newpos] = $key;
8076: }
8077: if ($imgdeletions{$key}) {
8078: $changes{$type}{$key} = 1;
1.216 raeburn 8079: #FIXME need to obsolete item in RES space
1.242 raeburn 8080: } elsif ($env{'form.'.$type.'_image_'.$i.'.filename'}) {
8081: my ($cdom,$cnum) = split(/_/,$key);
8082: my ($imgurl,$error) = &process_textbook_image($r,$dom,$confname,$type.'_image_'.$i,
8083: $cdom,$cnum,$type,$configuserok,
8084: $switchserver,$author_ok);
8085: if ($imgurl) {
8086: $confhash{$type}{$key}{'image'} = $imgurl;
8087: $changes{$type}{$key} = 1;
1.216 raeburn 8088: }
1.242 raeburn 8089: if ($error) {
8090: &Apache::lonnet::logthis($error);
8091: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
8092: }
8093: } elsif ($domconfig{$action}{$type}{$key}{'image'}) {
8094: $confhash{$type}{$key}{'image'} =
8095: $domconfig{$action}{$type}{$key}{'image'};
1.216 raeburn 8096: }
8097: }
8098: }
8099: }
8100: }
8101: }
1.102 raeburn 8102: } else {
1.144 raeburn 8103: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 8104: $changes{'notify'}{'approval'} = 1;
8105: }
1.218 raeburn 8106: if (ref($confhash{'uniquecode'} eq 'HASH')) {
1.216 raeburn 8107: $changes{'uniquecode'} = 1;
8108: }
8109: }
8110: if ($context eq 'requestcourses') {
1.242 raeburn 8111: foreach my $type ('textbooks','templates') {
8112: if ($newbook{$type}) {
8113: $changes{$type}{$newbook{$type}} = 1;
1.243 raeburn 8114: foreach my $item ('subject','title','publisher','author') {
8115: next if ((($item eq 'author') || ($item eq 'publisher')) &&
8116: ($type eq 'template'));
1.242 raeburn 8117: $env{'form.'.$type.'_addbook_'.$item} =~ s/(`)/'/g;
8118: if ($env{'form.'.$type.'_addbook_'.$item}) {
8119: $confhash{$type}{$newbook{$type}}{$item} = $env{'form.'.$type.'_addbook_'.$item};
8120: }
8121: }
8122: if ($type eq 'textbooks') {
8123: if ($env{'form.'.$type.'_addbook_image.filename'} ne '') {
8124: my ($cdom,$cnum) = split(/_/,$newbook{$type});
8125: my ($imageurl,$error) =
8126: &process_textbook_image($r,$dom,$confname,$type.'_addbook_image',$cdom,$cnum,$type,
8127: $configuserok,$switchserver,$author_ok);
8128: if ($imageurl) {
8129: $confhash{$type}{$newbook{$type}}{'image'} = $imageurl;
8130: }
8131: if ($error) {
8132: &Apache::lonnet::logthis($error);
8133: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
8134: }
8135: }
1.216 raeburn 8136: }
8137: }
1.242 raeburn 8138: if (@{$allpos{$type}} > 0) {
8139: my $idx = 0;
8140: foreach my $item (@{$allpos{$type}}) {
8141: if ($item ne '') {
8142: $confhash{$type}{$item}{'order'} = $idx;
8143: if (ref($domconfig{$action}) eq 'HASH') {
8144: if (ref($domconfig{$action}{$type}) eq 'HASH') {
8145: if (ref($domconfig{$action}{$type}{$item}) eq 'HASH') {
8146: if ($domconfig{$action}{$type}{$item}{'order'} ne $idx) {
8147: $changes{$type}{$item} = 1;
8148: }
1.216 raeburn 8149: }
8150: }
8151: }
1.242 raeburn 8152: $idx ++;
1.216 raeburn 8153: }
8154: }
8155: }
8156: }
1.235 raeburn 8157: if (ref($validationitemsref) eq 'ARRAY') {
8158: foreach my $item (@{$validationitemsref}) {
8159: if ($item eq 'fields') {
8160: my @changed;
8161: @{$confhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.requestcourses_validation_'.$item);
8162: if (@{$confhash{'validation'}{$item}} > 0) {
8163: @{$confhash{'validation'}{$item}} = sort(@{$confhash{'validation'}{$item}});
8164: }
1.266 raeburn 8165: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
8166: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
8167: if (ref($domconfig{'requestcourses'}{'validation'}{$item}) eq 'ARRAY') {
8168: @changed = &Apache::loncommon::compare_arrays($confhash{'validation'}{$item},
8169: $domconfig{'requestcourses'}{'validation'}{$item});
8170: } else {
8171: @changed = @{$confhash{'validation'}{$item}};
8172: }
1.235 raeburn 8173: } else {
8174: @changed = @{$confhash{'validation'}{$item}};
8175: }
8176: } else {
8177: @changed = @{$confhash{'validation'}{$item}};
8178: }
8179: if (@changed) {
8180: if ($confhash{'validation'}{$item}) {
8181: $changes{'validation'}{$item} = join(', ',@{$confhash{'validation'}{$item}});
8182: } else {
8183: $changes{'validation'}{$item} = &mt('None');
8184: }
8185: }
8186: } else {
8187: $confhash{'validation'}{$item} = $env{'form.requestcourses_validation_'.$item};
8188: if ($item eq 'markup') {
8189: if ($env{'form.requestcourses_validation_'.$item}) {
8190: $env{'form.requestcourses_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
8191: }
8192: }
1.266 raeburn 8193: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
8194: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
8195: if ($domconfig{'requestcourses'}{'validation'}{$item} ne $confhash{'validation'}{$item}) {
8196: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
8197: }
8198: } else {
8199: if ($confhash{'validation'}{$item} ne '') {
8200: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
8201: }
1.235 raeburn 8202: }
8203: } else {
8204: if ($confhash{'validation'}{$item} ne '') {
8205: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
8206: }
8207: }
8208: }
8209: }
8210: }
8211: if ($env{'form.validationdc'}) {
8212: my $newval = $env{'form.validationdc'};
8213: my %domcoords = &get_active_dcs($dom);
8214: if (exists($domcoords{$newval})) {
8215: $confhash{'validation'}{'dc'} = $newval;
8216: }
8217: }
8218: if (ref($confhash{'validation'}) eq 'HASH') {
1.266 raeburn 8219: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
8220: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
8221: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
8222: unless ($confhash{'validation'}{'dc'} eq $domconfig{'requestcourses'}{'validation'}{'dc'}) {
8223: if ($confhash{'validation'}{'dc'} eq '') {
8224: $changes{'validation'}{'dc'} = &mt('None');
8225: } else {
8226: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
8227: }
1.235 raeburn 8228: }
1.266 raeburn 8229: } elsif ($confhash{'validation'}{'dc'} ne '') {
8230: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
1.235 raeburn 8231: }
8232: } elsif ($confhash{'validation'}{'dc'} ne '') {
8233: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
8234: }
8235: } elsif ($confhash{'validation'}{'dc'} ne '') {
8236: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
1.266 raeburn 8237: }
8238: } else {
8239: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
8240: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
8241: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
8242: $changes{'validation'}{'dc'} = &mt('None');
8243: }
8244: }
1.235 raeburn 8245: }
8246: }
1.102 raeburn 8247: }
8248: } else {
1.86 raeburn 8249: $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
1.197 raeburn 8250: $confhash{'authorquota'}{'default'} = $env{'form.authorquota'};
1.86 raeburn 8251: }
1.72 raeburn 8252: foreach my $item (@usertools) {
8253: foreach my $type (@{$types},'default','_LC_adv') {
1.104 raeburn 8254: my $unset;
1.101 raeburn 8255: if ($context eq 'requestcourses') {
1.104 raeburn 8256: $unset = '0';
8257: if ($type eq '_LC_adv') {
8258: $unset = '';
8259: }
1.101 raeburn 8260: if ($confhash{$item}{$type} eq 'autolimit') {
8261: $confhash{$item}{$type} .= '=';
8262: unless ($limithash{$item}{$type} =~ /\D/) {
8263: $confhash{$item}{$type} .= $limithash{$item}{$type};
8264: }
8265: }
1.163 raeburn 8266: } elsif ($context eq 'requestauthor') {
8267: $unset = '0';
8268: if ($type eq '_LC_adv') {
8269: $unset = '';
8270: }
1.72 raeburn 8271: } else {
1.101 raeburn 8272: if (grep(/^\Q$type\E$/,@{$toolshash{$item}})) {
8273: $confhash{$item}{$type} = 1;
8274: } else {
8275: $confhash{$item}{$type} = 0;
8276: }
1.72 raeburn 8277: }
1.86 raeburn 8278: if (ref($domconfig{$action}) eq 'HASH') {
1.163 raeburn 8279: if ($action eq 'requestauthor') {
8280: if ($domconfig{$action}{$type} ne $confhash{$type}) {
8281: $changes{$type} = 1;
8282: }
8283: } elsif (ref($domconfig{$action}{$item}) eq 'HASH') {
1.86 raeburn 8284: if ($domconfig{$action}{$item}{$type} ne $confhash{$item}{$type}) {
8285: $changes{$item}{$type} = 1;
8286: }
8287: } else {
8288: if ($context eq 'requestcourses') {
1.104 raeburn 8289: if ($confhash{$item}{$type} ne $unset) {
1.86 raeburn 8290: $changes{$item}{$type} = 1;
8291: }
8292: } else {
8293: if (!$confhash{$item}{$type}) {
8294: $changes{$item}{$type} = 1;
8295: }
8296: }
8297: }
8298: } else {
8299: if ($context eq 'requestcourses') {
1.104 raeburn 8300: if ($confhash{$item}{$type} ne $unset) {
1.72 raeburn 8301: $changes{$item}{$type} = 1;
8302: }
1.163 raeburn 8303: } elsif ($context eq 'requestauthor') {
8304: if ($confhash{$type} ne $unset) {
8305: $changes{$type} = 1;
8306: }
1.72 raeburn 8307: } else {
8308: if (!$confhash{$item}{$type}) {
8309: $changes{$item}{$type} = 1;
8310: }
8311: }
8312: }
1.1 raeburn 8313: }
8314: }
1.163 raeburn 8315: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 8316: if (ref($domconfig{'quotas'}) eq 'HASH') {
8317: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
8318: foreach my $key (keys(%{$domconfig{'quotas'}{'defaultquota'}})) {
8319: if (exists($confhash{'defaultquota'}{$key})) {
8320: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{'defaultquota'}{$key}) {
8321: $changes{'defaultquota'}{$key} = 1;
8322: }
8323: } else {
8324: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{'defaultquota'}{$key};
1.72 raeburn 8325: }
8326: }
1.86 raeburn 8327: } else {
8328: foreach my $key (keys(%{$domconfig{'quotas'}})) {
8329: if (exists($confhash{'defaultquota'}{$key})) {
8330: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{$key}) {
8331: $changes{'defaultquota'}{$key} = 1;
8332: }
8333: } else {
8334: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{$key};
1.72 raeburn 8335: }
1.1 raeburn 8336: }
8337: }
1.197 raeburn 8338: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
8339: foreach my $key (keys(%{$domconfig{'quotas'}{'authorquota'}})) {
8340: if (exists($confhash{'authorquota'}{$key})) {
8341: if ($confhash{'authorquota'}{$key} ne $domconfig{'quotas'}{'authorquota'}{$key}) {
8342: $changes{'authorquota'}{$key} = 1;
8343: }
8344: } else {
8345: $confhash{'authorquota'}{$key} = $domconfig{'quotas'}{'authorquota'}{$key};
8346: }
8347: }
8348: }
1.1 raeburn 8349: }
1.86 raeburn 8350: if (ref($confhash{'defaultquota'}) eq 'HASH') {
8351: foreach my $key (keys(%{$confhash{'defaultquota'}})) {
8352: if (ref($domconfig{'quotas'}) eq 'HASH') {
8353: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
8354: if (!exists($domconfig{'quotas'}{'defaultquota'}{$key})) {
8355: $changes{'defaultquota'}{$key} = 1;
8356: }
8357: } else {
8358: if (!exists($domconfig{'quotas'}{$key})) {
8359: $changes{'defaultquota'}{$key} = 1;
8360: }
1.72 raeburn 8361: }
8362: } else {
1.86 raeburn 8363: $changes{'defaultquota'}{$key} = 1;
1.55 raeburn 8364: }
1.1 raeburn 8365: }
8366: }
1.197 raeburn 8367: if (ref($confhash{'authorquota'}) eq 'HASH') {
8368: foreach my $key (keys(%{$confhash{'authorquota'}})) {
8369: if (ref($domconfig{'quotas'}) eq 'HASH') {
8370: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
8371: if (!exists($domconfig{'quotas'}{'authorquota'}{$key})) {
8372: $changes{'authorquota'}{$key} = 1;
8373: }
8374: } else {
8375: $changes{'authorquota'}{$key} = 1;
8376: }
8377: } else {
8378: $changes{'authorquota'}{$key} = 1;
8379: }
8380: }
8381: }
1.1 raeburn 8382: }
1.72 raeburn 8383:
1.163 raeburn 8384: if ($context eq 'requestauthor') {
8385: $domdefaults{'requestauthor'} = \%confhash;
8386: } else {
8387: foreach my $key (keys(%confhash)) {
1.242 raeburn 8388: unless (($context eq 'requestcourses') && (($key eq 'textbooks') || ($key eq 'templates'))) {
1.216 raeburn 8389: $domdefaults{$key} = $confhash{$key};
8390: }
1.163 raeburn 8391: }
1.72 raeburn 8392: }
1.163 raeburn 8393:
1.1 raeburn 8394: my %quotahash = (
1.86 raeburn 8395: $action => { %confhash }
1.1 raeburn 8396: );
8397: my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
8398: $dom);
8399: if ($putresult eq 'ok') {
8400: if (keys(%changes) > 0) {
1.72 raeburn 8401: my $cachetime = 24*60*60;
8402: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 8403: if (ref($lastactref) eq 'HASH') {
8404: $lastactref->{'domdefaults'} = 1;
8405: }
1.1 raeburn 8406: $resulttext = &mt('Changes made:').'<ul>';
1.210 raeburn 8407: unless (($context eq 'requestcourses') ||
1.163 raeburn 8408: ($context eq 'requestauthor')) {
1.86 raeburn 8409: if (ref($changes{'defaultquota'}) eq 'HASH') {
8410: $resulttext .= '<li>'.&mt('Portfolio default quotas').'<ul>';
8411: foreach my $type (@{$types},'default') {
8412: if (defined($changes{'defaultquota'}{$type})) {
8413: my $typetitle = $usertypes->{$type};
8414: if ($type eq 'default') {
8415: $typetitle = $othertitle;
8416: }
1.213 raeburn 8417: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'defaultquota'}{$type}).'</li>';
1.72 raeburn 8418: }
8419: }
1.86 raeburn 8420: $resulttext .= '</ul></li>';
1.72 raeburn 8421: }
1.197 raeburn 8422: if (ref($changes{'authorquota'}) eq 'HASH') {
1.223 bisitz 8423: $resulttext .= '<li>'.&mt('Authoring Space default quotas').'<ul>';
1.197 raeburn 8424: foreach my $type (@{$types},'default') {
8425: if (defined($changes{'authorquota'}{$type})) {
8426: my $typetitle = $usertypes->{$type};
8427: if ($type eq 'default') {
8428: $typetitle = $othertitle;
8429: }
1.213 raeburn 8430: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'authorquota'}{$type}).'</li>';
1.197 raeburn 8431: }
8432: }
8433: $resulttext .= '</ul></li>';
8434: }
1.72 raeburn 8435: }
1.80 raeburn 8436: my %newenv;
1.72 raeburn 8437: foreach my $item (@usertools) {
1.163 raeburn 8438: my (%haschgs,%inconf);
8439: if ($context eq 'requestauthor') {
8440: %haschgs = %changes;
1.210 raeburn 8441: %inconf = %confhash;
1.163 raeburn 8442: } else {
8443: if (ref($changes{$item}) eq 'HASH') {
8444: %haschgs = %{$changes{$item}};
8445: }
8446: if (ref($confhash{$item}) eq 'HASH') {
8447: %inconf = %{$confhash{$item}};
8448: }
8449: }
8450: if (keys(%haschgs) > 0) {
1.80 raeburn 8451: my $newacc =
8452: &Apache::lonnet::usertools_access($env{'user.name'},
8453: $env{'user.domain'},
1.86 raeburn 8454: $item,'reload',$context);
1.210 raeburn 8455: if (($context eq 'requestcourses') ||
1.163 raeburn 8456: ($context eq 'requestauthor')) {
1.108 raeburn 8457: if ($env{'environment.canrequest.'.$item} ne $newacc) {
8458: $newenv{'environment.canrequest.'.$item} = $newacc;
1.86 raeburn 8459: }
8460: } else {
8461: if ($env{'environment.availabletools.'.$item} ne $newacc) {
8462: $newenv{'environment.availabletools.'.$item} = $newacc;
8463: }
1.80 raeburn 8464: }
1.163 raeburn 8465: unless ($context eq 'requestauthor') {
8466: $resulttext .= '<li>'.$titles{$item}.'<ul>';
8467: }
1.72 raeburn 8468: foreach my $type (@{$types},'default','_LC_adv') {
1.163 raeburn 8469: if ($haschgs{$type}) {
1.72 raeburn 8470: my $typetitle = $usertypes->{$type};
8471: if ($type eq 'default') {
8472: $typetitle = $othertitle;
8473: } elsif ($type eq '_LC_adv') {
8474: $typetitle = 'LON-CAPA Advanced Users';
8475: }
1.163 raeburn 8476: if ($inconf{$type}) {
1.101 raeburn 8477: if ($context eq 'requestcourses') {
8478: my $cond;
1.163 raeburn 8479: if ($inconf{$type} =~ /^autolimit=(\d*)$/) {
1.101 raeburn 8480: if ($1 eq '') {
8481: $cond = &mt('(Automatic processing of any request).');
8482: } else {
8483: $cond = &mt('(Automatic processing of requests up to limit of [quant,_1,request] per user).',$1);
8484: }
8485: } else {
1.163 raeburn 8486: $cond = $conditions{$inconf{$type}};
1.101 raeburn 8487: }
8488: $resulttext .= '<li>'.&mt('Set to be available to [_1].',$typetitle).' '.$cond.'</li>';
1.172 raeburn 8489: } elsif ($context eq 'requestauthor') {
8490: $resulttext .= '<li>'.&mt('Set to "[_1]" for "[_2]".',
8491: $titles{$inconf{$type}},$typetitle);
8492:
1.101 raeburn 8493: } else {
8494: $resulttext .= '<li>'.&mt('Set to be available to [_1]',$typetitle).'</li>';
8495: }
1.72 raeburn 8496: } else {
1.104 raeburn 8497: if ($type eq '_LC_adv') {
1.163 raeburn 8498: if ($inconf{$type} eq '0') {
1.104 raeburn 8499: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
8500: } else {
8501: $resulttext .= '<li>'.&mt('No override set for [_1]',$typetitle).'</li>';
8502: }
8503: } else {
8504: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
8505: }
1.72 raeburn 8506: }
8507: }
1.26 raeburn 8508: }
1.163 raeburn 8509: unless ($context eq 'requestauthor') {
8510: $resulttext .= '</ul></li>';
8511: }
1.26 raeburn 8512: }
1.1 raeburn 8513: }
1.163 raeburn 8514: if (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.102 raeburn 8515: if (ref($changes{'notify'}) eq 'HASH') {
8516: if ($changes{'notify'}{'approval'}) {
8517: if (ref($confhash{'notify'}) eq 'HASH') {
8518: if ($confhash{'notify'}{'approval'}) {
8519: $resulttext .= '<li>'.&mt('Notification of requests requiring approval will be sent to: ').$confhash{'notify'}{'approval'}.'</li>';
8520: } else {
1.163 raeburn 8521: $resulttext .= '<li>'.&mt('No Domain Coordinators will receive notification of requests requiring approval.').'</li>';
1.102 raeburn 8522: }
8523: }
8524: }
8525: }
8526: }
1.216 raeburn 8527: if ($action eq 'requestcourses') {
8528: my @offon = ('off','on');
8529: if ($changes{'uniquecode'}) {
1.218 raeburn 8530: if (ref($confhash{'uniquecode'}) eq 'HASH') {
8531: my $codestr = join(' ',map{ &mt($_); } sort(keys(%{$confhash{'uniquecode'}})));
8532: $resulttext .= '<li>'.
8533: &mt('Generation of six character code as course identifier for distribution to students set to on for: [_1].','<b>'.$codestr.'</b>').
8534: '</li>';
8535: } else {
8536: $resulttext .= '<li>'.&mt('Generation of six character code as course identifier for distribution to students set to off.').
8537: '</li>';
8538: }
1.216 raeburn 8539: }
1.242 raeburn 8540: foreach my $type ('textbooks','templates') {
8541: if (ref($changes{$type}) eq 'HASH') {
8542: $resulttext .= '<li>'.&mt("Available $type updated").'<ul>';
8543: foreach my $key (sort(keys(%{$changes{$type}}))) {
8544: my %coursehash = &Apache::lonnet::coursedescription($key);
8545: my $coursetitle = $coursehash{'description'};
8546: my $position = $confhash{$type}{$key}{'order'} + 1;
8547: $resulttext .= '<li>';
1.243 raeburn 8548: foreach my $item ('subject','title','publisher','author') {
8549: next if ((($item eq 'author') || ($item eq 'publisher')) &&
8550: ($type eq 'templates'));
1.242 raeburn 8551: my $name = $item.':';
8552: $name =~ s/^(\w)/\U$1/;
8553: $resulttext .= &mt($name).' '.$confhash{$type}{$key}{$item}.'<br />';
8554: }
8555: $resulttext .= ' '.&mt('Order: [_1]',$position).'<br />';
8556: if ($type eq 'textbooks') {
8557: if ($confhash{$type}{$key}{'image'}) {
8558: $resulttext .= ' '.&mt('Image: [_1]',
8559: '<img src="'.$confhash{$type}{$key}{'image'}.'"'.
8560: ' alt="Textbook cover" />').'<br />';
8561: }
8562: }
8563: $resulttext .= ' '.&mt('LON-CAPA Course: [_1]',$coursetitle).'</li>';
1.216 raeburn 8564: }
1.242 raeburn 8565: $resulttext .= '</ul></li>';
1.216 raeburn 8566: }
8567: }
1.235 raeburn 8568: if (ref($changes{'validation'}) eq 'HASH') {
8569: if ((ref($validationitemsref) eq 'ARRAY') && (ref($validationnamesref) eq 'HASH')) {
8570: $resulttext .= '<li>'.&mt('Validation of courses/communities updated').'<ul>';
8571: foreach my $item (@{$validationitemsref}) {
8572: if (exists($changes{'validation'}{$item})) {
8573: if ($item eq 'markup') {
8574: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
8575: '<br /><pre>'.$changes{'validation'}{$item}.'</pre>').'</li>';
8576: } else {
8577: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
8578: '<b>'.$changes{'validation'}{$item}.'</b>').'</li>';
8579: }
8580: }
8581: }
8582: if (exists($changes{'validation'}{'dc'})) {
8583: $resulttext .= '<li>'.&mt('Validated course requests identified as processed by: [_1]',
8584: '<b>'.$changes{'validation'}{'dc'}.'</b>').'</li>';
8585: }
8586: }
8587: }
1.216 raeburn 8588: }
1.1 raeburn 8589: $resulttext .= '</ul>';
1.80 raeburn 8590: if (keys(%newenv)) {
8591: &Apache::lonnet::appenv(\%newenv);
8592: }
1.1 raeburn 8593: } else {
1.86 raeburn 8594: if ($context eq 'requestcourses') {
8595: $resulttext = &mt('No changes made to rights to request creation of courses.');
1.163 raeburn 8596: } elsif ($context eq 'requestauthor') {
8597: $resulttext = &mt('No changes made to rights to request author space.');
1.86 raeburn 8598: } else {
1.90 weissno 8599: $resulttext = &mt('No changes made to availability of personal information pages, blogs, portfolios or default quotas');
1.86 raeburn 8600: }
1.1 raeburn 8601: }
8602: } else {
1.11 albertel 8603: $resulttext = '<span class="LC_error">'.
8604: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 8605: }
1.216 raeburn 8606: if ($errors) {
8607: $resulttext .= '<p>'.&mt('The following errors occurred when modifying Textbook settings.').
8608: '<ul>'.$errors.'</ul></p>';
8609: }
1.3 raeburn 8610: return $resulttext;
1.1 raeburn 8611: }
8612:
1.216 raeburn 8613: sub process_textbook_image {
1.242 raeburn 8614: my ($r,$dom,$confname,$caller,$cdom,$cnum,$type,$configuserok,$switchserver,$author_ok) = @_;
1.216 raeburn 8615: my $filename = $env{'form.'.$caller.'.filename'};
8616: my ($error,$url);
8617: my ($width,$height) = (50,50);
8618: if ($configuserok eq 'ok') {
8619: if ($switchserver) {
8620: $error = &mt('Upload of textbook image is not permitted to this server: [_1]',
8621: $switchserver);
8622: } elsif ($author_ok eq 'ok') {
8623: my ($result,$imageurl) =
8624: &publishlogo($r,'upload',$caller,$dom,$confname,
1.242 raeburn 8625: "$type/$dom/$cnum/cover",$width,$height);
1.216 raeburn 8626: if ($result eq 'ok') {
8627: $url = $imageurl;
8628: } else {
8629: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
8630: }
8631: } else {
8632: $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);
8633: }
8634: } else {
8635: $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);
8636: }
8637: return ($url,$error);
8638: }
8639:
1.267 raeburn 8640: sub modify_ltitools {
8641: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
8642: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
8643: my ($newid,@allpos,%changes,%confhash,$errors,$resulttext);
8644: my $confname = $dom.'-domainconfig';
8645: my $servadm = $r->dir_config('lonAdmEMail');
8646: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
8647: my (%posslti,%possfield);
8648: my @courseroles = ('cc','in','ta','ep','st');
8649: my @ltiroles = qw(Instructor ContentDeveloper TeachingAssistant Learner);
8650: map { $posslti{$_} = 1; } @ltiroles;
8651: my @allfields = ('fullname','firstname','lastname','email','user','roles');
8652: map { $possfield{$_} = 1; } @allfields;
8653: my %lt = <itools_names();
8654: if ($env{'form.ltitools_add'}) {
8655: my $title = $env{'form.ltitools_add_title'};
8656: $title =~ s/(`)/'/g;
8657: ($newid,my $error) = &get_ltitools_id($dom,$title);
8658: if ($newid) {
8659: my $position = $env{'form.ltitools_add_pos'};
8660: $position =~ s/\D+//g;
8661: if ($position ne '') {
8662: $allpos[$position] = $newid;
8663: }
8664: $changes{$newid} = 1;
8665: foreach my $item ('title','url','key','secret') {
8666: $env{'form.ltitools_add_'.$item} =~ s/(`)/'/g;
8667: if ($env{'form.ltitools_add_'.$item}) {
8668: $confhash{$newid}{$item} = $env{'form.ltitools_add_'.$item};
8669: }
8670: }
8671: if ($env{'form.ltitools_add_version'} eq 'LTI-1p0') {
8672: $confhash{$newid}{'version'} = $env{'form.ltitools_add_version'};
8673: }
8674: if ($env{'form.ltitools_add_msgtype'} eq 'basic-lti-launch-request') {
8675: $confhash{$newid}{'msgtype'} = $env{'form.ltitools_add_msgtype'};
8676: }
8677: foreach my $item ('width','height') {
8678: $env{'form.ltitools_add_'.$item} =~ s/^\s+//;
8679: $env{'form.ltitools_add_'.$item} =~ s/\s+$//;
8680: if ($env{'form.ltitools_add_'.$item} =~ /^\d+$/) {
8681: $confhash{$newid}{'display'}{$item} = $env{'form.ltitools_add_'.$item};
8682: }
8683: }
8684: if ($env{'form.ltitools_add_target'} eq 'window') {
8685: $confhash{$newid}{'display'}{'target'} = $env{'form.ltitools_add_target'};
8686: } else {
8687: $confhash{$newid}{'display'}{'target'} = 'iframe';
8688: }
8689: foreach my $item ('passback','roster') {
8690: if ($env{'form.ltitools_add_'.$item}) {
8691: $confhash{$newid}{$item} = 1;
8692: }
8693: }
8694: if ($env{'form.ltitools_add_image.filename'} ne '') {
8695: my ($imageurl,$error) =
8696: &process_ltitools_image($r,$dom,$confname,'ltitools_add_image',$dom,
8697: $configuserok,$switchserver,$author_ok);
8698: if ($imageurl) {
8699: $confhash{$newid}{'image'} = $imageurl;
8700: }
8701: if ($error) {
8702: &Apache::lonnet::logthis($error);
8703: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
8704: }
8705: }
8706: my @fields = &Apache::loncommon::get_env_multiple('form.ltitools_add_fields');
8707: foreach my $field (@fields) {
8708: if ($possfield{$field}) {
8709: if ($field eq 'roles') {
8710: foreach my $role (@courseroles) {
8711: my $choice = $env{'form.ltitools_add_roles_'.$role};
8712: if (($choice ne '') && ($posslti{$choice})) {
8713: $confhash{$newid}{'roles'}{$role} = $choice;
8714: if ($role eq 'cc') {
8715: $confhash{$newid}{'roles'}{'co'} = $choice;
8716: }
8717: }
8718: }
8719: } else {
8720: $confhash{$newid}{'fields'}{$field} = 1;
8721: }
8722: }
8723: }
1.273 raeburn 8724: my @courseconfig = &Apache::loncommon::get_env_multiple('form.ltitools_courseconfig');
8725: foreach my $item (@courseconfig) {
8726: $confhash{$newid}{'crsconf'}{$item} = 1;
8727: }
1.267 raeburn 8728: if ($env{'form.ltitools_add_custom'}) {
8729: my $name = $env{'form.ltitools_add_custom_name'};
8730: my $value = $env{'form.ltitools_add_custom_value'};
8731: $value =~ s/(`)/'/g;
8732: $name =~ s/(`)/'/g;
8733: $confhash{$newid}{'custom'}{$name} = $value;
8734: }
8735: } else {
8736: my $error = &mt('Failed to acquire unique ID for new external tool');
8737: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
8738: }
8739: }
8740: if (ref($domconfig{$action}) eq 'HASH') {
8741: my %deletions;
8742: my @todelete = &Apache::loncommon::get_env_multiple('form.ltitools_del');
8743: if (@todelete) {
8744: map { $deletions{$_} = 1; } @todelete;
8745: }
8746: my %customadds;
8747: my @newcustom = &Apache::loncommon::get_env_multiple('form.ltitools_customadd');
8748: if (@newcustom) {
8749: map { $customadds{$_} = 1; } @newcustom;
8750: }
8751: my %imgdeletions;
8752: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.ltitools_image_del');
8753: if (@todeleteimages) {
8754: map { $imgdeletions{$_} = 1; } @todeleteimages;
8755: }
8756: my $maxnum = $env{'form.ltitools_maxnum'};
8757: for (my $i=0; $i<=$maxnum; $i++) {
8758: my $itemid = $env{'form.ltitools_id_'.$i};
8759: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
8760: if ($deletions{$itemid}) {
8761: if ($domconfig{$action}{$itemid}{'image'}) {
8762: #FIXME need to obsolete item in RES space
8763: }
8764: $changes{$itemid} = $domconfig{$action}{$itemid}{'title'};
8765: next;
8766: } else {
8767: my $newpos = $env{'form.ltitools_'.$itemid};
8768: $newpos =~ s/\D+//g;
8769: foreach my $item ('title','url','key','secret') {
8770: $confhash{$itemid}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
8771: if ($domconfig{$action}{$itemid}{$item} ne $confhash{$itemid}{$item}) {
8772: $changes{$itemid} = 1;
8773: }
8774: }
8775: if ($env{'form.ltitools_version_'.$i} eq 'LTI-1p0') {
8776: $confhash{$itemid}{'version'} = $env{'form.ltitools_version_'.$i};
8777: }
8778: if ($env{'form.ltitools_msgtype_'.$i} eq 'basic-lti-launch-request') {
8779: $confhash{$itemid}{'msgtype'} = $env{'form.ltitools_msgtype_'.$i};
8780: }
8781: foreach my $size ('width','height') {
8782: $env{'form.ltitools_'.$size.'_'.$i} =~ s/^\s+//;
8783: $env{'form.ltitools_'.$size.'_'.$i} =~ s/\s+$//;
8784: if ($env{'form.ltitools_'.$size.'_'.$i} =~ /^\d+$/) {
8785: $confhash{$itemid}{'display'}{$size} = $env{'form.ltitools_'.$size.'_'.$i};
8786: if (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
8787: if ($domconfig{$action}{$itemid}{'display'}{$size} ne $confhash{$itemid}{'display'}{$size}) {
8788: $changes{$itemid} = 1;
8789: }
8790: } else {
8791: $changes{$itemid} = 1;
8792: }
8793: }
8794: }
8795: if ($env{'form.ltitools_target_'.$i} eq 'window') {
8796: $confhash{$itemid}{'display'}{'target'} = $env{'form.ltitools_target_'.$i};
8797: } else {
8798: $confhash{$itemid}{'display'}{'target'} = 'iframe';
8799: }
8800: if (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
8801: if ($domconfig{$action}{$itemid}{'display'}{'target'} ne $confhash{$itemid}{'display'}{'target'}) {
8802: $changes{$itemid} = 1;
8803: }
8804: } else {
8805: $changes{$itemid} = 1;
8806: }
8807: foreach my $extra ('passback','roster') {
8808: if ($env{'form.ltitools_'.$extra.'_'.$i}) {
8809: $confhash{$itemid}{$extra} = 1;
8810: }
8811: if ($domconfig{$action}{$itemid}{$extra} ne $confhash{$itemid}{$extra}) {
8812: $changes{$itemid} = 1;
8813: }
8814: }
1.273 raeburn 8815: my @courseconfig = &Apache::loncommon::get_env_multiple('form.ltitools_courseconfig_'.$i);
8816: foreach my $item ('label','title','target') {
8817: if (grep(/^\Q$item\E$/,@courseconfig)) {
8818: $confhash{$itemid}{'crsconf'}{$item} = 1;
8819: if (ref($domconfig{$action}{$itemid}{'crsconf'}) eq 'HASH') {
8820: if ($domconfig{$action}{$itemid}{'crsconf'}{$item} ne $confhash{$itemid}{'crsconf'}{$item}) {
8821: $changes{$itemid} = 1;
8822: }
8823: } else {
8824: $changes{$itemid} = 1;
8825: }
8826: }
8827: }
1.267 raeburn 8828: my @fields = &Apache::loncommon::get_env_multiple('form.ltitools_fields_'.$i);
8829: foreach my $field (@fields) {
8830: if ($possfield{$field}) {
8831: if ($field eq 'roles') {
8832: foreach my $role (@courseroles) {
8833: my $choice = $env{'form.ltitools_roles_'.$role.'_'.$i};
8834: if (($choice ne '') && ($posslti{$choice})) {
8835: $confhash{$itemid}{'roles'}{$role} = $choice;
8836: if ($role eq 'cc') {
8837: $confhash{$itemid}{'roles'}{'co'} = $choice;
8838: }
8839: }
8840: if (ref($domconfig{$action}{$itemid}{'roles'}) eq 'HASH') {
8841: if ($domconfig{$action}{$itemid}{'roles'}{$role} ne $confhash{$itemid}{'roles'}{$role}) {
8842: $changes{$itemid} = 1;
8843: }
8844: } elsif ($confhash{$itemid}{'roles'}{$role}) {
8845: $changes{$itemid} = 1;
8846: }
8847: }
8848: } else {
8849: $confhash{$itemid}{'fields'}{$field} = 1;
8850: if (ref($domconfig{$action}{$itemid}{'fields'}) eq 'HASH') {
8851: if ($domconfig{$action}{$itemid}{'fields'}{$field} ne $confhash{$itemid}{'fields'}{$field}) {
8852: $changes{$itemid} = 1;
8853: }
8854: } else {
8855: $changes{$itemid} = 1;
8856: }
8857: }
8858: }
8859: }
8860: $allpos[$newpos] = $itemid;
8861: }
8862: if ($imgdeletions{$itemid}) {
8863: $changes{$itemid} = 1;
8864: #FIXME need to obsolete item in RES space
8865: } elsif ($env{'form.ltitools_image_'.$i.'.filename'}) {
8866: my ($imgurl,$error) = &process_ltitools_image($r,$dom,$confname,'ltitools_image_'.$i,
8867: $itemid,$configuserok,$switchserver,
8868: $author_ok);
8869: if ($imgurl) {
8870: $confhash{$itemid}{'image'} = $imgurl;
8871: $changes{$itemid} = 1;
8872: }
8873: if ($error) {
8874: &Apache::lonnet::logthis($error);
8875: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
8876: }
8877: } elsif ($domconfig{$action}{$itemid}{'image'}) {
8878: $confhash{$itemid}{'image'} =
8879: $domconfig{$action}{$itemid}{'image'};
8880: }
8881: if ($customadds{$i}) {
8882: my $name = $env{'form.ltitools_custom_name_'.$i};
8883: $name =~ s/(`)/'/g;
8884: $name =~ s/^\s+//;
8885: $name =~ s/\s+$//;
8886: my $value = $env{'form.ltitools_custom_value_'.$i};
8887: $value =~ s/(`)/'/g;
8888: $value =~ s/^\s+//;
8889: $value =~ s/\s+$//;
8890: if ($name ne '') {
8891: $confhash{$itemid}{'custom'}{$name} = $value;
8892: $changes{$itemid} = 1;
8893: }
8894: }
8895: my %customdels;
8896: my @customdeletions = &Apache::loncommon::get_env_multiple('form.ltitools_customdel_'.$i);
8897: if (@customdeletions) {
8898: $changes{$itemid} = 1;
8899: }
8900: map { $customdels{$_} = 1; } @customdeletions;
8901: if (ref($domconfig{$action}{$itemid}{'custom'}) eq 'HASH') {
8902: foreach my $key (keys(%{$domconfig{$action}{$itemid}{'custom'}})) {
8903: unless ($customdels{$key}) {
8904: if ($env{'form.ltitools_customval_'.$key.'_'.$i} ne '') {
8905: $confhash{$itemid}{'custom'}{$key} = $env{'form.ltitools_customval_'.$key.'_'.$i};
8906: }
8907: if ($domconfig{$action}{$itemid}{'custom'}{$key} ne $env{'form.ltitools_customval_'.$key.'_'.$i}) {
8908: $changes{$itemid} = 1;
8909: }
8910: }
8911: }
8912: }
8913: unless ($changes{$itemid}) {
8914: foreach my $key (keys(%{$domconfig{$action}{$itemid}})) {
8915: if (ref($domconfig{$action}{$itemid}{$key}) eq 'HASH') {
8916: if (ref($confhash{$itemid}{$key}) eq 'HASH') {
8917: foreach my $innerkey (keys(%{$domconfig{$action}{$itemid}{$key}})) {
8918: unless (exists($confhash{$itemid}{$key}{$innerkey})) {
8919: $changes{$itemid} = 1;
8920: last;
8921: }
8922: }
8923: } elsif (keys(%{$domconfig{$action}{$itemid}{$key}}) > 0) {
8924: $changes{$itemid} = 1;
8925: }
8926: }
8927: last if ($changes{$itemid});
8928: }
8929: }
8930: }
8931: }
8932: }
8933: if (@allpos > 0) {
8934: my $idx = 0;
8935: foreach my $itemid (@allpos) {
8936: if ($itemid ne '') {
8937: $confhash{$itemid}{'order'} = $idx;
8938: if (ref($domconfig{$action}) eq 'HASH') {
8939: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
8940: if ($domconfig{$action}{$itemid}{'order'} ne $idx) {
8941: $changes{$itemid} = 1;
8942: }
8943: }
8944: }
8945: $idx ++;
8946: }
8947: }
8948: }
8949: my %ltitoolshash = (
8950: $action => { %confhash }
8951: );
8952: my $putresult = &Apache::lonnet::put_dom('configuration',\%ltitoolshash,
8953: $dom);
8954: if ($putresult eq 'ok') {
8955: if (keys(%changes) > 0) {
8956: my $cachetime = 24*60*60;
8957: &Apache::lonnet::do_cache_new('ltitools',$dom,\%confhash,$cachetime);
8958: if (ref($lastactref) eq 'HASH') {
8959: $lastactref->{'ltitools'} = 1;
8960: }
8961: $resulttext = &mt('Changes made:').'<ul>';
8962: my %bynum;
8963: foreach my $itemid (sort(keys(%changes))) {
8964: my $position = $confhash{$itemid}{'order'};
8965: $bynum{$position} = $itemid;
8966: }
8967: foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
8968: my $itemid = $bynum{$pos};
8969: if (ref($confhash{$itemid}) ne 'HASH') {
8970: $resulttext .= '<li>'.&mt('Deleted: [_1]',$changes{$itemid}).'</li>';
8971: } else {
8972: $resulttext .= '<li><b>'.$confhash{$itemid}{'title'}.'</b>';
8973: if ($confhash{$itemid}{'image'}) {
8974: $resulttext .= ' '.
8975: '<img src="'.$confhash{$itemid}{'image'}.'"'.
8976: ' alt="'.&mt('Tool Provider icon').'" />';
8977: }
8978: $resulttext .= '</li><ul>';
8979: my $position = $pos + 1;
8980: $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
8981: foreach my $item ('version','msgtype','url','key') {
8982: if ($confhash{$itemid}{$item} ne '') {
8983: $resulttext .= '<li>'.$lt{$item}.': '.$confhash{$itemid}{$item}.'</li>';
8984: }
8985: }
8986: if ($confhash{$itemid}{'secret'} ne '') {
8987: $resulttext .= '<li>'.$lt{'secret'}.': ';
8988: my $num = length($confhash{$itemid}{'secret'});
8989: $resulttext .= ('*'x$num).'</li>';
8990: }
1.273 raeburn 8991: $resulttext .= '<li>'.&mt('Configurable in course:');
8992: my @possconfig = ('label','title','target');
8993: my $numconfig = 0;
8994: if (ref($confhash{$itemid}{'crsconf'}) eq 'HASH') {
8995: foreach my $item (@possconfig) {
8996: if ($confhash{$itemid}{'crsconf'}{$item}) {
8997: $numconfig ++;
8998: $resulttext .= ' '.$lt{'crs'.$item};
8999: }
9000: }
9001: }
9002: if (!$numconfig) {
9003: $resulttext .= &mt('None');
9004: }
9005: $resulttext .= '</li>';
1.267 raeburn 9006: foreach my $item ('passback','roster') {
9007: $resulttext .= '<li>'.$lt{$item}.' ';
9008: if ($confhash{$itemid}{$item}) {
9009: $resulttext .= &mt('Yes');
9010: } else {
9011: $resulttext .= &mt('No');
9012: }
9013: $resulttext .= '</li>';
9014: }
9015: if (ref($confhash{$itemid}{'display'}) eq 'HASH') {
9016: my $displaylist;
9017: if ($confhash{$itemid}{'display'}{'target'}) {
9018: $displaylist = &mt('Display target').': '.
9019: $confhash{$itemid}{'display'}{'target'}.',';
9020: }
9021: foreach my $size ('width','height') {
9022: if ($confhash{$itemid}{'display'}{$size}) {
9023: $displaylist .= (' 'x2).$lt{$size}.': '.
9024: $confhash{$itemid}{'display'}{$size}.',';
9025: }
9026: }
9027: if ($displaylist) {
9028: $displaylist =~ s/,$//;
9029: $resulttext .= '<li>'.$displaylist.'</li>';
9030: }
9031: }
9032: if (ref($confhash{$itemid}{'fields'}) eq 'HASH') {
9033: my $fieldlist;
9034: foreach my $field (@allfields) {
9035: if ($confhash{$itemid}{'fields'}{$field}) {
9036: $fieldlist .= (' 'x2).$lt{$field}.',';
9037: }
9038: }
9039: if ($fieldlist) {
9040: $fieldlist =~ s/,$//;
9041: $resulttext .= '<li>'.&mt('Data sent').':'.$fieldlist.'</li>';
9042: }
9043: }
9044: if (ref($confhash{$itemid}{'roles'}) eq 'HASH') {
9045: my $rolemaps;
9046: foreach my $role (@courseroles) {
9047: if ($confhash{$itemid}{'roles'}{$role}) {
9048: $rolemaps .= (' 'x2).&Apache::lonnet::plaintext($role,'Course').'='.
9049: $confhash{$itemid}{'roles'}{$role}.',';
9050: }
9051: }
9052: if ($rolemaps) {
9053: $rolemaps =~ s/,$//;
9054: $resulttext .= '<li>'.&mt('Role mapping:').$rolemaps.'</li>';
9055: }
9056: }
9057: if (ref($confhash{$itemid}{'custom'}) eq 'HASH') {
9058: my $customlist;
9059: if (keys(%{$confhash{$itemid}{'custom'}})) {
9060: foreach my $key (sort(keys(%{$confhash{$itemid}{'custom'}}))) {
9061: $customlist .= $key.':'.$confhash{$itemid}{'custom'}{$key}.(' 'x2);
9062: }
9063: }
9064: if ($customlist) {
9065: $resulttext .= '<li>'.&mt('Custom items').':'.$customlist.'</li>';
9066: }
9067: }
9068: $resulttext .= '</ul></li>';
9069: }
9070: }
9071: $resulttext .= '</ul>';
9072: } else {
9073: $resulttext = &mt('No changes made.');
9074: }
9075: } else {
9076: $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
9077: }
9078: if ($errors) {
9079: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
9080: $errors.'</ul>';
9081: }
9082: return $resulttext;
9083: }
9084:
9085: sub process_ltitools_image {
9086: my ($r,$dom,$confname,$caller,$itemid,$configuserok,$switchserver,$author_ok) = @_;
9087: my $filename = $env{'form.'.$caller.'.filename'};
9088: my ($error,$url);
9089: my ($width,$height) = (21,21);
9090: if ($configuserok eq 'ok') {
9091: if ($switchserver) {
9092: $error = &mt('Upload of Tool Provider (LTI) icon is not permitted to this server: [_1]',
9093: $switchserver);
9094: } elsif ($author_ok eq 'ok') {
9095: my ($result,$imageurl,$madethumb) =
9096: &publishlogo($r,'upload',$caller,$dom,$confname,
9097: "ltitools/$itemid/icon",$width,$height);
9098: if ($result eq 'ok') {
9099: if ($madethumb) {
9100: my ($path,$imagefile) = ($imageurl =~ m{^(.+)/([^/]+)$});
9101: my $imagethumb = "$path/tn-".$imagefile;
9102: $url = $imagethumb;
9103: } else {
9104: $url = $imageurl;
9105: }
9106: } else {
9107: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
9108: }
9109: } else {
9110: $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);
9111: }
9112: } else {
9113: $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);
9114: }
9115: return ($url,$error);
9116: }
9117:
9118: sub get_ltitools_id {
9119: my ($cdom,$title) = @_;
9120: # get lock on ltitools db
9121: my $lockhash = {
9122: lock => $env{'user.name'}.
9123: ':'.$env{'user.domain'},
9124: };
9125: my $tries = 0;
9126: my $gotlock = &Apache::lonnet::newput_dom('ltitools',$lockhash,$cdom);
9127: my ($id,$error);
9128:
9129: while (($gotlock ne 'ok') && ($tries<10)) {
9130: $tries ++;
9131: sleep (0.1);
9132: $gotlock = &Apache::lonnet::newput_dom('ltitools',$lockhash,$cdom);
9133: }
9134: if ($gotlock eq 'ok') {
9135: my %currids = &Apache::lonnet::dump_dom('ltitools',$cdom);
9136: if ($currids{'lock'}) {
9137: delete($currids{'lock'});
9138: if (keys(%currids)) {
9139: my @curr = sort { $a <=> $b } keys(%currids);
9140: if ($curr[-1] =~ /^\d+$/) {
9141: $id = 1 + $curr[-1];
9142: }
9143: } else {
9144: $id = 1;
9145: }
9146: if ($id) {
9147: unless (&Apache::lonnet::newput_dom('ltitools',{ $id => $title },$cdom) eq 'ok') {
9148: $error = 'nostore';
9149: }
9150: } else {
9151: $error = 'nonumber';
9152: }
9153: }
9154: my $dellockoutcome = &Apache::lonnet::del_dom('ltitools',['lock'],$cdom);
9155: } else {
9156: $error = 'nolock';
9157: }
9158: return ($id,$error);
9159: }
9160:
1.3 raeburn 9161: sub modify_autoenroll {
1.205 raeburn 9162: my ($dom,$lastactref,%domconfig) = @_;
1.1 raeburn 9163: my ($resulttext,%changes);
9164: my %currautoenroll;
9165: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
9166: foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
9167: $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
9168: }
9169: }
9170: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
9171: my %title = ( run => 'Auto-enrollment active',
1.129 raeburn 9172: sender => 'Sender for notification messages',
1.274 raeburn 9173: coowners => 'Automatic assignment of co-ownership to instructors of record (institutional data)',
9174: failsafe => 'Failsafe for no drops if institutional data missing for a section');
1.1 raeburn 9175: my @offon = ('off','on');
1.17 raeburn 9176: my $sender_uname = $env{'form.sender_uname'};
9177: my $sender_domain = $env{'form.sender_domain'};
9178: if ($sender_domain eq '') {
9179: $sender_uname = '';
9180: } elsif ($sender_uname eq '') {
9181: $sender_domain = '';
9182: }
1.129 raeburn 9183: my $coowners = $env{'form.autoassign_coowners'};
1.274 raeburn 9184: my $failsafe = $env{'form.autoenroll_failsafe'};
9185: $failsafe =~ s{^\s+|\s+$}{}g;
9186: if ($failsafe =~ /\D/) {
9187: undef($failsafe);
9188: }
1.1 raeburn 9189: my %autoenrollhash = (
1.129 raeburn 9190: autoenroll => { 'run' => $env{'form.autoenroll_run'},
9191: 'sender_uname' => $sender_uname,
9192: 'sender_domain' => $sender_domain,
9193: 'co-owners' => $coowners,
1.274 raeburn 9194: 'autofailsafe' => $failsafe,
1.1 raeburn 9195: }
9196: );
1.4 raeburn 9197: my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
9198: $dom);
1.1 raeburn 9199: if ($putresult eq 'ok') {
9200: if (exists($currautoenroll{'run'})) {
9201: if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
9202: $changes{'run'} = 1;
9203: }
9204: } elsif ($autorun) {
9205: if ($env{'form.autoenroll_run'} ne '1') {
1.23 raeburn 9206: $changes{'run'} = 1;
1.1 raeburn 9207: }
9208: }
1.17 raeburn 9209: if ($currautoenroll{'sender_uname'} ne $sender_uname) {
1.1 raeburn 9210: $changes{'sender'} = 1;
9211: }
1.17 raeburn 9212: if ($currautoenroll{'sender_domain'} ne $sender_domain) {
1.1 raeburn 9213: $changes{'sender'} = 1;
9214: }
1.129 raeburn 9215: if ($currautoenroll{'co-owners'} ne '') {
9216: if ($currautoenroll{'co-owners'} ne $coowners) {
9217: $changes{'coowners'} = 1;
9218: }
9219: } elsif ($coowners) {
9220: $changes{'coowners'} = 1;
1.274 raeburn 9221: }
9222: if ($currautoenroll{'autofailsafe'} ne $failsafe) {
9223: $changes{'autofailsafe'} = 1;
9224: }
1.1 raeburn 9225: if (keys(%changes) > 0) {
9226: $resulttext = &mt('Changes made:').'<ul>';
1.3 raeburn 9227: if ($changes{'run'}) {
1.1 raeburn 9228: $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
9229: }
9230: if ($changes{'sender'}) {
1.17 raeburn 9231: if ($sender_uname eq '' || $sender_domain eq '') {
9232: $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
9233: } else {
9234: $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
9235: }
1.1 raeburn 9236: }
1.129 raeburn 9237: if ($changes{'coowners'}) {
9238: $resulttext .= '<li>'.&mt("$title{'coowners'} set to $offon[$env{'form.autoassign_coowners'}]").'</li>';
9239: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 9240: if (ref($lastactref) eq 'HASH') {
9241: $lastactref->{'domainconfig'} = 1;
9242: }
1.129 raeburn 9243: }
1.274 raeburn 9244: if ($changes{'autofailsafe'}) {
9245: if ($failsafe ne '') {
9246: $resulttext .= '<li>'.&mt("$title{'failsafe'} set to [_1]",$failsafe).'</li>';
9247: } else {
9248: $resulttext .= '<li>'.&mt("$title{'failsafe'} deleted");
9249: }
9250: &Apache::lonnet::get_domain_defaults($dom,1);
9251: if (ref($lastactref) eq 'HASH') {
9252: $lastactref->{'domdefaults'} = 1;
9253: }
9254: }
1.1 raeburn 9255: $resulttext .= '</ul>';
9256: } else {
9257: $resulttext = &mt('No changes made to auto-enrollment settings');
9258: }
9259: } else {
1.11 albertel 9260: $resulttext = '<span class="LC_error">'.
9261: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 9262: }
1.3 raeburn 9263: return $resulttext;
1.1 raeburn 9264: }
9265:
9266: sub modify_autoupdate {
1.3 raeburn 9267: my ($dom,%domconfig) = @_;
1.1 raeburn 9268: my ($resulttext,%currautoupdate,%fields,%changes);
9269: if (ref($domconfig{'autoupdate'}) eq 'HASH') {
9270: foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
9271: $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
9272: }
9273: }
9274: my @offon = ('off','on');
9275: my %title = &Apache::lonlocal::texthash (
9276: run => 'Auto-update:',
9277: classlists => 'Updates to user information in classlists?'
9278: );
1.44 raeburn 9279: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 9280: my %fieldtitles = &Apache::lonlocal::texthash (
9281: id => 'Student/Employee ID',
1.20 raeburn 9282: permanentemail => 'E-mail address',
1.1 raeburn 9283: lastname => 'Last Name',
9284: firstname => 'First Name',
9285: middlename => 'Middle Name',
1.132 raeburn 9286: generation => 'Generation',
1.1 raeburn 9287: );
1.142 raeburn 9288: $othertitle = &mt('All users');
1.1 raeburn 9289: if (keys(%{$usertypes}) > 0) {
1.26 raeburn 9290: $othertitle = &mt('Other users');
1.1 raeburn 9291: }
9292: foreach my $key (keys(%env)) {
9293: if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
1.132 raeburn 9294: my ($usertype,$item) = ($1,$2);
9295: if (grep(/^\Q$item\E$/,keys(%fieldtitles))) {
9296: if ($usertype eq 'default') {
9297: push(@{$fields{$1}},$2);
9298: } elsif (ref($types) eq 'ARRAY') {
9299: if (grep(/^\Q$usertype\E$/,@{$types})) {
9300: push(@{$fields{$1}},$2);
9301: }
9302: }
9303: }
1.1 raeburn 9304: }
9305: }
1.131 raeburn 9306: my @lockablenames = &Apache::loncommon::get_env_multiple('form.lockablenames');
9307: @lockablenames = sort(@lockablenames);
9308: if (ref($currautoupdate{'lockablenames'}) eq 'ARRAY') {
9309: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
9310: if (@changed) {
9311: $changes{'lockablenames'} = 1;
9312: }
9313: } else {
9314: if (@lockablenames) {
9315: $changes{'lockablenames'} = 1;
9316: }
9317: }
1.1 raeburn 9318: my %updatehash = (
9319: autoupdate => { run => $env{'form.autoupdate_run'},
9320: classlists => $env{'form.classlists'},
9321: fields => {%fields},
1.131 raeburn 9322: lockablenames => \@lockablenames,
1.1 raeburn 9323: }
9324: );
9325: foreach my $key (keys(%currautoupdate)) {
9326: if (($key eq 'run') || ($key eq 'classlists')) {
9327: if (exists($updatehash{autoupdate}{$key})) {
9328: if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
9329: $changes{$key} = 1;
9330: }
9331: }
9332: } elsif ($key eq 'fields') {
9333: if (ref($currautoupdate{$key}) eq 'HASH') {
1.26 raeburn 9334: foreach my $item (@{$types},'default') {
1.1 raeburn 9335: if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
9336: my $change = 0;
9337: foreach my $type (@{$currautoupdate{$key}{$item}}) {
9338: if (!exists($fields{$item})) {
9339: $change = 1;
1.132 raeburn 9340: last;
1.1 raeburn 9341: } elsif (ref($fields{$item}) eq 'ARRAY') {
1.26 raeburn 9342: if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
1.1 raeburn 9343: $change = 1;
1.132 raeburn 9344: last;
1.1 raeburn 9345: }
9346: }
9347: }
9348: if ($change) {
9349: push(@{$changes{$key}},$item);
9350: }
1.26 raeburn 9351: }
1.1 raeburn 9352: }
9353: }
1.131 raeburn 9354: } elsif ($key eq 'lockablenames') {
9355: if (ref($currautoupdate{$key}) eq 'ARRAY') {
9356: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
9357: if (@changed) {
9358: $changes{'lockablenames'} = 1;
9359: }
9360: } else {
9361: if (@lockablenames) {
9362: $changes{'lockablenames'} = 1;
9363: }
9364: }
9365: }
9366: }
9367: unless (grep(/^\Qlockablenames\E$/,keys(%currautoupdate))) {
9368: if (@lockablenames) {
9369: $changes{'lockablenames'} = 1;
1.1 raeburn 9370: }
9371: }
1.26 raeburn 9372: foreach my $item (@{$types},'default') {
9373: if (defined($fields{$item})) {
9374: if (ref($currautoupdate{'fields'}) eq 'HASH') {
1.132 raeburn 9375: if (ref($currautoupdate{'fields'}{$item}) eq 'ARRAY') {
9376: my $change = 0;
9377: if (ref($fields{$item}) eq 'ARRAY') {
9378: foreach my $type (@{$fields{$item}}) {
9379: if (!grep(/^\Q$type\E$/,@{$currautoupdate{'fields'}{$item}})) {
9380: $change = 1;
9381: last;
9382: }
9383: }
9384: }
9385: if ($change) {
9386: push(@{$changes{'fields'}},$item);
9387: }
9388: } else {
1.26 raeburn 9389: push(@{$changes{'fields'}},$item);
9390: }
9391: } else {
9392: push(@{$changes{'fields'}},$item);
1.1 raeburn 9393: }
9394: }
9395: }
9396: my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
9397: $dom);
9398: if ($putresult eq 'ok') {
9399: if (keys(%changes) > 0) {
9400: $resulttext = &mt('Changes made:').'<ul>';
9401: foreach my $key (sort(keys(%changes))) {
1.131 raeburn 9402: if ($key eq 'lockablenames') {
9403: $resulttext .= '<li>';
9404: if (@lockablenames) {
9405: $usertypes->{'default'} = $othertitle;
9406: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update), available for the following affiliations:").' '.
9407: join(', ', map { $usertypes->{$_}; } @lockablenames).'</li>';
9408: } else {
9409: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update) is unavailable.");
9410: }
9411: $resulttext .= '</li>';
9412: } elsif (ref($changes{$key}) eq 'ARRAY') {
1.1 raeburn 9413: foreach my $item (@{$changes{$key}}) {
9414: my @newvalues;
9415: foreach my $type (@{$fields{$item}}) {
9416: push(@newvalues,$fieldtitles{$type});
9417: }
1.3 raeburn 9418: my $newvaluestr;
9419: if (@newvalues > 0) {
9420: $newvaluestr = join(', ',@newvalues);
9421: } else {
9422: $newvaluestr = &mt('none');
1.6 raeburn 9423: }
1.1 raeburn 9424: if ($item eq 'default') {
1.26 raeburn 9425: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
1.1 raeburn 9426: } else {
1.26 raeburn 9427: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
1.1 raeburn 9428: }
9429: }
9430: } else {
9431: my $newvalue;
9432: if ($key eq 'run') {
9433: $newvalue = $offon[$env{'form.autoupdate_run'}];
9434: } else {
9435: $newvalue = $offon[$env{'form.'.$key}];
1.3 raeburn 9436: }
1.1 raeburn 9437: $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
9438: }
9439: }
9440: $resulttext .= '</ul>';
9441: } else {
1.3 raeburn 9442: $resulttext = &mt('No changes made to autoupdates');
1.1 raeburn 9443: }
9444: } else {
1.11 albertel 9445: $resulttext = '<span class="LC_error">'.
9446: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 9447: }
1.3 raeburn 9448: return $resulttext;
1.1 raeburn 9449: }
9450:
1.125 raeburn 9451: sub modify_autocreate {
9452: my ($dom,%domconfig) = @_;
9453: my ($resulttext,%changes,%currautocreate,%newvals,%autocreatehash);
9454: if (ref($domconfig{'autocreate'}) eq 'HASH') {
9455: foreach my $key (keys(%{$domconfig{'autocreate'}})) {
9456: $currautocreate{$key} = $domconfig{'autocreate'}{$key};
9457: }
9458: }
9459: my %title= ( xml => 'Auto-creation of courses in XML course description files',
9460: req => 'Auto-creation of validated requests for official courses',
9461: xmldc => 'Identity of course creator of courses from XML files',
9462: );
9463: my @types = ('xml','req');
9464: foreach my $item (@types) {
9465: $newvals{$item} = $env{'form.autocreate_'.$item};
9466: $newvals{$item} =~ s/\D//g;
9467: $newvals{$item} = 0 if ($newvals{$item} eq '');
9468: }
9469: $newvals{'xmldc'} = $env{'form.autocreate_xmldc'};
9470: my %domcoords = &get_active_dcs($dom);
9471: unless (exists($domcoords{$newvals{'xmldc'}})) {
9472: $newvals{'xmldc'} = '';
9473: }
9474: %autocreatehash = (
9475: autocreate => { xml => $newvals{'xml'},
9476: req => $newvals{'req'},
9477: }
9478: );
9479: if ($newvals{'xmldc'} ne '') {
9480: $autocreatehash{'autocreate'}{'xmldc'} = $newvals{'xmldc'};
9481: }
9482: my $putresult = &Apache::lonnet::put_dom('configuration',\%autocreatehash,
9483: $dom);
9484: if ($putresult eq 'ok') {
9485: my @items = @types;
9486: if ($newvals{'xml'}) {
9487: push(@items,'xmldc');
9488: }
9489: foreach my $item (@items) {
9490: if (exists($currautocreate{$item})) {
9491: if ($currautocreate{$item} ne $newvals{$item}) {
9492: $changes{$item} = 1;
9493: }
9494: } elsif ($newvals{$item}) {
9495: $changes{$item} = 1;
9496: }
9497: }
9498: if (keys(%changes) > 0) {
9499: my @offon = ('off','on');
9500: $resulttext = &mt('Changes made:').'<ul>';
9501: foreach my $item (@types) {
9502: if ($changes{$item}) {
9503: my $newtxt = $offon[$newvals{$item}];
1.178 raeburn 9504: $resulttext .= '<li>'.
9505: &mt("$title{$item} set to [_1]$newtxt [_2]",
9506: '<b>','</b>').
9507: '</li>';
1.125 raeburn 9508: }
9509: }
9510: if ($changes{'xmldc'}) {
9511: my ($dcname,$dcdom) = split(':',$newvals{'xmldc'});
9512: my $newtxt = &Apache::loncommon::plainname($dcname,$dcdom);
1.178 raeburn 9513: $resulttext .= '<li>'.&mt("$title{'xmldc'} set to [_1]",'<b>'.$newtxt.'</b>').'</li>';
1.125 raeburn 9514: }
9515: $resulttext .= '</ul>';
9516: } else {
9517: $resulttext = &mt('No changes made to auto-creation settings');
9518: }
9519: } else {
9520: $resulttext = '<span class="LC_error">'.
9521: &mt('An error occurred: [_1]',$putresult).'</span>';
9522: }
9523: return $resulttext;
9524: }
9525:
1.23 raeburn 9526: sub modify_directorysrch {
9527: my ($dom,%domconfig) = @_;
9528: my ($resulttext,%changes);
9529: my %currdirsrch;
9530: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
9531: foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
9532: $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
9533: }
9534: }
1.277 raeburn 9535: my %title = ( available => 'Institutional directory search available',
9536: localonly => 'Other domains can search institution',
9537: lcavailable => 'LON-CAPA directory search available',
9538: lclocalonly => 'Other domains can search LON-CAPA domain',
1.23 raeburn 9539: searchby => 'Search types',
9540: searchtypes => 'Search latitude');
9541: my @offon = ('off','on');
1.24 raeburn 9542: my @otherdoms = ('Yes','No');
1.23 raeburn 9543:
1.25 raeburn 9544: my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');
1.23 raeburn 9545: my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
9546: my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
9547:
1.44 raeburn 9548: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.26 raeburn 9549: if (keys(%{$usertypes}) == 0) {
9550: @cansearch = ('default');
9551: } else {
9552: if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
9553: foreach my $type (@{$currdirsrch{'cansearch'}}) {
9554: if (!grep(/^\Q$type\E$/,@cansearch)) {
9555: push(@{$changes{'cansearch'}},$type);
9556: }
1.23 raeburn 9557: }
1.26 raeburn 9558: foreach my $type (@cansearch) {
9559: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
9560: push(@{$changes{'cansearch'}},$type);
9561: }
1.23 raeburn 9562: }
1.26 raeburn 9563: } else {
9564: push(@{$changes{'cansearch'}},@cansearch);
1.23 raeburn 9565: }
9566: }
9567:
9568: if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
9569: foreach my $by (@{$currdirsrch{'searchby'}}) {
9570: if (!grep(/^\Q$by\E$/,@searchby)) {
9571: push(@{$changes{'searchby'}},$by);
9572: }
9573: }
9574: foreach my $by (@searchby) {
9575: if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
9576: push(@{$changes{'searchby'}},$by);
9577: }
9578: }
9579: } else {
9580: push(@{$changes{'searchby'}},@searchby);
9581: }
1.25 raeburn 9582:
9583: if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
9584: foreach my $type (@{$currdirsrch{'searchtypes'}}) {
9585: if (!grep(/^\Q$type\E$/,@searchtypes)) {
9586: push(@{$changes{'searchtypes'}},$type);
9587: }
9588: }
9589: foreach my $type (@searchtypes) {
9590: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
9591: push(@{$changes{'searchtypes'}},$type);
9592: }
9593: }
9594: } else {
9595: if (exists($currdirsrch{'searchtypes'})) {
9596: foreach my $type (@searchtypes) {
9597: if ($type ne $currdirsrch{'searchtypes'}) {
9598: push(@{$changes{'searchtypes'}},$type);
9599: }
9600: }
9601: if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
9602: push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
9603: }
9604: } else {
9605: push(@{$changes{'searchtypes'}},@searchtypes);
9606: }
9607: }
9608:
1.23 raeburn 9609: my %dirsrch_hash = (
9610: directorysrch => { available => $env{'form.dirsrch_available'},
9611: cansearch => \@cansearch,
1.277 raeburn 9612: localonly => $env{'form.dirsrch_instlocalonly'},
9613: lclocalonly => $env{'form.dirsrch_domlocalonly'},
9614: lcavailable => $env{'form.dirsrch_domavailable'},
1.23 raeburn 9615: searchby => \@searchby,
1.25 raeburn 9616: searchtypes => \@searchtypes,
1.23 raeburn 9617: }
9618: );
9619: my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
9620: $dom);
9621: if ($putresult eq 'ok') {
9622: if (exists($currdirsrch{'available'})) {
9623: if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
9624: $changes{'available'} = 1;
9625: }
9626: } else {
9627: if ($env{'form.dirsrch_available'} eq '1') {
9628: $changes{'available'} = 1;
9629: }
9630: }
1.277 raeburn 9631: if (exists($currdirsrch{'lcavailable'})) {
9632: if ($currdirsrch{'lcavailable'} ne $env{'form.dirsrch_domavailable'}) {
9633: $changes{'lcavailable'} = 1;
9634: }
9635: } else {
9636: if ($env{'form.dirsrch_lcavailable'} eq '1') {
9637: $changes{'lcavailable'} = 1;
9638: }
9639: }
1.24 raeburn 9640: if (exists($currdirsrch{'localonly'})) {
1.277 raeburn 9641: if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_instlocalonly'}) {
1.24 raeburn 9642: $changes{'localonly'} = 1;
9643: }
9644: } else {
1.277 raeburn 9645: if ($env{'form.dirsrch_instlocalonly'} eq '1') {
1.24 raeburn 9646: $changes{'localonly'} = 1;
9647: }
9648: }
1.277 raeburn 9649: if (exists($currdirsrch{'lclocalonly'})) {
9650: if ($currdirsrch{'lclocalonly'} ne $env{'form.dirsrch_domlocalonly'}) {
9651: $changes{'lclocalonly'} = 1;
9652: }
9653: } else {
9654: if ($env{'form.dirsrch_domlocalonly'} eq '1') {
9655: $changes{'lclocalonly'} = 1;
9656: }
9657: }
1.23 raeburn 9658: if (keys(%changes) > 0) {
9659: $resulttext = &mt('Changes made:').'<ul>';
9660: if ($changes{'available'}) {
9661: $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
9662: }
1.277 raeburn 9663: if ($changes{'lcavailable'}) {
9664: $resulttext .= '<li>'.&mt("$title{'lcavailable'} set to: $offon[$env{'form.dirsrch_domavailable'}]").'</li>';
9665: }
1.24 raeburn 9666: if ($changes{'localonly'}) {
1.277 raeburn 9667: $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_instlocalonly'}]").'</li>';
1.24 raeburn 9668: }
1.277 raeburn 9669: if ($changes{'lclocalonly'}) {
9670: $resulttext .= '<li>'.&mt("$title{'lclocalonly'} set to: $otherdoms[$env{'form.dirsrch_domlocalonly'}]").'</li>';
9671: }
1.23 raeburn 9672: if (ref($changes{'cansearch'}) eq 'ARRAY') {
9673: my $chgtext;
1.26 raeburn 9674: if (ref($usertypes) eq 'HASH') {
9675: if (keys(%{$usertypes}) > 0) {
9676: foreach my $type (@{$types}) {
9677: if (grep(/^\Q$type\E$/,@cansearch)) {
9678: $chgtext .= $usertypes->{$type}.'; ';
9679: }
9680: }
9681: if (grep(/^default$/,@cansearch)) {
9682: $chgtext .= $othertitle;
9683: } else {
9684: $chgtext =~ s/\; $//;
9685: }
1.210 raeburn 9686: $resulttext .=
1.178 raeburn 9687: '<li>'.
9688: &mt("Users from domain '[_1]' permitted to search the institutional directory set to: [_2]",
9689: '<span class="LC_cusr_emph">'.$dom.'</span>',$chgtext).
9690: '</li>';
1.23 raeburn 9691: }
9692: }
9693: }
9694: if (ref($changes{'searchby'}) eq 'ARRAY') {
9695: my ($searchtitles,$titleorder) = &sorted_searchtitles();
9696: my $chgtext;
9697: foreach my $type (@{$titleorder}) {
9698: if (grep(/^\Q$type\E$/,@searchby)) {
9699: if (defined($searchtitles->{$type})) {
9700: $chgtext .= $searchtitles->{$type}.'; ';
9701: }
9702: }
9703: }
9704: $chgtext =~ s/\; $//;
9705: $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
9706: }
1.25 raeburn 9707: if (ref($changes{'searchtypes'}) eq 'ARRAY') {
9708: my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes();
9709: my $chgtext;
9710: foreach my $type (@{$srchtypeorder}) {
9711: if (grep(/^\Q$type\E$/,@searchtypes)) {
9712: if (defined($srchtypes_desc->{$type})) {
9713: $chgtext .= $srchtypes_desc->{$type}.'; ';
9714: }
9715: }
9716: }
9717: $chgtext =~ s/\; $//;
1.178 raeburn 9718: $resulttext .= '<li>'.&mt($title{'searchtypes'}.' set to: "[_1]"',$chgtext).'</li>';
1.23 raeburn 9719: }
9720: $resulttext .= '</ul>';
9721: } else {
1.277 raeburn 9722: $resulttext = &mt('No changes made to directory search settings');
1.23 raeburn 9723: }
9724: } else {
9725: $resulttext = '<span class="LC_error">'.
1.27 raeburn 9726: &mt('An error occurred: [_1]',$putresult).'</span>';
9727: }
9728: return $resulttext;
9729: }
9730:
1.28 raeburn 9731: sub modify_contacts {
1.205 raeburn 9732: my ($dom,$lastactref,%domconfig) = @_;
1.28 raeburn 9733: my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
9734: if (ref($domconfig{'contacts'}) eq 'HASH') {
9735: foreach my $key (keys(%{$domconfig{'contacts'}})) {
9736: $currsetting{$key} = $domconfig{'contacts'}{$key};
9737: }
9738: }
1.134 raeburn 9739: my (%others,%to,%bcc);
1.28 raeburn 9740: my @contacts = ('supportemail','adminemail');
1.102 raeburn 9741: my @mailings = ('errormail','packagesmail','helpdeskmail','lonstatusmail',
1.203 raeburn 9742: 'requestsmail','updatesmail','idconflictsmail');
9743: my @toggles = ('reporterrors','reportupdates');
1.28 raeburn 9744: foreach my $type (@mailings) {
9745: @{$newsetting{$type}} =
9746: &Apache::loncommon::get_env_multiple('form.'.$type);
9747: foreach my $item (@contacts) {
9748: if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
9749: $contacts_hash{contacts}{$type}{$item} = 1;
9750: } else {
9751: $contacts_hash{contacts}{$type}{$item} = 0;
9752: }
9753: }
9754: $others{$type} = $env{'form.'.$type.'_others'};
9755: $contacts_hash{contacts}{$type}{'others'} = $others{$type};
1.134 raeburn 9756: if ($type eq 'helpdeskmail') {
9757: $bcc{$type} = $env{'form.'.$type.'_bcc'};
9758: $contacts_hash{contacts}{$type}{'bcc'} = $bcc{$type};
9759: }
1.28 raeburn 9760: }
9761: foreach my $item (@contacts) {
9762: $to{$item} = $env{'form.'.$item};
9763: $contacts_hash{'contacts'}{$item} = $to{$item};
9764: }
1.203 raeburn 9765: foreach my $item (@toggles) {
9766: if ($env{'form.'.$item} =~ /^(0|1)$/) {
9767: $contacts_hash{'contacts'}{$item} = $env{'form.'.$item};
9768: }
9769: }
1.28 raeburn 9770: if (keys(%currsetting) > 0) {
9771: foreach my $item (@contacts) {
9772: if ($to{$item} ne $currsetting{$item}) {
9773: $changes{$item} = 1;
9774: }
9775: }
9776: foreach my $type (@mailings) {
9777: foreach my $item (@contacts) {
9778: if (ref($currsetting{$type}) eq 'HASH') {
9779: if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
9780: push(@{$changes{$type}},$item);
9781: }
9782: } else {
9783: push(@{$changes{$type}},@{$newsetting{$type}});
9784: }
9785: }
9786: if ($others{$type} ne $currsetting{$type}{'others'}) {
9787: push(@{$changes{$type}},'others');
9788: }
1.134 raeburn 9789: if ($type eq 'helpdeskmail') {
9790: if ($bcc{$type} ne $currsetting{$type}{'bcc'}) {
9791: push(@{$changes{$type}},'bcc');
9792: }
9793: }
1.28 raeburn 9794: }
9795: } else {
9796: my %default;
9797: $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
9798: $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
9799: $default{'errormail'} = 'adminemail';
9800: $default{'packagesmail'} = 'adminemail';
9801: $default{'helpdeskmail'} = 'supportemail';
1.89 raeburn 9802: $default{'lonstatusmail'} = 'adminemail';
1.102 raeburn 9803: $default{'requestsmail'} = 'adminemail';
1.190 raeburn 9804: $default{'updatesmail'} = 'adminemail';
1.28 raeburn 9805: foreach my $item (@contacts) {
9806: if ($to{$item} ne $default{$item}) {
9807: $changes{$item} = 1;
1.203 raeburn 9808: }
1.28 raeburn 9809: }
9810: foreach my $type (@mailings) {
9811: if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
9812:
9813: push(@{$changes{$type}},@{$newsetting{$type}});
9814: }
9815: if ($others{$type} ne '') {
9816: push(@{$changes{$type}},'others');
1.134 raeburn 9817: }
9818: if ($type eq 'helpdeskmail') {
9819: if ($bcc{$type} ne '') {
9820: push(@{$changes{$type}},'bcc');
9821: }
9822: }
1.28 raeburn 9823: }
9824: }
1.203 raeburn 9825: foreach my $item (@toggles) {
9826: if (($env{'form.'.$item} == 1) && ($currsetting{$item} == 0)) {
9827: $changes{$item} = 1;
9828: } elsif ((!$env{'form.'.$item}) &&
9829: (($currsetting{$item} eq '') || ($currsetting{$item} == 1))) {
9830: $changes{$item} = 1;
9831: }
9832: }
1.28 raeburn 9833: my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
9834: $dom);
9835: if ($putresult eq 'ok') {
9836: if (keys(%changes) > 0) {
1.205 raeburn 9837: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 9838: if (ref($lastactref) eq 'HASH') {
9839: $lastactref->{'domainconfig'} = 1;
9840: }
1.28 raeburn 9841: my ($titles,$short_titles) = &contact_titles();
9842: $resulttext = &mt('Changes made:').'<ul>';
9843: foreach my $item (@contacts) {
9844: if ($changes{$item}) {
9845: $resulttext .= '<li>'.$titles->{$item}.
9846: &mt(' set to: ').
9847: '<span class="LC_cusr_emph">'.
9848: $to{$item}.'</span></li>';
9849: }
9850: }
9851: foreach my $type (@mailings) {
9852: if (ref($changes{$type}) eq 'ARRAY') {
9853: $resulttext .= '<li>'.$titles->{$type}.': ';
9854: my @text;
9855: foreach my $item (@{$newsetting{$type}}) {
9856: push(@text,$short_titles->{$item});
9857: }
9858: if ($others{$type} ne '') {
9859: push(@text,$others{$type});
9860: }
9861: $resulttext .= '<span class="LC_cusr_emph">'.
1.134 raeburn 9862: join(', ',@text).'</span>';
9863: if ($type eq 'helpdeskmail') {
9864: if ($bcc{$type} ne '') {
9865: $resulttext .= ' '.&mt('with Bcc to').': <span class="LC_cusr_emph">'.$bcc{$type}.'</span>';
9866: }
9867: }
9868: $resulttext .= '</li>';
1.28 raeburn 9869: }
9870: }
1.203 raeburn 9871: my @offon = ('off','on');
9872: if ($changes{'reporterrors'}) {
9873: $resulttext .= '<li>'.
9874: &mt('E-mail error reports to [_1] set to "'.
9875: $offon[$env{'form.reporterrors'}].'".',
9876: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
9877: &mt('LON-CAPA core group - MSU'),600,500)).
9878: '</li>';
9879: }
9880: if ($changes{'reportupdates'}) {
9881: $resulttext .= '<li>'.
9882: &mt('E-mail record of completed LON-CAPA updates to [_1] set to "'.
9883: $offon[$env{'form.reportupdates'}].'".',
9884: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
9885: &mt('LON-CAPA core group - MSU'),600,500)).
9886: '</li>';
9887: }
1.28 raeburn 9888: $resulttext .= '</ul>';
9889: } else {
1.34 raeburn 9890: $resulttext = &mt('No changes made to contact information');
1.28 raeburn 9891: }
9892: } else {
9893: $resulttext = '<span class="LC_error">'.
9894: &mt('An error occurred: [_1].',$putresult).'</span>';
9895: }
9896: return $resulttext;
9897: }
9898:
9899: sub modify_usercreation {
1.27 raeburn 9900: my ($dom,%domconfig) = @_;
1.224 raeburn 9901: my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate,%save_usercreate);
1.43 raeburn 9902: my $warningmsg;
1.27 raeburn 9903: if (ref($domconfig{'usercreation'}) eq 'HASH') {
9904: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
1.224 raeburn 9905: if ($key eq 'cancreate') {
9906: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
9907: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
9908: if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
1.269 raeburn 9909: ($item eq 'captcha') || ($item eq 'recaptchakeys') ||
9910: ($item eq 'recaptchaversion')) {
1.224 raeburn 9911: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
9912: } else {
9913: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
9914: }
9915: }
9916: }
9917: } elsif ($key eq 'email_rule') {
9918: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
9919: } else {
9920: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
9921: }
1.27 raeburn 9922: }
9923: }
9924: my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
1.32 raeburn 9925: my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
1.224 raeburn 9926: my @contexts = ('author','course','requestcrs');
1.34 raeburn 9927: foreach my $item(@contexts) {
1.224 raeburn 9928: $cancreate{$item} = $env{'form.can_createuser_'.$item};
1.93 raeburn 9929: }
1.34 raeburn 9930: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
9931: foreach my $item (@contexts) {
1.224 raeburn 9932: if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
9933: push(@{$changes{'cancreate'}},$item);
1.50 raeburn 9934: }
1.27 raeburn 9935: }
1.34 raeburn 9936: } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
9937: foreach my $item (@contexts) {
1.43 raeburn 9938: if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
1.34 raeburn 9939: if ($cancreate{$item} ne 'any') {
9940: push(@{$changes{'cancreate'}},$item);
9941: }
9942: } else {
9943: if ($cancreate{$item} ne 'none') {
9944: push(@{$changes{'cancreate'}},$item);
9945: }
1.27 raeburn 9946: }
9947: }
9948: } else {
1.43 raeburn 9949: foreach my $item (@contexts) {
1.34 raeburn 9950: push(@{$changes{'cancreate'}},$item);
9951: }
1.27 raeburn 9952: }
1.34 raeburn 9953:
1.27 raeburn 9954: if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
9955: foreach my $type (@{$curr_usercreation{'username_rule'}}) {
9956: if (!grep(/^\Q$type\E$/,@username_rule)) {
9957: push(@{$changes{'username_rule'}},$type);
9958: }
9959: }
9960: foreach my $type (@username_rule) {
9961: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
9962: push(@{$changes{'username_rule'}},$type);
9963: }
9964: }
9965: } else {
9966: push(@{$changes{'username_rule'}},@username_rule);
9967: }
9968:
1.32 raeburn 9969: if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
9970: foreach my $type (@{$curr_usercreation{'id_rule'}}) {
9971: if (!grep(/^\Q$type\E$/,@id_rule)) {
9972: push(@{$changes{'id_rule'}},$type);
9973: }
9974: }
9975: foreach my $type (@id_rule) {
9976: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
9977: push(@{$changes{'id_rule'}},$type);
9978: }
9979: }
9980: } else {
9981: push(@{$changes{'id_rule'}},@id_rule);
9982: }
9983:
1.43 raeburn 9984: my @authen_contexts = ('author','course','domain');
1.28 raeburn 9985: my @authtypes = ('int','krb4','krb5','loc');
9986: my %authhash;
1.43 raeburn 9987: foreach my $item (@authen_contexts) {
1.28 raeburn 9988: my @authallowed = &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
9989: foreach my $auth (@authtypes) {
9990: if (grep(/^\Q$auth\E$/,@authallowed)) {
9991: $authhash{$item}{$auth} = 1;
9992: } else {
9993: $authhash{$item}{$auth} = 0;
9994: }
9995: }
9996: }
9997: if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
1.43 raeburn 9998: foreach my $item (@authen_contexts) {
1.28 raeburn 9999: if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
10000: foreach my $auth (@authtypes) {
10001: if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
10002: push(@{$changes{'authtypes'}},$item);
10003: last;
10004: }
10005: }
10006: }
10007: }
10008: } else {
1.43 raeburn 10009: foreach my $item (@authen_contexts) {
1.28 raeburn 10010: push(@{$changes{'authtypes'}},$item);
10011: }
10012: }
10013:
1.224 raeburn 10014: $save_usercreate{'cancreate'}{'course'} = $cancreate{'course'};
10015: $save_usercreate{'cancreate'}{'author'} = $cancreate{'author'};
10016: $save_usercreate{'cancreate'}{'requestcrs'} = $cancreate{'requestcrs'};
10017: $save_usercreate{'id_rule'} = \@id_rule;
10018: $save_usercreate{'username_rule'} = \@username_rule,
10019: $save_usercreate{'authtypes'} = \%authhash;
10020:
1.27 raeburn 10021: my %usercreation_hash = (
1.224 raeburn 10022: usercreation => \%save_usercreate,
10023: );
1.27 raeburn 10024:
10025: my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
10026: $dom);
1.50 raeburn 10027:
1.224 raeburn 10028: if ($putresult eq 'ok') {
10029: if (keys(%changes) > 0) {
10030: $resulttext = &mt('Changes made:').'<ul>';
10031: if (ref($changes{'cancreate'}) eq 'ARRAY') {
10032: my %lt = &usercreation_types();
10033: foreach my $type (@{$changes{'cancreate'}}) {
10034: my $chgtext = $lt{$type}.', ';
10035: if ($cancreate{$type} eq 'none') {
10036: $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
10037: } elsif ($cancreate{$type} eq 'any') {
10038: $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
10039: } elsif ($cancreate{$type} eq 'official') {
10040: $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
10041: } elsif ($cancreate{$type} eq 'unofficial') {
10042: $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
10043: }
10044: $resulttext .= '<li>'.$chgtext.'</li>';
10045: }
10046: }
10047: if (ref($changes{'username_rule'}) eq 'ARRAY') {
10048: my ($rules,$ruleorder) =
10049: &Apache::lonnet::inst_userrules($dom,'username');
10050: my $chgtext = '<ul>';
10051: foreach my $type (@username_rule) {
10052: if (ref($rules->{$type}) eq 'HASH') {
10053: $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
10054: }
10055: }
10056: $chgtext .= '</ul>';
10057: if (@username_rule > 0) {
10058: $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
10059: } else {
10060: $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>';
10061: }
10062: }
10063: if (ref($changes{'id_rule'}) eq 'ARRAY') {
10064: my ($idrules,$idruleorder) =
10065: &Apache::lonnet::inst_userrules($dom,'id');
10066: my $chgtext = '<ul>';
10067: foreach my $type (@id_rule) {
10068: if (ref($idrules->{$type}) eq 'HASH') {
10069: $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
10070: }
10071: }
10072: $chgtext .= '</ul>';
10073: if (@id_rule > 0) {
10074: $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
10075: } else {
10076: $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
10077: }
10078: }
10079: my %authname = &authtype_names();
10080: my %context_title = &context_names();
10081: if (ref($changes{'authtypes'}) eq 'ARRAY') {
10082: my $chgtext = '<ul>';
10083: foreach my $type (@{$changes{'authtypes'}}) {
10084: my @allowed;
10085: $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
10086: foreach my $auth (@authtypes) {
10087: if ($authhash{$type}{$auth}) {
10088: push(@allowed,$authname{$auth});
10089: }
10090: }
10091: if (@allowed > 0) {
10092: $chgtext .= join(', ',@allowed).'</li>';
10093: } else {
10094: $chgtext .= &mt('none').'</li>';
10095: }
10096: }
10097: $chgtext .= '</ul>';
10098: $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
10099: $resulttext .= '</li>';
10100: }
10101: $resulttext .= '</ul>';
10102: } else {
10103: $resulttext = &mt('No changes made to user creation settings');
10104: }
10105: } else {
10106: $resulttext = '<span class="LC_error">'.
10107: &mt('An error occurred: [_1]',$putresult).'</span>';
10108: }
10109: if ($warningmsg ne '') {
10110: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
10111: }
10112: return $resulttext;
10113: }
10114:
10115: sub modify_selfcreation {
10116: my ($dom,%domconfig) = @_;
10117: my ($resulttext,$warningmsg,%curr_usercreation,%curr_usermodify,%changes,%cancreate);
10118: my (%save_usercreate,%save_usermodify);
1.228 raeburn 10119: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
10120: if (ref($types) eq 'ARRAY') {
10121: $usertypes->{'default'} = $othertitle;
10122: push(@{$types},'default');
10123: }
1.224 raeburn 10124: #
10125: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usercreation'}.
10126: #
10127: if (ref($domconfig{'usercreation'}) eq 'HASH') {
10128: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
10129: if ($key eq 'cancreate') {
10130: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
10131: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
10132: if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
10133: ($item eq 'captcha') || ($item eq 'recaptchakeys') ||
1.269 raeburn 10134: ($item eq 'recaptchaversion') ||
1.236 raeburn 10135: ($item eq 'emailusername') || ($item eq 'notify') ||
1.240 raeburn 10136: ($item eq 'selfcreateprocessing') || ($item eq 'shibenv')) {
1.224 raeburn 10137: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
10138: } else {
10139: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
10140: }
10141: }
10142: }
10143: } elsif ($key eq 'email_rule') {
10144: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
10145: } else {
10146: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
10147: }
10148: }
10149: }
10150: #
10151: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usermodification'}.
10152: #
10153: if (ref($domconfig{'usermodification'}) eq 'HASH') {
10154: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
10155: if ($key eq 'selfcreate') {
10156: $curr_usermodify{$key} = $domconfig{'usermodification'}{$key};
10157: } else {
10158: $save_usermodify{$key} = $domconfig{'usermodification'}{$key};
10159: }
10160: }
10161: }
10162:
10163: my @contexts = ('selfcreate');
10164: @{$cancreate{'selfcreate'}} = ();
10165: %{$cancreate{'emailusername'}} = ();
10166: @{$cancreate{'statustocreate'}} = ();
1.236 raeburn 10167: %{$cancreate{'selfcreateprocessing'}} = ();
1.240 raeburn 10168: %{$cancreate{'shibenv'}} = ();
1.50 raeburn 10169: my %selfcreatetypes = (
10170: sso => 'users authenticated by institutional single sign on',
10171: login => 'users authenticated by institutional log-in',
1.236 raeburn 10172: email => 'users who provide a valid e-mail address for use as username',
1.50 raeburn 10173: );
1.224 raeburn 10174: #
10175: # Populate $cancreate{'selfcreate'} array reference with types of user, for which self-creation of user accounts
10176: # is permitted.
10177: #
1.236 raeburn 10178:
10179: my @statuses;
10180: if (ref($domconfig{'inststatus'}) eq 'HASH') {
10181: if (ref($domconfig{'inststatus'}{'inststatusguest'}) eq 'ARRAY') {
10182: @statuses = @{$domconfig{'inststatus'}{'inststatusguest'}};
10183: }
10184: }
10185: push(@statuses,'default');
10186:
1.228 raeburn 10187: foreach my $item ('login','sso','email') {
1.224 raeburn 10188: if ($item eq 'email') {
1.236 raeburn 10189: if ($env{'form.cancreate_email'}) {
1.224 raeburn 10190: push(@{$cancreate{'selfcreate'}},'email');
1.236 raeburn 10191: push(@contexts,'selfcreateprocessing');
10192: foreach my $type (@statuses) {
10193: if ($type eq 'default') {
10194: $cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess'};
10195: } else {
10196: $cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess_'.$type};
10197: }
10198: }
1.224 raeburn 10199: }
10200: } else {
10201: if ($env{'form.cancreate_'.$item}) {
10202: push(@{$cancreate{'selfcreate'}},$item);
10203: }
10204: }
10205: }
10206: my (@email_rule,%userinfo,%savecaptcha);
10207: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
10208: #
1.228 raeburn 10209: # Populate $cancreate{'emailusername'}{$type} hash ref with information fields (if new user will provide data
10210: # value set to one), if self-creation with e-mail address permitted, where $type is user type: faculty, staff, student etc.
1.224 raeburn 10211: #
1.236 raeburn 10212:
1.244 raeburn 10213: if ($env{'form.cancreate_email'}) {
1.228 raeburn 10214: push(@contexts,'emailusername');
10215: if (ref($types) eq 'ARRAY') {
10216: foreach my $type (@{$types}) {
10217: if (ref($infofields) eq 'ARRAY') {
10218: foreach my $field (@{$infofields}) {
10219: if ($env{'form.canmodify_emailusername_'.$type.'_'.$field} =~ /^(required|optional)$/) {
10220: $cancreate{'emailusername'}{$type}{$field} = $1;
10221: }
10222: }
1.224 raeburn 10223: }
10224: }
10225: }
10226: #
10227: # Populate $cancreate{'notify'} hash ref with names of Domain Coordinators who are to be notified of
10228: # queued requests for self-creation of account using e-mail address as username
10229: #
10230:
10231: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.selfcreationnotifyapproval');
10232: @approvalnotify = sort(@approvalnotify);
10233: $cancreate{'notify'}{'approval'} = join(',',@approvalnotify);
10234: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
10235: if (ref($curr_usercreation{'cancreate'}{'notify'}) eq 'HASH') {
10236: if ($curr_usercreation{'cancreate'}{'notify'}{'approval'} ne $cancreate{'notify'}{'approval'}) {
10237: push(@{$changes{'cancreate'}},'notify');
10238: }
10239: } else {
10240: if ($cancreate{'notify'}{'approval'}) {
10241: push(@{$changes{'cancreate'}},'notify');
10242: }
10243: }
10244: } elsif ($cancreate{'notify'}{'approval'}) {
10245: push(@{$changes{'cancreate'}},'notify');
10246: }
10247:
10248: #
10249: # Retrieve rules (if any) governing types of e-mail address which may be used as a username
10250: #
10251: @email_rule = &Apache::loncommon::get_env_multiple('form.email_rule');
10252: &process_captcha('cancreate',\%changes,\%savecaptcha,$curr_usercreation{'cancreate'});
10253: if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
10254: if (@{$curr_usercreation{'email_rule'}} > 0) {
10255: foreach my $type (@{$curr_usercreation{'email_rule'}}) {
10256: if (!grep(/^\Q$type\E$/,@email_rule)) {
10257: push(@{$changes{'email_rule'}},$type);
10258: }
10259: }
10260: }
10261: if (@email_rule > 0) {
10262: foreach my $type (@email_rule) {
10263: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'email_rule'}})) {
10264: push(@{$changes{'email_rule'}},$type);
10265: }
10266: }
10267: }
10268: } elsif (@email_rule > 0) {
10269: push(@{$changes{'email_rule'}},@email_rule);
10270: }
10271: }
10272: #
1.236 raeburn 10273: # Check if domain default is set appropriately, if self-creation of accounts is to be available for
1.224 raeburn 10274: # institutional log-in.
10275: #
10276: if (grep(/^login$/,@{$cancreate{'selfcreate'}})) {
10277: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
10278: if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) ||
10279: ($domdefaults{'auth_def'} eq 'localauth'))) {
10280: $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.').' '.
10281: &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.');
10282: }
10283: }
10284: my @fields = ('lastname','firstname','middlename','generation',
10285: 'permanentemail','id');
1.240 raeburn 10286: my @shibfields = (@fields,'inststatus');
1.224 raeburn 10287: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
10288: #
10289: # Where usernames may created for institutional log-in and/or institutional single sign on:
10290: # (a) populate $cancreate{'statustocreate'} array reference with institutional status types who
10291: # may self-create accounts
10292: # (b) populate $save_usermodify{'selfcreate'} hash reference with status types, and information fields
10293: # which the user may supply, if institutional data is unavailable.
10294: #
10295: if (($env{'form.cancreate_login'}) || ($env{'form.cancreate_sso'})) {
10296: if (ref($types) eq 'ARRAY') {
1.228 raeburn 10297: if (@{$types} > 1) {
1.224 raeburn 10298: @{$cancreate{'statustocreate'}} = &Apache::loncommon::get_env_multiple('form.statustocreate');
10299: push(@contexts,'statustocreate');
10300: } else {
10301: undef($cancreate{'statustocreate'});
10302: }
10303: foreach my $type (@{$types}) {
10304: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$type);
10305: foreach my $field (@fields) {
10306: if (grep(/^\Q$field\E$/,@modifiable)) {
10307: $save_usermodify{'selfcreate'}{$type}{$field} = 1;
10308: } else {
10309: $save_usermodify{'selfcreate'}{$type}{$field} = 0;
10310: }
10311: }
10312: }
10313: if (ref($curr_usermodify{'selfcreate'}) eq 'HASH') {
10314: foreach my $type (@{$types}) {
10315: if (ref($curr_usermodify{'selfcreate'}{$type}) eq 'HASH') {
10316: foreach my $field (@fields) {
10317: if ($save_usermodify{'selfcreate'}{$type}{$field} ne
10318: $curr_usermodify{'selfcreate'}{$type}{$field}) {
10319: push(@{$changes{'selfcreate'}},$type);
10320: last;
10321: }
10322: }
10323: }
10324: }
10325: } else {
10326: foreach my $type (@{$types}) {
10327: push(@{$changes{'selfcreate'}},$type);
10328: }
10329: }
10330: }
1.240 raeburn 10331: foreach my $field (@shibfields) {
10332: if ($env{'form.shibenv_'.$field} ne '') {
10333: $cancreate{'shibenv'}{$field} = $env{'form.shibenv_'.$field};
10334: }
10335: }
10336: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
10337: if (ref($curr_usercreation{'cancreate'}{'shibenv'}) eq 'HASH') {
10338: foreach my $field (@shibfields) {
10339: if ($env{'form.shibenv_'.$field} ne $curr_usercreation{'cancreate'}{'shibenv'}{$field}) {
10340: push(@{$changes{'cancreate'}},'shibenv');
10341: }
10342: }
10343: } else {
10344: foreach my $field (@shibfields) {
10345: if ($env{'form.shibenv_'.$field}) {
10346: push(@{$changes{'cancreate'}},'shibenv');
10347: last;
10348: }
10349: }
10350: }
10351: }
1.224 raeburn 10352: }
10353: foreach my $item (@contexts) {
10354: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
10355: foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
10356: if (ref($cancreate{$item}) eq 'ARRAY') {
10357: if (!grep(/^$curr$/,@{$cancreate{$item}})) {
10358: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
10359: push(@{$changes{'cancreate'}},$item);
10360: }
10361: }
10362: }
10363: }
10364: if (ref($cancreate{$item}) eq 'ARRAY') {
10365: foreach my $type (@{$cancreate{$item}}) {
10366: if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
10367: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
10368: push(@{$changes{'cancreate'}},$item);
10369: }
10370: }
10371: }
10372: }
10373: } elsif (ref($curr_usercreation{'cancreate'}{$item}) eq 'HASH') {
10374: if (ref($cancreate{$item}) eq 'HASH') {
10375: foreach my $curr (keys(%{$curr_usercreation{'cancreate'}{$item}})) {
1.228 raeburn 10376: if (ref($curr_usercreation{'cancreate'}{$item}{$curr}) eq 'HASH') {
10377: foreach my $field (keys(%{$curr_usercreation{'cancreate'}{$item}{$curr}})) {
10378: unless ($curr_usercreation{'cancreate'}{$item}{$curr}{$field} eq $cancreate{$item}{$curr}{$field}) {
10379: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
10380: push(@{$changes{'cancreate'}},$item);
10381: }
10382: }
10383: }
1.236 raeburn 10384: } elsif ($item eq 'selfcreateprocessing') {
10385: if ($cancreate{$item}{$curr} ne $curr_usercreation{'cancreate'}{$item}{$curr}) {
10386: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
10387: push(@{$changes{'cancreate'}},$item);
10388: }
10389: }
1.228 raeburn 10390: } else {
10391: if (!$cancreate{$item}{$curr}) {
10392: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
10393: push(@{$changes{'cancreate'}},$item);
10394: }
1.224 raeburn 10395: }
10396: }
10397: }
10398: foreach my $field (keys(%{$cancreate{$item}})) {
1.228 raeburn 10399: if (ref($cancreate{$item}{$field}) eq 'HASH') {
10400: foreach my $inner (keys(%{$cancreate{$item}{$field}})) {
10401: if (ref($curr_usercreation{'cancreate'}{$item}{$field}) eq 'HASH') {
10402: unless ($curr_usercreation{'cancreate'}{$item}{$field}{$inner} eq $cancreate{$item}{$field}{$inner}) {
10403: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
10404: push(@{$changes{'cancreate'}},$item);
10405: }
10406: }
10407: } else {
10408: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
10409: push(@{$changes{'cancreate'}},$item);
10410: }
10411: }
10412: }
1.236 raeburn 10413: } elsif ($item eq 'selfcreateprocessing') {
10414: if ($cancreate{$item}{$field} ne $curr_usercreation{'cancreate'}{$item}{$field}) {
10415: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
10416: push(@{$changes{'cancreate'}},$item);
10417: }
10418: }
1.228 raeburn 10419: } else {
10420: if (!$curr_usercreation{'cancreate'}{$item}{$field}) {
10421: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
10422: push(@{$changes{'cancreate'}},$item);
10423: }
1.224 raeburn 10424: }
10425: }
10426: }
10427: }
10428: } elsif ($curr_usercreation{'cancreate'}{$item}) {
10429: if (ref($cancreate{$item}) eq 'ARRAY') {
10430: if (!grep(/^\Q$curr_usercreation{'cancreate'}{$item}\E$/,@{$cancreate{$item}})) {
10431: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
10432: push(@{$changes{'cancreate'}},$item);
10433: }
10434: }
10435: } elsif (ref($cancreate{$item}) eq 'HASH') {
10436: if (!$cancreate{$item}{$curr_usercreation{'cancreate'}{$item}}) {
10437: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
10438: push(@{$changes{'cancreate'}},$item);
10439: }
10440: }
10441: }
10442: } elsif ($item eq 'emailusername') {
1.228 raeburn 10443: if (ref($cancreate{$item}) eq 'HASH') {
10444: foreach my $type (keys(%{$cancreate{$item}})) {
10445: if (ref($cancreate{$item}{$type}) eq 'HASH') {
10446: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
10447: if ($cancreate{$item}{$type}{$field}) {
10448: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
10449: push(@{$changes{'cancreate'}},$item);
10450: }
10451: last;
10452: }
10453: }
10454: }
10455: }
1.224 raeburn 10456: }
10457: }
10458: }
10459: #
10460: # Populate %save_usercreate hash with updates to self-creation configuration.
10461: #
10462: $save_usercreate{'cancreate'}{'captcha'} = $savecaptcha{'captcha'};
10463: $save_usercreate{'cancreate'}{'recaptchakeys'} = $savecaptcha{'recaptchakeys'};
1.269 raeburn 10464: $save_usercreate{'cancreate'}{'recaptchaversion'} = $savecaptcha{'recaptchaversion'};
1.224 raeburn 10465: $save_usercreate{'cancreate'}{'selfcreate'} = $cancreate{'selfcreate'};
10466: if (ref($cancreate{'notify'}) eq 'HASH') {
10467: $save_usercreate{'cancreate'}{'notify'} = $cancreate{'notify'};
10468: }
1.236 raeburn 10469: if (ref($cancreate{'selfcreateprocessing'}) eq 'HASH') {
10470: $save_usercreate{'cancreate'}{'selfcreateprocessing'} = $cancreate{'selfcreateprocessing'};
10471: }
1.224 raeburn 10472: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
10473: $save_usercreate{'cancreate'}{'statustocreate'} = $cancreate{'statustocreate'};
10474: }
1.240 raeburn 10475: if (ref($cancreate{'shibenv'}) eq 'HASH') {
10476: $save_usercreate{'cancreate'}{'shibenv'} = $cancreate{'shibenv'};
10477: }
1.224 raeburn 10478: $save_usercreate{'cancreate'}{'emailusername'} = $cancreate{'emailusername'};
10479: $save_usercreate{'emailrule'} = \@email_rule;
10480:
10481: my %userconfig_hash = (
10482: usercreation => \%save_usercreate,
10483: usermodification => \%save_usermodify,
10484: );
10485: my $putresult = &Apache::lonnet::put_dom('configuration',\%userconfig_hash,
10486: $dom);
10487: #
10488: # Accumulate details of changes to domain cofiguration for self-creation of usernames in $resulttext
10489: #
1.27 raeburn 10490: if ($putresult eq 'ok') {
10491: if (keys(%changes) > 0) {
10492: $resulttext = &mt('Changes made:').'<ul>';
10493: if (ref($changes{'cancreate'}) eq 'ARRAY') {
1.224 raeburn 10494: my %lt = &selfcreation_types();
1.34 raeburn 10495: foreach my $type (@{$changes{'cancreate'}}) {
1.100 raeburn 10496: my $chgtext;
1.45 raeburn 10497: if ($type eq 'selfcreate') {
1.50 raeburn 10498: if (@{$cancreate{$type}} == 0) {
1.224 raeburn 10499: $chgtext .= &mt('Self creation of a new user account is not permitted.');
1.50 raeburn 10500: } else {
1.224 raeburn 10501: $chgtext .= &mt('Self-creation of a new account is permitted for:').
10502: '<ul>';
1.50 raeburn 10503: foreach my $case (@{$cancreate{$type}}) {
10504: $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
10505: }
10506: $chgtext .= '</ul>';
1.100 raeburn 10507: if (ref($cancreate{$type}) eq 'ARRAY') {
10508: if (grep(/^(login|sso)$/,@{$cancreate{$type}})) {
10509: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
10510: if (@{$cancreate{'statustocreate'}} == 0) {
1.224 raeburn 10511: $chgtext .= '<br />'.
10512: '<span class="LC_warning">'.
10513: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
10514: '</span>';
1.100 raeburn 10515: }
10516: }
10517: }
10518: }
1.43 raeburn 10519: }
1.240 raeburn 10520: } elsif ($type eq 'shibenv') {
10521: if (keys(%{$cancreate{$type}}) == 0) {
10522: $chgtext .= &mt('Shibboleth-autheticated user does not use environment variables to set user information');
10523: } else {
10524: $chgtext .= &mt('Shibboleth-autheticated user information set from environment variables, as follows:').
10525: '<ul>';
10526: foreach my $field (@shibfields) {
10527: next if ($cancreate{$type}{$field} eq '');
10528: if ($field eq 'inststatus') {
10529: $chgtext .= '<li>'.&mt('Institutional status').' -- '.$cancreate{$type}{$field}.'</li>';
10530: } else {
10531: $chgtext .= '<li>'.$fieldtitles{$field}.' -- '.$cancreate{$type}{$field}.'</li>';
10532: }
10533: }
10534: $chgtext .= '</ul>';
10535: }
1.93 raeburn 10536: } elsif ($type eq 'statustocreate') {
1.96 raeburn 10537: if ((ref($cancreate{'selfcreate'}) eq 'ARRAY') &&
10538: (ref($cancreate{'statustocreate'}) eq 'ARRAY')) {
10539: if (@{$cancreate{'selfcreate'}} > 0) {
10540: if (@{$cancreate{'statustocreate'}} == 0) {
1.100 raeburn 10541: $chgtext .= &mt("Institutional affiliations permitted to create accounts set to 'None'.");
1.96 raeburn 10542: if (!grep(/^email$/,@{$cancreate{'selfcreate'}})) {
1.224 raeburn 10543: $chgtext .= '<br />'.
10544: '<span class="LC_warning">'.
10545: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
10546: '</span>';
10547: }
1.96 raeburn 10548: } elsif (ref($usertypes) eq 'HASH') {
10549: if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.100 raeburn 10550: $chgtext .= &mt('Creation of a new account for an institutional user is restricted to the following institutional affiliation(s):');
10551: } else {
10552: $chgtext .= &mt('Institutional affiliations permitted to create accounts with institutional authentication were set as follows:');
10553: }
10554: $chgtext .= '<ul>';
10555: foreach my $case (@{$cancreate{$type}}) {
10556: if ($case eq 'default') {
10557: $chgtext .= '<li>'.$othertitle.'</li>';
10558: } else {
10559: $chgtext .= '<li>'.$usertypes->{$case}.'</li>';
1.93 raeburn 10560: }
10561: }
1.100 raeburn 10562: $chgtext .= '</ul>';
10563: if (!grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.224 raeburn 10564: $chgtext .= '<br /><span class="LC_warning">'.
10565: &mt('However, users authenticated by institutional login/single sign on are not currently permitted to create accounts.').
10566: '</span>';
1.100 raeburn 10567: }
10568: }
10569: } else {
10570: if (@{$cancreate{$type}} == 0) {
10571: $chgtext .= &mt("Institutional affiliations permitted to create accounts were set to 'none'.");
10572: } else {
10573: $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 10574: }
10575: }
10576: }
1.236 raeburn 10577: } elsif ($type eq 'selfcreateprocessing') {
10578: my %choices = &Apache::lonlocal::texthash (
10579: automatic => 'Automatic approval',
10580: approval => 'Queued for approval',
10581: );
10582: if (@statuses > 1) {
10583: $chgtext .= &mt('Processing of requests to create account with e-mail address as username set as follows:').
10584: '<ul>';
10585: foreach my $type (@statuses) {
10586: if ($type eq 'default') {
10587: $chgtext .= '<li>'.$othertitle.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$type}}.'</li>';
10588: } else {
10589: $chgtext .= '<li>'.$usertypes->{$type}.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$type}}.'</li>';
10590: }
10591: }
10592: $chgtext .= '</ul>';
10593: } else {
10594: $chgtext .= &mt('Processing of requests to create account with e-mail address as username set to: "[_1]"',
10595: $choices{$cancreate{'selfcreateprocessing'}{'default'}});
10596: }
1.165 raeburn 10597: } elsif ($type eq 'captcha') {
1.224 raeburn 10598: if ($savecaptcha{$type} eq 'notused') {
1.165 raeburn 10599: $chgtext .= &mt('No CAPTCHA validation in use for self-creation screen.');
10600: } else {
10601: my %captchas = &captcha_phrases();
1.224 raeburn 10602: if ($captchas{$savecaptcha{$type}}) {
10603: $chgtext .= &mt("Validation for self-creation screen set to $captchas{$savecaptcha{$type}}.");
1.165 raeburn 10604: } else {
1.210 raeburn 10605: $chgtext .= &mt('Validation for self-creation screen set to unknown type.');
1.165 raeburn 10606: }
10607: }
10608: } elsif ($type eq 'recaptchakeys') {
10609: my ($privkey,$pubkey);
1.224 raeburn 10610: if (ref($savecaptcha{$type}) eq 'HASH') {
10611: $pubkey = $savecaptcha{$type}{'public'};
10612: $privkey = $savecaptcha{$type}{'private'};
1.165 raeburn 10613: }
10614: $chgtext .= &mt('ReCAPTCHA keys changes').'<ul>';
10615: if (!$pubkey) {
10616: $chgtext .= '<li>'.&mt('Public key deleted').'</li>';
10617: } else {
10618: $chgtext .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
10619: }
10620: if (!$privkey) {
10621: $chgtext .= '<li>'.&mt('Private key deleted').'</li>';
10622: } else {
10623: $chgtext .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
10624: }
10625: $chgtext .= '</ul>';
1.269 raeburn 10626: } elsif ($type eq 'recaptchaversion') {
10627: if ($savecaptcha{'captcha'} eq 'recaptcha') {
1.270 raeburn 10628: $chgtext .= &mt('ReCAPTCHA set to version [_1]',$savecaptcha{$type});
1.269 raeburn 10629: }
1.224 raeburn 10630: } elsif ($type eq 'emailusername') {
10631: if (ref($cancreate{'emailusername'}) eq 'HASH') {
1.228 raeburn 10632: if (ref($types) eq 'ARRAY') {
10633: foreach my $type (@{$types}) {
10634: if (ref($cancreate{'emailusername'}{$type}) eq 'HASH') {
10635: if (keys(%{$cancreate{'emailusername'}{$type}}) > 0) {
1.245 raeburn 10636: $chgtext .= &mt('When self-creating account with e-mail as username, the following information will be provided by [_1]:',"'$usertypes->{$type}'").
1.228 raeburn 10637: '<ul>';
10638: foreach my $field (@{$infofields}) {
10639: if ($cancreate{'emailusername'}{$type}{$field}) {
10640: $chgtext .= '<li>'.$infotitles->{$field}.'</li>';
10641: }
10642: }
1.245 raeburn 10643: $chgtext .= '</ul>';
10644: } else {
10645: $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 10646: }
10647: } else {
1.245 raeburn 10648: $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 10649: }
10650: }
10651: }
10652: }
10653: } elsif ($type eq 'notify') {
10654: $chgtext = &mt('No Domain Coordinators will receive notification of username requests requiring approval.');
10655: if (ref($changes{'cancreate'}) eq 'ARRAY') {
10656: if ((grep(/^notify$/,@{$changes{'cancreate'}})) && (ref($cancreate{'notify'}) eq 'HASH')) {
10657: if ($cancreate{'notify'}{'approval'}) {
10658: $chgtext = &mt('Notification of username requests requiring approval will be sent to: ').$cancreate{'notify'}{'approval'};
10659: }
10660: }
1.43 raeburn 10661: }
1.34 raeburn 10662: }
1.224 raeburn 10663: if ($chgtext) {
10664: $resulttext .= '<li>'.$chgtext.'</li>';
1.32 raeburn 10665: }
10666: }
10667: }
1.43 raeburn 10668: if (ref($changes{'email_rule'}) eq 'ARRAY') {
10669: my ($emailrules,$emailruleorder) =
10670: &Apache::lonnet::inst_userrules($dom,'email');
10671: my $chgtext = '<ul>';
10672: foreach my $type (@email_rule) {
10673: if (ref($emailrules->{$type}) eq 'HASH') {
10674: $chgtext .= '<li>'.$emailrules->{$type}{'name'}.'</li>';
10675: }
10676: }
10677: $chgtext .= '</ul>';
10678: if (@email_rule > 0) {
1.224 raeburn 10679: $resulttext .= '<li>'.
10680: &mt('Accounts may not be created by users self-enrolling with e-mail addresses of the following types: ').
10681: $chgtext.
10682: '</li>';
1.43 raeburn 10683: } else {
1.224 raeburn 10684: $resulttext .= '<li>'.
10685: &mt('There are now no restrictions on e-mail addresses which may be used as a username when self-enrolling.').
10686: '</li>';
1.43 raeburn 10687: }
10688: }
1.224 raeburn 10689: if (ref($changes{'selfcreate'}) eq 'ARRAY') {
10690: $resulttext .= '<li>'.&mt('When self-creating institutional account:').'<ul>';
10691: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
10692: foreach my $type (@{$changes{'selfcreate'}}) {
10693: my $typename = $type;
10694: if (ref($usertypes) eq 'HASH') {
10695: if ($usertypes->{$type} ne '') {
10696: $typename = $usertypes->{$type};
10697: }
10698: }
10699: my @modifiable;
10700: $resulttext .= '<li>'.
10701: &mt('Self-creation of account by users with status: [_1]',
10702: '<span class="LC_cusr_emph">'.$typename.'</span>').
10703: ' - '.&mt('modifiable fields (if institutional data blank): ');
10704: foreach my $field (@fields) {
10705: if ($save_usermodify{'selfcreate'}{$type}{$field}) {
10706: push(@modifiable,'<b>'.$fieldtitles{$field}.'</b>');
1.28 raeburn 10707: }
10708: }
1.224 raeburn 10709: if (@modifiable > 0) {
10710: $resulttext .= join(', ',@modifiable);
1.43 raeburn 10711: } else {
1.224 raeburn 10712: $resulttext .= &mt('none');
1.43 raeburn 10713: }
1.224 raeburn 10714: $resulttext .= '</li>';
1.28 raeburn 10715: }
1.224 raeburn 10716: $resulttext .= '</ul></li>';
1.28 raeburn 10717: }
1.27 raeburn 10718: $resulttext .= '</ul>';
10719: } else {
1.224 raeburn 10720: $resulttext = &mt('No changes made to self-creation settings');
1.27 raeburn 10721: }
10722: } else {
10723: $resulttext = '<span class="LC_error">'.
1.23 raeburn 10724: &mt('An error occurred: [_1]',$putresult).'</span>';
10725: }
1.43 raeburn 10726: if ($warningmsg ne '') {
10727: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
10728: }
1.23 raeburn 10729: return $resulttext;
10730: }
10731:
1.165 raeburn 10732: sub process_captcha {
10733: my ($container,$changes,$newsettings,$current) = @_;
10734: return unless ((ref($changes) eq 'HASH') && (ref($newsettings) eq 'HASH') || (ref($current) eq 'HASH'));
10735: $newsettings->{'captcha'} = $env{'form.'.$container.'_captcha'};
10736: unless ($newsettings->{'captcha'} eq 'recaptcha' || $newsettings->{'captcha'} eq 'notused') {
10737: $newsettings->{'captcha'} = 'original';
10738: }
10739: if ($current->{'captcha'} ne $newsettings->{'captcha'}) {
1.210 raeburn 10740: if ($container eq 'cancreate') {
1.169 raeburn 10741: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
10742: push(@{$changes->{'cancreate'}},'captcha');
10743: } elsif (!defined($changes->{'cancreate'})) {
10744: $changes->{'cancreate'} = ['captcha'];
10745: }
10746: } else {
10747: $changes->{'captcha'} = 1;
1.165 raeburn 10748: }
10749: }
1.269 raeburn 10750: my ($newpub,$newpriv,$currpub,$currpriv,$newversion,$currversion);
1.165 raeburn 10751: if ($newsettings->{'captcha'} eq 'recaptcha') {
10752: $newpub = $env{'form.'.$container.'_recaptchapub'};
10753: $newpriv = $env{'form.'.$container.'_recaptchapriv'};
1.250 raeburn 10754: $newpub =~ s/[^\w\-]//g;
10755: $newpriv =~ s/[^\w\-]//g;
1.169 raeburn 10756: $newsettings->{'recaptchakeys'} = {
10757: public => $newpub,
10758: private => $newpriv,
10759: };
1.269 raeburn 10760: $newversion = $env{'form.'.$container.'_recaptchaversion'};
10761: $newversion =~ s/\D//g;
10762: if ($newversion ne '2') {
10763: $newversion = 1;
10764: }
10765: $newsettings->{'recaptchaversion'} = $newversion;
1.165 raeburn 10766: }
10767: if (ref($current->{'recaptchakeys'}) eq 'HASH') {
10768: $currpub = $current->{'recaptchakeys'}{'public'};
10769: $currpriv = $current->{'recaptchakeys'}{'private'};
1.179 raeburn 10770: unless ($newsettings->{'captcha'} eq 'recaptcha') {
10771: $newsettings->{'recaptchakeys'} = {
10772: public => '',
10773: private => '',
10774: }
10775: }
1.165 raeburn 10776: }
1.269 raeburn 10777: if ($current->{'captcha'} eq 'recaptcha') {
10778: $currversion = $current->{'recaptchaversion'};
10779: if ($currversion ne '2') {
10780: $currversion = 1;
10781: }
10782: }
10783: if ($currversion ne $newversion) {
10784: if ($container eq 'cancreate') {
10785: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
10786: push(@{$changes->{'cancreate'}},'recaptchaversion');
10787: } elsif (!defined($changes->{'cancreate'})) {
10788: $changes->{'cancreate'} = ['recaptchaversion'];
10789: }
10790: } else {
10791: $changes->{'recaptchaversion'} = 1;
10792: }
10793: }
1.165 raeburn 10794: if (($newpub ne $currpub) || ($newpriv ne $currpriv)) {
1.169 raeburn 10795: if ($container eq 'cancreate') {
10796: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
10797: push(@{$changes->{'cancreate'}},'recaptchakeys');
10798: } elsif (!defined($changes->{'cancreate'})) {
10799: $changes->{'cancreate'} = ['recaptchakeys'];
10800: }
10801: } else {
1.210 raeburn 10802: $changes->{'recaptchakeys'} = 1;
1.165 raeburn 10803: }
10804: }
10805: return;
10806: }
10807:
1.33 raeburn 10808: sub modify_usermodification {
10809: my ($dom,%domconfig) = @_;
1.224 raeburn 10810: my ($resulttext,%curr_usermodification,%changes,%modifyhash);
1.33 raeburn 10811: if (ref($domconfig{'usermodification'}) eq 'HASH') {
10812: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
1.224 raeburn 10813: if ($key eq 'selfcreate') {
10814: $modifyhash{$key} = $domconfig{'usermodification'}{$key};
10815: } else {
10816: $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
10817: }
1.33 raeburn 10818: }
10819: }
1.224 raeburn 10820: my @contexts = ('author','course');
1.33 raeburn 10821: my %context_title = (
10822: author => 'In author context',
10823: course => 'In course context',
10824: );
10825: my @fields = ('lastname','firstname','middlename','generation',
10826: 'permanentemail','id');
10827: my %roles = (
10828: author => ['ca','aa'],
10829: course => ['st','ep','ta','in','cr'],
10830: );
10831: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
10832: foreach my $context (@contexts) {
10833: foreach my $role (@{$roles{$context}}) {
10834: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$role);
10835: foreach my $item (@fields) {
10836: if (grep(/^\Q$item\E$/,@modifiable)) {
10837: $modifyhash{$context}{$role}{$item} = 1;
10838: } else {
10839: $modifyhash{$context}{$role}{$item} = 0;
10840: }
10841: }
10842: }
10843: if (ref($curr_usermodification{$context}) eq 'HASH') {
10844: foreach my $role (@{$roles{$context}}) {
10845: if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
10846: foreach my $field (@fields) {
10847: if ($modifyhash{$context}{$role}{$field} ne
10848: $curr_usermodification{$context}{$role}{$field}) {
10849: push(@{$changes{$context}},$role);
10850: last;
10851: }
10852: }
10853: }
10854: }
10855: } else {
10856: foreach my $context (@contexts) {
10857: foreach my $role (@{$roles{$context}}) {
10858: push(@{$changes{$context}},$role);
10859: }
10860: }
10861: }
10862: }
10863: my %usermodification_hash = (
10864: usermodification => \%modifyhash,
10865: );
10866: my $putresult = &Apache::lonnet::put_dom('configuration',
10867: \%usermodification_hash,$dom);
10868: if ($putresult eq 'ok') {
10869: if (keys(%changes) > 0) {
10870: $resulttext = &mt('Changes made: ').'<ul>';
10871: foreach my $context (@contexts) {
10872: if (ref($changes{$context}) eq 'ARRAY') {
10873: $resulttext .= '<li>'.$context_title{$context}.':<ul>';
10874: if (ref($changes{$context}) eq 'ARRAY') {
10875: foreach my $role (@{$changes{$context}}) {
10876: my $rolename;
1.224 raeburn 10877: if ($role eq 'cr') {
10878: $rolename = &mt('Custom');
1.33 raeburn 10879: } else {
1.224 raeburn 10880: $rolename = &Apache::lonnet::plaintext($role);
1.33 raeburn 10881: }
10882: my @modifiable;
1.224 raeburn 10883: $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
1.33 raeburn 10884: foreach my $field (@fields) {
10885: if ($modifyhash{$context}{$role}{$field}) {
10886: push(@modifiable,$fieldtitles{$field});
10887: }
10888: }
10889: if (@modifiable > 0) {
10890: $resulttext .= join(', ',@modifiable);
10891: } else {
10892: $resulttext .= &mt('none');
10893: }
10894: $resulttext .= '</li>';
10895: }
10896: $resulttext .= '</ul></li>';
10897: }
10898: }
10899: }
10900: $resulttext .= '</ul>';
10901: } else {
10902: $resulttext = &mt('No changes made to user modification settings');
10903: }
10904: } else {
10905: $resulttext = '<span class="LC_error">'.
10906: &mt('An error occurred: [_1]',$putresult).'</span>';
10907: }
10908: return $resulttext;
10909: }
10910:
1.43 raeburn 10911: sub modify_defaults {
1.212 raeburn 10912: my ($dom,$lastactref,%domconfig) = @_;
1.43 raeburn 10913: my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
1.212 raeburn 10914: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.141 raeburn 10915: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def','portal_def');
1.43 raeburn 10916: my @authtypes = ('internal','krb4','krb5','localauth');
10917: foreach my $item (@items) {
10918: $newvalues{$item} = $env{'form.'.$item};
10919: if ($item eq 'auth_def') {
10920: if ($newvalues{$item} ne '') {
10921: if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
10922: push(@errors,$item);
10923: }
10924: }
10925: } elsif ($item eq 'lang_def') {
10926: if ($newvalues{$item} ne '') {
10927: if ($newvalues{$item} =~ /^(\w+)/) {
10928: my $langcode = $1;
1.103 raeburn 10929: if ($langcode ne 'x_chef') {
10930: if (code2language($langcode) eq '') {
10931: push(@errors,$item);
10932: }
1.43 raeburn 10933: }
10934: } else {
10935: push(@errors,$item);
10936: }
10937: }
1.54 raeburn 10938: } elsif ($item eq 'timezone_def') {
10939: if ($newvalues{$item} ne '') {
1.62 raeburn 10940: if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
1.54 raeburn 10941: push(@errors,$item);
10942: }
10943: }
1.68 raeburn 10944: } elsif ($item eq 'datelocale_def') {
10945: if ($newvalues{$item} ne '') {
10946: my @datelocale_ids = DateTime::Locale->ids();
10947: if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
10948: push(@errors,$item);
10949: }
10950: }
1.141 raeburn 10951: } elsif ($item eq 'portal_def') {
10952: if ($newvalues{$item} ne '') {
10953: 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])\/?$/) {
10954: push(@errors,$item);
10955: }
10956: }
1.43 raeburn 10957: }
10958: if (grep(/^\Q$item\E$/,@errors)) {
10959: $newvalues{$item} = $domdefaults{$item};
10960: } elsif ($domdefaults{$item} ne $newvalues{$item}) {
10961: $changes{$item} = 1;
10962: }
1.72 raeburn 10963: $domdefaults{$item} = $newvalues{$item};
1.43 raeburn 10964: }
10965: my %defaults_hash = (
1.72 raeburn 10966: defaults => \%newvalues,
10967: );
1.43 raeburn 10968: my $title = &defaults_titles();
1.236 raeburn 10969:
10970: my $currinststatus;
10971: if (ref($domconfig{'inststatus'}) eq 'HASH') {
10972: $currinststatus = $domconfig{'inststatus'};
10973: } else {
10974: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
10975: $currinststatus = {
10976: inststatustypes => $usertypes,
10977: inststatusorder => $types,
10978: inststatusguest => [],
10979: };
10980: }
10981: my @todelete = &Apache::loncommon::get_env_multiple('form.inststatus_delete');
10982: my @allpos;
10983: my %guests;
10984: my %alltypes;
10985: my ($currtitles,$currguests,$currorder);
10986: if (ref($currinststatus) eq 'HASH') {
10987: if (ref($currinststatus->{'inststatusorder'}) eq 'ARRAY') {
10988: foreach my $type (@{$currinststatus->{'inststatusorder'}}) {
10989: if (ref($currinststatus->{inststatustypes}) eq 'HASH') {
10990: if ($currinststatus->{inststatustypes}->{$type} ne '') {
10991: $currtitles .= $currinststatus->{inststatustypes}->{$type}.',';
10992: }
10993: }
10994: unless (grep(/^\Q$type\E$/,@todelete)) {
10995: my $position = $env{'form.inststatus_pos_'.$type};
10996: $position =~ s/\D+//g;
10997: $allpos[$position] = $type;
10998: $alltypes{$type} = $env{'form.inststatus_title_'.$type};
10999: $alltypes{$type} =~ s/`//g;
11000: if ($env{'form.inststatus_guest_'.$type}) {
11001: $guests{$type} = 1;
11002: }
11003: }
11004: }
11005: if (ref($currinststatus->{'inststatusguest'}) eq 'ARRAY') {
11006: $currguests = join(',',@{$currinststatus->{'inststatusguest'}});
11007: }
11008: $currorder = join(',',@{$currinststatus->{'inststatusorder'}});
11009: $currtitles =~ s/,$//;
11010: }
11011: }
11012: if ($env{'form.addinststatus'}) {
11013: my $newtype = $env{'form.addinststatus'};
11014: $newtype =~ s/\W//g;
11015: unless (exists($alltypes{$newtype})) {
11016: if ($env{'form.addinststatus_guest'}) {
11017: $guests{$newtype} = 1;
11018: }
11019: $alltypes{$newtype} = $env{'form.addinststatus_title'};
11020: $alltypes{$newtype} =~ s/`//g;
11021: my $position = $env{'form.addinststatus_pos'};
11022: $position =~ s/\D+//g;
11023: if ($position ne '') {
11024: $allpos[$position] = $newtype;
11025: }
11026: }
11027: }
11028: my (@orderedstatus,@orderedguests);
11029: foreach my $type (@allpos) {
11030: unless (($type eq '') || (grep(/^\Q$type\E$/,@orderedstatus))) {
11031: push(@orderedstatus,$type);
11032: if ($guests{$type}) {
11033: push(@orderedguests,$type);
11034: }
11035: }
11036: }
11037: foreach my $type (keys(%alltypes)) {
11038: unless (grep(/^\Q$type\E$/,@orderedstatus)) {
11039: delete($alltypes{$type});
11040: }
11041: }
11042: $defaults_hash{'inststatus'} = {
11043: inststatustypes => \%alltypes,
11044: inststatusorder => \@orderedstatus,
11045: inststatusguest => \@orderedguests,
11046: };
11047: if (ref($defaults_hash{'inststatus'}) eq 'HASH') {
11048: foreach my $item ('inststatustypes','inststatusorder','inststatusguest') {
11049: $domdefaults{$item} = $defaults_hash{'inststatus'}{$item};
11050: }
11051: }
11052: if ($currorder ne join(',',@orderedstatus)) {
11053: $changes{'inststatus'}{'inststatusorder'} = 1;
11054: }
11055: if ($currguests ne join(',',@orderedguests)) {
11056: $changes{'inststatus'}{'inststatusguest'} = 1;
11057: }
11058: my $newtitles;
11059: foreach my $item (@orderedstatus) {
11060: $newtitles .= $alltypes{$item}.',';
11061: }
11062: $newtitles =~ s/,$//;
11063: if ($currtitles ne $newtitles) {
11064: $changes{'inststatus'}{'inststatustypes'} = 1;
11065: }
1.43 raeburn 11066: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
11067: $dom);
11068: if ($putresult eq 'ok') {
11069: if (keys(%changes) > 0) {
11070: $resulttext = &mt('Changes made:').'<ul>';
1.212 raeburn 11071: my $version = &Apache::lonnet::get_server_loncaparev($dom);
1.43 raeburn 11072: 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";
11073: foreach my $item (sort(keys(%changes))) {
1.236 raeburn 11074: if ($item eq 'inststatus') {
11075: if (ref($changes{'inststatus'}) eq 'HASH') {
11076: if (($changes{'inststatus'}{'inststatustypes'}) || $changes{'inststatus'}{'inststatusorder'}) {
11077: $resulttext .= '<li>'.&mt('Institutional user status types set to:').' ';
11078: foreach my $type (@orderedstatus) {
11079: $resulttext .= $alltypes{$type}.', ';
11080: }
11081: $resulttext =~ s/, $//;
11082: $resulttext .= '</li>';
11083: }
11084: if ($changes{'inststatus'}{'inststatusguest'}) {
11085: $resulttext .= '<li>';
11086: if (@orderedguests) {
11087: $resulttext .= &mt('Types assignable to "non-institutional" usernames set to:').' ';
11088: foreach my $type (@orderedguests) {
11089: $resulttext .= $alltypes{$type}.', ';
11090: }
11091: $resulttext =~ s/, $//;
11092: } else {
11093: $resulttext .= &mt('Types assignable to "non-institutional" usernames set to none.');
11094: }
11095: $resulttext .= '</li>';
11096: }
11097: }
11098: } else {
11099: my $value = $env{'form.'.$item};
11100: if ($value eq '') {
11101: $value = &mt('none');
11102: } elsif ($item eq 'auth_def') {
11103: my %authnames = &authtype_names();
11104: my %shortauth = (
11105: internal => 'int',
11106: krb4 => 'krb4',
11107: krb5 => 'krb5',
11108: localauth => 'loc',
11109: );
11110: $value = $authnames{$shortauth{$value}};
11111: }
11112: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
11113: $mailmsgtext .= "$title->{$item} set to $value\n";
1.43 raeburn 11114: }
11115: }
11116: $resulttext .= '</ul>';
11117: $mailmsgtext .= "\n";
11118: my $cachetime = 24*60*60;
1.72 raeburn 11119: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 11120: if (ref($lastactref) eq 'HASH') {
11121: $lastactref->{'domdefaults'} = 1;
11122: }
1.68 raeburn 11123: if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
1.203 raeburn 11124: my $notify = 1;
11125: if (ref($domconfig{'contacts'}) eq 'HASH') {
11126: if ($domconfig{'contacts'}{'reportupdates'} == 0) {
11127: $notify = 0;
11128: }
11129: }
11130: if ($notify) {
11131: &Apache::lonmsg::sendemail('installrecord@loncapa.org',
11132: "LON-CAPA Domain Settings Change - $dom",
11133: $mailmsgtext);
11134: }
1.54 raeburn 11135: }
1.43 raeburn 11136: } else {
1.54 raeburn 11137: $resulttext = &mt('No changes made to default authentication/language/timezone settings');
1.43 raeburn 11138: }
11139: } else {
11140: $resulttext = '<span class="LC_error">'.
11141: &mt('An error occurred: [_1]',$putresult).'</span>';
11142: }
11143: if (@errors > 0) {
11144: $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
11145: foreach my $item (@errors) {
11146: $resulttext .= ' "'.$title->{$item}.'",';
11147: }
11148: $resulttext =~ s/,$//;
11149: }
11150: return $resulttext;
11151: }
11152:
1.46 raeburn 11153: sub modify_scantron {
1.205 raeburn 11154: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.46 raeburn 11155: my ($resulttext,%confhash,%changes,$errors);
11156: my $custom = 'custom.tab';
11157: my $default = 'default.tab';
11158: my $servadm = $r->dir_config('lonAdmEMail');
11159: my ($configuserok,$author_ok,$switchserver) =
11160: &config_check($dom,$confname,$servadm);
11161: if ($env{'form.scantronformat.filename'} ne '') {
11162: my $error;
11163: if ($configuserok eq 'ok') {
11164: if ($switchserver) {
1.130 raeburn 11165: $error = &mt("Upload of bubblesheet format file is not permitted to this server: [_1]",$switchserver);
1.46 raeburn 11166: } else {
11167: if ($author_ok eq 'ok') {
11168: my ($result,$scantronurl) =
11169: &publishlogo($r,'upload','scantronformat',$dom,
11170: $confname,'scantron','','',$custom);
11171: if ($result eq 'ok') {
11172: $confhash{'scantron'}{'scantronformat'} = $scantronurl;
1.48 raeburn 11173: $changes{'scantronformat'} = 1;
1.46 raeburn 11174: } else {
11175: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
11176: }
11177: } else {
11178: $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);
11179: }
11180: }
11181: } else {
11182: $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);
11183: }
11184: if ($error) {
11185: &Apache::lonnet::logthis($error);
11186: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
11187: }
11188: }
1.48 raeburn 11189: if (ref($domconfig{'scantron'}) eq 'HASH') {
11190: if ($domconfig{'scantron'}{'scantronformat'} ne '') {
11191: if ($env{'form.scantronformat_del'}) {
11192: $confhash{'scantron'}{'scantronformat'} = '';
11193: $changes{'scantronformat'} = 1;
1.46 raeburn 11194: }
11195: }
11196: }
11197: if (keys(%confhash) > 0) {
11198: my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
11199: $dom);
11200: if ($putresult eq 'ok') {
11201: if (keys(%changes) > 0) {
1.48 raeburn 11202: if (ref($confhash{'scantron'}) eq 'HASH') {
11203: $resulttext = &mt('Changes made:').'<ul>';
11204: if ($confhash{'scantron'}{'scantronformat'} eq '') {
1.130 raeburn 11205: $resulttext .= '<li>'.&mt('[_1] bubblesheet format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
1.48 raeburn 11206: } else {
1.130 raeburn 11207: $resulttext .= '<li>'.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
1.46 raeburn 11208: }
1.48 raeburn 11209: $resulttext .= '</ul>';
11210: } else {
1.130 raeburn 11211: $resulttext = &mt('Changes made to bubblesheet format file.');
1.46 raeburn 11212: }
11213: $resulttext .= '</ul>';
11214: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 11215: if (ref($lastactref) eq 'HASH') {
11216: $lastactref->{'domainconfig'} = 1;
11217: }
1.46 raeburn 11218: } else {
1.130 raeburn 11219: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 11220: }
11221: } else {
11222: $resulttext = '<span class="LC_error">'.
11223: &mt('An error occurred: [_1]',$putresult).'</span>';
11224: }
11225: } else {
1.130 raeburn 11226: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 11227: }
11228: if ($errors) {
11229: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
11230: $errors.'</ul>';
11231: }
11232: return $resulttext;
11233: }
11234:
1.48 raeburn 11235: sub modify_coursecategories {
1.239 raeburn 11236: my ($dom,$lastactref,%domconfig) = @_;
1.57 raeburn 11237: my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
11238: $cathash);
1.48 raeburn 11239: my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
1.238 raeburn 11240: my @catitems = ('unauth','auth');
11241: my @cattypes = ('std','domonly','codesrch','none');
1.55 raeburn 11242: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
1.57 raeburn 11243: $cathash = $domconfig{'coursecategories'}{'cats'};
11244: if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
11245: $changes{'togglecats'} = 1;
11246: $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
11247: }
11248: if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
11249: $changes{'categorize'} = 1;
11250: $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
11251: }
1.120 raeburn 11252: if ($domconfig{'coursecategories'}{'togglecatscomm'} ne $env{'form.togglecatscomm'}) {
11253: $changes{'togglecatscomm'} = 1;
11254: $domconfig{'coursecategories'}{'togglecatscomm'} = $env{'form.togglecatscomm'};
11255: }
11256: if ($domconfig{'coursecategories'}{'categorizecomm'} ne $env{'form.categorizecomm'}) {
11257: $changes{'categorizecomm'} = 1;
11258: $domconfig{'coursecategories'}{'categorizecomm'} = $env{'form.categorizecomm'};
1.272 raeburn 11259:
11260: }
11261: if ($domconfig{'coursecategories'}{'togglecatsplace'} ne $env{'form.togglecatsplace'}) {
11262: $changes{'togglecatsplace'} = 1;
11263: $domconfig{'coursecategories'}{'togglecatsplace'} = $env{'form.togglecatsplace'};
11264: }
11265: if ($domconfig{'coursecategories'}{'categorizeplace'} ne $env{'form.categorizeplace'}) {
11266: $changes{'categorizeplace'} = 1;
11267: $domconfig{'coursecategories'}{'categorizeplace'} = $env{'form.categorizeplace'};
1.120 raeburn 11268: }
1.238 raeburn 11269: foreach my $item (@catitems) {
11270: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
11271: if ($domconfig{'coursecategories'}{$item} ne $env{'form.coursecat_'.$item}) {
11272: $changes{$item} = 1;
11273: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
11274: }
11275: }
11276: }
1.57 raeburn 11277: } else {
11278: $changes{'togglecats'} = 1;
11279: $changes{'categorize'} = 1;
1.124 raeburn 11280: $changes{'togglecatscomm'} = 1;
11281: $changes{'categorizecomm'} = 1;
1.272 raeburn 11282: $changes{'togglecatsplace'} = 1;
11283: $changes{'categorizeplace'} = 1;
1.87 raeburn 11284: $domconfig{'coursecategories'} = {
11285: togglecats => $env{'form.togglecats'},
11286: categorize => $env{'form.categorize'},
1.124 raeburn 11287: togglecatscomm => $env{'form.togglecatscomm'},
11288: categorizecomm => $env{'form.categorizecomm'},
1.272 raeburn 11289: togglecatsplace => $env{'form.togglecatsplace'},
11290: categorizeplace => $env{'form.categorizeplace'},
1.120 raeburn 11291: };
1.238 raeburn 11292: foreach my $item (@catitems) {
11293: if ($env{'form.coursecat_'.$item} ne 'std') {
11294: $changes{$item} = 1;
11295: }
11296: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
11297: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
11298: }
11299: }
1.57 raeburn 11300: }
11301: if (ref($cathash) eq 'HASH') {
11302: if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '') && ($env{'form.instcode'} == 0)) {
1.55 raeburn 11303: push (@deletecategory,'instcode::0');
11304: }
1.120 raeburn 11305: if (($domconfig{'coursecategories'}{'cats'}{'communities::0'} ne '') && ($env{'form.communities'} == 0)) {
11306: push(@deletecategory,'communities::0');
11307: }
1.272 raeburn 11308: if (($domconfig{'coursecategories'}{'cats'}{'placement::0'} ne '') && ($env{'form.placement'} == 0)) {
11309: push(@deletecategory,'placement::0');
11310: }
1.48 raeburn 11311: }
1.57 raeburn 11312: my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
11313: if (ref($cathash) eq 'HASH') {
1.48 raeburn 11314: if (@deletecategory > 0) {
11315: #FIXME Need to remove category from all courses using a deleted category
1.57 raeburn 11316: &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
1.48 raeburn 11317: foreach my $item (@deletecategory) {
1.57 raeburn 11318: if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
11319: delete($domconfig{'coursecategories'}{'cats'}{$item});
1.48 raeburn 11320: $deletions{$item} = 1;
1.57 raeburn 11321: &recurse_cat_deletes($item,$cathash,\%deletions);
1.48 raeburn 11322: }
11323: }
11324: }
1.57 raeburn 11325: foreach my $item (keys(%{$cathash})) {
1.48 raeburn 11326: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
1.57 raeburn 11327: if ($cathash->{$item} ne $env{'form.'.$item}) {
1.48 raeburn 11328: $reorderings{$item} = 1;
1.57 raeburn 11329: $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
1.48 raeburn 11330: }
11331: if ($env{'form.addcategory_name_'.$item} ne '') {
11332: my $newcat = $env{'form.addcategory_name_'.$item};
11333: my $newdepth = $depth+1;
11334: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 11335: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
1.48 raeburn 11336: $adds{$newitem} = 1;
11337: }
11338: if ($env{'form.subcat_'.$item} ne '') {
11339: my $newcat = $env{'form.subcat_'.$item};
11340: my $newdepth = $depth+1;
11341: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 11342: $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
1.48 raeburn 11343: $adds{$newitem} = 1;
11344: }
11345: }
11346: }
11347: if ($env{'form.instcode'} eq '1') {
1.57 raeburn 11348: if (ref($cathash) eq 'HASH') {
1.48 raeburn 11349: my $newitem = 'instcode::0';
1.57 raeburn 11350: if ($cathash->{$newitem} eq '') {
11351: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 11352: $adds{$newitem} = 1;
11353: }
11354: } else {
11355: my $newitem = 'instcode::0';
1.57 raeburn 11356: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 11357: $adds{$newitem} = 1;
11358: }
11359: }
1.120 raeburn 11360: if ($env{'form.communities'} eq '1') {
11361: if (ref($cathash) eq 'HASH') {
11362: my $newitem = 'communities::0';
11363: if ($cathash->{$newitem} eq '') {
11364: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
11365: $adds{$newitem} = 1;
11366: }
11367: } else {
11368: my $newitem = 'communities::0';
11369: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
11370: $adds{$newitem} = 1;
11371: }
11372: }
1.272 raeburn 11373: if ($env{'form.placement'} eq '1') {
11374: if (ref($cathash) eq 'HASH') {
11375: my $newitem = 'placement::0';
11376: if ($cathash->{$newitem} eq '') {
11377: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.placement_pos'};
11378: $adds{$newitem} = 1;
11379: }
11380: } else {
11381: my $newitem = 'placement::0';
11382: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.placement_pos'};
11383: $adds{$newitem} = 1;
11384: }
11385: }
1.48 raeburn 11386: if ($env{'form.addcategory_name'} ne '') {
1.120 raeburn 11387: if (($env{'form.addcategory_name'} ne 'instcode') &&
1.272 raeburn 11388: ($env{'form.addcategory_name'} ne 'communities') &&
11389: ($env{'form.addcategory_name'} ne 'placement')) {
1.120 raeburn 11390: my $newitem = &escape($env{'form.addcategory_name'}).'::0';
11391: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
11392: $adds{$newitem} = 1;
11393: }
1.48 raeburn 11394: }
1.57 raeburn 11395: my $putresult;
1.48 raeburn 11396: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
11397: if (keys(%deletions) > 0) {
11398: foreach my $key (keys(%deletions)) {
11399: if ($predelallitems{$key} ne '') {
11400: $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
11401: }
11402: }
11403: }
11404: my (@chkcats,@chktrails,%chkallitems);
1.57 raeburn 11405: &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
1.48 raeburn 11406: if (ref($chkcats[0]) eq 'ARRAY') {
11407: my $depth = 0;
11408: my $chg = 0;
11409: for (my $i=0; $i<@{$chkcats[0]}; $i++) {
11410: my $name = $chkcats[0][$i];
11411: my $item;
11412: if ($name eq '') {
11413: $chg ++;
11414: } else {
11415: $item = &escape($name).'::0';
11416: if ($chg) {
1.57 raeburn 11417: $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
1.48 raeburn 11418: }
11419: $depth ++;
1.57 raeburn 11420: &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
1.48 raeburn 11421: $depth --;
11422: }
11423: }
11424: }
1.57 raeburn 11425: }
11426: if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
11427: $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
1.48 raeburn 11428: if ($putresult eq 'ok') {
1.57 raeburn 11429: my %title = (
1.120 raeburn 11430: togglecats => 'Show/Hide a course in catalog',
11431: categorize => 'Assign a category to a course',
11432: togglecatscomm => 'Show/Hide a community in catalog',
11433: categorizecomm => 'Assign a category to a community',
1.57 raeburn 11434: );
11435: my %level = (
1.120 raeburn 11436: dom => 'set in Domain ("Modify Course/Community")',
11437: crs => 'set in Course ("Course Configuration")',
11438: comm => 'set in Community ("Community Configuration")',
1.238 raeburn 11439: none => 'No catalog',
11440: std => 'Standard catalog',
11441: domonly => 'Domain-only catalog',
11442: codesrch => 'Code search form',
1.57 raeburn 11443: );
1.48 raeburn 11444: $resulttext = &mt('Changes made:').'<ul>';
1.57 raeburn 11445: if ($changes{'togglecats'}) {
11446: $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>';
11447: }
11448: if ($changes{'categorize'}) {
11449: $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
1.48 raeburn 11450: }
1.120 raeburn 11451: if ($changes{'togglecatscomm'}) {
11452: $resulttext .= '<li>'.&mt("$title{'togglecatscomm'} $level{$env{'form.togglecatscomm'}}").'</li>';
11453: }
11454: if ($changes{'categorizecomm'}) {
11455: $resulttext .= '<li>'.&mt("$title{'categorizecomm'} $level{$env{'form.categorizecomm'}}").'</li>';
11456: }
1.238 raeburn 11457: if ($changes{'unauth'}) {
11458: $resulttext .= '<li>'.&mt('Catalog type for unauthenticated users set to "'.$level{$env{'form.coursecat_unauth'}}.'"').'</li>';
11459: }
11460: if ($changes{'auth'}) {
11461: $resulttext .= '<li>'.&mt('Catalog type for authenticated users set to "'.$level{$env{'form.coursecat_auth'}}.'"').'</li>';
11462: }
1.57 raeburn 11463: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
11464: my $cathash;
11465: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
11466: $cathash = $domconfig{'coursecategories'}{'cats'};
11467: } else {
11468: $cathash = {};
11469: }
11470: my (@cats,@trails,%allitems);
11471: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
11472: if (keys(%deletions) > 0) {
11473: $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
11474: foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) {
11475: $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
11476: }
11477: $resulttext .= '</ul></li>';
11478: }
11479: if (keys(%reorderings) > 0) {
11480: my %sort_by_trail;
11481: $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
11482: foreach my $key (keys(%reorderings)) {
11483: if ($allitems{$key} ne '') {
11484: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
11485: }
1.48 raeburn 11486: }
1.57 raeburn 11487: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
11488: $resulttext .= '<li>'.$trails[$trail].'</li>';
11489: }
11490: $resulttext .= '</ul></li>';
1.48 raeburn 11491: }
1.57 raeburn 11492: if (keys(%adds) > 0) {
11493: my %sort_by_trail;
11494: $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
11495: foreach my $key (keys(%adds)) {
11496: if ($allitems{$key} ne '') {
11497: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
11498: }
11499: }
11500: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
11501: $resulttext .= '<li>'.$trails[$trail].'</li>';
1.48 raeburn 11502: }
1.57 raeburn 11503: $resulttext .= '</ul></li>';
1.48 raeburn 11504: }
11505: }
11506: $resulttext .= '</ul>';
1.239 raeburn 11507: if ($changes{'unauth'} || $changes{'auth'}) {
1.246 raeburn 11508: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
11509: if ($changes{'auth'}) {
11510: $domdefaults{'catauth'} = $domconfig{'coursecategories'}{'auth'};
11511: }
11512: if ($changes{'unauth'}) {
11513: $domdefaults{'catunauth'} = $domconfig{'coursecategories'}{'unauth'};
11514: }
11515: my $cachetime = 24*60*60;
11516: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.239 raeburn 11517: if (ref($lastactref) eq 'HASH') {
1.246 raeburn 11518: $lastactref->{'domdefaults'} = 1;
1.239 raeburn 11519: }
11520: }
1.48 raeburn 11521: } else {
11522: $resulttext = '<span class="LC_error">'.
1.57 raeburn 11523: &mt('An error occurred: [_1]',$putresult).'</span>';
1.48 raeburn 11524: }
11525: } else {
1.120 raeburn 11526: $resulttext = &mt('No changes made to course and community categories');
1.48 raeburn 11527: }
11528: return $resulttext;
11529: }
11530:
1.69 raeburn 11531: sub modify_serverstatuses {
11532: my ($dom,%domconfig) = @_;
11533: my ($resulttext,%changes,%currserverstatus,%newserverstatus);
11534: if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
11535: %currserverstatus = %{$domconfig{'serverstatuses'}};
11536: }
11537: my @pages = &serverstatus_pages();
11538: foreach my $type (@pages) {
11539: $newserverstatus{$type}{'namedusers'} = '';
11540: $newserverstatus{$type}{'machines'} = '';
11541: if (defined($env{'form.'.$type.'_namedusers'})) {
11542: my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
11543: my @okusers;
11544: foreach my $user (@users) {
11545: my ($uname,$udom) = split(/:/,$user);
11546: if (($udom =~ /^$match_domain$/) &&
11547: (&Apache::lonnet::domain($udom)) &&
11548: ($uname =~ /^$match_username$/)) {
11549: if (!grep(/^\Q$user\E/,@okusers)) {
11550: push(@okusers,$user);
11551: }
11552: }
11553: }
11554: if (@okusers > 0) {
11555: @okusers = sort(@okusers);
11556: $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
11557: }
11558: }
11559: if (defined($env{'form.'.$type.'_machines'})) {
11560: my @machines = split(/,/,$env{'form.'.$type.'_machines'});
11561: my @okmachines;
11562: foreach my $ip (@machines) {
11563: my @parts = split(/\./,$ip);
11564: next if (@parts < 4);
11565: my $badip = 0;
11566: for (my $i=0; $i<4; $i++) {
11567: if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
11568: $badip = 1;
11569: last;
11570: }
11571: }
11572: if (!$badip) {
11573: push(@okmachines,$ip);
11574: }
11575: }
11576: @okmachines = sort(@okmachines);
11577: $newserverstatus{$type}{'machines'} = join(',',@okmachines);
11578: }
11579: }
11580: my %serverstatushash = (
11581: serverstatuses => \%newserverstatus,
11582: );
11583: foreach my $type (@pages) {
1.83 raeburn 11584: foreach my $setting ('namedusers','machines') {
1.84 raeburn 11585: my (@current,@new);
1.83 raeburn 11586: if (ref($currserverstatus{$type}) eq 'HASH') {
1.84 raeburn 11587: if ($currserverstatus{$type}{$setting} ne '') {
11588: @current = split(/,/,$currserverstatus{$type}{$setting});
11589: }
11590: }
11591: if ($newserverstatus{$type}{$setting} ne '') {
11592: @new = split(/,/,$newserverstatus{$type}{$setting});
1.83 raeburn 11593: }
11594: if (@current > 0) {
11595: if (@new > 0) {
11596: foreach my $item (@current) {
11597: if (!grep(/^\Q$item\E$/,@new)) {
11598: $changes{$type}{$setting} = 1;
1.82 raeburn 11599: last;
11600: }
11601: }
1.84 raeburn 11602: foreach my $item (@new) {
11603: if (!grep(/^\Q$item\E$/,@current)) {
11604: $changes{$type}{$setting} = 1;
11605: last;
1.82 raeburn 11606: }
11607: }
11608: } else {
1.83 raeburn 11609: $changes{$type}{$setting} = 1;
1.69 raeburn 11610: }
1.83 raeburn 11611: } elsif (@new > 0) {
11612: $changes{$type}{$setting} = 1;
1.69 raeburn 11613: }
11614: }
11615: }
11616: if (keys(%changes) > 0) {
1.81 raeburn 11617: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 11618: my $putresult = &Apache::lonnet::put_dom('configuration',
11619: \%serverstatushash,$dom);
11620: if ($putresult eq 'ok') {
11621: $resulttext .= &mt('Changes made:').'<ul>';
11622: foreach my $type (@pages) {
1.84 raeburn 11623: if (ref($changes{$type}) eq 'HASH') {
1.69 raeburn 11624: $resulttext .= '<li>'.$titles->{$type}.'<ul>';
1.84 raeburn 11625: if ($changes{$type}{'namedusers'}) {
1.69 raeburn 11626: if ($newserverstatus{$type}{'namedusers'} eq '') {
11627: $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n";
11628: } else {
11629: $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n";
11630: }
1.84 raeburn 11631: }
11632: if ($changes{$type}{'machines'}) {
1.69 raeburn 11633: if ($newserverstatus{$type}{'machines'} eq '') {
11634: $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n";
11635: } else {
11636: $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n";
11637: }
11638:
11639: }
11640: $resulttext .= '</ul></li>';
11641: }
11642: }
11643: $resulttext .= '</ul>';
11644: } else {
11645: $resulttext = '<span class="LC_error">'.
11646: &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>';
11647:
11648: }
11649: } else {
11650: $resulttext = &mt('No changes made to access to server status pages');
11651: }
11652: return $resulttext;
11653: }
11654:
1.118 jms 11655: sub modify_helpsettings {
1.122 jms 11656: my ($r,$dom,$confname,%domconfig) = @_;
1.166 raeburn 11657: my ($resulttext,$errors,%changes,%helphash);
11658: my %defaultchecked = ('submitbugs' => 'on');
11659: my @offon = ('off','on');
1.118 jms 11660: my @toggles = ('submitbugs');
11661: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
11662: foreach my $item (@toggles) {
1.166 raeburn 11663: if ($defaultchecked{$item} eq 'on') {
11664: if ($domconfig{'helpsettings'}{$item} eq '') {
11665: if ($env{'form.'.$item} eq '0') {
11666: $changes{$item} = 1;
11667: }
11668: } elsif ($domconfig{'helpsettings'}{$item} ne $env{'form.'.$item}) {
11669: $changes{$item} = 1;
11670: }
11671: } elsif ($defaultchecked{$item} eq 'off') {
11672: if ($domconfig{'helpsettings'}{$item} eq '') {
11673: if ($env{'form.'.$item} eq '1') {
11674: $changes{$item} = 1;
11675: }
11676: } elsif ($domconfig{'helpsettings'}{$item} ne $env{'form.'.$item}) {
11677: $changes{$item} = 1;
11678: }
11679: }
1.210 raeburn 11680: if (($env{'form.'.$item} eq '0') || ($env{'form.'.$item} eq '1')) {
1.166 raeburn 11681: $helphash{'helpsettings'}{$item} = $env{'form.'.$item};
11682: }
11683: }
1.118 jms 11684: }
1.123 jms 11685: my $putresult;
11686: if (keys(%changes) > 0) {
1.166 raeburn 11687: $putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom);
1.168 raeburn 11688: if ($putresult eq 'ok') {
1.166 raeburn 11689: $resulttext = &mt('Changes made:').'<ul>';
11690: foreach my $item (sort(keys(%changes))) {
11691: if ($item eq 'submitbugs') {
11692: $resulttext .= '<li>'.&mt('Display link to: [_1] set to "'.$offon[$env{'form.'.$item}].'".',
11693: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
11694: &mt('LON-CAPA bug tracker'),600,500)).'</li>';
11695: }
11696: }
11697: $resulttext .= '</ul>';
11698: } else {
11699: $resulttext = &mt('No changes made to help settings');
1.168 raeburn 11700: $errors .= '<li><span class="LC_error">'.
11701: &mt('An error occurred storing the settings: [_1]',
11702: $putresult).'</span></li>';
1.166 raeburn 11703: }
1.118 jms 11704: }
11705: if ($errors) {
1.168 raeburn 11706: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.118 jms 11707: $errors.'</ul>';
11708: }
11709: return $resulttext;
11710: }
11711:
1.121 raeburn 11712: sub modify_coursedefaults {
1.212 raeburn 11713: my ($dom,$lastactref,%domconfig) = @_;
1.121 raeburn 11714: my ($resulttext,$errors,%changes,%defaultshash);
1.257 raeburn 11715: my %defaultchecked = (
11716: 'canuse_pdfforms' => 'off',
11717: 'uselcmath' => 'on',
11718: 'usejsme' => 'on'
11719: );
11720: my @toggles = ('canuse_pdfforms','uselcmath','usejsme');
1.198 raeburn 11721: my @numbers = ('anonsurvey_threshold','uploadquota_official','uploadquota_unofficial',
1.276 raeburn 11722: 'uploadquota_community','uploadquota_textbook','uploadquota_placement',
11723: 'mysqltables_official','mysqltables_unofficial','mysqltables_community',
11724: 'mysqltables_textbook','mysqltables_placement');
1.271 raeburn 11725: my @types = ('official','unofficial','community','textbook','placement');
1.198 raeburn 11726: my %staticdefaults = (
11727: anonsurvey_threshold => 10,
11728: uploadquota => 500,
1.257 raeburn 11729: postsubmit => 60,
1.276 raeburn 11730: mysqltables => 172800,
1.198 raeburn 11731: );
1.121 raeburn 11732:
11733: $defaultshash{'coursedefaults'} = {};
11734:
11735: if (ref($domconfig{'coursedefaults'}) ne 'HASH') {
11736: if ($domconfig{'coursedefaults'} eq '') {
11737: $domconfig{'coursedefaults'} = {};
11738: }
11739: }
11740:
11741: if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
11742: foreach my $item (@toggles) {
11743: if ($defaultchecked{$item} eq 'on') {
11744: if (($domconfig{'coursedefaults'}{$item} eq '') &&
11745: ($env{'form.'.$item} eq '0')) {
11746: $changes{$item} = 1;
1.192 raeburn 11747: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
1.121 raeburn 11748: $changes{$item} = 1;
11749: }
11750: } elsif ($defaultchecked{$item} eq 'off') {
11751: if (($domconfig{'coursedefaults'}{$item} eq '') &&
11752: ($env{'form.'.$item} eq '1')) {
11753: $changes{$item} = 1;
11754: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
11755: $changes{$item} = 1;
11756: }
11757: }
11758: $defaultshash{'coursedefaults'}{$item} = $env{'form.'.$item};
11759: }
1.198 raeburn 11760: foreach my $item (@numbers) {
11761: my ($currdef,$newdef);
1.208 raeburn 11762: $newdef = $env{'form.'.$item};
1.198 raeburn 11763: if ($item eq 'anonsurvey_threshold') {
11764: $currdef = $domconfig{'coursedefaults'}{$item};
11765: $newdef =~ s/\D//g;
11766: if ($newdef eq '' || $newdef < 1) {
11767: $newdef = 1;
11768: }
11769: $defaultshash{'coursedefaults'}{$item} = $newdef;
11770: } else {
1.276 raeburn 11771: my ($setting,$type) = ($item =~ /^(uploadquota|mysqltables)_(\w+)$/);
11772: if (ref($domconfig{'coursedefaults'}{$setting}) eq 'HASH') {
11773: $currdef = $domconfig{'coursedefaults'}{$setting}{$type};
1.198 raeburn 11774: }
11775: $newdef =~ s/[^\w.\-]//g;
1.276 raeburn 11776: $defaultshash{'coursedefaults'}{$setting}{$type} = $newdef;
1.198 raeburn 11777: }
11778: if ($currdef ne $newdef) {
11779: my $staticdef;
11780: if ($item eq 'anonsurvey_threshold') {
11781: unless (($currdef eq '') && ($newdef == $staticdefaults{$item})) {
11782: $changes{$item} = 1;
11783: }
1.276 raeburn 11784: } elsif ($item =~ /^(uploadquota|mysqltables)_/) {
11785: my $setting = $1;
11786: unless (($currdef eq '') && ($newdef == $staticdefaults{$setting})) {
11787: $changes{$setting} = 1;
1.198 raeburn 11788: }
11789: }
1.139 raeburn 11790: }
11791: }
1.264 raeburn 11792: my $currclone = $domconfig{'coursedefaults'}{'canclone'};
11793: my @currclonecode;
11794: if (ref($currclone) eq 'HASH') {
11795: if (ref($currclone->{'instcode'}) eq 'ARRAY') {
11796: @currclonecode = @{$currclone->{'instcode'}};
11797: }
11798: }
11799: my $newclone;
11800: if ($env{'form.canclone'} =~ /^(none|domain|instcode)$/) {
11801: $newclone = $env{'form.canclone'};
11802: }
11803: if ($newclone eq 'instcode') {
11804: my @newcodes = &Apache::loncommon::get_env_multiple('form.clonecode');
11805: my (%codedefaults,@code_order,@clonecode);
11806: &Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
11807: \@code_order);
11808: foreach my $item (@code_order) {
11809: if (grep(/^\Q$item\E$/,@newcodes)) {
11810: push(@clonecode,$item);
11811: }
11812: }
11813: if (@clonecode) {
11814: $defaultshash{'coursedefaults'}{'canclone'} = { $newclone => \@clonecode };
11815: my @diffs = &Apache::loncommon::compare_arrays(\@currclonecode,\@clonecode);
11816: if (@diffs) {
11817: $changes{'canclone'} = 1;
11818: }
11819: } else {
11820: $newclone eq '';
11821: }
11822: } elsif ($newclone ne '') {
11823: $defaultshash{'coursedefaults'}{'canclone'} = $newclone;
11824: }
11825: if ($newclone ne $currclone) {
11826: $changes{'canclone'} = 1;
11827: }
1.257 raeburn 11828: my %credits;
11829: foreach my $type (@types) {
11830: unless ($type eq 'community') {
11831: $credits{$type} = $env{'form.'.$type.'_credits'};
11832: $credits{$type} =~ s/[^\d.]+//g;
11833: }
11834: }
11835: if ((ref($domconfig{'coursedefaults'}{'coursecredits'}) ne 'HASH') &&
11836: ($env{'form.coursecredits'} eq '1')) {
11837: $changes{'coursecredits'} = 1;
11838: foreach my $type (keys(%credits)) {
11839: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
11840: }
11841: } else {
11842: if ($env{'form.coursecredits'} eq '1') {
11843: foreach my $type (@types) {
11844: unless ($type eq 'community') {
11845: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type} ne $credits{$type}) {
11846: $changes{'coursecredits'} = 1;
11847: }
11848: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
11849: }
11850: }
11851: } elsif (ref($domconfig{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
11852: foreach my $type (@types) {
11853: unless ($type eq 'community') {
11854: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type}) {
11855: $changes{'coursecredits'} = 1;
11856: last;
11857: }
11858: }
11859: }
11860: }
11861: }
11862: if ($env{'form.postsubmit'} eq '1') {
11863: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'on';
11864: my %currtimeout;
11865: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
11866: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'off') {
11867: $changes{'postsubmit'} = 1;
11868: }
11869: if (ref($domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
11870: %currtimeout = %{$domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}};
11871: }
11872: } else {
11873: $changes{'postsubmit'} = 1;
11874: }
11875: foreach my $type (@types) {
11876: my $timeout = $env{'form.'.$type.'_timeout'};
11877: $timeout =~ s/\D//g;
11878: if ($timeout == $staticdefaults{'postsubmit'}) {
11879: $timeout = '';
11880: } elsif (($timeout eq '') || ($timeout =~ /^0+$/)) {
11881: $timeout = '0';
11882: }
11883: unless ($timeout eq '') {
11884: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type} = $timeout;
11885: }
11886: if (exists($currtimeout{$type})) {
11887: if ($timeout ne $currtimeout{$type}) {
11888: $changes{'postsubmit'} = 1;
11889: }
11890: } elsif ($timeout ne '') {
11891: $changes{'postsubmit'} = 1;
11892: }
11893: }
11894: } else {
11895: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'off';
11896: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
11897: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'on') {
11898: $changes{'postsubmit'} = 1;
11899: }
11900: } else {
11901: $changes{'postsubmit'} = 1;
11902: }
1.192 raeburn 11903: }
1.121 raeburn 11904: }
11905: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
11906: $dom);
11907: if ($putresult eq 'ok') {
11908: if (keys(%changes) > 0) {
1.213 raeburn 11909: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.257 raeburn 11910: if (($changes{'canuse_pdfforms'}) || ($changes{'uploadquota'}) || ($changes{'postsubmit'}) ||
1.264 raeburn 11911: ($changes{'coursecredits'}) || ($changes{'uselcmath'}) || ($changes{'usejsme'}) ||
1.276 raeburn 11912: ($changes{'canclone'}) || ($changes{'mysqltables'})) {
1.257 raeburn 11913: foreach my $item ('canuse_pdfforms','uselcmath','usejsme') {
11914: if ($changes{$item}) {
11915: $domdefaults{$item}=$defaultshash{'coursedefaults'}{$item};
11916: }
11917: }
1.192 raeburn 11918: if ($changes{'coursecredits'}) {
11919: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
1.257 raeburn 11920: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'coursecredits'}})) {
11921: $domdefaults{$type.'credits'} =
11922: $defaultshash{'coursedefaults'}{'coursecredits'}{$type};
11923: }
11924: }
11925: }
11926: if ($changes{'postsubmit'}) {
11927: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
11928: $domdefaults{'postsubmit'} = $defaultshash{'coursedefaults'}{'postsubmit'}{'client'};
11929: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
11930: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}})) {
11931: $domdefaults{$type.'postsubtimeout'} =
11932: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
11933: }
11934: }
1.192 raeburn 11935: }
11936: }
1.198 raeburn 11937: if ($changes{'uploadquota'}) {
11938: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
11939: foreach my $type (@types) {
11940: $domdefaults{$type.'quota'}=$defaultshash{'coursedefaults'}{'uploadquota'}{$type};
11941: }
11942: }
11943: }
1.264 raeburn 11944: if ($changes{'canclone'}) {
11945: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
11946: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
11947: my @clonecodes = @{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}};
11948: if (@clonecodes) {
11949: $domdefaults{'canclone'} = join('+',@clonecodes);
11950: }
11951: }
11952: } else {
11953: $domdefaults{'canclone'}=$defaultshash{'coursedefaults'}{'canclone'};
11954: }
11955: }
1.121 raeburn 11956: my $cachetime = 24*60*60;
11957: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 11958: if (ref($lastactref) eq 'HASH') {
11959: $lastactref->{'domdefaults'} = 1;
11960: }
1.121 raeburn 11961: }
11962: $resulttext = &mt('Changes made:').'<ul>';
11963: foreach my $item (sort(keys(%changes))) {
11964: if ($item eq 'canuse_pdfforms') {
11965: if ($env{'form.'.$item} eq '1') {
11966: $resulttext .= '<li>'.&mt("Course/Community users can create/upload PDF forms set to 'on'").'</li>';
11967: } else {
11968: $resulttext .= '<li>'.&mt('Course/Community users can create/upload PDF forms set to "off"').'</li>';
11969: }
1.257 raeburn 11970: } elsif ($item eq 'uselcmath') {
11971: if ($env{'form.'.$item} eq '1') {
11972: $resulttext .= '<li>'.&mt('Math preview uses LON-CAPA previewer (javascript), if supported by browser.').'</li>';
11973: } else {
11974: $resulttext .= '<li>'.&mt('Math preview uses DragMath (Java), if supported by client OS.').'</li>';
11975: }
11976: } elsif ($item eq 'usejsme') {
11977: if ($env{'form.'.$item} eq '1') {
11978: $resulttext .= '<li>'.&mt('Molecule editor uses JSME (HTML5), if supported by browser.').'</li>';
11979: } else {
11980: $resulttext .= '<li>'.&mt('Molecule editor uses JME (Java), if supported by client OS.').'</li>';
11981: }
1.139 raeburn 11982: } elsif ($item eq 'anonsurvey_threshold') {
1.192 raeburn 11983: $resulttext .= '<li>'.&mt('Responder count required for display of anonymous survey submissions set to [_1].',$defaultshash{'coursedefaults'}{'anonsurvey_threshold'}).'</li>';
1.198 raeburn 11984: } elsif ($item eq 'uploadquota') {
11985: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
11986: $resulttext .= '<li>'.&mt('Default quota for content uploaded to a course/community via Course Editor set as follows:').'<ul>'.
11987: '<li>'.&mt('Official courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'official'}.'</b>').'</li>'.
11988: '<li>'.&mt('Unofficial courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'unofficial'}.'</b>').'</li>'.
1.216 raeburn 11989: '<li>'.&mt('Textbook courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'textbook'}.'</b>').'</li>'.
1.271 raeburn 11990: '<li>'.&mt('Placement tests: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'placement'}.'</b>').'</li>'.
1.198 raeburn 11991: '<li>'.&mt('Communities: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'community'}.'</b>').'</li>'.
11992: '</ul>'.
11993: '</li>';
11994: } else {
11995: $resulttext .= '<li>'.&mt('Default quota for content uploaded via Course Editor remains default: [_1] MB',$staticdefaults{'uploadquota'}).'</li>';
11996: }
1.276 raeburn 11997: } elsif ($item eq 'mysqltables') {
11998: if (ref($defaultshash{'coursedefaults'}{'mysqltables'}) eq 'HASH') {
11999: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver').'<ul>'.
12000: '<li>'.&mt('Official courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'official'}.'</b>').'</li>'.
12001: '<li>'.&mt('Unofficial courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'unofficial'}.'</b>').'</li>'.
12002: '<li>'.&mt('Textbook courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'textbook'}.'</b>').'</li>'.
12003: '<li>'.&mt('Placement tests: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'placement'}.'</b>').'</li>'.
12004: '<li>'.&mt('Communities: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'community'}.'</b>').'</li>'.
12005: '</ul>'.
12006: '</li>';
12007: } else {
12008: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver remains default: [_1] s',$staticdefaults{'uploadquota'}).'</li>';
12009: }
1.257 raeburn 12010: } elsif ($item eq 'postsubmit') {
12011: if ($domdefaults{'postsubmit'} eq 'off') {
12012: $resulttext .= '<li>'.&mt('Submit button(s) remain enabled on page after student makes submission.');
12013: } else {
12014: $resulttext .= '<li>'.&mt('Submit button(s) disabled on page after student makes submission').'; ';
12015: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
12016: $resulttext .= &mt('durations:').'<ul>';
12017: foreach my $type (@types) {
12018: $resulttext .= '<li>';
12019: my $timeout;
12020: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
12021: $timeout = $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
12022: }
12023: my $display;
12024: if ($timeout eq '0') {
12025: $display = &mt('unlimited');
12026: } elsif ($timeout eq '') {
12027: $display = &mt('[quant,_1,second] (default)',$staticdefaults{'postsubmit'});
12028: } else {
12029: $display = &mt('[quant,_1,second]',$timeout);
12030: }
12031: if ($type eq 'community') {
12032: $resulttext .= &mt('Communities');
12033: } elsif ($type eq 'official') {
12034: $resulttext .= &mt('Official courses');
12035: } elsif ($type eq 'unofficial') {
12036: $resulttext .= &mt('Unofficial courses');
12037: } elsif ($type eq 'textbook') {
12038: $resulttext .= &mt('Textbook courses');
1.271 raeburn 12039: } elsif ($type eq 'placement') {
12040: $resulttext .= &mt('Placement tests');
1.257 raeburn 12041: }
12042: $resulttext .= ' -- '.$display.'</li>';
12043: }
12044: $resulttext .= '</ul>';
12045: }
12046: $resulttext .= '</li>';
12047: }
1.192 raeburn 12048: } elsif ($item eq 'coursecredits') {
12049: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
12050: if (($domdefaults{'officialcredits'} eq '') &&
1.216 raeburn 12051: ($domdefaults{'unofficialcredits'} eq '') &&
12052: ($domdefaults{'textbookcredits'} eq '')) {
1.192 raeburn 12053: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
12054: } else {
12055: $resulttext .= '<li>'.&mt('Student credits can be set per course by a Domain Coordinator, with the following defaults applying:').'<ul>'.
12056: '<li>'.&mt('Official courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'official'}).'</li>'.
12057: '<li>'.&mt('Unofficial courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'}).'</li>'.
1.216 raeburn 12058: '<li>'.&mt('Textbook courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'textbook'}).'</li>'.
1.192 raeburn 12059: '</ul>'.
12060: '</li>';
12061: }
12062: } else {
12063: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
12064: }
1.264 raeburn 12065: } elsif ($item eq 'canclone') {
12066: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
12067: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
12068: my $clonecodes = join(' '.&mt('and').' ',@{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}});
12069: $resulttext .= '<li>'.&mt('By default, official courses can be cloned from existing courses with the same: [_1]','<b>'.$clonecodes.'</b>').'</li>';
12070: }
12071: } elsif ($defaultshash{'coursedefaults'}{'canclone'} eq 'domain') {
12072: $resulttext .= '<li>'.&mt('By default, a course requester can clone any course from his/her domain.').'</li>';
12073: } else {
12074: $resulttext .= '<li>'.&mt('By default, only course owner and coordinators may clone a course.').'</li>';
12075: }
1.140 raeburn 12076: }
1.121 raeburn 12077: }
12078: $resulttext .= '</ul>';
12079: } else {
12080: $resulttext = &mt('No changes made to course defaults');
12081: }
12082: } else {
12083: $resulttext = '<span class="LC_error">'.
12084: &mt('An error occurred: [_1]',$putresult).'</span>';
12085: }
12086: return $resulttext;
12087: }
12088:
1.231 raeburn 12089: sub modify_selfenrollment {
12090: my ($dom,$lastactref,%domconfig) = @_;
12091: my ($resulttext,$errors,%changes,%selfenrollhash,%ordered);
1.271 raeburn 12092: my @types = ('official','unofficial','community','textbook','placement');
1.231 raeburn 12093: my %titles = &tool_titles();
1.232 raeburn 12094: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
12095: ($ordered{'admin'},my $titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
1.231 raeburn 12096: $ordered{'default'} = ['types','registered','approval','limit'];
12097:
12098: my (%roles,%shown,%toplevel);
12099: $roles{'0'} = &Apache::lonnet::plaintext('dc');
12100:
12101: if (ref($domconfig{'selfenrollment'}) ne 'HASH') {
12102: if ($domconfig{'selfenrollment'} eq '') {
12103: $domconfig{'selfenrollment'} = {};
12104: }
12105: }
12106: %toplevel = (
12107: admin => 'Configuration Rights',
12108: default => 'Default settings',
12109: validation => 'Validation of self-enrollment requests',
12110: );
1.233 raeburn 12111: my ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
1.231 raeburn 12112:
12113: if (ref($ordered{'admin'}) eq 'ARRAY') {
12114: foreach my $item (@{$ordered{'admin'}}) {
12115: foreach my $type (@types) {
12116: if ($env{'form.selfenrolladmin_'.$item.'_'.$type}) {
12117: $selfenrollhash{'admin'}{$type}{$item} = 1;
12118: } else {
12119: $selfenrollhash{'admin'}{$type}{$item} = 0;
12120: }
12121: if (ref($domconfig{'selfenrollment'}{'admin'}) eq 'HASH') {
12122: if (ref($domconfig{'selfenrollment'}{'admin'}{$type}) eq 'HASH') {
12123: if ($selfenrollhash{'admin'}{$type}{$item} ne
12124: $domconfig{'selfenrollment'}{'admin'}{$type}{$item}) {
12125: push(@{$changes{'admin'}{$type}},$item);
12126: }
12127: } else {
12128: if (!$selfenrollhash{'admin'}{$type}{$item}) {
12129: push(@{$changes{'admin'}{$type}},$item);
12130: }
12131: }
12132: } elsif (!$selfenrollhash{'admin'}{$type}{$item}) {
12133: push(@{$changes{'admin'}{$type}},$item);
12134: }
12135: }
12136: }
12137: }
12138:
12139: foreach my $item (@{$ordered{'default'}}) {
12140: foreach my $type (@types) {
12141: my $value = $env{'form.selfenrolldefault_'.$item.'_'.$type};
12142: if ($item eq 'types') {
12143: unless (($value eq 'all') || ($value eq 'dom')) {
12144: $value = '';
12145: }
12146: } elsif ($item eq 'registered') {
12147: unless ($value eq '1') {
12148: $value = 0;
12149: }
12150: } elsif ($item eq 'approval') {
12151: unless ($value =~ /^[012]$/) {
12152: $value = 0;
12153: }
12154: } else {
12155: unless (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
12156: $value = 'none';
12157: }
12158: }
12159: $selfenrollhash{'default'}{$type}{$item} = $value;
12160: if (ref($domconfig{'selfenrollment'}{'default'}) eq 'HASH') {
12161: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
12162: if ($selfenrollhash{'default'}{$type}{$item} ne
12163: $domconfig{'selfenrollment'}{'default'}{$type}{$item}) {
12164: push(@{$changes{'default'}{$type}},$item);
12165: }
12166: } else {
12167: push(@{$changes{'default'}{$type}},$item);
12168: }
12169: } else {
12170: push(@{$changes{'default'}{$type}},$item);
12171: }
12172: if ($item eq 'limit') {
12173: if (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
12174: $env{'form.selfenrolldefault_cap_'.$type} =~ s/\D//g;
12175: if ($env{'form.selfenrolldefault_cap_'.$type} ne '') {
12176: $selfenrollhash{'default'}{$type}{'cap'} = $env{'form.selfenrolldefault_cap_'.$type};
12177: }
12178: } else {
12179: $selfenrollhash{'default'}{$type}{'cap'} = '';
12180: }
12181: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
12182: if ($selfenrollhash{'default'}{$type}{'cap'} ne
12183: $domconfig{'selfenrollment'}{'admin'}{$type}{'cap'}) {
12184: push(@{$changes{'default'}{$type}},'cap');
12185: }
12186: } elsif ($selfenrollhash{'default'}{$type}{'cap'} ne '') {
12187: push(@{$changes{'default'}{$type}},'cap');
12188: }
12189: }
12190: }
12191: }
12192:
12193: foreach my $item (@{$itemsref}) {
12194: if ($item eq 'fields') {
12195: my @changed;
12196: @{$selfenrollhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.selfenroll_validation_'.$item);
12197: if (@{$selfenrollhash{'validation'}{$item}} > 0) {
12198: @{$selfenrollhash{'validation'}{$item}} = sort(@{$selfenrollhash{'validation'}{$item}});
12199: }
12200: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
12201: if (ref($domconfig{'selfenrollment'}{'validation'}{$item}) eq 'ARRAY') {
12202: @changed = &Apache::loncommon::compare_arrays($selfenrollhash{'validation'}{$item},
12203: $domconfig{'selfenrollment'}{'validation'}{$item});
12204: } else {
12205: @changed = @{$selfenrollhash{'validation'}{$item}};
12206: }
12207: } else {
12208: @changed = @{$selfenrollhash{'validation'}{$item}};
12209: }
12210: if (@changed) {
12211: if ($selfenrollhash{'validation'}{$item}) {
12212: $changes{'validation'}{$item} = join(', ',@{$selfenrollhash{'validation'}{$item}});
12213: } else {
12214: $changes{'validation'}{$item} = &mt('None');
12215: }
12216: }
12217: } else {
12218: $selfenrollhash{'validation'}{$item} = $env{'form.selfenroll_validation_'.$item};
12219: if ($item eq 'markup') {
12220: if ($env{'form.selfenroll_validation_'.$item}) {
12221: $env{'form.selfenroll_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
12222: }
12223: }
12224: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
12225: if ($domconfig{'selfenrollment'}{'validation'}{$item} ne $selfenrollhash{'validation'}{$item}) {
12226: $changes{'validation'}{$item} = $selfenrollhash{'validation'}{$item};
12227: }
12228: }
12229: }
12230: }
12231:
12232: my $putresult = &Apache::lonnet::put_dom('configuration',{'selfenrollment' => \%selfenrollhash},
12233: $dom);
12234: if ($putresult eq 'ok') {
12235: if (keys(%changes) > 0) {
12236: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
12237: $resulttext = &mt('Changes made:').'<ul>';
12238: foreach my $key ('admin','default','validation') {
12239: if (ref($changes{$key}) eq 'HASH') {
12240: $resulttext .= '<li>'.$toplevel{$key}.'<ul>';
12241: if ($key eq 'validation') {
12242: foreach my $item (@{$itemsref}) {
12243: if (exists($changes{$key}{$item})) {
12244: if ($item eq 'markup') {
12245: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
12246: '<br /><pre>'.$changes{$key}{$item}.'</pre>').'</li>';
12247: } else {
12248: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
12249: '<b>'.$changes{$key}{$item}.'</b>').'</li>';
12250: }
12251: }
12252: }
12253: } else {
12254: foreach my $type (@types) {
12255: if ($type eq 'community') {
12256: $roles{'1'} = &mt('Community personnel');
12257: } else {
12258: $roles{'1'} = &mt('Course personnel');
12259: }
12260: if (ref($changes{$key}{$type}) eq 'ARRAY') {
1.232 raeburn 12261: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
12262: if ($key eq 'admin') {
12263: my @mgrdc = ();
12264: if (ref($ordered{$key}) eq 'ARRAY') {
12265: foreach my $item (@{$ordered{'admin'}}) {
12266: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
12267: if ($selfenrollhash{$key}{$type}{$item} eq '0') {
12268: push(@mgrdc,$item);
12269: }
12270: }
12271: }
12272: if (@mgrdc) {
12273: $domdefaults{$type.'selfenrolladmdc'} = join(',',@mgrdc);
12274: } else {
12275: delete($domdefaults{$type.'selfenrolladmdc'});
12276: }
12277: }
12278: } else {
12279: if (ref($ordered{$key}) eq 'ARRAY') {
12280: foreach my $item (@{$ordered{$key}}) {
12281: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
12282: $domdefaults{$type.'selfenroll'.$item} =
12283: $selfenrollhash{$key}{$type}{$item};
12284: }
12285: }
12286: }
12287: }
12288: }
1.231 raeburn 12289: $resulttext .= '<li>'.$titles{$type}.'<ul>';
12290: foreach my $item (@{$ordered{$key}}) {
12291: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
12292: $resulttext .= '<li>';
12293: if ($key eq 'admin') {
12294: $resulttext .= &mt('[_1] -- management by: [_2]',$titlesref->{$item},
12295: '<b>'.$roles{$selfenrollhash{'admin'}{$type}{$item}}.'</b>');
12296: } else {
12297: $resulttext .= &mt('[_1] set to: [_2]',$titlesref->{$item},
12298: '<b>'.$descs{$item}{$selfenrollhash{'default'}{$type}{$item}}.'</b>');
12299: }
12300: $resulttext .= '</li>';
12301: }
12302: }
12303: $resulttext .= '</ul></li>';
12304: }
12305: }
12306: $resulttext .= '</ul></li>';
12307: }
12308: }
1.232 raeburn 12309: if ((exists($changes{'admin'})) || (exists($changes{'default'}))) {
12310: my $cachetime = 24*60*60;
12311: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
12312: if (ref($lastactref) eq 'HASH') {
12313: $lastactref->{'domdefaults'} = 1;
12314: }
12315: }
1.231 raeburn 12316: }
12317: $resulttext .= '</ul>';
12318: } else {
12319: $resulttext = &mt('No changes made to self-enrollment settings');
12320: }
12321: } else {
12322: $resulttext = '<span class="LC_error">'.
12323: &mt('An error occurred: [_1]',$putresult).'</span>';
12324: }
12325: return $resulttext;
12326: }
12327:
1.137 raeburn 12328: sub modify_usersessions {
1.212 raeburn 12329: my ($dom,$lastactref,%domconfig) = @_;
1.145 raeburn 12330: my @hostingtypes = ('version','excludedomain','includedomain');
12331: my @offloadtypes = ('primary','default');
12332: my %types = (
12333: remote => \@hostingtypes,
12334: hosted => \@hostingtypes,
12335: spares => \@offloadtypes,
12336: );
12337: my @prefixes = ('remote','hosted','spares');
1.137 raeburn 12338: my @lcversions = &Apache::lonnet::all_loncaparevs();
1.275 raeburn 12339: my (%by_ip,%by_location,@intdoms,@instdoms);
12340: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
1.138 raeburn 12341: my @locations = sort(keys(%by_location));
1.137 raeburn 12342: my (%defaultshash,%changes);
12343: foreach my $prefix (@prefixes) {
12344: $defaultshash{'usersessions'}{$prefix} = {};
12345: }
1.212 raeburn 12346: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.137 raeburn 12347: my $resulttext;
1.138 raeburn 12348: my %iphost = &Apache::lonnet::get_iphost();
1.137 raeburn 12349: foreach my $prefix (@prefixes) {
1.145 raeburn 12350: next if ($prefix eq 'spares');
12351: foreach my $type (@{$types{$prefix}}) {
1.137 raeburn 12352: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
12353: if ($type eq 'version') {
12354: my $value = $env{'form.'.$prefix.'_'.$type};
12355: my $okvalue;
12356: if ($value ne '') {
12357: if (grep(/^\Q$value\E$/,@lcversions)) {
12358: $okvalue = $value;
12359: }
12360: }
12361: if (ref($domconfig{'usersessions'}) eq 'HASH') {
12362: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
12363: if ($domconfig{'usersessions'}{$prefix}{$type} ne '') {
12364: if ($inuse == 0) {
12365: $changes{$prefix}{$type} = 1;
12366: } else {
12367: if ($okvalue ne $domconfig{'usersessions'}{$prefix}{$type}) {
12368: $changes{$prefix}{$type} = 1;
12369: }
12370: if ($okvalue ne '') {
12371: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
12372: }
12373: }
12374: } else {
12375: if (($inuse == 1) && ($okvalue ne '')) {
12376: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
12377: $changes{$prefix}{$type} = 1;
12378: }
12379: }
12380: } else {
12381: if (($inuse == 1) && ($okvalue ne '')) {
12382: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
12383: $changes{$prefix}{$type} = 1;
12384: }
12385: }
12386: } else {
12387: if (($inuse == 1) && ($okvalue ne '')) {
12388: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
12389: $changes{$prefix}{$type} = 1;
12390: }
12391: }
12392: } else {
12393: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
12394: my @okvals;
12395: foreach my $val (@vals) {
1.138 raeburn 12396: if ($val =~ /:/) {
12397: my @items = split(/:/,$val);
12398: foreach my $item (@items) {
12399: if (ref($by_location{$item}) eq 'ARRAY') {
12400: push(@okvals,$item);
12401: }
12402: }
12403: } else {
12404: if (ref($by_location{$val}) eq 'ARRAY') {
12405: push(@okvals,$val);
12406: }
1.137 raeburn 12407: }
12408: }
12409: @okvals = sort(@okvals);
12410: if (ref($domconfig{'usersessions'}) eq 'HASH') {
12411: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
12412: if (ref($domconfig{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
12413: if ($inuse == 0) {
12414: $changes{$prefix}{$type} = 1;
12415: } else {
12416: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
12417: my @changed = &Apache::loncommon::compare_arrays($domconfig{'usersessions'}{$prefix}{$type},$defaultshash{'usersessions'}{$prefix}{$type});
12418: if (@changed > 0) {
12419: $changes{$prefix}{$type} = 1;
12420: }
12421: }
12422: } else {
12423: if ($inuse == 1) {
12424: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
12425: $changes{$prefix}{$type} = 1;
12426: }
12427: }
12428: } else {
12429: if ($inuse == 1) {
12430: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
12431: $changes{$prefix}{$type} = 1;
12432: }
12433: }
12434: } else {
12435: if ($inuse == 1) {
12436: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
12437: $changes{$prefix}{$type} = 1;
12438: }
12439: }
12440: }
12441: }
12442: }
1.145 raeburn 12443:
12444: my @alldoms = &Apache::lonnet::all_domains();
1.149 raeburn 12445: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.145 raeburn 12446: my %spareid = ¤t_offloads_to($dom,$domconfig{'usersessions'},\%servers);
12447: my $savespares;
12448:
12449: foreach my $lonhost (sort(keys(%servers))) {
12450: my $serverhomeID =
12451: &Apache::lonnet::get_server_homeID($servers{$lonhost});
1.152 raeburn 12452: my $serverhostname = &Apache::lonnet::hostname($lonhost);
1.145 raeburn 12453: $defaultshash{'usersessions'}{'spares'}{$lonhost} = {};
12454: my %spareschg;
12455: foreach my $type (@{$types{'spares'}}) {
12456: my @okspares;
12457: my @checked = &Apache::loncommon::get_env_multiple('form.spare_'.$type.'_'.$lonhost);
12458: foreach my $server (@checked) {
1.152 raeburn 12459: if (&Apache::lonnet::hostname($server) ne '') {
12460: unless (&Apache::lonnet::hostname($server) eq $serverhostname) {
12461: unless (grep(/^\Q$server\E$/,@okspares)) {
12462: push(@okspares,$server);
12463: }
1.145 raeburn 12464: }
12465: }
12466: }
12467: my $new = $env{'form.newspare_'.$type.'_'.$lonhost};
12468: my $newspare;
1.152 raeburn 12469: if (($new ne '') && (&Apache::lonnet::hostname($new))) {
12470: unless (&Apache::lonnet::hostname($new) eq $serverhostname) {
1.145 raeburn 12471: $newspare = $new;
12472: }
12473: }
1.152 raeburn 12474: my @spares;
12475: if (($newspare ne '') && (!grep(/^\Q$newspare\E$/,@okspares))) {
12476: @spares = sort(@okspares,$newspare);
12477: } else {
12478: @spares = sort(@okspares);
12479: }
12480: $defaultshash{'usersessions'}{'spares'}{$lonhost}{$type} = \@spares;
1.145 raeburn 12481: if (ref($spareid{$lonhost}) eq 'HASH') {
12482: if (ref($spareid{$lonhost}{$type}) eq 'ARRAY') {
1.152 raeburn 12483: my @diffs = &Apache::loncommon::compare_arrays($spareid{$lonhost}{$type},\@spares);
1.145 raeburn 12484: if (@diffs > 0) {
12485: $spareschg{$type} = 1;
12486: }
12487: }
12488: }
12489: }
12490: if (keys(%spareschg) > 0) {
12491: $changes{'spares'}{$lonhost} = \%spareschg;
12492: }
12493: }
1.261 raeburn 12494: $defaultshash{'usersessions'}{'offloadnow'} = {};
12495: my @offloadnow = &Apache::loncommon::get_env_multiple('form.offloadnow');
12496: my @okoffload;
12497: if (@offloadnow) {
12498: foreach my $server (@offloadnow) {
12499: if (&Apache::lonnet::hostname($server) ne '') {
12500: unless (grep(/^\Q$server\E$/,@okoffload)) {
12501: push(@okoffload,$server);
12502: }
12503: }
12504: }
12505: if (@okoffload) {
12506: foreach my $lonhost (@okoffload) {
12507: $defaultshash{'usersessions'}{'offloadnow'}{$lonhost} = 1;
12508: }
12509: }
12510: }
1.145 raeburn 12511: if (ref($domconfig{'usersessions'}) eq 'HASH') {
12512: if (ref($domconfig{'usersessions'}{'spares'}) eq 'HASH') {
12513: if (ref($changes{'spares'}) eq 'HASH') {
12514: if (keys(%{$changes{'spares'}}) > 0) {
12515: $savespares = 1;
12516: }
12517: }
12518: } else {
12519: $savespares = 1;
12520: }
1.261 raeburn 12521: if (ref($domconfig{'usersessions'}{'offloadnow'}) eq 'HASH') {
12522: foreach my $lonhost (keys(%{$domconfig{'usersessions'}{'offloadnow'}})) {
12523: unless ($defaultshash{'usersessions'}{'offloadnow'}{$lonhost}) {
12524: $changes{'offloadnow'} = 1;
12525: last;
12526: }
12527: }
12528: unless ($changes{'offloadnow'}) {
12529: foreach my $lonhost (keys(%{$defaultshash{'usersessions'}{'offloadnow'}})) {
12530: unless ($domconfig{'usersessions'}{'offloadnow'}{$lonhost}) {
12531: $changes{'offloadnow'} = 1;
12532: last;
12533: }
12534: }
12535: }
12536: } elsif (@okoffload) {
12537: $changes{'offloadnow'} = 1;
12538: }
12539: } elsif (@okoffload) {
12540: $changes{'offloadnow'} = 1;
1.145 raeburn 12541: }
1.147 raeburn 12542: my $nochgmsg = &mt('No changes made to settings for user session hosting/offloading.');
12543: if ((keys(%changes) > 0) || ($savespares)) {
1.137 raeburn 12544: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
12545: $dom);
12546: if ($putresult eq 'ok') {
12547: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
12548: if (ref($defaultshash{'usersessions'}{'remote'}) eq 'HASH') {
12549: $domdefaults{'remotesessions'} = $defaultshash{'usersessions'}{'remote'};
12550: }
12551: if (ref($defaultshash{'usersessions'}{'hosted'}) eq 'HASH') {
12552: $domdefaults{'hostedsessions'} = $defaultshash{'usersessions'}{'hosted'};
12553: }
1.261 raeburn 12554: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
12555: $domdefaults{'offloadnow'} = $defaultshash{'usersessions'}{'offloadnow'};
12556: }
1.137 raeburn 12557: }
12558: my $cachetime = 24*60*60;
12559: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 12560: if (ref($lastactref) eq 'HASH') {
12561: $lastactref->{'domdefaults'} = 1;
12562: }
1.147 raeburn 12563: if (keys(%changes) > 0) {
12564: my %lt = &usersession_titles();
12565: $resulttext = &mt('Changes made:').'<ul>';
12566: foreach my $prefix (@prefixes) {
12567: if (ref($changes{$prefix}) eq 'HASH') {
12568: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
12569: if ($prefix eq 'spares') {
12570: if (ref($changes{$prefix}) eq 'HASH') {
12571: foreach my $lonhost (sort(keys(%{$changes{$prefix}}))) {
12572: $resulttext .= '<li><b>'.$lonhost.'</b> ';
1.148 raeburn 12573: my $lonhostdom = &Apache::lonnet::host_domain($lonhost);
1.211 raeburn 12574: my $cachekey = &escape('spares').':'.&escape($lonhostdom);
12575: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
1.147 raeburn 12576: if (ref($changes{$prefix}{$lonhost}) eq 'HASH') {
12577: foreach my $type (@{$types{$prefix}}) {
12578: if ($changes{$prefix}{$lonhost}{$type}) {
12579: my $offloadto = &mt('None');
12580: if (ref($defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}) eq 'ARRAY') {
12581: if (@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}} > 0) {
12582: $offloadto = join(', ',@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}});
12583: }
1.145 raeburn 12584: }
1.147 raeburn 12585: $resulttext .= &mt('[_1] set to: [_2].','<i>'.$lt{$type}.'</i>',$offloadto).(' 'x3);
1.145 raeburn 12586: }
1.137 raeburn 12587: }
12588: }
1.147 raeburn 12589: $resulttext .= '</li>';
1.137 raeburn 12590: }
12591: }
1.147 raeburn 12592: } else {
12593: foreach my $type (@{$types{$prefix}}) {
12594: if (defined($changes{$prefix}{$type})) {
12595: my $newvalue;
12596: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
12597: if (ref($defaultshash{'usersessions'}{$prefix})) {
12598: if ($type eq 'version') {
12599: $newvalue = $defaultshash{'usersessions'}{$prefix}{$type};
12600: } elsif (ref($defaultshash{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
12601: if (@{$defaultshash{'usersessions'}{$prefix}{$type}} > 0) {
12602: $newvalue = join(', ',@{$defaultshash{'usersessions'}{$prefix}{$type}});
12603: }
1.145 raeburn 12604: }
12605: }
12606: }
1.147 raeburn 12607: if ($newvalue eq '') {
12608: if ($type eq 'version') {
12609: $resulttext .= '<li>'.&mt('[_1] set to: off',$lt{$type}).'</li>';
12610: } else {
12611: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
12612: }
1.145 raeburn 12613: } else {
1.147 raeburn 12614: if ($type eq 'version') {
12615: $newvalue .= ' '.&mt('(or later)');
12616: }
12617: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
1.145 raeburn 12618: }
1.137 raeburn 12619: }
12620: }
12621: }
1.147 raeburn 12622: $resulttext .= '</ul>';
1.137 raeburn 12623: }
12624: }
1.261 raeburn 12625: if ($changes{'offloadnow'}) {
12626: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
12627: if (keys(%{$defaultshash{'usersessions'}{'offloadnow'}}) > 0) {
12628: $resulttext .= '<li>'.&mt('Switch active users on next access, for server(s):').'<ul>';
12629: foreach my $lonhost (sort(keys(%{$defaultshash{'usersessions'}{'offloadnow'}}))) {
12630: $resulttext .= '<li>'.$lonhost.'</li>';
12631: }
12632: $resulttext .= '</ul>';
12633: } else {
12634: $resulttext .= '<li>'.&mt('No servers now set to switch active users on next access.');
12635: }
12636: } else {
12637: $resulttext .= '<li>'.&mt('No servers now set to switch active users on next access.').'</li>';
12638: }
12639: }
1.147 raeburn 12640: $resulttext .= '</ul>';
12641: } else {
12642: $resulttext = $nochgmsg;
1.137 raeburn 12643: }
12644: } else {
12645: $resulttext = '<span class="LC_error">'.
12646: &mt('An error occurred: [_1]',$putresult).'</span>';
12647: }
12648: } else {
1.147 raeburn 12649: $resulttext = $nochgmsg;
1.137 raeburn 12650: }
12651: return $resulttext;
12652: }
12653:
1.275 raeburn 12654: sub modify_ssl {
12655: my ($dom,$lastactref,%domconfig) = @_;
12656: my (%by_ip,%by_location,@intdoms,@instdoms);
12657: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
12658: my @locations = sort(keys(%by_location));
12659: my %servers = &Apache::lonnet::internet_dom_servers($dom);
12660: my (%defaultshash,%changes);
12661: my $action = 'ssl';
12662: my @prefixes = ('connect','replication');
12663: foreach my $prefix (@prefixes) {
12664: $defaultshash{$action}{$prefix} = {};
12665: }
12666: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
12667: my $resulttext;
12668: my %iphost = &Apache::lonnet::get_iphost();
12669: my @reptypes = ('certreq','nocertreq');
12670: my @connecttypes = ('dom','intdom','other');
12671: my %types = (
12672: connect => \@connecttypes,
12673: replication => \@reptypes,
12674: );
12675: my $action = 'ssl';
12676: foreach my $prefix (sort(keys(%types))) {
12677: foreach my $type (@{$types{$prefix}}) {
12678: if ($prefix eq 'connect') {
12679: my $value = 'yes';
12680: if ($env{'form.'.$prefix.'_'.$type} =~ /^(no|req)$/) {
12681: $value = $env{'form.'.$prefix.'_'.$type};
12682: }
12683: if (ref($domconfig{$action}{$prefix}) eq 'HASH') {
12684: if ($domconfig{$action}{$prefix}{$type} ne '') {
12685: if ($value ne $domconfig{$action}{$prefix}{$type}) {
12686: $changes{$prefix}{$type} = 1;
12687: }
12688: $defaultshash{$action}{$prefix}{$type} = $value;
12689: } else {
12690: $defaultshash{$action}{$prefix}{$type} = $value;
12691: $changes{$prefix}{$type} = 1;
12692: }
12693: } else {
12694: $defaultshash{$action}{$prefix}{$type} = $value;
12695: $changes{$prefix}{$type} = 1;
12696: }
12697: if (($type eq 'dom') && (keys(%servers) == 1)) {
12698: delete($changes{$prefix}{$type});
12699: } elsif (($type eq 'intdom') && (@instdoms == 1)) {
12700: delete($changes{$prefix}{$type});
12701: } elsif (($type eq 'other') && (keys(%by_location) == 0)) {
12702: delete($changes{$prefix}{$type});
12703: }
12704: } elsif ($prefix eq 'replication') {
12705: if (@locations > 0) {
12706: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
12707: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
12708: my @okvals;
12709: foreach my $val (@vals) {
12710: if ($val =~ /:/) {
12711: my @items = split(/:/,$val);
12712: foreach my $item (@items) {
12713: if (ref($by_location{$item}) eq 'ARRAY') {
12714: push(@okvals,$item);
12715: }
12716: }
12717: } else {
12718: if (ref($by_location{$val}) eq 'ARRAY') {
12719: push(@okvals,$val);
12720: }
12721: }
12722: }
12723: @okvals = sort(@okvals);
12724: if (ref($domconfig{$action}) eq 'HASH') {
12725: if (ref($domconfig{$action}{$prefix}) eq 'HASH') {
12726: if (ref($domconfig{$action}{$prefix}{$type}) eq 'ARRAY') {
12727: if ($inuse == 0) {
12728: $changes{$prefix}{$type} = 1;
12729: } else {
12730: $defaultshash{$action}{$prefix}{$type} = \@okvals;
12731: my @changed = &Apache::loncommon::compare_arrays($domconfig{$action}{$prefix}{$type},$defaultshash{$action}{$prefix}{$type});
12732: if (@changed > 0) {
12733: $changes{$prefix}{$type} = 1;
12734: }
12735: }
12736: } else {
12737: if ($inuse == 1) {
12738: $defaultshash{$action}{$prefix}{$type} = \@okvals;
12739: $changes{$prefix}{$type} = 1;
12740: }
12741: }
12742: } else {
12743: if ($inuse == 1) {
12744: $defaultshash{$action}{$prefix}{$type} = \@okvals;
12745: $changes{$prefix}{$type} = 1;
12746: }
12747: }
12748: } else {
12749: if ($inuse == 1) {
12750: $defaultshash{$action}{$prefix}{$type} = \@okvals;
12751: $changes{$prefix}{$type} = 1;
12752: }
12753: }
12754: }
12755: }
12756: }
12757: }
12758: my $nochgmsg = &mt('No changes made to LON-CAPA SSL settings');
12759: if (keys(%changes) > 0) {
12760: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
12761: $dom);
12762: if ($putresult eq 'ok') {
12763: if (ref($defaultshash{$action}) eq 'HASH') {
12764: if (ref($defaultshash{$action}{'replication'}) eq 'HASH') {
12765: $domdefaults{'replication'} = $defaultshash{$action}{'replication'};
12766: }
12767: if (ref($defaultshash{$action}{'connect'}) eq 'HASH') {
12768: $domdefaults{'connect'} = $domconfig{$action}{'connect'};
12769: }
12770: }
12771: my $cachetime = 24*60*60;
12772: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
12773: if (ref($lastactref) eq 'HASH') {
12774: $lastactref->{'domdefaults'} = 1;
12775: }
12776: if (keys(%changes) > 0) {
12777: my %titles = &ssl_titles();
12778: $resulttext = &mt('Changes made:').'<ul>';
12779: foreach my $prefix (@prefixes) {
12780: if (ref($changes{$prefix}) eq 'HASH') {
12781: $resulttext .= '<li>'.$titles{$prefix}.'<ul>';
12782: foreach my $type (@{$types{$prefix}}) {
12783: if (defined($changes{$prefix}{$type})) {
12784: my $newvalue;
12785: if (ref($defaultshash{$action}) eq 'HASH') {
12786: if (ref($defaultshash{$action}{$prefix})) {
12787: if ($prefix eq 'connect') {
12788: $newvalue = $titles{$defaultshash{$action}{$prefix}{$type}};
12789: } elsif (ref($defaultshash{$action}{$prefix}{$type}) eq 'ARRAY') {
12790: if (@{$defaultshash{$action}{$prefix}{$type}} > 0) {
12791: $newvalue = join(', ',@{$defaultshash{$action}{$prefix}{$type}});
12792: }
12793: }
12794: }
12795: if ($newvalue eq '') {
12796: $resulttext .= '<li>'.&mt('[_1] set to: none',$titles{$type}).'</li>';
12797: } else {
12798: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$titles{$type},$newvalue).'</li>';
12799: }
12800: }
12801: }
12802: }
12803: $resulttext .= '</ul>';
12804: }
12805: }
12806: } else {
12807: $resulttext = $nochgmsg;
12808: }
12809: } else {
12810: $resulttext = '<span class="LC_error">'.
12811: &mt('An error occurred: [_1]',$putresult).'</span>';
12812: }
12813: } else {
12814: $resulttext = $nochgmsg;
12815: }
12816: return $resulttext;
12817: }
12818:
1.150 raeburn 12819: sub modify_loadbalancing {
12820: my ($dom,%domconfig) = @_;
12821: my $primary_id = &Apache::lonnet::domain($dom,'primary');
12822: my $intdom = &Apache::lonnet::internet_dom($primary_id);
12823: my ($othertitle,$usertypes,$types) =
12824: &Apache::loncommon::sorted_inst_types($dom);
12825: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.253 raeburn 12826: my %libraryservers = &Apache::lonnet::get_servers($dom,'library');
1.150 raeburn 12827: my @sparestypes = ('primary','default');
12828: my %typetitles = &sparestype_titles();
12829: my $resulttext;
1.171 raeburn 12830: my (%currbalancer,%currtargets,%currrules,%existing);
12831: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
12832: %existing = %{$domconfig{'loadbalancing'}};
12833: }
12834: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
12835: \%currtargets,\%currrules);
12836: my ($saveloadbalancing,%defaultshash,%changes);
12837: my ($alltypes,$othertypes,$titles) =
12838: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
12839: my %ruletitles = &offloadtype_text();
12840: my @deletions = &Apache::loncommon::get_env_multiple('form.loadbalancing_delete');
12841: for (my $i=0; $i<$env{'form.loadbalancing_total'}; $i++) {
12842: my $balancer = $env{'form.loadbalancing_lonhost_'.$i};
12843: if ($balancer eq '') {
12844: next;
12845: }
1.210 raeburn 12846: if (!exists($servers{$balancer})) {
1.171 raeburn 12847: if (exists($currbalancer{$balancer})) {
12848: push(@{$changes{'delete'}},$balancer);
1.150 raeburn 12849: }
1.171 raeburn 12850: next;
12851: }
12852: if ((@deletions > 0) && (grep(/^\Q$i\E$/,@deletions))) {
12853: push(@{$changes{'delete'}},$balancer);
12854: next;
12855: }
12856: if (!exists($currbalancer{$balancer})) {
12857: push(@{$changes{'add'}},$balancer);
12858: }
12859: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'} = [];
12860: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'default'} = [];
12861: $defaultshash{'loadbalancing'}{$balancer}{'rules'} = {};
12862: unless (ref($domconfig{'loadbalancing'}) eq 'HASH') {
12863: $saveloadbalancing = 1;
12864: }
12865: foreach my $sparetype (@sparestypes) {
12866: my @targets = &Apache::loncommon::get_env_multiple('form.loadbalancing_target_'.$i.'_'.$sparetype);
12867: my @offloadto;
12868: foreach my $target (@targets) {
12869: if (($servers{$target}) && ($target ne $balancer)) {
12870: if ($sparetype eq 'default') {
12871: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}) eq 'ARRAY') {
12872: next if (grep(/^\Q$target\E$/,@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}}));
1.150 raeburn 12873: }
12874: }
1.171 raeburn 12875: unless(grep(/^\Q$target\E$/,@offloadto)) {
12876: push(@offloadto,$target);
12877: }
1.150 raeburn 12878: }
1.171 raeburn 12879: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype} = \@offloadto;
1.150 raeburn 12880: }
12881: }
1.171 raeburn 12882: if (ref($currtargets{$balancer}) eq 'HASH') {
1.150 raeburn 12883: foreach my $sparetype (@sparestypes) {
1.171 raeburn 12884: if (ref($currtargets{$balancer}{$sparetype}) eq 'ARRAY') {
12885: my @targetdiffs = &Apache::loncommon::compare_arrays($currtargets{$balancer}{$sparetype},$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype});
1.150 raeburn 12886: if (@targetdiffs > 0) {
1.171 raeburn 12887: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 12888: }
1.171 raeburn 12889: } elsif (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
12890: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
12891: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 12892: }
12893: }
12894: }
12895: } else {
1.171 raeburn 12896: if (ref($defaultshash{'loadbalancing'}{$balancer}) eq 'HASH') {
1.210 raeburn 12897: foreach my $sparetype (@sparestypes) {
1.171 raeburn 12898: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
12899: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
12900: $changes{'curr'}{$balancer}{'targets'} = 1;
12901: }
1.150 raeburn 12902: }
12903: }
1.210 raeburn 12904: }
1.150 raeburn 12905: }
12906: my $ishomedom;
1.171 raeburn 12907: if (&Apache::lonnet::host_domain($balancer) eq $dom) {
12908: $ishomedom = 1;
1.150 raeburn 12909: }
12910: if (ref($alltypes) eq 'ARRAY') {
12911: foreach my $type (@{$alltypes}) {
12912: my $rule;
1.210 raeburn 12913: unless ((($type eq '_LC_external') || ($type eq '_LC_internetdom')) &&
1.150 raeburn 12914: (!$ishomedom)) {
1.171 raeburn 12915: $rule = $env{'form.loadbalancing_rules_'.$i.'_'.$type};
12916: }
12917: if ($rule eq 'specific') {
1.255 raeburn 12918: my $specifiedhost = $env{'form.loadbalancing_singleserver_'.$i.'_'.$type};
12919: if (exists($servers{$specifiedhost})) {
12920: $rule = $specifiedhost;
12921: }
1.150 raeburn 12922: }
1.171 raeburn 12923: $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type} = $rule;
12924: if (ref($currrules{$balancer}) eq 'HASH') {
12925: if ($rule ne $currrules{$balancer}{$type}) {
12926: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 12927: }
12928: } elsif ($rule ne '') {
1.171 raeburn 12929: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 12930: }
12931: }
12932: }
1.171 raeburn 12933: }
12934: my $nochgmsg = &mt('No changes made to Load Balancer settings.');
12935: if ((keys(%changes) > 0) || ($saveloadbalancing)) {
12936: unless (ref($defaultshash{'loadbalancing'}) eq 'HASH') {
12937: $defaultshash{'loadbalancing'} = {};
12938: }
12939: my $putresult = &Apache::lonnet::put_dom('configuration',
12940: \%defaultshash,$dom);
12941: if ($putresult eq 'ok') {
12942: if (keys(%changes) > 0) {
1.252 raeburn 12943: my %toupdate;
1.171 raeburn 12944: if (ref($changes{'delete'}) eq 'ARRAY') {
12945: foreach my $balancer (sort(@{$changes{'delete'}})) {
12946: $resulttext .= '<li>'.&mt('Load Balancing discontinued for: [_1]',$balancer).'</li>';
1.252 raeburn 12947: $toupdate{$balancer} = 1;
1.150 raeburn 12948: }
1.171 raeburn 12949: }
12950: if (ref($changes{'add'}) eq 'ARRAY') {
1.210 raeburn 12951: foreach my $balancer (sort(@{$changes{'add'}})) {
1.171 raeburn 12952: $resulttext .= '<li>'.&mt('Load Balancing enabled for: [_1]',$balancer);
1.252 raeburn 12953: $toupdate{$balancer} = 1;
1.171 raeburn 12954: }
12955: }
12956: if (ref($changes{'curr'}) eq 'HASH') {
12957: foreach my $balancer (sort(keys(%{$changes{'curr'}}))) {
1.253 raeburn 12958: $toupdate{$balancer} = 1;
1.171 raeburn 12959: if (ref($changes{'curr'}{$balancer}) eq 'HASH') {
12960: if ($changes{'curr'}{$balancer}{'targets'}) {
12961: my %offloadstr;
12962: foreach my $sparetype (@sparestypes) {
12963: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
12964: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
12965: $offloadstr{$sparetype} = join(', ',@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
12966: }
12967: }
1.150 raeburn 12968: }
1.171 raeburn 12969: if (keys(%offloadstr) == 0) {
12970: $resulttext .= '<li>'.&mt("Servers to which Load Balance server offloads set to 'None', by default").'</li>';
1.150 raeburn 12971: } else {
1.171 raeburn 12972: my $showoffload;
12973: foreach my $sparetype (@sparestypes) {
12974: $showoffload .= '<i>'.$typetitles{$sparetype}.'</i>: ';
12975: if (defined($offloadstr{$sparetype})) {
12976: $showoffload .= $offloadstr{$sparetype};
12977: } else {
12978: $showoffload .= &mt('None');
12979: }
12980: $showoffload .= (' 'x3);
12981: }
12982: $resulttext .= '<li>'.&mt('By default, Load Balancer: [_1] set to offload to - [_2]',$balancer,$showoffload).'</li>';
1.150 raeburn 12983: }
12984: }
12985: }
1.171 raeburn 12986: if (ref($changes{'curr'}{$balancer}{'rules'}) eq 'HASH') {
12987: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
12988: foreach my $type (@{$alltypes}) {
12989: if ($changes{'curr'}{$balancer}{'rules'}{$type}) {
12990: my $rule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
12991: my $balancetext;
12992: if ($rule eq '') {
12993: $balancetext = $ruletitles{'default'};
1.209 raeburn 12994: } elsif (($rule eq 'homeserver') || ($rule eq 'externalbalancer') ||
1.254 raeburn 12995: ($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
12996: if (($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
1.252 raeburn 12997: foreach my $sparetype (@sparestypes) {
12998: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
12999: map { $toupdate{$_} = 1; } (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
13000: }
13001: }
1.253 raeburn 13002: foreach my $item (@{$alltypes}) {
13003: next if ($item =~ /^_LC_ipchange/);
13004: my $hasrule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$item};
13005: if ($hasrule eq 'homeserver') {
13006: map { $toupdate{$_} = 1; } (keys(%libraryservers));
13007: } else {
13008: unless (($hasrule eq 'default') || ($hasrule eq 'none') || ($hasrule eq 'externalbalancer')) {
13009: if ($servers{$hasrule}) {
13010: $toupdate{$hasrule} = 1;
13011: }
13012: }
13013: }
13014: }
1.254 raeburn 13015: if (($rule eq 'balancer') || ($rule eq 'offloadedto')) {
13016: $balancetext = $ruletitles{$rule};
13017: } else {
13018: my $receiver = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
13019: $balancetext = $ruletitles{'particular'}.' '.$receiver;
13020: if ($receiver) {
13021: $toupdate{$receiver};
13022: }
13023: }
13024: } else {
13025: $balancetext = $ruletitles{$rule};
1.252 raeburn 13026: }
1.171 raeburn 13027: } else {
13028: $balancetext = &mt('offload to [_1]',$defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type});
13029: }
1.210 raeburn 13030: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- balancing for [_2] set to - "[_3]"',$balancer,$titles->{$type},$balancetext).'</li>';
1.150 raeburn 13031: }
13032: }
13033: }
13034: }
1.252 raeburn 13035: if (keys(%toupdate)) {
13036: my %thismachine;
13037: my $updatedhere;
13038: my $cachetime = 60*60*24;
13039: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
13040: foreach my $lonhost (keys(%toupdate)) {
13041: if ($thismachine{$lonhost}) {
13042: unless ($updatedhere) {
13043: &Apache::lonnet::do_cache_new('loadbalancing',$dom,
13044: $defaultshash{'loadbalancing'},
13045: $cachetime);
13046: $updatedhere = 1;
13047: }
13048: } else {
13049: my $cachekey = &escape('loadbalancing').':'.&escape($dom);
13050: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
13051: }
13052: }
13053: }
1.150 raeburn 13054: }
1.171 raeburn 13055: }
13056: if ($resulttext ne '') {
13057: $resulttext = &mt('Changes made:').'<ul>'.$resulttext.'</ul>';
1.150 raeburn 13058: } else {
13059: $resulttext = $nochgmsg;
13060: }
13061: } else {
1.171 raeburn 13062: $resulttext = $nochgmsg;
1.150 raeburn 13063: }
13064: } else {
1.171 raeburn 13065: $resulttext = '<span class="LC_error">'.
13066: &mt('An error occurred: [_1]',$putresult).'</span>';
1.150 raeburn 13067: }
13068: } else {
1.171 raeburn 13069: $resulttext = $nochgmsg;
1.150 raeburn 13070: }
13071: return $resulttext;
13072: }
13073:
1.48 raeburn 13074: sub recurse_check {
13075: my ($chkcats,$categories,$depth,$name) = @_;
13076: if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
13077: my $chg = 0;
13078: for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
13079: my $category = $chkcats->[$depth]{$name}[$j];
13080: my $item;
13081: if ($category eq '') {
13082: $chg ++;
13083: } else {
13084: my $deeper = $depth + 1;
13085: $item = &escape($category).':'.&escape($name).':'.$depth;
13086: if ($chg) {
13087: $categories->{$item} -= $chg;
13088: }
13089: &recurse_check($chkcats,$categories,$deeper,$category);
13090: $deeper --;
13091: }
13092: }
13093: }
13094: return;
13095: }
13096:
13097: sub recurse_cat_deletes {
13098: my ($item,$coursecategories,$deletions) = @_;
13099: my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
13100: my $subdepth = $depth + 1;
13101: if (ref($coursecategories) eq 'HASH') {
13102: foreach my $subitem (keys(%{$coursecategories})) {
13103: my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
13104: if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
13105: delete($coursecategories->{$subitem});
13106: $deletions->{$subitem} = 1;
13107: &recurse_cat_deletes($subitem,$coursecategories,$deletions);
1.168 raeburn 13108: }
1.48 raeburn 13109: }
13110: }
13111: return;
13112: }
13113:
1.125 raeburn 13114: sub get_active_dcs {
13115: my ($dom) = @_;
1.191 raeburn 13116: my $now = time;
13117: my %dompersonnel = &Apache::lonnet::get_domain_roles($dom,['dc'],$now,$now);
1.125 raeburn 13118: my %domcoords;
13119: my $numdcs = 0;
13120: foreach my $server (keys(%dompersonnel)) {
13121: foreach my $user (sort(keys(%{$dompersonnel{$server}}))) {
13122: my ($trole,$uname,$udom,$runame,$rudom,$rsec) = split(/:/,$user);
1.191 raeburn 13123: $domcoords{$uname.':'.$udom} = $dompersonnel{$server}{$user};
1.125 raeburn 13124: }
13125: }
13126: return %domcoords;
13127: }
13128:
13129: sub active_dc_picker {
1.191 raeburn 13130: my ($dom,$numinrow,$inputtype,$name,%currhash) = @_;
1.235 raeburn 13131: my %domcoords = &get_active_dcs($dom);
1.191 raeburn 13132: my @domcoord = keys(%domcoords);
13133: if (keys(%currhash)) {
13134: foreach my $dc (keys(%currhash)) {
13135: unless (exists($domcoords{$dc})) {
13136: push(@domcoord,$dc);
13137: }
13138: }
13139: }
13140: @domcoord = sort(@domcoord);
1.210 raeburn 13141: my $numdcs = scalar(@domcoord);
1.191 raeburn 13142: my $rows = 0;
13143: my $table;
1.125 raeburn 13144: if ($numdcs > 1) {
1.191 raeburn 13145: $table = '<table>';
13146: for (my $i=0; $i<@domcoord; $i++) {
1.125 raeburn 13147: my $rem = $i%($numinrow);
13148: if ($rem == 0) {
13149: if ($i > 0) {
1.191 raeburn 13150: $table .= '</tr>';
1.125 raeburn 13151: }
1.191 raeburn 13152: $table .= '<tr>';
13153: $rows ++;
1.125 raeburn 13154: }
1.191 raeburn 13155: my $check = '';
13156: if ($inputtype eq 'radio') {
13157: if (keys(%currhash) == 0) {
13158: if (!$i) {
13159: $check = ' checked="checked"';
13160: }
13161: } elsif (exists($currhash{$domcoord[$i]})) {
13162: $check = ' checked="checked"';
13163: }
13164: } else {
13165: if (exists($currhash{$domcoord[$i]})) {
13166: $check = ' checked="checked"';
1.125 raeburn 13167: }
13168: }
1.191 raeburn 13169: if ($i == @domcoord - 1) {
1.125 raeburn 13170: my $colsleft = $numinrow - $rem;
13171: if ($colsleft > 1) {
1.191 raeburn 13172: $table .= '<td class="LC_left_item" colspan="'.$colsleft.'">';
1.125 raeburn 13173: } else {
1.191 raeburn 13174: $table .= '<td class="LC_left_item">';
1.125 raeburn 13175: }
13176: } else {
1.191 raeburn 13177: $table .= '<td class="LC_left_item">';
13178: }
13179: my ($dcname,$dcdom) = split(':',$domcoord[$i]);
13180: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
13181: $table .= '<span class="LC_nobreak"><label>'.
13182: '<input type="'.$inputtype.'" name="'.$name.'"'.
13183: ' value="'.$domcoord[$i].'"'.$check.' />'.$user;
13184: if ($user ne $dcname.':'.$dcdom) {
1.219 raeburn 13185: $table .= ' ('.$dcname.':'.$dcdom.')';
1.191 raeburn 13186: }
1.219 raeburn 13187: $table .= '</label></span></td>';
1.191 raeburn 13188: }
13189: $table .= '</tr></table>';
13190: } elsif ($numdcs == 1) {
1.219 raeburn 13191: my ($dcname,$dcdom) = split(':',$domcoord[0]);
13192: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
1.191 raeburn 13193: if ($inputtype eq 'radio') {
1.247 raeburn 13194: $table = '<input type="hidden" name="'.$name.'" value="'.$domcoord[0].'" />'.$user;
1.219 raeburn 13195: if ($user ne $dcname.':'.$dcdom) {
13196: $table .= ' ('.$dcname.':'.$dcdom.')';
13197: }
1.191 raeburn 13198: } else {
13199: my $check;
13200: if (exists($currhash{$domcoord[0]})) {
13201: $check = ' checked="checked"';
1.125 raeburn 13202: }
1.247 raeburn 13203: $table = '<span class="LC_nobreak"><label>'.
13204: '<input type="checkbox" name="'.$name.'" '.
13205: 'value="'.$domcoord[0].'"'.$check.' />'.$user;
1.219 raeburn 13206: if ($user ne $dcname.':'.$dcdom) {
1.220 raeburn 13207: $table .= ' ('.$dcname.':'.$dcdom.')';
1.219 raeburn 13208: }
1.220 raeburn 13209: $table .= '</label></span>';
1.191 raeburn 13210: $rows ++;
1.125 raeburn 13211: }
13212: }
1.191 raeburn 13213: return ($numdcs,$table,$rows);
1.125 raeburn 13214: }
13215:
1.137 raeburn 13216: sub usersession_titles {
13217: return &Apache::lonlocal::texthash(
13218: hosted => 'Hosting of sessions for users from other domains on servers in this domain',
13219: remote => 'Hosting of sessions for users in this domain on servers in other domains',
1.145 raeburn 13220: spares => 'Servers offloaded to, when busy',
1.137 raeburn 13221: version => 'LON-CAPA version requirement',
1.138 raeburn 13222: excludedomain => 'Allow all, but exclude specific domains',
13223: includedomain => 'Deny all, but include specific domains',
1.145 raeburn 13224: primary => 'Primary (checked first)',
1.154 raeburn 13225: default => 'Default',
1.137 raeburn 13226: );
13227: }
13228:
1.152 raeburn 13229: sub id_for_thisdom {
13230: my (%servers) = @_;
13231: my %altids;
13232: foreach my $server (keys(%servers)) {
13233: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
13234: if ($serverhome ne $server) {
13235: $altids{$serverhome} = $server;
13236: }
13237: }
13238: return %altids;
13239: }
13240:
1.150 raeburn 13241: sub count_servers {
13242: my ($currbalancer,%servers) = @_;
13243: my (@spares,$numspares);
13244: foreach my $lonhost (sort(keys(%servers))) {
13245: next if ($currbalancer eq $lonhost);
13246: push(@spares,$lonhost);
13247: }
13248: if ($currbalancer) {
13249: $numspares = scalar(@spares);
13250: } else {
13251: $numspares = scalar(@spares) - 1;
13252: }
13253: return ($numspares,@spares);
13254: }
13255:
13256: sub lonbalance_targets_js {
1.171 raeburn 13257: my ($dom,$types,$servers,$settings) = @_;
1.150 raeburn 13258: my $select = &mt('Select');
13259: my ($alltargets,$allishome,$allinsttypes,@alltypes);
13260: if (ref($servers) eq 'HASH') {
13261: $alltargets = join("','",sort(keys(%{$servers})));
13262: my @homedoms;
13263: foreach my $server (sort(keys(%{$servers}))) {
13264: if (&Apache::lonnet::host_domain($server) eq $dom) {
13265: push(@homedoms,'1');
13266: } else {
13267: push(@homedoms,'0');
13268: }
13269: }
13270: $allishome = join("','",@homedoms);
13271: }
13272: if (ref($types) eq 'ARRAY') {
13273: if (@{$types} > 0) {
13274: @alltypes = @{$types};
13275: }
13276: }
13277: push(@alltypes,'default','_LC_adv','_LC_author','_LC_internetdom','_LC_external');
13278: $allinsttypes = join("','",@alltypes);
1.171 raeburn 13279: my (%currbalancer,%currtargets,%currrules,%existing);
13280: if (ref($settings) eq 'HASH') {
13281: %existing = %{$settings};
13282: }
13283: &get_loadbalancers_config($servers,\%existing,\%currbalancer,
13284: \%currtargets,\%currrules);
1.210 raeburn 13285: my $balancers = join("','",sort(keys(%currbalancer)));
1.150 raeburn 13286: return <<"END";
13287:
13288: <script type="text/javascript">
13289: // <![CDATA[
13290:
1.171 raeburn 13291: currBalancers = new Array('$balancers');
13292:
13293: function toggleTargets(balnum) {
13294: var lonhostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
13295: var prevhostitem = document.getElementById('loadbalancing_prevlonhost_'+balnum);
13296: var balancer = lonhostitem.options[lonhostitem.selectedIndex].value;
13297: var prevbalancer = prevhostitem.value;
13298: var baltotal = document.getElementById('loadbalancing_total').value;
13299: prevhostitem.value = balancer;
13300: if (prevbalancer != '') {
13301: var prevIdx = currBalancers.indexOf(prevbalancer);
13302: if (prevIdx != -1) {
13303: currBalancers.splice(prevIdx,1);
13304: }
13305: }
1.150 raeburn 13306: if (balancer == '') {
1.171 raeburn 13307: hideSpares(balnum);
1.150 raeburn 13308: } else {
1.171 raeburn 13309: var currIdx = currBalancers.indexOf(balancer);
13310: if (currIdx == -1) {
13311: currBalancers.push(balancer);
13312: }
1.150 raeburn 13313: var homedoms = new Array('$allishome');
1.171 raeburn 13314: var ishomedom = homedoms[lonhostitem.selectedIndex];
13315: showSpares(balancer,ishomedom,balnum);
1.150 raeburn 13316: }
1.171 raeburn 13317: balancerChange(balnum,baltotal,'change',prevbalancer,balancer);
1.150 raeburn 13318: return;
13319: }
13320:
1.171 raeburn 13321: function showSpares(balancer,ishomedom,balnum) {
1.150 raeburn 13322: var alltargets = new Array('$alltargets');
13323: var insttypes = new Array('$allinsttypes');
1.151 raeburn 13324: var offloadtypes = new Array('primary','default');
13325:
1.171 raeburn 13326: document.getElementById('loadbalancing_targets_'+balnum).style.display='block';
13327: document.getElementById('loadbalancing_disabled_'+balnum).style.display='none';
1.152 raeburn 13328:
1.151 raeburn 13329: for (var i=0; i<offloadtypes.length; i++) {
13330: var count = 0;
13331: for (var j=0; j<alltargets.length; j++) {
13332: if (alltargets[j] != balancer) {
1.171 raeburn 13333: var item = document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+count);
13334: item.value = alltargets[j];
13335: item.style.textAlign='left';
13336: item.style.textFace='normal';
13337: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+count).innerHTML = alltargets[j];
13338: if (currBalancers.indexOf(alltargets[j]) == -1) {
13339: item.disabled = '';
13340: } else {
13341: item.disabled = 'disabled';
13342: item.checked = false;
13343: }
1.151 raeburn 13344: count ++;
13345: }
1.150 raeburn 13346: }
13347: }
1.151 raeburn 13348: for (var k=0; k<insttypes.length; k++) {
13349: if ((insttypes[k] == '_LC_external') || (insttypes[k] == '_LC_internetdom')) {
1.150 raeburn 13350: if (ishomedom == 1) {
1.171 raeburn 13351: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
13352: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 13353: } else {
1.171 raeburn 13354: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
13355: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.150 raeburn 13356: }
13357: } else {
1.171 raeburn 13358: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
13359: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 13360: }
1.151 raeburn 13361: if ((insttypes[k] != '_LC_external') &&
13362: ((insttypes[k] != '_LC_internetdom') ||
13363: ((insttypes[k] == '_LC_internetdom') && (ishomedom == 1)))) {
1.171 raeburn 13364: var item = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]);
13365: item.options.length = 0;
13366: item.options[0] = new Option("","",true,true);
1.210 raeburn 13367: var idx = 0;
1.151 raeburn 13368: for (var m=0; m<alltargets.length; m++) {
1.171 raeburn 13369: if ((currBalancers.indexOf(alltargets[m]) == -1) && (alltargets[m] != balancer)) {
13370: idx ++;
13371: item.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
1.150 raeburn 13372: }
13373: }
13374: }
13375: }
13376: return;
13377: }
13378:
1.171 raeburn 13379: function hideSpares(balnum) {
1.150 raeburn 13380: var alltargets = new Array('$alltargets');
13381: var insttypes = new Array('$allinsttypes');
13382: var offloadtypes = new Array('primary','default');
13383:
1.171 raeburn 13384: document.getElementById('loadbalancing_targets_'+balnum).style.display='none';
13385: document.getElementById('loadbalancing_disabled_'+balnum).style.display='block';
1.150 raeburn 13386:
13387: var total = alltargets.length - 1;
13388: for (var i=0; i<offloadtypes; i++) {
13389: for (var j=0; j<total; j++) {
1.171 raeburn 13390: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).checked = false;
13391: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).value = '';
13392: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+j).innerHTML = '';
1.151 raeburn 13393: }
1.150 raeburn 13394: }
13395: for (var k=0; k<insttypes.length; k++) {
1.171 raeburn 13396: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
13397: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.151 raeburn 13398: if (insttypes[k] != '_LC_external') {
1.171 raeburn 13399: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).length = 0;
13400: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).options[0] = new Option("","",true,true);
1.150 raeburn 13401: }
13402: }
13403: return;
13404: }
13405:
1.171 raeburn 13406: function checkOffloads(item,balnum,type) {
1.150 raeburn 13407: var alltargets = new Array('$alltargets');
13408: var offloadtypes = new Array('primary','default');
13409: if (item.checked) {
13410: var total = alltargets.length - 1;
13411: var other;
13412: if (type == offloadtypes[0]) {
1.151 raeburn 13413: other = offloadtypes[1];
1.150 raeburn 13414: } else {
1.151 raeburn 13415: other = offloadtypes[0];
1.150 raeburn 13416: }
13417: for (var i=0; i<total; i++) {
1.171 raeburn 13418: var server = document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).value;
1.150 raeburn 13419: if (server == item.value) {
1.171 raeburn 13420: if (document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked) {
13421: document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked = false;
1.150 raeburn 13422: }
13423: }
13424: }
13425: }
13426: return;
13427: }
13428:
1.171 raeburn 13429: function singleServerToggle(balnum,type) {
13430: var offloadtoSelIdx = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex;
1.150 raeburn 13431: if (offloadtoSelIdx == 0) {
1.171 raeburn 13432: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_0').checked = true;
13433: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 13434:
13435: } else {
1.171 raeburn 13436: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_2').checked = true;
13437: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
1.150 raeburn 13438: }
13439: return;
13440: }
13441:
1.171 raeburn 13442: function balanceruleChange(formname,balnum,type) {
1.150 raeburn 13443: if (type == '_LC_external') {
1.171 raeburn 13444: return;
1.150 raeburn 13445: }
1.171 raeburn 13446: var typesRules = getIndicesByName(formname,'loadbalancing_rules_'+balnum+'_'+type);
1.150 raeburn 13447: for (var i=0; i<typesRules.length; i++) {
13448: if (formname.elements[typesRules[i]].checked) {
13449: if (formname.elements[typesRules[i]].value != 'specific') {
1.171 raeburn 13450: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex = 0;
13451: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 13452: } else {
1.171 raeburn 13453: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
13454: }
13455: }
13456: }
13457: return;
13458: }
13459:
13460: function balancerDeleteChange(balnum) {
13461: var hostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
13462: var baltotal = document.getElementById('loadbalancing_total').value;
13463: var addtarget;
13464: var removetarget;
13465: var action = 'delete';
13466: if (document.getElementById('loadbalancing_delete_'+balnum)) {
13467: var lonhost = hostitem.value;
13468: var currIdx = currBalancers.indexOf(lonhost);
13469: if (document.getElementById('loadbalancing_delete_'+balnum).checked) {
13470: if (currIdx != -1) {
13471: currBalancers.splice(currIdx,1);
13472: }
13473: addtarget = lonhost;
13474: } else {
13475: if (currIdx == -1) {
13476: currBalancers.push(lonhost);
13477: }
13478: removetarget = lonhost;
13479: action = 'undelete';
13480: }
13481: balancerChange(balnum,baltotal,action,addtarget,removetarget);
13482: }
13483: return;
13484: }
13485:
13486: function balancerChange(balnum,baltotal,action,addtarget,removetarget) {
13487: if (baltotal > 1) {
13488: var offloadtypes = new Array('primary','default');
13489: var alltargets = new Array('$alltargets');
13490: var insttypes = new Array('$allinsttypes');
13491: for (var i=0; i<baltotal; i++) {
13492: if (i != balnum) {
13493: for (var j=0; j<offloadtypes.length; j++) {
13494: var total = alltargets.length - 1;
13495: for (var k=0; k<total; k++) {
13496: var serveritem = document.getElementById('loadbalancing_target_'+i+'_'+offloadtypes[j]+'_'+k);
13497: var server = serveritem.value;
13498: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
13499: if (server == addtarget) {
13500: serveritem.disabled = '';
13501: }
13502: }
13503: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
13504: if (server == removetarget) {
13505: serveritem.disabled = 'disabled';
13506: serveritem.checked = false;
13507: }
13508: }
13509: }
13510: }
13511: for (var j=0; j<insttypes.length; j++) {
13512: if (insttypes[j] != '_LC_external') {
13513: if (document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j])) {
13514: var singleserver = document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j]);
13515: var currSel = singleserver.selectedIndex;
13516: var currVal = singleserver.options[currSel].value;
13517: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
13518: var numoptions = singleserver.options.length;
13519: var needsnew = 1;
13520: for (var k=0; k<numoptions; k++) {
13521: if (singleserver.options[k] == addtarget) {
13522: needsnew = 0;
13523: break;
13524: }
13525: }
13526: if (needsnew == 1) {
13527: singleserver.options[numoptions] = new Option(addtarget,addtarget,false,false);
13528: }
13529: }
13530: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
13531: singleserver.options.length = 0;
13532: if ((currVal) && (currVal != removetarget)) {
13533: singleserver.options[0] = new Option("","",false,false);
13534: } else {
13535: singleserver.options[0] = new Option("","",true,true);
13536: }
13537: var idx = 0;
13538: for (var m=0; m<alltargets.length; m++) {
13539: if (currBalancers.indexOf(alltargets[m]) == -1) {
13540: idx ++;
13541: if (currVal == alltargets[m]) {
13542: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],true,true);
13543: } else {
13544: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
13545: }
13546: }
13547: }
13548: }
13549: }
13550: }
13551: }
1.150 raeburn 13552: }
13553: }
13554: }
13555: return;
13556: }
13557:
1.152 raeburn 13558: // ]]>
13559: </script>
13560:
13561: END
13562: }
13563:
13564: sub new_spares_js {
13565: my @sparestypes = ('primary','default');
13566: my $types = join("','",@sparestypes);
13567: my $select = &mt('Select');
13568: return <<"END";
13569:
13570: <script type="text/javascript">
13571: // <![CDATA[
13572:
13573: function updateNewSpares(formname,lonhost) {
13574: var types = new Array('$types');
13575: var include = new Array();
13576: var exclude = new Array();
13577: for (var i=0; i<types.length; i++) {
13578: var spareboxes = getIndicesByName(formname,'spare_'+types[i]+'_'+lonhost);
13579: for (var j=0; j<spareboxes.length; j++) {
13580: if (formname.elements[spareboxes[j]].checked) {
13581: exclude.push(formname.elements[spareboxes[j]].value);
13582: } else {
13583: include.push(formname.elements[spareboxes[j]].value);
13584: }
13585: }
13586: }
13587: for (var i=0; i<types.length; i++) {
13588: var newSpare = document.getElementById('newspare_'+types[i]+'_'+lonhost);
13589: var selIdx = newSpare.selectedIndex;
13590: var currnew = newSpare.options[selIdx].value;
13591: var okSpares = new Array();
13592: for (var j=0; j<newSpare.options.length; j++) {
13593: var possible = newSpare.options[j].value;
13594: if (possible != '') {
13595: if (exclude.indexOf(possible) == -1) {
13596: okSpares.push(possible);
13597: } else {
13598: if (currnew == possible) {
13599: selIdx = 0;
13600: }
13601: }
13602: }
13603: }
13604: for (var k=0; k<include.length; k++) {
13605: if (okSpares.indexOf(include[k]) == -1) {
13606: okSpares.push(include[k]);
13607: }
13608: }
13609: okSpares.sort();
13610: newSpare.options.length = 0;
13611: if (selIdx == 0) {
13612: newSpare.options[0] = new Option("$select","",true,true);
13613: } else {
13614: newSpare.options[0] = new Option("$select","",false,false);
13615: }
13616: for (var m=0; m<okSpares.length; m++) {
13617: var idx = m+1;
13618: var selThis = 0;
13619: if (selIdx != 0) {
13620: if (okSpares[m] == currnew) {
13621: selThis = 1;
13622: }
13623: }
13624: if (selThis == 1) {
13625: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],true,true);
13626: } else {
13627: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],false,false);
13628: }
13629: }
13630: }
13631: return;
13632: }
13633:
13634: function checkNewSpares(lonhost,type) {
13635: var newSpare = document.getElementById('newspare_'+type+'_'+lonhost);
13636: var chosen = newSpare.options[newSpare.selectedIndex].value;
13637: if (chosen != '') {
13638: var othertype;
13639: var othernewSpare;
13640: if (type == 'primary') {
13641: othernewSpare = document.getElementById('newspare_default_'+lonhost);
13642: }
13643: if (type == 'default') {
13644: othernewSpare = document.getElementById('newspare_primary_'+lonhost);
13645: }
13646: if (othernewSpare.options[othernewSpare.selectedIndex].value == chosen) {
13647: othernewSpare.selectedIndex = 0;
13648: }
13649: }
13650: return;
13651: }
13652:
13653: // ]]>
13654: </script>
13655:
13656: END
13657:
13658: }
13659:
13660: sub common_domprefs_js {
13661: return <<"END";
13662:
13663: <script type="text/javascript">
13664: // <![CDATA[
13665:
1.150 raeburn 13666: function getIndicesByName(formname,item) {
1.152 raeburn 13667: var group = new Array();
1.150 raeburn 13668: for (var i=0;i<formname.elements.length;i++) {
13669: if (formname.elements[i].name == item) {
1.152 raeburn 13670: group.push(formname.elements[i].id);
1.150 raeburn 13671: }
13672: }
1.152 raeburn 13673: return group;
1.150 raeburn 13674: }
13675:
13676: // ]]>
13677: </script>
13678:
13679: END
1.152 raeburn 13680:
1.150 raeburn 13681: }
13682:
1.165 raeburn 13683: sub recaptcha_js {
13684: my %lt = &captcha_phrases();
13685: return <<"END";
13686:
13687: <script type="text/javascript">
13688: // <![CDATA[
13689:
13690: function updateCaptcha(caller,context) {
13691: var privitem;
13692: var pubitem;
13693: var privtext;
13694: var pubtext;
1.269 raeburn 13695: var versionitem;
13696: var versiontext;
1.165 raeburn 13697: if (document.getElementById(context+'_recaptchapub')) {
13698: pubitem = document.getElementById(context+'_recaptchapub');
13699: } else {
13700: return;
13701: }
13702: if (document.getElementById(context+'_recaptchapriv')) {
13703: privitem = document.getElementById(context+'_recaptchapriv');
13704: } else {
13705: return;
13706: }
13707: if (document.getElementById(context+'_recaptchapubtxt')) {
13708: pubtext = document.getElementById(context+'_recaptchapubtxt');
13709: } else {
13710: return;
13711: }
13712: if (document.getElementById(context+'_recaptchaprivtxt')) {
13713: privtext = document.getElementById(context+'_recaptchaprivtxt');
13714: } else {
13715: return;
13716: }
1.269 raeburn 13717: if (document.getElementById(context+'_recaptchaversion')) {
13718: versionitem = document.getElementById(context+'_recaptchaversion');
13719: } else {
13720: return;
13721: }
13722: if (document.getElementById(context+'_recaptchavertxt')) {
13723: versiontext = document.getElementById(context+'_recaptchavertxt');
13724: } else {
13725: return;
13726: }
1.165 raeburn 13727: if (caller.checked) {
13728: if (caller.value == 'recaptcha') {
13729: pubitem.type = 'text';
13730: privitem.type = 'text';
13731: pubitem.size = '40';
13732: privitem.size = '40';
13733: pubtext.innerHTML = "$lt{'pub'}";
13734: privtext.innerHTML = "$lt{'priv'}";
1.269 raeburn 13735: versionitem.type = 'text';
13736: versionitem.size = '3';
13737: versiontext.innerHTML = "$lt{'ver'}";
1.165 raeburn 13738: } else {
13739: pubitem.type = 'hidden';
13740: privitem.type = 'hidden';
1.269 raeburn 13741: versionitem.type = 'hidden';
1.165 raeburn 13742: pubtext.innerHTML = '';
13743: privtext.innerHTML = '';
1.269 raeburn 13744: versiontext.innerHTML = '';
1.165 raeburn 13745: }
13746: }
13747: return;
13748: }
13749:
13750: // ]]>
13751: </script>
13752:
13753: END
13754:
13755: }
13756:
1.236 raeburn 13757: sub toggle_display_js {
1.192 raeburn 13758: return <<"END";
13759:
13760: <script type="text/javascript">
13761: // <![CDATA[
13762:
1.236 raeburn 13763: function toggleDisplay(domForm,caller) {
13764: if (document.getElementById(caller)) {
13765: var divitem = document.getElementById(caller);
13766: var optionsElement = domForm.coursecredits;
1.264 raeburn 13767: var checkval = 1;
13768: var dispval = 'block';
1.236 raeburn 13769: if (caller == 'emailoptions') {
13770: optionsElement = domForm.cancreate_email;
13771: }
1.257 raeburn 13772: if (caller == 'studentsubmission') {
13773: optionsElement = domForm.postsubmit;
13774: }
1.264 raeburn 13775: if (caller == 'cloneinstcode') {
13776: optionsElement = domForm.canclone;
13777: checkval = 'instcode';
13778: }
1.236 raeburn 13779: if (optionsElement.length) {
1.192 raeburn 13780: var currval;
1.236 raeburn 13781: for (var i=0; i<optionsElement.length; i++) {
13782: if (optionsElement[i].checked) {
13783: currval = optionsElement[i].value;
1.192 raeburn 13784: }
13785: }
1.264 raeburn 13786: if (currval == checkval) {
13787: divitem.style.display = dispval;
1.192 raeburn 13788: } else {
1.236 raeburn 13789: divitem.style.display = 'none';
1.192 raeburn 13790: }
13791: }
13792: }
13793: return;
13794: }
13795:
13796: // ]]>
13797: </script>
13798:
13799: END
13800:
13801: }
13802:
1.165 raeburn 13803: sub captcha_phrases {
13804: return &Apache::lonlocal::texthash (
13805: priv => 'Private key',
13806: pub => 'Public key',
13807: original => 'original (CAPTCHA)',
13808: recaptcha => 'successor (ReCAPTCHA)',
13809: notused => 'unused',
1.269 raeburn 13810: ver => 'ReCAPTCHA version (1 or 2)',
1.165 raeburn 13811: );
13812: }
13813:
1.205 raeburn 13814: sub devalidate_remote_domconfs {
1.212 raeburn 13815: my ($dom,$cachekeys) = @_;
13816: return unless (ref($cachekeys) eq 'HASH');
1.205 raeburn 13817: my %servers = &Apache::lonnet::internet_dom_servers($dom);
13818: my %thismachine;
13819: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
1.267 raeburn 13820: my @posscached = ('domainconfig','domdefaults','ltitools');
1.260 raeburn 13821: if (keys(%servers)) {
1.205 raeburn 13822: foreach my $server (keys(%servers)) {
13823: next if ($thismachine{$server});
1.212 raeburn 13824: my @cached;
13825: foreach my $name (@posscached) {
13826: if ($cachekeys->{$name}) {
13827: push(@cached,&escape($name).':'.&escape($dom));
13828: }
13829: }
13830: if (@cached) {
13831: &Apache::lonnet::remote_devalidate_cache($server,\@cached);
13832: }
1.205 raeburn 13833: }
13834: }
13835: return;
13836: }
13837:
1.3 raeburn 13838: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>