Annotation of loncom/interface/domainprefs.pm, revision 1.277
1.1 raeburn 1: # The LearningOnline Network with CAPA
2: # Handler to set domain-wide configuration settings
3: #
1.277 ! raeburn 4: # $Id: domainprefs.pm,v 1.276 2016/08/15 18:01:09 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: }
1.277 ! raeburn 702: print STDERR "$action num ||$numheaders||\n";
1.110 raeburn 703: if ($numheaders > 1) {
1.64 raeburn 704: my $colspan = '';
1.145 raeburn 705: my $rightcolspan = '';
1.238 raeburn 706: if (($action eq 'rolecolors') || ($action eq 'defaults') ||
1.277 ! raeburn 707: ($action eq 'directorysrch') ||
1.256 raeburn 708: (($action eq 'login') && ($numheaders < 4))) {
1.64 raeburn 709: $colspan = ' colspan="2"';
710: }
1.145 raeburn 711: if ($action eq 'usersessions') {
712: $rightcolspan = ' colspan="3"';
713: }
1.30 raeburn 714: $output .= '
1.3 raeburn 715: <tr>
716: <td>
717: <table class="LC_nested">
718: <tr class="LC_info_row">
1.59 bisitz 719: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[0]->{'col1'}).'</td>
1.145 raeburn 720: <td class="LC_right_item"'.$rightcolspan.'>'.&mt($item->{'header'}->[0]->{'col2'}).'</td>
1.30 raeburn 721: </tr>';
1.69 raeburn 722: $rowtotal ++;
1.230 raeburn 723: if (($action eq 'autoupdate') || ($action eq 'usercreation') || ($action eq 'selfcreation') ||
1.236 raeburn 724: ($action eq 'usermodification') || ($action eq 'defaults') || ($action eq 'coursedefaults') ||
1.277 ! raeburn 725: ($action eq 'selfenrollment') || ($action eq 'usersessions') || ($action eq 'ssl') ||
! 726: ($action eq 'directorysrch')) {
1.230 raeburn 727: $output .= $item->{'print'}->('top',$dom,$settings,\$rowtotal);
1.57 raeburn 728: } elsif ($action eq 'coursecategories') {
1.230 raeburn 729: $output .= $item->{'print'}->('top',$dom,$item,$settings,\$rowtotal);
1.110 raeburn 730: } elsif ($action eq 'login') {
1.256 raeburn 731: if ($numheaders == 4) {
1.168 raeburn 732: $colspan = ' colspan="2"';
733: $output .= &print_login('service',$dom,$confname,$phase,$settings,\$rowtotal);
734: } else {
735: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal);
736: }
1.230 raeburn 737: } elsif (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.163 raeburn 738: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.122 jms 739: } elsif ($action eq 'rolecolors') {
1.30 raeburn 740: $output .= &print_rolecolors($phase,'student',$dom,$confname,$settings,\$rowtotal);
1.6 raeburn 741: }
1.30 raeburn 742: $output .= '
1.6 raeburn 743: </table>
744: </td>
745: </tr>
746: <tr>
747: <td>
748: <table class="LC_nested">
749: <tr class="LC_info_row">
1.230 raeburn 750: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col1'}).'</td>
1.59 bisitz 751: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col2'}).'</td>
1.30 raeburn 752: </tr>';
753: $rowtotal ++;
1.230 raeburn 754: if (($action eq 'autoupdate') || ($action eq 'usercreation') ||
755: ($action eq 'selfcreation') || ($action eq 'selfenrollment') ||
1.275 raeburn 756: ($action eq 'usersessions') || ($action eq 'coursecategories') ||
757: ($action eq 'ssl')) {
1.238 raeburn 758: if ($action eq 'coursecategories') {
759: $output .= &print_coursecategories('middle',$dom,$item,$settings,\$rowtotal);
760: $colspan = ' colspan="2"';
761: } else {
762: $output .= $item->{'print'}->('middle',$dom,$settings,\$rowtotal);
763: }
764: $output .= '
1.63 raeburn 765: </table>
766: </td>
767: </tr>
768: <tr>
769: <td>
770: <table class="LC_nested">
771: <tr class="LC_info_row">
772: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1.224 raeburn 773: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
1.238 raeburn 774: </tr>'."\n";
775: if ($action eq 'coursecategories') {
776: $output .= &print_coursecategories('bottom',$dom,$item,$settings,\$rowtotal);
777: } else {
778: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
779: }
1.63 raeburn 780: $rowtotal ++;
1.236 raeburn 781: } elsif (($action eq 'usermodification') || ($action eq 'coursedefaults') ||
1.277 ! raeburn 782: ($action eq 'defaults') || ($action eq 'directorysrch')) {
1.230 raeburn 783: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1.110 raeburn 784: } elsif ($action eq 'login') {
1.256 raeburn 785: if ($numheaders == 4) {
1.168 raeburn 786: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal).'
787: </table>
788: </td>
789: </tr>
790: <tr>
791: <td>
792: <table class="LC_nested">
793: <tr class="LC_info_row">
794: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1.216 raeburn 795: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td></tr>'.
1.168 raeburn 796: &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
797: $rowtotal ++;
798: } else {
799: $output .= &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
800: }
1.256 raeburn 801: $output .= '
802: </table>
803: </td>
804: </tr>
805: <tr>
806: <td>
807: <table class="LC_nested">
808: <tr class="LC_info_row">';
809: if ($numheaders == 4) {
810: $output .= '
811: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
812: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
813: </tr>';
814: } else {
815: $output .= '
816: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
817: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
818: </tr>';
819: }
820: $rowtotal ++;
821: $output .= &print_login('headtag',$dom,$confname,$phase,$settings,\$rowtotal);
1.102 raeburn 822: } elsif ($action eq 'requestcourses') {
1.247 raeburn 823: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
824: $rowtotal ++;
825: $output .= &print_studentcode($settings,\$rowtotal).'
1.216 raeburn 826: </table>
827: </td>
828: </tr>
829: <tr>
830: <td>
831: <table class="LC_nested">
832: <tr class="LC_info_row">
833: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
834: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
1.242 raeburn 835: &textbookcourses_javascript($settings).
836: &print_textbookcourses($dom,'textbooks',$settings,\$rowtotal).'
837: </table>
838: </td>
839: </tr>
840: <tr>
841: <td>
842: <table class="LC_nested">
843: <tr class="LC_info_row">
844: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
845: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td> </tr>'.
846: &print_textbookcourses($dom,'templates',$settings,\$rowtotal).'
1.235 raeburn 847: </table>
848: </td>
849: </tr>
850: <tr>
851: <td>
852: <table class="LC_nested">
853: <tr class="LC_info_row">
1.242 raeburn 854: <td class="LC_left_item"'.$colspan.' valign="top">'.&mt($item->{'header'}->[4]->{'col1'}).'</td>
855: <td class="LC_right_item" valign="top">'.&mt($item->{'header'}->[4]->{'col2'}).'</td>
1.235 raeburn 856: </tr>'.
857: &print_validation_rows('requestcourses',$dom,$settings,\$rowtotal);
1.163 raeburn 858: } elsif ($action eq 'requestauthor') {
859: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
1.247 raeburn 860: $rowtotal ++;
1.122 jms 861: } elsif ($action eq 'rolecolors') {
1.30 raeburn 862: $output .= &print_rolecolors($phase,'coordinator',$dom,$confname,$settings,\$rowtotal).'
1.6 raeburn 863: </table>
864: </td>
865: </tr>
866: <tr>
867: <td>
868: <table class="LC_nested">
869: <tr class="LC_info_row">
1.69 raeburn 870: <td class="LC_left_item"'.$colspan.' valign="top">'.
871: &mt($item->{'header'}->[2]->{'col1'}).'</td>
872: <td class="LC_right_item" valign="top">'.
873: &mt($item->{'header'}->[2]->{'col2'}).'</td>
1.3 raeburn 874: </tr>'.
1.30 raeburn 875: &print_rolecolors($phase,'author',$dom,$confname,$settings,\$rowtotal).'
1.3 raeburn 876: </table>
877: </td>
878: </tr>
879: <tr>
880: <td>
881: <table class="LC_nested">
882: <tr class="LC_info_row">
1.59 bisitz 883: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
884: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
1.3 raeburn 885: </tr>'.
1.30 raeburn 886: &print_rolecolors($phase,'admin',$dom,$confname,$settings,\$rowtotal);
887: $rowtotal += 2;
1.6 raeburn 888: }
1.3 raeburn 889: } else {
1.30 raeburn 890: $output .= '
1.3 raeburn 891: <tr>
892: <td>
893: <table class="LC_nested">
1.30 raeburn 894: <tr class="LC_info_row">';
1.277 ! raeburn 895: if ($action eq 'login') {
1.30 raeburn 896: $output .= '
1.59 bisitz 897: <td class="LC_left_item" colspan="2">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
1.69 raeburn 898: } elsif ($action eq 'serverstatuses') {
899: $output .= '
900: <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).
901: '<br />('.&mt('Automatic access for Dom. Coords.').')</td>';
902:
1.6 raeburn 903: } else {
1.30 raeburn 904: $output .= '
1.69 raeburn 905: <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
906: }
1.72 raeburn 907: if (defined($item->{'header'}->[0]->{'col3'})) {
908: $output .= '<td class="LC_left_item" valign="top">'.
909: &mt($item->{'header'}->[0]->{'col2'});
910: if ($action eq 'serverstatuses') {
911: $output .= '<br />(<tt>'.&mt('user1:domain1,user2:domain2 etc.').'</tt>)';
912: }
1.69 raeburn 913: } else {
914: $output .= '<td class="LC_right_item" valign="top">'.
915: &mt($item->{'header'}->[0]->{'col2'});
916: }
917: $output .= '</td>';
918: if ($item->{'header'}->[0]->{'col3'}) {
1.150 raeburn 919: if (defined($item->{'header'}->[0]->{'col4'})) {
920: $output .= '<td class="LC_left_item" valign="top">'.
921: &mt($item->{'header'}->[0]->{'col3'});
922: } else {
923: $output .= '<td class="LC_right_item" valign="top">'.
924: &mt($item->{'header'}->[0]->{'col3'});
925: }
1.69 raeburn 926: if ($action eq 'serverstatuses') {
927: $output .= '<br />(<tt>'.&mt('IP1,IP2 etc.').'</tt>)';
928: }
929: $output .= '</td>';
1.6 raeburn 930: }
1.150 raeburn 931: if ($item->{'header'}->[0]->{'col4'}) {
932: $output .= '<td class="LC_right_item" valign="top">'.
933: &mt($item->{'header'}->[0]->{'col4'});
934: }
1.69 raeburn 935: $output .= '</tr>';
1.48 raeburn 936: $rowtotal ++;
1.168 raeburn 937: if ($action eq 'quotas') {
1.86 raeburn 938: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.277 ! raeburn 939: } elsif (($action eq 'autoenroll') || ($action eq 'autocreate') ||
! 940: ($action eq 'contacts') || ($action eq 'serverstatuses') ||
! 941: ($action eq 'loadbalancing') || ($action eq 'ltitools')) {
1.230 raeburn 942: $output .= $item->{'print'}->($dom,$settings,\$rowtotal);
1.46 raeburn 943: } elsif ($action eq 'scantron') {
944: $output .= &print_scantronformat($r,$dom,$confname,$settings,\$rowtotal);
1.118 jms 945: } elsif ($action eq 'helpsettings') {
1.168 raeburn 946: $output .= &print_helpsettings($dom,$confname,$settings,\$rowtotal);
1.121 raeburn 947: }
1.3 raeburn 948: }
1.30 raeburn 949: $output .= '
1.3 raeburn 950: </table>
951: </td>
952: </tr>
1.30 raeburn 953: </table><br />';
954: return ($output,$rowtotal);
1.1 raeburn 955: }
956:
1.3 raeburn 957: sub print_login {
1.168 raeburn 958: my ($caller,$dom,$confname,$phase,$settings,$rowtotal) = @_;
1.110 raeburn 959: my ($css_class,$datatable);
1.6 raeburn 960: my %choices = &login_choices();
1.110 raeburn 961:
1.168 raeburn 962: if ($caller eq 'service') {
1.149 raeburn 963: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.110 raeburn 964: my $choice = $choices{'disallowlogin'};
965: $css_class = ' class="LC_odd_row"';
1.128 raeburn 966: $datatable .= '<tr'.$css_class.'><td>'.$choice.'</td>'.
1.110 raeburn 967: '<td align="right"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1.128 raeburn 968: '<th>'.$choices{'server'}.'</th>'.
969: '<th>'.$choices{'serverpath'}.'</th>'.
970: '<th>'.$choices{'custompath'}.'</th>'.
971: '<th><span class="LC_nobreak">'.$choices{'exempt'}.'</span></th></tr>'."\n";
1.110 raeburn 972: my %disallowed;
973: if (ref($settings) eq 'HASH') {
974: if (ref($settings->{'loginvia'}) eq 'HASH') {
975: %disallowed = %{$settings->{'loginvia'}};
976: }
977: }
978: foreach my $lonhost (sort(keys(%servers))) {
979: my $direct = 'selected="selected"';
1.128 raeburn 980: if (ref($disallowed{$lonhost}) eq 'HASH') {
981: if ($disallowed{$lonhost}{'server'} ne '') {
982: $direct = '';
983: }
1.110 raeburn 984: }
1.115 raeburn 985: $datatable .= '<tr><td>'.$servers{$lonhost}.'</td>'.
1.128 raeburn 986: '<td><select name="'.$lonhost.'_server">'.
1.110 raeburn 987: '<option value=""'.$direct.'>'.$choices{'directlogin'}.
988: '</option>';
1.184 raeburn 989: foreach my $hostid (sort(keys(%servers))) {
1.115 raeburn 990: next if ($servers{$hostid} eq $servers{$lonhost});
1.110 raeburn 991: my $selected = '';
1.128 raeburn 992: if (ref($disallowed{$lonhost}) eq 'HASH') {
993: if ($hostid eq $disallowed{$lonhost}{'server'}) {
994: $selected = 'selected="selected"';
995: }
1.110 raeburn 996: }
997: $datatable .= '<option value="'.$hostid.'"'.$selected.'>'.
998: $servers{$hostid}.'</option>';
999: }
1.128 raeburn 1000: $datatable .= '</select></td>'.
1001: '<td><select name="'.$lonhost.'_serverpath">';
1002: foreach my $path ('','/','/adm/login','/adm/roles','custom') {
1003: my $pathname = $path;
1004: if ($path eq 'custom') {
1005: $pathname = &mt('Custom Path').' ->';
1006: }
1007: my $selected = '';
1008: if (ref($disallowed{$lonhost}) eq 'HASH') {
1009: if ($path eq $disallowed{$lonhost}{'serverpath'}) {
1010: $selected = 'selected="selected"';
1011: }
1012: } elsif ($path eq '') {
1013: $selected = 'selected="selected"';
1014: }
1015: $datatable .= '<option value="'.$path.'"'.$selected.'>'.$pathname.'</option>';
1016: }
1017: $datatable .= '</select></td>';
1018: my ($custom,$exempt);
1019: if (ref($disallowed{$lonhost}) eq 'HASH') {
1020: $custom = $disallowed{$lonhost}{'custompath'};
1021: $exempt = $disallowed{$lonhost}{'exempt'};
1022: }
1023: $datatable .= '<td><input type="text" name="'.$lonhost.'_custompath" size="6" value="'.$custom.'" /></td>'.
1024: '<td><input type="text" name="'.$lonhost.'_exempt" size="8" value="'.$exempt.'" /></td>'.
1025: '</tr>';
1.110 raeburn 1026: }
1027: $datatable .= '</table></td></tr>';
1028: return $datatable;
1.168 raeburn 1029: } elsif ($caller eq 'page') {
1030: my %defaultchecked = (
1031: 'coursecatalog' => 'on',
1.188 raeburn 1032: 'helpdesk' => 'on',
1.168 raeburn 1033: 'adminmail' => 'off',
1034: 'newuser' => 'off',
1035: );
1.188 raeburn 1036: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.168 raeburn 1037: my (%checkedon,%checkedoff);
1.42 raeburn 1038: foreach my $item (@toggles) {
1.168 raeburn 1039: if ($defaultchecked{$item} eq 'on') {
1040: $checkedon{$item} = ' checked="checked" ';
1.42 raeburn 1041: $checkedoff{$item} = ' ';
1.168 raeburn 1042: } elsif ($defaultchecked{$item} eq 'off') {
1043: $checkedoff{$item} = ' checked="checked" ';
1.42 raeburn 1044: $checkedon{$item} = ' ';
1045: }
1.1 raeburn 1046: }
1.168 raeburn 1047: my @images = ('img','logo','domlogo','login');
1048: my @logintext = ('textcol','bgcol');
1049: my @bgs = ('pgbg','mainbg','sidebg');
1050: my @links = ('link','alink','vlink');
1051: my %designhash = &Apache::loncommon::get_domainconf($dom);
1052: my %defaultdesign = %Apache::loncommon::defaultdesign;
1053: my (%is_custom,%designs);
1054: my %defaults = (
1055: font => $defaultdesign{'login.font'},
1056: );
1.6 raeburn 1057: foreach my $item (@images) {
1.168 raeburn 1058: $defaults{$item} = $defaultdesign{'login.'.$item};
1059: $defaults{'showlogo'}{$item} = 1;
1060: }
1061: foreach my $item (@bgs) {
1062: $defaults{'bgs'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 1063: }
1.41 raeburn 1064: foreach my $item (@logintext) {
1.168 raeburn 1065: $defaults{'logintext'}{$item} = $defaultdesign{'login.'.$item};
1.41 raeburn 1066: }
1.168 raeburn 1067: foreach my $item (@links) {
1068: $defaults{'links'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 1069: }
1.168 raeburn 1070: if (ref($settings) eq 'HASH') {
1071: foreach my $item (@toggles) {
1072: if ($settings->{$item} eq '1') {
1073: $checkedon{$item} = ' checked="checked" ';
1074: $checkedoff{$item} = ' ';
1075: } elsif ($settings->{$item} eq '0') {
1076: $checkedoff{$item} = ' checked="checked" ';
1077: $checkedon{$item} = ' ';
1078: }
1079: }
1080: foreach my $item (@images) {
1081: if (defined($settings->{$item})) {
1082: $designs{$item} = $settings->{$item};
1083: $is_custom{$item} = 1;
1084: }
1085: if (defined($settings->{'showlogo'}{$item})) {
1086: $designs{'showlogo'}{$item} = $settings->{'showlogo'}{$item};
1087: }
1088: }
1089: foreach my $item (@logintext) {
1090: if ($settings->{$item} ne '') {
1091: $designs{'logintext'}{$item} = $settings->{$item};
1092: $is_custom{$item} = 1;
1093: }
1094: }
1095: if ($settings->{'font'} ne '') {
1096: $designs{'font'} = $settings->{'font'};
1097: $is_custom{'font'} = 1;
1098: }
1099: foreach my $item (@bgs) {
1100: if ($settings->{$item} ne '') {
1101: $designs{'bgs'}{$item} = $settings->{$item};
1102: $is_custom{$item} = 1;
1103: }
1104: }
1105: foreach my $item (@links) {
1106: if ($settings->{$item} ne '') {
1107: $designs{'links'}{$item} = $settings->{$item};
1108: $is_custom{$item} = 1;
1109: }
1110: }
1111: } else {
1112: if ($designhash{$dom.'.login.font'} ne '') {
1113: $designs{'font'} = $designhash{$dom.'.login.font'};
1114: $is_custom{'font'} = 1;
1115: }
1116: foreach my $item (@images) {
1117: if ($designhash{$dom.'.login.'.$item} ne '') {
1118: $designs{$item} = $designhash{$dom.'.login.'.$item};
1119: $is_custom{$item} = 1;
1120: }
1121: }
1122: foreach my $item (@bgs) {
1123: if ($designhash{$dom.'.login.'.$item} ne '') {
1124: $designs{'bgs'}{$item} = $designhash{$dom.'.login.'.$item};
1125: $is_custom{$item} = 1;
1126: }
1.6 raeburn 1127: }
1.168 raeburn 1128: foreach my $item (@links) {
1129: if ($designhash{$dom.'.login.'.$item} ne '') {
1130: $designs{'links'}{$item} = $designhash{$dom.'.login.'.$item};
1131: $is_custom{$item} = 1;
1132: }
1.6 raeburn 1133: }
1134: }
1.168 raeburn 1135: my %alt_text = &Apache::lonlocal::texthash ( img => 'Log-in banner',
1136: logo => 'Institution Logo',
1137: domlogo => 'Domain Logo',
1138: login => 'Login box');
1139: my $itemcount = 1;
1140: foreach my $item (@toggles) {
1141: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1142: $datatable .=
1143: '<tr'.$css_class.'><td colspan="2">'.$choices{$item}.
1144: '</td><td>'.
1145: '<span class="LC_nobreak"><label><input type="radio" name="'.
1146: $item.'"'.$checkedon{$item}.' value="1" />'.&mt('Yes').
1147: '</label> <label><input type="radio" name="'.$item.'"'.
1148: $checkedoff{$item}.' value="0" />'.&mt('No').'</label></span></td>'.
1149: '</tr>';
1150: $itemcount ++;
1.6 raeburn 1151: }
1.168 raeburn 1152: $datatable .= &display_color_options($dom,$confname,$phase,'login',$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal,\@logintext);
1153: $datatable .= '</tr></table></td></tr>';
1154: } elsif ($caller eq 'help') {
1155: my ($defaulturl,$defaulttype,%url,%type,%lt,%langchoices);
1156: my $switchserver = &check_switchserver($dom,$confname);
1157: my $itemcount = 1;
1158: $defaulturl = '/adm/loginproblems.html';
1159: $defaulttype = 'default';
1160: %lt = &Apache::lonlocal::texthash (
1161: del => 'Delete?',
1162: rep => 'Replace:',
1163: upl => 'Upload:',
1164: default => 'Default',
1165: custom => 'Custom',
1166: );
1167: %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
1168: my @currlangs;
1169: if (ref($settings) eq 'HASH') {
1170: if (ref($settings->{'helpurl'}) eq 'HASH') {
1171: foreach my $key (sort(keys(%{$settings->{'helpurl'}}))) {
1172: next if ($settings->{'helpurl'}{$key} eq '');
1173: $url{$key} = $settings->{'helpurl'}{$key}.'?inhibitmenu=yes';
1174: $type{$key} = 'custom';
1175: unless ($key eq 'nolang') {
1176: push(@currlangs,$key);
1177: }
1178: }
1179: } elsif ($settings->{'helpurl'} ne '') {
1180: $type{'nolang'} = 'custom';
1181: $url{'nolang'} = $settings->{'helpurl'}.'?inhibitmenu=yes';
1.8 raeburn 1182: }
1183: }
1.168 raeburn 1184: foreach my $lang ('nolang',sort(@currlangs)) {
1185: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1186: $datatable .= '<tr'.$css_class.'>';
1187: if ($url{$lang} eq '') {
1188: $url{$lang} = $defaulturl;
1189: }
1190: if ($type{$lang} eq '') {
1191: $type{$lang} = $defaulttype;
1192: }
1193: $datatable .= '<td colspan="2"><span class="LC_nobreak">';
1194: if ($lang eq 'nolang') {
1195: $datatable .= &mt('Log-in help page if no specific language file: [_1]',
1196: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1197: } else {
1198: $datatable .= &mt('Log-in help page for language: [_1] is [_2]',
1199: $langchoices{$lang},
1200: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1201: }
1202: $datatable .= '</span></td>'."\n".
1203: '<td class="LC_left_item">';
1204: if ($type{$lang} eq 'custom') {
1205: $datatable .= '<span class="LC_nobreak"><label>'.
1206: '<input type="checkbox" name="loginhelpurl_del" value="'.$lang.'" />'.
1207: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1208: } else {
1209: $datatable .= $lt{'upl'};
1210: }
1211: $datatable .='<br />';
1212: if ($switchserver) {
1213: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1214: } else {
1215: $datatable .= '<input type="file" name="loginhelpurl_'.$lang.'" />';
1.6 raeburn 1216: }
1.168 raeburn 1217: $datatable .= '</td></tr>';
1218: $itemcount ++;
1.6 raeburn 1219: }
1.168 raeburn 1220: my @addlangs;
1221: foreach my $lang (sort(keys(%langchoices))) {
1222: next if ((grep(/^\Q$lang\E$/,@currlangs)) || ($lang eq 'x_chef'));
1223: push(@addlangs,$lang);
1224: }
1225: if (@addlangs > 0) {
1226: my %toadd;
1227: map { $toadd{$_} = $langchoices{$_} ; } @addlangs;
1228: $toadd{''} = &mt('Select');
1229: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1230: $datatable .= '<tr'.$css_class.'><td class="LC_left_item" colspan="2">'.
1231: &mt('Add log-in help page for a specific language:').' '.
1232: &Apache::loncommon::select_form('','loginhelpurl_add_lang',\%toadd).
1233: '</td><td class="LC_left_item">'.$lt{'upl'}.'<br />';
1234: if ($switchserver) {
1235: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1236: } else {
1237: $datatable .= '<input type="file" name="loginhelpurl_add_file" />';
1.6 raeburn 1238: }
1.168 raeburn 1239: $datatable .= '</td></tr>';
1.169 raeburn 1240: $itemcount ++;
1.6 raeburn 1241: }
1.169 raeburn 1242: $datatable .= &captcha_choice('login',$settings,$itemcount);
1.256 raeburn 1243: } elsif ($caller eq 'headtag') {
1244: my %domservers = &Apache::lonnet::get_servers($dom);
1245: my $choice = $choices{'headtag'};
1246: $css_class = ' class="LC_odd_row"';
1247: $datatable .= '<tr'.$css_class.'><td colspan="2">'.$choice.'</td>'.
1248: '<td align="left"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1249: '<th>'.$choices{'current'}.'</th>'.
1250: '<th>'.$choices{'action'}.'</th>'.
1251: '<th>'.$choices{'exempt'}.'</th></tr>'."\n";
1252: my (%currurls,%currexempt);
1253: if (ref($settings) eq 'HASH') {
1254: if (ref($settings->{'headtag'}) eq 'HASH') {
1255: foreach my $lonhost (keys(%{$settings->{'headtag'}})) {
1256: if (ref($settings->{'headtag'}{$lonhost}) eq 'HASH') {
1257: $currurls{$lonhost} = $settings->{'headtag'}{$lonhost}{'url'};
1258: $currexempt{$lonhost} = $settings->{'headtag'}{$lonhost}{'exempt'};
1259: }
1260: }
1261: }
1262: }
1263: my %lt = &Apache::lonlocal::texthash(
1264: del => 'Delete?',
1265: rep => 'Replace:',
1266: upl => 'Upload:',
1267: curr => 'View contents',
1268: none => 'None',
1269: );
1270: my $switchserver = &check_switchserver($dom,$confname);
1271: foreach my $lonhost (sort(keys(%domservers))) {
1272: my $exempt = &check_exempt_addresses($currexempt{$lonhost});
1273: $datatable .= '<tr><td>'.$domservers{$lonhost}.'</td>';
1274: if ($currurls{$lonhost}) {
1275: $datatable .= '<td class="LC_right_item"><a href="'.
1276: "javascript:void(open('$currurls{$lonhost}?inhibitmenu=yes','Custom_HeadTag',
1277: 'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
1278: '">'.$lt{'curr'}.'</a></td>'.
1279: '<td><span class="LC_nobreak"><label>'.
1280: '<input type="checkbox" name="loginheadtag_del" value="'.$lonhost.'" />'.
1281: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1282: } else {
1283: $datatable .= '<td class="LC_right_item">'.$lt{'none'}.'</td><td>'.$lt{'upl'};
1284: }
1285: $datatable .='<br />';
1286: if ($switchserver) {
1287: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1288: } else {
1289: $datatable .= '<input type="file" name="loginheadtag_'.$lonhost.'" />';
1290: }
1291: $datatable .= '</td><td><input type="textbox" name="loginheadtagexempt_'.$lonhost.'" value="'.$exempt.'" /></td></tr>';
1292: }
1293: $datatable .= '</table></td></tr>';
1.1 raeburn 1294: }
1.6 raeburn 1295: return $datatable;
1296: }
1297:
1298: sub login_choices {
1299: my %choices =
1300: &Apache::lonlocal::texthash (
1.116 bisitz 1301: coursecatalog => 'Display Course/Community Catalog link?',
1.110 raeburn 1302: adminmail => "Display Administrator's E-mail Address?",
1.188 raeburn 1303: helpdesk => 'Display "Contact Helpdesk" link',
1.110 raeburn 1304: disallowlogin => "Login page requests redirected",
1305: hostid => "Server",
1.128 raeburn 1306: server => "Redirect to:",
1307: serverpath => "Path",
1308: custompath => "Custom",
1309: exempt => "Exempt IP(s)",
1.110 raeburn 1310: directlogin => "No redirect",
1311: newuser => "Link to create a user account",
1312: img => "Header",
1313: logo => "Main Logo",
1314: domlogo => "Domain Logo",
1315: login => "Log-in Header",
1316: textcol => "Text color",
1317: bgcol => "Box color",
1318: bgs => "Background colors",
1319: links => "Link colors",
1320: font => "Font color",
1321: pgbg => "Header",
1322: mainbg => "Page",
1323: sidebg => "Login box",
1324: link => "Link",
1325: alink => "Active link",
1326: vlink => "Visited link",
1.256 raeburn 1327: headtag => "Custom markup",
1328: action => "Action",
1329: current => "Current",
1.6 raeburn 1330: );
1331: return %choices;
1332: }
1333:
1334: sub print_rolecolors {
1.30 raeburn 1335: my ($phase,$role,$dom,$confname,$settings,$rowtotal) = @_;
1.6 raeburn 1336: my %choices = &color_font_choices();
1337: my @bgs = ('pgbg','tabbg','sidebg');
1338: my @links = ('link','alink','vlink');
1339: my @images = ('img');
1340: my %alt_text = &Apache::lonlocal::texthash(img => "Banner for $role role");
1.7 albertel 1341: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.6 raeburn 1342: my %defaultdesign = %Apache::loncommon::defaultdesign;
1343: my (%is_custom,%designs);
1.200 raeburn 1344: my %defaults = &role_defaults($role,\@bgs,\@links,\@images);
1.6 raeburn 1345: if (ref($settings) eq 'HASH') {
1346: if (ref($settings->{$role}) eq 'HASH') {
1347: if ($settings->{$role}->{'img'} ne '') {
1348: $designs{'img'} = $settings->{$role}->{'img'};
1349: $is_custom{'img'} = 1;
1350: }
1351: if ($settings->{$role}->{'font'} ne '') {
1352: $designs{'font'} = $settings->{$role}->{'font'};
1353: $is_custom{'font'} = 1;
1354: }
1.97 tempelho 1355: if ($settings->{$role}->{'fontmenu'} ne '') {
1356: $designs{'fontmenu'} = $settings->{$role}->{'fontmenu'};
1357: $is_custom{'fontmenu'} = 1;
1358: }
1.6 raeburn 1359: foreach my $item (@bgs) {
1360: if ($settings->{$role}->{$item} ne '') {
1361: $designs{'bgs'}{$item} = $settings->{$role}->{$item};
1362: $is_custom{$item} = 1;
1363: }
1364: }
1365: foreach my $item (@links) {
1366: if ($settings->{$role}->{$item} ne '') {
1367: $designs{'links'}{$item} = $settings->{$role}->{$item};
1368: $is_custom{$item} = 1;
1369: }
1370: }
1371: }
1372: } else {
1373: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
1374: $designs{img} = $designhash{$dom.'.'.$role.'.img'};
1375: $is_custom{'img'} = 1;
1376: }
1.97 tempelho 1377: if ($designhash{$dom.'.'.$role.'.fontmenu'} ne '') {
1378: $designs{fontmenu} = $designhash{$dom.'.'.$role.'.fontmenu'};
1379: $is_custom{'fontmenu'} = 1;
1380: }
1.6 raeburn 1381: if ($designhash{$dom.'.'.$role.'.font'} ne '') {
1382: $designs{font} = $designhash{$dom.'.'.$role.'.font'};
1383: $is_custom{'font'} = 1;
1384: }
1385: foreach my $item (@bgs) {
1386: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1387: $designs{'bgs'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1388: $is_custom{$item} = 1;
1389:
1390: }
1391: }
1392: foreach my $item (@links) {
1393: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1394: $designs{'links'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1395: $is_custom{$item} = 1;
1396: }
1397: }
1398: }
1399: my $itemcount = 1;
1.30 raeburn 1400: my $datatable = &display_color_options($dom,$confname,$phase,$role,$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal);
1.6 raeburn 1401: $datatable .= '</tr></table></td></tr>';
1402: return $datatable;
1403: }
1404:
1.200 raeburn 1405: sub role_defaults {
1406: my ($role,$bgs,$links,$images,$logintext) = @_;
1.202 raeburn 1407: my %defaults;
1408: unless ((ref($bgs) eq 'ARRAY') && (ref($links) eq 'ARRAY') && (ref($images) eq 'ARRAY')) {
1.200 raeburn 1409: return %defaults;
1410: }
1411: my %defaultdesign = %Apache::loncommon::defaultdesign;
1412: if ($role eq 'login') {
1413: %defaults = (
1414: font => $defaultdesign{$role.'.font'},
1415: );
1416: if (ref($logintext) eq 'ARRAY') {
1417: foreach my $item (@{$logintext}) {
1418: $defaults{'logintext'}{$item} = $defaultdesign{$role.'.'.$item};
1419: }
1420: }
1421: foreach my $item (@{$images}) {
1422: $defaults{'showlogo'}{$item} = 1;
1423: }
1424: } else {
1425: %defaults = (
1426: img => $defaultdesign{$role.'.img'},
1427: font => $defaultdesign{$role.'.font'},
1428: fontmenu => $defaultdesign{$role.'.fontmenu'},
1429: );
1430: }
1431: foreach my $item (@{$bgs}) {
1432: $defaults{'bgs'}{$item} = $defaultdesign{$role.'.'.$item};
1433: }
1434: foreach my $item (@{$links}) {
1435: $defaults{'links'}{$item} = $defaultdesign{$role.'.'.$item};
1436: }
1437: foreach my $item (@{$images}) {
1438: $defaults{$item} = $defaultdesign{$role.'.'.$item};
1439: }
1440: return %defaults;
1441: }
1442:
1.6 raeburn 1443: sub display_color_options {
1.9 raeburn 1444: my ($dom,$confname,$phase,$role,$itemcount,$choices,$is_custom,$defaults,$designs,
1.135 bisitz 1445: $images,$bgs,$links,$alt_text,$rowtotal,$logintext) = @_;
1.159 raeburn 1446: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.6 raeburn 1447: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.176 raeburn 1448: my $datatable = '<tr'.$css_class.'>'.
1.6 raeburn 1449: '<td>'.$choices->{'font'}.'</td>';
1450: if (!$is_custom->{'font'}) {
1.30 raeburn 1451: $datatable .= '<td>'.&mt('Default in use:').' <span id="css_default_'.$role.'_font" style="color: '.$defaults->{'font'}.';">'.$defaults->{'font'}.'</span></td>';
1.6 raeburn 1452: } else {
1453: $datatable .= '<td> </td>';
1454: }
1.174 foxr 1455: my $current_color = $designs->{'font'} ? $designs->{'font'} : $defaults->{'font'};
1456:
1.8 raeburn 1457: $datatable .= '<td><span class="LC_nobreak">'.
1.174 foxr 1458: '<input type="text" class="colorchooser" size="10" name="'.$role.'_font"'.
1.202 raeburn 1459: ' value="'.$current_color.'" /> '.
1.174 foxr 1460: ' </td></tr>';
1.107 raeburn 1461: unless ($role eq 'login') {
1462: $datatable .= '<tr'.$css_class.'>'.
1463: '<td>'.$choices->{'fontmenu'}.'</td>';
1464: if (!$is_custom->{'fontmenu'}) {
1465: $datatable .= '<td>'.&mt('Default in use:').' <span id="css_default_'.$role.'_font" style="color: '.$defaults->{'fontmenu'}.';">'.$defaults->{'fontmenu'}.'</span></td>';
1466: } else {
1467: $datatable .= '<td> </td>';
1468: }
1.202 raeburn 1469: $current_color = $designs->{'fontmenu'} ?
1.174 foxr 1470: $designs->{'fontmenu'} : $defaults->{'fontmenu'};
1.107 raeburn 1471: $datatable .= '<td><span class="LC_nobreak">'.
1.174 foxr 1472: '<input class="colorchooser" type="text" size="10" name="'
1473: .$role.'_fontmenu"'.
1474: ' value="'.$current_color.'" /> '.
1475: ' </td></tr>';
1.97 tempelho 1476: }
1.9 raeburn 1477: my $switchserver = &check_switchserver($dom,$confname);
1.6 raeburn 1478: foreach my $img (@{$images}) {
1.18 albertel 1479: $itemcount ++;
1.6 raeburn 1480: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.8 raeburn 1481: $datatable .= '<tr'.$css_class.'>'.
1.70 raeburn 1482: '<td>'.$choices->{$img};
1.41 raeburn 1483: my ($imgfile,$img_import,$login_hdr_pick,$logincolors);
1.70 raeburn 1484: if ($role eq 'login') {
1485: if ($img eq 'login') {
1486: $login_hdr_pick =
1.135 bisitz 1487: &login_header_options($img,$role,$defaults,$is_custom,$choices);
1.70 raeburn 1488: $logincolors =
1489: &login_text_colors($img,$role,$logintext,$phase,$choices,
1.201 raeburn 1490: $designs,$defaults);
1.70 raeburn 1491: } elsif ($img ne 'domlogo') {
1492: $datatable.= &logo_display_options($img,$defaults,$designs);
1493: }
1494: }
1495: $datatable .= '</td>';
1.6 raeburn 1496: if ($designs->{$img} ne '') {
1497: $imgfile = $designs->{$img};
1.18 albertel 1498: $img_import = ($imgfile =~ m{^/adm/});
1.6 raeburn 1499: } else {
1500: $imgfile = $defaults->{$img};
1501: }
1502: if ($imgfile) {
1.9 raeburn 1503: my ($showfile,$fullsize);
1504: if ($imgfile =~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
1.6 raeburn 1505: my $urldir = $1;
1506: my $filename = $2;
1507: my @info = &Apache::lonnet::stat_file($designs->{$img});
1508: if (@info) {
1509: my $thumbfile = 'tn-'.$filename;
1510: my @thumb=&Apache::lonnet::stat_file($urldir.'/'.$thumbfile);
1511: if (@thumb) {
1512: $showfile = $urldir.'/'.$thumbfile;
1513: } else {
1514: $showfile = $imgfile;
1515: }
1516: } else {
1517: $showfile = '';
1518: }
1519: } elsif ($imgfile =~ m-^/(adm/[^/]+)/([^/]+)$-) {
1.16 raeburn 1520: $showfile = $imgfile;
1.6 raeburn 1521: my $imgdir = $1;
1522: my $filename = $2;
1.159 raeburn 1523: if (-e "$londocroot/$imgdir/tn-".$filename) {
1.6 raeburn 1524: $showfile = "/$imgdir/tn-".$filename;
1525: } else {
1.159 raeburn 1526: my $input = $londocroot.$imgfile;
1527: my $output = "$londocroot/$imgdir/tn-".$filename;
1.6 raeburn 1528: if (!-e $output) {
1.9 raeburn 1529: my ($width,$height) = &thumb_dimensions();
1.16 raeburn 1530: my ($fullwidth,$fullheight) = &check_dimensions($input);
1531: if ($fullwidth ne '' && $fullheight ne '') {
1532: if ($fullwidth > $width && $fullheight > $height) {
1533: my $size = $width.'x'.$height;
1534: system("convert -sample $size $input $output");
1.159 raeburn 1535: $showfile = "/$imgdir/tn-".$filename;
1.16 raeburn 1536: }
1537: }
1.6 raeburn 1538: }
1539: }
1.16 raeburn 1540: }
1.6 raeburn 1541: if ($showfile) {
1.40 raeburn 1542: if ($showfile =~ m{^/(adm|res)/}) {
1543: if ($showfile =~ m{^/res/}) {
1544: my $local_showfile =
1545: &Apache::lonnet::filelocation('',$showfile);
1546: &Apache::lonnet::repcopy($local_showfile);
1547: }
1548: $showfile = &Apache::loncommon::lonhttpdurl($showfile);
1549: }
1550: if ($imgfile) {
1551: if ($imgfile =~ m{^/(adm|res)/}) {
1552: if ($imgfile =~ m{^/res/}) {
1553: my $local_imgfile =
1554: &Apache::lonnet::filelocation('',$imgfile);
1555: &Apache::lonnet::repcopy($local_imgfile);
1556: }
1557: $fullsize = &Apache::loncommon::lonhttpdurl($imgfile);
1558: } else {
1559: $fullsize = $imgfile;
1560: }
1561: }
1.41 raeburn 1562: $datatable .= '<td>';
1563: if ($img eq 'login') {
1.135 bisitz 1564: $datatable .= $login_hdr_pick;
1565: }
1.41 raeburn 1566: $datatable .= &image_changes($is_custom->{$img},$alt_text->{$img},$img_import,
1567: $showfile,$fullsize,$role,$img,$imgfile,$logincolors);
1.6 raeburn 1568: } else {
1.201 raeburn 1569: $datatable .= '<td> </td><td class="LC_left_item">'.
1570: &mt('Upload:').'<br />';
1.6 raeburn 1571: }
1572: } else {
1.201 raeburn 1573: $datatable .= '<td> </td><td class="LC_left_item">'.
1574: &mt('Upload:').'<br />';
1.6 raeburn 1575: }
1.9 raeburn 1576: if ($switchserver) {
1577: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1578: } else {
1.135 bisitz 1579: if ($img ne 'login') { # suppress file selection for Log-in header
1580: $datatable .=' <input type="file" name="'.$role.'_'.$img.'" />';
1581: }
1.9 raeburn 1582: }
1583: $datatable .= '</td></tr>';
1.6 raeburn 1584: }
1585: $itemcount ++;
1586: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1587: $datatable .= '<tr'.$css_class.'>'.
1588: '<td>'.$choices->{'bgs'}.'</td>';
1589: my $bgs_def;
1590: foreach my $item (@{$bgs}) {
1591: if (!$is_custom->{$item}) {
1.70 raeburn 1592: $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 1593: }
1594: }
1595: if ($bgs_def) {
1.8 raeburn 1596: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$bgs_def.'</tr></table></td>';
1.6 raeburn 1597: } else {
1598: $datatable .= '<td> </td>';
1599: }
1600: $datatable .= '<td class="LC_right_item">'.
1601: '<table border="0"><tr>';
1.174 foxr 1602:
1.6 raeburn 1603: foreach my $item (@{$bgs}) {
1.201 raeburn 1604: $datatable .= '<td align="center">'.$choices->{$item};
1.174 foxr 1605: my $color = $designs->{'bgs'}{$item} ? $designs->{'bgs'}{$item} : $defaults->{'bgs'}{$item};
1.6 raeburn 1606: if ($designs->{'bgs'}{$item}) {
1.174 foxr 1607: $datatable .= ' ';
1.6 raeburn 1608: }
1.174 foxr 1609: $datatable .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1.41 raeburn 1610: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.6 raeburn 1611: }
1612: $datatable .= '</tr></table></td></tr>';
1613: $itemcount ++;
1614: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1615: $datatable .= '<tr'.$css_class.'>'.
1616: '<td>'.$choices->{'links'}.'</td>';
1617: my $links_def;
1618: foreach my $item (@{$links}) {
1619: if (!$is_custom->{$item}) {
1.30 raeburn 1620: $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 1621: }
1622: }
1623: if ($links_def) {
1.8 raeburn 1624: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$links_def.'</tr></table></td>';
1.6 raeburn 1625: } else {
1626: $datatable .= '<td> </td>';
1627: }
1628: $datatable .= '<td class="LC_right_item">'.
1629: '<table border="0"><tr>';
1630: foreach my $item (@{$links}) {
1.234 raeburn 1631: my $color = $designs->{'links'}{$item} ? $designs->{'links'}{$item} : $defaults->{'links'}{$item};
1.201 raeburn 1632: $datatable .= '<td align="center">'.$choices->{$item}."\n";
1.6 raeburn 1633: if ($designs->{'links'}{$item}) {
1.174 foxr 1634: $datatable.=' ';
1.6 raeburn 1635: }
1.174 foxr 1636: $datatable .= '<br /><input type="text" size="8" class="colorchooser" name="'.$role.'_'.$item.'" value="'.$color.
1.6 raeburn 1637: '" /></td>';
1638: }
1.30 raeburn 1639: $$rowtotal += $itemcount;
1.3 raeburn 1640: return $datatable;
1641: }
1642:
1.70 raeburn 1643: sub logo_display_options {
1644: my ($img,$defaults,$designs) = @_;
1645: my $checkedon;
1646: if (ref($defaults) eq 'HASH') {
1647: if (ref($defaults->{'showlogo'}) eq 'HASH') {
1648: if ($defaults->{'showlogo'}{$img}) {
1649: $checkedon = 'checked="checked" ';
1650: }
1651: }
1652: }
1653: if (ref($designs) eq 'HASH') {
1654: if (ref($designs->{'showlogo'}) eq 'HASH') {
1655: if (defined($designs->{'showlogo'}{$img})) {
1656: if ($designs->{'showlogo'}{$img} == 0) {
1657: $checkedon = '';
1658: } elsif ($designs->{'showlogo'}{$img} == 1) {
1659: $checkedon = 'checked="checked" ';
1660: }
1661: }
1662: }
1663: }
1664: return '<br /><label> <input type="checkbox" name="'.
1665: 'login_showlogo_'.$img.'" value="1" '.$checkedon.'/>'.
1666: &mt('show').'</label>'."\n";
1667: }
1668:
1.41 raeburn 1669: sub login_header_options {
1.135 bisitz 1670: my ($img,$role,$defaults,$is_custom,$choices) = @_;
1671: my $output = '';
1.41 raeburn 1672: if ((!$is_custom->{'textcol'}) || (!$is_custom->{'bgcol'})) {
1.135 bisitz 1673: $output .= &mt('Text default(s):').'<br />';
1.41 raeburn 1674: if (!$is_custom->{'textcol'}) {
1675: $output .= $choices->{'textcol'}.': '.$defaults->{'logintext'}{'textcol'}.
1676: ' ';
1677: }
1678: if (!$is_custom->{'bgcol'}) {
1679: $output .= $choices->{'bgcol'}.': '.
1680: '<span id="css_'.$role.'_font" style="background-color: '.
1681: $defaults->{'logintext'}{'bgcol'}.';"> </span>';
1682: }
1683: $output .= '<br />';
1684: }
1685: $output .='<br />';
1686: return $output;
1687: }
1688:
1689: sub login_text_colors {
1.201 raeburn 1690: my ($img,$role,$logintext,$phase,$choices,$designs,$defaults) = @_;
1.41 raeburn 1691: my $color_menu = '<table border="0"><tr>';
1692: foreach my $item (@{$logintext}) {
1.201 raeburn 1693: $color_menu .= '<td align="center">'.$choices->{$item};
1694: my $color = $designs->{'logintext'}{$item} ? $designs->{'logintext'}{$item} : $defaults->{'logintext'}{$item};
1695: $color_menu .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1696: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.41 raeburn 1697: }
1698: $color_menu .= '</tr></table><br />';
1699: return $color_menu;
1700: }
1701:
1702: sub image_changes {
1703: my ($is_custom,$alt_text,$img_import,$showfile,$fullsize,$role,$img,$imgfile,$logincolors) = @_;
1704: my $output;
1.135 bisitz 1705: if ($img eq 'login') {
1706: # suppress image for Log-in header
1707: } elsif (!$is_custom) {
1.70 raeburn 1708: if ($img ne 'domlogo') {
1.41 raeburn 1709: $output .= &mt('Default image:').'<br />';
1710: } else {
1711: $output .= &mt('Default in use:').'<br />';
1712: }
1713: }
1.135 bisitz 1714: if ($img eq 'login') { # suppress image for Log-in header
1715: $output .= '<td>'.$logincolors;
1.41 raeburn 1716: } else {
1.135 bisitz 1717: if ($img_import) {
1718: $output .= '<input type="hidden" name="'.$role.'_import_'.$img.'" value="'.$imgfile.'" />';
1719: }
1720: $output .= '<a href="'.$fullsize.'" target="_blank"><img src="'.
1721: $showfile.'" alt="'.$alt_text.'" border="0" /></a></td>';
1722: if ($is_custom) {
1723: $output .= '<td>'.$logincolors.'<span class="LC_nobreak"><label>'.
1724: '<input type="checkbox" name="'.
1725: $role.'_del_'.$img.'" value="1" />'.&mt('Delete?').
1726: '</label> '.&mt('Replace:').'</span><br />';
1727: } else {
1.201 raeburn 1728: $output .= '<td valign="middle">'.$logincolors.&mt('Upload:').'<br />';
1.135 bisitz 1729: }
1.41 raeburn 1730: }
1731: return $output;
1732: }
1733:
1.3 raeburn 1734: sub print_quotas {
1.86 raeburn 1735: my ($dom,$settings,$rowtotal,$action) = @_;
1736: my $context;
1737: if ($action eq 'quotas') {
1738: $context = 'tools';
1739: } else {
1740: $context = $action;
1741: }
1.197 raeburn 1742: my ($datatable,$defaultquota,$authorquota,@usertools,@options,%validations);
1.44 raeburn 1743: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.3 raeburn 1744: my $typecount = 0;
1.101 raeburn 1745: my ($css_class,%titles);
1.86 raeburn 1746: if ($context eq 'requestcourses') {
1.271 raeburn 1747: @usertools = ('official','unofficial','community','textbook','placement');
1.106 raeburn 1748: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 1749: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
1750: %titles = &courserequest_titles();
1.163 raeburn 1751: } elsif ($context eq 'requestauthor') {
1752: @usertools = ('author');
1753: @options = ('norequest','approval','automatic');
1.210 raeburn 1754: %titles = &authorrequest_titles();
1.86 raeburn 1755: } else {
1.162 raeburn 1756: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 1757: %titles = &tool_titles();
1.86 raeburn 1758: }
1.26 raeburn 1759: if (ref($types) eq 'ARRAY') {
1.23 raeburn 1760: foreach my $type (@{$types}) {
1.197 raeburn 1761: my ($currdefquota,$currauthorquota);
1.163 raeburn 1762: unless (($context eq 'requestcourses') ||
1763: ($context eq 'requestauthor')) {
1.86 raeburn 1764: if (ref($settings) eq 'HASH') {
1765: if (ref($settings->{defaultquota}) eq 'HASH') {
1.197 raeburn 1766: $currdefquota = $settings->{defaultquota}->{$type};
1.86 raeburn 1767: } else {
1768: $currdefquota = $settings->{$type};
1769: }
1.197 raeburn 1770: if (ref($settings->{authorquota}) eq 'HASH') {
1771: $currauthorquota = $settings->{authorquota}->{$type};
1772: }
1.78 raeburn 1773: }
1.72 raeburn 1774: }
1.3 raeburn 1775: if (defined($usertypes->{$type})) {
1776: $typecount ++;
1777: $css_class = $typecount%2?' class="LC_odd_row"':'';
1.72 raeburn 1778: $datatable .= '<tr'.$css_class.'>'.
1.3 raeburn 1779: '<td>'.$usertypes->{$type}.'</td>'.
1.72 raeburn 1780: '<td class="LC_left_item">';
1.101 raeburn 1781: if ($context eq 'requestcourses') {
1782: $datatable .= '<table><tr>';
1783: }
1784: my %cell;
1.72 raeburn 1785: foreach my $item (@usertools) {
1.101 raeburn 1786: if ($context eq 'requestcourses') {
1787: my ($curroption,$currlimit);
1788: if (ref($settings) eq 'HASH') {
1789: if (ref($settings->{$item}) eq 'HASH') {
1790: $curroption = $settings->{$item}->{$type};
1791: if ($curroption =~ /^autolimit=(\d*)$/) {
1792: $currlimit = $1;
1793: }
1794: }
1795: }
1796: if (!$curroption) {
1797: $curroption = 'norequest';
1798: }
1799: $datatable .= '<th>'.$titles{$item}.'</th>';
1800: foreach my $option (@options) {
1801: my $val = $option;
1802: if ($option eq 'norequest') {
1803: $val = 0;
1804: }
1805: if ($option eq 'validate') {
1806: my $canvalidate = 0;
1807: if (ref($validations{$item}) eq 'HASH') {
1808: if ($validations{$item}{$type}) {
1809: $canvalidate = 1;
1810: }
1811: }
1812: next if (!$canvalidate);
1813: }
1814: my $checked = '';
1815: if ($option eq $curroption) {
1816: $checked = ' checked="checked"';
1817: } elsif ($option eq 'autolimit') {
1818: if ($curroption =~ /^autolimit/) {
1819: $checked = ' checked="checked"';
1820: }
1821: }
1822: $cell{$item} .= '<span class="LC_nobreak"><label>'.
1823: '<input type="radio" name="crsreq_'.$item.
1824: '_'.$type.'" value="'.$val.'"'.$checked.' />'.
1.127 raeburn 1825: $titles{$option}.'</label>';
1.101 raeburn 1826: if ($option eq 'autolimit') {
1.127 raeburn 1827: $cell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 1828: $item.'_limit_'.$type.'" size="1" '.
1.103 raeburn 1829: 'value="'.$currlimit.'" />';
1.101 raeburn 1830: }
1.127 raeburn 1831: $cell{$item} .= '</span> ';
1.103 raeburn 1832: if ($option eq 'autolimit') {
1.127 raeburn 1833: $cell{$item} .= $titles{'unlimited'};
1.103 raeburn 1834: }
1.101 raeburn 1835: }
1.163 raeburn 1836: } elsif ($context eq 'requestauthor') {
1837: my $curroption;
1838: if (ref($settings) eq 'HASH') {
1839: $curroption = $settings->{$type};
1840: }
1841: if (!$curroption) {
1842: $curroption = 'norequest';
1843: }
1844: foreach my $option (@options) {
1845: my $val = $option;
1846: if ($option eq 'norequest') {
1847: $val = 0;
1848: }
1849: my $checked = '';
1850: if ($option eq $curroption) {
1851: $checked = ' checked="checked"';
1852: }
1853: $datatable .= '<span class="LC_nobreak"><label>'.
1854: '<input type="radio" name="authorreq_'.$type.
1855: '" value="'.$val.'"'.$checked.' />'.
1856: $titles{$option}.'</label></span> ';
1857: }
1.101 raeburn 1858: } else {
1859: my $checked = 'checked="checked" ';
1860: if (ref($settings) eq 'HASH') {
1861: if (ref($settings->{$item}) eq 'HASH') {
1862: if ($settings->{$item}->{$type} == 0) {
1863: $checked = '';
1864: } elsif ($settings->{$item}->{$type} == 1) {
1865: $checked = 'checked="checked" ';
1866: }
1.78 raeburn 1867: }
1.72 raeburn 1868: }
1.101 raeburn 1869: $datatable .= '<span class="LC_nobreak"><label>'.
1870: '<input type="checkbox" name="'.$context.'_'.$item.
1871: '" value="'.$type.'" '.$checked.'/>'.$titles{$item}.
1872: '</label></span> ';
1.72 raeburn 1873: }
1.101 raeburn 1874: }
1875: if ($context eq 'requestcourses') {
1876: $datatable .= '</tr><tr>';
1877: foreach my $item (@usertools) {
1.106 raeburn 1878: $datatable .= '<td style="vertical-align: top">'.$cell{$item}.'</td>';
1.101 raeburn 1879: }
1880: $datatable .= '</tr></table>';
1.72 raeburn 1881: }
1.86 raeburn 1882: $datatable .= '</td>';
1.163 raeburn 1883: unless (($context eq 'requestcourses') ||
1884: ($context eq 'requestauthor')) {
1.86 raeburn 1885: $datatable .=
1.197 raeburn 1886: '<td class="LC_right_item">'.
1887: '<span class="LC_nobreak">'.&mt('Portfolio').': '.
1.3 raeburn 1888: '<input type="text" name="quota_'.$type.
1.72 raeburn 1889: '" value="'.$currdefquota.
1.197 raeburn 1890: '" size="5" /></span>'.(' ' x 2).
1891: '<span class="LC_nobreak">'.&mt('Authoring').': '.
1892: '<input type="text" name="authorquota_'.$type.
1893: '" value="'.$currauthorquota.
1894: '" size="5" /></span></td>';
1.86 raeburn 1895: }
1896: $datatable .= '</tr>';
1.3 raeburn 1897: }
1898: }
1899: }
1.163 raeburn 1900: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 1901: $defaultquota = '20';
1.197 raeburn 1902: $authorquota = '500';
1.86 raeburn 1903: if (ref($settings) eq 'HASH') {
1904: if (ref($settings->{'defaultquota'}) eq 'HASH') {
1905: $defaultquota = $settings->{'defaultquota'}->{'default'};
1906: } elsif (defined($settings->{'default'})) {
1907: $defaultquota = $settings->{'default'};
1908: }
1.197 raeburn 1909: if (ref($settings->{'authorquota'}) eq 'HASH') {
1910: $authorquota = $settings->{'authorquota'}->{'default'};
1911: }
1.3 raeburn 1912: }
1913: }
1914: $typecount ++;
1915: $css_class = $typecount%2?' class="LC_odd_row"':'';
1916: $datatable .= '<tr'.$css_class.'>'.
1.26 raeburn 1917: '<td>'.$othertitle.'</td>'.
1.72 raeburn 1918: '<td class="LC_left_item">';
1.101 raeburn 1919: if ($context eq 'requestcourses') {
1920: $datatable .= '<table><tr>';
1921: }
1922: my %defcell;
1.72 raeburn 1923: foreach my $item (@usertools) {
1.101 raeburn 1924: if ($context eq 'requestcourses') {
1925: my ($curroption,$currlimit);
1926: if (ref($settings) eq 'HASH') {
1927: if (ref($settings->{$item}) eq 'HASH') {
1928: $curroption = $settings->{$item}->{'default'};
1929: if ($curroption =~ /^autolimit=(\d*)$/) {
1930: $currlimit = $1;
1931: }
1932: }
1933: }
1934: if (!$curroption) {
1935: $curroption = 'norequest';
1936: }
1937: $datatable .= '<th>'.$titles{$item}.'</th>';
1938: foreach my $option (@options) {
1939: my $val = $option;
1940: if ($option eq 'norequest') {
1941: $val = 0;
1942: }
1943: if ($option eq 'validate') {
1944: my $canvalidate = 0;
1945: if (ref($validations{$item}) eq 'HASH') {
1946: if ($validations{$item}{'default'}) {
1947: $canvalidate = 1;
1948: }
1949: }
1950: next if (!$canvalidate);
1951: }
1952: my $checked = '';
1953: if ($option eq $curroption) {
1954: $checked = ' checked="checked"';
1955: } elsif ($option eq 'autolimit') {
1956: if ($curroption =~ /^autolimit/) {
1957: $checked = ' checked="checked"';
1958: }
1959: }
1960: $defcell{$item} .= '<span class="LC_nobreak"><label>'.
1961: '<input type="radio" name="crsreq_'.$item.
1962: '_default" value="'.$val.'"'.$checked.' />'.
1963: $titles{$option}.'</label>';
1964: if ($option eq 'autolimit') {
1.127 raeburn 1965: $defcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 1966: $item.'_limit_default" size="1" '.
1967: 'value="'.$currlimit.'" />';
1968: }
1.127 raeburn 1969: $defcell{$item} .= '</span> ';
1.104 raeburn 1970: if ($option eq 'autolimit') {
1.127 raeburn 1971: $defcell{$item} .= $titles{'unlimited'};
1.104 raeburn 1972: }
1.101 raeburn 1973: }
1.163 raeburn 1974: } elsif ($context eq 'requestauthor') {
1975: my $curroption;
1976: if (ref($settings) eq 'HASH') {
1.172 raeburn 1977: $curroption = $settings->{'default'};
1.163 raeburn 1978: }
1979: if (!$curroption) {
1980: $curroption = 'norequest';
1981: }
1982: foreach my $option (@options) {
1983: my $val = $option;
1984: if ($option eq 'norequest') {
1985: $val = 0;
1986: }
1987: my $checked = '';
1988: if ($option eq $curroption) {
1989: $checked = ' checked="checked"';
1990: }
1991: $datatable .= '<span class="LC_nobreak"><label>'.
1992: '<input type="radio" name="authorreq_default"'.
1993: ' value="'.$val.'"'.$checked.' />'.
1994: $titles{$option}.'</label></span> ';
1995: }
1.101 raeburn 1996: } else {
1997: my $checked = 'checked="checked" ';
1998: if (ref($settings) eq 'HASH') {
1999: if (ref($settings->{$item}) eq 'HASH') {
2000: if ($settings->{$item}->{'default'} == 0) {
2001: $checked = '';
2002: } elsif ($settings->{$item}->{'default'} == 1) {
2003: $checked = 'checked="checked" ';
2004: }
1.78 raeburn 2005: }
1.72 raeburn 2006: }
1.101 raeburn 2007: $datatable .= '<span class="LC_nobreak"><label>'.
2008: '<input type="checkbox" name="'.$context.'_'.$item.
2009: '" value="default" '.$checked.'/>'.$titles{$item}.
2010: '</label></span> ';
2011: }
2012: }
2013: if ($context eq 'requestcourses') {
2014: $datatable .= '</tr><tr>';
2015: foreach my $item (@usertools) {
1.106 raeburn 2016: $datatable .= '<td style="vertical-align: top">'.$defcell{$item}.'</td>';
1.72 raeburn 2017: }
1.101 raeburn 2018: $datatable .= '</tr></table>';
1.72 raeburn 2019: }
1.86 raeburn 2020: $datatable .= '</td>';
1.163 raeburn 2021: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.197 raeburn 2022: $datatable .= '<td class="LC_right_item">'.
2023: '<span class="LC_nobreak">'.&mt('Portfolio').': '.
1.86 raeburn 2024: '<input type="text" name="defaultquota" value="'.
1.197 raeburn 2025: $defaultquota.'" size="5" /></span>'.(' ' x2).
2026: '<span class="LC_nobreak">'.&mt('Authoring').': '.
2027: '<input type="text" name="authorquota" value="'.
2028: $authorquota.'" size="5" /></span></td>';
1.86 raeburn 2029: }
2030: $datatable .= '</tr>';
1.72 raeburn 2031: $typecount ++;
2032: $css_class = $typecount%2?' class="LC_odd_row"':'';
2033: $datatable .= '<tr'.$css_class.'>'.
1.197 raeburn 2034: '<td>'.&mt('LON-CAPA Advanced Users').'<br />';
1.104 raeburn 2035: if ($context eq 'requestcourses') {
1.109 raeburn 2036: $datatable .= &mt('(overrides affiliation, if set)').
2037: '</td>'.
2038: '<td class="LC_left_item">'.
2039: '<table><tr>';
1.101 raeburn 2040: } else {
1.109 raeburn 2041: $datatable .= &mt('(overrides affiliation, if checked)').
2042: '</td>'.
2043: '<td class="LC_left_item" colspan="2">'.
2044: '<br />';
1.101 raeburn 2045: }
2046: my %advcell;
1.72 raeburn 2047: foreach my $item (@usertools) {
1.101 raeburn 2048: if ($context eq 'requestcourses') {
2049: my ($curroption,$currlimit);
2050: if (ref($settings) eq 'HASH') {
2051: if (ref($settings->{$item}) eq 'HASH') {
2052: $curroption = $settings->{$item}->{'_LC_adv'};
2053: if ($curroption =~ /^autolimit=(\d*)$/) {
2054: $currlimit = $1;
2055: }
2056: }
2057: }
2058: $datatable .= '<th>'.$titles{$item}.'</th>';
1.104 raeburn 2059: my $checked = '';
2060: if ($curroption eq '') {
2061: $checked = ' checked="checked"';
2062: }
2063: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
2064: '<input type="radio" name="crsreq_'.$item.
2065: '__LC_adv" value=""'.$checked.' />'.
2066: &mt('No override set').'</label></span> ';
1.101 raeburn 2067: foreach my $option (@options) {
2068: my $val = $option;
2069: if ($option eq 'norequest') {
2070: $val = 0;
2071: }
2072: if ($option eq 'validate') {
2073: my $canvalidate = 0;
2074: if (ref($validations{$item}) eq 'HASH') {
2075: if ($validations{$item}{'_LC_adv'}) {
2076: $canvalidate = 1;
2077: }
2078: }
2079: next if (!$canvalidate);
2080: }
2081: my $checked = '';
1.104 raeburn 2082: if ($val eq $curroption) {
1.101 raeburn 2083: $checked = ' checked="checked"';
2084: } elsif ($option eq 'autolimit') {
2085: if ($curroption =~ /^autolimit/) {
2086: $checked = ' checked="checked"';
2087: }
2088: }
2089: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
2090: '<input type="radio" name="crsreq_'.$item.
2091: '__LC_adv" value="'.$val.'"'.$checked.' />'.
2092: $titles{$option}.'</label>';
2093: if ($option eq 'autolimit') {
1.127 raeburn 2094: $advcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 2095: $item.'_limit__LC_adv" size="1" '.
2096: 'value="'.$currlimit.'" />';
2097: }
1.127 raeburn 2098: $advcell{$item} .= '</span> ';
1.104 raeburn 2099: if ($option eq 'autolimit') {
1.127 raeburn 2100: $advcell{$item} .= $titles{'unlimited'};
1.104 raeburn 2101: }
1.101 raeburn 2102: }
1.163 raeburn 2103: } elsif ($context eq 'requestauthor') {
2104: my $curroption;
2105: if (ref($settings) eq 'HASH') {
2106: $curroption = $settings->{'_LC_adv'};
2107: }
2108: my $checked = '';
2109: if ($curroption eq '') {
2110: $checked = ' checked="checked"';
2111: }
2112: $datatable .= '<span class="LC_nobreak"><label>'.
2113: '<input type="radio" name="authorreq__LC_adv"'.
2114: ' value=""'.$checked.' />'.
2115: &mt('No override set').'</label></span> ';
2116: foreach my $option (@options) {
2117: my $val = $option;
2118: if ($option eq 'norequest') {
2119: $val = 0;
2120: }
2121: my $checked = '';
2122: if ($val eq $curroption) {
2123: $checked = ' checked="checked"';
2124: }
2125: $datatable .= '<span class="LC_nobreak"><label>'.
1.173 raeburn 2126: '<input type="radio" name="authorreq__LC_adv"'.
2127: ' value="'.$val.'"'.$checked.' />'.
1.163 raeburn 2128: $titles{$option}.'</label></span> ';
2129: }
1.101 raeburn 2130: } else {
2131: my $checked = 'checked="checked" ';
2132: if (ref($settings) eq 'HASH') {
2133: if (ref($settings->{$item}) eq 'HASH') {
2134: if ($settings->{$item}->{'_LC_adv'} == 0) {
2135: $checked = '';
2136: } elsif ($settings->{$item}->{'_LC_adv'} == 1) {
2137: $checked = 'checked="checked" ';
2138: }
1.79 raeburn 2139: }
1.72 raeburn 2140: }
1.101 raeburn 2141: $datatable .= '<span class="LC_nobreak"><label>'.
2142: '<input type="checkbox" name="'.$context.'_'.$item.
2143: '" value="_LC_adv" '.$checked.'/>'.$titles{$item}.
2144: '</label></span> ';
2145: }
2146: }
2147: if ($context eq 'requestcourses') {
2148: $datatable .= '</tr><tr>';
2149: foreach my $item (@usertools) {
1.106 raeburn 2150: $datatable .= '<td style="vertical-align: top">'.$advcell{$item}.'</td>';
1.72 raeburn 2151: }
1.101 raeburn 2152: $datatable .= '</tr></table>';
1.72 raeburn 2153: }
1.98 raeburn 2154: $datatable .= '</td></tr>';
1.30 raeburn 2155: $$rowtotal += $typecount;
1.3 raeburn 2156: return $datatable;
2157: }
2158:
1.163 raeburn 2159: sub print_requestmail {
2160: my ($dom,$action,$settings,$rowtotal) = @_;
1.208 raeburn 2161: my ($now,$datatable,%currapp);
1.102 raeburn 2162: $now = time;
2163: if (ref($settings) eq 'HASH') {
2164: if (ref($settings->{'notify'}) eq 'HASH') {
2165: if ($settings->{'notify'}{'approval'} ne '') {
1.224 raeburn 2166: map {$currapp{$_}=1;} split(/,/,$settings->{'notify'}{'approval'});
1.102 raeburn 2167: }
2168: }
2169: }
1.191 raeburn 2170: my $numinrow = 2;
1.224 raeburn 2171: my $css_class;
2172: $css_class = ($$rowtotal%2? ' class="LC_odd_row"':'');
1.163 raeburn 2173: my $text;
2174: if ($action eq 'requestcourses') {
2175: $text = &mt('Receive notification of course requests requiring approval');
1.224 raeburn 2176: } elsif ($action eq 'requestauthor') {
2177: $text = &mt('Receive notification of Authoring Space requests requiring approval');
1.163 raeburn 2178: } else {
1.224 raeburn 2179: $text = &mt('Receive notification of queued requests for self-created user accounts requiring approval');
1.163 raeburn 2180: }
1.224 raeburn 2181: $datatable = '<tr'.$css_class.'>'.
1.163 raeburn 2182: ' <td>'.$text.'</td>'.
1.102 raeburn 2183: ' <td class="LC_left_item">';
1.191 raeburn 2184: my ($numdc,$table,$rows) = &active_dc_picker($dom,$numinrow,'checkbox',
1.224 raeburn 2185: $action.'notifyapproval',%currapp);
1.191 raeburn 2186: if ($numdc > 0) {
2187: $datatable .= $table;
1.102 raeburn 2188: } else {
2189: $datatable .= &mt('There are no active Domain Coordinators');
2190: }
2191: $datatable .='</td></tr>';
2192: return $datatable;
2193: }
2194:
1.216 raeburn 2195: sub print_studentcode {
2196: my ($settings,$rowtotal) = @_;
2197: my $rownum = 0;
1.218 raeburn 2198: my ($output,%current);
1.271 raeburn 2199: my @crstypes = ('official','unofficial','community','textbook','placement');
1.248 raeburn 2200: if (ref($settings) eq 'HASH') {
2201: if (ref($settings->{'uniquecode'}) eq 'HASH') {
2202: foreach my $type (@crstypes) {
2203: $current{$type} = $settings->{'uniquecode'}{$type};
2204: }
1.218 raeburn 2205: }
2206: }
2207: $output .= '<tr>'.
2208: '<td class="LC_left_item">'.&mt('Generate unique six character code as course identifier?').'</td>'.
2209: '<td class="LC_left_item">';
2210: foreach my $type (@crstypes) {
2211: my $check = ' ';
2212: if ($current{$type}) {
2213: $check = ' checked="checked" ';
2214: }
2215: $output .= '<span class="LC_nobreak"><label>'.
2216: '<input type="checkbox" name="uniquecode" value="'.$type.'"'.$check.'/>'.
2217: &mt($type).'</label></span>'.(' 'x2).' ';
2218: }
2219: $output .= '</td></tr>';
2220: $$rowtotal ++;
2221: return $output;
1.216 raeburn 2222: }
2223:
2224: sub print_textbookcourses {
1.242 raeburn 2225: my ($dom,$type,$settings,$rowtotal) = @_;
1.216 raeburn 2226: my $rownum = 0;
2227: my $css_class;
2228: my $itemcount = 1;
2229: my $maxnum = 0;
2230: my $bookshash;
2231: if (ref($settings) eq 'HASH') {
1.242 raeburn 2232: $bookshash = $settings->{$type};
1.216 raeburn 2233: }
2234: my %ordered;
2235: if (ref($bookshash) eq 'HASH') {
2236: foreach my $item (keys(%{$bookshash})) {
2237: if (ref($bookshash->{$item}) eq 'HASH') {
2238: my $num = $bookshash->{$item}{'order'};
2239: $ordered{$num} = $item;
2240: }
2241: }
2242: }
2243: my $confname = $dom.'-domainconfig';
2244: my $switchserver = &check_switchserver($dom,$confname);
1.242 raeburn 2245: my $maxnum = scalar(keys(%ordered));
2246: my $datatable;
1.216 raeburn 2247: if (keys(%ordered)) {
2248: my @items = sort { $a <=> $b } keys(%ordered);
2249: for (my $i=0; $i<@items; $i++) {
2250: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2251: my $key = $ordered{$items[$i]};
2252: my %coursehash=&Apache::lonnet::coursedescription($key);
2253: my $coursetitle = $coursehash{'description'};
1.243 raeburn 2254: my ($subject,$title,$author,$publisher,$image,$imgsrc,$cdom,$cnum);
1.216 raeburn 2255: if (ref($bookshash->{$key}) eq 'HASH') {
2256: $subject = $bookshash->{$key}->{'subject'};
2257: $title = $bookshash->{$key}->{'title'};
1.242 raeburn 2258: if ($type eq 'textbooks') {
1.243 raeburn 2259: $publisher = $bookshash->{$key}->{'publisher'};
1.242 raeburn 2260: $author = $bookshash->{$key}->{'author'};
2261: $image = $bookshash->{$key}->{'image'};
2262: if ($image ne '') {
2263: my ($path,$imagefile) = ($image =~ m{^(.+)/([^/]+)$});
2264: my $imagethumb = "$path/tn-".$imagefile;
2265: $imgsrc = '<img src="'.$imagethumb.'" alt="'.&mt('Textbook image').'" />';
2266: }
1.216 raeburn 2267: }
2268: }
1.242 raeburn 2269: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type".'_'."$key','$type'".');"';
1.216 raeburn 2270: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.242 raeburn 2271: .'<select name="'.$type.'_'.$key.'"'.$chgstr.'>';
1.216 raeburn 2272: for (my $k=0; $k<=$maxnum; $k++) {
2273: my $vpos = $k+1;
2274: my $selstr;
2275: if ($k == $i) {
2276: $selstr = ' selected="selected" ';
2277: }
2278: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2279: }
2280: $datatable .= '</select>'.(' 'x2).
1.242 raeburn 2281: '<label><input type="checkbox" name="'.$type.'_del" value="'.$key.'" />'.
1.216 raeburn 2282: &mt('Delete?').'</label></span></td>'.
2283: '<td colspan="2">'.
1.242 raeburn 2284: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_subject_'.$i.'" value="'.$subject.'" /></span> '.
1.216 raeburn 2285: (' 'x2).
1.242 raeburn 2286: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_title_'.$i.'" value="'.$title.'" /></span> ';
2287: if ($type eq 'textbooks') {
2288: $datatable .= (' 'x2).
1.243 raeburn 2289: '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_publisher_'.$i.'" value="'.$publisher.'" /></span> '.
2290: (' 'x2).
1.242 raeburn 2291: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_author_'.$i.'" value="'.$author.'" /></span> '.
2292: (' 'x2).
2293: '<span class="LC_nobreak">'.&mt('Thumbnail:');
2294: if ($image) {
1.267 raeburn 2295: $datatable .= $imgsrc.
1.242 raeburn 2296: '<label><input type="checkbox" name="'.$type.'_image_del"'.
2297: ' value="'.$key.'" />'.&mt('Delete?').'</label></span> '.
2298: '<span class="LC_nobreak"> '.&mt('Replace:').' ';
2299: }
2300: if ($switchserver) {
2301: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2302: } else {
2303: $datatable .= '<input type="file" name="'.$type.'_image_'.$i.'" value="" />';
2304: }
1.216 raeburn 2305: }
1.242 raeburn 2306: $datatable .= '<input type="hidden" name="'.$type.'_id_'.$i.'" value="'.$type.'_'.$key.'" /></span> '.
1.216 raeburn 2307: '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
2308: $coursetitle.'</span></td></tr>'."\n";
2309: $itemcount ++;
2310: }
2311: }
2312: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.242 raeburn 2313: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type"."_addbook_pos','$type'".');"';
1.216 raeburn 2314: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
1.242 raeburn 2315: '<input type="hidden" name="'.$type.'_maxnum" value="'.$maxnum.'" />'."\n".
2316: '<select name="'.$type.'_addbook_pos"'.$chgstr.'>';
1.216 raeburn 2317: for (my $k=0; $k<$maxnum+1; $k++) {
2318: my $vpos = $k+1;
2319: my $selstr;
2320: if ($k == $maxnum) {
2321: $selstr = ' selected="selected" ';
2322: }
2323: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2324: }
2325: $datatable .= '</select> '."\n".
1.242 raeburn 2326: '<input type="checkbox" name="'.$type.'_addbook" value="1" />'.&mt('Add').'</td>'."\n".
1.216 raeburn 2327: '<td colspan="2">'.
1.242 raeburn 2328: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_addbook_subject" value="" /></span> '."\n".
1.216 raeburn 2329: (' 'x2).
1.242 raeburn 2330: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_addbook_title" value="" /></span> '."\n".
2331: (' 'x2);
2332: if ($type eq 'textbooks') {
1.243 raeburn 2333: $datatable .= '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_addbook_publisher" value="" /></span> '."\n".
2334: (' 'x2).
2335: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_addbook_author" value="" /></span> '."\n".
1.242 raeburn 2336: (' 'x2).
2337: '<span class="LC_nobreak">'.&mt('Image:').' ';
2338: if ($switchserver) {
2339: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2340: } else {
2341: $datatable .= '<input type="file" name="'.$type.'_addbook_image" value="" />';
2342: }
1.216 raeburn 2343: }
2344: $datatable .= '</span>'."\n".
2345: '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
1.242 raeburn 2346: &Apache::loncommon::select_dom_form($env{'request.role.domain'},$type.'_addbook_cdom').
2347: '<input type="text" size="25" name="'.$type.'_addbook_cnum" value="" />'.
1.216 raeburn 2348: &Apache::loncommon::selectcourse_link
1.242 raeburn 2349: ('display',$type.'_addbook_cnum',$type.'_addbook_cdom',undef,undef,undef,'Course');
1.216 raeburn 2350: '</span></td>'."\n".
2351: '</tr>'."\n";
2352: $itemcount ++;
2353: return $datatable;
2354: }
2355:
1.217 raeburn 2356: sub textbookcourses_javascript {
1.242 raeburn 2357: my ($settings) = @_;
2358: return unless(ref($settings) eq 'HASH');
2359: my (%ordered,%total,%jstext);
2360: foreach my $type ('textbooks','templates') {
2361: $total{$type} = 0;
2362: if (ref($settings->{$type}) eq 'HASH') {
2363: foreach my $item (keys(%{$settings->{$type}})) {
2364: if (ref($settings->{$type}->{$item}) eq 'HASH') {
2365: my $num = $settings->{$type}->{$item}{'order'};
2366: $ordered{$type}{$num} = $item;
2367: }
2368: }
2369: $total{$type} = scalar(keys(%{$settings->{$type}}));
2370: }
2371: my @jsarray = ();
2372: foreach my $item (sort {$a <=> $b } (keys(%{$ordered{$type}}))) {
2373: push(@jsarray,$ordered{$type}{$item});
2374: }
2375: $jstext{$type} = ' var '.$type.' = Array('."'".join("','",@jsarray)."'".');'."\n";
1.217 raeburn 2376: }
2377: return <<"ENDSCRIPT";
2378: <script type="text/javascript">
2379: // <![CDATA[
1.242 raeburn 2380: function reorderBooks(form,item,caller) {
1.217 raeburn 2381: var changedVal;
1.242 raeburn 2382: $jstext{'textbooks'};
2383: $jstext{'templates'};
2384: var newpos;
2385: var maxh;
2386: if (caller == 'textbooks') {
2387: newpos = 'textbooks_addbook_pos';
2388: maxh = 1 + $total{'textbooks'};
2389: } else {
2390: newpos = 'templates_addbook_pos';
2391: maxh = 1 + $total{'templates'};
2392: }
1.217 raeburn 2393: var current = new Array;
2394: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
2395: if (item == newpos) {
2396: changedVal = newitemVal;
2397: } else {
2398: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
2399: current[newitemVal] = newpos;
2400: }
1.242 raeburn 2401: if (caller == 'textbooks') {
2402: for (var i=0; i<textbooks.length; i++) {
2403: var elementName = 'textbooks_'+textbooks[i];
2404: if (elementName != item) {
2405: if (form.elements[elementName]) {
2406: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2407: current[currVal] = elementName;
2408: }
2409: }
2410: }
2411: }
2412: if (caller == 'templates') {
2413: for (var i=0; i<templates.length; i++) {
2414: var elementName = 'templates_'+templates[i];
2415: if (elementName != item) {
2416: if (form.elements[elementName]) {
2417: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2418: current[currVal] = elementName;
2419: }
1.217 raeburn 2420: }
2421: }
2422: }
2423: var oldVal;
2424: for (var j=0; j<maxh; j++) {
2425: if (current[j] == undefined) {
2426: oldVal = j;
2427: }
2428: }
2429: if (oldVal < changedVal) {
2430: for (var k=oldVal+1; k<=changedVal ; k++) {
2431: var elementName = current[k];
2432: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
2433: }
2434: } else {
2435: for (var k=changedVal; k<oldVal; k++) {
2436: var elementName = current[k];
2437: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
2438: }
2439: }
2440: return;
2441: }
2442:
2443: // ]]>
2444: </script>
2445:
2446: ENDSCRIPT
2447: }
2448:
1.267 raeburn 2449: sub ltitools_javascript {
2450: my ($settings) = @_;
2451: return unless(ref($settings) eq 'HASH');
2452: my (%ordered,$total,%jstext);
2453: $total = 0;
2454: foreach my $item (keys(%{$settings})) {
2455: if (ref($settings->{$item}) eq 'HASH') {
2456: my $num = $settings->{$item}{'order'};
2457: $ordered{$num} = $item;
2458: }
2459: }
2460: $total = scalar(keys(%{$settings}));
2461: my @jsarray = ();
2462: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
2463: push(@jsarray,$ordered{$item});
2464: }
2465: my $jstext = ' var ltitools = Array('."'".join("','",@jsarray)."'".');'."\n";
2466: return <<"ENDSCRIPT";
2467: <script type="text/javascript">
2468: // <![CDATA[
2469: function reorderLTI(form,item) {
2470: var changedVal;
2471: $jstext
2472: var newpos = 'ltitools_add_pos';
2473: var maxh = 1 + $total;
2474: var current = new Array;
2475: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
2476: if (item == newpos) {
2477: changedVal = newitemVal;
2478: } else {
2479: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
2480: current[newitemVal] = newpos;
2481: }
2482: for (var i=0; i<ltitools.length; i++) {
2483: var elementName = 'ltitools_'+ltitools[i];
2484: if (elementName != item) {
2485: if (form.elements[elementName]) {
2486: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2487: current[currVal] = elementName;
2488: }
2489: }
2490: }
2491: var oldVal;
2492: for (var j=0; j<maxh; j++) {
2493: if (current[j] == undefined) {
2494: oldVal = j;
2495: }
2496: }
2497: if (oldVal < changedVal) {
2498: for (var k=oldVal+1; k<=changedVal ; k++) {
2499: var elementName = current[k];
2500: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
2501: }
2502: } else {
2503: for (var k=changedVal; k<oldVal; k++) {
2504: var elementName = current[k];
2505: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
2506: }
2507: }
2508: return;
2509: }
2510:
2511: // ]]>
2512: </script>
2513:
2514: ENDSCRIPT
2515: }
2516:
1.3 raeburn 2517: sub print_autoenroll {
1.30 raeburn 2518: my ($dom,$settings,$rowtotal) = @_;
1.3 raeburn 2519: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
1.274 raeburn 2520: my ($defdom,$runon,$runoff,$coownerson,$coownersoff,$failsafe);
1.3 raeburn 2521: if (ref($settings) eq 'HASH') {
2522: if (exists($settings->{'run'})) {
2523: if ($settings->{'run'} eq '0') {
2524: $runoff = ' checked="checked" ';
2525: $runon = ' ';
2526: } else {
2527: $runon = ' checked="checked" ';
2528: $runoff = ' ';
2529: }
2530: } else {
2531: if ($autorun) {
2532: $runon = ' checked="checked" ';
2533: $runoff = ' ';
2534: } else {
2535: $runoff = ' checked="checked" ';
2536: $runon = ' ';
2537: }
2538: }
1.129 raeburn 2539: if (exists($settings->{'co-owners'})) {
2540: if ($settings->{'co-owners'} eq '0') {
2541: $coownersoff = ' checked="checked" ';
2542: $coownerson = ' ';
2543: } else {
2544: $coownerson = ' checked="checked" ';
2545: $coownersoff = ' ';
2546: }
2547: } else {
2548: $coownersoff = ' checked="checked" ';
2549: $coownerson = ' ';
2550: }
1.3 raeburn 2551: if (exists($settings->{'sender_domain'})) {
2552: $defdom = $settings->{'sender_domain'};
2553: }
1.274 raeburn 2554: if (exists($settings->{'autofailsafe'})) {
2555: $failsafe = $settings->{'autofailsafe'};
2556: }
1.14 raeburn 2557: } else {
2558: if ($autorun) {
2559: $runon = ' checked="checked" ';
2560: $runoff = ' ';
2561: } else {
2562: $runoff = ' checked="checked" ';
2563: $runon = ' ';
2564: }
1.3 raeburn 2565: }
2566: my $domform = &Apache::loncommon::select_dom_form($defdom,'sender_domain',1);
1.39 raeburn 2567: my $notif_sender;
2568: if (ref($settings) eq 'HASH') {
2569: $notif_sender = $settings->{'sender_uname'};
2570: }
1.3 raeburn 2571: my $datatable='<tr class="LC_odd_row">'.
2572: '<td>'.&mt('Auto-enrollment active?').'</td>'.
1.8 raeburn 2573: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 2574: '<input type="radio" name="autoenroll_run"'.
1.8 raeburn 2575: $runon.' value="1" />'.&mt('Yes').'</label> '.
2576: '<label><input type="radio" name="autoenroll_run"'.
1.14 raeburn 2577: $runoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 2578: '</tr><tr>'.
2579: '<td>'.&mt('Notification messages - sender').
1.8 raeburn 2580: '</td><td class="LC_right_item"><span class="LC_nobreak">'.
1.3 raeburn 2581: &mt('username').': '.
2582: '<input type="text" name="sender_uname" value="'.
1.39 raeburn 2583: $notif_sender.'" size="10" /> '.&mt('domain').
1.129 raeburn 2584: ': '.$domform.'</span></td></tr>'.
2585: '<tr class="LC_odd_row">'.
2586: '<td>'.&mt('Automatically assign co-ownership').'</td>'.
2587: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2588: '<input type="radio" name="autoassign_coowners"'.
2589: $coownerson.' value="1" />'.&mt('Yes').'</label> '.
2590: '<label><input type="radio" name="autoassign_coowners"'.
2591: $coownersoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.274 raeburn 2592: '</tr><tr>'.
2593: '<td>'.&mt('Failsafe for no drops when institutional data missing').'</td>'.
2594: '<td class="LC_right_item"><span class="LC_nobreak">'.
2595: '<input type="text" name="autoenroll_failsafe"'.
2596: ' value="'.$failsafe.'" size="4" /></td></tr>';
2597: $$rowtotal += 4;
1.3 raeburn 2598: return $datatable;
2599: }
2600:
2601: sub print_autoupdate {
1.30 raeburn 2602: my ($position,$dom,$settings,$rowtotal) = @_;
1.3 raeburn 2603: my $datatable;
2604: if ($position eq 'top') {
2605: my $updateon = ' ';
2606: my $updateoff = ' checked="checked" ';
2607: my $classlistson = ' ';
2608: my $classlistsoff = ' checked="checked" ';
2609: if (ref($settings) eq 'HASH') {
2610: if ($settings->{'run'} eq '1') {
2611: $updateon = $updateoff;
2612: $updateoff = ' ';
2613: }
2614: if ($settings->{'classlists'} eq '1') {
2615: $classlistson = $classlistsoff;
2616: $classlistsoff = ' ';
2617: }
2618: }
2619: my %title = (
2620: run => 'Auto-update active?',
2621: classlists => 'Update information in classlists?',
2622: );
2623: $datatable = '<tr class="LC_odd_row">'.
2624: '<td>'.&mt($title{'run'}).'</td>'.
1.8 raeburn 2625: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 2626: '<input type="radio" name="autoupdate_run"'.
1.8 raeburn 2627: $updateon.' value="1" />'.&mt('Yes').'</label> '.
2628: '<label><input type="radio" name="autoupdate_run"'.
2629: $updateoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 2630: '</tr><tr>'.
2631: '<td>'.&mt($title{'classlists'}).'</td>'.
1.8 raeburn 2632: '<td class="LC_right_item"><span class="LC_nobreak">'.
2633: '<label><input type="radio" name="classlists"'.
2634: $classlistson.' value="1" />'.&mt('Yes').'</label> '.
2635: '<label><input type="radio" name="classlists"'.
2636: $classlistsoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 2637: '</tr>';
1.30 raeburn 2638: $$rowtotal += 2;
1.131 raeburn 2639: } elsif ($position eq 'middle') {
2640: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
2641: my $numinrow = 3;
2642: my $locknamesettings;
2643: $datatable .= &insttypes_row($settings,$types,$usertypes,
2644: $dom,$numinrow,$othertitle,
2645: 'lockablenames');
2646: $$rowtotal ++;
1.3 raeburn 2647: } else {
1.44 raeburn 2648: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.132 raeburn 2649: my @fields = ('lastname','firstname','middlename','generation',
1.20 raeburn 2650: 'permanentemail','id');
1.33 raeburn 2651: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1.3 raeburn 2652: my $numrows = 0;
1.26 raeburn 2653: if (ref($types) eq 'ARRAY') {
2654: if (@{$types} > 0) {
2655: $datatable =
2656: &usertype_update_row($settings,$usertypes,\%fieldtitles,
2657: \@fields,$types,\$numrows);
1.30 raeburn 2658: $$rowtotal += @{$types};
1.26 raeburn 2659: }
1.3 raeburn 2660: }
2661: $datatable .=
2662: &usertype_update_row($settings,{'default' => $othertitle},
2663: \%fieldtitles,\@fields,['default'],
2664: \$numrows);
1.30 raeburn 2665: $$rowtotal ++;
1.3 raeburn 2666: }
2667: return $datatable;
2668: }
2669:
1.125 raeburn 2670: sub print_autocreate {
2671: my ($dom,$settings,$rowtotal) = @_;
1.191 raeburn 2672: my (%createon,%createoff,%currhash);
1.125 raeburn 2673: my @types = ('xml','req');
2674: if (ref($settings) eq 'HASH') {
2675: foreach my $item (@types) {
2676: $createoff{$item} = ' checked="checked" ';
2677: $createon{$item} = ' ';
2678: if (exists($settings->{$item})) {
2679: if ($settings->{$item}) {
2680: $createon{$item} = ' checked="checked" ';
2681: $createoff{$item} = ' ';
2682: }
2683: }
2684: }
1.210 raeburn 2685: if ($settings->{'xmldc'} ne '') {
1.191 raeburn 2686: $currhash{$settings->{'xmldc'}} = 1;
2687: }
1.125 raeburn 2688: } else {
2689: foreach my $item (@types) {
2690: $createoff{$item} = ' checked="checked" ';
2691: $createon{$item} = ' ';
2692: }
2693: }
2694: $$rowtotal += 2;
1.191 raeburn 2695: my $numinrow = 2;
1.125 raeburn 2696: my $datatable='<tr class="LC_odd_row">'.
2697: '<td>'.&mt('Create pending official courses from XML files').'</td>'.
2698: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2699: '<input type="radio" name="autocreate_xml"'.
2700: $createon{'xml'}.' value="1" />'.&mt('Yes').'</label> '.
2701: '<label><input type="radio" name="autocreate_xml"'.
1.143 raeburn 2702: $createoff{'xml'}.' value="0" />'.&mt('No').'</label></span>'.
2703: '</td></tr><tr>'.
2704: '<td>'.&mt('Create pending requests for official courses (if validated)').'</td>'.
2705: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2706: '<input type="radio" name="autocreate_req"'.
2707: $createon{'req'}.' value="1" />'.&mt('Yes').'</label> '.
2708: '<label><input type="radio" name="autocreate_req"'.
2709: $createoff{'req'}.' value="0" />'.&mt('No').'</label></span>';
1.191 raeburn 2710: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
2711: 'autocreate_xmldc',%currhash);
1.247 raeburn 2712: $datatable .= '</td></tr><tr class="LC_odd_row"><td>';
1.125 raeburn 2713: if ($numdc > 1) {
1.247 raeburn 2714: $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)').
2715: '</td><td class="LC_left_item">';
1.125 raeburn 2716: } else {
1.247 raeburn 2717: $datatable .= &mt('Course creation processed as:').
2718: '</td><td class="LC_right_item">';
1.125 raeburn 2719: }
1.247 raeburn 2720: $datatable .= $dctable.'</td></tr>';
1.191 raeburn 2721: $$rowtotal += $rows;
1.125 raeburn 2722: return $datatable;
2723: }
2724:
1.23 raeburn 2725: sub print_directorysrch {
1.277 ! raeburn 2726: my ($position,$dom,$settings,$rowtotal) = @_;
! 2727: my $datatable;
! 2728: if ($position eq 'top') {
! 2729: my $instsrchon = ' ';
! 2730: my $instsrchoff = ' checked="checked" ';
! 2731: my ($exacton,$containson,$beginson);
! 2732: my $instlocalon = ' ';
! 2733: my $instlocaloff = ' checked="checked" ';
! 2734: if (ref($settings) eq 'HASH') {
! 2735: if ($settings->{'available'} eq '1') {
! 2736: $instsrchon = $instsrchoff;
! 2737: $instsrchoff = ' ';
! 2738: }
! 2739: if ($settings->{'localonly'} eq '1') {
! 2740: $instlocalon = $instlocaloff;
! 2741: $instlocaloff = ' ';
! 2742: }
! 2743: if (ref($settings->{'searchtypes'}) eq 'ARRAY') {
! 2744: foreach my $type (@{$settings->{'searchtypes'}}) {
! 2745: if ($type eq 'exact') {
! 2746: $exacton = ' checked="checked" ';
! 2747: } elsif ($type eq 'contains') {
! 2748: $containson = ' checked="checked" ';
! 2749: } elsif ($type eq 'begins') {
! 2750: $beginson = ' checked="checked" ';
! 2751: }
! 2752: }
! 2753: } else {
! 2754: if ($settings->{'searchtypes'} eq 'exact') {
! 2755: $exacton = ' checked="checked" ';
! 2756: } elsif ($settings->{'searchtypes'} eq 'contains') {
! 2757: $containson = ' checked="checked" ';
! 2758: } elsif ($settings->{'searchtypes'} eq 'specify') {
1.25 raeburn 2759: $exacton = ' checked="checked" ';
2760: $containson = ' checked="checked" ';
2761: }
2762: }
1.277 ! raeburn 2763: }
! 2764: my ($searchtitles,$titleorder) = &sorted_searchtitles();
! 2765: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
! 2766:
! 2767: my $numinrow = 4;
! 2768: my $cansrchrow = 0;
! 2769: $datatable='<tr class="LC_odd_row">'.
! 2770: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Institutional directory search available?').'</span></td>'.
! 2771: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
! 2772: '<input type="radio" name="dirsrch_available"'.
! 2773: $instsrchon.' value="1" />'.&mt('Yes').'</label> '.
! 2774: '<label><input type="radio" name="dirsrch_available"'.
! 2775: $instsrchoff.' value="0" />'.&mt('No').'</label></span></td>'.
! 2776: '</tr><tr>'.
! 2777: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search institution?').'</span></td>'.
! 2778: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
! 2779: '<input type="radio" name="dirsrch_instlocalonly"'.
! 2780: $instlocaloff.' value="0" />'.&mt('Yes').'</label> '.
! 2781: '<label><input type="radio" name="dirsrch_instlocalonly"'.
! 2782: $instlocalon.' value="1" />'.&mt('No').'</label></span></td>'.
! 2783: '</tr>';
! 2784: $$rowtotal += 2;
! 2785: if (ref($usertypes) eq 'HASH') {
! 2786: if (keys(%{$usertypes}) > 0) {
! 2787: $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
! 2788: $numinrow,$othertitle,'cansearch');
! 2789: $cansrchrow = 1;
1.25 raeburn 2790: }
1.23 raeburn 2791: }
1.277 ! raeburn 2792: if ($cansrchrow) {
! 2793: $$rowtotal ++;
! 2794: $datatable .= '<tr>';
! 2795: } else {
! 2796: $datatable .= '<tr class="LC_odd_row">';
1.26 raeburn 2797: }
1.277 ! raeburn 2798: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Supported search methods').
! 2799: '</span></td><td class="LC_left_item" colspan="2"><table><tr>';
! 2800: foreach my $title (@{$titleorder}) {
! 2801: if (defined($searchtitles->{$title})) {
! 2802: my $check = ' ';
! 2803: if (ref($settings) eq 'HASH') {
! 2804: if (ref($settings->{'searchby'}) eq 'ARRAY') {
! 2805: if (grep(/^\Q$title\E$/,@{$settings->{'searchby'}})) {
! 2806: $check = ' checked="checked" ';
! 2807: }
1.39 raeburn 2808: }
1.25 raeburn 2809: }
1.277 ! raeburn 2810: $datatable .= '<td class="LC_left_item">'.
! 2811: '<span class="LC_nobreak"><label>'.
! 2812: '<input type="checkbox" name="searchby" '.
! 2813: 'value="'.$title.'"'.$check.'/>'.
! 2814: $searchtitles->{$title}.'</label></span></td>';
1.25 raeburn 2815: }
2816: }
1.277 ! raeburn 2817: $datatable .= '</tr></table></td></tr>';
! 2818: $$rowtotal ++;
! 2819: if ($cansrchrow) {
! 2820: $datatable .= '<tr class="LC_odd_row">';
! 2821: } else {
! 2822: $datatable .= '<tr>';
! 2823: }
! 2824: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Search latitude').'</span></td>'.
! 2825: '<td class="LC_left_item" colspan="2">'.
! 2826: '<span class="LC_nobreak"><label>'.
! 2827: '<input type="checkbox" name="searchtypes" '.
! 2828: $exacton.' value="exact" />'.&mt('Exact match').
! 2829: '</label> '.
! 2830: '<label><input type="checkbox" name="searchtypes" '.
! 2831: $beginson.' value="begins" />'.&mt('Begins with').
! 2832: '</label> '.
! 2833: '<label><input type="checkbox" name="searchtypes" '.
! 2834: $containson.' value="contains" />'.&mt('Contains').
! 2835: '</label></span></td></tr>';
! 2836: $$rowtotal ++;
1.26 raeburn 2837: } else {
1.277 ! raeburn 2838: my $domsrchon = ' checked="checked" ';
! 2839: my $domsrchoff = ' ';
! 2840: my $domlocalon = ' ';
! 2841: my $domlocaloff = ' checked="checked" ';
! 2842: if (ref($settings) eq 'HASH') {
! 2843: if ($settings->{'lclocalonly'} eq '1') {
! 2844: $domlocalon = $domlocaloff;
! 2845: $domlocaloff = ' ';
! 2846: }
! 2847: if ($settings->{'lcavailable'} eq '0') {
! 2848: $domsrchoff = $domsrchon;
! 2849: $domsrchon = ' ';
! 2850: }
! 2851: }
! 2852: $datatable='<tr class="LC_odd_row">'.
! 2853: '<td colspan="2"><span class ="LC_nobreak">'.&mt('LON-CAPA directory search available?').'</span></td>'.
! 2854: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
! 2855: '<input type="radio" name="dirsrch_domavailable"'.
! 2856: $domsrchon.' value="1" />'.&mt('Yes').'</label> '.
! 2857: '<label><input type="radio" name="dirsrch_domavailable"'.
! 2858: $domsrchoff.' value="0" />'.&mt('No').'</label></span></td>'.
! 2859: '</tr><tr>'.
! 2860: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search LON-CAPA domain?').'</span></td>'.
! 2861: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
! 2862: '<input type="radio" name="dirsrch_domlocalonly"'.
! 2863: $domlocaloff.' value="0" />'.&mt('Yes').'</label> '.
! 2864: '<label><input type="radio" name="dirsrch_domlocalonly"'.
! 2865: $domlocalon.' value="1" />'.&mt('No').'</label></span></td>'.
! 2866: '</tr>';
! 2867: $$rowtotal += 2;
1.26 raeburn 2868: }
1.25 raeburn 2869: return $datatable;
2870: }
2871:
1.28 raeburn 2872: sub print_contacts {
1.30 raeburn 2873: my ($dom,$settings,$rowtotal) = @_;
1.28 raeburn 2874: my $datatable;
2875: my @contacts = ('adminemail','supportemail');
1.134 raeburn 2876: my (%checked,%to,%otheremails,%bccemails);
1.102 raeburn 2877: my @mailings = ('errormail','packagesmail','lonstatusmail','helpdeskmail',
1.203 raeburn 2878: 'requestsmail','updatesmail','idconflictsmail');
1.28 raeburn 2879: foreach my $type (@mailings) {
2880: $otheremails{$type} = '';
2881: }
1.134 raeburn 2882: $bccemails{'helpdeskmail'} = '';
1.28 raeburn 2883: if (ref($settings) eq 'HASH') {
2884: foreach my $item (@contacts) {
2885: if (exists($settings->{$item})) {
2886: $to{$item} = $settings->{$item};
2887: }
2888: }
2889: foreach my $type (@mailings) {
2890: if (exists($settings->{$type})) {
2891: if (ref($settings->{$type}) eq 'HASH') {
2892: foreach my $item (@contacts) {
2893: if ($settings->{$type}{$item}) {
2894: $checked{$type}{$item} = ' checked="checked" ';
2895: }
2896: }
2897: $otheremails{$type} = $settings->{$type}{'others'};
1.134 raeburn 2898: if ($type eq 'helpdeskmail') {
2899: $bccemails{$type} = $settings->{$type}{'bcc'};
2900: }
1.28 raeburn 2901: }
1.89 raeburn 2902: } elsif ($type eq 'lonstatusmail') {
2903: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
1.28 raeburn 2904: }
2905: }
2906: } else {
2907: $to{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
2908: $to{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
2909: $checked{'errormail'}{'adminemail'} = ' checked="checked" ';
2910: $checked{'packagesmail'}{'adminemail'} = ' checked="checked" ';
1.89 raeburn 2911: $checked{'helpdeskmail'}{'supportemail'} = ' checked="checked" ';
2912: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
1.102 raeburn 2913: $checked{'requestsmail'}{'adminemail'} = ' checked="checked" ';
1.190 raeburn 2914: $checked{'updatesmail'}{'adminemail'} = ' checked="checked" ';
1.203 raeburn 2915: $checked{'idconflictsmail'}{'adminemail'} = ' checked="checked" ';
1.28 raeburn 2916: }
2917: my ($titles,$short_titles) = &contact_titles();
2918: my $rownum = 0;
2919: my $css_class;
2920: foreach my $item (@contacts) {
1.69 raeburn 2921: $css_class = $rownum%2?' class="LC_odd_row"':'';
1.30 raeburn 2922: $datatable .= '<tr'.$css_class.'>'.
2923: '<td><span class="LC_nobreak">'.$titles->{$item}.
2924: '</span></td><td class="LC_right_item">'.
1.28 raeburn 2925: '<input type="text" name="'.$item.'" value="'.
2926: $to{$item}.'" /></td></tr>';
1.203 raeburn 2927: $rownum ++;
1.28 raeburn 2928: }
2929: foreach my $type (@mailings) {
1.69 raeburn 2930: $css_class = $rownum%2?' class="LC_odd_row"':'';
1.28 raeburn 2931: $datatable .= '<tr'.$css_class.'>'.
1.30 raeburn 2932: '<td><span class="LC_nobreak">'.
2933: $titles->{$type}.': </span></td>'.
1.28 raeburn 2934: '<td class="LC_left_item">'.
2935: '<span class="LC_nobreak">';
2936: foreach my $item (@contacts) {
2937: $datatable .= '<label>'.
2938: '<input type="checkbox" name="'.$type.'"'.
2939: $checked{$type}{$item}.
2940: ' value="'.$item.'" />'.$short_titles->{$item}.
2941: '</label> ';
2942: }
2943: $datatable .= '</span><br />'.&mt('Others').': '.
2944: '<input type="text" name="'.$type.'_others" '.
1.134 raeburn 2945: 'value="'.$otheremails{$type}.'" />';
2946: if ($type eq 'helpdeskmail') {
1.136 raeburn 2947: $datatable .= '<br />'.&mt('Bcc:').(' 'x6).
1.134 raeburn 2948: '<input type="text" name="'.$type.'_bcc" '.
2949: 'value="'.$bccemails{$type}.'" />';
2950: }
2951: $datatable .= '</td></tr>'."\n";
1.203 raeburn 2952: $rownum ++;
1.28 raeburn 2953: }
1.203 raeburn 2954: my %choices;
2955: $choices{'reporterrors'} = &mt('E-mail error reports to [_1]',
2956: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
2957: &mt('LON-CAPA core group - MSU'),600,500));
2958: $choices{'reportupdates'} = &mt('E-mail record of completed LON-CAPA updates to [_1]',
2959: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
2960: &mt('LON-CAPA core group - MSU'),600,500));
2961: my @toggles = ('reporterrors','reportupdates');
2962: my %defaultchecked = ('reporterrors' => 'on',
2963: 'reportupdates' => 'on');
2964: (my $reports,$rownum) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
2965: \%choices,$rownum);
2966: $datatable .= $reports;
1.30 raeburn 2967: $$rowtotal += $rownum;
1.28 raeburn 2968: return $datatable;
2969: }
2970:
1.118 jms 2971: sub print_helpsettings {
1.168 raeburn 2972: my ($dom,$confname,$settings,$rowtotal) = @_;
2973: my ($datatable,$itemcount);
1.166 raeburn 2974: $itemcount = 1;
1.168 raeburn 2975: my (%choices,%defaultchecked,@toggles);
2976: $choices{'submitbugs'} = &mt('Display link to: [_1]?',
2977: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
2978: &mt('LON-CAPA bug tracker'),600,500));
2979: %defaultchecked = ('submitbugs' => 'on');
2980: @toggles = ('submitbugs',);
1.166 raeburn 2981:
1.168 raeburn 2982: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
2983: \%choices,$itemcount);
1.166 raeburn 2984: return $datatable;
1.121 raeburn 2985: }
2986:
2987: sub radiobutton_prefs {
1.192 raeburn 2988: my ($settings,$toggles,$defaultchecked,$choices,$itemcount,$onclick,
1.257 raeburn 2989: $additional,$align) = @_;
1.121 raeburn 2990: return unless ((ref($toggles) eq 'ARRAY') && (ref($defaultchecked) eq 'HASH') &&
2991: (ref($choices) eq 'HASH'));
2992:
1.170 raeburn 2993: my (%checkedon,%checkedoff,$datatable,$css_class);
1.121 raeburn 2994:
2995: foreach my $item (@{$toggles}) {
2996: if ($defaultchecked->{$item} eq 'on') {
1.118 jms 2997: $checkedon{$item} = ' checked="checked" ';
2998: $checkedoff{$item} = ' ';
1.121 raeburn 2999: } elsif ($defaultchecked->{$item} eq 'off') {
1.118 jms 3000: $checkedoff{$item} = ' checked="checked" ';
3001: $checkedon{$item} = ' ';
3002: }
3003: }
3004: if (ref($settings) eq 'HASH') {
1.121 raeburn 3005: foreach my $item (@{$toggles}) {
1.118 jms 3006: if ($settings->{$item} eq '1') {
3007: $checkedon{$item} = ' checked="checked" ';
3008: $checkedoff{$item} = ' ';
3009: } elsif ($settings->{$item} eq '0') {
3010: $checkedoff{$item} = ' checked="checked" ';
3011: $checkedon{$item} = ' ';
3012: }
3013: }
1.121 raeburn 3014: }
1.192 raeburn 3015: if ($onclick) {
3016: $onclick = ' onclick="'.$onclick.'"';
3017: }
1.121 raeburn 3018: foreach my $item (@{$toggles}) {
1.118 jms 3019: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.121 raeburn 3020: $datatable .=
1.192 raeburn 3021: '<tr'.$css_class.'><td valign="top">'.
3022: '<span class="LC_nobreak">'.$choices->{$item}.
1.257 raeburn 3023: '</span></td>';
3024: if ($align eq 'left') {
3025: $datatable .= '<td class="LC_left_item">';
3026: } else {
3027: $datatable .= '<td class="LC_right_item">';
3028: }
3029: $datatable .=
3030: '<span class="LC_nobreak">'.
1.118 jms 3031: '<label><input type="radio" name="'.
1.192 raeburn 3032: $item.'" '.$checkedon{$item}.' value="1"'.$onclick.' />'.&mt('Yes').
1.118 jms 3033: '</label> <label><input type="radio" name="'.$item.'" '.
1.192 raeburn 3034: $checkedoff{$item}.' value="0"'.$onclick.' />'.&mt('No').'</label>'.
3035: '</span>'.$additional.
3036: '</td>'.
1.118 jms 3037: '</tr>';
3038: $itemcount ++;
1.121 raeburn 3039: }
3040: return ($datatable,$itemcount);
3041: }
3042:
1.267 raeburn 3043: sub print_ltitools {
3044: my ($dom,$settings,$rowtotal) = @_;
3045: my $rownum = 0;
3046: my $css_class;
3047: my $itemcount = 1;
3048: my $maxnum = 0;
3049: my %ordered;
3050: if (ref($settings) eq 'HASH') {
3051: foreach my $item (keys(%{$settings})) {
3052: if (ref($settings->{$item}) eq 'HASH') {
3053: my $num = $settings->{$item}{'order'};
3054: $ordered{$num} = $item;
3055: }
3056: }
3057: }
3058: my $confname = $dom.'-domainconfig';
3059: my $switchserver = &check_switchserver($dom,$confname);
3060: my $maxnum = scalar(keys(%ordered));
3061: my $datatable = <itools_javascript($settings);
3062: my %lt = <itools_names();
3063: my @courseroles = ('cc','in','ta','ep','st');
3064: my @ltiroles = qw(Instructor ContentDeveloper TeachingAssistant Learner);
3065: my @fields = ('fullname','firstname','lastname','email','user','roles');
3066: if (keys(%ordered)) {
3067: my @items = sort { $a <=> $b } keys(%ordered);
3068: for (my $i=0; $i<@items; $i++) {
3069: $css_class = $itemcount%2?' class="LC_odd_row"':'';
3070: my $item = $ordered{$items[$i]};
3071: my ($title,$key,$secret,$url,$imgsrc,$version);
3072: if (ref($settings->{$item}) eq 'HASH') {
3073: $title = $settings->{$item}->{'title'};
3074: $url = $settings->{$item}->{'url'};
3075: $key = $settings->{$item}->{'key'};
3076: $secret = $settings->{$item}->{'secret'};
3077: my $image = $settings->{$item}->{'image'};
3078: if ($image ne '') {
3079: $imgsrc = '<img src="'.$image.'" alt="'.&mt('Tool Provider icon').'" />';
3080: }
3081: }
3082: my $chgstr = ' onchange="javascript:reorderLTI(this.form,'."'ltitools_".$item."'".');"';
3083: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
3084: .'<select name="ltitools_'.$item.'"'.$chgstr.'>';
3085: for (my $k=0; $k<=$maxnum; $k++) {
3086: my $vpos = $k+1;
3087: my $selstr;
3088: if ($k == $i) {
3089: $selstr = ' selected="selected" ';
3090: }
3091: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
3092: }
3093: $datatable .= '</select>'.(' 'x2).
3094: '<label><input type="checkbox" name="ltitools_del" value="'.$item.'" />'.
3095: &mt('Delete?').'</label></span></td>'.
3096: '<td colspan="2">'.
3097: '<fieldset><legend>'.&mt('Required settings').'</legend>'.
3098: '<span class="LC_nobreak">'.$lt{'title'}.':<input type="text" size="30" name="ltitools_title_'.$i.'" value="'.$title.'" /></span> '.
3099: (' 'x2).
3100: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="ltitools_version_'.$i.'">'.
3101: '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '.
3102: (' 'x2).
3103: '<span class="LC_nobreak">'.$lt{'msgtype'}.':<select name="ltitools_msgtype_'.$i.'">'.
3104: '<option value="basic-lti-launch-request" selected="selected">Launch</option></select></span> '.
3105: '<br /><br />'.
3106: '<span class="LC_nobreak">'.$lt{'url'}.':<input type="text" size="30" name="ltitools_url_'.$i.'"'.
3107: ' value="'.$url.'" /></span>'.
3108: (' 'x2).
3109: '<span class="LC_nobreak">'.$lt{'key'}.
3110: '<input type="text" size="25" name="ltitools_key_'.$i.'" value="'.$key.'" /></span> '.
3111: (' 'x2).
3112: '<span class="LC_nobreak">'.$lt{'secret'}.':'.
3113: '<input type="password" size="20" name="ltitools_secret_'.$i.'" value="'.$secret.'" />'.
3114: '<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>'.
3115: '<input type="hidden" name="ltitools_id_'.$i.'" value="'.$item.'" /></span>'.
3116: '</fieldset>'.
3117: '<fieldset><legend>'.&mt('Optional settings').'</legend>'.
3118: '<span class="LC_nobreak">'.&mt('Display target:');
3119: my %currdisp;
3120: if (ref($settings->{$item}->{'display'}) eq 'HASH') {
3121: if ($settings->{$item}->{'display'}->{'target'} eq 'window') {
3122: $currdisp{'window'} = ' checked="checked"';
3123: } else {
3124: $currdisp{'iframe'} = ' checked="checked"';
3125: }
3126: if ($settings->{$item}->{'display'}->{'width'} =~ /^(\d+)$/) {
3127: $currdisp{'width'} = $1;
3128: }
3129: if ($settings->{$item}->{'display'}->{'height'} =~ /^(\d+)$/) {
3130: $currdisp{'height'} = $1;
3131: }
3132: } else {
3133: $currdisp{'iframe'} = ' checked="checked"';
3134: }
3135: foreach my $disp ('iframe','window') {
3136: $datatable .= '<label><input type="radio" name="ltitools_target_'.$i.'" value="'.$disp.'"'.$currdisp{$disp}.' />'.
3137: $lt{$disp}.'</label>'.(' 'x2);
3138: }
3139: $datatable .= (' 'x4);
3140: foreach my $dimen ('width','height') {
3141: $datatable .= '<label>'.$lt{$dimen}.' '.
3142: '<input type="text" name="ltitools_'.$dimen.'_'.$i.'" size="5" value="'.$currdisp{$dimen}.'" /></label>'.
3143: (' 'x2);
3144: }
3145: $datatable .= '<br />';
3146: foreach my $extra ('passback','roster') {
3147: my $checkedon = '';
3148: my $checkedoff = ' checked="checked"';
3149: if ($settings->{$item}->{$extra}) {
3150: $checkedon = $checkedoff;
3151: $checkedoff = '';
3152: }
3153: $datatable .= $lt{$extra}.' '.
3154: '<label><input type="radio" name="ltitools_'.$extra.'_'.$i.'" value="1"'.$checkedon.' />'.
3155: &mt('Yes').'</label>'.(' 'x2).
3156: '<label><input type="radio" name="ltitools_'.$extra.'_'.$i.'" value="0"'.$checkedoff.' />'.
3157: &mt('No').'</label>'.(' 'x4);
3158: }
3159: $datatable .= '<br /><br /><span class="LC_nobreak">'.$lt{'icon'}.': ';
3160: if ($imgsrc) {
3161: $datatable .= $imgsrc.
3162: '<label><input type="checkbox" name="ltitools_image_del"'.
3163: ' value="'.$item.'" />'.&mt('Delete?').'</label></span> '.
3164: '<span class="LC_nobreak"> '.&mt('Replace:').' ';
3165: } else {
3166: $datatable .= '('.&mt('if larger than 21x21 pixels, image will be scaled').') ';
3167: }
3168: if ($switchserver) {
3169: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
3170: } else {
3171: $datatable .= '<input type="file" name="ltitools_image_'.$i.'" value="" />';
3172: }
3173: $datatable .= '</span></fieldset>';
3174: my (%checkedfields,%rolemaps);
3175: if (ref($settings->{$item}) eq 'HASH') {
3176: if (ref($settings->{$item}->{'fields'}) eq 'HASH') {
3177: %checkedfields = %{$settings->{$item}->{'fields'}};
3178: }
3179: if (ref($settings->{$item}->{'roles'}) eq 'HASH') {
3180: %rolemaps = %{$settings->{$item}->{'roles'}};
3181: $checkedfields{'roles'} = 1;
3182: }
3183: }
3184: $datatable .= '<fieldset><legend>'.&mt('User data sent on launch').'</legend>'.
3185: '<span class="LC_nobreak">';
3186: foreach my $field (@fields) {
3187: my $checked;
3188: if ($checkedfields{$field}) {
3189: $checked = ' checked="checked"';
3190: }
3191: $datatable .= '<label>'.
3192: '<input type="checkbox" name="ltitools_fields_'.$i.'" value="'.$field.'"'.$checked.' />'.
3193: $lt{$field}.'</label>'.(' ' x2);
3194: }
3195: $datatable .= '</span></fieldset>'.
3196: '<fieldset><legend>'.&mt('Role mapping').'</legend><table><tr>';
3197: foreach my $role (@courseroles) {
3198: my ($selected,$selectnone);
3199: if (!$rolemaps{$role}) {
3200: $selectnone = ' selected="selected"';
3201: }
3202: $datatable .= '<td align="center">'.
3203: &Apache::lonnet::plaintext($role,'Course').'<br />'.
3204: '<select name="ltitools_roles_'.$role.'_'.$i.'">'.
3205: '<option value=""'.$selectnone.'>'.&mt('Select').'</option>';
3206: foreach my $ltirole (@ltiroles) {
3207: unless ($selectnone) {
3208: if ($rolemaps{$role} eq $ltirole) {
3209: $selected = ' selected="selected"';
3210: } else {
3211: $selected = '';
3212: }
3213: }
3214: $datatable .= '<option value="'.$ltirole.'"'.$selected.'>'.$ltirole.'</option>';
3215: }
3216: $datatable .= '</select></td>';
3217: }
1.273 raeburn 3218: $datatable .= '</tr></table></fieldset>';
3219: my %courseconfig;
3220: if (ref($settings->{$item}) eq 'HASH') {
3221: if (ref($settings->{$item}->{'crsconf'}) eq 'HASH') {
3222: %courseconfig = %{$settings->{$item}->{'crsconf'}};
3223: }
3224: }
3225: $datatable .= '<fieldset><legend>'.&mt('Configurable in course').'</legend><span class="LC_nobreak">';
3226: foreach my $item ('label','title','target') {
3227: my $checked;
3228: if ($courseconfig{$item}) {
3229: $checked = ' checked="checked"';
3230: }
3231: $datatable .= '<label>'.
3232: '<input type="checkbox" name="ltitools_courseconfig_'.$i.'" value="'.$item.'"'.$checked.' />'.
3233: $lt{'crs'.$item}.'</label>'.(' ' x2)."\n";
3234: }
3235: $datatable .= '</span></fieldset>'.
1.267 raeburn 3236: '<fieldset><legend>'.&mt('Custom items sent on launch').'</legend>'.
3237: '<table><tr><th>'.&mt('Action').'</th><th>'.&mt('Name').'</th><th>'.&mt('Value').'</th></tr>';
3238: if (ref($settings->{$item}->{'custom'}) eq 'HASH') {
3239: my %custom = %{$settings->{$item}->{'custom'}};
3240: if (keys(%custom) > 0) {
3241: foreach my $key (sort(keys(%custom))) {
3242: $datatable .= '<tr><td><span class="LC_nobreak">'.
3243: '<label><input type="checkbox" name="ltitools_customdel_'.$i.'" value="'.
3244: $key.'" />'.&mt('Delete').'</label></span></td><td>'.$key.'</td>'.
3245: '<td><input type="text" name="ltitools_customval_'.$key.'_'.$i.'"'.
3246: ' value="'.$custom{$key}.'" /></td></tr>';
3247: }
3248: }
3249: }
3250: $datatable .= '<tr><td><span class="LC_nobreak">'.
3251: '<label><input type="checkbox" name="ltitools_customadd" value="'.$i.'" />'.
3252: &mt('Add').'</label></span></td><td><input type="text" name="ltitools_custom_name_'.$i.'" />'.
3253: '</td><td><input type="text" name="ltitools_custom_value_'.$i.'" /></td></tr>';
3254: $datatable .= '</table></fieldset></td></tr>'."\n";
3255: $itemcount ++;
3256: }
3257: }
3258: $css_class = $itemcount%2?' class="LC_odd_row"':'';
3259: my $chgstr = ' onchange="javascript:reorderLTI(this.form,'."'ltitools_add_pos'".');"';
3260: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
3261: '<input type="hidden" name="ltitools_maxnum" value="'.$maxnum.'" />'."\n".
3262: '<select name="ltitools_add_pos"'.$chgstr.'>';
3263: for (my $k=0; $k<$maxnum+1; $k++) {
3264: my $vpos = $k+1;
3265: my $selstr;
3266: if ($k == $maxnum) {
3267: $selstr = ' selected="selected" ';
3268: }
3269: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
3270: }
3271: $datatable .= '</select> '."\n".
3272: '<input type="checkbox" name="ltitools_add" value="1" />'.&mt('Add').'</td>'."\n".
3273: '<td colspan="2">'.
3274: '<fieldset><legend>'.&mt('Required settings').'</legend>'.
3275: '<span class="LC_nobreak">'.$lt{'title'}.':<input type="text" size="30" name="ltitools_add_title" value="" /></span> '."\n".
3276: (' 'x2).
3277: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="ltitools_add_version">'.
3278: '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '."\n".
3279: (' 'x2).
3280: '<span class="LC_nobreak">'.$lt{'msgtype'}.':<select name="ltitools_add_msgtype">'.
3281: '<option value="basic-lti-launch-request" selected="selected">Launch</option></select></span> '.
3282: '<br />'.
3283: '<span class="LC_nobreak">'.$lt{'url'}.':<input type="text" size="30" name="ltitools_add_url" value="" /></span> '."\n".
3284: (' 'x2).
3285: '<span class="LC_nobreak">'.$lt{'key'}.':<input type="text" size="25" name="ltitools_add_key" value="" /></span> '."\n".
3286: (' 'x2).
3287: '<span class="LC_nobreak">'.$lt{'secret'}.':<input type="password" size="20" name="ltitools_add_secret" value="" />'.
3288: '<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".
3289: '</fieldset>'.
3290: '<fieldset><legend>'.&mt('Optional settings').'</legend>'.
3291: '<span class="LC_nobreak">'.&mt('Display target:');
3292: my %defaultdisp;
3293: $defaultdisp{'iframe'} = ' checked="checked"';
3294: foreach my $disp ('iframe','window') {
3295: $datatable .= '<label><input type="radio" name="ltitools_add_target" value="'.$disp.'"'.$defaultdisp{$disp}.' />'.
3296: $lt{$disp}.'</label>'.(' 'x2);
3297: }
3298: $datatable .= (' 'x4);
3299: foreach my $dimen ('width','height') {
3300: $datatable .= '<label>'.$lt{$dimen}.' '.
3301: '<input type="text" name="ltitools_add_'.$dimen.'" size="5" /></label>'.
3302: (' 'x2);
3303: }
3304: $datatable .= '<br />';
3305: foreach my $extra ('passback','roster') {
3306: $datatable .= $lt{$extra}.' '.
3307: '<label><input type="radio" name="ltitools_add_'.$extra.'" value="1" />'.
3308: &mt('Yes').'</label>'.(' 'x2).
3309: '<label><input type="radio" name="ltitools_add_'.$extra.'" value="0" checked="checked" />'.
3310: &mt('No').'</label>'.(' 'x4);
3311: }
3312: $datatable .= '<br /><br /><span class="LC_nobreak">'.$lt{'icon'}.': '.
3313: '('.&mt('if larger than 21x21 pixels, image will be scaled').') ';
3314: if ($switchserver) {
3315: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
3316: } else {
3317: $datatable .= '<input type="file" name="ltitools_add_image" value="" />';
3318: }
3319: $datatable .= '</span></fieldset>'.
3320: '<fieldset><legend>'.&mt('User data sent on launch').'</legend>'.
3321: '<span class="LC_nobreak">';
3322: foreach my $field (@fields) {
3323: $datatable .= '<label>'.
3324: '<input type="checkbox" name="ltitools_add_fields" value="'.$field.'" />'.
3325: $lt{$field}.'</label>'.(' ' x2);
3326: }
3327: $datatable .= '</span></fieldset>'.
3328: '<fieldset><legend>'.&mt('Role mapping').'</legend><table><tr>';
3329: foreach my $role (@courseroles) {
3330: my ($checked,$checkednone);
3331: $datatable .= '<td align="center">'.
3332: &Apache::lonnet::plaintext($role,'Course').'<br />'.
3333: '<select name="ltitools_add_roles_'.$role.'">'.
3334: '<option value="" selected="selected">'.&mt('Select').'</option>';
3335: foreach my $ltirole (@ltiroles) {
3336: $datatable .= '<option value="'.$ltirole.'">'.$ltirole.'</option>';
3337: }
3338: $datatable .= '</select></td>';
3339: }
3340: $datatable .= '</tr></table></fieldset>'.
1.273 raeburn 3341: '<fieldset><legend>'.&mt('Configurable in course').'</legend><span class="LC_nobreak">';
3342: foreach my $item ('label','title','target') {
3343: $datatable .= '<label>'.
3344: '<input type="checkbox" name="ltitools_courseconfig" value="'.$item.'" checked="checked" />'.
3345: $lt{'crs'.$item}.'</label>'.(' ' x2)."\n";
3346: }
3347: $datatable .= '</span></fieldset>'.
1.267 raeburn 3348: '<fieldset><legend>'.&mt('Custom items sent on launch').'</legend>'.
3349: '<table><tr><th>'.&mt('Action').'</th><th>'.&mt('Name').'</th><th>'.&mt('Value').'</th></tr>'.
3350: '<tr><td><span class="LC_nobreak">'.
3351: '<label><input type="checkbox" name="ltitools_add_custom" value="1" />'.
3352: &mt('Add').'</label></span></td><td><input type="text" name="ltitools_add_custom_name" />'.
3353: '</td><td><input type="text" name="ltitools_add_custom_value" /></td></tr>'.
3354: '</table></fieldset></td></tr>'."\n".
3355: '</td>'."\n".
3356: '</tr>'."\n";
3357: $itemcount ++;
3358: return $datatable;
3359: }
3360:
3361: sub ltitools_names {
3362: my %lt = &Apache::lonlocal::texthash(
3363: 'title' => 'Title',
3364: 'version' => 'Version',
3365: 'msgtype' => 'Message Type',
3366: 'url' => 'URL',
3367: 'key' => 'Key',
3368: 'secret' => 'Secret',
3369: 'icon' => 'Icon',
3370: 'user' => 'Username:domain',
3371: 'fullname' => 'Full Name',
3372: 'firstname' => 'First Name',
3373: 'lastname' => 'Last Name',
3374: 'email' => 'E-mail',
3375: 'roles' => 'Role',
3376: 'window' => 'Window/Tab',
3377: 'iframe' => 'iFrame',
3378: 'height' => 'Height',
3379: 'width' => 'Width',
3380: 'passback' => 'Tool can return grades:',
3381: 'roster' => 'Tool can retrieve roster:',
1.273 raeburn 3382: 'crstarget' => 'Display target',
3383: 'crslabel' => 'Course label',
3384: 'crstitle' => 'Course title',
1.267 raeburn 3385: );
3386: return %lt;
3387: }
3388:
1.121 raeburn 3389: sub print_coursedefaults {
1.139 raeburn 3390: my ($position,$dom,$settings,$rowtotal) = @_;
1.192 raeburn 3391: my ($css_class,$datatable,%checkedon,%checkedoff,%defaultchecked,@toggles);
1.121 raeburn 3392: my $itemcount = 1;
1.192 raeburn 3393: my %choices = &Apache::lonlocal::texthash (
3394: canuse_pdfforms => 'Course/Community users can create/upload PDF forms',
1.198 raeburn 3395: uploadquota => 'Default quota for files uploaded directly to course/community using Course Editor (MB)',
1.192 raeburn 3396: anonsurvey_threshold => 'Responder count needed before showing submissions for anonymous surveys',
3397: coursecredits => 'Credits can be specified for courses',
1.257 raeburn 3398: uselcmath => 'Math preview uses LON-CAPA previewer (javascript) in place of DragMath (Java)',
3399: usejsme => 'Molecule editor uses JSME (HTML5) in place of JME (Java)',
3400: postsubmit => 'Disable submit button/keypress following student submission',
1.276 raeburn 3401: canclone => "People who may clone a course (besides course's owner and coordinators)",
3402: mysqltables => 'Lifetime (s) of "Temporary" MySQL tables (student performance data) on homeserver',
1.192 raeburn 3403: );
1.198 raeburn 3404: my %staticdefaults = (
3405: anonsurvey_threshold => 10,
3406: uploadquota => 500,
1.257 raeburn 3407: postsubmit => 60,
1.276 raeburn 3408: mysqltables => 172800,
1.198 raeburn 3409: );
1.139 raeburn 3410: if ($position eq 'top') {
1.257 raeburn 3411: %defaultchecked = (
3412: 'canuse_pdfforms' => 'off',
3413: 'uselcmath' => 'on',
3414: 'usejsme' => 'on',
1.264 raeburn 3415: 'canclone' => 'none',
1.257 raeburn 3416: );
3417: @toggles = ('canuse_pdfforms','uselcmath','usejsme');
1.139 raeburn 3418: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
1.257 raeburn 3419: \%choices,$itemcount);
1.264 raeburn 3420: $css_class = $itemcount%2?' class="LC_odd_row"':'';
3421: $datatable .=
3422: '<tr'.$css_class.'><td valign="top">'.
3423: '<span class="LC_nobreak">'.$choices{'canclone'}.
3424: '</span></td><td class="LC_left_item">';
3425: my $currcanclone = 'none';
3426: my $onclick;
3427: my @cloneoptions = ('none','domain');
3428: my %clonetitles = (
3429: none => 'No additional course requesters',
3430: domain => "Any course requester in course's domain",
3431: instcode => 'Course requests for official courses ...',
3432: );
3433: my (%codedefaults,@code_order,@posscodes);
3434: if (&Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
3435: \@code_order) eq 'ok') {
3436: if (@code_order > 0) {
3437: push(@cloneoptions,'instcode');
3438: $onclick = ' onclick="toggleDisplay(this.form,'."'cloneinstcode'".');"';
3439: }
3440: }
3441: if (ref($settings) eq 'HASH') {
3442: if ($settings->{'canclone'}) {
3443: if (ref($settings->{'canclone'}) eq 'HASH') {
3444: if (ref($settings->{'canclone'}{'instcode'}) eq 'ARRAY') {
3445: if (@code_order > 0) {
3446: $currcanclone = 'instcode';
3447: @posscodes = @{$settings->{'canclone'}{'instcode'}};
3448: }
3449: }
3450: } elsif ($settings->{'canclone'} eq 'domain') {
3451: $currcanclone = $settings->{'canclone'};
3452: }
3453: }
3454: }
3455: foreach my $option (@cloneoptions) {
3456: my ($checked,$additional);
3457: if ($currcanclone eq $option) {
3458: $checked = ' checked="checked"';
3459: }
3460: if ($option eq 'instcode') {
3461: if (@code_order) {
3462: my $show = 'none';
3463: if ($checked) {
3464: $show = 'block';
3465: }
3466: $additional = '<div id="cloneinstcode" style="display:'.$show.'" />'.
3467: &mt('Institutional codes for new and cloned course have identical:').
3468: '<br />';
3469: foreach my $item (@code_order) {
3470: my $codechk;
3471: if ($checked) {
3472: if (grep(/^\Q$item\E$/,@posscodes)) {
3473: $codechk = ' checked="checked"';
3474: }
3475: }
3476: $additional .= '<label>'.
3477: '<input type="checkbox" name="clonecode" value="'.$item.'"'.$codechk.' />'.
3478: $item.'</label>';
3479: }
3480: $additional .= (' 'x2).'('.&mt('check as many as needed').')</div>';
3481: }
3482: }
3483: $datatable .=
3484: '<span class="LC_nobreak"><label><input type="radio" name="canclone"'.$checked.
3485: ' value="'.$option.'"'.$onclick.' />'.$clonetitles{$option}.
3486: '</label> '.$additional.'</span><br />';
3487: }
3488: $datatable .= '</td>'.
3489: '</tr>';
3490: $itemcount ++;
1.139 raeburn 3491: } else {
3492: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.276 raeburn 3493: my ($currdefresponder,%defcredits,%curruploadquota,%deftimeout,%currmysql);
1.192 raeburn 3494: my $currusecredits = 0;
1.257 raeburn 3495: my $postsubmitclient = 1;
1.271 raeburn 3496: my @types = ('official','unofficial','community','textbook','placement');
1.139 raeburn 3497: if (ref($settings) eq 'HASH') {
3498: $currdefresponder = $settings->{'anonsurvey_threshold'};
1.198 raeburn 3499: if (ref($settings->{'uploadquota'}) eq 'HASH') {
3500: foreach my $type (keys(%{$settings->{'uploadquota'}})) {
3501: $curruploadquota{$type} = $settings->{'uploadquota'}{$type};
3502: }
3503: }
1.192 raeburn 3504: if (ref($settings->{'coursecredits'}) eq 'HASH') {
1.257 raeburn 3505: foreach my $type (@types) {
3506: next if ($type eq 'community');
3507: $defcredits{$type} = $settings->{'coursecredits'}->{$type};
3508: if ($defcredits{$type} ne '') {
3509: $currusecredits = 1;
3510: }
3511: }
3512: }
3513: if (ref($settings->{'postsubmit'}) eq 'HASH') {
3514: if ($settings->{'postsubmit'}->{'client'} eq 'off') {
3515: $postsubmitclient = 0;
3516: foreach my $type (@types) {
3517: $deftimeout{$type} = $staticdefaults{'postsubmit'};
3518: }
3519: } else {
3520: foreach my $type (@types) {
3521: if (ref($settings->{'postsubmit'}->{'timeout'}) eq 'HASH') {
3522: if ($settings->{'postsubmit'}->{'timeout'}->{$type} =~ /^\d+$/) {
3523: $deftimeout{$type} = $settings->{'postsubmit'}->{'timeout'}->{$type};
3524: } else {
3525: $deftimeout{$type} = $staticdefaults{'postsubmit'};
3526: }
3527: } else {
3528: $deftimeout{$type} = $staticdefaults{'postsubmit'};
3529: }
3530: }
3531: }
3532: } else {
3533: foreach my $type (@types) {
3534: $deftimeout{$type} = $staticdefaults{'postsubmit'};
1.192 raeburn 3535: }
3536: }
1.276 raeburn 3537: if (ref($settings->{'mysqltables'}) eq 'HASH') {
3538: foreach my $type (keys(%{$settings->{'mysqltables'}})) {
3539: $currmysql{$type} = $settings->{'mysqltables'}{$type};
3540: }
3541: } else {
3542: foreach my $type (@types) {
3543: $currmysql{$type} = $staticdefaults{'mysqltables'};
3544: }
3545: }
1.258 raeburn 3546: } else {
3547: foreach my $type (@types) {
3548: $deftimeout{$type} = $staticdefaults{'postsubmit'};
3549: }
1.139 raeburn 3550: }
3551: if (!$currdefresponder) {
1.198 raeburn 3552: $currdefresponder = $staticdefaults{'anonsurvey_threshold'};
1.139 raeburn 3553: } elsif ($currdefresponder < 1) {
3554: $currdefresponder = 1;
3555: }
1.198 raeburn 3556: foreach my $type (@types) {
3557: if ($curruploadquota{$type} eq '') {
3558: $curruploadquota{$type} = $staticdefaults{'uploadquota'};
3559: }
3560: }
1.139 raeburn 3561: $datatable .=
1.192 raeburn 3562: '<tr'.$css_class.'><td><span class="LC_nobreak">'.
3563: $choices{'anonsurvey_threshold'}.
1.139 raeburn 3564: '</span></td>'.
3565: '<td class="LC_right_item"><span class="LC_nobreak">'.
3566: '<input type="text" name="anonsurvey_threshold"'.
3567: ' value="'.$currdefresponder.'" size="5" /></span>'.
1.230 raeburn 3568: '</td></tr>'."\n";
3569: $itemcount ++;
3570: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
3571: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
3572: $choices{'uploadquota'}.
3573: '</span></td>'.
3574: '<td align="right" class="LC_right_item">'.
3575: '<table><tr>';
1.198 raeburn 3576: foreach my $type (@types) {
3577: $datatable .= '<td align="center">'.&mt($type).'<br />'.
3578: '<input type="text" name="uploadquota_'.$type.'"'.
3579: ' value="'.$curruploadquota{$type}.'" size="5" /></td>';
3580: }
3581: $datatable .= '</tr></table></td></tr>'."\n";
1.230 raeburn 3582: $itemcount ++;
1.236 raeburn 3583: my $onclick = "toggleDisplay(this.form,'credits');";
1.210 raeburn 3584: my $display = 'none';
1.192 raeburn 3585: if ($currusecredits) {
3586: $display = 'block';
3587: }
3588: my $additional = '<div id="credits" style="display: '.$display.'">'.
1.257 raeburn 3589: '<i>'.&mt('Default credits').'</i><br /><table><tr>';
3590: foreach my $type (@types) {
3591: next if ($type eq 'community');
3592: $additional .= '<td align="center">'.&mt($type).'<br />'.
3593: '<input type="text" name="'.$type.'_credits"'.
1.258 raeburn 3594: ' value="'.$defcredits{$type}.'" size="3" /></td>';
1.257 raeburn 3595: }
3596: $additional .= '</tr></table></div>'."\n";
1.192 raeburn 3597: %defaultchecked = ('coursecredits' => 'off');
3598: @toggles = ('coursecredits');
3599: my $current = {
3600: 'coursecredits' => $currusecredits,
3601: };
3602: (my $table,$itemcount) =
3603: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
1.257 raeburn 3604: \%choices,$itemcount,$onclick,$additional,'left');
3605: $datatable .= $table;
3606: $onclick = "toggleDisplay(this.form,'studentsubmission');";
3607: my $display = 'none';
3608: if ($postsubmitclient) {
3609: $display = 'block';
3610: }
3611: $additional = '<div id="studentsubmission" style="display: '.$display.'">'.
1.259 raeburn 3612: &mt('Number of seconds submit is disabled').'<br />'.
3613: '<i>'.&mt('Enter 0 to remain disabled until page reload.').'</i><br />'.
3614: '<table><tr>';
1.257 raeburn 3615: foreach my $type (@types) {
3616: $additional .= '<td align="center">'.&mt($type).'<br />'.
3617: '<input type="text" name="'.$type.'_timeout" value="'.
3618: $deftimeout{$type}.'" size="5" /></td>';
3619: }
3620: $additional .= '</tr></table></div>'."\n";
3621: %defaultchecked = ('postsubmit' => 'on');
3622: @toggles = ('postsubmit');
3623: my $current = {
3624: 'postsubmit' => $postsubmitclient,
3625: };
3626: ($table,$itemcount) =
3627: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
3628: \%choices,$itemcount,$onclick,$additional,'left');
1.192 raeburn 3629: $datatable .= $table;
1.276 raeburn 3630: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
3631: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
3632: $choices{'mysqltables'}.
3633: '</span></td>'.
3634: '<td align="right" class="LC_right_item">'.
3635: '<table><tr>';
3636: foreach my $type (@types) {
3637: $datatable .= '<td align="center">'.&mt($type).'<br />'.
3638: '<input type="text" name="mysqltables_'.$type.'"'.
3639: ' value="'.$currmysql{$type}.'" size="5" /></td>';
3640: }
3641: $datatable .= '</tr></table></td></tr>'."\n";
3642: $itemcount ++;
3643:
1.139 raeburn 3644: }
1.192 raeburn 3645: $$rowtotal += $itemcount;
1.121 raeburn 3646: return $datatable;
1.118 jms 3647: }
3648:
1.231 raeburn 3649: sub print_selfenrollment {
3650: my ($position,$dom,$settings,$rowtotal) = @_;
3651: my ($css_class,$datatable);
3652: my $itemcount = 1;
1.271 raeburn 3653: my @types = ('official','unofficial','community','textbook','placement');
1.231 raeburn 3654: if (($position eq 'top') || ($position eq 'middle')) {
1.232 raeburn 3655: my ($rowsref,$titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
3656: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
1.231 raeburn 3657: my @rows;
3658: my $key;
3659: if ($position eq 'top') {
3660: $key = 'admin';
3661: if (ref($rowsref) eq 'ARRAY') {
3662: @rows = @{$rowsref};
3663: }
3664: } elsif ($position eq 'middle') {
3665: $key = 'default';
3666: @rows = ('types','registered','approval','limit');
3667: }
3668: foreach my $row (@rows) {
3669: if (defined($titlesref->{$row})) {
3670: $itemcount ++;
3671: $css_class = $itemcount%2?' class="LC_odd_row"':'';
3672: $datatable .= '<tr'.$css_class.'>'.
3673: '<td>'.$titlesref->{$row}.'</td>'.
3674: '<td class="LC_left_item">'.
3675: '<table><tr>';
3676: my (%current,%currentcap);
3677: if (ref($settings) eq 'HASH') {
3678: if (ref($settings->{$key}) eq 'HASH') {
3679: foreach my $type (@types) {
3680: if (ref($settings->{$key}->{$type}) eq 'HASH') {
3681: $current{$type} = $settings->{$key}->{$type}->{$row};
3682: }
3683: if (($row eq 'limit') && ($key eq 'default')) {
3684: if (ref($settings->{$key}->{$type}) eq 'HASH') {
3685: $currentcap{$type} = $settings->{$key}->{$type}->{'cap'};
3686: }
3687: }
3688: }
3689: }
3690: }
3691: my %roles = (
3692: '0' => &Apache::lonnet::plaintext('dc'),
3693: );
3694:
3695: foreach my $type (@types) {
3696: unless (($row eq 'registered') && ($key eq 'default')) {
3697: $datatable .= '<th>'.&mt($type).'</th>';
3698: }
3699: }
3700: unless (($row eq 'registered') && ($key eq 'default')) {
3701: $datatable .= '</tr><tr>';
3702: }
3703: foreach my $type (@types) {
3704: if ($type eq 'community') {
3705: $roles{'1'} = &mt('Community personnel');
3706: } else {
3707: $roles{'1'} = &mt('Course personnel');
3708: }
3709: $datatable .= '<td style="vertical-align: top">';
3710: if ($position eq 'top') {
3711: my %checked;
3712: if ($current{$type} eq '0') {
3713: $checked{'0'} = ' checked="checked"';
3714: } else {
3715: $checked{'1'} = ' checked="checked"';
3716: }
3717: foreach my $role ('1','0') {
3718: $datatable .= '<span class="LC_nobreak"><label>'.
3719: '<input type="radio" name="selfenrolladmin_'.$row.'_'.$type.'" '.
3720: 'value="'.$role.'"'.$checked{$role}.' />'.
3721: $roles{$role}.'</label></span> ';
3722: }
3723: } else {
3724: if ($row eq 'types') {
3725: my %checked;
3726: if ($current{$type} =~ /^(all|dom)$/) {
3727: $checked{$1} = ' checked="checked"';
3728: } else {
3729: $checked{''} = ' checked="checked"';
3730: }
3731: foreach my $val ('','dom','all') {
3732: $datatable .= '<span class="LC_nobreak"><label>'.
3733: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
3734: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
3735: }
3736: } elsif ($row eq 'registered') {
3737: my %checked;
3738: if ($current{$type} eq '1') {
3739: $checked{'1'} = ' checked="checked"';
3740: } else {
3741: $checked{'0'} = ' checked="checked"';
3742: }
3743: foreach my $val ('0','1') {
3744: $datatable .= '<span class="LC_nobreak"><label>'.
3745: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
3746: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
3747: }
3748: } elsif ($row eq 'approval') {
3749: my %checked;
3750: if ($current{$type} =~ /^([12])$/) {
3751: $checked{$1} = ' checked="checked"';
3752: } else {
3753: $checked{'0'} = ' checked="checked"';
3754: }
3755: for my $val (0..2) {
3756: $datatable .= '<span class="LC_nobreak"><label>'.
3757: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
3758: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
3759: }
3760: } elsif ($row eq 'limit') {
3761: my %checked;
3762: if ($current{$type} =~ /^(allstudents|selfenrolled)$/) {
3763: $checked{$1} = ' checked="checked"';
3764: } else {
3765: $checked{'none'} = ' checked="checked"';
3766: }
3767: my $cap;
3768: if ($currentcap{$type} =~ /^\d+$/) {
3769: $cap = $currentcap{$type};
3770: }
3771: foreach my $val ('none','allstudents','selfenrolled') {
3772: $datatable .= '<span class="LC_nobreak"><label>'.
3773: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
3774: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
3775: }
3776: $datatable .= '<br />'.
3777: '<span class="LC_nobreak">'.&mt('Maximum allowed: ').
3778: '<input type="text" name="selfenrolldefault_cap_'.$type.'" size = "5" value="'.$cap.'" />'.
3779: '</span>';
3780: }
3781: }
3782: $datatable .= '</td>';
3783: }
3784: $datatable .= '</tr>';
3785: }
3786: $datatable .= '</table></td></tr>';
3787: }
3788: } elsif ($position eq 'bottom') {
1.235 raeburn 3789: $datatable .= &print_validation_rows('selfenroll',$dom,$settings,\$itemcount);
3790: }
3791: $$rowtotal += $itemcount;
3792: return $datatable;
3793: }
3794:
3795: sub print_validation_rows {
3796: my ($caller,$dom,$settings,$rowtotal) = @_;
3797: my ($itemsref,$namesref,$fieldsref);
3798: if ($caller eq 'selfenroll') {
3799: ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
3800: } elsif ($caller eq 'requestcourses') {
3801: ($itemsref,$namesref,$fieldsref) = &Apache::loncoursequeueadmin::requestcourses_validation_types();
3802: }
3803: my %currvalidation;
3804: if (ref($settings) eq 'HASH') {
3805: if (ref($settings->{'validation'}) eq 'HASH') {
3806: %currvalidation = %{$settings->{'validation'}};
1.231 raeburn 3807: }
1.235 raeburn 3808: }
3809: my $datatable;
3810: my $itemcount = 0;
3811: foreach my $item (@{$itemsref}) {
3812: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
3813: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
3814: $namesref->{$item}.
3815: '</span></td>'.
3816: '<td class="LC_left_item">';
3817: if (($item eq 'url') || ($item eq 'button')) {
3818: $datatable .= '<span class="LC_nobreak">'.
3819: '<input type="text" name="'.$caller.'_validation_'.$item.'"'.
3820: ' value="'.$currvalidation{$item}.'" size="50" /></span>';
3821: } elsif ($item eq 'fields') {
3822: my @currfields;
3823: if (ref($currvalidation{$item}) eq 'ARRAY') {
3824: @currfields = @{$currvalidation{$item}};
3825: }
3826: foreach my $field (@{$fieldsref}) {
3827: my $check = '';
3828: if (grep(/^\Q$field\E$/,@currfields)) {
3829: $check = ' checked="checked"';
3830: }
3831: $datatable .= '<span class="LC_nobreak"><label>'.
3832: '<input type="checkbox" name="'.$caller.'_validation_fields"'.
3833: ' value="'.$field.'"'.$check.' />'.$field.
3834: '</label></span> ';
3835: }
3836: } elsif ($item eq 'markup') {
3837: $datatable .= '<textarea name="'.$caller.'_validation_markup" cols="50" rows="5" wrap="soft">'.
3838: $currvalidation{$item}.
1.231 raeburn 3839: '</textarea>';
1.235 raeburn 3840: }
3841: $datatable .= '</td></tr>'."\n";
3842: if (ref($rowtotal)) {
1.231 raeburn 3843: $itemcount ++;
3844: }
3845: }
1.235 raeburn 3846: if ($caller eq 'requestcourses') {
3847: my %currhash;
1.248 raeburn 3848: if (ref($settings) eq 'HASH') {
3849: if (ref($settings->{'validation'}) eq 'HASH') {
3850: if ($settings->{'validation'}{'dc'} ne '') {
3851: $currhash{$settings->{'validation'}{'dc'}} = 1;
3852: }
1.235 raeburn 3853: }
3854: }
3855: my $numinrow = 2;
3856: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
3857: 'validationdc',%currhash);
1.247 raeburn 3858: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
3859: $datatable .= '</td></tr><tr'.$css_class.'><td>';
1.235 raeburn 3860: if ($numdc > 1) {
1.247 raeburn 3861: $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)');
1.235 raeburn 3862: } else {
1.247 raeburn 3863: $datatable .= &mt('Course creation processed as: ');
1.235 raeburn 3864: }
1.247 raeburn 3865: $datatable .= '</td><td class="LC_left_item">'.$dctable.'</td></tr>';
1.235 raeburn 3866: $itemcount ++;
3867: }
3868: if (ref($rowtotal)) {
3869: $$rowtotal += $itemcount;
3870: }
1.231 raeburn 3871: return $datatable;
3872: }
3873:
1.137 raeburn 3874: sub print_usersessions {
3875: my ($position,$dom,$settings,$rowtotal) = @_;
3876: my ($css_class,$datatable,%checked,%choices);
1.275 raeburn 3877: my (%by_ip,%by_location,@intdoms,@instdoms);
3878: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
1.145 raeburn 3879:
3880: my @alldoms = &Apache::lonnet::all_domains();
1.152 raeburn 3881: my %serverhomes = %Apache::lonnet::serverhomeIDs;
1.149 raeburn 3882: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.152 raeburn 3883: my %altids = &id_for_thisdom(%servers);
1.145 raeburn 3884: my $itemcount = 1;
3885: if ($position eq 'top') {
1.152 raeburn 3886: if (keys(%serverhomes) > 1) {
1.145 raeburn 3887: my %spareid = ¤t_offloads_to($dom,$settings,\%servers);
1.261 raeburn 3888: my $curroffloadnow;
3889: if (ref($settings) eq 'HASH') {
3890: if (ref($settings->{'offloadnow'}) eq 'HASH') {
3891: $curroffloadnow = $settings->{'offloadnow'};
3892: }
3893: }
3894: $datatable .= &spares_row($dom,\%servers,\%spareid,\%serverhomes,\%altids,$curroffloadnow,$rowtotal);
1.145 raeburn 3895: } else {
1.140 raeburn 3896: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.150 raeburn 3897: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one server.');
1.140 raeburn 3898: }
1.137 raeburn 3899: } else {
1.145 raeburn 3900: if (keys(%by_location) == 0) {
3901: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.150 raeburn 3902: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one institution.');
1.145 raeburn 3903: } else {
3904: my %lt = &usersession_titles();
3905: my $numinrow = 5;
3906: my $prefix;
3907: my @types;
3908: if ($position eq 'bottom') {
3909: $prefix = 'remote';
3910: @types = ('version','excludedomain','includedomain');
3911: } else {
3912: $prefix = 'hosted';
3913: @types = ('excludedomain','includedomain');
3914: }
3915: my (%current,%checkedon,%checkedoff);
3916: my @lcversions = &Apache::lonnet::all_loncaparevs();
3917: my @locations = sort(keys(%by_location));
3918: foreach my $type (@types) {
3919: $checkedon{$type} = '';
3920: $checkedoff{$type} = ' checked="checked"';
3921: }
3922: if (ref($settings) eq 'HASH') {
3923: if (ref($settings->{$prefix}) eq 'HASH') {
3924: foreach my $key (keys(%{$settings->{$prefix}})) {
3925: $current{$key} = $settings->{$prefix}{$key};
3926: if ($key eq 'version') {
3927: if ($current{$key} ne '') {
3928: $checkedon{$key} = ' checked="checked"';
3929: $checkedoff{$key} = '';
3930: }
3931: } elsif (ref($current{$key}) eq 'ARRAY') {
3932: $checkedon{$key} = ' checked="checked"';
3933: $checkedoff{$key} = '';
3934: }
1.137 raeburn 3935: }
3936: }
3937: }
1.145 raeburn 3938: foreach my $type (@types) {
3939: next if ($type ne 'version' && !@locations);
3940: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
3941: $datatable .= '<tr'.$css_class.'>
3942: <td><span class="LC_nobreak">'.$lt{$type}.'</span><br />
3943: <span class="LC_nobreak">
3944: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedoff{$type}.' value="0" />'.&mt('Not in use').'</label>
3945: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedon{$type}.' value="1" />'.&mt('In use').'</label></span></td><td>';
3946: if ($type eq 'version') {
3947: my $selector = '<select name="'.$prefix.'_version">';
3948: foreach my $version (@lcversions) {
3949: my $selected = '';
3950: if ($current{'version'} eq $version) {
3951: $selected = ' selected="selected"';
3952: }
3953: $selector .= ' <option value="'.$version.'"'.
3954: $selected.'>'.$version.'</option>';
3955: }
3956: $selector .= '</select> ';
3957: $datatable .= &mt('remote server must be version: [_1] or later',$selector);
3958: } else {
3959: $datatable.= '<div><input type="button" value="'.&mt('check all').'" '.
3960: 'onclick="javascript:checkAll(document.display.'.$prefix.'_'.$type.')"'.
3961: ' />'.(' 'x2).
3962: '<input type="button" value="'.&mt('uncheck all').'" '.
3963: 'onclick="javascript:uncheckAll(document.display.'.$prefix.'_'.$type.')" />'.
3964: "\n".
3965: '</div><div><table>';
3966: my $rem;
3967: for (my $i=0; $i<@locations; $i++) {
3968: my ($showloc,$value,$checkedtype);
3969: if (ref($by_location{$locations[$i]}) eq 'ARRAY') {
3970: my $ip = $by_location{$locations[$i]}->[0];
3971: if (ref($by_ip{$ip}) eq 'ARRAY') {
3972: $value = join(':',@{$by_ip{$ip}});
3973: $showloc = join(', ',@{$by_ip{$ip}});
3974: if (ref($current{$type}) eq 'ARRAY') {
3975: foreach my $loc (@{$by_ip{$ip}}) {
3976: if (grep(/^\Q$loc\E$/,@{$current{$type}})) {
3977: $checkedtype = ' checked="checked"';
3978: last;
3979: }
3980: }
1.138 raeburn 3981: }
3982: }
3983: }
1.145 raeburn 3984: $rem = $i%($numinrow);
3985: if ($rem == 0) {
3986: if ($i > 0) {
3987: $datatable .= '</tr>';
3988: }
3989: $datatable .= '<tr>';
3990: }
3991: $datatable .= '<td class="LC_left_item">'.
3992: '<span class="LC_nobreak"><label>'.
3993: '<input type="checkbox" name="'.$prefix.'_'.$type.
3994: '" value="'.$value.'"'.$checkedtype.' />'.$showloc.
3995: '</label></span></td>';
1.137 raeburn 3996: }
1.145 raeburn 3997: $rem = @locations%($numinrow);
3998: my $colsleft = $numinrow - $rem;
3999: if ($colsleft > 1 ) {
4000: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
4001: ' </td>';
4002: } elsif ($colsleft == 1) {
4003: $datatable .= '<td class="LC_left_item"> </td>';
1.137 raeburn 4004: }
1.145 raeburn 4005: $datatable .= '</tr></table>';
1.137 raeburn 4006: }
1.145 raeburn 4007: $datatable .= '</td></tr>';
4008: $itemcount ++;
1.137 raeburn 4009: }
4010: }
4011: }
4012: $$rowtotal += $itemcount;
4013: return $datatable;
4014: }
4015:
1.275 raeburn 4016: sub print_ssl {
4017: my ($position,$dom,$settings,$rowtotal) = @_;
4018: my ($css_class,$datatable);
4019: my $lonhost = '';
4020: my $itemcount = 1;
4021: if ($position eq 'top') {
4022: my %domservers = &Apache::lonnet::get_servers($dom);
4023: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4024: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
4025: &LONCAPA::SSL::print_certstatus(\%domservers,'web','domprefs').
4026: '</td></tr>';
4027: $itemcount ++;
4028: } else {
4029: my %titles = &ssl_titles();
4030: my (%by_ip,%by_location,@intdoms,@instdoms);
4031: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
4032: my @alldoms = &Apache::lonnet::all_domains();
4033: my %serverhomes = %Apache::lonnet::serverhomeIDs;
4034: my @domservers = &Apache::lonnet::get_servers($dom);
4035: my %servers = &Apache::lonnet::internet_dom_servers($dom);
4036: my %altids = &id_for_thisdom(%servers);
4037: if ($position eq 'middle') {
4038: foreach my $type ('dom','intdom','other') {
4039: my %checked;
4040: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4041: $datatable .= '<tr'.$css_class.'><td>'.$titles{$type}.'</td>'.
4042: '<td class="LC_right_item">';
4043: my $skip;
4044: if ($type eq 'dom') {
4045: unless (keys(%servers) > 1) {
4046: $datatable .= &mt('Nothing to set here, as there are no other servers/VMs');
4047: $skip = 1;
4048: }
4049: }
4050: if ($type eq 'intdom') {
4051: unless (@instdoms > 1) {
4052: $datatable .= &mt('Nothing to set here, as there are no other domains for this institution');
4053: $skip = 1;
4054: }
4055: } elsif ($type eq 'other') {
4056: if (keys(%by_location) == 0) {
4057: $datatable .= &mt('Nothing to set here, as there are no other institutions');
4058: $skip = 1;
4059: }
4060: }
4061: unless ($skip) {
4062: $checked{'yes'} = ' checked="checked"';
4063: if (ref($settings) eq 'HASH') {
4064: if (ref($settings->{'connect'}) eq 'HASH') {
4065: if ($settings->{'connect'}->{$type} =~ /^(no|req)$/) {
4066: $checked{$1} = $checked{'yes'};
4067: delete($checked{'yes'});
4068: }
4069: }
4070: }
4071: foreach my $option ('no','yes','req') {
4072: $datatable .= '<span class="LC_nobreak"><label>'.
4073: '<input type="radio" name="connect_'.$type.'" '.
4074: 'value="'.$option.'"'.$checked{$option}.' />'.$titles{$option}.
4075: '</label></span>'.(' 'x2);
4076: }
4077: }
4078: $datatable .= '</td></tr>';
4079: $itemcount ++;
4080: }
4081: } else {
4082: my $numinrow = 5;
4083: my $prefix = 'replication';
4084: my @types = ('certreq','nocertreq');
4085: my (%current,%checkedon,%checkedoff);
4086: my @locations = sort(keys(%by_location));
4087: foreach my $type (@types) {
4088: $checkedon{$type} = '';
4089: $checkedoff{$type} = ' checked="checked"';
4090: }
4091: if (ref($settings) eq 'HASH') {
4092: if (ref($settings->{$prefix}) eq 'HASH') {
4093: foreach my $key (keys(%{$settings->{$prefix}})) {
4094: $current{$key} = $settings->{$prefix}{$key};
4095: if (ref($current{$key}) eq 'ARRAY') {
4096: $checkedon{$key} = ' checked="checked"';
4097: $checkedoff{$key} = '';
4098: }
4099: }
4100: }
4101: }
4102: if (@locations > 0) {
4103: foreach my $type (@types) {
4104: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4105: $datatable .= '<tr'.$css_class.'>
4106: <td><span class="LC_nobreak LC_right_item">'.$titles{$type}.'</span><br />
4107: <span class="LC_nobreak">
4108: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedoff{$type}.' value="0" />'.&mt('Not in use').'</label>
4109: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedon{$type}.' value="1" />'.&mt('In use').'</label></span></td><td>
4110: <div><input type="button" value="'.&mt('check all').'" '.
4111: 'onclick="javascript:checkAll(document.display.'.$prefix.'_'.$type.')"'.
4112: ' />'.(' 'x2)."\n".
4113: '<input type="button" value="'.&mt('uncheck all').'" '.
4114: 'onclick="javascript:uncheckAll(document.display.'.$prefix.'_'.$type.')" />'.
4115: "\n".
4116: '</div><div><table>';
4117: my $rem;
4118: for (my $i=0; $i<@locations; $i++) {
4119: my ($showloc,$value,$checkedtype);
4120: if (ref($by_location{$locations[$i]}) eq 'ARRAY') {
4121: my $ip = $by_location{$locations[$i]}->[0];
4122: if (ref($by_ip{$ip}) eq 'ARRAY') {
4123: $value = join(':',@{$by_ip{$ip}});
4124: $showloc = join(', ',@{$by_ip{$ip}});
4125: if (ref($current{$type}) eq 'ARRAY') {
4126: foreach my $loc (@{$by_ip{$ip}}) {
4127: if (grep(/^\Q$loc\E$/,@{$current{$type}})) {
4128: $checkedtype = ' checked="checked"';
4129: last;
4130: }
4131: }
4132: }
4133: }
4134: }
4135: $rem = $i%($numinrow);
4136: if ($rem == 0) {
4137: if ($i > 0) {
4138: $datatable .= '</tr>';
4139: }
4140: $datatable .= '<tr>';
4141: }
4142: $datatable .= '<td class="LC_left_item">'.
4143: '<span class="LC_nobreak"><label>'.
4144: '<input type="checkbox" name="'.$prefix.'_'.$type.
4145: '" value="'.$value.'"'.$checkedtype.' />'.$showloc.
4146: '</label></span></td>';
4147: }
4148: $rem = @locations%($numinrow);
4149: my $colsleft = $numinrow - $rem;
4150: if ($colsleft > 1 ) {
4151: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
4152: ' </td>';
4153: } elsif ($colsleft == 1) {
4154: $datatable .= '<td class="LC_left_item"> </td>';
4155: }
4156: $datatable .= '</tr></table></td></tr>';
4157: $itemcount ++;
4158: }
4159: } else {
4160: $datatable .= '<tr'.$css_class.'><td>'.&mt('Nothing to set here, as there are no other institutions').'</td></tr>';
4161: $itemcount ++;
4162: }
4163: }
4164: }
4165: $$rowtotal += $itemcount;
4166: return $datatable;
4167: }
4168:
4169: sub ssl_titles {
4170: return &Apache::lonlocal::texthash (
4171: dom => 'LON-CAPA servers/VMs from same domain',
4172: intdom => 'LON-CAPA servers/VMs from same "internet" domain',
4173: other => 'External LON-CAPA servers/VMs',
4174: connect => 'Connections to other servers',
4175: replication => 'Replicating content to other institutions',
4176: certreq => 'Client certificate required, but specific domains exempt',
4177: nocertreq => 'No client certificate required, except for specific domains',
4178: no => 'SSL not used',
4179: yes => 'SSL Optional (used if available)',
4180: req => 'SSL Required',
4181: );
4182: }
4183:
1.138 raeburn 4184: sub build_location_hashes {
1.275 raeburn 4185: my ($intdoms,$by_ip,$by_location,$instdoms) = @_;
1.138 raeburn 4186: return unless((ref($intdoms) eq 'ARRAY') && (ref($by_ip) eq 'HASH') &&
1.275 raeburn 4187: (ref($by_location) eq 'HASH') && (ref($instdoms) eq 'ARRAY'));
1.138 raeburn 4188: my %iphost = &Apache::lonnet::get_iphost();
4189: my $primary_id = &Apache::lonnet::domain($env{'request.role.domain'},'primary');
4190: my $primary_ip = &Apache::lonnet::get_host_ip($primary_id);
4191: if (ref($iphost{$primary_ip}) eq 'ARRAY') {
4192: foreach my $id (@{$iphost{$primary_ip}}) {
4193: my $intdom = &Apache::lonnet::internet_dom($id);
4194: unless(grep(/^\Q$intdom\E$/,@{$intdoms})) {
4195: push(@{$intdoms},$intdom);
4196: }
4197: }
4198: }
4199: foreach my $ip (keys(%iphost)) {
4200: if (ref($iphost{$ip}) eq 'ARRAY') {
4201: foreach my $id (@{$iphost{$ip}}) {
4202: my $location = &Apache::lonnet::internet_dom($id);
4203: if ($location) {
1.275 raeburn 4204: if (grep(/^\Q$location\E$/,@{$intdoms})) {
4205: my $dom = &Apache::lonnet::host_domain($id);
4206: unless (grep(/^\Q$dom\E/,@{$instdoms})) {
4207: push(@{$instdoms},$dom);
4208: }
4209: next;
4210: }
1.138 raeburn 4211: if (ref($by_ip->{$ip}) eq 'ARRAY') {
4212: unless(grep(/^\Q$location\E$/,@{$by_ip->{$ip}})) {
4213: push(@{$by_ip->{$ip}},$location);
4214: }
4215: } else {
4216: $by_ip->{$ip} = [$location];
4217: }
4218: }
4219: }
4220: }
4221: }
4222: foreach my $ip (sort(keys(%{$by_ip}))) {
4223: if (ref($by_ip->{$ip}) eq 'ARRAY') {
4224: @{$by_ip->{$ip}} = sort(@{$by_ip->{$ip}});
4225: my $first = $by_ip->{$ip}->[0];
4226: if (ref($by_location->{$first}) eq 'ARRAY') {
4227: unless (grep(/^\Q$ip\E$/,@{$by_location->{$first}})) {
4228: push(@{$by_location->{$first}},$ip);
4229: }
4230: } else {
4231: $by_location->{$first} = [$ip];
4232: }
4233: }
4234: }
4235: return;
4236: }
4237:
1.145 raeburn 4238: sub current_offloads_to {
4239: my ($dom,$settings,$servers) = @_;
4240: my (%spareid,%otherdomconfigs);
1.152 raeburn 4241: if (ref($servers) eq 'HASH') {
1.145 raeburn 4242: foreach my $lonhost (sort(keys(%{$servers}))) {
4243: my $gotspares;
1.152 raeburn 4244: if (ref($settings) eq 'HASH') {
4245: if (ref($settings->{'spares'}) eq 'HASH') {
4246: if (ref($settings->{'spares'}{$lonhost}) eq 'HASH') {
4247: $spareid{$lonhost}{'primary'} = $settings->{'spares'}{$lonhost}{'primary'};
4248: $spareid{$lonhost}{'default'} = $settings->{'spares'}{$lonhost}{'default'};
4249: $gotspares = 1;
4250: }
1.145 raeburn 4251: }
4252: }
4253: unless ($gotspares) {
4254: my $gotspares;
4255: my $serverhomeID =
4256: &Apache::lonnet::get_server_homeID($servers->{$lonhost});
4257: my $serverhomedom =
4258: &Apache::lonnet::host_domain($serverhomeID);
4259: if ($serverhomedom ne $dom) {
4260: if (ref($otherdomconfigs{$serverhomedom} eq 'HASH')) {
4261: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
4262: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
4263: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
4264: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
4265: $gotspares = 1;
4266: }
4267: }
4268: } else {
4269: $otherdomconfigs{$serverhomedom} =
4270: &Apache::lonnet::get_dom('configuration',['usersessions'],$serverhomedom);
4271: if (ref($otherdomconfigs{$serverhomedom}) eq 'HASH') {
4272: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
4273: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
4274: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{$lonhost}) eq 'HASH') {
4275: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
4276: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
4277: $gotspares = 1;
4278: }
4279: }
4280: }
4281: }
4282: }
4283: }
4284: }
4285: unless ($gotspares) {
4286: if ($lonhost eq $Apache::lonnet::perlvar{'lonHostID'}) {
4287: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
4288: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
4289: } else {
4290: my $server_hostname = &Apache::lonnet::hostname($lonhost);
4291: my $server_homeID = &Apache::lonnet::get_server_homeID($server_hostname);
4292: if ($server_homeID eq $Apache::lonnet::perlvar{'lonHostID'}) {
4293: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
4294: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
4295: } else {
1.150 raeburn 4296: my %what = (
4297: spareid => 1,
4298: );
4299: my ($result,$returnhash) =
4300: &Apache::lonnet::get_remote_globals($lonhost,\%what);
4301: if ($result eq 'ok') {
4302: if (ref($returnhash) eq 'HASH') {
4303: if (ref($returnhash->{'spareid'}) eq 'HASH') {
4304: $spareid{$lonhost}{'primary'} = $returnhash->{'spareid'}->{'primary'};
4305: $spareid{$lonhost}{'default'} = $returnhash->{'spareid'}->{'default'};
4306: }
4307: }
1.145 raeburn 4308: }
4309: }
4310: }
4311: }
4312: }
4313: }
4314: return %spareid;
4315: }
4316:
4317: sub spares_row {
1.261 raeburn 4318: my ($dom,$servers,$spareid,$serverhomes,$altids,$curroffloadnow,$rowtotal) = @_;
1.145 raeburn 4319: my $css_class;
4320: my $numinrow = 4;
4321: my $itemcount = 1;
4322: my $datatable;
1.152 raeburn 4323: my %typetitles = &sparestype_titles();
4324: if ((ref($servers) eq 'HASH') && (ref($spareid) eq 'HASH') && (ref($altids) eq 'HASH')) {
1.145 raeburn 4325: foreach my $server (sort(keys(%{$servers}))) {
1.152 raeburn 4326: my $serverhome = &Apache::lonnet::get_server_homeID($servers->{$server});
4327: my ($othercontrol,$serverdom);
4328: if ($serverhome ne $server) {
4329: $serverdom = &Apache::lonnet::host_domain($serverhome);
4330: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
4331: } else {
4332: $serverdom = &Apache::lonnet::host_domain($server);
4333: if ($serverdom ne $dom) {
4334: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
4335: }
4336: }
4337: next unless (ref($spareid->{$server}) eq 'HASH');
1.261 raeburn 4338: my $checkednow;
4339: if (ref($curroffloadnow) eq 'HASH') {
4340: if ($curroffloadnow->{$server}) {
4341: $checkednow = ' checked="checked"';
4342: }
4343: }
1.145 raeburn 4344: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
4345: $datatable .= '<tr'.$css_class.'>
4346: <td rowspan="2">
1.183 bisitz 4347: <span class="LC_nobreak">'.
4348: &mt('[_1] when busy, offloads to:'
1.261 raeburn 4349: ,'<b>'.$server.'</b>').'</span><br />'.
4350: '<span class="LC_nobreak">'."\n".
4351: '<label><input type="checkbox" name="offloadnow" value="'.$server.'"'.$checkednow.' />'.
4352: ' '.&mt('Switch active users on next access').'</label></span>'.
1.183 bisitz 4353: "\n";
1.145 raeburn 4354: my (%current,%canselect);
1.152 raeburn 4355: my @choices =
4356: &possible_newspares($server,$spareid->{$server},$serverhomes,$altids);
4357: foreach my $type ('primary','default') {
4358: if (ref($spareid->{$server}) eq 'HASH') {
1.145 raeburn 4359: if (ref($spareid->{$server}{$type}) eq 'ARRAY') {
4360: my @spares = @{$spareid->{$server}{$type}};
4361: if (@spares > 0) {
1.152 raeburn 4362: if ($othercontrol) {
4363: $current{$type} = join(', ',@spares);
4364: } else {
4365: $current{$type} .= '<table>';
4366: my $numspares = scalar(@spares);
4367: for (my $i=0; $i<@spares; $i++) {
4368: my $rem = $i%($numinrow);
4369: if ($rem == 0) {
4370: if ($i > 0) {
4371: $current{$type} .= '</tr>';
4372: }
4373: $current{$type} .= '<tr>';
1.145 raeburn 4374: }
1.152 raeburn 4375: $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'".');" /> '.
4376: $spareid->{$server}{$type}[$i].
4377: '</label></td>'."\n";
4378: }
4379: my $rem = @spares%($numinrow);
4380: my $colsleft = $numinrow - $rem;
4381: if ($colsleft > 1 ) {
4382: $current{$type} .= '<td colspan="'.$colsleft.
4383: '" class="LC_left_item">'.
4384: ' </td>';
4385: } elsif ($colsleft == 1) {
4386: $current{$type} .= '<td class="LC_left_item"> </td>'."\n";
1.145 raeburn 4387: }
1.152 raeburn 4388: $current{$type} .= '</tr></table>';
1.150 raeburn 4389: }
1.145 raeburn 4390: }
4391: }
4392: if ($current{$type} eq '') {
4393: $current{$type} = &mt('None specified');
4394: }
1.152 raeburn 4395: if ($othercontrol) {
4396: if ($type eq 'primary') {
4397: $canselect{$type} = $othercontrol;
4398: }
4399: } else {
4400: $canselect{$type} =
4401: &mt('Add new [_1]'.$type.'[_2]:','<i>','</i>').' '.
4402: '<select name="newspare_'.$type.'_'.$server.'" '.
4403: 'id="newspare_'.$type.'_'.$server.'" onchange="checkNewSpares('."'$server','$type'".');">'."\n".
4404: '<option value="" selected ="selected">'.&mt('Select').'</option>'."\n";
4405: if (@choices > 0) {
4406: foreach my $lonhost (@choices) {
4407: $canselect{$type} .= '<option value="'.$lonhost.'">'.$lonhost.'</option>'."\n";
4408: }
4409: }
4410: $canselect{$type} .= '</select>'."\n";
4411: }
4412: } else {
4413: $current{$type} = &mt('Could not be determined');
4414: if ($type eq 'primary') {
4415: $canselect{$type} = $othercontrol;
4416: }
1.145 raeburn 4417: }
1.152 raeburn 4418: if ($type eq 'default') {
4419: $datatable .= '<tr'.$css_class.'>';
4420: }
4421: $datatable .= '<td><i>'.$typetitles{$type}.'</i></td>'."\n".
4422: '<td>'.$current{$type}.'</td>'."\n".
4423: '<td>'.$canselect{$type}.'</td></tr>'."\n";
1.145 raeburn 4424: }
4425: $itemcount ++;
4426: }
4427: }
4428: $$rowtotal += $itemcount;
4429: return $datatable;
4430: }
4431:
1.152 raeburn 4432: sub possible_newspares {
4433: my ($server,$currspares,$serverhomes,$altids) = @_;
4434: my $serverhostname = &Apache::lonnet::hostname($server);
4435: my %excluded;
4436: if ($serverhostname ne '') {
4437: %excluded = (
4438: $serverhostname => 1,
4439: );
4440: }
4441: if (ref($currspares) eq 'HASH') {
4442: foreach my $type (keys(%{$currspares})) {
4443: if (ref($currspares->{$type}) eq 'ARRAY') {
4444: if (@{$currspares->{$type}} > 0) {
4445: foreach my $curr (@{$currspares->{$type}}) {
4446: my $hostname = &Apache::lonnet::hostname($curr);
4447: $excluded{$hostname} = 1;
4448: }
4449: }
4450: }
4451: }
4452: }
4453: my @choices;
4454: if ((ref($serverhomes) eq 'HASH') && (ref($altids) eq 'HASH')) {
4455: if (keys(%{$serverhomes}) > 1) {
4456: foreach my $name (sort(keys(%{$serverhomes}))) {
4457: unless ($excluded{$name}) {
4458: if (exists($altids->{$serverhomes->{$name}})) {
4459: push(@choices,$altids->{$serverhomes->{$name}});
4460: } else {
4461: push(@choices,$serverhomes->{$name});
1.145 raeburn 4462: }
4463: }
4464: }
4465: }
4466: }
1.152 raeburn 4467: return sort(@choices);
1.145 raeburn 4468: }
4469:
1.150 raeburn 4470: sub print_loadbalancing {
4471: my ($dom,$settings,$rowtotal) = @_;
4472: my $primary_id = &Apache::lonnet::domain($dom,'primary');
4473: my $intdom = &Apache::lonnet::internet_dom($primary_id);
4474: my $numinrow = 1;
4475: my $datatable;
4476: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.171 raeburn 4477: my (%currbalancer,%currtargets,%currrules,%existing);
4478: if (ref($settings) eq 'HASH') {
4479: %existing = %{$settings};
4480: }
4481: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
4482: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
4483: \%currtargets,\%currrules);
1.150 raeburn 4484: } else {
4485: return;
4486: }
4487: my ($othertitle,$usertypes,$types) =
4488: &Apache::loncommon::sorted_inst_types($dom);
1.209 raeburn 4489: my $rownum = 8;
1.150 raeburn 4490: if (ref($types) eq 'ARRAY') {
4491: $rownum += scalar(@{$types});
4492: }
1.171 raeburn 4493: my @css_class = ('LC_odd_row','LC_even_row');
4494: my $balnum = 0;
4495: my $islast;
4496: my (@toshow,$disabledtext);
4497: if (keys(%currbalancer) > 0) {
4498: @toshow = sort(keys(%currbalancer));
4499: if (scalar(@toshow) < scalar(keys(%servers)) + 1) {
4500: push(@toshow,'');
4501: }
4502: } else {
4503: @toshow = ('');
4504: $disabledtext = &mt('No existing load balancer');
4505: }
4506: foreach my $lonhost (@toshow) {
4507: if ($balnum == scalar(@toshow)-1) {
4508: $islast = 1;
4509: } else {
4510: $islast = 0;
4511: }
4512: my $cssidx = $balnum%2;
4513: my $targets_div_style = 'display: none';
4514: my $disabled_div_style = 'display: block';
4515: my $homedom_div_style = 'display: none';
4516: $datatable .= '<tr class="'.$css_class[$cssidx].'">'.
4517: '<td rowspan="'.$rownum.'" valign="top">'.
4518: '<p>';
4519: if ($lonhost eq '') {
1.210 raeburn 4520: $datatable .= '<span class="LC_nobreak">';
1.171 raeburn 4521: if (keys(%currbalancer) > 0) {
4522: $datatable .= &mt('Add balancer:');
4523: } else {
4524: $datatable .= &mt('Enable balancer:');
4525: }
4526: $datatable .= ' '.
4527: '<select name="loadbalancing_lonhost_'.$balnum.'"'.
4528: ' id="loadbalancing_lonhost_'.$balnum.'"'.
4529: ' onchange="toggleTargets('."'$balnum'".');">'."\n".
4530: '<option value="" selected="selected">'.&mt('None').
4531: '</option>'."\n";
4532: foreach my $server (sort(keys(%servers))) {
4533: next if ($currbalancer{$server});
4534: $datatable .= '<option value="'.$server.'">'.$server.'</option>'."\n";
4535: }
1.210 raeburn 4536: $datatable .=
1.171 raeburn 4537: '</select>'."\n".
4538: '<input type="hidden" name="loadbalancing_prevlonhost_'.$balnum.'" id="loadbalancing_prevlonhost_'.$balnum.'" value="" /> </span>'."\n";
4539: } else {
4540: $datatable .= '<i>'.$lonhost.'</i><br /><span class="LC_nobreak">'.
4541: '<label><input type="checkbox" name="loadbalancing_delete" value="'.$balnum.'" id="loadbalancing_delete_'.$balnum.'" onclick="javascript:balancerDeleteChange('."'$balnum'".');" /> '.
4542: &mt('Stop balancing').'</label>'.
4543: '<input type="hidden" name="loadbalancing_lonhost_'.$balnum.'" value="'.$lonhost.'" id="loadbalancing_lonhost_'.$balnum.'" /></span>';
4544: $targets_div_style = 'display: block';
4545: $disabled_div_style = 'display: none';
4546: if ($dom eq &Apache::lonnet::host_domain($lonhost)) {
4547: $homedom_div_style = 'display: block';
4548: }
4549: }
4550: $datatable .= '</p></td><td rowspan="'.$rownum.'" valign="top">'.
4551: '<div id="loadbalancing_disabled_'.$balnum.'" style="'.
4552: $disabled_div_style.'">'.$disabledtext.'</div>'."\n".
4553: '<div id="loadbalancing_targets_'.$balnum.'" style="'.$targets_div_style.'">'.&mt('Offloads to:').'<br />';
4554: my ($numspares,@spares) = &count_servers($lonhost,%servers);
4555: my @sparestypes = ('primary','default');
4556: my %typetitles = &sparestype_titles();
4557: foreach my $sparetype (@sparestypes) {
4558: my $targettable;
4559: for (my $i=0; $i<$numspares; $i++) {
4560: my $checked;
4561: if (ref($currtargets{$lonhost}) eq 'HASH') {
4562: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
4563: if (grep(/^\Q$spares[$i]\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
4564: $checked = ' checked="checked"';
4565: }
4566: }
4567: }
4568: my ($chkboxval,$disabled);
4569: if (($lonhost ne '') && (exists($servers{$lonhost}))) {
4570: $chkboxval = $spares[$i];
4571: }
4572: if (exists($currbalancer{$spares[$i]})) {
4573: $disabled = ' disabled="disabled"';
4574: }
1.210 raeburn 4575: $targettable .=
1.253 raeburn 4576: '<td><span class="LC_nobreak"><label>'.
4577: '<input type="checkbox" name="loadbalancing_target_'.$balnum.'_'.$sparetype.'"'.
1.171 raeburn 4578: $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 4579: '</span></label></span></td>';
1.171 raeburn 4580: my $rem = $i%($numinrow);
4581: if ($rem == 0) {
4582: if (($i > 0) && ($i < $numspares-1)) {
4583: $targettable .= '</tr>';
4584: }
4585: if ($i < $numspares-1) {
4586: $targettable .= '<tr>';
1.150 raeburn 4587: }
4588: }
4589: }
1.171 raeburn 4590: if ($targettable ne '') {
4591: my $rem = $numspares%($numinrow);
4592: my $colsleft = $numinrow - $rem;
4593: if ($colsleft > 1 ) {
4594: $targettable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
4595: ' </td>';
4596: } elsif ($colsleft == 1) {
4597: $targettable .= '<td class="LC_left_item"> </td>';
4598: }
4599: $datatable .= '<i>'.$typetitles{$sparetype}.'</i><br />'.
4600: '<table><tr>'.$targettable.'</tr></table><br />';
4601: }
4602: }
4603: $datatable .= '</div></td></tr>'.
4604: &loadbalancing_rules($dom,$intdom,$currrules{$lonhost},
4605: $othertitle,$usertypes,$types,\%servers,
4606: \%currbalancer,$lonhost,
4607: $targets_div_style,$homedom_div_style,
4608: $css_class[$cssidx],$balnum,$islast);
4609: $$rowtotal += $rownum;
4610: $balnum ++;
4611: }
4612: $datatable .= '<input type="hidden" name="loadbalancing_total" id="loadbalancing_total" value="'.$balnum.'" />';
4613: return $datatable;
4614: }
4615:
4616: sub get_loadbalancers_config {
4617: my ($servers,$existing,$currbalancer,$currtargets,$currrules) = @_;
4618: return unless ((ref($servers) eq 'HASH') &&
4619: (ref($existing) eq 'HASH') && (ref($currbalancer) eq 'HASH') &&
4620: (ref($currtargets) eq 'HASH') && (ref($currrules) eq 'HASH'));
4621: if (keys(%{$existing}) > 0) {
4622: my $oldlonhost;
4623: foreach my $key (sort(keys(%{$existing}))) {
4624: if ($key eq 'lonhost') {
4625: $oldlonhost = $existing->{'lonhost'};
4626: $currbalancer->{$oldlonhost} = 1;
4627: } elsif ($key eq 'targets') {
4628: if ($oldlonhost) {
4629: $currtargets->{$oldlonhost} = $existing->{'targets'};
4630: }
4631: } elsif ($key eq 'rules') {
4632: if ($oldlonhost) {
4633: $currrules->{$oldlonhost} = $existing->{'rules'};
4634: }
4635: } elsif (ref($existing->{$key}) eq 'HASH') {
4636: $currbalancer->{$key} = 1;
4637: $currtargets->{$key} = $existing->{$key}{'targets'};
4638: $currrules->{$key} = $existing->{$key}{'rules'};
1.150 raeburn 4639: }
4640: }
1.171 raeburn 4641: } else {
4642: my ($balancerref,$targetsref) =
4643: &Apache::lonnet::get_lonbalancer_config($servers);
4644: if ((ref($balancerref) eq 'HASH') && (ref($targetsref) eq 'HASH')) {
4645: foreach my $server (sort(keys(%{$balancerref}))) {
4646: $currbalancer->{$server} = 1;
4647: $currtargets->{$server} = $targetsref->{$server};
1.150 raeburn 4648: }
4649: }
4650: }
1.171 raeburn 4651: return;
1.150 raeburn 4652: }
4653:
4654: sub loadbalancing_rules {
4655: my ($dom,$intdom,$currrules,$othertitle,$usertypes,$types,$servers,
1.171 raeburn 4656: $currbalancer,$lonhost,$targets_div_style,$homedom_div_style,
4657: $css_class,$balnum,$islast) = @_;
1.150 raeburn 4658: my $output;
1.171 raeburn 4659: my $num = 0;
1.210 raeburn 4660: my ($alltypes,$othertypes,$titles) =
1.150 raeburn 4661: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
4662: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
4663: foreach my $type (@{$alltypes}) {
1.171 raeburn 4664: $num ++;
1.150 raeburn 4665: my $current;
4666: if (ref($currrules) eq 'HASH') {
4667: $current = $currrules->{$type};
4668: }
1.253 raeburn 4669: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.171 raeburn 4670: if ($dom ne &Apache::lonnet::host_domain($lonhost)) {
1.150 raeburn 4671: $current = '';
4672: }
4673: }
4674: $output .= &loadbalance_rule_row($type,$titles->{$type},$current,
1.171 raeburn 4675: $servers,$currbalancer,$lonhost,$dom,
4676: $targets_div_style,$homedom_div_style,
4677: $css_class,$balnum,$num,$islast);
1.150 raeburn 4678: }
4679: }
4680: return $output;
4681: }
4682:
4683: sub loadbalancing_titles {
4684: my ($dom,$intdom,$usertypes,$types) = @_;
4685: my %othertypes = (
4686: '_LC_adv' => &mt('Advanced users from [_1]',$dom),
4687: '_LC_author' => &mt('Users from [_1] with author role',$dom),
4688: '_LC_internetdom' => &mt('Users not from [_1], but from [_2]',$dom,$intdom),
4689: '_LC_external' => &mt('Users not from [_1]',$intdom),
1.209 raeburn 4690: '_LC_ipchangesso' => &mt('SSO users from [_1], with IP mismatch',$dom),
4691: '_LC_ipchange' => &mt('Non-SSO users with IP mismatch'),
1.150 raeburn 4692: );
1.209 raeburn 4693: my @alltypes = ('_LC_adv','_LC_author','_LC_internetdom','_LC_external','_LC_ipchangesso','_LC_ipchange');
1.150 raeburn 4694: if (ref($types) eq 'ARRAY') {
4695: unshift(@alltypes,@{$types},'default');
4696: }
4697: my %titles;
4698: foreach my $type (@alltypes) {
4699: if ($type =~ /^_LC_/) {
4700: $titles{$type} = $othertypes{$type};
4701: } elsif ($type eq 'default') {
4702: $titles{$type} = &mt('All users from [_1]',$dom);
4703: if (ref($types) eq 'ARRAY') {
4704: if (@{$types} > 0) {
4705: $titles{$type} = &mt('Other users from [_1]',$dom);
4706: }
4707: }
4708: } elsif (ref($usertypes) eq 'HASH') {
4709: $titles{$type} = $usertypes->{$type};
4710: }
4711: }
4712: return (\@alltypes,\%othertypes,\%titles);
4713: }
4714:
4715: sub loadbalance_rule_row {
1.171 raeburn 4716: my ($type,$title,$current,$servers,$currbalancer,$lonhost,$dom,
4717: $targets_div_style,$homedom_div_style,$css_class,$balnum,$num,$islast) = @_;
1.209 raeburn 4718: my @rulenames;
1.150 raeburn 4719: my %ruletitles = &offloadtype_text();
1.209 raeburn 4720: if (($type eq '_LC_ipchangesso') || ($type eq '_LC_ipchange')) {
1.254 raeburn 4721: @rulenames = ('balancer','offloadedto','specific');
1.150 raeburn 4722: } else {
1.209 raeburn 4723: @rulenames = ('default','homeserver');
4724: if ($type eq '_LC_external') {
4725: push(@rulenames,'externalbalancer');
4726: } else {
4727: push(@rulenames,'specific');
4728: }
4729: push(@rulenames,'none');
1.150 raeburn 4730: }
4731: my $style = $targets_div_style;
1.253 raeburn 4732: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.150 raeburn 4733: $style = $homedom_div_style;
4734: }
1.171 raeburn 4735: my $space;
4736: if ($islast && $num == 1) {
4737: $space = '<div display="inline-block"> </div>';
4738: }
1.210 raeburn 4739: my $output =
1.171 raeburn 4740: '<tr class="'.$css_class.'" id="balanceruletr_'.$balnum.'_'.$num.'"><td valign="top">'.$space.
4741: '<div id="balanceruletitle_'.$balnum.'_'.$type.'" style="'.$style.'">'.$title.'</div></td>'."\n".
4742: '<td valaign="top">'.$space.
4743: '<div id="balancerule_'.$balnum.'_'.$type.'" style="'.$style.'">'."\n";
1.150 raeburn 4744: for (my $i=0; $i<@rulenames; $i++) {
4745: my $rule = $rulenames[$i];
4746: my ($checked,$extra);
4747: if ($rulenames[$i] eq 'default') {
4748: $rule = '';
4749: }
4750: if ($rulenames[$i] eq 'specific') {
4751: if (ref($servers) eq 'HASH') {
4752: my $default;
4753: if (($current ne '') && (exists($servers->{$current}))) {
4754: $checked = ' checked="checked"';
4755: }
4756: unless ($checked) {
4757: $default = ' selected="selected"';
4758: }
1.210 raeburn 4759: $extra =
1.171 raeburn 4760: ': <select name="loadbalancing_singleserver_'.$balnum.'_'.$type.
4761: '" id="loadbalancing_singleserver_'.$balnum.'_'.$type.
4762: '" onchange="singleServerToggle('."'$balnum','$type'".')">'."\n".
4763: '<option value=""'.$default.'></option>'."\n";
4764: foreach my $server (sort(keys(%{$servers}))) {
4765: if (ref($currbalancer) eq 'HASH') {
4766: next if (exists($currbalancer->{$server}));
4767: }
1.150 raeburn 4768: my $selected;
1.171 raeburn 4769: if ($server eq $current) {
1.150 raeburn 4770: $selected = ' selected="selected"';
4771: }
1.171 raeburn 4772: $extra .= '<option value="'.$server.'"'.$selected.'>'.$server.'</option>';
1.150 raeburn 4773: }
4774: $extra .= '</select>';
4775: }
4776: } elsif ($rule eq $current) {
4777: $checked = ' checked="checked"';
4778: }
4779: $output .= '<span class="LC_nobreak"><label>'.
1.171 raeburn 4780: '<input type="radio" name="loadbalancing_rules_'.$balnum.'_'.$type.
4781: '" id="loadbalancing_rules_'.$balnum.'_'.$type.'_'.$i.'" value="'.
4782: $rule.'" onclick="balanceruleChange('."this.form,'$balnum','$type'".
1.254 raeburn 4783: ')"'.$checked.' /> ';
4784: if (($rulenames[$i] eq 'specific') && ($type =~ /^_LC_ipchange/)) {
4785: $output .= $ruletitles{'particular'};
4786: } else {
4787: $output .= $ruletitles{$rulenames[$i]};
4788: }
4789: $output .= '</label>'.$extra.'</span><br />'."\n";
1.150 raeburn 4790: }
4791: $output .= '</div></td></tr>'."\n";
4792: return $output;
4793: }
4794:
4795: sub offloadtype_text {
4796: my %ruletitles = &Apache::lonlocal::texthash (
4797: 'default' => 'Offloads to default destinations',
4798: 'homeserver' => "Offloads to user's home server",
4799: 'externalbalancer' => "Offloads to Load Balancer in user's domain",
4800: 'specific' => 'Offloads to specific server',
1.161 raeburn 4801: 'none' => 'No offload',
1.209 raeburn 4802: 'balancer' => 'Session hosted on Load Balancer, after re-authentication',
4803: 'offloadedto' => 'Session hosted on offload server, after re-authentication',
1.254 raeburn 4804: 'particular' => 'Session hosted (after re-auth) on server:',
1.150 raeburn 4805: );
4806: return %ruletitles;
4807: }
4808:
4809: sub sparestype_titles {
4810: my %typestitles = &Apache::lonlocal::texthash (
4811: 'primary' => 'primary',
4812: 'default' => 'default',
4813: );
4814: return %typestitles;
4815: }
4816:
1.28 raeburn 4817: sub contact_titles {
4818: my %titles = &Apache::lonlocal::texthash (
4819: 'supportemail' => 'Support E-mail address',
1.69 raeburn 4820: 'adminemail' => 'Default Server Admin E-mail address',
1.28 raeburn 4821: 'errormail' => 'Error reports to be e-mailed to',
4822: 'packagesmail' => 'Package update alerts to be e-mailed to',
1.89 raeburn 4823: 'helpdeskmail' => 'Helpdesk requests to be e-mailed to',
4824: 'lonstatusmail' => 'E-mail from nightly status check (warnings/errors)',
1.102 raeburn 4825: 'requestsmail' => 'E-mail from course requests requiring approval',
1.190 raeburn 4826: 'updatesmail' => 'E-mail from nightly check of LON-CAPA module integrity/updates',
1.203 raeburn 4827: 'idconflictsmail' => 'E-mail from bi-nightly check for multiple users sharing same student/employee ID',
1.28 raeburn 4828: );
4829: my %short_titles = &Apache::lonlocal::texthash (
4830: adminemail => 'Admin E-mail address',
4831: supportemail => 'Support E-mail',
4832: );
4833: return (\%titles,\%short_titles);
4834: }
4835:
1.72 raeburn 4836: sub tool_titles {
4837: my %titles = &Apache::lonlocal::texthash (
1.162 raeburn 4838: aboutme => 'Personal web page',
1.86 raeburn 4839: blog => 'Blog',
1.162 raeburn 4840: webdav => 'WebDAV',
1.86 raeburn 4841: portfolio => 'Portfolio',
1.88 bisitz 4842: official => 'Official courses (with institutional codes)',
4843: unofficial => 'Unofficial courses',
1.98 raeburn 4844: community => 'Communities',
1.216 raeburn 4845: textbook => 'Textbook courses',
1.271 raeburn 4846: placement => 'Placement tests',
1.86 raeburn 4847: );
1.72 raeburn 4848: return %titles;
4849: }
4850:
1.101 raeburn 4851: sub courserequest_titles {
4852: my %titles = &Apache::lonlocal::texthash (
4853: official => 'Official',
4854: unofficial => 'Unofficial',
4855: community => 'Communities',
1.216 raeburn 4856: textbook => 'Textbook',
1.271 raeburn 4857: placement => 'Placement tests',
1.101 raeburn 4858: norequest => 'Not allowed',
1.104 raeburn 4859: approval => 'Approval by Dom. Coord.',
1.101 raeburn 4860: validate => 'With validation',
4861: autolimit => 'Numerical limit',
1.103 raeburn 4862: unlimited => '(blank for unlimited)',
1.101 raeburn 4863: );
4864: return %titles;
4865: }
4866:
1.163 raeburn 4867: sub authorrequest_titles {
4868: my %titles = &Apache::lonlocal::texthash (
4869: norequest => 'Not allowed',
4870: approval => 'Approval by Dom. Coord.',
4871: automatic => 'Automatic approval',
4872: );
4873: return %titles;
1.210 raeburn 4874: }
1.163 raeburn 4875:
1.101 raeburn 4876: sub courserequest_conditions {
4877: my %conditions = &Apache::lonlocal::texthash (
1.104 raeburn 4878: approval => '(Processing of request subject to approval by Domain Coordinator).',
1.193 bisitz 4879: validate => '(Processing of request subject to institutional validation).',
1.101 raeburn 4880: );
4881: return %conditions;
4882: }
4883:
4884:
1.27 raeburn 4885: sub print_usercreation {
1.30 raeburn 4886: my ($position,$dom,$settings,$rowtotal) = @_;
1.27 raeburn 4887: my $numinrow = 4;
1.28 raeburn 4888: my $datatable;
4889: if ($position eq 'top') {
1.30 raeburn 4890: $$rowtotal ++;
1.34 raeburn 4891: my $rowcount = 0;
1.32 raeburn 4892: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username');
1.28 raeburn 4893: if (ref($rules) eq 'HASH') {
4894: if (keys(%{$rules}) > 0) {
1.32 raeburn 4895: $datatable .= &user_formats_row('username',$settings,$rules,
4896: $ruleorder,$numinrow,$rowcount);
1.30 raeburn 4897: $$rowtotal ++;
1.32 raeburn 4898: $rowcount ++;
4899: }
4900: }
4901: my ($idrules,$idruleorder) = &Apache::lonnet::inst_userrules($dom,'id');
4902: if (ref($idrules) eq 'HASH') {
4903: if (keys(%{$idrules}) > 0) {
4904: $datatable .= &user_formats_row('id',$settings,$idrules,
4905: $idruleorder,$numinrow,$rowcount);
4906: $$rowtotal ++;
4907: $rowcount ++;
1.28 raeburn 4908: }
4909: }
1.39 raeburn 4910: if ($rowcount == 0) {
4911: $datatable .= '<tr><td colspan="2">'.&mt('No format rules have been defined for usernames or IDs in this domain.').'</td></tr>';
4912: $$rowtotal ++;
4913: $rowcount ++;
4914: }
1.34 raeburn 4915: } elsif ($position eq 'middle') {
1.224 raeburn 4916: my @creators = ('author','course','requestcrs');
1.37 raeburn 4917: my ($rules,$ruleorder) =
4918: &Apache::lonnet::inst_userrules($dom,'username');
1.34 raeburn 4919: my %lt = &usercreation_types();
4920: my %checked;
4921: if (ref($settings) eq 'HASH') {
4922: if (ref($settings->{'cancreate'}) eq 'HASH') {
4923: foreach my $item (@creators) {
4924: $checked{$item} = $settings->{'cancreate'}{$item};
4925: }
4926: } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {
4927: foreach my $item (@creators) {
4928: if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {
4929: $checked{$item} = 'none';
4930: }
4931: }
4932: }
4933: }
4934: my $rownum = 0;
4935: foreach my $item (@creators) {
4936: $rownum ++;
1.224 raeburn 4937: if ($checked{$item} eq '') {
4938: $checked{$item} = 'any';
1.34 raeburn 4939: }
4940: my $css_class;
4941: if ($rownum%2) {
4942: $css_class = '';
4943: } else {
4944: $css_class = ' class="LC_odd_row" ';
4945: }
4946: $datatable .= '<tr'.$css_class.'>'.
4947: '<td><span class="LC_nobreak">'.$lt{$item}.
4948: '</span></td><td align="right">';
1.224 raeburn 4949: my @options = ('any');
4950: if (ref($rules) eq 'HASH') {
4951: if (keys(%{$rules}) > 0) {
4952: push(@options,('official','unofficial'));
1.37 raeburn 4953: }
4954: }
1.224 raeburn 4955: push(@options,'none');
1.37 raeburn 4956: foreach my $option (@options) {
1.50 raeburn 4957: my $type = 'radio';
1.34 raeburn 4958: my $check = ' ';
1.224 raeburn 4959: if ($checked{$item} eq $option) {
4960: $check = ' checked="checked" ';
1.34 raeburn 4961: }
4962: $datatable .= '<span class="LC_nobreak"><label>'.
1.50 raeburn 4963: '<input type="'.$type.'" name="can_createuser_'.
1.34 raeburn 4964: $item.'" value="'.$option.'"'.$check.'/> '.
4965: $lt{$option}.'</label> </span>';
4966: }
4967: $datatable .= '</td></tr>';
4968: }
1.28 raeburn 4969: } else {
4970: my @contexts = ('author','course','domain');
4971: my @authtypes = ('int','krb4','krb5','loc');
4972: my %checked;
4973: if (ref($settings) eq 'HASH') {
4974: if (ref($settings->{'authtypes'}) eq 'HASH') {
4975: foreach my $item (@contexts) {
4976: if (ref($settings->{'authtypes'}{$item}) eq 'HASH') {
4977: foreach my $auth (@authtypes) {
4978: if ($settings->{'authtypes'}{$item}{$auth}) {
4979: $checked{$item}{$auth} = ' checked="checked" ';
4980: }
4981: }
4982: }
4983: }
1.27 raeburn 4984: }
1.35 raeburn 4985: } else {
4986: foreach my $item (@contexts) {
1.36 raeburn 4987: foreach my $auth (@authtypes) {
1.35 raeburn 4988: $checked{$item}{$auth} = ' checked="checked" ';
4989: }
4990: }
1.27 raeburn 4991: }
1.28 raeburn 4992: my %title = &context_names();
4993: my %authname = &authtype_names();
4994: my $rownum = 0;
4995: my $css_class;
4996: foreach my $item (@contexts) {
4997: if ($rownum%2) {
4998: $css_class = '';
4999: } else {
5000: $css_class = ' class="LC_odd_row" ';
5001: }
1.30 raeburn 5002: $datatable .= '<tr'.$css_class.'>'.
1.28 raeburn 5003: '<td>'.$title{$item}.
5004: '</td><td class="LC_left_item">'.
5005: '<span class="LC_nobreak">';
5006: foreach my $auth (@authtypes) {
5007: $datatable .= '<label>'.
5008: '<input type="checkbox" name="'.$item.'_auth" '.
5009: $checked{$item}{$auth}.' value="'.$auth.'" />'.
5010: $authname{$auth}.'</label> ';
5011: }
5012: $datatable .= '</span></td></tr>';
5013: $rownum ++;
1.27 raeburn 5014: }
1.30 raeburn 5015: $$rowtotal += $rownum;
1.27 raeburn 5016: }
5017: return $datatable;
5018: }
5019:
1.224 raeburn 5020: sub print_selfcreation {
5021: my ($position,$dom,$settings,$rowtotal) = @_;
1.236 raeburn 5022: my (@selfcreate,$createsettings,$processing,$datatable);
1.224 raeburn 5023: if (ref($settings) eq 'HASH') {
5024: if (ref($settings->{'cancreate'}) eq 'HASH') {
5025: $createsettings = $settings->{'cancreate'};
1.236 raeburn 5026: if (ref($createsettings) eq 'HASH') {
5027: if (ref($createsettings->{'selfcreate'}) eq 'ARRAY') {
5028: @selfcreate = @{$createsettings->{'selfcreate'}};
5029: } elsif ($createsettings->{'selfcreate'} ne '') {
5030: if ($settings->{'cancreate'}{'selfcreate'} eq 'any') {
5031: @selfcreate = ('email','login','sso');
5032: } elsif ($createsettings->{'selfcreate'} ne 'none') {
5033: @selfcreate = ($createsettings->{'selfcreate'});
5034: }
5035: }
5036: if (ref($createsettings->{'selfcreateprocessing'}) eq 'HASH') {
5037: $processing = $createsettings->{'selfcreateprocessing'};
1.224 raeburn 5038: }
5039: }
5040: }
5041: }
5042: my %radiohash;
5043: my $numinrow = 4;
5044: map { $radiohash{'cancreate_'.$_} = 1; } @selfcreate;
5045: if ($position eq 'top') {
5046: my %choices = &Apache::lonlocal::texthash (
5047: cancreate_login => 'Institutional Login',
5048: cancreate_sso => 'Institutional Single Sign On',
5049: );
5050: my @toggles = sort(keys(%choices));
5051: my %defaultchecked = (
5052: 'cancreate_login' => 'off',
5053: 'cancreate_sso' => 'off',
5054: );
1.228 raeburn 5055: my ($onclick,$itemcount);
1.224 raeburn 5056: ($datatable,$itemcount) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
5057: \%choices,$itemcount,$onclick);
1.228 raeburn 5058: $$rowtotal += $itemcount;
5059:
1.224 raeburn 5060: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
5061:
5062: if (ref($usertypes) eq 'HASH') {
5063: if (keys(%{$usertypes}) > 0) {
5064: $datatable .= &insttypes_row($createsettings,$types,$usertypes,
5065: $dom,$numinrow,$othertitle,
1.228 raeburn 5066: 'statustocreate',$$rowtotal);
1.224 raeburn 5067: $$rowtotal ++;
5068: }
5069: }
1.240 raeburn 5070: my @fields = ('lastname','firstname','middlename','permanentemail','id','inststatus');
5071: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
5072: $fieldtitles{'inststatus'} = &mt('Institutional status');
5073: my $rem;
5074: my $numperrow = 2;
5075: my $css_class = $$rowtotal%2?' class="LC_odd_row"':'';
5076: $datatable .= '<tr'.$css_class.'>'.
1.241 raeburn 5077: '<td class="LC_left_item">'.&mt('Mapping of Shibboleth environment variable names to user data fields (SSO auth)').'</td>'.
1.240 raeburn 5078: '<td class="LC_left_item">'."\n".
5079: '<table><tr><td>'."\n";
5080: for (my $i=0; $i<@fields; $i++) {
5081: $rem = $i%($numperrow);
5082: if ($rem == 0) {
5083: if ($i > 0) {
5084: $datatable .= '</tr>';
5085: }
5086: $datatable .= '<tr>';
5087: }
5088: my $currval;
1.248 raeburn 5089: if (ref($createsettings) eq 'HASH') {
5090: if (ref($createsettings->{'shibenv'}) eq 'HASH') {
5091: $currval = $createsettings->{'shibenv'}{$fields[$i]};
5092: }
1.240 raeburn 5093: }
5094: $datatable .= '<td class="LC_left_item">'.
5095: '<span class="LC_nobreak">'.
5096: '<input type="text" name="shibenv_'.$fields[$i].'" '.
5097: 'value="'.$currval.'" size="10" /> '.
5098: $fieldtitles{$fields[$i]}.'</span></td>';
5099: }
5100: my $colsleft = $numperrow - $rem;
5101: if ($colsleft > 1 ) {
5102: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
5103: ' </td>';
5104: } elsif ($colsleft == 1) {
5105: $datatable .= '<td class="LC_left_item"> </td>';
5106: }
5107: $datatable .= '</tr></table></td></tr>';
5108: $$rowtotal ++;
1.224 raeburn 5109: } elsif ($position eq 'middle') {
5110: my %domconf = &Apache::lonnet::get_dom('configuration',['usermodification'],$dom);
5111: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
5112: $usertypes->{'default'} = $othertitle;
5113: if (ref($types) eq 'ARRAY') {
5114: push(@{$types},'default');
5115: $usertypes->{'default'} = $othertitle;
5116: foreach my $status (@{$types}) {
5117: $datatable .= &modifiable_userdata_row('selfcreate',$status,$domconf{'usermodification'},
1.228 raeburn 5118: $numinrow,$$rowtotal,$usertypes);
1.240 raeburn 5119: $$rowtotal ++;
1.224 raeburn 5120: }
5121: }
5122: } else {
1.236 raeburn 5123: my %choices = &Apache::lonlocal::texthash (
5124: cancreate_email => 'E-mail address as username',
5125: );
5126: my @toggles = sort(keys(%choices));
5127: my %defaultchecked = (
5128: 'cancreate_email' => 'off',
5129: );
5130: my $itemcount = 0;
5131: my $display = 'none';
5132: if (grep(/^\Qemail\E$/,@selfcreate)) {
5133: $display = 'block';
5134: }
5135: my $onclick = "toggleDisplay(this.form,'emailoptions');";
5136: my $additional = '<div id="emailoptions" style="display: '.$display.'">';
5137: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
5138: my $usertypes = {};
5139: my $order = [];
5140: if ((ref($domdefaults{'inststatustypes'}) eq 'HASH') && (ref($domdefaults{'inststatusguest'}) eq 'ARRAY')) {
5141: $usertypes = $domdefaults{'inststatustypes'};
5142: $order = $domdefaults{'inststatusguest'};
5143: }
5144: if (ref($order) eq 'ARRAY') {
5145: push(@{$order},'default');
5146: if (@{$order} > 1) {
5147: $usertypes->{'default'} = &mt('Other users');
5148: $additional .= '<table><tr>';
5149: foreach my $status (@{$order}) {
5150: $additional .= '<th>'.$usertypes->{$status}.'</th>';
5151: }
5152: $additional .= '</tr><tr>';
5153: foreach my $status (@{$order}) {
5154: $additional .= '<td>'.&email_as_username($rowtotal,$processing,$status).'</td>';
1.224 raeburn 5155: }
1.236 raeburn 5156: $additional .= '</tr></table>';
1.224 raeburn 5157: } else {
1.236 raeburn 5158: $usertypes->{'default'} = &mt('All users');
5159: $additional .= &email_as_username($rowtotal,$processing);
1.224 raeburn 5160: }
5161: }
1.236 raeburn 5162: $additional .= '</div>'."\n";
5163:
5164: ($datatable,$itemcount) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
1.240 raeburn 5165: \%choices,$$rowtotal,$onclick,$additional);
5166: $$rowtotal ++;
1.236 raeburn 5167: $datatable .= &print_requestmail($dom,'selfcreation',$createsettings,$rowtotal);
1.228 raeburn 5168: $$rowtotal ++;
1.224 raeburn 5169: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
1.228 raeburn 5170: $numinrow = 1;
1.236 raeburn 5171: if (ref($order) eq 'ARRAY') {
5172: foreach my $status (@{$order}) {
1.228 raeburn 5173: $datatable .= &modifiable_userdata_row('cancreate','emailusername_'.$status,$settings,
5174: $numinrow,$$rowtotal,$usertypes,$infofields,$infotitles);
5175: $$rowtotal ++;
5176: }
5177: }
1.224 raeburn 5178: my ($emailrules,$emailruleorder) =
5179: &Apache::lonnet::inst_userrules($dom,'email');
5180: if (ref($emailrules) eq 'HASH') {
5181: if (keys(%{$emailrules}) > 0) {
5182: $datatable .= &user_formats_row('email',$settings,$emailrules,
1.228 raeburn 5183: $emailruleorder,$numinrow,$$rowtotal);
1.224 raeburn 5184: $$rowtotal ++;
5185: }
5186: }
1.228 raeburn 5187: $datatable .= &captcha_choice('cancreate',$createsettings,$$rowtotal);
1.224 raeburn 5188: }
5189: return $datatable;
5190: }
5191:
1.236 raeburn 5192: sub email_as_username {
5193: my ($rowtotal,$processing,$type) = @_;
5194: my %choices =
5195: &Apache::lonlocal::texthash (
5196: automatic => 'Automatic approval',
5197: approval => 'Queued for approval',
5198: );
5199: my $output;
5200: foreach my $option ('automatic','approval') {
5201: my $checked;
5202: if (ref($processing) eq 'HASH') {
5203: if ($type eq '') {
5204: if (!exists($processing->{'default'})) {
5205: if ($option eq 'automatic') {
5206: $checked = ' checked="checked"';
5207: }
5208: } else {
5209: if ($processing->{'default'} eq $option) {
5210: $checked = ' checked="checked"';
5211: }
5212: }
5213: } else {
5214: if (!exists($processing->{$type})) {
5215: if ($option eq 'automatic') {
5216: $checked = ' checked="checked"';
5217: }
5218: } else {
5219: if ($processing->{$type} eq $option) {
5220: $checked = ' checked="checked"';
5221: }
5222: }
5223: }
5224: } elsif ($option eq 'automatic') {
5225: $checked = ' checked="checked"';
5226: }
5227: my $name = 'cancreate_emailprocess';
5228: if (($type ne '') && ($type ne 'default')) {
5229: $name .= '_'.$type;
5230: }
5231: $output .= '<span class="LC_nobreak"><label>'.
5232: '<input type="radio" name="'.$name.'"'.
5233: $checked.' value="'.$option.'" />'.
5234: $choices{$option}.'</label></span>';
5235: if ($type eq '') {
5236: $output .= ' ';
5237: } else {
5238: $output .= '<br />';
5239: }
5240: }
5241: $$rowtotal ++;
5242: return $output;
5243: }
5244:
1.165 raeburn 5245: sub captcha_choice {
1.169 raeburn 5246: my ($context,$settings,$itemcount) = @_;
1.269 raeburn 5247: my ($keyentry,$currpub,$currpriv,%checked,$rowname,$pubtext,$privtext,
5248: $vertext,$currver);
1.165 raeburn 5249: my %lt = &captcha_phrases();
5250: $keyentry = 'hidden';
5251: if ($context eq 'cancreate') {
1.224 raeburn 5252: $rowname = &mt('CAPTCHA validation');
1.169 raeburn 5253: } elsif ($context eq 'login') {
5254: $rowname = &mt('"Contact helpdesk" CAPTCHA validation');
1.165 raeburn 5255: }
5256: if (ref($settings) eq 'HASH') {
5257: if ($settings->{'captcha'}) {
5258: $checked{$settings->{'captcha'}} = ' checked="checked"';
5259: } else {
5260: $checked{'original'} = ' checked="checked"';
5261: }
5262: if ($settings->{'captcha'} eq 'recaptcha') {
5263: $pubtext = $lt{'pub'};
5264: $privtext = $lt{'priv'};
5265: $keyentry = 'text';
1.269 raeburn 5266: $vertext = $lt{'ver'};
5267: $currver = $settings->{'recaptchaversion'};
5268: if ($currver ne '2') {
5269: $currver = 1;
5270: }
1.165 raeburn 5271: }
5272: if (ref($settings->{'recaptchakeys'}) eq 'HASH') {
5273: $currpub = $settings->{'recaptchakeys'}{'public'};
5274: $currpriv = $settings->{'recaptchakeys'}{'private'};
5275: }
5276: } else {
5277: $checked{'original'} = ' checked="checked"';
5278: }
1.169 raeburn 5279: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
5280: my $output = '<tr'.$css_class.'>'.
5281: '<td class="LC_left_item">'.$rowname.'</td><td class="LC_left_item" colspan="2">'."\n".
1.165 raeburn 5282: '<table><tr><td>'."\n";
5283: foreach my $option ('original','recaptcha','notused') {
5284: $output .= '<span class="LC_nobreak"><label><input type="radio" name="'.$context.'_captcha" value="'.
5285: $option.'" '.$checked{$option}.' onchange="javascript:updateCaptcha('."this,'$context'".');" />'.
5286: $lt{$option}.'</label></span>';
5287: unless ($option eq 'notused') {
5288: $output .= (' 'x2)."\n";
5289: }
5290: }
5291: #
5292: # Note: If reCAPTCHA is to be used for LON-CAPA servers in a domain, a domain coordinator should visit:
5293: # https://www.google.com/recaptcha and generate a Public and Private key. For domains with multiple
1.210 raeburn 5294: # servers a single key pair will be used for all servers, so the internet domain (e.g., yourcollege.edu)
1.165 raeburn 5295: # specified for use with the key should be broad enough to accommodate all servers in the LON-CAPA domain.
1.210 raeburn 5296: #
1.165 raeburn 5297: $output .= '</td></tr>'."\n".
5298: '<tr><td>'."\n".
5299: '<span class="LC_nobreak"><span id="'.$context.'_recaptchapubtxt">'.$pubtext.'</span> '."\n".
5300: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapub" name="'.$context.'_recaptchapub" value="'.
5301: $currpub.'" size="40" /></span><br />'."\n".
5302: '<span class="LC_nobreak"><span id="'.$context.'_recaptchaprivtxt">'.$privtext.'</span> '."\n".
5303: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapriv" name="'.$context.'_recaptchapriv" value="'.
1.269 raeburn 5304: $currpriv.'" size="40" /></span><br />'.
5305: '<span class="LC_nobreak"><span id="'.$context.'_recaptchavertxt">'.$vertext.'</span> '."\n".
5306: '<input type="'.$keyentry.'" id="'.$context.'_recaptchaversion" name="'.$context.'_recaptchaversion" value="'.
5307: $currver.'" size="3" /></span><br />'.
5308: '</td></tr></table>'."\n".
1.165 raeburn 5309: '</td></tr>';
5310: return $output;
5311: }
5312:
1.32 raeburn 5313: sub user_formats_row {
5314: my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount) = @_;
5315: my $output;
5316: my %text = (
5317: 'username' => 'new usernames',
5318: 'id' => 'IDs',
1.45 raeburn 5319: 'email' => 'self-created accounts (e-mail)',
1.32 raeburn 5320: );
5321: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
5322: $output = '<tr '.$css_class.'>'.
1.63 raeburn 5323: '<td><span class="LC_nobreak">';
5324: if ($type eq 'email') {
5325: $output .= &mt("Formats disallowed for $text{$type}: ");
5326: } else {
5327: $output .= &mt("Format rules to check for $text{$type}: ");
5328: }
5329: $output .= '</span></td>'.
5330: '<td class="LC_left_item" colspan="2"><table>';
1.27 raeburn 5331: my $rem;
5332: if (ref($ruleorder) eq 'ARRAY') {
5333: for (my $i=0; $i<@{$ruleorder}; $i++) {
5334: if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
5335: my $rem = $i%($numinrow);
5336: if ($rem == 0) {
5337: if ($i > 0) {
5338: $output .= '</tr>';
5339: }
5340: $output .= '<tr>';
5341: }
5342: my $check = ' ';
1.39 raeburn 5343: if (ref($settings) eq 'HASH') {
5344: if (ref($settings->{$type.'_rule'}) eq 'ARRAY') {
5345: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) {
5346: $check = ' checked="checked" ';
5347: }
1.27 raeburn 5348: }
5349: }
5350: $output .= '<td class="LC_left_item">'.
5351: '<span class="LC_nobreak"><label>'.
1.32 raeburn 5352: '<input type="checkbox" name="'.$type.'_rule" '.
1.27 raeburn 5353: 'value="'.$ruleorder->[$i].'"'.$check.'/>'.
5354: $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
5355: }
5356: }
5357: $rem = @{$ruleorder}%($numinrow);
5358: }
5359: my $colsleft = $numinrow - $rem;
5360: if ($colsleft > 1 ) {
5361: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
5362: ' </td>';
5363: } elsif ($colsleft == 1) {
5364: $output .= '<td class="LC_left_item"> </td>';
5365: }
5366: $output .= '</tr></table></td></tr>';
5367: return $output;
5368: }
5369:
1.34 raeburn 5370: sub usercreation_types {
5371: my %lt = &Apache::lonlocal::texthash (
5372: author => 'When adding a co-author',
5373: course => 'When adding a user to a course',
1.100 raeburn 5374: requestcrs => 'When requesting a course',
1.34 raeburn 5375: any => 'Any',
5376: official => 'Institutional only ',
5377: unofficial => 'Non-institutional only',
5378: none => 'None',
5379: );
5380: return %lt;
1.48 raeburn 5381: }
1.34 raeburn 5382:
1.224 raeburn 5383: sub selfcreation_types {
5384: my %lt = &Apache::lonlocal::texthash (
5385: selfcreate => 'User creates own account',
5386: any => 'Any',
5387: official => 'Institutional only ',
5388: unofficial => 'Non-institutional only',
5389: email => 'E-mail address',
5390: login => 'Institutional Login',
5391: sso => 'SSO',
5392: );
5393: }
5394:
1.28 raeburn 5395: sub authtype_names {
5396: my %lt = &Apache::lonlocal::texthash(
5397: int => 'Internal',
5398: krb4 => 'Kerberos 4',
5399: krb5 => 'Kerberos 5',
5400: loc => 'Local',
5401: );
5402: return %lt;
5403: }
5404:
5405: sub context_names {
5406: my %context_title = &Apache::lonlocal::texthash(
5407: author => 'Creating users when an Author',
5408: course => 'Creating users when in a course',
5409: domain => 'Creating users when a Domain Coordinator',
5410: );
5411: return %context_title;
5412: }
5413:
1.33 raeburn 5414: sub print_usermodification {
5415: my ($position,$dom,$settings,$rowtotal) = @_;
5416: my $numinrow = 4;
5417: my ($context,$datatable,$rowcount);
5418: if ($position eq 'top') {
5419: $rowcount = 0;
5420: $context = 'author';
5421: foreach my $role ('ca','aa') {
5422: $datatable .= &modifiable_userdata_row($context,$role,$settings,
5423: $numinrow,$rowcount);
5424: $$rowtotal ++;
5425: $rowcount ++;
5426: }
1.230 raeburn 5427: } elsif ($position eq 'bottom') {
1.33 raeburn 5428: $context = 'course';
5429: $rowcount = 0;
5430: foreach my $role ('st','ep','ta','in','cr') {
5431: $datatable .= &modifiable_userdata_row($context,$role,$settings,
5432: $numinrow,$rowcount);
5433: $$rowtotal ++;
5434: $rowcount ++;
5435: }
5436: }
5437: return $datatable;
5438: }
5439:
1.43 raeburn 5440: sub print_defaults {
1.236 raeburn 5441: my ($position,$dom,$settings,$rowtotal) = @_;
1.43 raeburn 5442: my $rownum = 0;
5443: my ($datatable,$css_class);
1.236 raeburn 5444: if ($position eq 'top') {
5445: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def',
5446: 'datelocale_def','portal_def');
5447: my %defaults;
5448: if (ref($settings) eq 'HASH') {
5449: %defaults = %{$settings};
1.43 raeburn 5450: } else {
1.236 raeburn 5451: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
5452: foreach my $item (@items) {
5453: $defaults{$item} = $domdefaults{$item};
5454: }
1.43 raeburn 5455: }
1.236 raeburn 5456: my $titles = &defaults_titles($dom);
5457: foreach my $item (@items) {
5458: if ($rownum%2) {
5459: $css_class = '';
5460: } else {
5461: $css_class = ' class="LC_odd_row" ';
5462: }
5463: $datatable .= '<tr'.$css_class.'>'.
5464: '<td><span class="LC_nobreak">'.$titles->{$item}.
5465: '</span></td><td class="LC_right_item" colspan="3">';
5466: if ($item eq 'auth_def') {
5467: my @authtypes = ('internal','krb4','krb5','localauth');
5468: my %shortauth = (
5469: internal => 'int',
5470: krb4 => 'krb4',
5471: krb5 => 'krb5',
5472: localauth => 'loc'
5473: );
5474: my %authnames = &authtype_names();
5475: foreach my $auth (@authtypes) {
5476: my $checked = ' ';
5477: if ($defaults{$item} eq $auth) {
5478: $checked = ' checked="checked" ';
5479: }
5480: $datatable .= '<label><input type="radio" name="'.$item.
5481: '" value="'.$auth.'"'.$checked.'/>'.
5482: $authnames{$shortauth{$auth}}.'</label> ';
5483: }
5484: } elsif ($item eq 'timezone_def') {
5485: my $includeempty = 1;
5486: $datatable .= &Apache::loncommon::select_timezone($item,$defaults{$item},undef,$includeempty);
5487: } elsif ($item eq 'datelocale_def') {
5488: my $includeempty = 1;
5489: $datatable .= &Apache::loncommon::select_datelocale($item,$defaults{$item},undef,$includeempty);
5490: } elsif ($item eq 'lang_def') {
1.263 raeburn 5491: my $includeempty = 1;
5492: $datatable .= &Apache::loncommon::select_language($item,$defaults{$item},$includeempty);
1.236 raeburn 5493: } else {
5494: my $size;
5495: if ($item eq 'portal_def') {
5496: $size = ' size="25"';
5497: }
5498: $datatable .= '<input type="text" name="'.$item.'" value="'.
5499: $defaults{$item}.'"'.$size.' />';
1.43 raeburn 5500: }
1.236 raeburn 5501: $datatable .= '</td></tr>';
5502: $rownum ++;
5503: }
5504: } else {
5505: my (%defaults);
5506: if (ref($settings) eq 'HASH') {
5507: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH') &&
5508: (ref($settings->{'inststatusguest'}) eq 'ARRAY')) {
5509: my $maxnum = @{$settings->{'inststatusorder'}};
5510: for (my $i=0; $i<$maxnum; $i++) {
5511: $css_class = $rownum%2?' class="LC_odd_row"':'';
5512: my $item = $settings->{'inststatusorder'}->[$i];
5513: my $title = $settings->{'inststatustypes'}->{$item};
5514: my $guestok;
5515: if (grep(/^\Q$item\E$/,@{$settings->{'inststatusguest'}})) {
5516: $guestok = 1;
5517: }
5518: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'$item'".');"';
5519: $datatable .= '<tr'.$css_class.'>'.
5520: '<td><span class="LC_nobreak">'.
5521: '<select name="inststatus_pos_'.$item.'"'.$chgstr.'>';
5522: for (my $k=0; $k<=$maxnum; $k++) {
5523: my $vpos = $k+1;
5524: my $selstr;
5525: if ($k == $i) {
5526: $selstr = ' selected="selected" ';
5527: }
5528: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
5529: }
5530: my ($checkedon,$checkedoff);
5531: $checkedoff = ' checked="checked"';
5532: if ($guestok) {
5533: $checkedon = $checkedoff;
5534: $checkedoff = '';
5535: }
5536: $datatable .= '</select> '.&mt('Internal ID:').' <b>'.$item.'</b> '.
5537: '<input type="checkbox" name="inststatus_delete" value="'.$item.'" />'.
5538: &mt('delete').'</span></td>'.
5539: '<td class="LC_left_item"><span class="LC_nobreak">'.&mt('Name displayed:').
5540: '<input type="text" size="20" name="inststatus_title_'.$item.'" value="'.$title.'" />'.
5541: '</span></td>'.
5542: '<td class="LC_right_item"><span class="LC_nobreak">'.
5543: '<label><input type="radio" value="1" name="inststatus_guest_'.$item.'"'.$checkedon.' />'.
5544: &mt('Yes').'</label>'.(' 'x2).
5545: '<label><input type="radio" value="0" name="inststatus_guest_'.$item.'"'.$checkedoff.' />'.
5546: &mt('No').'</label></span></td></tr>';
5547: }
5548: $css_class = $rownum%2?' class="LC_odd_row"':'';
5549: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'addinststatus_pos'".');"';
5550: $datatable .= '<tr '.$css_class.'>'.
5551: '<td><span class="LC_nobreak"><select name="addinststatus_pos"'.$chgstr.'>';
5552: for (my $k=0; $k<=$maxnum; $k++) {
5553: my $vpos = $k+1;
5554: my $selstr;
5555: if ($k == $maxnum) {
5556: $selstr = ' selected="selected" ';
5557: }
5558: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
5559: }
5560: $datatable .= '</select> '.&mt('Internal ID:').
1.263 raeburn 5561: '<input type="text" size="10" name="addinststatus" value="" />'.
1.236 raeburn 5562: ' '.&mt('(new)').
5563: '</span></td><td class="LC_left_item"><span class="LC_nobreak">'.
5564: &mt('Name displayed:').
5565: '<input type="text" size="20" name="addinststatus_title" value="" /></span></td>'.
5566: '<td class="LC_right_item"><span class="LC_nobreak">'.
5567: '<label><input type="radio" value="1" name="addinststatus_guest" />'.
5568: &mt('Yes').'</label>'.(' 'x2).
5569: '<label><input type="radio" value="0" name="addinststatus_guest" />'.
5570: &mt('No').'</label></span></td></tr>';
5571: '</tr>'."\n";
5572: $rownum ++;
1.141 raeburn 5573: }
1.43 raeburn 5574: }
5575: }
5576: $$rowtotal += $rownum;
5577: return $datatable;
5578: }
5579:
1.168 raeburn 5580: sub get_languages_hash {
5581: my %langchoices;
5582: foreach my $id (&Apache::loncommon::languageids()) {
5583: my $code = &Apache::loncommon::supportedlanguagecode($id);
5584: if ($code ne '') {
5585: $langchoices{$code} = &Apache::loncommon::plainlanguagedescription($id);
5586: }
5587: }
5588: return %langchoices;
5589: }
5590:
1.43 raeburn 5591: sub defaults_titles {
1.141 raeburn 5592: my ($dom) = @_;
1.43 raeburn 5593: my %titles = &Apache::lonlocal::texthash (
5594: 'auth_def' => 'Default authentication type',
5595: 'auth_arg_def' => 'Default authentication argument',
5596: 'lang_def' => 'Default language',
1.54 raeburn 5597: 'timezone_def' => 'Default timezone',
1.68 raeburn 5598: 'datelocale_def' => 'Default locale for dates',
1.141 raeburn 5599: 'portal_def' => 'Portal/Default URL',
1.43 raeburn 5600: );
1.141 raeburn 5601: if ($dom) {
5602: my $uprimary_id = &Apache::lonnet::domain($dom,'primary');
5603: my $uint_dom = &Apache::lonnet::internet_dom($uprimary_id);
5604: my $protocol = $Apache::lonnet::protocol{$uprimary_id};
5605: $protocol = 'http' if ($protocol ne 'https');
5606: if ($uint_dom) {
5607: $titles{'portal_def'} .= ' '.&mt('(for example: [_1])',$protocol.'://loncapa.'.
5608: $uint_dom);
5609: }
5610: }
1.43 raeburn 5611: return (\%titles);
5612: }
5613:
1.46 raeburn 5614: sub print_scantronformat {
5615: my ($r,$dom,$confname,$settings,$rowtotal) = @_;
5616: my $itemcount = 1;
1.60 raeburn 5617: my ($datatable,$css_class,$scantronurl,$is_custom,%error,%scantronurls,
5618: %confhash);
1.46 raeburn 5619: my $switchserver = &check_switchserver($dom,$confname);
5620: my %lt = &Apache::lonlocal::texthash (
1.95 www 5621: default => 'Default bubblesheet format file error',
5622: custom => 'Custom bubblesheet format file error',
1.46 raeburn 5623: );
5624: my %scantronfiles = (
5625: default => 'default.tab',
5626: custom => 'custom.tab',
5627: );
5628: foreach my $key (keys(%scantronfiles)) {
5629: $scantronurls{$key} = '/res/'.$dom.'/'.$confname.'/scantron/'
5630: .$scantronfiles{$key};
5631: }
5632: my @defaultinfo = &Apache::lonnet::stat_file($scantronurls{'default'});
5633: if ((!@defaultinfo) || ($defaultinfo[0] eq 'no_such_dir')) {
5634: if (!$switchserver) {
5635: my $servadm = $r->dir_config('lonAdmEMail');
5636: my ($configuserok,$author_ok) = &config_check($dom,$confname,$servadm);
5637: if ($configuserok eq 'ok') {
5638: if ($author_ok eq 'ok') {
5639: my %legacyfile = (
5640: default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab',
5641: custom => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab',
5642: );
5643: my %md5chk;
5644: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 5645: ($md5chk{$type}) = split(/ /,`md5sum $legacyfile{$type}`);
5646: chomp($md5chk{$type});
1.46 raeburn 5647: }
5648: if ($md5chk{'default'} ne $md5chk{'custom'}) {
5649: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 5650: ($scantronurls{$type},my $error) =
1.46 raeburn 5651: &legacy_scantronformat($r,$dom,$confname,
5652: $type,$legacyfile{$type},
5653: $scantronurls{$type},
5654: $scantronfiles{$type});
1.60 raeburn 5655: if ($error ne '') {
5656: $error{$type} = $error;
5657: }
5658: }
5659: if (keys(%error) == 0) {
5660: $is_custom = 1;
5661: $confhash{'scantron'}{'scantronformat'} =
5662: $scantronurls{'custom'};
5663: my $putresult =
5664: &Apache::lonnet::put_dom('configuration',
5665: \%confhash,$dom);
5666: if ($putresult ne 'ok') {
5667: $error{'custom'} =
5668: '<span class="LC_error">'.
5669: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
5670: }
1.46 raeburn 5671: }
5672: } else {
1.60 raeburn 5673: ($scantronurls{'default'},my $error) =
1.46 raeburn 5674: &legacy_scantronformat($r,$dom,$confname,
5675: 'default',$legacyfile{'default'},
5676: $scantronurls{'default'},
5677: $scantronfiles{'default'});
1.60 raeburn 5678: if ($error eq '') {
5679: $confhash{'scantron'}{'scantronformat'} = '';
5680: my $putresult =
5681: &Apache::lonnet::put_dom('configuration',
5682: \%confhash,$dom);
5683: if ($putresult ne 'ok') {
5684: $error{'default'} =
5685: '<span class="LC_error">'.
5686: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
5687: }
5688: } else {
5689: $error{'default'} = $error;
5690: }
1.46 raeburn 5691: }
5692: }
5693: }
5694: } else {
1.95 www 5695: $error{'default'} = &mt("Unable to copy default bubblesheet formatfile to domain's RES space: [_1]",$switchserver);
1.46 raeburn 5696: }
5697: }
5698: if (ref($settings) eq 'HASH') {
5699: if ($settings->{'scantronformat'} eq "/res/$dom/$confname/scantron/custom.tab") {
5700: my @info = &Apache::lonnet::stat_file($settings->{'scantronformat'});
5701: if ((!@info) || ($info[0] eq 'no_such_dir')) {
5702: $scantronurl = '';
5703: } else {
5704: $scantronurl = $settings->{'scantronformat'};
5705: }
5706: $is_custom = 1;
5707: } else {
5708: $scantronurl = $scantronurls{'default'};
5709: }
5710: } else {
1.60 raeburn 5711: if ($is_custom) {
5712: $scantronurl = $scantronurls{'custom'};
5713: } else {
5714: $scantronurl = $scantronurls{'default'};
5715: }
1.46 raeburn 5716: }
5717: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5718: $datatable .= '<tr'.$css_class.'>';
5719: if (!$is_custom) {
1.65 raeburn 5720: $datatable .= '<td>'.&mt('Default in use:').'<br />'.
5721: '<span class="LC_nobreak">';
1.46 raeburn 5722: if ($scantronurl) {
1.199 raeburn 5723: $datatable .= &Apache::loncommon::modal_link($scantronurl,&mt('Default bubblesheet format file'),600,500,
5724: undef,undef,undef,undef,'background-color:#ffffff');
1.46 raeburn 5725: } else {
5726: $datatable = &mt('File unavailable for display');
5727: }
1.65 raeburn 5728: $datatable .= '</span></td>';
1.60 raeburn 5729: if (keys(%error) == 0) {
5730: $datatable .= '<td valign="bottom">';
5731: if (!$switchserver) {
5732: $datatable .= &mt('Upload:').'<br />';
5733: }
5734: } else {
5735: my $errorstr;
5736: foreach my $key (sort(keys(%error))) {
5737: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
5738: }
5739: $datatable .= '<td>'.$errorstr;
5740: }
1.46 raeburn 5741: } else {
5742: if (keys(%error) > 0) {
5743: my $errorstr;
5744: foreach my $key (sort(keys(%error))) {
5745: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
5746: }
1.60 raeburn 5747: $datatable .= '<td>'.$errorstr.'</td><td> ';
1.46 raeburn 5748: } elsif ($scantronurl) {
1.199 raeburn 5749: my $link = &Apache::loncommon::modal_link($scantronurl,&mt('Custom bubblesheet format file'),600,500,
5750: undef,undef,undef,undef,'background-color:#ffffff');
1.65 raeburn 5751: $datatable .= '<td><span class="LC_nobreak">'.
1.199 raeburn 5752: $link.
5753: '<label><input type="checkbox" name="scantronformat_del"'.
5754: ' value="1" />'.&mt('Delete?').'</label></span></td>'.
1.65 raeburn 5755: '<td><span class="LC_nobreak"> '.
5756: &mt('Replace:').'</span><br />';
1.46 raeburn 5757: }
5758: }
5759: if (keys(%error) == 0) {
5760: if ($switchserver) {
5761: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
5762: } else {
1.65 raeburn 5763: $datatable .='<span class="LC_nobreak"> '.
5764: '<input type="file" name="scantronformat" /></span>';
1.46 raeburn 5765: }
5766: }
5767: $datatable .= '</td></tr>';
5768: $$rowtotal ++;
5769: return $datatable;
5770: }
5771:
5772: sub legacy_scantronformat {
5773: my ($r,$dom,$confname,$file,$legacyfile,$newurl,$newfile) = @_;
5774: my ($url,$error);
5775: my @statinfo = &Apache::lonnet::stat_file($newurl);
5776: if ((!@statinfo) || ($statinfo[0] eq 'no_such_dir')) {
5777: (my $result,$url) =
5778: &publishlogo($r,'copy',$legacyfile,$dom,$confname,'scantron',
5779: '','',$newfile);
5780: if ($result ne 'ok') {
1.130 raeburn 5781: $error = &mt("An error occurred publishing the [_1] bubblesheet format file in RES space. Error was: [_2].",$newfile,$result);
1.46 raeburn 5782: }
5783: }
5784: return ($url,$error);
5785: }
1.43 raeburn 5786:
1.49 raeburn 5787: sub print_coursecategories {
1.57 raeburn 5788: my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;
5789: my $datatable;
5790: if ($position eq 'top') {
1.238 raeburn 5791: my (%checked);
5792: my @catitems = ('unauth','auth');
5793: my @cattypes = ('std','domonly','codesrch','none');
5794: $checked{'unauth'} = 'std';
5795: $checked{'auth'} = 'std';
5796: if (ref($settings) eq 'HASH') {
5797: foreach my $type (@cattypes) {
5798: if ($type eq $settings->{'unauth'}) {
5799: $checked{'unauth'} = $type;
5800: }
5801: if ($type eq $settings->{'auth'}) {
5802: $checked{'auth'} = $type;
5803: }
5804: }
5805: }
5806: my %lt = &Apache::lonlocal::texthash (
5807: unauth => 'Catalog type for unauthenticated users',
5808: auth => 'Catalog type for authenticated users',
5809: none => 'No catalog',
5810: std => 'Standard catalog',
5811: domonly => 'Domain-only catalog',
5812: codesrch => "Code search form",
5813: );
5814: my $itemcount = 0;
5815: foreach my $item (@catitems) {
5816: my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
5817: $datatable .= '<tr '.$css_class.'>'.
5818: '<td>'.$lt{$item}.'</td>'.
5819: '<td class="LC_right_item"><span class="LC_nobreak">';
5820: foreach my $type (@cattypes) {
5821: my $ischecked;
5822: if ($checked{$item} eq $type) {
5823: $ischecked=' checked="checked"';
5824: }
5825: $datatable .= '<label>'.
5826: '<input type="radio" name="coursecat_'.$item.'" value="'.$type.'"'.$ischecked.
5827: ' />'.$lt{$type}.'</label> ';
5828: }
5829: $datatable .= '</td></tr>';
5830: $itemcount ++;
5831: }
5832: $$rowtotal += $itemcount;
5833: } elsif ($position eq 'middle') {
1.57 raeburn 5834: my $toggle_cats_crs = ' ';
5835: my $toggle_cats_dom = ' checked="checked" ';
5836: my $can_cat_crs = ' ';
5837: my $can_cat_dom = ' checked="checked" ';
1.120 raeburn 5838: my $toggle_catscomm_comm = ' ';
5839: my $toggle_catscomm_dom = ' checked="checked" ';
5840: my $can_catcomm_comm = ' ';
5841: my $can_catcomm_dom = ' checked="checked" ';
1.272 raeburn 5842: my $toggle_catsplace_place = ' ';
5843: my $toggle_catsplace_dom = ' checked="checked" ';
5844: my $can_catplace_place = ' ';
5845: my $can_catplace_dom = ' checked="checked" ';
1.120 raeburn 5846:
1.57 raeburn 5847: if (ref($settings) eq 'HASH') {
5848: if ($settings->{'togglecats'} eq 'crs') {
5849: $toggle_cats_crs = $toggle_cats_dom;
5850: $toggle_cats_dom = ' ';
5851: }
5852: if ($settings->{'categorize'} eq 'crs') {
5853: $can_cat_crs = $can_cat_dom;
5854: $can_cat_dom = ' ';
5855: }
1.120 raeburn 5856: if ($settings->{'togglecatscomm'} eq 'comm') {
5857: $toggle_catscomm_comm = $toggle_catscomm_dom;
5858: $toggle_catscomm_dom = ' ';
5859: }
5860: if ($settings->{'categorizecomm'} eq 'comm') {
5861: $can_catcomm_comm = $can_catcomm_dom;
5862: $can_catcomm_dom = ' ';
5863: }
1.272 raeburn 5864: if ($settings->{'togglecatsplace'} eq 'place') {
5865: $toggle_catsplace_place = $toggle_catsplace_dom;
5866: $toggle_catsplace_dom = ' ';
5867: }
5868: if ($settings->{'categorizeplace'} eq 'place') {
5869: $can_catplace_place = $can_catplace_dom;
5870: $can_catplace_dom = ' ';
5871: }
1.57 raeburn 5872: }
5873: my %title = &Apache::lonlocal::texthash (
1.272 raeburn 5874: togglecats => 'Show/Hide a course in catalog',
5875: togglecatscomm => 'Show/Hide a community in catalog',
5876: togglecatsplace => 'Show/Hide a placement test in catalog',
5877: categorize => 'Assign a category to a course',
5878: categorizecomm => 'Assign a category to a community',
5879: categorizeplace => 'Assign a category to a placement test',
1.57 raeburn 5880: );
5881: my %level = &Apache::lonlocal::texthash (
1.272 raeburn 5882: dom => 'Set in Domain',
5883: crs => 'Set in Course',
5884: comm => 'Set in Community',
5885: place => 'Set in Placement Test',
1.57 raeburn 5886: );
5887: $datatable = '<tr class="LC_odd_row">'.
5888: '<td>'.$title{'togglecats'}.'</td>'.
5889: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
5890: '<input type="radio" name="togglecats"'.
5891: $toggle_cats_dom.' value="dom" />'.$level{'dom'}.'</label> '.
5892: '<label><input type="radio" name="togglecats"'.
5893: $toggle_cats_crs.' value="crs" />'.$level{'crs'}.'</label></span></td>'.
5894: '</tr><tr>'.
5895: '<td>'.$title{'categorize'}.'</td>'.
5896: '<td class="LC_right_item"><span class="LC_nobreak">'.
5897: '<label><input type="radio" name="categorize"'.
5898: $can_cat_dom.' value="dom" />'.$level{'dom'}.'</label> '.
5899: '<label><input type="radio" name="categorize"'.
5900: $can_cat_crs.'value="crs" />'.$level{'crs'}.'</label></span></td>'.
1.120 raeburn 5901: '</tr><tr class="LC_odd_row">'.
5902: '<td>'.$title{'togglecatscomm'}.'</td>'.
5903: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
5904: '<input type="radio" name="togglecatscomm"'.
5905: $toggle_catscomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
5906: '<label><input type="radio" name="togglecatscomm"'.
5907: $toggle_catscomm_comm.' value="comm" />'.$level{'comm'}.'</label></span></td>'.
5908: '</tr><tr>'.
5909: '<td>'.$title{'categorizecomm'}.'</td>'.
5910: '<td class="LC_right_item"><span class="LC_nobreak">'.
5911: '<label><input type="radio" name="categorizecomm"'.
5912: $can_catcomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
5913: '<label><input type="radio" name="categorizecomm"'.
5914: $can_catcomm_comm.'value="comm" />'.$level{'comm'}.'</label></span></td>'.
1.272 raeburn 5915: '</tr><tr>'.
5916: '<td>'.$title{'togglecatsplace'}.'</td>'.
5917: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
5918: '<input type="radio" name="togglecatsplace"'.
5919: $toggle_catsplace_dom.' value="dom" />'.$level{'dom'}.'</label> '.
5920: '<label><input type="radio" name="togglecatscomm"'.
5921: $toggle_catsplace_place.' value="comm" />'.$level{'place'}.'</label></span></td>'.
5922: '</tr><tr>'.
5923: '<td>'.$title{'categorizeplace'}.'</td>'.
5924: '<td class="LC_right_item"><span class="LC_nobreak">'.
5925: '<label><input type="radio" name="categorizeplace"'.
5926: $can_catplace_dom.' value="dom" />'.$level{'dom'}.'</label> '.
5927: '<label><input type="radio" name="categorizeplace"'.
5928: $can_catplace_place.'value="place" />'.$level{'place'}.'</label></span></td>'.
1.57 raeburn 5929: '</tr>';
1.272 raeburn 5930: $$rowtotal += 6;
1.57 raeburn 5931: } else {
5932: my $css_class;
5933: my $itemcount = 1;
5934: my $cathash;
5935: if (ref($settings) eq 'HASH') {
5936: $cathash = $settings->{'cats'};
5937: }
5938: if (ref($cathash) eq 'HASH') {
5939: my (@cats,@trails,%allitems,%idx,@jsarray);
5940: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
5941: \%allitems,\%idx,\@jsarray);
5942: my $maxdepth = scalar(@cats);
5943: my $colattrib = '';
5944: if ($maxdepth > 2) {
5945: $colattrib = ' colspan="2" ';
5946: }
5947: my @path;
5948: if (@cats > 0) {
5949: if (ref($cats[0]) eq 'ARRAY') {
5950: my $numtop = @{$cats[0]};
5951: my $maxnum = $numtop;
1.120 raeburn 5952: my %default_names = (
5953: instcode => &mt('Official courses'),
5954: communities => &mt('Communities'),
1.272 raeburn 5955: placement => &mt('Placement Tests'),
1.120 raeburn 5956: );
5957:
5958: if ((!grep(/^instcode$/,@{$cats[0]})) ||
5959: ($cathash->{'instcode::0'} eq '') ||
5960: (!grep(/^communities$/,@{$cats[0]})) ||
1.272 raeburn 5961: ($cathash->{'communities::0'} eq '') ||
5962: (!grep(/^placement$/,@{$cats[0]})) ||
5963: ($cathash->{'placement::0'} eq '')) {
1.57 raeburn 5964: $maxnum ++;
5965: }
5966: my $lastidx;
5967: for (my $i=0; $i<$numtop; $i++) {
5968: my $parent = $cats[0][$i];
5969: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5970: my $item = &escape($parent).'::0';
5971: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$item','$idx{$item}'".');"';
5972: $lastidx = $idx{$item};
5973: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
5974: .'<select name="'.$item.'"'.$chgstr.'>';
5975: for (my $k=0; $k<=$maxnum; $k++) {
5976: my $vpos = $k+1;
5977: my $selstr;
5978: if ($k == $i) {
5979: $selstr = ' selected="selected" ';
5980: }
5981: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
5982: }
1.214 raeburn 5983: $datatable .= '</select></span></td><td>';
1.272 raeburn 5984: if ($parent eq 'instcode' || $parent eq 'communities' || $parent eq 'placement') {
1.120 raeburn 5985: $datatable .= '<span class="LC_nobreak">'
5986: .$default_names{$parent}.'</span>';
5987: if ($parent eq 'instcode') {
5988: $datatable .= '<br /><span class="LC_nobreak">('
5989: .&mt('with institutional codes')
5990: .')</span></td><td'.$colattrib.'>';
5991: } else {
5992: $datatable .= '<table><tr><td>';
5993: }
5994: $datatable .= '<span class="LC_nobreak">'
5995: .'<label><input type="radio" name="'
5996: .$parent.'" value="1" checked="checked" />'
5997: .&mt('Display').'</label>';
5998: if ($parent eq 'instcode') {
5999: $datatable .= ' ';
6000: } else {
6001: $datatable .= '</span></td></tr><tr><td>'
6002: .'<span class="LC_nobreak">';
6003: }
6004: $datatable .= '<label><input type="radio" name="'
6005: .$parent.'" value="0" />'
6006: .&mt('Do not display').'</label></span>';
1.272 raeburn 6007: if (($parent eq 'communities') || ($parent eq 'placement')) {
1.120 raeburn 6008: $datatable .= '</td></tr></table>';
6009: }
6010: $datatable .= '</td>';
1.57 raeburn 6011: } else {
6012: $datatable .= $parent
1.214 raeburn 6013: .' <span class="LC_nobreak"><label>'
6014: .'<input type="checkbox" name="deletecategory" '
1.57 raeburn 6015: .'value="'.$item.'" />'.&mt('Delete').'</label></span></td>';
6016: }
6017: my $depth = 1;
6018: push(@path,$parent);
6019: $datatable .= &build_category_rows($itemcount,\@cats,$depth,$parent,\@path,\%idx);
6020: pop(@path);
6021: $datatable .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
6022: $itemcount ++;
6023: }
1.48 raeburn 6024: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.57 raeburn 6025: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','$lastidx'".');"';
6026: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="addcategory_pos"'.$chgstr.'>';
1.48 raeburn 6027: for (my $k=0; $k<=$maxnum; $k++) {
6028: my $vpos = $k+1;
6029: my $selstr;
1.57 raeburn 6030: if ($k == $numtop) {
1.48 raeburn 6031: $selstr = ' selected="selected" ';
6032: }
6033: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
6034: }
1.59 bisitz 6035: $datatable .= '</select></span></td><td colspan="2">'.&mt('Add category:').' '
1.57 raeburn 6036: .'<input type="text" size="20" name="addcategory_name" value="" /></td>'
6037: .'</tr>'."\n";
1.48 raeburn 6038: $itemcount ++;
1.272 raeburn 6039: foreach my $default ('instcode','communities','placement') {
1.120 raeburn 6040: if ((!grep(/^\Q$default\E$/,@{$cats[0]})) || ($cathash->{$default.'::0'} eq '')) {
6041: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6042: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','$lastidx'".');"';
6043: $datatable .= '<tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr><tr '.$css_class.'><td>'.
6044: '<span class="LC_nobreak"><select name="'.$default.'_pos"'.$chgstr.'>';
6045: for (my $k=0; $k<=$maxnum; $k++) {
6046: my $vpos = $k+1;
6047: my $selstr;
6048: if ($k == $maxnum) {
6049: $selstr = ' selected="selected" ';
6050: }
6051: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.57 raeburn 6052: }
1.120 raeburn 6053: $datatable .= '</select></span></td>'.
6054: '<td><span class="LC_nobreak">'.
6055: $default_names{$default}.'</span>';
6056: if ($default eq 'instcode') {
6057: $datatable .= '<br /><span class="LC_nobreak">('
6058: .&mt('with institutional codes').')</span>';
6059: }
6060: $datatable .= '</td>'
6061: .'<td><span class="LC_nobreak"><label><input type="radio" name="'.$default.'" value="1" />'
6062: .&mt('Display').'</label> '
6063: .'<label><input type="radio" name="'.$default.'" value="0" checked="checked"/>'
6064: .&mt('Do not display').'</label></span></td></tr>';
1.48 raeburn 6065: }
6066: }
6067: }
1.57 raeburn 6068: } else {
6069: $datatable .= &initialize_categories($itemcount);
1.48 raeburn 6070: }
6071: } else {
1.238 raeburn 6072: $datatable .= '<td class="LC_right_item">'.$hdritem->{'header'}->[1]->{'col2'}.'</td>'
1.57 raeburn 6073: .&initialize_categories($itemcount);
1.48 raeburn 6074: }
1.57 raeburn 6075: $$rowtotal += $itemcount;
1.48 raeburn 6076: }
6077: return $datatable;
6078: }
6079:
1.69 raeburn 6080: sub print_serverstatuses {
6081: my ($dom,$settings,$rowtotal) = @_;
6082: my $datatable;
6083: my @pages = &serverstatus_pages();
6084: my (%namedaccess,%machineaccess);
6085: foreach my $type (@pages) {
6086: $namedaccess{$type} = '';
6087: $machineaccess{$type}= '';
6088: }
6089: if (ref($settings) eq 'HASH') {
6090: foreach my $type (@pages) {
6091: if (exists($settings->{$type})) {
6092: if (ref($settings->{$type}) eq 'HASH') {
6093: foreach my $key (keys(%{$settings->{$type}})) {
6094: if ($key eq 'namedusers') {
6095: $namedaccess{$type} = $settings->{$type}->{$key};
6096: } elsif ($key eq 'machines') {
6097: $machineaccess{$type} = $settings->{$type}->{$key};
6098: }
6099: }
6100: }
6101: }
6102: }
6103: }
1.81 raeburn 6104: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 6105: my $rownum = 0;
6106: my $css_class;
6107: foreach my $type (@pages) {
6108: $rownum ++;
6109: $css_class = $rownum%2?' class="LC_odd_row"':'';
6110: $datatable .= '<tr'.$css_class.'>'.
6111: '<td><span class="LC_nobreak">'.
6112: $titles->{$type}.'</span></td>'.
6113: '<td class="LC_left_item">'.
6114: '<input type="text" name="'.$type.'_namedusers" '.
6115: 'value="'.$namedaccess{$type}.'" size="30" /></td>'.
6116: '<td class="LC_right_item">'.
6117: '<span class="LC_nobreak">'.
6118: '<input type="text" name="'.$type.'_machines" '.
6119: 'value="'.$machineaccess{$type}.'" size="10" />'.
6120: '</td></tr>'."\n";
6121: }
6122: $$rowtotal += $rownum;
6123: return $datatable;
6124: }
6125:
6126: sub serverstatus_pages {
6127: return ('userstatus','lonstatus','loncron','server-status','codeversions',
1.275 raeburn 6128: 'checksums','clusterstatus','certstatus','metadata_keywords',
6129: 'metadata_harvest','takeoffline','takeonline','showenv','toggledebug',
6130: 'ping','domconf','uniquecodes','diskusage','coursecatalog');
1.69 raeburn 6131: }
6132:
1.236 raeburn 6133: sub defaults_javascript {
6134: my ($settings) = @_;
1.248 raeburn 6135: return unless (ref($settings) eq 'HASH');
1.236 raeburn 6136: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
6137: my $maxnum = scalar(@{$settings->{'inststatusorder'}});
6138: if ($maxnum eq '') {
6139: $maxnum = 0;
6140: }
6141: $maxnum ++;
1.249 raeburn 6142: my $jstext = ' var inststatuses = Array('."'".join("','",@{$settings->{'inststatusorder'}})."'".');';
1.236 raeburn 6143: return <<"ENDSCRIPT";
6144: <script type="text/javascript">
6145: // <![CDATA[
6146: function reorderTypes(form,caller) {
6147: var changedVal;
6148: $jstext
6149: var newpos = 'addinststatus_pos';
6150: var current = new Array;
6151: var maxh = $maxnum;
6152: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
6153: var oldVal;
6154: if (caller == newpos) {
6155: changedVal = newitemVal;
6156: } else {
6157: var curritem = 'inststatus_pos_'+caller;
6158: changedVal = form.elements[curritem].options[form.elements[curritem].selectedIndex].value;
6159: current[newitemVal] = newpos;
6160: }
6161: for (var i=0; i<inststatuses.length; i++) {
6162: if (inststatuses[i] != caller) {
6163: var elementName = 'inststatus_pos_'+inststatuses[i];
6164: if (form.elements[elementName]) {
6165: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
6166: current[currVal] = elementName;
6167: }
6168: }
6169: }
6170: for (var j=0; j<maxh; j++) {
6171: if (current[j] == undefined) {
6172: oldVal = j;
6173: }
6174: }
6175: if (oldVal < changedVal) {
6176: for (var k=oldVal+1; k<=changedVal ; k++) {
6177: var elementName = current[k];
6178: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
6179: }
6180: } else {
6181: for (var k=changedVal; k<oldVal; k++) {
6182: var elementName = current[k];
6183: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
6184: }
6185: }
6186: return;
6187: }
6188:
6189: // ]]>
6190: </script>
6191:
6192: ENDSCRIPT
6193: }
6194: }
6195:
1.49 raeburn 6196: sub coursecategories_javascript {
6197: my ($settings) = @_;
1.57 raeburn 6198: my ($output,$jstext,$cathash);
1.49 raeburn 6199: if (ref($settings) eq 'HASH') {
1.57 raeburn 6200: $cathash = $settings->{'cats'};
6201: }
6202: if (ref($cathash) eq 'HASH') {
1.49 raeburn 6203: my (@cats,@jsarray,%idx);
1.57 raeburn 6204: &Apache::loncommon::gather_categories($cathash,\@cats,\%idx,\@jsarray);
1.49 raeburn 6205: if (@jsarray > 0) {
6206: $jstext = ' var categories = Array('.scalar(@jsarray).');'."\n";
6207: for (my $i=0; $i<@jsarray; $i++) {
6208: if (ref($jsarray[$i]) eq 'ARRAY') {
6209: my $catstr = join('","',@{$jsarray[$i]});
6210: $jstext .= ' categories['.$i.'] = Array("'.$catstr.'");'."\n";
6211: }
6212: }
6213: }
6214: } else {
6215: $jstext = ' var categories = Array(1);'."\n".
6216: ' categories[0] = Array("instcode_pos");'."\n";
6217: }
1.237 bisitz 6218: my $instcode_reserved = &mt('The name: [_1] is a reserved category.','"instcode"');
6219: my $communities_reserved = &mt('The name: [_1] is a reserved category.','"communities"');
1.272 raeburn 6220: my $placement_reserved = &mt('The name: [_1] is a reserved category.','"placement"');
1.265 damieng 6221: my $choose_again = "\n".&mt('Please use a different name for the new top level category.');
6222: &js_escape(\$instcode_reserved);
6223: &js_escape(\$communities_reserved);
1.272 raeburn 6224: &js_escape(\$placement_reserved);
1.265 damieng 6225: &js_escape(\$choose_again);
1.49 raeburn 6226: $output = <<"ENDSCRIPT";
6227: <script type="text/javascript">
1.109 raeburn 6228: // <![CDATA[
1.49 raeburn 6229: function reorderCats(form,parent,item,idx) {
6230: var changedVal;
6231: $jstext
6232: var newpos = 'addcategory_pos';
6233: if (parent == '') {
6234: var has_instcode = 0;
6235: var maxtop = categories[idx].length;
6236: for (var j=0; j<maxtop; j++) {
6237: if (categories[idx][j] == 'instcode::0') {
6238: has_instcode == 1;
6239: }
6240: }
6241: if (has_instcode == 0) {
6242: categories[idx][maxtop] = 'instcode_pos';
6243: }
6244: } else {
6245: newpos += '_'+parent;
6246: }
6247: var maxh = 1 + categories[idx].length;
6248: var current = new Array;
6249: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
6250: if (item == newpos) {
6251: changedVal = newitemVal;
6252: } else {
6253: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
6254: current[newitemVal] = newpos;
6255: }
6256: for (var i=0; i<categories[idx].length; i++) {
6257: var elementName = categories[idx][i];
6258: if (elementName != item) {
6259: if (form.elements[elementName]) {
6260: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
6261: current[currVal] = elementName;
6262: }
6263: }
6264: }
6265: var oldVal;
6266: for (var j=0; j<maxh; j++) {
6267: if (current[j] == undefined) {
6268: oldVal = j;
6269: }
6270: }
6271: if (oldVal < changedVal) {
6272: for (var k=oldVal+1; k<=changedVal ; k++) {
6273: var elementName = current[k];
6274: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
6275: }
6276: } else {
6277: for (var k=changedVal; k<oldVal; k++) {
6278: var elementName = current[k];
6279: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
6280: }
6281: }
6282: return;
6283: }
1.120 raeburn 6284:
6285: function categoryCheck(form) {
6286: if (form.elements['addcategory_name'].value == 'instcode') {
6287: alert('$instcode_reserved\\n$choose_again');
6288: return false;
6289: }
6290: if (form.elements['addcategory_name'].value == 'communities') {
6291: alert('$communities_reserved\\n$choose_again');
6292: return false;
6293: }
1.272 raeburn 6294: if (form.elements['addcategory_name'].value == 'placement') {
6295: alert('$placement_reserved\\n$choose_again');
6296: return false;
6297: }
1.120 raeburn 6298: return true;
6299: }
6300:
1.109 raeburn 6301: // ]]>
1.49 raeburn 6302: </script>
6303:
6304: ENDSCRIPT
6305: return $output;
6306: }
6307:
1.48 raeburn 6308: sub initialize_categories {
6309: my ($itemcount) = @_;
1.120 raeburn 6310: my ($datatable,$css_class,$chgstr);
6311: my %default_names = (
6312: instcode => 'Official courses (with institutional codes)',
6313: communities => 'Communities',
1.272 raeburn 6314: placement => 'Placement Tests',
1.120 raeburn 6315: );
6316: my $select0 = ' selected="selected"';
6317: my $select1 = '';
1.272 raeburn 6318: foreach my $default ('instcode','communities','placement') {
1.120 raeburn 6319: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6320: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'',$default"."_pos','0'".');"';
1.272 raeburn 6321: if (($default eq 'communities') || ($default eq 'placement')) {
1.120 raeburn 6322: $select1 = $select0;
6323: $select0 = '';
6324: }
6325: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
6326: .'<select name="'.$default.'_pos">'
6327: .'<option value="0"'.$select0.'>1</option>'
6328: .'<option value="1"'.$select1.'>2</option>'
6329: .'<option value="2">3</option></select> '
6330: .$default_names{$default}
6331: .'</span></td><td><span class="LC_nobreak">'
6332: .'<label><input type="radio" name="'.$default.'" value="1" checked="checked" />'
6333: .&mt('Display').'</label> <label>'
6334: .'<input type="radio" name="'.$default.'" value="0" />'.&mt('Do not display')
1.48 raeburn 6335: .'</label></span></td></tr>';
1.120 raeburn 6336: $itemcount ++;
6337: }
1.48 raeburn 6338: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.49 raeburn 6339: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','0'".');"';
1.48 raeburn 6340: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.120 raeburn 6341: .'<select name="addcategory_pos"'.$chgstr.'>'
6342: .'<option value="0">1</option>'
6343: .'<option value="1">2</option>'
6344: .'<option value="2" selected="selected">3</option></select> '
1.48 raeburn 6345: .&mt('Add category').'</td><td>'.&mt('Name:')
6346: .' <input type="text" size="20" name="addcategory_name" value="" /></td></tr>';
6347: return $datatable;
6348: }
6349:
6350: sub build_category_rows {
1.49 raeburn 6351: my ($itemcount,$cats,$depth,$parent,$path,$idx) = @_;
6352: my ($text,$name,$item,$chgstr);
1.48 raeburn 6353: if (ref($cats) eq 'ARRAY') {
6354: my $maxdepth = scalar(@{$cats});
6355: if (ref($cats->[$depth]) eq 'HASH') {
6356: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
6357: my $numchildren = @{$cats->[$depth]{$parent}};
6358: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.204 raeburn 6359: $text .= '<td><table class="LC_data_table">';
1.49 raeburn 6360: my ($idxnum,$parent_name,$parent_item);
6361: my $higher = $depth - 1;
6362: if ($higher == 0) {
6363: $parent_name = &escape($parent).'::'.$higher;
6364: } else {
6365: if (ref($path) eq 'ARRAY') {
6366: $parent_name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
6367: }
6368: }
6369: $parent_item = 'addcategory_pos_'.$parent_name;
1.48 raeburn 6370: for (my $j=0; $j<=$numchildren; $j++) {
1.49 raeburn 6371: if ($j < $numchildren) {
1.48 raeburn 6372: $name = $cats->[$depth]{$parent}[$j];
6373: $item = &escape($name).':'.&escape($parent).':'.$depth;
1.49 raeburn 6374: $idxnum = $idx->{$item};
6375: } else {
6376: $name = $parent_name;
6377: $item = $parent_item;
1.48 raeburn 6378: }
1.49 raeburn 6379: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'$parent_name','$item','$idxnum'".');"';
6380: $text .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="'.$item.'"'.$chgstr.'>';
1.48 raeburn 6381: for (my $i=0; $i<=$numchildren; $i++) {
6382: my $vpos = $i+1;
6383: my $selstr;
6384: if ($j == $i) {
6385: $selstr = ' selected="selected" ';
6386: }
6387: $text .= '<option value="'.$i.'"'.$selstr.'>'.$vpos.'</option>';
6388: }
6389: $text .= '</select> ';
6390: if ($j < $numchildren) {
6391: my $deeper = $depth+1;
6392: $text .= $name.' '
6393: .'<label><input type="checkbox" name="deletecategory" value="'
6394: .$item.'" />'.&mt('Delete').'</label></span></td><td>';
6395: if(ref($path) eq 'ARRAY') {
6396: push(@{$path},$name);
1.49 raeburn 6397: $text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path,$idx);
1.48 raeburn 6398: pop(@{$path});
6399: }
6400: } else {
1.59 bisitz 6401: $text .= &mt('Add subcategory:').' </span><input type="textbox" size="20" name="addcategory_name_';
1.48 raeburn 6402: if ($j == $numchildren) {
6403: $text .= $name;
6404: } else {
6405: $text .= $item;
6406: }
6407: $text .= '" value="" />';
6408: }
6409: $text .= '</td></tr>';
6410: }
6411: $text .= '</table></td>';
6412: } else {
6413: my $higher = $depth-1;
6414: if ($higher == 0) {
6415: $name = &escape($parent).'::'.$higher;
6416: } else {
6417: if (ref($path) eq 'ARRAY') {
6418: $name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
6419: }
6420: }
6421: my $colspan;
6422: if ($parent ne 'instcode') {
6423: $colspan = $maxdepth - $depth - 1;
6424: $text .= '<td colspan="'.$colspan.'">'.&mt('Add subcategory:').'<input type="textbox" size="20" name="subcat_'.$name.'" value="" /></td>';
6425: }
6426: }
6427: }
6428: }
6429: return $text;
6430: }
6431:
1.33 raeburn 6432: sub modifiable_userdata_row {
1.228 raeburn 6433: my ($context,$item,$settings,$numinrow,$rowcount,$usertypes,$fieldsref,$titlesref) = @_;
6434: my ($role,$rolename,$statustype);
6435: $role = $item;
1.224 raeburn 6436: if ($context eq 'cancreate') {
1.228 raeburn 6437: if ($item =~ /^emailusername_(.+)$/) {
6438: $statustype = $1;
6439: $role = 'emailusername';
6440: if (ref($usertypes) eq 'HASH') {
6441: if ($usertypes->{$statustype}) {
6442: $rolename = &mt('Data provided by [_1]',$usertypes->{$statustype});
6443: } else {
6444: $rolename = &mt('Data provided by user');
6445: }
6446: }
1.224 raeburn 6447: }
6448: } elsif ($context eq 'selfcreate') {
1.63 raeburn 6449: if (ref($usertypes) eq 'HASH') {
6450: $rolename = $usertypes->{$role};
6451: } else {
6452: $rolename = $role;
6453: }
1.33 raeburn 6454: } else {
1.63 raeburn 6455: if ($role eq 'cr') {
6456: $rolename = &mt('Custom role');
6457: } else {
6458: $rolename = &Apache::lonnet::plaintext($role);
6459: }
1.33 raeburn 6460: }
1.224 raeburn 6461: my (@fields,%fieldtitles);
6462: if (ref($fieldsref) eq 'ARRAY') {
6463: @fields = @{$fieldsref};
6464: } else {
6465: @fields = ('lastname','firstname','middlename','generation',
6466: 'permanentemail','id');
6467: }
6468: if ((ref($titlesref) eq 'HASH')) {
6469: %fieldtitles = %{$titlesref};
6470: } else {
6471: %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
6472: }
1.33 raeburn 6473: my $output;
6474: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
6475: $output = '<tr '.$css_class.'>'.
6476: '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
6477: '<td class="LC_left_item" colspan="2"><table>';
6478: my $rem;
6479: my %checks;
6480: if (ref($settings) eq 'HASH') {
6481: if (ref($settings->{$context}) eq 'HASH') {
6482: if (ref($settings->{$context}->{$role}) eq 'HASH') {
1.228 raeburn 6483: my $hashref = $settings->{$context}->{$role};
6484: if ($role eq 'emailusername') {
6485: if ($statustype) {
6486: if (ref($settings->{$context}->{$role}->{$statustype}) eq 'HASH') {
6487: $hashref = $settings->{$context}->{$role}->{$statustype};
6488: if (ref($hashref) eq 'HASH') {
6489: foreach my $field (@fields) {
6490: if ($hashref->{$field}) {
6491: $checks{$field} = $hashref->{$field};
6492: }
6493: }
6494: }
6495: }
6496: }
6497: } else {
6498: if (ref($hashref) eq 'HASH') {
6499: foreach my $field (@fields) {
6500: if ($hashref->{$field}) {
6501: $checks{$field} = ' checked="checked" ';
6502: }
6503: }
1.33 raeburn 6504: }
6505: }
6506: }
6507: }
6508: }
1.228 raeburn 6509:
1.33 raeburn 6510: for (my $i=0; $i<@fields; $i++) {
6511: my $rem = $i%($numinrow);
6512: if ($rem == 0) {
6513: if ($i > 0) {
6514: $output .= '</tr>';
6515: }
6516: $output .= '<tr>';
6517: }
6518: my $check = ' ';
1.228 raeburn 6519: unless ($role eq 'emailusername') {
6520: if (exists($checks{$fields[$i]})) {
6521: $check = $checks{$fields[$i]}
6522: } else {
6523: if ($role eq 'st') {
6524: if (ref($settings) ne 'HASH') {
6525: $check = ' checked="checked" ';
6526: }
1.33 raeburn 6527: }
6528: }
6529: }
6530: $output .= '<td class="LC_left_item">'.
1.228 raeburn 6531: '<span class="LC_nobreak">';
6532: if ($role eq 'emailusername') {
6533: unless ($checks{$fields[$i]} =~ /^(required|optional)$/) {
6534: $checks{$fields[$i]} = 'omit';
6535: }
6536: foreach my $option ('required','optional','omit') {
6537: my $checked='';
6538: if ($checks{$fields[$i]} eq $option) {
6539: $checked='checked="checked" ';
6540: }
6541: $output .= '<label>'.
6542: '<input type="radio" name="canmodify_'.$item.'_'.$fields[$i].'" value="'.$option.'" '.$checked.'/>'.
6543: &mt($option).'</label>'.(' ' x2);
6544: }
6545: $output .= '<i>'.$fieldtitles{$fields[$i]}.'</i>';
6546: } else {
6547: $output .= '<label>'.
6548: '<input type="checkbox" name="canmodify_'.$role.'" '.
6549: 'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
6550: '</label>';
6551: }
6552: $output .= '</span></td>';
1.33 raeburn 6553: $rem = @fields%($numinrow);
6554: }
6555: my $colsleft = $numinrow - $rem;
6556: if ($colsleft > 1 ) {
6557: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
6558: ' </td>';
6559: } elsif ($colsleft == 1) {
6560: $output .= '<td class="LC_left_item"> </td>';
6561: }
6562: $output .= '</tr></table></td></tr>';
6563: return $output;
6564: }
1.28 raeburn 6565:
1.93 raeburn 6566: sub insttypes_row {
1.224 raeburn 6567: my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle,$context,$rownum) = @_;
1.93 raeburn 6568: my %lt = &Apache::lonlocal::texthash (
6569: cansearch => 'Users allowed to search',
6570: statustocreate => 'Institutional affiliation(s) able to create own account (login/SSO)',
1.131 raeburn 6571: lockablenames => 'User preference to lock name',
1.93 raeburn 6572: );
6573: my $showdom;
6574: if ($context eq 'cansearch') {
6575: $showdom = ' ('.$dom.')';
6576: }
1.165 raeburn 6577: my $class = 'LC_left_item';
6578: if ($context eq 'statustocreate') {
6579: $class = 'LC_right_item';
6580: }
1.224 raeburn 6581: my $css_class = ' class="LC_odd_row"';
6582: if ($rownum ne '') {
6583: $css_class = ($rownum%2? ' class="LC_odd_row"':'');
6584: }
6585: my $output = '<tr'.$css_class.'>'.
6586: '<td>'.$lt{$context}.$showdom.
6587: '</td><td class="'.$class.'" colspan="2"><table>';
1.26 raeburn 6588: my $rem;
6589: if (ref($types) eq 'ARRAY') {
6590: for (my $i=0; $i<@{$types}; $i++) {
6591: if (defined($usertypes->{$types->[$i]})) {
6592: my $rem = $i%($numinrow);
6593: if ($rem == 0) {
6594: if ($i > 0) {
6595: $output .= '</tr>';
6596: }
6597: $output .= '<tr>';
1.23 raeburn 6598: }
1.26 raeburn 6599: my $check = ' ';
1.99 raeburn 6600: if (ref($settings) eq 'HASH') {
6601: if (ref($settings->{$context}) eq 'ARRAY') {
6602: if (grep(/^\Q$types->[$i]\E$/,@{$settings->{$context}})) {
6603: $check = ' checked="checked" ';
6604: }
6605: } elsif ($context eq 'statustocreate') {
1.26 raeburn 6606: $check = ' checked="checked" ';
6607: }
1.23 raeburn 6608: }
1.26 raeburn 6609: $output .= '<td class="LC_left_item">'.
6610: '<span class="LC_nobreak"><label>'.
1.93 raeburn 6611: '<input type="checkbox" name="'.$context.'" '.
1.26 raeburn 6612: 'value="'.$types->[$i].'"'.$check.'/>'.
6613: $usertypes->{$types->[$i]}.'</label></span></td>';
1.23 raeburn 6614: }
6615: }
1.26 raeburn 6616: $rem = @{$types}%($numinrow);
1.23 raeburn 6617: }
6618: my $colsleft = $numinrow - $rem;
1.131 raeburn 6619: if (($rem == 0) && (@{$types} > 0)) {
6620: $output .= '<tr>';
6621: }
1.23 raeburn 6622: if ($colsleft > 1) {
1.25 raeburn 6623: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
1.23 raeburn 6624: } else {
1.25 raeburn 6625: $output .= '<td class="LC_left_item">';
1.23 raeburn 6626: }
6627: my $defcheck = ' ';
1.99 raeburn 6628: if (ref($settings) eq 'HASH') {
6629: if (ref($settings->{$context}) eq 'ARRAY') {
6630: if (grep(/^default$/,@{$settings->{$context}})) {
6631: $defcheck = ' checked="checked" ';
6632: }
6633: } elsif ($context eq 'statustocreate') {
1.26 raeburn 6634: $defcheck = ' checked="checked" ';
6635: }
1.23 raeburn 6636: }
1.25 raeburn 6637: $output .= '<span class="LC_nobreak"><label>'.
1.93 raeburn 6638: '<input type="checkbox" name="'.$context.'" '.
1.25 raeburn 6639: 'value="default"'.$defcheck.'/>'.
6640: $othertitle.'</label></span></td>'.
6641: '</tr></table></td></tr>';
6642: return $output;
1.23 raeburn 6643: }
6644:
6645: sub sorted_searchtitles {
6646: my %searchtitles = &Apache::lonlocal::texthash(
6647: 'uname' => 'username',
6648: 'lastname' => 'last name',
6649: 'lastfirst' => 'last name, first name',
6650: );
6651: my @titleorder = ('uname','lastname','lastfirst');
6652: return (\%searchtitles,\@titleorder);
6653: }
6654:
1.25 raeburn 6655: sub sorted_searchtypes {
6656: my %srchtypes_desc = (
6657: exact => 'is exact match',
6658: contains => 'contains ..',
6659: begins => 'begins with ..',
6660: );
6661: my @srchtypeorder = ('exact','begins','contains');
6662: return (\%srchtypes_desc,\@srchtypeorder);
6663: }
6664:
1.3 raeburn 6665: sub usertype_update_row {
6666: my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
6667: my $datatable;
6668: my $numinrow = 4;
6669: foreach my $type (@{$types}) {
6670: if (defined($usertypes->{$type})) {
6671: $$rownums ++;
6672: my $css_class = $$rownums%2?' class="LC_odd_row"':'';
6673: $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
6674: '</td><td class="LC_left_item"><table>';
6675: for (my $i=0; $i<@{$fields}; $i++) {
6676: my $rem = $i%($numinrow);
6677: if ($rem == 0) {
6678: if ($i > 0) {
6679: $datatable .= '</tr>';
6680: }
6681: $datatable .= '<tr>';
6682: }
6683: my $check = ' ';
1.39 raeburn 6684: if (ref($settings) eq 'HASH') {
6685: if (ref($settings->{'fields'}) eq 'HASH') {
6686: if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
6687: if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
6688: $check = ' checked="checked" ';
6689: }
1.3 raeburn 6690: }
6691: }
6692: }
6693:
6694: if ($i == @{$fields}-1) {
6695: my $colsleft = $numinrow - $rem;
6696: if ($colsleft > 1) {
6697: $datatable .= '<td colspan="'.$colsleft.'">';
6698: } else {
6699: $datatable .= '<td>';
6700: }
6701: } else {
6702: $datatable .= '<td>';
6703: }
1.8 raeburn 6704: $datatable .= '<span class="LC_nobreak"><label>'.
6705: '<input type="checkbox" name="updateable_'.$type.
6706: '_'.$fields->[$i].'" value="1"'.$check.'/>'.
6707: $fieldtitles->{$fields->[$i]}.'</label></span></td>';
1.3 raeburn 6708: }
6709: $datatable .= '</tr></table></td></tr>';
6710: }
6711: }
6712: return $datatable;
1.1 raeburn 6713: }
6714:
6715: sub modify_login {
1.205 raeburn 6716: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.168 raeburn 6717: my ($resulttext,$errors,$colchgtext,%changes,%colchanges,%newfile,%newurl,
6718: %curr_loginvia,%loginhash,@currlangs,@newlangs,$addedfile,%title,@offon);
6719: %title = ( coursecatalog => 'Display course catalog',
6720: adminmail => 'Display administrator E-mail address',
1.188 raeburn 6721: helpdesk => 'Display "Contact Helpdesk" link',
1.168 raeburn 6722: newuser => 'Link for visitors to create a user account',
6723: loginheader => 'Log-in box header');
6724: @offon = ('off','on');
1.112 raeburn 6725: if (ref($domconfig{login}) eq 'HASH') {
6726: if (ref($domconfig{login}{loginvia}) eq 'HASH') {
6727: foreach my $lonhost (keys(%{$domconfig{login}{loginvia}})) {
6728: $curr_loginvia{$lonhost} = $domconfig{login}{loginvia}{$lonhost};
6729: }
6730: }
6731: }
1.9 raeburn 6732: ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
6733: \%domconfig,\%loginhash);
1.188 raeburn 6734: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 6735: foreach my $item (@toggles) {
6736: $loginhash{login}{$item} = $env{'form.'.$item};
6737: }
1.41 raeburn 6738: $loginhash{login}{loginheader} = $env{'form.loginheader'};
1.6 raeburn 6739: if (ref($colchanges{'login'}) eq 'HASH') {
6740: $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
6741: \%loginhash);
6742: }
1.110 raeburn 6743:
1.149 raeburn 6744: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.256 raeburn 6745: my %domservers = &Apache::lonnet::get_servers($dom);
1.128 raeburn 6746: my @loginvia_attribs = ('serverpath','custompath','exempt');
1.110 raeburn 6747: if (keys(%servers) > 1) {
6748: foreach my $lonhost (keys(%servers)) {
1.128 raeburn 6749: next if ($env{'form.'.$lonhost.'_server'} eq $lonhost);
6750: if (ref($curr_loginvia{$lonhost}) eq 'HASH') {
6751: if ($env{'form.'.$lonhost.'_server'} eq $curr_loginvia{$lonhost}{'server'}) {
6752: $loginhash{login}{loginvia}{$lonhost}{'server'} = $curr_loginvia{$lonhost}{'server'};
6753: } elsif ($curr_loginvia{$lonhost}{'server'} ne '') {
6754: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
6755: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
6756: $changes{'loginvia'}{$lonhost} = 1;
6757: } else {
6758: $loginhash{login}{loginvia}{$lonhost}{'server'} = '';
6759: $changes{'loginvia'}{$lonhost} = 1;
6760: }
6761: } else {
6762: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
6763: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
6764: $changes{'loginvia'}{$lonhost} = 1;
6765: }
6766: }
6767: if ($loginhash{login}{loginvia}{$lonhost}{'server'} eq '') {
6768: foreach my $item (@loginvia_attribs) {
6769: $loginhash{login}{loginvia}{$lonhost}{$item} = '';
6770: }
6771: } else {
6772: foreach my $item (@loginvia_attribs) {
6773: my $new = $env{'form.'.$lonhost.'_'.$item};
6774: if (($item eq 'serverpath') && ($new eq 'custom')) {
6775: $env{'form.'.$lonhost.'_custompath'} =~ s/\s+//g;
6776: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
6777: $new = '/';
6778: }
6779: }
6780: if (($item eq 'custompath') &&
6781: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
6782: $new = '';
6783: }
6784: if ($new ne $curr_loginvia{$lonhost}{$item}) {
6785: $changes{'loginvia'}{$lonhost} = 1;
6786: }
6787: if ($item eq 'exempt') {
1.256 raeburn 6788: $new = &check_exempt_addresses($new);
1.128 raeburn 6789: }
6790: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
6791: }
6792: }
1.112 raeburn 6793: } else {
1.128 raeburn 6794: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
6795: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
1.112 raeburn 6796: $changes{'loginvia'}{$lonhost} = 1;
1.128 raeburn 6797: foreach my $item (@loginvia_attribs) {
6798: my $new = $env{'form.'.$lonhost.'_'.$item};
6799: if (($item eq 'serverpath') && ($new eq 'custom')) {
6800: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
6801: $new = '/';
6802: }
6803: }
6804: if (($item eq 'custompath') &&
6805: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
6806: $new = '';
6807: }
6808: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
6809: }
1.110 raeburn 6810: }
6811: }
6812: }
6813: }
1.119 raeburn 6814:
1.168 raeburn 6815: my $servadm = $r->dir_config('lonAdmEMail');
6816: my %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
6817: if (ref($domconfig{'login'}) eq 'HASH') {
6818: if (ref($domconfig{'login'}{'helpurl'}) eq 'HASH') {
6819: foreach my $lang (sort(keys(%{$domconfig{'login'}{'helpurl'}}))) {
6820: if ($lang eq 'nolang') {
6821: push(@currlangs,$lang);
6822: } elsif (defined($langchoices{$lang})) {
6823: push(@currlangs,$lang);
6824: } else {
6825: next;
6826: }
6827: }
6828: }
6829: }
6830: my @delurls = &Apache::loncommon::get_env_multiple('form.loginhelpurl_del');
6831: if (@currlangs > 0) {
6832: foreach my $lang (@currlangs) {
6833: if (grep(/^\Q$lang\E$/,@delurls)) {
6834: $changes{'helpurl'}{$lang} = 1;
6835: } elsif ($env{'form.loginhelpurl_'.$lang.'.filename'}) {
6836: $changes{'helpurl'}{$lang} = 1;
6837: $newfile{$lang} = $env{'form.loginhelpurl_'.$lang.'.filename'};
6838: push(@newlangs,$lang);
6839: } else {
6840: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
6841: }
6842: }
6843: }
6844: unless (grep(/^nolang$/,@currlangs)) {
6845: if ($env{'form.loginhelpurl_nolang.filename'}) {
6846: $changes{'helpurl'}{'nolang'} = 1;
6847: $newfile{'nolang'} = $env{'form.loginhelpurl_nolang.filename'};
6848: push(@newlangs,'nolang');
6849: }
6850: }
6851: if ($env{'form.loginhelpurl_add_lang'}) {
6852: if ((defined($langchoices{$env{'form.loginhelpurl_add_lang'}})) &&
6853: ($env{'form.loginhelpurl_add_file.filename'})) {
6854: $newfile{$env{'form.loginhelpurl_add_lang'}} = $env{'form.loginhelpurl_add_file.filename'};
6855: $addedfile = $env{'form.loginhelpurl_add_lang'};
6856: }
6857: }
6858: if ((@newlangs > 0) || ($addedfile)) {
6859: my $error;
6860: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
6861: if ($configuserok eq 'ok') {
6862: if ($switchserver) {
6863: $error = &mt("Upload of custom help file is not permitted to this server: [_1]",$switchserver);
6864: } elsif ($author_ok eq 'ok') {
6865: my @allnew = @newlangs;
6866: if ($addedfile ne '') {
6867: push(@allnew,$addedfile);
6868: }
6869: foreach my $lang (@allnew) {
6870: my $formelem = 'loginhelpurl_'.$lang;
6871: if ($lang eq $env{'form.loginhelpurl_add_lang'}) {
6872: $formelem = 'loginhelpurl_add_file';
6873: }
6874: (my $result,$newurl{$lang}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
6875: "help/$lang",'','',$newfile{$lang});
6876: if ($result eq 'ok') {
6877: $loginhash{'login'}{'helpurl'}{$lang} = $newurl{$lang};
6878: $changes{'helpurl'}{$lang} = 1;
6879: } else {
6880: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$newfile{$lang},$result);
6881: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
1.210 raeburn 6882: if ((grep(/^\Q$lang\E$/,@currlangs)) &&
1.168 raeburn 6883: (!grep(/^\Q$lang\E$/,@delurls))) {
6884: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
6885: }
6886: }
6887: }
6888: } else {
6889: $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);
6890: }
6891: } else {
6892: $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);
6893: }
6894: if ($error) {
6895: &Apache::lonnet::logthis($error);
6896: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
6897: }
6898: }
1.256 raeburn 6899:
6900: my (%currheadtagurls,%currexempt,@newhosts,%newheadtagurls,%possexempt);
6901: if (ref($domconfig{'login'}) eq 'HASH') {
6902: if (ref($domconfig{'login'}{'headtag'}) eq 'HASH') {
6903: foreach my $lonhost (keys(%{$domconfig{'login'}{'headtag'}})) {
6904: if ($domservers{$lonhost}) {
6905: if (ref($domconfig{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
6906: $currheadtagurls{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'url'};
1.268 raeburn 6907: $currexempt{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'exempt'};
1.256 raeburn 6908: }
6909: }
6910: }
6911: }
6912: }
6913: my @delheadtagurls = &Apache::loncommon::get_env_multiple('form.loginheadtag_del');
6914: foreach my $lonhost (sort(keys(%domservers))) {
6915: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
6916: $changes{'headtag'}{$lonhost} = 1;
6917: } else {
6918: if ($env{'form.loginheadtagexempt_'.$lonhost}) {
6919: $possexempt{$lonhost} = &check_exempt_addresses($env{'form.loginheadtagexempt_'.$lonhost});
6920: }
6921: if ($env{'form.loginheadtag_'.$lonhost.'.filename'}) {
6922: push(@newhosts,$lonhost);
6923: } elsif ($currheadtagurls{$lonhost}) {
6924: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $currheadtagurls{$lonhost};
6925: if ($currexempt{$lonhost}) {
6926: if ((!exists($possexempt{$lonhost})) || ($possexempt{$lonhost} ne $currexempt{$lonhost})) {
6927: $changes{'headtag'}{$lonhost} = 1;
6928: }
6929: } elsif ($possexempt{$lonhost}) {
6930: $changes{'headtag'}{$lonhost} = 1;
6931: }
6932: if ($possexempt{$lonhost}) {
6933: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
6934: }
6935: }
6936: }
6937: }
6938: if (@newhosts) {
6939: my $error;
6940: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
6941: if ($configuserok eq 'ok') {
6942: if ($switchserver) {
6943: $error = &mt("Upload of custom markup is not permitted to this server: [_1]",$switchserver);
6944: } elsif ($author_ok eq 'ok') {
6945: foreach my $lonhost (@newhosts) {
6946: my $formelem = 'loginheadtag_'.$lonhost;
6947: (my $result,$newheadtagurls{$lonhost}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
6948: "login/headtag/$lonhost",'','',
6949: $env{'form.loginheadtag_'.$lonhost.'.filename'});
6950: if ($result eq 'ok') {
6951: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $newheadtagurls{$lonhost};
6952: $changes{'headtag'}{$lonhost} = 1;
6953: if ($possexempt{$lonhost}) {
6954: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
6955: }
6956: } else {
6957: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",
6958: $newheadtagurls{$lonhost},$result);
6959: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
6960: if ((grep(/^\Q$lonhost\E$/,keys(%currheadtagurls))) &&
6961: (!grep(/^\Q$lonhost\E$/,@delheadtagurls))) {
6962: $loginhash{'login'}{'headtag'}{$lonhost} = $currheadtagurls{$lonhost};
6963: }
6964: }
6965: }
6966: } else {
6967: $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);
6968: }
6969: } else {
6970: $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);
6971: }
6972: if ($error) {
6973: &Apache::lonnet::logthis($error);
6974: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
6975: }
6976: }
1.169 raeburn 6977: &process_captcha('login',\%changes,$loginhash{'login'},$domconfig{'login'});
1.168 raeburn 6978:
6979: my $defaulthelpfile = '/adm/loginproblems.html';
6980: my $defaulttext = &mt('Default in use');
6981:
1.1 raeburn 6982: my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
6983: $dom);
6984: if ($putresult eq 'ok') {
1.188 raeburn 6985: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 6986: my %defaultchecked = (
6987: 'coursecatalog' => 'on',
1.188 raeburn 6988: 'helpdesk' => 'on',
1.42 raeburn 6989: 'adminmail' => 'off',
1.43 raeburn 6990: 'newuser' => 'off',
1.42 raeburn 6991: );
1.55 raeburn 6992: if (ref($domconfig{'login'}) eq 'HASH') {
6993: foreach my $item (@toggles) {
6994: if ($defaultchecked{$item} eq 'on') {
6995: if (($domconfig{'login'}{$item} eq '0') &&
6996: ($env{'form.'.$item} eq '1')) {
6997: $changes{$item} = 1;
6998: } elsif (($domconfig{'login'}{$item} eq '' ||
6999: $domconfig{'login'}{$item} eq '1') &&
7000: ($env{'form.'.$item} eq '0')) {
7001: $changes{$item} = 1;
7002: }
7003: } elsif ($defaultchecked{$item} eq 'off') {
7004: if (($domconfig{'login'}{$item} eq '1') &&
7005: ($env{'form.'.$item} eq '0')) {
7006: $changes{$item} = 1;
7007: } elsif (($domconfig{'login'}{$item} eq '' ||
7008: $domconfig{'login'}{$item} eq '0') &&
7009: ($env{'form.'.$item} eq '1')) {
7010: $changes{$item} = 1;
7011: }
1.42 raeburn 7012: }
7013: }
1.41 raeburn 7014: }
1.6 raeburn 7015: if (keys(%changes) > 0 || $colchgtext) {
1.41 raeburn 7016: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 7017: if (ref($lastactref) eq 'HASH') {
7018: $lastactref->{'domainconfig'} = 1;
7019: }
1.1 raeburn 7020: $resulttext = &mt('Changes made:').'<ul>';
7021: foreach my $item (sort(keys(%changes))) {
1.135 bisitz 7022: if ($item eq 'loginvia') {
1.112 raeburn 7023: if (ref($changes{$item}) eq 'HASH') {
7024: $resulttext .= '<li>'.&mt('Log-in page availability:').'<ul>';
7025: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
1.128 raeburn 7026: if (defined($servers{$loginhash{login}{loginvia}{$lonhost}{'server'}})) {
7027: if (ref($loginhash{login}{loginvia}{$lonhost}) eq 'HASH') {
7028: my $protocol = $Apache::lonnet::protocol{$env{'form.'.$lonhost.'_server'}};
7029: $protocol = 'http' if ($protocol ne 'https');
7030: my $target = $protocol.'://'.$servers{$env{'form.'.$lonhost.'_server'}};
7031:
7032: if ($loginhash{login}{loginvia}{$lonhost}{'serverpath'} eq 'custom') {
7033: $target .= $loginhash{login}{loginvia}{$lonhost}{'custompath'};
7034: } else {
7035: $target .= $loginhash{login}{loginvia}{$lonhost}{'serverpath'};
7036: }
7037: $resulttext .= '<li>'.&mt('Server: [_1] log-in page redirects to [_2].',$servers{$lonhost},'<a href="'.$target.'">'.$target.'</a>');
7038: if ($loginhash{login}{loginvia}{$lonhost}{'exempt'} ne '') {
7039: $resulttext .= ' '.&mt('No redirection for clients from following IPs:').' '.$loginhash{login}{loginvia}{$lonhost}{'exempt'};
7040: }
7041: $resulttext .= '</li>';
7042: } else {
7043: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$lonhost).'</li>';
7044: }
1.112 raeburn 7045: } else {
1.128 raeburn 7046: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$servers{$lonhost}).'</li>';
1.112 raeburn 7047: }
7048: }
1.128 raeburn 7049: $resulttext .= '</ul></li>';
1.112 raeburn 7050: }
1.168 raeburn 7051: } elsif ($item eq 'helpurl') {
7052: if (ref($changes{$item}) eq 'HASH') {
7053: foreach my $lang (sort(keys(%{$changes{$item}}))) {
7054: if (grep(/^\Q$lang\E$/,@delurls)) {
7055: my ($chg,$link);
7056: $link = &Apache::loncommon::modal_link($defaulthelpfile,$defaulttext,600,500);
7057: if ($lang eq 'nolang') {
7058: $chg = &mt('custom log-in help file removed for no preferred language; [_1]',$link);
7059: } else {
7060: $chg = &mt('custom log-in help file removed for specific language: [_1]; [_2]',$langchoices{$lang},$link);
7061: }
7062: $resulttext .= '<li>'.$chg.'</li>';
7063: } else {
7064: my $chg;
7065: if ($lang eq 'nolang') {
7066: $chg = &mt('custom log-in help file for no preferred language');
7067: } else {
7068: $chg = &mt('custom log-in help file for specific language: [_1]',$langchoices{$lang});
7069: }
7070: $resulttext .= '<li>'.&Apache::loncommon::modal_link(
7071: $loginhash{'login'}{'helpurl'}{$lang}.
7072: '?inhibitmenu=yes',$chg,600,500).
7073: '</li>';
7074: }
7075: }
7076: }
1.256 raeburn 7077: } elsif ($item eq 'headtag') {
7078: if (ref($changes{$item}) eq 'HASH') {
7079: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
7080: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
7081: $resulttext .= '<li>'.&mt('custom markup file removed for [_1]',$domservers{$lonhost}).'</li>';
7082: } elsif (ref($loginhash{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
7083: $resulttext .= '<li><a href="'.
7084: "javascript:void(open('$loginhash{'login'}{'headtag'}{$lonhost}{'url'}?inhibitmenu=yes','Custom_HeadTag',
7085: 'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
7086: '">'.&mt('custom markup').'</a> '.&mt('(for [_1])',$servers{$lonhost}).' ';
7087: if ($possexempt{$lonhost}) {
7088: $resulttext .= &mt('not included for client IP(s): [_1]',$possexempt{$lonhost});
7089: } else {
7090: $resulttext .= &mt('included for any client IP');
7091: }
7092: $resulttext .= '</li>';
7093: }
7094: }
7095: }
1.169 raeburn 7096: } elsif ($item eq 'captcha') {
7097: if (ref($loginhash{'login'}) eq 'HASH') {
1.210 raeburn 7098: my $chgtxt;
1.169 raeburn 7099: if ($loginhash{'login'}{$item} eq 'notused') {
7100: $chgtxt .= &mt('No CAPTCHA validation in use for helpdesk form.');
7101: } else {
7102: my %captchas = &captcha_phrases();
7103: if ($captchas{$loginhash{'login'}{$item}}) {
7104: $chgtxt .= &mt("Validation for helpdesk form set to $captchas{$loginhash{'login'}{$item}}.");
7105: } else {
7106: $chgtxt .= &mt('Validation for helpdesk form set to unknown type.');
7107: }
7108: }
7109: $resulttext .= '<li>'.$chgtxt.'</li>';
7110: }
7111: } elsif ($item eq 'recaptchakeys') {
7112: if (ref($loginhash{'login'}) eq 'HASH') {
7113: my ($privkey,$pubkey);
7114: if (ref($loginhash{'login'}{$item}) eq 'HASH') {
7115: $pubkey = $loginhash{'login'}{$item}{'public'};
7116: $privkey = $loginhash{'login'}{$item}{'private'};
7117: }
7118: my $chgtxt .= &mt('ReCAPTCHA keys changes').'<ul>';
7119: if (!$pubkey) {
7120: $chgtxt .= '<li>'.&mt('Public key deleted').'</li>';
7121: } else {
7122: $chgtxt .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
7123: }
7124: if (!$privkey) {
7125: $chgtxt .= '<li>'.&mt('Private key deleted').'</li>';
7126: } else {
1.251 raeburn 7127: $chgtxt .= '<li>'.&mt('Private key set to [_1]',$privkey).'</li>';
1.169 raeburn 7128: }
7129: $chgtxt .= '</ul>';
7130: $resulttext .= '<li>'.$chgtxt.'</li>';
7131: }
1.269 raeburn 7132: } elsif ($item eq 'recaptchaversion') {
7133: if (ref($loginhash{'login'}) eq 'HASH') {
7134: if ($loginhash{'login'}{'captcha'} eq 'recaptcha') {
1.270 raeburn 7135: $resulttext .= '<li>'.&mt('ReCAPTCHA for helpdesk form set to version [_1]',$loginhash{'login'}{'recaptchaversion'}).
1.269 raeburn 7136: '</li>';
7137: }
7138: }
1.41 raeburn 7139: } else {
7140: $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
7141: }
1.1 raeburn 7142: }
1.6 raeburn 7143: $resulttext .= $colchgtext.'</ul>';
1.1 raeburn 7144: } else {
7145: $resulttext = &mt('No changes made to log-in page settings');
7146: }
7147: } else {
1.11 albertel 7148: $resulttext = '<span class="LC_error">'.
7149: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 7150: }
1.6 raeburn 7151: if ($errors) {
1.9 raeburn 7152: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.6 raeburn 7153: $errors.'</ul>';
7154: }
7155: return $resulttext;
7156: }
7157:
1.256 raeburn 7158:
7159: sub check_exempt_addresses {
7160: my ($iplist) = @_;
7161: $iplist =~ s/^\s+//;
7162: $iplist =~ s/\s+$//;
7163: my @poss_ips = split(/\s*[,:]\s*/,$iplist);
7164: my (@okips,$new);
7165: foreach my $ip (@poss_ips) {
7166: if ($ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
7167: if (($1 <= 255) && ($2 <= 255) && ($3 <= 255) && ($4 <= 255)) {
7168: push(@okips,$ip);
7169: }
7170: }
7171: }
7172: if (@okips > 0) {
7173: $new = join(',',@okips);
7174: } else {
7175: $new = '';
7176: }
7177: return $new;
7178: }
7179:
1.6 raeburn 7180: sub color_font_choices {
7181: my %choices =
7182: &Apache::lonlocal::texthash (
7183: img => "Header",
7184: bgs => "Background colors",
7185: links => "Link colors",
1.55 raeburn 7186: images => "Images",
1.6 raeburn 7187: font => "Font color",
1.201 raeburn 7188: fontmenu => "Font menu",
1.76 raeburn 7189: pgbg => "Page",
1.6 raeburn 7190: tabbg => "Header",
7191: sidebg => "Border",
7192: link => "Link",
7193: alink => "Active link",
7194: vlink => "Visited link",
7195: );
7196: return %choices;
7197: }
7198:
7199: sub modify_rolecolors {
1.205 raeburn 7200: my ($r,$dom,$confname,$roles,$lastactref,%domconfig) = @_;
1.6 raeburn 7201: my ($resulttext,%rolehash);
7202: $rolehash{'rolecolors'} = {};
1.55 raeburn 7203: if (ref($domconfig{'rolecolors'}) ne 'HASH') {
7204: if ($domconfig{'rolecolors'} eq '') {
7205: $domconfig{'rolecolors'} = {};
7206: }
7207: }
1.9 raeburn 7208: my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
1.6 raeburn 7209: $domconfig{'rolecolors'},$rolehash{'rolecolors'});
7210: my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
7211: $dom);
7212: if ($putresult eq 'ok') {
7213: if (keys(%changes) > 0) {
1.41 raeburn 7214: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 7215: if (ref($lastactref) eq 'HASH') {
7216: $lastactref->{'domainconfig'} = 1;
7217: }
1.6 raeburn 7218: $resulttext = &display_colorchgs($dom,\%changes,$roles,
7219: $rolehash{'rolecolors'});
7220: } else {
7221: $resulttext = &mt('No changes made to default color schemes');
7222: }
7223: } else {
1.11 albertel 7224: $resulttext = '<span class="LC_error">'.
7225: &mt('An error occurred: [_1]',$putresult).'</span>';
1.6 raeburn 7226: }
7227: if ($errors) {
7228: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
7229: $errors.'</ul>';
7230: }
7231: return $resulttext;
7232: }
7233:
7234: sub modify_colors {
1.9 raeburn 7235: my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
1.12 raeburn 7236: my (%changes,%choices);
1.51 raeburn 7237: my @bgs;
1.6 raeburn 7238: my @links = ('link','alink','vlink');
1.41 raeburn 7239: my @logintext;
1.6 raeburn 7240: my @images;
7241: my $servadm = $r->dir_config('lonAdmEMail');
7242: my $errors;
1.200 raeburn 7243: my %defaults;
1.6 raeburn 7244: foreach my $role (@{$roles}) {
7245: if ($role eq 'login') {
1.12 raeburn 7246: %choices = &login_choices();
1.41 raeburn 7247: @logintext = ('textcol','bgcol');
1.12 raeburn 7248: } else {
7249: %choices = &color_font_choices();
7250: }
7251: if ($role eq 'login') {
1.41 raeburn 7252: @images = ('img','logo','domlogo','login');
1.51 raeburn 7253: @bgs = ('pgbg','mainbg','sidebg');
1.6 raeburn 7254: } else {
7255: @images = ('img');
1.200 raeburn 7256: @bgs = ('pgbg','tabbg','sidebg');
7257: }
7258: my %defaults = &role_defaults($role,\@bgs,\@links,\@images,\@logintext);
7259: unless ($env{'form.'.$role.'_font'} eq $defaults{'font'}) {
7260: $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
7261: }
7262: if ($role eq 'login') {
7263: foreach my $item (@logintext) {
1.234 raeburn 7264: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
7265: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
7266: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
7267: }
7268: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'logintext'}{$item})) {
1.200 raeburn 7269: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
7270: }
7271: }
7272: } else {
1.234 raeburn 7273: $env{'form.'.$role.'_fontmenu'} = lc($env{'form.'.$role.'_fontmenu'});
7274: if ($env{'form.'.$role.'_fontmenu'} =~ /^\w+/) {
7275: $env{'form.'.$role.'_fontmenu'} = '#'.$env{'form.'.$role.'_fontmenu'};
7276: }
7277: unless($env{'form.'.$role.'_fontmenu'} eq lc($defaults{'fontmenu'})) {
1.200 raeburn 7278: $confhash->{$role}{'fontmenu'} = $env{'form.'.$role.'_fontmenu'};
7279: }
1.6 raeburn 7280: }
1.200 raeburn 7281: foreach my $item (@bgs) {
1.234 raeburn 7282: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
7283: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
7284: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
7285: }
7286: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'bgs'}{$item})) {
1.200 raeburn 7287: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
7288: }
7289: }
7290: foreach my $item (@links) {
1.234 raeburn 7291: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
7292: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
7293: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
7294: }
7295: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'links'}{$item})) {
1.200 raeburn 7296: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
7297: }
1.6 raeburn 7298: }
1.46 raeburn 7299: my ($configuserok,$author_ok,$switchserver) =
7300: &config_check($dom,$confname,$servadm);
1.9 raeburn 7301: my ($width,$height) = &thumb_dimensions();
1.40 raeburn 7302: if (ref($domconfig->{$role}) ne 'HASH') {
7303: $domconfig->{$role} = {};
7304: }
1.8 raeburn 7305: foreach my $img (@images) {
1.70 raeburn 7306: if (($role eq 'login') && (($img eq 'img') || ($img eq 'logo'))) {
7307: if (defined($env{'form.login_showlogo_'.$img})) {
7308: $confhash->{$role}{'showlogo'}{$img} = 1;
7309: } else {
7310: $confhash->{$role}{'showlogo'}{$img} = 0;
7311: }
7312: }
1.18 albertel 7313: if ( ! $env{'form.'.$role.'_'.$img.'.filename'}
7314: && !defined($domconfig->{$role}{$img})
7315: && !$env{'form.'.$role.'_del_'.$img}
7316: && $env{'form.'.$role.'_import_'.$img}) {
7317: # import the old configured image from the .tab setting
7318: # if they haven't provided a new one
7319: $domconfig->{$role}{$img} =
7320: $env{'form.'.$role.'_import_'.$img};
7321: }
1.6 raeburn 7322: if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
1.9 raeburn 7323: my $error;
1.6 raeburn 7324: if ($configuserok eq 'ok') {
1.9 raeburn 7325: if ($switchserver) {
1.12 raeburn 7326: $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
1.9 raeburn 7327: } else {
7328: if ($author_ok eq 'ok') {
7329: my ($result,$logourl) =
7330: &publishlogo($r,'upload',$role.'_'.$img,
7331: $dom,$confname,$img,$width,$height);
7332: if ($result eq 'ok') {
7333: $confhash->{$role}{$img} = $logourl;
1.12 raeburn 7334: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 7335: } else {
1.12 raeburn 7336: $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 7337: }
7338: } else {
1.46 raeburn 7339: $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 7340: }
7341: }
7342: } else {
1.46 raeburn 7343: $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 7344: }
7345: if ($error) {
1.8 raeburn 7346: &Apache::lonnet::logthis($error);
1.11 albertel 7347: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
1.8 raeburn 7348: }
7349: } elsif ($domconfig->{$role}{$img} ne '') {
1.9 raeburn 7350: if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
7351: my $error;
7352: if ($configuserok eq 'ok') {
7353: # is confname an author?
7354: if ($switchserver eq '') {
7355: if ($author_ok eq 'ok') {
7356: my ($result,$logourl) =
7357: &publishlogo($r,'copy',$domconfig->{$role}{$img},
7358: $dom,$confname,$img,$width,$height);
7359: if ($result eq 'ok') {
7360: $confhash->{$role}{$img} = $logourl;
1.18 albertel 7361: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 7362: }
7363: }
7364: }
7365: }
1.6 raeburn 7366: }
7367: }
7368: }
7369: if (ref($domconfig) eq 'HASH') {
7370: if (ref($domconfig->{$role}) eq 'HASH') {
7371: foreach my $img (@images) {
7372: if ($domconfig->{$role}{$img} ne '') {
7373: if ($env{'form.'.$role.'_del_'.$img}) {
7374: $confhash->{$role}{$img} = '';
1.12 raeburn 7375: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 7376: } else {
1.9 raeburn 7377: if ($confhash->{$role}{$img} eq '') {
7378: $confhash->{$role}{$img} = $domconfig->{$role}{$img};
7379: }
1.6 raeburn 7380: }
7381: } else {
7382: if ($env{'form.'.$role.'_del_'.$img}) {
7383: $confhash->{$role}{$img} = '';
1.12 raeburn 7384: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 7385: }
7386: }
1.70 raeburn 7387: if (($role eq 'login') && (($img eq 'logo') || ($img eq 'img'))) {
7388: if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') {
7389: if ($confhash->{$role}{'showlogo'}{$img} ne
7390: $domconfig->{$role}{'showlogo'}{$img}) {
7391: $changes{$role}{'showlogo'}{$img} = 1;
7392: }
7393: } else {
7394: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
7395: $changes{$role}{'showlogo'}{$img} = 1;
7396: }
7397: }
7398: }
7399: }
1.6 raeburn 7400: if ($domconfig->{$role}{'font'} ne '') {
7401: if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
7402: $changes{$role}{'font'} = 1;
7403: }
7404: } else {
7405: if ($confhash->{$role}{'font'}) {
7406: $changes{$role}{'font'} = 1;
7407: }
7408: }
1.107 raeburn 7409: if ($role ne 'login') {
7410: if ($domconfig->{$role}{'fontmenu'} ne '') {
7411: if ($confhash->{$role}{'fontmenu'} ne $domconfig->{$role}{'fontmenu'}) {
7412: $changes{$role}{'fontmenu'} = 1;
7413: }
7414: } else {
7415: if ($confhash->{$role}{'fontmenu'}) {
7416: $changes{$role}{'fontmenu'} = 1;
7417: }
1.97 tempelho 7418: }
7419: }
1.6 raeburn 7420: foreach my $item (@bgs) {
7421: if ($domconfig->{$role}{$item} ne '') {
7422: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
7423: $changes{$role}{'bgs'}{$item} = 1;
7424: }
7425: } else {
7426: if ($confhash->{$role}{$item}) {
7427: $changes{$role}{'bgs'}{$item} = 1;
7428: }
7429: }
7430: }
7431: foreach my $item (@links) {
7432: if ($domconfig->{$role}{$item} ne '') {
7433: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
7434: $changes{$role}{'links'}{$item} = 1;
7435: }
7436: } else {
7437: if ($confhash->{$role}{$item}) {
7438: $changes{$role}{'links'}{$item} = 1;
7439: }
7440: }
7441: }
1.41 raeburn 7442: foreach my $item (@logintext) {
7443: if ($domconfig->{$role}{$item} ne '') {
7444: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
7445: $changes{$role}{'logintext'}{$item} = 1;
7446: }
7447: } else {
7448: if ($confhash->{$role}{$item}) {
7449: $changes{$role}{'logintext'}{$item} = 1;
7450: }
7451: }
7452: }
1.6 raeburn 7453: } else {
7454: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 7455: \@logintext,$confhash,\%changes);
1.6 raeburn 7456: }
7457: } else {
7458: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 7459: \@logintext,$confhash,\%changes);
1.6 raeburn 7460: }
7461: }
7462: return ($errors,%changes);
7463: }
7464:
1.46 raeburn 7465: sub config_check {
7466: my ($dom,$confname,$servadm) = @_;
7467: my ($configuserok,$author_ok,$switchserver,%currroles);
7468: my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
7469: ($configuserok,%currroles) = &check_configuser($uhome,$dom,
7470: $confname,$servadm);
7471: if ($configuserok eq 'ok') {
7472: $switchserver = &check_switchserver($dom,$confname);
7473: if ($switchserver eq '') {
7474: $author_ok = &check_authorstatus($dom,$confname,%currroles);
7475: }
7476: }
7477: return ($configuserok,$author_ok,$switchserver);
7478: }
7479:
1.6 raeburn 7480: sub default_change_checker {
1.41 raeburn 7481: my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
1.6 raeburn 7482: foreach my $item (@{$links}) {
7483: if ($confhash->{$role}{$item}) {
7484: $changes->{$role}{'links'}{$item} = 1;
7485: }
7486: }
7487: foreach my $item (@{$bgs}) {
7488: if ($confhash->{$role}{$item}) {
7489: $changes->{$role}{'bgs'}{$item} = 1;
7490: }
7491: }
1.41 raeburn 7492: foreach my $item (@{$logintext}) {
7493: if ($confhash->{$role}{$item}) {
7494: $changes->{$role}{'logintext'}{$item} = 1;
7495: }
7496: }
1.6 raeburn 7497: foreach my $img (@{$images}) {
7498: if ($env{'form.'.$role.'_del_'.$img}) {
7499: $confhash->{$role}{$img} = '';
1.12 raeburn 7500: $changes->{$role}{'images'}{$img} = 1;
1.6 raeburn 7501: }
1.70 raeburn 7502: if ($role eq 'login') {
7503: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
7504: $changes->{$role}{'showlogo'}{$img} = 1;
7505: }
7506: }
1.6 raeburn 7507: }
7508: if ($confhash->{$role}{'font'}) {
7509: $changes->{$role}{'font'} = 1;
7510: }
1.48 raeburn 7511: }
1.6 raeburn 7512:
7513: sub display_colorchgs {
7514: my ($dom,$changes,$roles,$confhash) = @_;
7515: my (%choices,$resulttext);
7516: if (!grep(/^login$/,@{$roles})) {
7517: $resulttext = &mt('Changes made:').'<br />';
7518: }
7519: foreach my $role (@{$roles}) {
7520: if ($role eq 'login') {
7521: %choices = &login_choices();
7522: } else {
7523: %choices = &color_font_choices();
7524: }
7525: if (ref($changes->{$role}) eq 'HASH') {
7526: if ($role ne 'login') {
7527: $resulttext .= '<h4>'.&mt($role).'</h4>';
7528: }
7529: foreach my $key (sort(keys(%{$changes->{$role}}))) {
7530: if ($role ne 'login') {
7531: $resulttext .= '<ul>';
7532: }
7533: if (ref($changes->{$role}{$key}) eq 'HASH') {
7534: if ($role ne 'login') {
7535: $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
7536: }
7537: foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
1.70 raeburn 7538: if (($role eq 'login') && ($key eq 'showlogo')) {
7539: if ($confhash->{$role}{$key}{$item}) {
7540: $resulttext .= '<li>'.&mt("$choices{$item} set to be displayed").'</li>';
7541: } else {
7542: $resulttext .= '<li>'.&mt("$choices{$item} set to not be displayed").'</li>';
7543: }
7544: } elsif ($confhash->{$role}{$item} eq '') {
1.6 raeburn 7545: $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
7546: } else {
1.12 raeburn 7547: my $newitem = $confhash->{$role}{$item};
7548: if ($key eq 'images') {
7549: $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" valign="bottom" />';
7550: }
7551: $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
1.6 raeburn 7552: }
7553: }
7554: if ($role ne 'login') {
7555: $resulttext .= '</ul></li>';
7556: }
7557: } else {
7558: if ($confhash->{$role}{$key} eq '') {
7559: $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
7560: } else {
7561: $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
7562: }
7563: }
7564: if ($role ne 'login') {
7565: $resulttext .= '</ul>';
7566: }
7567: }
7568: }
7569: }
1.3 raeburn 7570: return $resulttext;
1.1 raeburn 7571: }
7572:
1.9 raeburn 7573: sub thumb_dimensions {
7574: return ('200','50');
7575: }
7576:
1.16 raeburn 7577: sub check_dimensions {
7578: my ($inputfile) = @_;
7579: my ($fullwidth,$fullheight);
7580: if ($inputfile =~ m|^[/\w.\-]+$|) {
7581: if (open(PIPE,"identify $inputfile 2>&1 |")) {
7582: my $imageinfo = <PIPE>;
7583: if (!close(PIPE)) {
7584: &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
7585: }
7586: chomp($imageinfo);
7587: my ($fullsize) =
1.21 raeburn 7588: ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
1.16 raeburn 7589: if ($fullsize) {
7590: ($fullwidth,$fullheight) = split(/x/,$fullsize);
7591: }
7592: }
7593: }
7594: return ($fullwidth,$fullheight);
7595: }
7596:
1.9 raeburn 7597: sub check_configuser {
7598: my ($uhome,$dom,$confname,$servadm) = @_;
7599: my ($configuserok,%currroles);
7600: if ($uhome eq 'no_host') {
7601: srand( time() ^ ($$ + ($$ << 15)) ); # Seed rand.
7602: my $configpass = &LONCAPA::Enrollment::create_password();
7603: $configuserok =
7604: &Apache::lonnet::modifyuser($dom,$confname,'','internal',
7605: $configpass,'','','','','',undef,$servadm);
7606: } else {
7607: $configuserok = 'ok';
7608: %currroles =
7609: &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
7610: }
7611: return ($configuserok,%currroles);
7612: }
7613:
7614: sub check_authorstatus {
7615: my ($dom,$confname,%currroles) = @_;
7616: my $author_ok;
1.40 raeburn 7617: if (!$currroles{':'.$dom.':au'}) {
1.9 raeburn 7618: my $start = time;
7619: my $end = 0;
7620: $author_ok =
7621: &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
1.47 raeburn 7622: 'au',$end,$start,'','','domconfig');
1.9 raeburn 7623: } else {
7624: $author_ok = 'ok';
7625: }
7626: return $author_ok;
7627: }
7628:
7629: sub publishlogo {
1.46 raeburn 7630: my ($r,$action,$formname,$dom,$confname,$subdir,$thumbwidth,$thumbheight,$savefileas) = @_;
1.267 raeburn 7631: my ($output,$fname,$logourl,$madethumb);
1.9 raeburn 7632: if ($action eq 'upload') {
7633: $fname=$env{'form.'.$formname.'.filename'};
7634: chop($env{'form.'.$formname});
7635: } else {
7636: ($fname) = ($formname =~ /([^\/]+)$/);
7637: }
1.46 raeburn 7638: if ($savefileas ne '') {
7639: $fname = $savefileas;
7640: }
1.9 raeburn 7641: $fname=&Apache::lonnet::clean_filename($fname);
7642: # See if there is anything left
7643: unless ($fname) { return ('error: no uploaded file'); }
7644: $fname="$subdir/$fname";
1.210 raeburn 7645: my $docroot=$r->dir_config('lonDocRoot');
1.164 raeburn 7646: my $filepath="$docroot/priv";
7647: my $relpath = "$dom/$confname";
1.9 raeburn 7648: my ($fnamepath,$file,$fetchthumb);
7649: $file=$fname;
7650: if ($fname=~m|/|) {
7651: ($fnamepath,$file) = ($fname =~ m|^(.*)/([^/]+)$|);
7652: }
1.164 raeburn 7653: my @parts=split(/\//,"$filepath/$relpath/$fnamepath");
1.9 raeburn 7654: my $count;
1.164 raeburn 7655: for ($count=5;$count<=$#parts;$count++) {
1.9 raeburn 7656: $filepath.="/$parts[$count]";
7657: if ((-e $filepath)!=1) {
7658: mkdir($filepath,02770);
7659: }
7660: }
7661: # Check for bad extension and disallow upload
7662: if ($file=~/\.(\w+)$/ &&
7663: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
7664: $output =
1.207 bisitz 7665: &mt('Invalid file extension ([_1]) - reserved for internal use.',$1);
1.9 raeburn 7666: } elsif ($file=~/\.(\w+)$/ &&
7667: !defined(&Apache::loncommon::fileembstyle($1))) {
7668: $output = &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
7669: } elsif ($file=~/\.(\d+)\.(\w+)$/) {
1.195 bisitz 7670: $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 7671: } elsif (-d "$filepath/$file") {
1.195 bisitz 7672: $output = &mt('Filename is a directory name - rename the file and re-upload');
1.9 raeburn 7673: } else {
7674: my $source = $filepath.'/'.$file;
7675: my $logfile;
7676: if (!open($logfile,">>$source".'.log')) {
1.196 raeburn 7677: return (&mt('No write permission to Authoring Space'));
1.9 raeburn 7678: }
7679: print $logfile
7680: "\n================= Publish ".localtime()." ================\n".
7681: $env{'user.name'}.':'.$env{'user.domain'}."\n";
7682: # Save the file
7683: if (!open(FH,'>'.$source)) {
7684: &Apache::lonnet::logthis('Failed to create '.$source);
7685: return (&mt('Failed to create file'));
7686: }
7687: if ($action eq 'upload') {
7688: if (!print FH ($env{'form.'.$formname})) {
7689: &Apache::lonnet::logthis('Failed to write to '.$source);
7690: return (&mt('Failed to write file'));
7691: }
7692: } else {
7693: my $original = &Apache::lonnet::filelocation('',$formname);
7694: if(!copy($original,$source)) {
7695: &Apache::lonnet::logthis('Failed to copy '.$original.' to '.$source);
7696: return (&mt('Failed to write file'));
7697: }
7698: }
7699: close(FH);
7700: chmod(0660, $source); # Permissions to rw-rw---.
7701:
7702: my $targetdir=$docroot.'/res/'.$dom.'/'.$confname .'/'.$fnamepath;
7703: my $copyfile=$targetdir.'/'.$file;
7704:
7705: my @parts=split(/\//,$targetdir);
7706: my $path="/$parts[1]/$parts[2]/$parts[3]/$parts[4]";
7707: for (my $count=5;$count<=$#parts;$count++) {
7708: $path.="/$parts[$count]";
7709: if (!-e $path) {
7710: print $logfile "\nCreating directory ".$path;
7711: mkdir($path,02770);
7712: }
7713: }
7714: my $versionresult;
7715: if (-e $copyfile) {
7716: $versionresult = &logo_versioning($targetdir,$file,$logfile);
7717: } else {
7718: $versionresult = 'ok';
7719: }
7720: if ($versionresult eq 'ok') {
7721: if (copy($source,$copyfile)) {
7722: print $logfile "\nCopied original source to ".$copyfile."\n";
7723: $output = 'ok';
7724: $logourl = '/res/'.$dom.'/'.$confname.'/'.$fname;
1.155 raeburn 7725: push(@{$modified_urls},[$copyfile,$source]);
7726: my $metaoutput =
7727: &write_metadata($dom,$confname,$formname,$targetdir,$file,$logfile);
7728: unless ($registered_cleanup) {
7729: my $handlers = $r->get_handlers('PerlCleanupHandler');
7730: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
7731: $registered_cleanup=1;
7732: }
1.9 raeburn 7733: } else {
7734: print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";
7735: $output = &mt('Failed to copy file to RES space').", $!";
7736: }
7737: if (($thumbwidth =~ /^\d+$/) && ($thumbheight =~ /^\d+$/)) {
7738: my $inputfile = $filepath.'/'.$file;
7739: my $outfile = $filepath.'/'.'tn-'.$file;
1.16 raeburn 7740: my ($fullwidth,$fullheight) = &check_dimensions($inputfile);
7741: if ($fullwidth ne '' && $fullheight ne '') {
7742: if ($fullwidth > $thumbwidth && $fullheight > $thumbheight) {
7743: my $thumbsize = $thumbwidth.'x'.$thumbheight;
7744: system("convert -sample $thumbsize $inputfile $outfile");
7745: chmod(0660, $filepath.'/tn-'.$file);
7746: if (-e $outfile) {
7747: my $copyfile=$targetdir.'/tn-'.$file;
7748: if (copy($outfile,$copyfile)) {
7749: print $logfile "\nCopied source to ".$copyfile."\n";
1.155 raeburn 7750: my $thumb_metaoutput =
7751: &write_metadata($dom,$confname,$formname,
7752: $targetdir,'tn-'.$file,$logfile);
7753: push(@{$modified_urls},[$copyfile,$outfile]);
7754: unless ($registered_cleanup) {
7755: my $handlers = $r->get_handlers('PerlCleanupHandler');
7756: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
7757: $registered_cleanup=1;
7758: }
1.267 raeburn 7759: $madethumb = 1;
1.16 raeburn 7760: } else {
7761: print $logfile "\nUnable to write ".$copyfile.
7762: ':'.$!."\n";
7763: }
7764: }
1.9 raeburn 7765: }
7766: }
7767: }
7768: } else {
7769: $output = $versionresult;
7770: }
7771: }
1.267 raeburn 7772: return ($output,$logourl,$madethumb);
1.9 raeburn 7773: }
7774:
7775: sub logo_versioning {
7776: my ($targetdir,$file,$logfile) = @_;
7777: my $target = $targetdir.'/'.$file;
7778: my ($maxversion,$fn,$extn,$output);
7779: $maxversion = 0;
7780: if ($file =~ /^(.+)\.(\w+)$/) {
7781: $fn=$1;
7782: $extn=$2;
7783: }
7784: opendir(DIR,$targetdir);
7785: while (my $filename=readdir(DIR)) {
7786: if ($filename=~/\Q$fn\E\.(\d+)\.\Q$extn\E$/) {
7787: $maxversion=($1>$maxversion)?$1:$maxversion;
7788: }
7789: }
7790: $maxversion++;
7791: print $logfile "\nCreating old version ".$maxversion."\n";
7792: my $copyfile=$targetdir.'/'.$fn.'.'.$maxversion.'.'.$extn;
7793: if (copy($target,$copyfile)) {
7794: print $logfile "Copied old target to ".$copyfile."\n";
7795: $copyfile=$copyfile.'.meta';
7796: if (copy($target.'.meta',$copyfile)) {
7797: print $logfile "Copied old target metadata to ".$copyfile."\n";
7798: $output = 'ok';
7799: } else {
7800: print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";
7801: $output = &mt('Failed to copy old meta').", $!, ";
7802: }
7803: } else {
7804: print $logfile "Unable to write ".$copyfile.':'.$!."\n";
7805: $output = &mt('Failed to copy old target').", $!, ";
7806: }
7807: return $output;
7808: }
7809:
7810: sub write_metadata {
7811: my ($dom,$confname,$formname,$targetdir,$file,$logfile) = @_;
7812: my (%metadatafields,%metadatakeys,$output);
7813: $metadatafields{'title'}=$formname;
7814: $metadatafields{'creationdate'}=time;
7815: $metadatafields{'lastrevisiondate'}=time;
7816: $metadatafields{'copyright'}='public';
7817: $metadatafields{'modifyinguser'}=$env{'user.name'}.':'.
7818: $env{'user.domain'};
7819: $metadatafields{'authorspace'}=$confname.':'.$dom;
7820: $metadatafields{'domain'}=$dom;
7821: {
7822: print $logfile "\nWrite metadata file for ".$targetdir.'/'.$file;
7823: my $mfh;
1.155 raeburn 7824: if (open($mfh,'>'.$targetdir.'/'.$file.'.meta')) {
1.184 raeburn 7825: foreach (sort(keys(%metadatafields))) {
1.155 raeburn 7826: unless ($_=~/\./) {
7827: my $unikey=$_;
7828: $unikey=~/^([A-Za-z]+)/;
7829: my $tag=$1;
7830: $tag=~tr/A-Z/a-z/;
7831: print $mfh "\n\<$tag";
7832: foreach (split(/\,/,$metadatakeys{$unikey})) {
7833: my $value=$metadatafields{$unikey.'.'.$_};
7834: $value=~s/\"/\'\'/g;
7835: print $mfh ' '.$_.'="'.$value.'"';
7836: }
7837: print $mfh '>'.
7838: &HTML::Entities::encode($metadatafields{$unikey},'<>&"')
7839: .'</'.$tag.'>';
7840: }
7841: }
7842: $output = 'ok';
7843: print $logfile "\nWrote metadata";
7844: close($mfh);
7845: } else {
7846: print $logfile "\nFailed to open metadata file";
1.9 raeburn 7847: $output = &mt('Could not write metadata');
7848: }
7849: }
1.155 raeburn 7850: return $output;
7851: }
7852:
7853: sub notifysubscribed {
7854: foreach my $targetsource (@{$modified_urls}){
7855: next unless (ref($targetsource) eq 'ARRAY');
7856: my ($target,$source)=@{$targetsource};
7857: if ($source ne '') {
7858: if (open(my $logfh,'>>'.$source.'.log')) {
7859: print $logfh "\nCleanup phase: Notifications\n";
7860: my @subscribed=&subscribed_hosts($target);
7861: foreach my $subhost (@subscribed) {
7862: print $logfh "\nNotifying host ".$subhost.':';
7863: my $reply=&Apache::lonnet::critical('update:'.$target,$subhost);
7864: print $logfh $reply;
7865: }
7866: my @subscribedmeta=&subscribed_hosts("$target.meta");
7867: foreach my $subhost (@subscribedmeta) {
7868: print $logfh "\nNotifying host for metadata only ".$subhost.':';
7869: my $reply=&Apache::lonnet::critical('update:'.$target.'.meta',
7870: $subhost);
7871: print $logfh $reply;
7872: }
7873: print $logfh "\n============ Done ============\n";
1.160 raeburn 7874: close($logfh);
1.155 raeburn 7875: }
7876: }
7877: }
7878: return OK;
7879: }
7880:
7881: sub subscribed_hosts {
7882: my ($target) = @_;
7883: my @subscribed;
7884: if (open(my $fh,"<$target.subscription")) {
7885: while (my $subline=<$fh>) {
7886: if ($subline =~ /^($match_lonid):/) {
7887: my $host = $1;
7888: if ($host ne $Apache::lonnet::perlvar{'lonHostID'}) {
7889: unless (grep(/^\Q$host\E$/,@subscribed)) {
7890: push(@subscribed,$host);
7891: }
7892: }
7893: }
7894: }
7895: }
7896: return @subscribed;
1.9 raeburn 7897: }
7898:
7899: sub check_switchserver {
7900: my ($dom,$confname) = @_;
7901: my ($allowed,$switchserver);
7902: my $home = &Apache::lonnet::homeserver($confname,$dom);
7903: if ($home eq 'no_host') {
7904: $home = &Apache::lonnet::domain($dom,'primary');
7905: }
7906: my @ids=&Apache::lonnet::current_machine_ids();
1.10 albertel 7907: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
7908: if (!$allowed) {
1.180 raeburn 7909: $switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role=dc./'.$dom.'/&destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
1.9 raeburn 7910: }
7911: return $switchserver;
7912: }
7913:
1.1 raeburn 7914: sub modify_quotas {
1.216 raeburn 7915: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
1.101 raeburn 7916: my ($context,@usertools,@options,%validations,%titles,%confhash,%toolshash,
1.216 raeburn 7917: %limithash,$toolregexp,%conditions,$resulttext,%changes,$confname,$configuserok,
1.235 raeburn 7918: $author_ok,$switchserver,$errors,$validationitemsref,$validationnamesref,
7919: $validationfieldsref);
1.86 raeburn 7920: if ($action eq 'quotas') {
7921: $context = 'tools';
1.163 raeburn 7922: } else {
1.86 raeburn 7923: $context = $action;
7924: }
7925: if ($context eq 'requestcourses') {
1.271 raeburn 7926: @usertools = ('official','unofficial','community','textbook','placement');
1.106 raeburn 7927: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 7928: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
7929: %titles = &courserequest_titles();
7930: $toolregexp = join('|',@usertools);
7931: %conditions = &courserequest_conditions();
1.216 raeburn 7932: $confname = $dom.'-domainconfig';
7933: my $servadm = $r->dir_config('lonAdmEMail');
7934: ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
1.235 raeburn 7935: ($validationitemsref,$validationnamesref,$validationfieldsref) =
7936: &Apache::loncoursequeueadmin::requestcourses_validation_types();
1.163 raeburn 7937: } elsif ($context eq 'requestauthor') {
7938: @usertools = ('author');
7939: %titles = &authorrequest_titles();
1.86 raeburn 7940: } else {
1.162 raeburn 7941: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 7942: %titles = &tool_titles();
1.86 raeburn 7943: }
1.212 raeburn 7944: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.44 raeburn 7945: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 7946: foreach my $key (keys(%env)) {
1.101 raeburn 7947: if ($context eq 'requestcourses') {
7948: if ($key =~ /^form\.crsreq_($toolregexp)_(.+)$/) {
7949: my $item = $1;
7950: my $type = $2;
7951: if ($type =~ /^limit_(.+)/) {
7952: $limithash{$item}{$1} = $env{$key};
7953: } else {
7954: $confhash{$item}{$type} = $env{$key};
7955: }
7956: }
1.163 raeburn 7957: } elsif ($context eq 'requestauthor') {
7958: if ($key =~ /^\Qform.authorreq_\E(.+)$/) {
7959: $confhash{$1} = $env{$key};
7960: }
1.101 raeburn 7961: } else {
1.86 raeburn 7962: if ($key =~ /^form\.quota_(.+)$/) {
7963: $confhash{'defaultquota'}{$1} = $env{$key};
1.197 raeburn 7964: } elsif ($key =~ /^form\.authorquota_(.+)$/) {
7965: $confhash{'authorquota'}{$1} = $env{$key};
7966: } elsif ($key =~ /^form\.\Q$context\E_(.+)$/) {
1.101 raeburn 7967: @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key);
7968: }
1.72 raeburn 7969: }
7970: }
1.163 raeburn 7971: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.224 raeburn 7972: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.'.$context.'notifyapproval');
1.102 raeburn 7973: @approvalnotify = sort(@approvalnotify);
7974: $confhash{'notify'}{'approval'} = join(',',@approvalnotify);
1.271 raeburn 7975: my @crstypes = ('official','unofficial','community','textbook','placement');
1.218 raeburn 7976: my @hasuniquecode = &Apache::loncommon::get_env_multiple('form.uniquecode');
7977: foreach my $type (@hasuniquecode) {
7978: if (grep(/^\Q$type\E$/,@crstypes)) {
7979: $confhash{'uniquecode'}{$type} = 1;
7980: }
1.216 raeburn 7981: }
1.242 raeburn 7982: my (%newbook,%allpos);
1.216 raeburn 7983: if ($context eq 'requestcourses') {
1.242 raeburn 7984: foreach my $type ('textbooks','templates') {
7985: @{$allpos{$type}} = ();
7986: my $invalid;
7987: if ($type eq 'textbooks') {
7988: $invalid = &mt('Invalid LON-CAPA course for textbook');
7989: } else {
7990: $invalid = &mt('Invalid LON-CAPA course for template');
7991: }
7992: if ($env{'form.'.$type.'_addbook'}) {
7993: if (($env{'form.'.$type.'_addbook_cnum'} =~ /^$match_courseid$/) &&
7994: ($env{'form.'.$type.'_addbook_cdom'} =~ /^$match_domain$/)) {
7995: if (&Apache::lonnet::homeserver($env{'form.'.$type.'_addbook_cnum'},
7996: $env{'form.'.$type.'_addbook_cdom'}) eq 'no_host') {
7997: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
7998: } else {
7999: $newbook{$type} = $env{'form.'.$type.'_addbook_cdom'}.'_'.$env{'form.'.$type.'_addbook_cnum'};
8000: my $position = $env{'form.'.$type.'_addbook_pos'};
8001: $position =~ s/\D+//g;
8002: if ($position ne '') {
8003: $allpos{$type}[$position] = $newbook{$type};
8004: }
1.216 raeburn 8005: }
1.242 raeburn 8006: } else {
8007: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
1.216 raeburn 8008: }
8009: }
1.242 raeburn 8010: }
1.216 raeburn 8011: }
1.102 raeburn 8012: if (ref($domconfig{$action}) eq 'HASH') {
8013: if (ref($domconfig{$action}{'notify'}) eq 'HASH') {
8014: if ($domconfig{$action}{'notify'}{'approval'} ne $confhash{'notify'}{'approval'}) {
8015: $changes{'notify'}{'approval'} = 1;
8016: }
8017: } else {
1.144 raeburn 8018: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 8019: $changes{'notify'}{'approval'} = 1;
8020: }
8021: }
1.218 raeburn 8022: if (ref($domconfig{$action}{'uniquecode'}) eq 'HASH') {
8023: if (ref($confhash{'uniquecode'}) eq 'HASH') {
8024: foreach my $crstype (keys(%{$domconfig{$action}{'uniquecode'}})) {
8025: unless ($confhash{'uniquecode'}{$crstype}) {
8026: $changes{'uniquecode'} = 1;
8027: }
8028: }
8029: unless ($changes{'uniquecode'}) {
8030: foreach my $crstype (keys(%{$confhash{'uniquecode'}})) {
8031: unless ($domconfig{$action}{'uniquecode'}{$crstype}) {
8032: $changes{'uniquecode'} = 1;
8033: }
8034: }
8035: }
8036: } else {
8037: $changes{'uniquecode'} = 1;
8038: }
8039: } elsif (ref($confhash{'uniquecode'}) eq 'HASH') {
8040: $changes{'uniquecode'} = 1;
1.216 raeburn 8041: }
8042: if ($context eq 'requestcourses') {
1.242 raeburn 8043: foreach my $type ('textbooks','templates') {
8044: if (ref($domconfig{$action}{$type}) eq 'HASH') {
8045: my %deletions;
8046: my @todelete = &Apache::loncommon::get_env_multiple('form.'.$type.'_del');
8047: if (@todelete) {
8048: map { $deletions{$_} = 1; } @todelete;
8049: }
8050: my %imgdeletions;
8051: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.'.$type.'_image_del');
8052: if (@todeleteimages) {
8053: map { $imgdeletions{$_} = 1; } @todeleteimages;
8054: }
8055: my $maxnum = $env{'form.'.$type.'_maxnum'};
8056: for (my $i=0; $i<=$maxnum; $i++) {
8057: my $itemid = $env{'form.'.$type.'_id_'.$i};
8058: my ($key) = ($itemid =~ /^\Q$type\E_(\w+)$/);
8059: if (ref($domconfig{$action}{$type}{$key}) eq 'HASH') {
8060: if ($deletions{$key}) {
8061: if ($domconfig{$action}{$type}{$key}{'image'}) {
8062: #FIXME need to obsolete item in RES space
8063: }
8064: next;
8065: } else {
8066: my $newpos = $env{'form.'.$itemid};
8067: $newpos =~ s/\D+//g;
1.243 raeburn 8068: foreach my $item ('subject','title','publisher','author') {
8069: next if ((($item eq 'author') || ($item eq 'publisher')) &&
8070: ($type eq 'templates'));
1.242 raeburn 8071: $confhash{$type}{$key}{$item} = $env{'form.'.$type.'_'.$item.'_'.$i};
8072: if ($domconfig{$action}{$type}{$key}{$item} ne $confhash{$type}{$key}{$item}) {
8073: $changes{$type}{$key} = 1;
8074: }
8075: }
8076: $allpos{$type}[$newpos] = $key;
8077: }
8078: if ($imgdeletions{$key}) {
8079: $changes{$type}{$key} = 1;
1.216 raeburn 8080: #FIXME need to obsolete item in RES space
1.242 raeburn 8081: } elsif ($env{'form.'.$type.'_image_'.$i.'.filename'}) {
8082: my ($cdom,$cnum) = split(/_/,$key);
8083: my ($imgurl,$error) = &process_textbook_image($r,$dom,$confname,$type.'_image_'.$i,
8084: $cdom,$cnum,$type,$configuserok,
8085: $switchserver,$author_ok);
8086: if ($imgurl) {
8087: $confhash{$type}{$key}{'image'} = $imgurl;
8088: $changes{$type}{$key} = 1;
1.216 raeburn 8089: }
1.242 raeburn 8090: if ($error) {
8091: &Apache::lonnet::logthis($error);
8092: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
8093: }
8094: } elsif ($domconfig{$action}{$type}{$key}{'image'}) {
8095: $confhash{$type}{$key}{'image'} =
8096: $domconfig{$action}{$type}{$key}{'image'};
1.216 raeburn 8097: }
8098: }
8099: }
8100: }
8101: }
8102: }
1.102 raeburn 8103: } else {
1.144 raeburn 8104: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 8105: $changes{'notify'}{'approval'} = 1;
8106: }
1.218 raeburn 8107: if (ref($confhash{'uniquecode'} eq 'HASH')) {
1.216 raeburn 8108: $changes{'uniquecode'} = 1;
8109: }
8110: }
8111: if ($context eq 'requestcourses') {
1.242 raeburn 8112: foreach my $type ('textbooks','templates') {
8113: if ($newbook{$type}) {
8114: $changes{$type}{$newbook{$type}} = 1;
1.243 raeburn 8115: foreach my $item ('subject','title','publisher','author') {
8116: next if ((($item eq 'author') || ($item eq 'publisher')) &&
8117: ($type eq 'template'));
1.242 raeburn 8118: $env{'form.'.$type.'_addbook_'.$item} =~ s/(`)/'/g;
8119: if ($env{'form.'.$type.'_addbook_'.$item}) {
8120: $confhash{$type}{$newbook{$type}}{$item} = $env{'form.'.$type.'_addbook_'.$item};
8121: }
8122: }
8123: if ($type eq 'textbooks') {
8124: if ($env{'form.'.$type.'_addbook_image.filename'} ne '') {
8125: my ($cdom,$cnum) = split(/_/,$newbook{$type});
8126: my ($imageurl,$error) =
8127: &process_textbook_image($r,$dom,$confname,$type.'_addbook_image',$cdom,$cnum,$type,
8128: $configuserok,$switchserver,$author_ok);
8129: if ($imageurl) {
8130: $confhash{$type}{$newbook{$type}}{'image'} = $imageurl;
8131: }
8132: if ($error) {
8133: &Apache::lonnet::logthis($error);
8134: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
8135: }
8136: }
1.216 raeburn 8137: }
8138: }
1.242 raeburn 8139: if (@{$allpos{$type}} > 0) {
8140: my $idx = 0;
8141: foreach my $item (@{$allpos{$type}}) {
8142: if ($item ne '') {
8143: $confhash{$type}{$item}{'order'} = $idx;
8144: if (ref($domconfig{$action}) eq 'HASH') {
8145: if (ref($domconfig{$action}{$type}) eq 'HASH') {
8146: if (ref($domconfig{$action}{$type}{$item}) eq 'HASH') {
8147: if ($domconfig{$action}{$type}{$item}{'order'} ne $idx) {
8148: $changes{$type}{$item} = 1;
8149: }
1.216 raeburn 8150: }
8151: }
8152: }
1.242 raeburn 8153: $idx ++;
1.216 raeburn 8154: }
8155: }
8156: }
8157: }
1.235 raeburn 8158: if (ref($validationitemsref) eq 'ARRAY') {
8159: foreach my $item (@{$validationitemsref}) {
8160: if ($item eq 'fields') {
8161: my @changed;
8162: @{$confhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.requestcourses_validation_'.$item);
8163: if (@{$confhash{'validation'}{$item}} > 0) {
8164: @{$confhash{'validation'}{$item}} = sort(@{$confhash{'validation'}{$item}});
8165: }
1.266 raeburn 8166: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
8167: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
8168: if (ref($domconfig{'requestcourses'}{'validation'}{$item}) eq 'ARRAY') {
8169: @changed = &Apache::loncommon::compare_arrays($confhash{'validation'}{$item},
8170: $domconfig{'requestcourses'}{'validation'}{$item});
8171: } else {
8172: @changed = @{$confhash{'validation'}{$item}};
8173: }
1.235 raeburn 8174: } else {
8175: @changed = @{$confhash{'validation'}{$item}};
8176: }
8177: } else {
8178: @changed = @{$confhash{'validation'}{$item}};
8179: }
8180: if (@changed) {
8181: if ($confhash{'validation'}{$item}) {
8182: $changes{'validation'}{$item} = join(', ',@{$confhash{'validation'}{$item}});
8183: } else {
8184: $changes{'validation'}{$item} = &mt('None');
8185: }
8186: }
8187: } else {
8188: $confhash{'validation'}{$item} = $env{'form.requestcourses_validation_'.$item};
8189: if ($item eq 'markup') {
8190: if ($env{'form.requestcourses_validation_'.$item}) {
8191: $env{'form.requestcourses_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
8192: }
8193: }
1.266 raeburn 8194: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
8195: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
8196: if ($domconfig{'requestcourses'}{'validation'}{$item} ne $confhash{'validation'}{$item}) {
8197: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
8198: }
8199: } else {
8200: if ($confhash{'validation'}{$item} ne '') {
8201: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
8202: }
1.235 raeburn 8203: }
8204: } else {
8205: if ($confhash{'validation'}{$item} ne '') {
8206: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
8207: }
8208: }
8209: }
8210: }
8211: }
8212: if ($env{'form.validationdc'}) {
8213: my $newval = $env{'form.validationdc'};
8214: my %domcoords = &get_active_dcs($dom);
8215: if (exists($domcoords{$newval})) {
8216: $confhash{'validation'}{'dc'} = $newval;
8217: }
8218: }
8219: if (ref($confhash{'validation'}) eq 'HASH') {
1.266 raeburn 8220: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
8221: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
8222: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
8223: unless ($confhash{'validation'}{'dc'} eq $domconfig{'requestcourses'}{'validation'}{'dc'}) {
8224: if ($confhash{'validation'}{'dc'} eq '') {
8225: $changes{'validation'}{'dc'} = &mt('None');
8226: } else {
8227: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
8228: }
1.235 raeburn 8229: }
1.266 raeburn 8230: } elsif ($confhash{'validation'}{'dc'} ne '') {
8231: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
1.235 raeburn 8232: }
8233: } elsif ($confhash{'validation'}{'dc'} ne '') {
8234: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
8235: }
8236: } elsif ($confhash{'validation'}{'dc'} ne '') {
8237: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
1.266 raeburn 8238: }
8239: } else {
8240: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
8241: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
8242: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
8243: $changes{'validation'}{'dc'} = &mt('None');
8244: }
8245: }
1.235 raeburn 8246: }
8247: }
1.102 raeburn 8248: }
8249: } else {
1.86 raeburn 8250: $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
1.197 raeburn 8251: $confhash{'authorquota'}{'default'} = $env{'form.authorquota'};
1.86 raeburn 8252: }
1.72 raeburn 8253: foreach my $item (@usertools) {
8254: foreach my $type (@{$types},'default','_LC_adv') {
1.104 raeburn 8255: my $unset;
1.101 raeburn 8256: if ($context eq 'requestcourses') {
1.104 raeburn 8257: $unset = '0';
8258: if ($type eq '_LC_adv') {
8259: $unset = '';
8260: }
1.101 raeburn 8261: if ($confhash{$item}{$type} eq 'autolimit') {
8262: $confhash{$item}{$type} .= '=';
8263: unless ($limithash{$item}{$type} =~ /\D/) {
8264: $confhash{$item}{$type} .= $limithash{$item}{$type};
8265: }
8266: }
1.163 raeburn 8267: } elsif ($context eq 'requestauthor') {
8268: $unset = '0';
8269: if ($type eq '_LC_adv') {
8270: $unset = '';
8271: }
1.72 raeburn 8272: } else {
1.101 raeburn 8273: if (grep(/^\Q$type\E$/,@{$toolshash{$item}})) {
8274: $confhash{$item}{$type} = 1;
8275: } else {
8276: $confhash{$item}{$type} = 0;
8277: }
1.72 raeburn 8278: }
1.86 raeburn 8279: if (ref($domconfig{$action}) eq 'HASH') {
1.163 raeburn 8280: if ($action eq 'requestauthor') {
8281: if ($domconfig{$action}{$type} ne $confhash{$type}) {
8282: $changes{$type} = 1;
8283: }
8284: } elsif (ref($domconfig{$action}{$item}) eq 'HASH') {
1.86 raeburn 8285: if ($domconfig{$action}{$item}{$type} ne $confhash{$item}{$type}) {
8286: $changes{$item}{$type} = 1;
8287: }
8288: } else {
8289: if ($context eq 'requestcourses') {
1.104 raeburn 8290: if ($confhash{$item}{$type} ne $unset) {
1.86 raeburn 8291: $changes{$item}{$type} = 1;
8292: }
8293: } else {
8294: if (!$confhash{$item}{$type}) {
8295: $changes{$item}{$type} = 1;
8296: }
8297: }
8298: }
8299: } else {
8300: if ($context eq 'requestcourses') {
1.104 raeburn 8301: if ($confhash{$item}{$type} ne $unset) {
1.72 raeburn 8302: $changes{$item}{$type} = 1;
8303: }
1.163 raeburn 8304: } elsif ($context eq 'requestauthor') {
8305: if ($confhash{$type} ne $unset) {
8306: $changes{$type} = 1;
8307: }
1.72 raeburn 8308: } else {
8309: if (!$confhash{$item}{$type}) {
8310: $changes{$item}{$type} = 1;
8311: }
8312: }
8313: }
1.1 raeburn 8314: }
8315: }
1.163 raeburn 8316: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 8317: if (ref($domconfig{'quotas'}) eq 'HASH') {
8318: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
8319: foreach my $key (keys(%{$domconfig{'quotas'}{'defaultquota'}})) {
8320: if (exists($confhash{'defaultquota'}{$key})) {
8321: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{'defaultquota'}{$key}) {
8322: $changes{'defaultquota'}{$key} = 1;
8323: }
8324: } else {
8325: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{'defaultquota'}{$key};
1.72 raeburn 8326: }
8327: }
1.86 raeburn 8328: } else {
8329: foreach my $key (keys(%{$domconfig{'quotas'}})) {
8330: if (exists($confhash{'defaultquota'}{$key})) {
8331: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{$key}) {
8332: $changes{'defaultquota'}{$key} = 1;
8333: }
8334: } else {
8335: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{$key};
1.72 raeburn 8336: }
1.1 raeburn 8337: }
8338: }
1.197 raeburn 8339: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
8340: foreach my $key (keys(%{$domconfig{'quotas'}{'authorquota'}})) {
8341: if (exists($confhash{'authorquota'}{$key})) {
8342: if ($confhash{'authorquota'}{$key} ne $domconfig{'quotas'}{'authorquota'}{$key}) {
8343: $changes{'authorquota'}{$key} = 1;
8344: }
8345: } else {
8346: $confhash{'authorquota'}{$key} = $domconfig{'quotas'}{'authorquota'}{$key};
8347: }
8348: }
8349: }
1.1 raeburn 8350: }
1.86 raeburn 8351: if (ref($confhash{'defaultquota'}) eq 'HASH') {
8352: foreach my $key (keys(%{$confhash{'defaultquota'}})) {
8353: if (ref($domconfig{'quotas'}) eq 'HASH') {
8354: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
8355: if (!exists($domconfig{'quotas'}{'defaultquota'}{$key})) {
8356: $changes{'defaultquota'}{$key} = 1;
8357: }
8358: } else {
8359: if (!exists($domconfig{'quotas'}{$key})) {
8360: $changes{'defaultquota'}{$key} = 1;
8361: }
1.72 raeburn 8362: }
8363: } else {
1.86 raeburn 8364: $changes{'defaultquota'}{$key} = 1;
1.55 raeburn 8365: }
1.1 raeburn 8366: }
8367: }
1.197 raeburn 8368: if (ref($confhash{'authorquota'}) eq 'HASH') {
8369: foreach my $key (keys(%{$confhash{'authorquota'}})) {
8370: if (ref($domconfig{'quotas'}) eq 'HASH') {
8371: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
8372: if (!exists($domconfig{'quotas'}{'authorquota'}{$key})) {
8373: $changes{'authorquota'}{$key} = 1;
8374: }
8375: } else {
8376: $changes{'authorquota'}{$key} = 1;
8377: }
8378: } else {
8379: $changes{'authorquota'}{$key} = 1;
8380: }
8381: }
8382: }
1.1 raeburn 8383: }
1.72 raeburn 8384:
1.163 raeburn 8385: if ($context eq 'requestauthor') {
8386: $domdefaults{'requestauthor'} = \%confhash;
8387: } else {
8388: foreach my $key (keys(%confhash)) {
1.242 raeburn 8389: unless (($context eq 'requestcourses') && (($key eq 'textbooks') || ($key eq 'templates'))) {
1.216 raeburn 8390: $domdefaults{$key} = $confhash{$key};
8391: }
1.163 raeburn 8392: }
1.72 raeburn 8393: }
1.163 raeburn 8394:
1.1 raeburn 8395: my %quotahash = (
1.86 raeburn 8396: $action => { %confhash }
1.1 raeburn 8397: );
8398: my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
8399: $dom);
8400: if ($putresult eq 'ok') {
8401: if (keys(%changes) > 0) {
1.72 raeburn 8402: my $cachetime = 24*60*60;
8403: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 8404: if (ref($lastactref) eq 'HASH') {
8405: $lastactref->{'domdefaults'} = 1;
8406: }
1.1 raeburn 8407: $resulttext = &mt('Changes made:').'<ul>';
1.210 raeburn 8408: unless (($context eq 'requestcourses') ||
1.163 raeburn 8409: ($context eq 'requestauthor')) {
1.86 raeburn 8410: if (ref($changes{'defaultquota'}) eq 'HASH') {
8411: $resulttext .= '<li>'.&mt('Portfolio default quotas').'<ul>';
8412: foreach my $type (@{$types},'default') {
8413: if (defined($changes{'defaultquota'}{$type})) {
8414: my $typetitle = $usertypes->{$type};
8415: if ($type eq 'default') {
8416: $typetitle = $othertitle;
8417: }
1.213 raeburn 8418: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'defaultquota'}{$type}).'</li>';
1.72 raeburn 8419: }
8420: }
1.86 raeburn 8421: $resulttext .= '</ul></li>';
1.72 raeburn 8422: }
1.197 raeburn 8423: if (ref($changes{'authorquota'}) eq 'HASH') {
1.223 bisitz 8424: $resulttext .= '<li>'.&mt('Authoring Space default quotas').'<ul>';
1.197 raeburn 8425: foreach my $type (@{$types},'default') {
8426: if (defined($changes{'authorquota'}{$type})) {
8427: my $typetitle = $usertypes->{$type};
8428: if ($type eq 'default') {
8429: $typetitle = $othertitle;
8430: }
1.213 raeburn 8431: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'authorquota'}{$type}).'</li>';
1.197 raeburn 8432: }
8433: }
8434: $resulttext .= '</ul></li>';
8435: }
1.72 raeburn 8436: }
1.80 raeburn 8437: my %newenv;
1.72 raeburn 8438: foreach my $item (@usertools) {
1.163 raeburn 8439: my (%haschgs,%inconf);
8440: if ($context eq 'requestauthor') {
8441: %haschgs = %changes;
1.210 raeburn 8442: %inconf = %confhash;
1.163 raeburn 8443: } else {
8444: if (ref($changes{$item}) eq 'HASH') {
8445: %haschgs = %{$changes{$item}};
8446: }
8447: if (ref($confhash{$item}) eq 'HASH') {
8448: %inconf = %{$confhash{$item}};
8449: }
8450: }
8451: if (keys(%haschgs) > 0) {
1.80 raeburn 8452: my $newacc =
8453: &Apache::lonnet::usertools_access($env{'user.name'},
8454: $env{'user.domain'},
1.86 raeburn 8455: $item,'reload',$context);
1.210 raeburn 8456: if (($context eq 'requestcourses') ||
1.163 raeburn 8457: ($context eq 'requestauthor')) {
1.108 raeburn 8458: if ($env{'environment.canrequest.'.$item} ne $newacc) {
8459: $newenv{'environment.canrequest.'.$item} = $newacc;
1.86 raeburn 8460: }
8461: } else {
8462: if ($env{'environment.availabletools.'.$item} ne $newacc) {
8463: $newenv{'environment.availabletools.'.$item} = $newacc;
8464: }
1.80 raeburn 8465: }
1.163 raeburn 8466: unless ($context eq 'requestauthor') {
8467: $resulttext .= '<li>'.$titles{$item}.'<ul>';
8468: }
1.72 raeburn 8469: foreach my $type (@{$types},'default','_LC_adv') {
1.163 raeburn 8470: if ($haschgs{$type}) {
1.72 raeburn 8471: my $typetitle = $usertypes->{$type};
8472: if ($type eq 'default') {
8473: $typetitle = $othertitle;
8474: } elsif ($type eq '_LC_adv') {
8475: $typetitle = 'LON-CAPA Advanced Users';
8476: }
1.163 raeburn 8477: if ($inconf{$type}) {
1.101 raeburn 8478: if ($context eq 'requestcourses') {
8479: my $cond;
1.163 raeburn 8480: if ($inconf{$type} =~ /^autolimit=(\d*)$/) {
1.101 raeburn 8481: if ($1 eq '') {
8482: $cond = &mt('(Automatic processing of any request).');
8483: } else {
8484: $cond = &mt('(Automatic processing of requests up to limit of [quant,_1,request] per user).',$1);
8485: }
8486: } else {
1.163 raeburn 8487: $cond = $conditions{$inconf{$type}};
1.101 raeburn 8488: }
8489: $resulttext .= '<li>'.&mt('Set to be available to [_1].',$typetitle).' '.$cond.'</li>';
1.172 raeburn 8490: } elsif ($context eq 'requestauthor') {
8491: $resulttext .= '<li>'.&mt('Set to "[_1]" for "[_2]".',
8492: $titles{$inconf{$type}},$typetitle);
8493:
1.101 raeburn 8494: } else {
8495: $resulttext .= '<li>'.&mt('Set to be available to [_1]',$typetitle).'</li>';
8496: }
1.72 raeburn 8497: } else {
1.104 raeburn 8498: if ($type eq '_LC_adv') {
1.163 raeburn 8499: if ($inconf{$type} eq '0') {
1.104 raeburn 8500: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
8501: } else {
8502: $resulttext .= '<li>'.&mt('No override set for [_1]',$typetitle).'</li>';
8503: }
8504: } else {
8505: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
8506: }
1.72 raeburn 8507: }
8508: }
1.26 raeburn 8509: }
1.163 raeburn 8510: unless ($context eq 'requestauthor') {
8511: $resulttext .= '</ul></li>';
8512: }
1.26 raeburn 8513: }
1.1 raeburn 8514: }
1.163 raeburn 8515: if (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.102 raeburn 8516: if (ref($changes{'notify'}) eq 'HASH') {
8517: if ($changes{'notify'}{'approval'}) {
8518: if (ref($confhash{'notify'}) eq 'HASH') {
8519: if ($confhash{'notify'}{'approval'}) {
8520: $resulttext .= '<li>'.&mt('Notification of requests requiring approval will be sent to: ').$confhash{'notify'}{'approval'}.'</li>';
8521: } else {
1.163 raeburn 8522: $resulttext .= '<li>'.&mt('No Domain Coordinators will receive notification of requests requiring approval.').'</li>';
1.102 raeburn 8523: }
8524: }
8525: }
8526: }
8527: }
1.216 raeburn 8528: if ($action eq 'requestcourses') {
8529: my @offon = ('off','on');
8530: if ($changes{'uniquecode'}) {
1.218 raeburn 8531: if (ref($confhash{'uniquecode'}) eq 'HASH') {
8532: my $codestr = join(' ',map{ &mt($_); } sort(keys(%{$confhash{'uniquecode'}})));
8533: $resulttext .= '<li>'.
8534: &mt('Generation of six character code as course identifier for distribution to students set to on for: [_1].','<b>'.$codestr.'</b>').
8535: '</li>';
8536: } else {
8537: $resulttext .= '<li>'.&mt('Generation of six character code as course identifier for distribution to students set to off.').
8538: '</li>';
8539: }
1.216 raeburn 8540: }
1.242 raeburn 8541: foreach my $type ('textbooks','templates') {
8542: if (ref($changes{$type}) eq 'HASH') {
8543: $resulttext .= '<li>'.&mt("Available $type updated").'<ul>';
8544: foreach my $key (sort(keys(%{$changes{$type}}))) {
8545: my %coursehash = &Apache::lonnet::coursedescription($key);
8546: my $coursetitle = $coursehash{'description'};
8547: my $position = $confhash{$type}{$key}{'order'} + 1;
8548: $resulttext .= '<li>';
1.243 raeburn 8549: foreach my $item ('subject','title','publisher','author') {
8550: next if ((($item eq 'author') || ($item eq 'publisher')) &&
8551: ($type eq 'templates'));
1.242 raeburn 8552: my $name = $item.':';
8553: $name =~ s/^(\w)/\U$1/;
8554: $resulttext .= &mt($name).' '.$confhash{$type}{$key}{$item}.'<br />';
8555: }
8556: $resulttext .= ' '.&mt('Order: [_1]',$position).'<br />';
8557: if ($type eq 'textbooks') {
8558: if ($confhash{$type}{$key}{'image'}) {
8559: $resulttext .= ' '.&mt('Image: [_1]',
8560: '<img src="'.$confhash{$type}{$key}{'image'}.'"'.
8561: ' alt="Textbook cover" />').'<br />';
8562: }
8563: }
8564: $resulttext .= ' '.&mt('LON-CAPA Course: [_1]',$coursetitle).'</li>';
1.216 raeburn 8565: }
1.242 raeburn 8566: $resulttext .= '</ul></li>';
1.216 raeburn 8567: }
8568: }
1.235 raeburn 8569: if (ref($changes{'validation'}) eq 'HASH') {
8570: if ((ref($validationitemsref) eq 'ARRAY') && (ref($validationnamesref) eq 'HASH')) {
8571: $resulttext .= '<li>'.&mt('Validation of courses/communities updated').'<ul>';
8572: foreach my $item (@{$validationitemsref}) {
8573: if (exists($changes{'validation'}{$item})) {
8574: if ($item eq 'markup') {
8575: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
8576: '<br /><pre>'.$changes{'validation'}{$item}.'</pre>').'</li>';
8577: } else {
8578: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
8579: '<b>'.$changes{'validation'}{$item}.'</b>').'</li>';
8580: }
8581: }
8582: }
8583: if (exists($changes{'validation'}{'dc'})) {
8584: $resulttext .= '<li>'.&mt('Validated course requests identified as processed by: [_1]',
8585: '<b>'.$changes{'validation'}{'dc'}.'</b>').'</li>';
8586: }
8587: }
8588: }
1.216 raeburn 8589: }
1.1 raeburn 8590: $resulttext .= '</ul>';
1.80 raeburn 8591: if (keys(%newenv)) {
8592: &Apache::lonnet::appenv(\%newenv);
8593: }
1.1 raeburn 8594: } else {
1.86 raeburn 8595: if ($context eq 'requestcourses') {
8596: $resulttext = &mt('No changes made to rights to request creation of courses.');
1.163 raeburn 8597: } elsif ($context eq 'requestauthor') {
8598: $resulttext = &mt('No changes made to rights to request author space.');
1.86 raeburn 8599: } else {
1.90 weissno 8600: $resulttext = &mt('No changes made to availability of personal information pages, blogs, portfolios or default quotas');
1.86 raeburn 8601: }
1.1 raeburn 8602: }
8603: } else {
1.11 albertel 8604: $resulttext = '<span class="LC_error">'.
8605: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 8606: }
1.216 raeburn 8607: if ($errors) {
8608: $resulttext .= '<p>'.&mt('The following errors occurred when modifying Textbook settings.').
8609: '<ul>'.$errors.'</ul></p>';
8610: }
1.3 raeburn 8611: return $resulttext;
1.1 raeburn 8612: }
8613:
1.216 raeburn 8614: sub process_textbook_image {
1.242 raeburn 8615: my ($r,$dom,$confname,$caller,$cdom,$cnum,$type,$configuserok,$switchserver,$author_ok) = @_;
1.216 raeburn 8616: my $filename = $env{'form.'.$caller.'.filename'};
8617: my ($error,$url);
8618: my ($width,$height) = (50,50);
8619: if ($configuserok eq 'ok') {
8620: if ($switchserver) {
8621: $error = &mt('Upload of textbook image is not permitted to this server: [_1]',
8622: $switchserver);
8623: } elsif ($author_ok eq 'ok') {
8624: my ($result,$imageurl) =
8625: &publishlogo($r,'upload',$caller,$dom,$confname,
1.242 raeburn 8626: "$type/$dom/$cnum/cover",$width,$height);
1.216 raeburn 8627: if ($result eq 'ok') {
8628: $url = $imageurl;
8629: } else {
8630: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
8631: }
8632: } else {
8633: $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);
8634: }
8635: } else {
8636: $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);
8637: }
8638: return ($url,$error);
8639: }
8640:
1.267 raeburn 8641: sub modify_ltitools {
8642: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
8643: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
8644: my ($newid,@allpos,%changes,%confhash,$errors,$resulttext);
8645: my $confname = $dom.'-domainconfig';
8646: my $servadm = $r->dir_config('lonAdmEMail');
8647: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
8648: my (%posslti,%possfield);
8649: my @courseroles = ('cc','in','ta','ep','st');
8650: my @ltiroles = qw(Instructor ContentDeveloper TeachingAssistant Learner);
8651: map { $posslti{$_} = 1; } @ltiroles;
8652: my @allfields = ('fullname','firstname','lastname','email','user','roles');
8653: map { $possfield{$_} = 1; } @allfields;
8654: my %lt = <itools_names();
8655: if ($env{'form.ltitools_add'}) {
8656: my $title = $env{'form.ltitools_add_title'};
8657: $title =~ s/(`)/'/g;
8658: ($newid,my $error) = &get_ltitools_id($dom,$title);
8659: if ($newid) {
8660: my $position = $env{'form.ltitools_add_pos'};
8661: $position =~ s/\D+//g;
8662: if ($position ne '') {
8663: $allpos[$position] = $newid;
8664: }
8665: $changes{$newid} = 1;
8666: foreach my $item ('title','url','key','secret') {
8667: $env{'form.ltitools_add_'.$item} =~ s/(`)/'/g;
8668: if ($env{'form.ltitools_add_'.$item}) {
8669: $confhash{$newid}{$item} = $env{'form.ltitools_add_'.$item};
8670: }
8671: }
8672: if ($env{'form.ltitools_add_version'} eq 'LTI-1p0') {
8673: $confhash{$newid}{'version'} = $env{'form.ltitools_add_version'};
8674: }
8675: if ($env{'form.ltitools_add_msgtype'} eq 'basic-lti-launch-request') {
8676: $confhash{$newid}{'msgtype'} = $env{'form.ltitools_add_msgtype'};
8677: }
8678: foreach my $item ('width','height') {
8679: $env{'form.ltitools_add_'.$item} =~ s/^\s+//;
8680: $env{'form.ltitools_add_'.$item} =~ s/\s+$//;
8681: if ($env{'form.ltitools_add_'.$item} =~ /^\d+$/) {
8682: $confhash{$newid}{'display'}{$item} = $env{'form.ltitools_add_'.$item};
8683: }
8684: }
8685: if ($env{'form.ltitools_add_target'} eq 'window') {
8686: $confhash{$newid}{'display'}{'target'} = $env{'form.ltitools_add_target'};
8687: } else {
8688: $confhash{$newid}{'display'}{'target'} = 'iframe';
8689: }
8690: foreach my $item ('passback','roster') {
8691: if ($env{'form.ltitools_add_'.$item}) {
8692: $confhash{$newid}{$item} = 1;
8693: }
8694: }
8695: if ($env{'form.ltitools_add_image.filename'} ne '') {
8696: my ($imageurl,$error) =
8697: &process_ltitools_image($r,$dom,$confname,'ltitools_add_image',$dom,
8698: $configuserok,$switchserver,$author_ok);
8699: if ($imageurl) {
8700: $confhash{$newid}{'image'} = $imageurl;
8701: }
8702: if ($error) {
8703: &Apache::lonnet::logthis($error);
8704: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
8705: }
8706: }
8707: my @fields = &Apache::loncommon::get_env_multiple('form.ltitools_add_fields');
8708: foreach my $field (@fields) {
8709: if ($possfield{$field}) {
8710: if ($field eq 'roles') {
8711: foreach my $role (@courseroles) {
8712: my $choice = $env{'form.ltitools_add_roles_'.$role};
8713: if (($choice ne '') && ($posslti{$choice})) {
8714: $confhash{$newid}{'roles'}{$role} = $choice;
8715: if ($role eq 'cc') {
8716: $confhash{$newid}{'roles'}{'co'} = $choice;
8717: }
8718: }
8719: }
8720: } else {
8721: $confhash{$newid}{'fields'}{$field} = 1;
8722: }
8723: }
8724: }
1.273 raeburn 8725: my @courseconfig = &Apache::loncommon::get_env_multiple('form.ltitools_courseconfig');
8726: foreach my $item (@courseconfig) {
8727: $confhash{$newid}{'crsconf'}{$item} = 1;
8728: }
1.267 raeburn 8729: if ($env{'form.ltitools_add_custom'}) {
8730: my $name = $env{'form.ltitools_add_custom_name'};
8731: my $value = $env{'form.ltitools_add_custom_value'};
8732: $value =~ s/(`)/'/g;
8733: $name =~ s/(`)/'/g;
8734: $confhash{$newid}{'custom'}{$name} = $value;
8735: }
8736: } else {
8737: my $error = &mt('Failed to acquire unique ID for new external tool');
8738: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
8739: }
8740: }
8741: if (ref($domconfig{$action}) eq 'HASH') {
8742: my %deletions;
8743: my @todelete = &Apache::loncommon::get_env_multiple('form.ltitools_del');
8744: if (@todelete) {
8745: map { $deletions{$_} = 1; } @todelete;
8746: }
8747: my %customadds;
8748: my @newcustom = &Apache::loncommon::get_env_multiple('form.ltitools_customadd');
8749: if (@newcustom) {
8750: map { $customadds{$_} = 1; } @newcustom;
8751: }
8752: my %imgdeletions;
8753: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.ltitools_image_del');
8754: if (@todeleteimages) {
8755: map { $imgdeletions{$_} = 1; } @todeleteimages;
8756: }
8757: my $maxnum = $env{'form.ltitools_maxnum'};
8758: for (my $i=0; $i<=$maxnum; $i++) {
8759: my $itemid = $env{'form.ltitools_id_'.$i};
8760: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
8761: if ($deletions{$itemid}) {
8762: if ($domconfig{$action}{$itemid}{'image'}) {
8763: #FIXME need to obsolete item in RES space
8764: }
8765: $changes{$itemid} = $domconfig{$action}{$itemid}{'title'};
8766: next;
8767: } else {
8768: my $newpos = $env{'form.ltitools_'.$itemid};
8769: $newpos =~ s/\D+//g;
8770: foreach my $item ('title','url','key','secret') {
8771: $confhash{$itemid}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
8772: if ($domconfig{$action}{$itemid}{$item} ne $confhash{$itemid}{$item}) {
8773: $changes{$itemid} = 1;
8774: }
8775: }
8776: if ($env{'form.ltitools_version_'.$i} eq 'LTI-1p0') {
8777: $confhash{$itemid}{'version'} = $env{'form.ltitools_version_'.$i};
8778: }
8779: if ($env{'form.ltitools_msgtype_'.$i} eq 'basic-lti-launch-request') {
8780: $confhash{$itemid}{'msgtype'} = $env{'form.ltitools_msgtype_'.$i};
8781: }
8782: foreach my $size ('width','height') {
8783: $env{'form.ltitools_'.$size.'_'.$i} =~ s/^\s+//;
8784: $env{'form.ltitools_'.$size.'_'.$i} =~ s/\s+$//;
8785: if ($env{'form.ltitools_'.$size.'_'.$i} =~ /^\d+$/) {
8786: $confhash{$itemid}{'display'}{$size} = $env{'form.ltitools_'.$size.'_'.$i};
8787: if (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
8788: if ($domconfig{$action}{$itemid}{'display'}{$size} ne $confhash{$itemid}{'display'}{$size}) {
8789: $changes{$itemid} = 1;
8790: }
8791: } else {
8792: $changes{$itemid} = 1;
8793: }
8794: }
8795: }
8796: if ($env{'form.ltitools_target_'.$i} eq 'window') {
8797: $confhash{$itemid}{'display'}{'target'} = $env{'form.ltitools_target_'.$i};
8798: } else {
8799: $confhash{$itemid}{'display'}{'target'} = 'iframe';
8800: }
8801: if (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
8802: if ($domconfig{$action}{$itemid}{'display'}{'target'} ne $confhash{$itemid}{'display'}{'target'}) {
8803: $changes{$itemid} = 1;
8804: }
8805: } else {
8806: $changes{$itemid} = 1;
8807: }
8808: foreach my $extra ('passback','roster') {
8809: if ($env{'form.ltitools_'.$extra.'_'.$i}) {
8810: $confhash{$itemid}{$extra} = 1;
8811: }
8812: if ($domconfig{$action}{$itemid}{$extra} ne $confhash{$itemid}{$extra}) {
8813: $changes{$itemid} = 1;
8814: }
8815: }
1.273 raeburn 8816: my @courseconfig = &Apache::loncommon::get_env_multiple('form.ltitools_courseconfig_'.$i);
8817: foreach my $item ('label','title','target') {
8818: if (grep(/^\Q$item\E$/,@courseconfig)) {
8819: $confhash{$itemid}{'crsconf'}{$item} = 1;
8820: if (ref($domconfig{$action}{$itemid}{'crsconf'}) eq 'HASH') {
8821: if ($domconfig{$action}{$itemid}{'crsconf'}{$item} ne $confhash{$itemid}{'crsconf'}{$item}) {
8822: $changes{$itemid} = 1;
8823: }
8824: } else {
8825: $changes{$itemid} = 1;
8826: }
8827: }
8828: }
1.267 raeburn 8829: my @fields = &Apache::loncommon::get_env_multiple('form.ltitools_fields_'.$i);
8830: foreach my $field (@fields) {
8831: if ($possfield{$field}) {
8832: if ($field eq 'roles') {
8833: foreach my $role (@courseroles) {
8834: my $choice = $env{'form.ltitools_roles_'.$role.'_'.$i};
8835: if (($choice ne '') && ($posslti{$choice})) {
8836: $confhash{$itemid}{'roles'}{$role} = $choice;
8837: if ($role eq 'cc') {
8838: $confhash{$itemid}{'roles'}{'co'} = $choice;
8839: }
8840: }
8841: if (ref($domconfig{$action}{$itemid}{'roles'}) eq 'HASH') {
8842: if ($domconfig{$action}{$itemid}{'roles'}{$role} ne $confhash{$itemid}{'roles'}{$role}) {
8843: $changes{$itemid} = 1;
8844: }
8845: } elsif ($confhash{$itemid}{'roles'}{$role}) {
8846: $changes{$itemid} = 1;
8847: }
8848: }
8849: } else {
8850: $confhash{$itemid}{'fields'}{$field} = 1;
8851: if (ref($domconfig{$action}{$itemid}{'fields'}) eq 'HASH') {
8852: if ($domconfig{$action}{$itemid}{'fields'}{$field} ne $confhash{$itemid}{'fields'}{$field}) {
8853: $changes{$itemid} = 1;
8854: }
8855: } else {
8856: $changes{$itemid} = 1;
8857: }
8858: }
8859: }
8860: }
8861: $allpos[$newpos] = $itemid;
8862: }
8863: if ($imgdeletions{$itemid}) {
8864: $changes{$itemid} = 1;
8865: #FIXME need to obsolete item in RES space
8866: } elsif ($env{'form.ltitools_image_'.$i.'.filename'}) {
8867: my ($imgurl,$error) = &process_ltitools_image($r,$dom,$confname,'ltitools_image_'.$i,
8868: $itemid,$configuserok,$switchserver,
8869: $author_ok);
8870: if ($imgurl) {
8871: $confhash{$itemid}{'image'} = $imgurl;
8872: $changes{$itemid} = 1;
8873: }
8874: if ($error) {
8875: &Apache::lonnet::logthis($error);
8876: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
8877: }
8878: } elsif ($domconfig{$action}{$itemid}{'image'}) {
8879: $confhash{$itemid}{'image'} =
8880: $domconfig{$action}{$itemid}{'image'};
8881: }
8882: if ($customadds{$i}) {
8883: my $name = $env{'form.ltitools_custom_name_'.$i};
8884: $name =~ s/(`)/'/g;
8885: $name =~ s/^\s+//;
8886: $name =~ s/\s+$//;
8887: my $value = $env{'form.ltitools_custom_value_'.$i};
8888: $value =~ s/(`)/'/g;
8889: $value =~ s/^\s+//;
8890: $value =~ s/\s+$//;
8891: if ($name ne '') {
8892: $confhash{$itemid}{'custom'}{$name} = $value;
8893: $changes{$itemid} = 1;
8894: }
8895: }
8896: my %customdels;
8897: my @customdeletions = &Apache::loncommon::get_env_multiple('form.ltitools_customdel_'.$i);
8898: if (@customdeletions) {
8899: $changes{$itemid} = 1;
8900: }
8901: map { $customdels{$_} = 1; } @customdeletions;
8902: if (ref($domconfig{$action}{$itemid}{'custom'}) eq 'HASH') {
8903: foreach my $key (keys(%{$domconfig{$action}{$itemid}{'custom'}})) {
8904: unless ($customdels{$key}) {
8905: if ($env{'form.ltitools_customval_'.$key.'_'.$i} ne '') {
8906: $confhash{$itemid}{'custom'}{$key} = $env{'form.ltitools_customval_'.$key.'_'.$i};
8907: }
8908: if ($domconfig{$action}{$itemid}{'custom'}{$key} ne $env{'form.ltitools_customval_'.$key.'_'.$i}) {
8909: $changes{$itemid} = 1;
8910: }
8911: }
8912: }
8913: }
8914: unless ($changes{$itemid}) {
8915: foreach my $key (keys(%{$domconfig{$action}{$itemid}})) {
8916: if (ref($domconfig{$action}{$itemid}{$key}) eq 'HASH') {
8917: if (ref($confhash{$itemid}{$key}) eq 'HASH') {
8918: foreach my $innerkey (keys(%{$domconfig{$action}{$itemid}{$key}})) {
8919: unless (exists($confhash{$itemid}{$key}{$innerkey})) {
8920: $changes{$itemid} = 1;
8921: last;
8922: }
8923: }
8924: } elsif (keys(%{$domconfig{$action}{$itemid}{$key}}) > 0) {
8925: $changes{$itemid} = 1;
8926: }
8927: }
8928: last if ($changes{$itemid});
8929: }
8930: }
8931: }
8932: }
8933: }
8934: if (@allpos > 0) {
8935: my $idx = 0;
8936: foreach my $itemid (@allpos) {
8937: if ($itemid ne '') {
8938: $confhash{$itemid}{'order'} = $idx;
8939: if (ref($domconfig{$action}) eq 'HASH') {
8940: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
8941: if ($domconfig{$action}{$itemid}{'order'} ne $idx) {
8942: $changes{$itemid} = 1;
8943: }
8944: }
8945: }
8946: $idx ++;
8947: }
8948: }
8949: }
8950: my %ltitoolshash = (
8951: $action => { %confhash }
8952: );
8953: my $putresult = &Apache::lonnet::put_dom('configuration',\%ltitoolshash,
8954: $dom);
8955: if ($putresult eq 'ok') {
8956: if (keys(%changes) > 0) {
8957: my $cachetime = 24*60*60;
8958: &Apache::lonnet::do_cache_new('ltitools',$dom,\%confhash,$cachetime);
8959: if (ref($lastactref) eq 'HASH') {
8960: $lastactref->{'ltitools'} = 1;
8961: }
8962: $resulttext = &mt('Changes made:').'<ul>';
8963: my %bynum;
8964: foreach my $itemid (sort(keys(%changes))) {
8965: my $position = $confhash{$itemid}{'order'};
8966: $bynum{$position} = $itemid;
8967: }
8968: foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
8969: my $itemid = $bynum{$pos};
8970: if (ref($confhash{$itemid}) ne 'HASH') {
8971: $resulttext .= '<li>'.&mt('Deleted: [_1]',$changes{$itemid}).'</li>';
8972: } else {
8973: $resulttext .= '<li><b>'.$confhash{$itemid}{'title'}.'</b>';
8974: if ($confhash{$itemid}{'image'}) {
8975: $resulttext .= ' '.
8976: '<img src="'.$confhash{$itemid}{'image'}.'"'.
8977: ' alt="'.&mt('Tool Provider icon').'" />';
8978: }
8979: $resulttext .= '</li><ul>';
8980: my $position = $pos + 1;
8981: $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
8982: foreach my $item ('version','msgtype','url','key') {
8983: if ($confhash{$itemid}{$item} ne '') {
8984: $resulttext .= '<li>'.$lt{$item}.': '.$confhash{$itemid}{$item}.'</li>';
8985: }
8986: }
8987: if ($confhash{$itemid}{'secret'} ne '') {
8988: $resulttext .= '<li>'.$lt{'secret'}.': ';
8989: my $num = length($confhash{$itemid}{'secret'});
8990: $resulttext .= ('*'x$num).'</li>';
8991: }
1.273 raeburn 8992: $resulttext .= '<li>'.&mt('Configurable in course:');
8993: my @possconfig = ('label','title','target');
8994: my $numconfig = 0;
8995: if (ref($confhash{$itemid}{'crsconf'}) eq 'HASH') {
8996: foreach my $item (@possconfig) {
8997: if ($confhash{$itemid}{'crsconf'}{$item}) {
8998: $numconfig ++;
8999: $resulttext .= ' '.$lt{'crs'.$item};
9000: }
9001: }
9002: }
9003: if (!$numconfig) {
9004: $resulttext .= &mt('None');
9005: }
9006: $resulttext .= '</li>';
1.267 raeburn 9007: foreach my $item ('passback','roster') {
9008: $resulttext .= '<li>'.$lt{$item}.' ';
9009: if ($confhash{$itemid}{$item}) {
9010: $resulttext .= &mt('Yes');
9011: } else {
9012: $resulttext .= &mt('No');
9013: }
9014: $resulttext .= '</li>';
9015: }
9016: if (ref($confhash{$itemid}{'display'}) eq 'HASH') {
9017: my $displaylist;
9018: if ($confhash{$itemid}{'display'}{'target'}) {
9019: $displaylist = &mt('Display target').': '.
9020: $confhash{$itemid}{'display'}{'target'}.',';
9021: }
9022: foreach my $size ('width','height') {
9023: if ($confhash{$itemid}{'display'}{$size}) {
9024: $displaylist .= (' 'x2).$lt{$size}.': '.
9025: $confhash{$itemid}{'display'}{$size}.',';
9026: }
9027: }
9028: if ($displaylist) {
9029: $displaylist =~ s/,$//;
9030: $resulttext .= '<li>'.$displaylist.'</li>';
9031: }
9032: }
9033: if (ref($confhash{$itemid}{'fields'}) eq 'HASH') {
9034: my $fieldlist;
9035: foreach my $field (@allfields) {
9036: if ($confhash{$itemid}{'fields'}{$field}) {
9037: $fieldlist .= (' 'x2).$lt{$field}.',';
9038: }
9039: }
9040: if ($fieldlist) {
9041: $fieldlist =~ s/,$//;
9042: $resulttext .= '<li>'.&mt('Data sent').':'.$fieldlist.'</li>';
9043: }
9044: }
9045: if (ref($confhash{$itemid}{'roles'}) eq 'HASH') {
9046: my $rolemaps;
9047: foreach my $role (@courseroles) {
9048: if ($confhash{$itemid}{'roles'}{$role}) {
9049: $rolemaps .= (' 'x2).&Apache::lonnet::plaintext($role,'Course').'='.
9050: $confhash{$itemid}{'roles'}{$role}.',';
9051: }
9052: }
9053: if ($rolemaps) {
9054: $rolemaps =~ s/,$//;
9055: $resulttext .= '<li>'.&mt('Role mapping:').$rolemaps.'</li>';
9056: }
9057: }
9058: if (ref($confhash{$itemid}{'custom'}) eq 'HASH') {
9059: my $customlist;
9060: if (keys(%{$confhash{$itemid}{'custom'}})) {
9061: foreach my $key (sort(keys(%{$confhash{$itemid}{'custom'}}))) {
9062: $customlist .= $key.':'.$confhash{$itemid}{'custom'}{$key}.(' 'x2);
9063: }
9064: }
9065: if ($customlist) {
9066: $resulttext .= '<li>'.&mt('Custom items').':'.$customlist.'</li>';
9067: }
9068: }
9069: $resulttext .= '</ul></li>';
9070: }
9071: }
9072: $resulttext .= '</ul>';
9073: } else {
9074: $resulttext = &mt('No changes made.');
9075: }
9076: } else {
9077: $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
9078: }
9079: if ($errors) {
9080: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
9081: $errors.'</ul>';
9082: }
9083: return $resulttext;
9084: }
9085:
9086: sub process_ltitools_image {
9087: my ($r,$dom,$confname,$caller,$itemid,$configuserok,$switchserver,$author_ok) = @_;
9088: my $filename = $env{'form.'.$caller.'.filename'};
9089: my ($error,$url);
9090: my ($width,$height) = (21,21);
9091: if ($configuserok eq 'ok') {
9092: if ($switchserver) {
9093: $error = &mt('Upload of Tool Provider (LTI) icon is not permitted to this server: [_1]',
9094: $switchserver);
9095: } elsif ($author_ok eq 'ok') {
9096: my ($result,$imageurl,$madethumb) =
9097: &publishlogo($r,'upload',$caller,$dom,$confname,
9098: "ltitools/$itemid/icon",$width,$height);
9099: if ($result eq 'ok') {
9100: if ($madethumb) {
9101: my ($path,$imagefile) = ($imageurl =~ m{^(.+)/([^/]+)$});
9102: my $imagethumb = "$path/tn-".$imagefile;
9103: $url = $imagethumb;
9104: } else {
9105: $url = $imageurl;
9106: }
9107: } else {
9108: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
9109: }
9110: } else {
9111: $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);
9112: }
9113: } else {
9114: $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);
9115: }
9116: return ($url,$error);
9117: }
9118:
9119: sub get_ltitools_id {
9120: my ($cdom,$title) = @_;
9121: # get lock on ltitools db
9122: my $lockhash = {
9123: lock => $env{'user.name'}.
9124: ':'.$env{'user.domain'},
9125: };
9126: my $tries = 0;
9127: my $gotlock = &Apache::lonnet::newput_dom('ltitools',$lockhash,$cdom);
9128: my ($id,$error);
9129:
9130: while (($gotlock ne 'ok') && ($tries<10)) {
9131: $tries ++;
9132: sleep (0.1);
9133: $gotlock = &Apache::lonnet::newput_dom('ltitools',$lockhash,$cdom);
9134: }
9135: if ($gotlock eq 'ok') {
9136: my %currids = &Apache::lonnet::dump_dom('ltitools',$cdom);
9137: if ($currids{'lock'}) {
9138: delete($currids{'lock'});
9139: if (keys(%currids)) {
9140: my @curr = sort { $a <=> $b } keys(%currids);
9141: if ($curr[-1] =~ /^\d+$/) {
9142: $id = 1 + $curr[-1];
9143: }
9144: } else {
9145: $id = 1;
9146: }
9147: if ($id) {
9148: unless (&Apache::lonnet::newput_dom('ltitools',{ $id => $title },$cdom) eq 'ok') {
9149: $error = 'nostore';
9150: }
9151: } else {
9152: $error = 'nonumber';
9153: }
9154: }
9155: my $dellockoutcome = &Apache::lonnet::del_dom('ltitools',['lock'],$cdom);
9156: } else {
9157: $error = 'nolock';
9158: }
9159: return ($id,$error);
9160: }
9161:
1.3 raeburn 9162: sub modify_autoenroll {
1.205 raeburn 9163: my ($dom,$lastactref,%domconfig) = @_;
1.1 raeburn 9164: my ($resulttext,%changes);
9165: my %currautoenroll;
9166: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
9167: foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
9168: $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
9169: }
9170: }
9171: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
9172: my %title = ( run => 'Auto-enrollment active',
1.129 raeburn 9173: sender => 'Sender for notification messages',
1.274 raeburn 9174: coowners => 'Automatic assignment of co-ownership to instructors of record (institutional data)',
9175: failsafe => 'Failsafe for no drops if institutional data missing for a section');
1.1 raeburn 9176: my @offon = ('off','on');
1.17 raeburn 9177: my $sender_uname = $env{'form.sender_uname'};
9178: my $sender_domain = $env{'form.sender_domain'};
9179: if ($sender_domain eq '') {
9180: $sender_uname = '';
9181: } elsif ($sender_uname eq '') {
9182: $sender_domain = '';
9183: }
1.129 raeburn 9184: my $coowners = $env{'form.autoassign_coowners'};
1.274 raeburn 9185: my $failsafe = $env{'form.autoenroll_failsafe'};
9186: $failsafe =~ s{^\s+|\s+$}{}g;
9187: if ($failsafe =~ /\D/) {
9188: undef($failsafe);
9189: }
1.1 raeburn 9190: my %autoenrollhash = (
1.129 raeburn 9191: autoenroll => { 'run' => $env{'form.autoenroll_run'},
9192: 'sender_uname' => $sender_uname,
9193: 'sender_domain' => $sender_domain,
9194: 'co-owners' => $coowners,
1.274 raeburn 9195: 'autofailsafe' => $failsafe,
1.1 raeburn 9196: }
9197: );
1.4 raeburn 9198: my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
9199: $dom);
1.1 raeburn 9200: if ($putresult eq 'ok') {
9201: if (exists($currautoenroll{'run'})) {
9202: if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
9203: $changes{'run'} = 1;
9204: }
9205: } elsif ($autorun) {
9206: if ($env{'form.autoenroll_run'} ne '1') {
1.23 raeburn 9207: $changes{'run'} = 1;
1.1 raeburn 9208: }
9209: }
1.17 raeburn 9210: if ($currautoenroll{'sender_uname'} ne $sender_uname) {
1.1 raeburn 9211: $changes{'sender'} = 1;
9212: }
1.17 raeburn 9213: if ($currautoenroll{'sender_domain'} ne $sender_domain) {
1.1 raeburn 9214: $changes{'sender'} = 1;
9215: }
1.129 raeburn 9216: if ($currautoenroll{'co-owners'} ne '') {
9217: if ($currautoenroll{'co-owners'} ne $coowners) {
9218: $changes{'coowners'} = 1;
9219: }
9220: } elsif ($coowners) {
9221: $changes{'coowners'} = 1;
1.274 raeburn 9222: }
9223: if ($currautoenroll{'autofailsafe'} ne $failsafe) {
9224: $changes{'autofailsafe'} = 1;
9225: }
1.1 raeburn 9226: if (keys(%changes) > 0) {
9227: $resulttext = &mt('Changes made:').'<ul>';
1.3 raeburn 9228: if ($changes{'run'}) {
1.1 raeburn 9229: $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
9230: }
9231: if ($changes{'sender'}) {
1.17 raeburn 9232: if ($sender_uname eq '' || $sender_domain eq '') {
9233: $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
9234: } else {
9235: $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
9236: }
1.1 raeburn 9237: }
1.129 raeburn 9238: if ($changes{'coowners'}) {
9239: $resulttext .= '<li>'.&mt("$title{'coowners'} set to $offon[$env{'form.autoassign_coowners'}]").'</li>';
9240: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 9241: if (ref($lastactref) eq 'HASH') {
9242: $lastactref->{'domainconfig'} = 1;
9243: }
1.129 raeburn 9244: }
1.274 raeburn 9245: if ($changes{'autofailsafe'}) {
9246: if ($failsafe ne '') {
9247: $resulttext .= '<li>'.&mt("$title{'failsafe'} set to [_1]",$failsafe).'</li>';
9248: } else {
9249: $resulttext .= '<li>'.&mt("$title{'failsafe'} deleted");
9250: }
9251: &Apache::lonnet::get_domain_defaults($dom,1);
9252: if (ref($lastactref) eq 'HASH') {
9253: $lastactref->{'domdefaults'} = 1;
9254: }
9255: }
1.1 raeburn 9256: $resulttext .= '</ul>';
9257: } else {
9258: $resulttext = &mt('No changes made to auto-enrollment settings');
9259: }
9260: } else {
1.11 albertel 9261: $resulttext = '<span class="LC_error">'.
9262: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 9263: }
1.3 raeburn 9264: return $resulttext;
1.1 raeburn 9265: }
9266:
9267: sub modify_autoupdate {
1.3 raeburn 9268: my ($dom,%domconfig) = @_;
1.1 raeburn 9269: my ($resulttext,%currautoupdate,%fields,%changes);
9270: if (ref($domconfig{'autoupdate'}) eq 'HASH') {
9271: foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
9272: $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
9273: }
9274: }
9275: my @offon = ('off','on');
9276: my %title = &Apache::lonlocal::texthash (
9277: run => 'Auto-update:',
9278: classlists => 'Updates to user information in classlists?'
9279: );
1.44 raeburn 9280: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 9281: my %fieldtitles = &Apache::lonlocal::texthash (
9282: id => 'Student/Employee ID',
1.20 raeburn 9283: permanentemail => 'E-mail address',
1.1 raeburn 9284: lastname => 'Last Name',
9285: firstname => 'First Name',
9286: middlename => 'Middle Name',
1.132 raeburn 9287: generation => 'Generation',
1.1 raeburn 9288: );
1.142 raeburn 9289: $othertitle = &mt('All users');
1.1 raeburn 9290: if (keys(%{$usertypes}) > 0) {
1.26 raeburn 9291: $othertitle = &mt('Other users');
1.1 raeburn 9292: }
9293: foreach my $key (keys(%env)) {
9294: if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
1.132 raeburn 9295: my ($usertype,$item) = ($1,$2);
9296: if (grep(/^\Q$item\E$/,keys(%fieldtitles))) {
9297: if ($usertype eq 'default') {
9298: push(@{$fields{$1}},$2);
9299: } elsif (ref($types) eq 'ARRAY') {
9300: if (grep(/^\Q$usertype\E$/,@{$types})) {
9301: push(@{$fields{$1}},$2);
9302: }
9303: }
9304: }
1.1 raeburn 9305: }
9306: }
1.131 raeburn 9307: my @lockablenames = &Apache::loncommon::get_env_multiple('form.lockablenames');
9308: @lockablenames = sort(@lockablenames);
9309: if (ref($currautoupdate{'lockablenames'}) eq 'ARRAY') {
9310: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
9311: if (@changed) {
9312: $changes{'lockablenames'} = 1;
9313: }
9314: } else {
9315: if (@lockablenames) {
9316: $changes{'lockablenames'} = 1;
9317: }
9318: }
1.1 raeburn 9319: my %updatehash = (
9320: autoupdate => { run => $env{'form.autoupdate_run'},
9321: classlists => $env{'form.classlists'},
9322: fields => {%fields},
1.131 raeburn 9323: lockablenames => \@lockablenames,
1.1 raeburn 9324: }
9325: );
9326: foreach my $key (keys(%currautoupdate)) {
9327: if (($key eq 'run') || ($key eq 'classlists')) {
9328: if (exists($updatehash{autoupdate}{$key})) {
9329: if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
9330: $changes{$key} = 1;
9331: }
9332: }
9333: } elsif ($key eq 'fields') {
9334: if (ref($currautoupdate{$key}) eq 'HASH') {
1.26 raeburn 9335: foreach my $item (@{$types},'default') {
1.1 raeburn 9336: if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
9337: my $change = 0;
9338: foreach my $type (@{$currautoupdate{$key}{$item}}) {
9339: if (!exists($fields{$item})) {
9340: $change = 1;
1.132 raeburn 9341: last;
1.1 raeburn 9342: } elsif (ref($fields{$item}) eq 'ARRAY') {
1.26 raeburn 9343: if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
1.1 raeburn 9344: $change = 1;
1.132 raeburn 9345: last;
1.1 raeburn 9346: }
9347: }
9348: }
9349: if ($change) {
9350: push(@{$changes{$key}},$item);
9351: }
1.26 raeburn 9352: }
1.1 raeburn 9353: }
9354: }
1.131 raeburn 9355: } elsif ($key eq 'lockablenames') {
9356: if (ref($currautoupdate{$key}) eq 'ARRAY') {
9357: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
9358: if (@changed) {
9359: $changes{'lockablenames'} = 1;
9360: }
9361: } else {
9362: if (@lockablenames) {
9363: $changes{'lockablenames'} = 1;
9364: }
9365: }
9366: }
9367: }
9368: unless (grep(/^\Qlockablenames\E$/,keys(%currautoupdate))) {
9369: if (@lockablenames) {
9370: $changes{'lockablenames'} = 1;
1.1 raeburn 9371: }
9372: }
1.26 raeburn 9373: foreach my $item (@{$types},'default') {
9374: if (defined($fields{$item})) {
9375: if (ref($currautoupdate{'fields'}) eq 'HASH') {
1.132 raeburn 9376: if (ref($currautoupdate{'fields'}{$item}) eq 'ARRAY') {
9377: my $change = 0;
9378: if (ref($fields{$item}) eq 'ARRAY') {
9379: foreach my $type (@{$fields{$item}}) {
9380: if (!grep(/^\Q$type\E$/,@{$currautoupdate{'fields'}{$item}})) {
9381: $change = 1;
9382: last;
9383: }
9384: }
9385: }
9386: if ($change) {
9387: push(@{$changes{'fields'}},$item);
9388: }
9389: } else {
1.26 raeburn 9390: push(@{$changes{'fields'}},$item);
9391: }
9392: } else {
9393: push(@{$changes{'fields'}},$item);
1.1 raeburn 9394: }
9395: }
9396: }
9397: my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
9398: $dom);
9399: if ($putresult eq 'ok') {
9400: if (keys(%changes) > 0) {
9401: $resulttext = &mt('Changes made:').'<ul>';
9402: foreach my $key (sort(keys(%changes))) {
1.131 raeburn 9403: if ($key eq 'lockablenames') {
9404: $resulttext .= '<li>';
9405: if (@lockablenames) {
9406: $usertypes->{'default'} = $othertitle;
9407: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update), available for the following affiliations:").' '.
9408: join(', ', map { $usertypes->{$_}; } @lockablenames).'</li>';
9409: } else {
9410: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update) is unavailable.");
9411: }
9412: $resulttext .= '</li>';
9413: } elsif (ref($changes{$key}) eq 'ARRAY') {
1.1 raeburn 9414: foreach my $item (@{$changes{$key}}) {
9415: my @newvalues;
9416: foreach my $type (@{$fields{$item}}) {
9417: push(@newvalues,$fieldtitles{$type});
9418: }
1.3 raeburn 9419: my $newvaluestr;
9420: if (@newvalues > 0) {
9421: $newvaluestr = join(', ',@newvalues);
9422: } else {
9423: $newvaluestr = &mt('none');
1.6 raeburn 9424: }
1.1 raeburn 9425: if ($item eq 'default') {
1.26 raeburn 9426: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
1.1 raeburn 9427: } else {
1.26 raeburn 9428: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
1.1 raeburn 9429: }
9430: }
9431: } else {
9432: my $newvalue;
9433: if ($key eq 'run') {
9434: $newvalue = $offon[$env{'form.autoupdate_run'}];
9435: } else {
9436: $newvalue = $offon[$env{'form.'.$key}];
1.3 raeburn 9437: }
1.1 raeburn 9438: $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
9439: }
9440: }
9441: $resulttext .= '</ul>';
9442: } else {
1.3 raeburn 9443: $resulttext = &mt('No changes made to autoupdates');
1.1 raeburn 9444: }
9445: } else {
1.11 albertel 9446: $resulttext = '<span class="LC_error">'.
9447: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 9448: }
1.3 raeburn 9449: return $resulttext;
1.1 raeburn 9450: }
9451:
1.125 raeburn 9452: sub modify_autocreate {
9453: my ($dom,%domconfig) = @_;
9454: my ($resulttext,%changes,%currautocreate,%newvals,%autocreatehash);
9455: if (ref($domconfig{'autocreate'}) eq 'HASH') {
9456: foreach my $key (keys(%{$domconfig{'autocreate'}})) {
9457: $currautocreate{$key} = $domconfig{'autocreate'}{$key};
9458: }
9459: }
9460: my %title= ( xml => 'Auto-creation of courses in XML course description files',
9461: req => 'Auto-creation of validated requests for official courses',
9462: xmldc => 'Identity of course creator of courses from XML files',
9463: );
9464: my @types = ('xml','req');
9465: foreach my $item (@types) {
9466: $newvals{$item} = $env{'form.autocreate_'.$item};
9467: $newvals{$item} =~ s/\D//g;
9468: $newvals{$item} = 0 if ($newvals{$item} eq '');
9469: }
9470: $newvals{'xmldc'} = $env{'form.autocreate_xmldc'};
9471: my %domcoords = &get_active_dcs($dom);
9472: unless (exists($domcoords{$newvals{'xmldc'}})) {
9473: $newvals{'xmldc'} = '';
9474: }
9475: %autocreatehash = (
9476: autocreate => { xml => $newvals{'xml'},
9477: req => $newvals{'req'},
9478: }
9479: );
9480: if ($newvals{'xmldc'} ne '') {
9481: $autocreatehash{'autocreate'}{'xmldc'} = $newvals{'xmldc'};
9482: }
9483: my $putresult = &Apache::lonnet::put_dom('configuration',\%autocreatehash,
9484: $dom);
9485: if ($putresult eq 'ok') {
9486: my @items = @types;
9487: if ($newvals{'xml'}) {
9488: push(@items,'xmldc');
9489: }
9490: foreach my $item (@items) {
9491: if (exists($currautocreate{$item})) {
9492: if ($currautocreate{$item} ne $newvals{$item}) {
9493: $changes{$item} = 1;
9494: }
9495: } elsif ($newvals{$item}) {
9496: $changes{$item} = 1;
9497: }
9498: }
9499: if (keys(%changes) > 0) {
9500: my @offon = ('off','on');
9501: $resulttext = &mt('Changes made:').'<ul>';
9502: foreach my $item (@types) {
9503: if ($changes{$item}) {
9504: my $newtxt = $offon[$newvals{$item}];
1.178 raeburn 9505: $resulttext .= '<li>'.
9506: &mt("$title{$item} set to [_1]$newtxt [_2]",
9507: '<b>','</b>').
9508: '</li>';
1.125 raeburn 9509: }
9510: }
9511: if ($changes{'xmldc'}) {
9512: my ($dcname,$dcdom) = split(':',$newvals{'xmldc'});
9513: my $newtxt = &Apache::loncommon::plainname($dcname,$dcdom);
1.178 raeburn 9514: $resulttext .= '<li>'.&mt("$title{'xmldc'} set to [_1]",'<b>'.$newtxt.'</b>').'</li>';
1.125 raeburn 9515: }
9516: $resulttext .= '</ul>';
9517: } else {
9518: $resulttext = &mt('No changes made to auto-creation settings');
9519: }
9520: } else {
9521: $resulttext = '<span class="LC_error">'.
9522: &mt('An error occurred: [_1]',$putresult).'</span>';
9523: }
9524: return $resulttext;
9525: }
9526:
1.23 raeburn 9527: sub modify_directorysrch {
9528: my ($dom,%domconfig) = @_;
9529: my ($resulttext,%changes);
9530: my %currdirsrch;
9531: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
9532: foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
9533: $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
9534: }
9535: }
1.277 ! raeburn 9536: my %title = ( available => 'Institutional directory search available',
! 9537: localonly => 'Other domains can search institution',
! 9538: lcavailable => 'LON-CAPA directory search available',
! 9539: lclocalonly => 'Other domains can search LON-CAPA domain',
1.23 raeburn 9540: searchby => 'Search types',
9541: searchtypes => 'Search latitude');
9542: my @offon = ('off','on');
1.24 raeburn 9543: my @otherdoms = ('Yes','No');
1.23 raeburn 9544:
1.25 raeburn 9545: my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');
1.23 raeburn 9546: my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
9547: my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
9548:
1.44 raeburn 9549: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.26 raeburn 9550: if (keys(%{$usertypes}) == 0) {
9551: @cansearch = ('default');
9552: } else {
9553: if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
9554: foreach my $type (@{$currdirsrch{'cansearch'}}) {
9555: if (!grep(/^\Q$type\E$/,@cansearch)) {
9556: push(@{$changes{'cansearch'}},$type);
9557: }
1.23 raeburn 9558: }
1.26 raeburn 9559: foreach my $type (@cansearch) {
9560: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
9561: push(@{$changes{'cansearch'}},$type);
9562: }
1.23 raeburn 9563: }
1.26 raeburn 9564: } else {
9565: push(@{$changes{'cansearch'}},@cansearch);
1.23 raeburn 9566: }
9567: }
9568:
9569: if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
9570: foreach my $by (@{$currdirsrch{'searchby'}}) {
9571: if (!grep(/^\Q$by\E$/,@searchby)) {
9572: push(@{$changes{'searchby'}},$by);
9573: }
9574: }
9575: foreach my $by (@searchby) {
9576: if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
9577: push(@{$changes{'searchby'}},$by);
9578: }
9579: }
9580: } else {
9581: push(@{$changes{'searchby'}},@searchby);
9582: }
1.25 raeburn 9583:
9584: if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
9585: foreach my $type (@{$currdirsrch{'searchtypes'}}) {
9586: if (!grep(/^\Q$type\E$/,@searchtypes)) {
9587: push(@{$changes{'searchtypes'}},$type);
9588: }
9589: }
9590: foreach my $type (@searchtypes) {
9591: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
9592: push(@{$changes{'searchtypes'}},$type);
9593: }
9594: }
9595: } else {
9596: if (exists($currdirsrch{'searchtypes'})) {
9597: foreach my $type (@searchtypes) {
9598: if ($type ne $currdirsrch{'searchtypes'}) {
9599: push(@{$changes{'searchtypes'}},$type);
9600: }
9601: }
9602: if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
9603: push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
9604: }
9605: } else {
9606: push(@{$changes{'searchtypes'}},@searchtypes);
9607: }
9608: }
9609:
1.23 raeburn 9610: my %dirsrch_hash = (
9611: directorysrch => { available => $env{'form.dirsrch_available'},
9612: cansearch => \@cansearch,
1.277 ! raeburn 9613: localonly => $env{'form.dirsrch_instlocalonly'},
! 9614: lclocalonly => $env{'form.dirsrch_domlocalonly'},
! 9615: lcavailable => $env{'form.dirsrch_domavailable'},
1.23 raeburn 9616: searchby => \@searchby,
1.25 raeburn 9617: searchtypes => \@searchtypes,
1.23 raeburn 9618: }
9619: );
9620: my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
9621: $dom);
9622: if ($putresult eq 'ok') {
9623: if (exists($currdirsrch{'available'})) {
9624: if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
9625: $changes{'available'} = 1;
9626: }
9627: } else {
9628: if ($env{'form.dirsrch_available'} eq '1') {
9629: $changes{'available'} = 1;
9630: }
9631: }
1.277 ! raeburn 9632: if (exists($currdirsrch{'lcavailable'})) {
! 9633: if ($currdirsrch{'lcavailable'} ne $env{'form.dirsrch_domavailable'}) {
! 9634: $changes{'lcavailable'} = 1;
! 9635: }
! 9636: } else {
! 9637: if ($env{'form.dirsrch_lcavailable'} eq '1') {
! 9638: $changes{'lcavailable'} = 1;
! 9639: }
! 9640: }
1.24 raeburn 9641: if (exists($currdirsrch{'localonly'})) {
1.277 ! raeburn 9642: if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_instlocalonly'}) {
1.24 raeburn 9643: $changes{'localonly'} = 1;
9644: }
9645: } else {
1.277 ! raeburn 9646: if ($env{'form.dirsrch_instlocalonly'} eq '1') {
1.24 raeburn 9647: $changes{'localonly'} = 1;
9648: }
9649: }
1.277 ! raeburn 9650: if (exists($currdirsrch{'lclocalonly'})) {
! 9651: if ($currdirsrch{'lclocalonly'} ne $env{'form.dirsrch_domlocalonly'}) {
! 9652: $changes{'lclocalonly'} = 1;
! 9653: }
! 9654: } else {
! 9655: if ($env{'form.dirsrch_domlocalonly'} eq '1') {
! 9656: $changes{'lclocalonly'} = 1;
! 9657: }
! 9658: }
1.23 raeburn 9659: if (keys(%changes) > 0) {
9660: $resulttext = &mt('Changes made:').'<ul>';
9661: if ($changes{'available'}) {
9662: $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
9663: }
1.277 ! raeburn 9664: if ($changes{'lcavailable'}) {
! 9665: $resulttext .= '<li>'.&mt("$title{'lcavailable'} set to: $offon[$env{'form.dirsrch_domavailable'}]").'</li>';
! 9666: }
1.24 raeburn 9667: if ($changes{'localonly'}) {
1.277 ! raeburn 9668: $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_instlocalonly'}]").'</li>';
1.24 raeburn 9669: }
1.277 ! raeburn 9670: if ($changes{'lclocalonly'}) {
! 9671: $resulttext .= '<li>'.&mt("$title{'lclocalonly'} set to: $otherdoms[$env{'form.dirsrch_domlocalonly'}]").'</li>';
! 9672: }
1.23 raeburn 9673: if (ref($changes{'cansearch'}) eq 'ARRAY') {
9674: my $chgtext;
1.26 raeburn 9675: if (ref($usertypes) eq 'HASH') {
9676: if (keys(%{$usertypes}) > 0) {
9677: foreach my $type (@{$types}) {
9678: if (grep(/^\Q$type\E$/,@cansearch)) {
9679: $chgtext .= $usertypes->{$type}.'; ';
9680: }
9681: }
9682: if (grep(/^default$/,@cansearch)) {
9683: $chgtext .= $othertitle;
9684: } else {
9685: $chgtext =~ s/\; $//;
9686: }
1.210 raeburn 9687: $resulttext .=
1.178 raeburn 9688: '<li>'.
9689: &mt("Users from domain '[_1]' permitted to search the institutional directory set to: [_2]",
9690: '<span class="LC_cusr_emph">'.$dom.'</span>',$chgtext).
9691: '</li>';
1.23 raeburn 9692: }
9693: }
9694: }
9695: if (ref($changes{'searchby'}) eq 'ARRAY') {
9696: my ($searchtitles,$titleorder) = &sorted_searchtitles();
9697: my $chgtext;
9698: foreach my $type (@{$titleorder}) {
9699: if (grep(/^\Q$type\E$/,@searchby)) {
9700: if (defined($searchtitles->{$type})) {
9701: $chgtext .= $searchtitles->{$type}.'; ';
9702: }
9703: }
9704: }
9705: $chgtext =~ s/\; $//;
9706: $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
9707: }
1.25 raeburn 9708: if (ref($changes{'searchtypes'}) eq 'ARRAY') {
9709: my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes();
9710: my $chgtext;
9711: foreach my $type (@{$srchtypeorder}) {
9712: if (grep(/^\Q$type\E$/,@searchtypes)) {
9713: if (defined($srchtypes_desc->{$type})) {
9714: $chgtext .= $srchtypes_desc->{$type}.'; ';
9715: }
9716: }
9717: }
9718: $chgtext =~ s/\; $//;
1.178 raeburn 9719: $resulttext .= '<li>'.&mt($title{'searchtypes'}.' set to: "[_1]"',$chgtext).'</li>';
1.23 raeburn 9720: }
9721: $resulttext .= '</ul>';
9722: } else {
1.277 ! raeburn 9723: $resulttext = &mt('No changes made to directory search settings');
1.23 raeburn 9724: }
9725: } else {
9726: $resulttext = '<span class="LC_error">'.
1.27 raeburn 9727: &mt('An error occurred: [_1]',$putresult).'</span>';
9728: }
9729: return $resulttext;
9730: }
9731:
1.28 raeburn 9732: sub modify_contacts {
1.205 raeburn 9733: my ($dom,$lastactref,%domconfig) = @_;
1.28 raeburn 9734: my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
9735: if (ref($domconfig{'contacts'}) eq 'HASH') {
9736: foreach my $key (keys(%{$domconfig{'contacts'}})) {
9737: $currsetting{$key} = $domconfig{'contacts'}{$key};
9738: }
9739: }
1.134 raeburn 9740: my (%others,%to,%bcc);
1.28 raeburn 9741: my @contacts = ('supportemail','adminemail');
1.102 raeburn 9742: my @mailings = ('errormail','packagesmail','helpdeskmail','lonstatusmail',
1.203 raeburn 9743: 'requestsmail','updatesmail','idconflictsmail');
9744: my @toggles = ('reporterrors','reportupdates');
1.28 raeburn 9745: foreach my $type (@mailings) {
9746: @{$newsetting{$type}} =
9747: &Apache::loncommon::get_env_multiple('form.'.$type);
9748: foreach my $item (@contacts) {
9749: if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
9750: $contacts_hash{contacts}{$type}{$item} = 1;
9751: } else {
9752: $contacts_hash{contacts}{$type}{$item} = 0;
9753: }
9754: }
9755: $others{$type} = $env{'form.'.$type.'_others'};
9756: $contacts_hash{contacts}{$type}{'others'} = $others{$type};
1.134 raeburn 9757: if ($type eq 'helpdeskmail') {
9758: $bcc{$type} = $env{'form.'.$type.'_bcc'};
9759: $contacts_hash{contacts}{$type}{'bcc'} = $bcc{$type};
9760: }
1.28 raeburn 9761: }
9762: foreach my $item (@contacts) {
9763: $to{$item} = $env{'form.'.$item};
9764: $contacts_hash{'contacts'}{$item} = $to{$item};
9765: }
1.203 raeburn 9766: foreach my $item (@toggles) {
9767: if ($env{'form.'.$item} =~ /^(0|1)$/) {
9768: $contacts_hash{'contacts'}{$item} = $env{'form.'.$item};
9769: }
9770: }
1.28 raeburn 9771: if (keys(%currsetting) > 0) {
9772: foreach my $item (@contacts) {
9773: if ($to{$item} ne $currsetting{$item}) {
9774: $changes{$item} = 1;
9775: }
9776: }
9777: foreach my $type (@mailings) {
9778: foreach my $item (@contacts) {
9779: if (ref($currsetting{$type}) eq 'HASH') {
9780: if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
9781: push(@{$changes{$type}},$item);
9782: }
9783: } else {
9784: push(@{$changes{$type}},@{$newsetting{$type}});
9785: }
9786: }
9787: if ($others{$type} ne $currsetting{$type}{'others'}) {
9788: push(@{$changes{$type}},'others');
9789: }
1.134 raeburn 9790: if ($type eq 'helpdeskmail') {
9791: if ($bcc{$type} ne $currsetting{$type}{'bcc'}) {
9792: push(@{$changes{$type}},'bcc');
9793: }
9794: }
1.28 raeburn 9795: }
9796: } else {
9797: my %default;
9798: $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
9799: $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
9800: $default{'errormail'} = 'adminemail';
9801: $default{'packagesmail'} = 'adminemail';
9802: $default{'helpdeskmail'} = 'supportemail';
1.89 raeburn 9803: $default{'lonstatusmail'} = 'adminemail';
1.102 raeburn 9804: $default{'requestsmail'} = 'adminemail';
1.190 raeburn 9805: $default{'updatesmail'} = 'adminemail';
1.28 raeburn 9806: foreach my $item (@contacts) {
9807: if ($to{$item} ne $default{$item}) {
9808: $changes{$item} = 1;
1.203 raeburn 9809: }
1.28 raeburn 9810: }
9811: foreach my $type (@mailings) {
9812: if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
9813:
9814: push(@{$changes{$type}},@{$newsetting{$type}});
9815: }
9816: if ($others{$type} ne '') {
9817: push(@{$changes{$type}},'others');
1.134 raeburn 9818: }
9819: if ($type eq 'helpdeskmail') {
9820: if ($bcc{$type} ne '') {
9821: push(@{$changes{$type}},'bcc');
9822: }
9823: }
1.28 raeburn 9824: }
9825: }
1.203 raeburn 9826: foreach my $item (@toggles) {
9827: if (($env{'form.'.$item} == 1) && ($currsetting{$item} == 0)) {
9828: $changes{$item} = 1;
9829: } elsif ((!$env{'form.'.$item}) &&
9830: (($currsetting{$item} eq '') || ($currsetting{$item} == 1))) {
9831: $changes{$item} = 1;
9832: }
9833: }
1.28 raeburn 9834: my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
9835: $dom);
9836: if ($putresult eq 'ok') {
9837: if (keys(%changes) > 0) {
1.205 raeburn 9838: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 9839: if (ref($lastactref) eq 'HASH') {
9840: $lastactref->{'domainconfig'} = 1;
9841: }
1.28 raeburn 9842: my ($titles,$short_titles) = &contact_titles();
9843: $resulttext = &mt('Changes made:').'<ul>';
9844: foreach my $item (@contacts) {
9845: if ($changes{$item}) {
9846: $resulttext .= '<li>'.$titles->{$item}.
9847: &mt(' set to: ').
9848: '<span class="LC_cusr_emph">'.
9849: $to{$item}.'</span></li>';
9850: }
9851: }
9852: foreach my $type (@mailings) {
9853: if (ref($changes{$type}) eq 'ARRAY') {
9854: $resulttext .= '<li>'.$titles->{$type}.': ';
9855: my @text;
9856: foreach my $item (@{$newsetting{$type}}) {
9857: push(@text,$short_titles->{$item});
9858: }
9859: if ($others{$type} ne '') {
9860: push(@text,$others{$type});
9861: }
9862: $resulttext .= '<span class="LC_cusr_emph">'.
1.134 raeburn 9863: join(', ',@text).'</span>';
9864: if ($type eq 'helpdeskmail') {
9865: if ($bcc{$type} ne '') {
9866: $resulttext .= ' '.&mt('with Bcc to').': <span class="LC_cusr_emph">'.$bcc{$type}.'</span>';
9867: }
9868: }
9869: $resulttext .= '</li>';
1.28 raeburn 9870: }
9871: }
1.203 raeburn 9872: my @offon = ('off','on');
9873: if ($changes{'reporterrors'}) {
9874: $resulttext .= '<li>'.
9875: &mt('E-mail error reports to [_1] set to "'.
9876: $offon[$env{'form.reporterrors'}].'".',
9877: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
9878: &mt('LON-CAPA core group - MSU'),600,500)).
9879: '</li>';
9880: }
9881: if ($changes{'reportupdates'}) {
9882: $resulttext .= '<li>'.
9883: &mt('E-mail record of completed LON-CAPA updates to [_1] set to "'.
9884: $offon[$env{'form.reportupdates'}].'".',
9885: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
9886: &mt('LON-CAPA core group - MSU'),600,500)).
9887: '</li>';
9888: }
1.28 raeburn 9889: $resulttext .= '</ul>';
9890: } else {
1.34 raeburn 9891: $resulttext = &mt('No changes made to contact information');
1.28 raeburn 9892: }
9893: } else {
9894: $resulttext = '<span class="LC_error">'.
9895: &mt('An error occurred: [_1].',$putresult).'</span>';
9896: }
9897: return $resulttext;
9898: }
9899:
9900: sub modify_usercreation {
1.27 raeburn 9901: my ($dom,%domconfig) = @_;
1.224 raeburn 9902: my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate,%save_usercreate);
1.43 raeburn 9903: my $warningmsg;
1.27 raeburn 9904: if (ref($domconfig{'usercreation'}) eq 'HASH') {
9905: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
1.224 raeburn 9906: if ($key eq 'cancreate') {
9907: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
9908: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
9909: if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
1.269 raeburn 9910: ($item eq 'captcha') || ($item eq 'recaptchakeys') ||
9911: ($item eq 'recaptchaversion')) {
1.224 raeburn 9912: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
9913: } else {
9914: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
9915: }
9916: }
9917: }
9918: } elsif ($key eq 'email_rule') {
9919: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
9920: } else {
9921: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
9922: }
1.27 raeburn 9923: }
9924: }
9925: my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
1.32 raeburn 9926: my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
1.224 raeburn 9927: my @contexts = ('author','course','requestcrs');
1.34 raeburn 9928: foreach my $item(@contexts) {
1.224 raeburn 9929: $cancreate{$item} = $env{'form.can_createuser_'.$item};
1.93 raeburn 9930: }
1.34 raeburn 9931: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
9932: foreach my $item (@contexts) {
1.224 raeburn 9933: if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
9934: push(@{$changes{'cancreate'}},$item);
1.50 raeburn 9935: }
1.27 raeburn 9936: }
1.34 raeburn 9937: } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
9938: foreach my $item (@contexts) {
1.43 raeburn 9939: if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
1.34 raeburn 9940: if ($cancreate{$item} ne 'any') {
9941: push(@{$changes{'cancreate'}},$item);
9942: }
9943: } else {
9944: if ($cancreate{$item} ne 'none') {
9945: push(@{$changes{'cancreate'}},$item);
9946: }
1.27 raeburn 9947: }
9948: }
9949: } else {
1.43 raeburn 9950: foreach my $item (@contexts) {
1.34 raeburn 9951: push(@{$changes{'cancreate'}},$item);
9952: }
1.27 raeburn 9953: }
1.34 raeburn 9954:
1.27 raeburn 9955: if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
9956: foreach my $type (@{$curr_usercreation{'username_rule'}}) {
9957: if (!grep(/^\Q$type\E$/,@username_rule)) {
9958: push(@{$changes{'username_rule'}},$type);
9959: }
9960: }
9961: foreach my $type (@username_rule) {
9962: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
9963: push(@{$changes{'username_rule'}},$type);
9964: }
9965: }
9966: } else {
9967: push(@{$changes{'username_rule'}},@username_rule);
9968: }
9969:
1.32 raeburn 9970: if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
9971: foreach my $type (@{$curr_usercreation{'id_rule'}}) {
9972: if (!grep(/^\Q$type\E$/,@id_rule)) {
9973: push(@{$changes{'id_rule'}},$type);
9974: }
9975: }
9976: foreach my $type (@id_rule) {
9977: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
9978: push(@{$changes{'id_rule'}},$type);
9979: }
9980: }
9981: } else {
9982: push(@{$changes{'id_rule'}},@id_rule);
9983: }
9984:
1.43 raeburn 9985: my @authen_contexts = ('author','course','domain');
1.28 raeburn 9986: my @authtypes = ('int','krb4','krb5','loc');
9987: my %authhash;
1.43 raeburn 9988: foreach my $item (@authen_contexts) {
1.28 raeburn 9989: my @authallowed = &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
9990: foreach my $auth (@authtypes) {
9991: if (grep(/^\Q$auth\E$/,@authallowed)) {
9992: $authhash{$item}{$auth} = 1;
9993: } else {
9994: $authhash{$item}{$auth} = 0;
9995: }
9996: }
9997: }
9998: if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
1.43 raeburn 9999: foreach my $item (@authen_contexts) {
1.28 raeburn 10000: if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
10001: foreach my $auth (@authtypes) {
10002: if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
10003: push(@{$changes{'authtypes'}},$item);
10004: last;
10005: }
10006: }
10007: }
10008: }
10009: } else {
1.43 raeburn 10010: foreach my $item (@authen_contexts) {
1.28 raeburn 10011: push(@{$changes{'authtypes'}},$item);
10012: }
10013: }
10014:
1.224 raeburn 10015: $save_usercreate{'cancreate'}{'course'} = $cancreate{'course'};
10016: $save_usercreate{'cancreate'}{'author'} = $cancreate{'author'};
10017: $save_usercreate{'cancreate'}{'requestcrs'} = $cancreate{'requestcrs'};
10018: $save_usercreate{'id_rule'} = \@id_rule;
10019: $save_usercreate{'username_rule'} = \@username_rule,
10020: $save_usercreate{'authtypes'} = \%authhash;
10021:
1.27 raeburn 10022: my %usercreation_hash = (
1.224 raeburn 10023: usercreation => \%save_usercreate,
10024: );
1.27 raeburn 10025:
10026: my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
10027: $dom);
1.50 raeburn 10028:
1.224 raeburn 10029: if ($putresult eq 'ok') {
10030: if (keys(%changes) > 0) {
10031: $resulttext = &mt('Changes made:').'<ul>';
10032: if (ref($changes{'cancreate'}) eq 'ARRAY') {
10033: my %lt = &usercreation_types();
10034: foreach my $type (@{$changes{'cancreate'}}) {
10035: my $chgtext = $lt{$type}.', ';
10036: if ($cancreate{$type} eq 'none') {
10037: $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
10038: } elsif ($cancreate{$type} eq 'any') {
10039: $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
10040: } elsif ($cancreate{$type} eq 'official') {
10041: $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
10042: } elsif ($cancreate{$type} eq 'unofficial') {
10043: $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
10044: }
10045: $resulttext .= '<li>'.$chgtext.'</li>';
10046: }
10047: }
10048: if (ref($changes{'username_rule'}) eq 'ARRAY') {
10049: my ($rules,$ruleorder) =
10050: &Apache::lonnet::inst_userrules($dom,'username');
10051: my $chgtext = '<ul>';
10052: foreach my $type (@username_rule) {
10053: if (ref($rules->{$type}) eq 'HASH') {
10054: $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
10055: }
10056: }
10057: $chgtext .= '</ul>';
10058: if (@username_rule > 0) {
10059: $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
10060: } else {
10061: $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>';
10062: }
10063: }
10064: if (ref($changes{'id_rule'}) eq 'ARRAY') {
10065: my ($idrules,$idruleorder) =
10066: &Apache::lonnet::inst_userrules($dom,'id');
10067: my $chgtext = '<ul>';
10068: foreach my $type (@id_rule) {
10069: if (ref($idrules->{$type}) eq 'HASH') {
10070: $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
10071: }
10072: }
10073: $chgtext .= '</ul>';
10074: if (@id_rule > 0) {
10075: $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
10076: } else {
10077: $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
10078: }
10079: }
10080: my %authname = &authtype_names();
10081: my %context_title = &context_names();
10082: if (ref($changes{'authtypes'}) eq 'ARRAY') {
10083: my $chgtext = '<ul>';
10084: foreach my $type (@{$changes{'authtypes'}}) {
10085: my @allowed;
10086: $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
10087: foreach my $auth (@authtypes) {
10088: if ($authhash{$type}{$auth}) {
10089: push(@allowed,$authname{$auth});
10090: }
10091: }
10092: if (@allowed > 0) {
10093: $chgtext .= join(', ',@allowed).'</li>';
10094: } else {
10095: $chgtext .= &mt('none').'</li>';
10096: }
10097: }
10098: $chgtext .= '</ul>';
10099: $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
10100: $resulttext .= '</li>';
10101: }
10102: $resulttext .= '</ul>';
10103: } else {
10104: $resulttext = &mt('No changes made to user creation settings');
10105: }
10106: } else {
10107: $resulttext = '<span class="LC_error">'.
10108: &mt('An error occurred: [_1]',$putresult).'</span>';
10109: }
10110: if ($warningmsg ne '') {
10111: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
10112: }
10113: return $resulttext;
10114: }
10115:
10116: sub modify_selfcreation {
10117: my ($dom,%domconfig) = @_;
10118: my ($resulttext,$warningmsg,%curr_usercreation,%curr_usermodify,%changes,%cancreate);
10119: my (%save_usercreate,%save_usermodify);
1.228 raeburn 10120: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
10121: if (ref($types) eq 'ARRAY') {
10122: $usertypes->{'default'} = $othertitle;
10123: push(@{$types},'default');
10124: }
1.224 raeburn 10125: #
10126: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usercreation'}.
10127: #
10128: if (ref($domconfig{'usercreation'}) eq 'HASH') {
10129: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
10130: if ($key eq 'cancreate') {
10131: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
10132: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
10133: if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
10134: ($item eq 'captcha') || ($item eq 'recaptchakeys') ||
1.269 raeburn 10135: ($item eq 'recaptchaversion') ||
1.236 raeburn 10136: ($item eq 'emailusername') || ($item eq 'notify') ||
1.240 raeburn 10137: ($item eq 'selfcreateprocessing') || ($item eq 'shibenv')) {
1.224 raeburn 10138: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
10139: } else {
10140: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
10141: }
10142: }
10143: }
10144: } elsif ($key eq 'email_rule') {
10145: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
10146: } else {
10147: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
10148: }
10149: }
10150: }
10151: #
10152: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usermodification'}.
10153: #
10154: if (ref($domconfig{'usermodification'}) eq 'HASH') {
10155: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
10156: if ($key eq 'selfcreate') {
10157: $curr_usermodify{$key} = $domconfig{'usermodification'}{$key};
10158: } else {
10159: $save_usermodify{$key} = $domconfig{'usermodification'}{$key};
10160: }
10161: }
10162: }
10163:
10164: my @contexts = ('selfcreate');
10165: @{$cancreate{'selfcreate'}} = ();
10166: %{$cancreate{'emailusername'}} = ();
10167: @{$cancreate{'statustocreate'}} = ();
1.236 raeburn 10168: %{$cancreate{'selfcreateprocessing'}} = ();
1.240 raeburn 10169: %{$cancreate{'shibenv'}} = ();
1.50 raeburn 10170: my %selfcreatetypes = (
10171: sso => 'users authenticated by institutional single sign on',
10172: login => 'users authenticated by institutional log-in',
1.236 raeburn 10173: email => 'users who provide a valid e-mail address for use as username',
1.50 raeburn 10174: );
1.224 raeburn 10175: #
10176: # Populate $cancreate{'selfcreate'} array reference with types of user, for which self-creation of user accounts
10177: # is permitted.
10178: #
1.236 raeburn 10179:
10180: my @statuses;
10181: if (ref($domconfig{'inststatus'}) eq 'HASH') {
10182: if (ref($domconfig{'inststatus'}{'inststatusguest'}) eq 'ARRAY') {
10183: @statuses = @{$domconfig{'inststatus'}{'inststatusguest'}};
10184: }
10185: }
10186: push(@statuses,'default');
10187:
1.228 raeburn 10188: foreach my $item ('login','sso','email') {
1.224 raeburn 10189: if ($item eq 'email') {
1.236 raeburn 10190: if ($env{'form.cancreate_email'}) {
1.224 raeburn 10191: push(@{$cancreate{'selfcreate'}},'email');
1.236 raeburn 10192: push(@contexts,'selfcreateprocessing');
10193: foreach my $type (@statuses) {
10194: if ($type eq 'default') {
10195: $cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess'};
10196: } else {
10197: $cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess_'.$type};
10198: }
10199: }
1.224 raeburn 10200: }
10201: } else {
10202: if ($env{'form.cancreate_'.$item}) {
10203: push(@{$cancreate{'selfcreate'}},$item);
10204: }
10205: }
10206: }
10207: my (@email_rule,%userinfo,%savecaptcha);
10208: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
10209: #
1.228 raeburn 10210: # Populate $cancreate{'emailusername'}{$type} hash ref with information fields (if new user will provide data
10211: # value set to one), if self-creation with e-mail address permitted, where $type is user type: faculty, staff, student etc.
1.224 raeburn 10212: #
1.236 raeburn 10213:
1.244 raeburn 10214: if ($env{'form.cancreate_email'}) {
1.228 raeburn 10215: push(@contexts,'emailusername');
10216: if (ref($types) eq 'ARRAY') {
10217: foreach my $type (@{$types}) {
10218: if (ref($infofields) eq 'ARRAY') {
10219: foreach my $field (@{$infofields}) {
10220: if ($env{'form.canmodify_emailusername_'.$type.'_'.$field} =~ /^(required|optional)$/) {
10221: $cancreate{'emailusername'}{$type}{$field} = $1;
10222: }
10223: }
1.224 raeburn 10224: }
10225: }
10226: }
10227: #
10228: # Populate $cancreate{'notify'} hash ref with names of Domain Coordinators who are to be notified of
10229: # queued requests for self-creation of account using e-mail address as username
10230: #
10231:
10232: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.selfcreationnotifyapproval');
10233: @approvalnotify = sort(@approvalnotify);
10234: $cancreate{'notify'}{'approval'} = join(',',@approvalnotify);
10235: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
10236: if (ref($curr_usercreation{'cancreate'}{'notify'}) eq 'HASH') {
10237: if ($curr_usercreation{'cancreate'}{'notify'}{'approval'} ne $cancreate{'notify'}{'approval'}) {
10238: push(@{$changes{'cancreate'}},'notify');
10239: }
10240: } else {
10241: if ($cancreate{'notify'}{'approval'}) {
10242: push(@{$changes{'cancreate'}},'notify');
10243: }
10244: }
10245: } elsif ($cancreate{'notify'}{'approval'}) {
10246: push(@{$changes{'cancreate'}},'notify');
10247: }
10248:
10249: #
10250: # Retrieve rules (if any) governing types of e-mail address which may be used as a username
10251: #
10252: @email_rule = &Apache::loncommon::get_env_multiple('form.email_rule');
10253: &process_captcha('cancreate',\%changes,\%savecaptcha,$curr_usercreation{'cancreate'});
10254: if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
10255: if (@{$curr_usercreation{'email_rule'}} > 0) {
10256: foreach my $type (@{$curr_usercreation{'email_rule'}}) {
10257: if (!grep(/^\Q$type\E$/,@email_rule)) {
10258: push(@{$changes{'email_rule'}},$type);
10259: }
10260: }
10261: }
10262: if (@email_rule > 0) {
10263: foreach my $type (@email_rule) {
10264: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'email_rule'}})) {
10265: push(@{$changes{'email_rule'}},$type);
10266: }
10267: }
10268: }
10269: } elsif (@email_rule > 0) {
10270: push(@{$changes{'email_rule'}},@email_rule);
10271: }
10272: }
10273: #
1.236 raeburn 10274: # Check if domain default is set appropriately, if self-creation of accounts is to be available for
1.224 raeburn 10275: # institutional log-in.
10276: #
10277: if (grep(/^login$/,@{$cancreate{'selfcreate'}})) {
10278: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
10279: if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) ||
10280: ($domdefaults{'auth_def'} eq 'localauth'))) {
10281: $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.').' '.
10282: &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.');
10283: }
10284: }
10285: my @fields = ('lastname','firstname','middlename','generation',
10286: 'permanentemail','id');
1.240 raeburn 10287: my @shibfields = (@fields,'inststatus');
1.224 raeburn 10288: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
10289: #
10290: # Where usernames may created for institutional log-in and/or institutional single sign on:
10291: # (a) populate $cancreate{'statustocreate'} array reference with institutional status types who
10292: # may self-create accounts
10293: # (b) populate $save_usermodify{'selfcreate'} hash reference with status types, and information fields
10294: # which the user may supply, if institutional data is unavailable.
10295: #
10296: if (($env{'form.cancreate_login'}) || ($env{'form.cancreate_sso'})) {
10297: if (ref($types) eq 'ARRAY') {
1.228 raeburn 10298: if (@{$types} > 1) {
1.224 raeburn 10299: @{$cancreate{'statustocreate'}} = &Apache::loncommon::get_env_multiple('form.statustocreate');
10300: push(@contexts,'statustocreate');
10301: } else {
10302: undef($cancreate{'statustocreate'});
10303: }
10304: foreach my $type (@{$types}) {
10305: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$type);
10306: foreach my $field (@fields) {
10307: if (grep(/^\Q$field\E$/,@modifiable)) {
10308: $save_usermodify{'selfcreate'}{$type}{$field} = 1;
10309: } else {
10310: $save_usermodify{'selfcreate'}{$type}{$field} = 0;
10311: }
10312: }
10313: }
10314: if (ref($curr_usermodify{'selfcreate'}) eq 'HASH') {
10315: foreach my $type (@{$types}) {
10316: if (ref($curr_usermodify{'selfcreate'}{$type}) eq 'HASH') {
10317: foreach my $field (@fields) {
10318: if ($save_usermodify{'selfcreate'}{$type}{$field} ne
10319: $curr_usermodify{'selfcreate'}{$type}{$field}) {
10320: push(@{$changes{'selfcreate'}},$type);
10321: last;
10322: }
10323: }
10324: }
10325: }
10326: } else {
10327: foreach my $type (@{$types}) {
10328: push(@{$changes{'selfcreate'}},$type);
10329: }
10330: }
10331: }
1.240 raeburn 10332: foreach my $field (@shibfields) {
10333: if ($env{'form.shibenv_'.$field} ne '') {
10334: $cancreate{'shibenv'}{$field} = $env{'form.shibenv_'.$field};
10335: }
10336: }
10337: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
10338: if (ref($curr_usercreation{'cancreate'}{'shibenv'}) eq 'HASH') {
10339: foreach my $field (@shibfields) {
10340: if ($env{'form.shibenv_'.$field} ne $curr_usercreation{'cancreate'}{'shibenv'}{$field}) {
10341: push(@{$changes{'cancreate'}},'shibenv');
10342: }
10343: }
10344: } else {
10345: foreach my $field (@shibfields) {
10346: if ($env{'form.shibenv_'.$field}) {
10347: push(@{$changes{'cancreate'}},'shibenv');
10348: last;
10349: }
10350: }
10351: }
10352: }
1.224 raeburn 10353: }
10354: foreach my $item (@contexts) {
10355: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
10356: foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
10357: if (ref($cancreate{$item}) eq 'ARRAY') {
10358: if (!grep(/^$curr$/,@{$cancreate{$item}})) {
10359: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
10360: push(@{$changes{'cancreate'}},$item);
10361: }
10362: }
10363: }
10364: }
10365: if (ref($cancreate{$item}) eq 'ARRAY') {
10366: foreach my $type (@{$cancreate{$item}}) {
10367: if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
10368: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
10369: push(@{$changes{'cancreate'}},$item);
10370: }
10371: }
10372: }
10373: }
10374: } elsif (ref($curr_usercreation{'cancreate'}{$item}) eq 'HASH') {
10375: if (ref($cancreate{$item}) eq 'HASH') {
10376: foreach my $curr (keys(%{$curr_usercreation{'cancreate'}{$item}})) {
1.228 raeburn 10377: if (ref($curr_usercreation{'cancreate'}{$item}{$curr}) eq 'HASH') {
10378: foreach my $field (keys(%{$curr_usercreation{'cancreate'}{$item}{$curr}})) {
10379: unless ($curr_usercreation{'cancreate'}{$item}{$curr}{$field} eq $cancreate{$item}{$curr}{$field}) {
10380: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
10381: push(@{$changes{'cancreate'}},$item);
10382: }
10383: }
10384: }
1.236 raeburn 10385: } elsif ($item eq 'selfcreateprocessing') {
10386: if ($cancreate{$item}{$curr} ne $curr_usercreation{'cancreate'}{$item}{$curr}) {
10387: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
10388: push(@{$changes{'cancreate'}},$item);
10389: }
10390: }
1.228 raeburn 10391: } else {
10392: if (!$cancreate{$item}{$curr}) {
10393: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
10394: push(@{$changes{'cancreate'}},$item);
10395: }
1.224 raeburn 10396: }
10397: }
10398: }
10399: foreach my $field (keys(%{$cancreate{$item}})) {
1.228 raeburn 10400: if (ref($cancreate{$item}{$field}) eq 'HASH') {
10401: foreach my $inner (keys(%{$cancreate{$item}{$field}})) {
10402: if (ref($curr_usercreation{'cancreate'}{$item}{$field}) eq 'HASH') {
10403: unless ($curr_usercreation{'cancreate'}{$item}{$field}{$inner} eq $cancreate{$item}{$field}{$inner}) {
10404: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
10405: push(@{$changes{'cancreate'}},$item);
10406: }
10407: }
10408: } else {
10409: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
10410: push(@{$changes{'cancreate'}},$item);
10411: }
10412: }
10413: }
1.236 raeburn 10414: } elsif ($item eq 'selfcreateprocessing') {
10415: if ($cancreate{$item}{$field} ne $curr_usercreation{'cancreate'}{$item}{$field}) {
10416: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
10417: push(@{$changes{'cancreate'}},$item);
10418: }
10419: }
1.228 raeburn 10420: } else {
10421: if (!$curr_usercreation{'cancreate'}{$item}{$field}) {
10422: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
10423: push(@{$changes{'cancreate'}},$item);
10424: }
1.224 raeburn 10425: }
10426: }
10427: }
10428: }
10429: } elsif ($curr_usercreation{'cancreate'}{$item}) {
10430: if (ref($cancreate{$item}) eq 'ARRAY') {
10431: if (!grep(/^\Q$curr_usercreation{'cancreate'}{$item}\E$/,@{$cancreate{$item}})) {
10432: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
10433: push(@{$changes{'cancreate'}},$item);
10434: }
10435: }
10436: } elsif (ref($cancreate{$item}) eq 'HASH') {
10437: if (!$cancreate{$item}{$curr_usercreation{'cancreate'}{$item}}) {
10438: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
10439: push(@{$changes{'cancreate'}},$item);
10440: }
10441: }
10442: }
10443: } elsif ($item eq 'emailusername') {
1.228 raeburn 10444: if (ref($cancreate{$item}) eq 'HASH') {
10445: foreach my $type (keys(%{$cancreate{$item}})) {
10446: if (ref($cancreate{$item}{$type}) eq 'HASH') {
10447: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
10448: if ($cancreate{$item}{$type}{$field}) {
10449: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
10450: push(@{$changes{'cancreate'}},$item);
10451: }
10452: last;
10453: }
10454: }
10455: }
10456: }
1.224 raeburn 10457: }
10458: }
10459: }
10460: #
10461: # Populate %save_usercreate hash with updates to self-creation configuration.
10462: #
10463: $save_usercreate{'cancreate'}{'captcha'} = $savecaptcha{'captcha'};
10464: $save_usercreate{'cancreate'}{'recaptchakeys'} = $savecaptcha{'recaptchakeys'};
1.269 raeburn 10465: $save_usercreate{'cancreate'}{'recaptchaversion'} = $savecaptcha{'recaptchaversion'};
1.224 raeburn 10466: $save_usercreate{'cancreate'}{'selfcreate'} = $cancreate{'selfcreate'};
10467: if (ref($cancreate{'notify'}) eq 'HASH') {
10468: $save_usercreate{'cancreate'}{'notify'} = $cancreate{'notify'};
10469: }
1.236 raeburn 10470: if (ref($cancreate{'selfcreateprocessing'}) eq 'HASH') {
10471: $save_usercreate{'cancreate'}{'selfcreateprocessing'} = $cancreate{'selfcreateprocessing'};
10472: }
1.224 raeburn 10473: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
10474: $save_usercreate{'cancreate'}{'statustocreate'} = $cancreate{'statustocreate'};
10475: }
1.240 raeburn 10476: if (ref($cancreate{'shibenv'}) eq 'HASH') {
10477: $save_usercreate{'cancreate'}{'shibenv'} = $cancreate{'shibenv'};
10478: }
1.224 raeburn 10479: $save_usercreate{'cancreate'}{'emailusername'} = $cancreate{'emailusername'};
10480: $save_usercreate{'emailrule'} = \@email_rule;
10481:
10482: my %userconfig_hash = (
10483: usercreation => \%save_usercreate,
10484: usermodification => \%save_usermodify,
10485: );
10486: my $putresult = &Apache::lonnet::put_dom('configuration',\%userconfig_hash,
10487: $dom);
10488: #
10489: # Accumulate details of changes to domain cofiguration for self-creation of usernames in $resulttext
10490: #
1.27 raeburn 10491: if ($putresult eq 'ok') {
10492: if (keys(%changes) > 0) {
10493: $resulttext = &mt('Changes made:').'<ul>';
10494: if (ref($changes{'cancreate'}) eq 'ARRAY') {
1.224 raeburn 10495: my %lt = &selfcreation_types();
1.34 raeburn 10496: foreach my $type (@{$changes{'cancreate'}}) {
1.100 raeburn 10497: my $chgtext;
1.45 raeburn 10498: if ($type eq 'selfcreate') {
1.50 raeburn 10499: if (@{$cancreate{$type}} == 0) {
1.224 raeburn 10500: $chgtext .= &mt('Self creation of a new user account is not permitted.');
1.50 raeburn 10501: } else {
1.224 raeburn 10502: $chgtext .= &mt('Self-creation of a new account is permitted for:').
10503: '<ul>';
1.50 raeburn 10504: foreach my $case (@{$cancreate{$type}}) {
10505: $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
10506: }
10507: $chgtext .= '</ul>';
1.100 raeburn 10508: if (ref($cancreate{$type}) eq 'ARRAY') {
10509: if (grep(/^(login|sso)$/,@{$cancreate{$type}})) {
10510: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
10511: if (@{$cancreate{'statustocreate'}} == 0) {
1.224 raeburn 10512: $chgtext .= '<br />'.
10513: '<span class="LC_warning">'.
10514: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
10515: '</span>';
1.100 raeburn 10516: }
10517: }
10518: }
10519: }
1.43 raeburn 10520: }
1.240 raeburn 10521: } elsif ($type eq 'shibenv') {
10522: if (keys(%{$cancreate{$type}}) == 0) {
10523: $chgtext .= &mt('Shibboleth-autheticated user does not use environment variables to set user information');
10524: } else {
10525: $chgtext .= &mt('Shibboleth-autheticated user information set from environment variables, as follows:').
10526: '<ul>';
10527: foreach my $field (@shibfields) {
10528: next if ($cancreate{$type}{$field} eq '');
10529: if ($field eq 'inststatus') {
10530: $chgtext .= '<li>'.&mt('Institutional status').' -- '.$cancreate{$type}{$field}.'</li>';
10531: } else {
10532: $chgtext .= '<li>'.$fieldtitles{$field}.' -- '.$cancreate{$type}{$field}.'</li>';
10533: }
10534: }
10535: $chgtext .= '</ul>';
10536: }
1.93 raeburn 10537: } elsif ($type eq 'statustocreate') {
1.96 raeburn 10538: if ((ref($cancreate{'selfcreate'}) eq 'ARRAY') &&
10539: (ref($cancreate{'statustocreate'}) eq 'ARRAY')) {
10540: if (@{$cancreate{'selfcreate'}} > 0) {
10541: if (@{$cancreate{'statustocreate'}} == 0) {
1.100 raeburn 10542: $chgtext .= &mt("Institutional affiliations permitted to create accounts set to 'None'.");
1.96 raeburn 10543: if (!grep(/^email$/,@{$cancreate{'selfcreate'}})) {
1.224 raeburn 10544: $chgtext .= '<br />'.
10545: '<span class="LC_warning">'.
10546: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
10547: '</span>';
10548: }
1.96 raeburn 10549: } elsif (ref($usertypes) eq 'HASH') {
10550: if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.100 raeburn 10551: $chgtext .= &mt('Creation of a new account for an institutional user is restricted to the following institutional affiliation(s):');
10552: } else {
10553: $chgtext .= &mt('Institutional affiliations permitted to create accounts with institutional authentication were set as follows:');
10554: }
10555: $chgtext .= '<ul>';
10556: foreach my $case (@{$cancreate{$type}}) {
10557: if ($case eq 'default') {
10558: $chgtext .= '<li>'.$othertitle.'</li>';
10559: } else {
10560: $chgtext .= '<li>'.$usertypes->{$case}.'</li>';
1.93 raeburn 10561: }
10562: }
1.100 raeburn 10563: $chgtext .= '</ul>';
10564: if (!grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.224 raeburn 10565: $chgtext .= '<br /><span class="LC_warning">'.
10566: &mt('However, users authenticated by institutional login/single sign on are not currently permitted to create accounts.').
10567: '</span>';
1.100 raeburn 10568: }
10569: }
10570: } else {
10571: if (@{$cancreate{$type}} == 0) {
10572: $chgtext .= &mt("Institutional affiliations permitted to create accounts were set to 'none'.");
10573: } else {
10574: $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 10575: }
10576: }
10577: }
1.236 raeburn 10578: } elsif ($type eq 'selfcreateprocessing') {
10579: my %choices = &Apache::lonlocal::texthash (
10580: automatic => 'Automatic approval',
10581: approval => 'Queued for approval',
10582: );
10583: if (@statuses > 1) {
10584: $chgtext .= &mt('Processing of requests to create account with e-mail address as username set as follows:').
10585: '<ul>';
10586: foreach my $type (@statuses) {
10587: if ($type eq 'default') {
10588: $chgtext .= '<li>'.$othertitle.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$type}}.'</li>';
10589: } else {
10590: $chgtext .= '<li>'.$usertypes->{$type}.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$type}}.'</li>';
10591: }
10592: }
10593: $chgtext .= '</ul>';
10594: } else {
10595: $chgtext .= &mt('Processing of requests to create account with e-mail address as username set to: "[_1]"',
10596: $choices{$cancreate{'selfcreateprocessing'}{'default'}});
10597: }
1.165 raeburn 10598: } elsif ($type eq 'captcha') {
1.224 raeburn 10599: if ($savecaptcha{$type} eq 'notused') {
1.165 raeburn 10600: $chgtext .= &mt('No CAPTCHA validation in use for self-creation screen.');
10601: } else {
10602: my %captchas = &captcha_phrases();
1.224 raeburn 10603: if ($captchas{$savecaptcha{$type}}) {
10604: $chgtext .= &mt("Validation for self-creation screen set to $captchas{$savecaptcha{$type}}.");
1.165 raeburn 10605: } else {
1.210 raeburn 10606: $chgtext .= &mt('Validation for self-creation screen set to unknown type.');
1.165 raeburn 10607: }
10608: }
10609: } elsif ($type eq 'recaptchakeys') {
10610: my ($privkey,$pubkey);
1.224 raeburn 10611: if (ref($savecaptcha{$type}) eq 'HASH') {
10612: $pubkey = $savecaptcha{$type}{'public'};
10613: $privkey = $savecaptcha{$type}{'private'};
1.165 raeburn 10614: }
10615: $chgtext .= &mt('ReCAPTCHA keys changes').'<ul>';
10616: if (!$pubkey) {
10617: $chgtext .= '<li>'.&mt('Public key deleted').'</li>';
10618: } else {
10619: $chgtext .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
10620: }
10621: if (!$privkey) {
10622: $chgtext .= '<li>'.&mt('Private key deleted').'</li>';
10623: } else {
10624: $chgtext .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
10625: }
10626: $chgtext .= '</ul>';
1.269 raeburn 10627: } elsif ($type eq 'recaptchaversion') {
10628: if ($savecaptcha{'captcha'} eq 'recaptcha') {
1.270 raeburn 10629: $chgtext .= &mt('ReCAPTCHA set to version [_1]',$savecaptcha{$type});
1.269 raeburn 10630: }
1.224 raeburn 10631: } elsif ($type eq 'emailusername') {
10632: if (ref($cancreate{'emailusername'}) eq 'HASH') {
1.228 raeburn 10633: if (ref($types) eq 'ARRAY') {
10634: foreach my $type (@{$types}) {
10635: if (ref($cancreate{'emailusername'}{$type}) eq 'HASH') {
10636: if (keys(%{$cancreate{'emailusername'}{$type}}) > 0) {
1.245 raeburn 10637: $chgtext .= &mt('When self-creating account with e-mail as username, the following information will be provided by [_1]:',"'$usertypes->{$type}'").
1.228 raeburn 10638: '<ul>';
10639: foreach my $field (@{$infofields}) {
10640: if ($cancreate{'emailusername'}{$type}{$field}) {
10641: $chgtext .= '<li>'.$infotitles->{$field}.'</li>';
10642: }
10643: }
1.245 raeburn 10644: $chgtext .= '</ul>';
10645: } else {
10646: $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 10647: }
10648: } else {
1.245 raeburn 10649: $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 10650: }
10651: }
10652: }
10653: }
10654: } elsif ($type eq 'notify') {
10655: $chgtext = &mt('No Domain Coordinators will receive notification of username requests requiring approval.');
10656: if (ref($changes{'cancreate'}) eq 'ARRAY') {
10657: if ((grep(/^notify$/,@{$changes{'cancreate'}})) && (ref($cancreate{'notify'}) eq 'HASH')) {
10658: if ($cancreate{'notify'}{'approval'}) {
10659: $chgtext = &mt('Notification of username requests requiring approval will be sent to: ').$cancreate{'notify'}{'approval'};
10660: }
10661: }
1.43 raeburn 10662: }
1.34 raeburn 10663: }
1.224 raeburn 10664: if ($chgtext) {
10665: $resulttext .= '<li>'.$chgtext.'</li>';
1.32 raeburn 10666: }
10667: }
10668: }
1.43 raeburn 10669: if (ref($changes{'email_rule'}) eq 'ARRAY') {
10670: my ($emailrules,$emailruleorder) =
10671: &Apache::lonnet::inst_userrules($dom,'email');
10672: my $chgtext = '<ul>';
10673: foreach my $type (@email_rule) {
10674: if (ref($emailrules->{$type}) eq 'HASH') {
10675: $chgtext .= '<li>'.$emailrules->{$type}{'name'}.'</li>';
10676: }
10677: }
10678: $chgtext .= '</ul>';
10679: if (@email_rule > 0) {
1.224 raeburn 10680: $resulttext .= '<li>'.
10681: &mt('Accounts may not be created by users self-enrolling with e-mail addresses of the following types: ').
10682: $chgtext.
10683: '</li>';
1.43 raeburn 10684: } else {
1.224 raeburn 10685: $resulttext .= '<li>'.
10686: &mt('There are now no restrictions on e-mail addresses which may be used as a username when self-enrolling.').
10687: '</li>';
1.43 raeburn 10688: }
10689: }
1.224 raeburn 10690: if (ref($changes{'selfcreate'}) eq 'ARRAY') {
10691: $resulttext .= '<li>'.&mt('When self-creating institutional account:').'<ul>';
10692: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
10693: foreach my $type (@{$changes{'selfcreate'}}) {
10694: my $typename = $type;
10695: if (ref($usertypes) eq 'HASH') {
10696: if ($usertypes->{$type} ne '') {
10697: $typename = $usertypes->{$type};
10698: }
10699: }
10700: my @modifiable;
10701: $resulttext .= '<li>'.
10702: &mt('Self-creation of account by users with status: [_1]',
10703: '<span class="LC_cusr_emph">'.$typename.'</span>').
10704: ' - '.&mt('modifiable fields (if institutional data blank): ');
10705: foreach my $field (@fields) {
10706: if ($save_usermodify{'selfcreate'}{$type}{$field}) {
10707: push(@modifiable,'<b>'.$fieldtitles{$field}.'</b>');
1.28 raeburn 10708: }
10709: }
1.224 raeburn 10710: if (@modifiable > 0) {
10711: $resulttext .= join(', ',@modifiable);
1.43 raeburn 10712: } else {
1.224 raeburn 10713: $resulttext .= &mt('none');
1.43 raeburn 10714: }
1.224 raeburn 10715: $resulttext .= '</li>';
1.28 raeburn 10716: }
1.224 raeburn 10717: $resulttext .= '</ul></li>';
1.28 raeburn 10718: }
1.27 raeburn 10719: $resulttext .= '</ul>';
10720: } else {
1.224 raeburn 10721: $resulttext = &mt('No changes made to self-creation settings');
1.27 raeburn 10722: }
10723: } else {
10724: $resulttext = '<span class="LC_error">'.
1.23 raeburn 10725: &mt('An error occurred: [_1]',$putresult).'</span>';
10726: }
1.43 raeburn 10727: if ($warningmsg ne '') {
10728: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
10729: }
1.23 raeburn 10730: return $resulttext;
10731: }
10732:
1.165 raeburn 10733: sub process_captcha {
10734: my ($container,$changes,$newsettings,$current) = @_;
10735: return unless ((ref($changes) eq 'HASH') && (ref($newsettings) eq 'HASH') || (ref($current) eq 'HASH'));
10736: $newsettings->{'captcha'} = $env{'form.'.$container.'_captcha'};
10737: unless ($newsettings->{'captcha'} eq 'recaptcha' || $newsettings->{'captcha'} eq 'notused') {
10738: $newsettings->{'captcha'} = 'original';
10739: }
10740: if ($current->{'captcha'} ne $newsettings->{'captcha'}) {
1.210 raeburn 10741: if ($container eq 'cancreate') {
1.169 raeburn 10742: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
10743: push(@{$changes->{'cancreate'}},'captcha');
10744: } elsif (!defined($changes->{'cancreate'})) {
10745: $changes->{'cancreate'} = ['captcha'];
10746: }
10747: } else {
10748: $changes->{'captcha'} = 1;
1.165 raeburn 10749: }
10750: }
1.269 raeburn 10751: my ($newpub,$newpriv,$currpub,$currpriv,$newversion,$currversion);
1.165 raeburn 10752: if ($newsettings->{'captcha'} eq 'recaptcha') {
10753: $newpub = $env{'form.'.$container.'_recaptchapub'};
10754: $newpriv = $env{'form.'.$container.'_recaptchapriv'};
1.250 raeburn 10755: $newpub =~ s/[^\w\-]//g;
10756: $newpriv =~ s/[^\w\-]//g;
1.169 raeburn 10757: $newsettings->{'recaptchakeys'} = {
10758: public => $newpub,
10759: private => $newpriv,
10760: };
1.269 raeburn 10761: $newversion = $env{'form.'.$container.'_recaptchaversion'};
10762: $newversion =~ s/\D//g;
10763: if ($newversion ne '2') {
10764: $newversion = 1;
10765: }
10766: $newsettings->{'recaptchaversion'} = $newversion;
1.165 raeburn 10767: }
10768: if (ref($current->{'recaptchakeys'}) eq 'HASH') {
10769: $currpub = $current->{'recaptchakeys'}{'public'};
10770: $currpriv = $current->{'recaptchakeys'}{'private'};
1.179 raeburn 10771: unless ($newsettings->{'captcha'} eq 'recaptcha') {
10772: $newsettings->{'recaptchakeys'} = {
10773: public => '',
10774: private => '',
10775: }
10776: }
1.165 raeburn 10777: }
1.269 raeburn 10778: if ($current->{'captcha'} eq 'recaptcha') {
10779: $currversion = $current->{'recaptchaversion'};
10780: if ($currversion ne '2') {
10781: $currversion = 1;
10782: }
10783: }
10784: if ($currversion ne $newversion) {
10785: if ($container eq 'cancreate') {
10786: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
10787: push(@{$changes->{'cancreate'}},'recaptchaversion');
10788: } elsif (!defined($changes->{'cancreate'})) {
10789: $changes->{'cancreate'} = ['recaptchaversion'];
10790: }
10791: } else {
10792: $changes->{'recaptchaversion'} = 1;
10793: }
10794: }
1.165 raeburn 10795: if (($newpub ne $currpub) || ($newpriv ne $currpriv)) {
1.169 raeburn 10796: if ($container eq 'cancreate') {
10797: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
10798: push(@{$changes->{'cancreate'}},'recaptchakeys');
10799: } elsif (!defined($changes->{'cancreate'})) {
10800: $changes->{'cancreate'} = ['recaptchakeys'];
10801: }
10802: } else {
1.210 raeburn 10803: $changes->{'recaptchakeys'} = 1;
1.165 raeburn 10804: }
10805: }
10806: return;
10807: }
10808:
1.33 raeburn 10809: sub modify_usermodification {
10810: my ($dom,%domconfig) = @_;
1.224 raeburn 10811: my ($resulttext,%curr_usermodification,%changes,%modifyhash);
1.33 raeburn 10812: if (ref($domconfig{'usermodification'}) eq 'HASH') {
10813: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
1.224 raeburn 10814: if ($key eq 'selfcreate') {
10815: $modifyhash{$key} = $domconfig{'usermodification'}{$key};
10816: } else {
10817: $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
10818: }
1.33 raeburn 10819: }
10820: }
1.224 raeburn 10821: my @contexts = ('author','course');
1.33 raeburn 10822: my %context_title = (
10823: author => 'In author context',
10824: course => 'In course context',
10825: );
10826: my @fields = ('lastname','firstname','middlename','generation',
10827: 'permanentemail','id');
10828: my %roles = (
10829: author => ['ca','aa'],
10830: course => ['st','ep','ta','in','cr'],
10831: );
10832: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
10833: foreach my $context (@contexts) {
10834: foreach my $role (@{$roles{$context}}) {
10835: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$role);
10836: foreach my $item (@fields) {
10837: if (grep(/^\Q$item\E$/,@modifiable)) {
10838: $modifyhash{$context}{$role}{$item} = 1;
10839: } else {
10840: $modifyhash{$context}{$role}{$item} = 0;
10841: }
10842: }
10843: }
10844: if (ref($curr_usermodification{$context}) eq 'HASH') {
10845: foreach my $role (@{$roles{$context}}) {
10846: if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
10847: foreach my $field (@fields) {
10848: if ($modifyhash{$context}{$role}{$field} ne
10849: $curr_usermodification{$context}{$role}{$field}) {
10850: push(@{$changes{$context}},$role);
10851: last;
10852: }
10853: }
10854: }
10855: }
10856: } else {
10857: foreach my $context (@contexts) {
10858: foreach my $role (@{$roles{$context}}) {
10859: push(@{$changes{$context}},$role);
10860: }
10861: }
10862: }
10863: }
10864: my %usermodification_hash = (
10865: usermodification => \%modifyhash,
10866: );
10867: my $putresult = &Apache::lonnet::put_dom('configuration',
10868: \%usermodification_hash,$dom);
10869: if ($putresult eq 'ok') {
10870: if (keys(%changes) > 0) {
10871: $resulttext = &mt('Changes made: ').'<ul>';
10872: foreach my $context (@contexts) {
10873: if (ref($changes{$context}) eq 'ARRAY') {
10874: $resulttext .= '<li>'.$context_title{$context}.':<ul>';
10875: if (ref($changes{$context}) eq 'ARRAY') {
10876: foreach my $role (@{$changes{$context}}) {
10877: my $rolename;
1.224 raeburn 10878: if ($role eq 'cr') {
10879: $rolename = &mt('Custom');
1.33 raeburn 10880: } else {
1.224 raeburn 10881: $rolename = &Apache::lonnet::plaintext($role);
1.33 raeburn 10882: }
10883: my @modifiable;
1.224 raeburn 10884: $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
1.33 raeburn 10885: foreach my $field (@fields) {
10886: if ($modifyhash{$context}{$role}{$field}) {
10887: push(@modifiable,$fieldtitles{$field});
10888: }
10889: }
10890: if (@modifiable > 0) {
10891: $resulttext .= join(', ',@modifiable);
10892: } else {
10893: $resulttext .= &mt('none');
10894: }
10895: $resulttext .= '</li>';
10896: }
10897: $resulttext .= '</ul></li>';
10898: }
10899: }
10900: }
10901: $resulttext .= '</ul>';
10902: } else {
10903: $resulttext = &mt('No changes made to user modification settings');
10904: }
10905: } else {
10906: $resulttext = '<span class="LC_error">'.
10907: &mt('An error occurred: [_1]',$putresult).'</span>';
10908: }
10909: return $resulttext;
10910: }
10911:
1.43 raeburn 10912: sub modify_defaults {
1.212 raeburn 10913: my ($dom,$lastactref,%domconfig) = @_;
1.43 raeburn 10914: my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
1.212 raeburn 10915: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.141 raeburn 10916: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def','portal_def');
1.43 raeburn 10917: my @authtypes = ('internal','krb4','krb5','localauth');
10918: foreach my $item (@items) {
10919: $newvalues{$item} = $env{'form.'.$item};
10920: if ($item eq 'auth_def') {
10921: if ($newvalues{$item} ne '') {
10922: if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
10923: push(@errors,$item);
10924: }
10925: }
10926: } elsif ($item eq 'lang_def') {
10927: if ($newvalues{$item} ne '') {
10928: if ($newvalues{$item} =~ /^(\w+)/) {
10929: my $langcode = $1;
1.103 raeburn 10930: if ($langcode ne 'x_chef') {
10931: if (code2language($langcode) eq '') {
10932: push(@errors,$item);
10933: }
1.43 raeburn 10934: }
10935: } else {
10936: push(@errors,$item);
10937: }
10938: }
1.54 raeburn 10939: } elsif ($item eq 'timezone_def') {
10940: if ($newvalues{$item} ne '') {
1.62 raeburn 10941: if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
1.54 raeburn 10942: push(@errors,$item);
10943: }
10944: }
1.68 raeburn 10945: } elsif ($item eq 'datelocale_def') {
10946: if ($newvalues{$item} ne '') {
10947: my @datelocale_ids = DateTime::Locale->ids();
10948: if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
10949: push(@errors,$item);
10950: }
10951: }
1.141 raeburn 10952: } elsif ($item eq 'portal_def') {
10953: if ($newvalues{$item} ne '') {
10954: 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])\/?$/) {
10955: push(@errors,$item);
10956: }
10957: }
1.43 raeburn 10958: }
10959: if (grep(/^\Q$item\E$/,@errors)) {
10960: $newvalues{$item} = $domdefaults{$item};
10961: } elsif ($domdefaults{$item} ne $newvalues{$item}) {
10962: $changes{$item} = 1;
10963: }
1.72 raeburn 10964: $domdefaults{$item} = $newvalues{$item};
1.43 raeburn 10965: }
10966: my %defaults_hash = (
1.72 raeburn 10967: defaults => \%newvalues,
10968: );
1.43 raeburn 10969: my $title = &defaults_titles();
1.236 raeburn 10970:
10971: my $currinststatus;
10972: if (ref($domconfig{'inststatus'}) eq 'HASH') {
10973: $currinststatus = $domconfig{'inststatus'};
10974: } else {
10975: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
10976: $currinststatus = {
10977: inststatustypes => $usertypes,
10978: inststatusorder => $types,
10979: inststatusguest => [],
10980: };
10981: }
10982: my @todelete = &Apache::loncommon::get_env_multiple('form.inststatus_delete');
10983: my @allpos;
10984: my %guests;
10985: my %alltypes;
10986: my ($currtitles,$currguests,$currorder);
10987: if (ref($currinststatus) eq 'HASH') {
10988: if (ref($currinststatus->{'inststatusorder'}) eq 'ARRAY') {
10989: foreach my $type (@{$currinststatus->{'inststatusorder'}}) {
10990: if (ref($currinststatus->{inststatustypes}) eq 'HASH') {
10991: if ($currinststatus->{inststatustypes}->{$type} ne '') {
10992: $currtitles .= $currinststatus->{inststatustypes}->{$type}.',';
10993: }
10994: }
10995: unless (grep(/^\Q$type\E$/,@todelete)) {
10996: my $position = $env{'form.inststatus_pos_'.$type};
10997: $position =~ s/\D+//g;
10998: $allpos[$position] = $type;
10999: $alltypes{$type} = $env{'form.inststatus_title_'.$type};
11000: $alltypes{$type} =~ s/`//g;
11001: if ($env{'form.inststatus_guest_'.$type}) {
11002: $guests{$type} = 1;
11003: }
11004: }
11005: }
11006: if (ref($currinststatus->{'inststatusguest'}) eq 'ARRAY') {
11007: $currguests = join(',',@{$currinststatus->{'inststatusguest'}});
11008: }
11009: $currorder = join(',',@{$currinststatus->{'inststatusorder'}});
11010: $currtitles =~ s/,$//;
11011: }
11012: }
11013: if ($env{'form.addinststatus'}) {
11014: my $newtype = $env{'form.addinststatus'};
11015: $newtype =~ s/\W//g;
11016: unless (exists($alltypes{$newtype})) {
11017: if ($env{'form.addinststatus_guest'}) {
11018: $guests{$newtype} = 1;
11019: }
11020: $alltypes{$newtype} = $env{'form.addinststatus_title'};
11021: $alltypes{$newtype} =~ s/`//g;
11022: my $position = $env{'form.addinststatus_pos'};
11023: $position =~ s/\D+//g;
11024: if ($position ne '') {
11025: $allpos[$position] = $newtype;
11026: }
11027: }
11028: }
11029: my (@orderedstatus,@orderedguests);
11030: foreach my $type (@allpos) {
11031: unless (($type eq '') || (grep(/^\Q$type\E$/,@orderedstatus))) {
11032: push(@orderedstatus,$type);
11033: if ($guests{$type}) {
11034: push(@orderedguests,$type);
11035: }
11036: }
11037: }
11038: foreach my $type (keys(%alltypes)) {
11039: unless (grep(/^\Q$type\E$/,@orderedstatus)) {
11040: delete($alltypes{$type});
11041: }
11042: }
11043: $defaults_hash{'inststatus'} = {
11044: inststatustypes => \%alltypes,
11045: inststatusorder => \@orderedstatus,
11046: inststatusguest => \@orderedguests,
11047: };
11048: if (ref($defaults_hash{'inststatus'}) eq 'HASH') {
11049: foreach my $item ('inststatustypes','inststatusorder','inststatusguest') {
11050: $domdefaults{$item} = $defaults_hash{'inststatus'}{$item};
11051: }
11052: }
11053: if ($currorder ne join(',',@orderedstatus)) {
11054: $changes{'inststatus'}{'inststatusorder'} = 1;
11055: }
11056: if ($currguests ne join(',',@orderedguests)) {
11057: $changes{'inststatus'}{'inststatusguest'} = 1;
11058: }
11059: my $newtitles;
11060: foreach my $item (@orderedstatus) {
11061: $newtitles .= $alltypes{$item}.',';
11062: }
11063: $newtitles =~ s/,$//;
11064: if ($currtitles ne $newtitles) {
11065: $changes{'inststatus'}{'inststatustypes'} = 1;
11066: }
1.43 raeburn 11067: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
11068: $dom);
11069: if ($putresult eq 'ok') {
11070: if (keys(%changes) > 0) {
11071: $resulttext = &mt('Changes made:').'<ul>';
1.212 raeburn 11072: my $version = &Apache::lonnet::get_server_loncaparev($dom);
1.43 raeburn 11073: 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";
11074: foreach my $item (sort(keys(%changes))) {
1.236 raeburn 11075: if ($item eq 'inststatus') {
11076: if (ref($changes{'inststatus'}) eq 'HASH') {
11077: if (($changes{'inststatus'}{'inststatustypes'}) || $changes{'inststatus'}{'inststatusorder'}) {
11078: $resulttext .= '<li>'.&mt('Institutional user status types set to:').' ';
11079: foreach my $type (@orderedstatus) {
11080: $resulttext .= $alltypes{$type}.', ';
11081: }
11082: $resulttext =~ s/, $//;
11083: $resulttext .= '</li>';
11084: }
11085: if ($changes{'inststatus'}{'inststatusguest'}) {
11086: $resulttext .= '<li>';
11087: if (@orderedguests) {
11088: $resulttext .= &mt('Types assignable to "non-institutional" usernames set to:').' ';
11089: foreach my $type (@orderedguests) {
11090: $resulttext .= $alltypes{$type}.', ';
11091: }
11092: $resulttext =~ s/, $//;
11093: } else {
11094: $resulttext .= &mt('Types assignable to "non-institutional" usernames set to none.');
11095: }
11096: $resulttext .= '</li>';
11097: }
11098: }
11099: } else {
11100: my $value = $env{'form.'.$item};
11101: if ($value eq '') {
11102: $value = &mt('none');
11103: } elsif ($item eq 'auth_def') {
11104: my %authnames = &authtype_names();
11105: my %shortauth = (
11106: internal => 'int',
11107: krb4 => 'krb4',
11108: krb5 => 'krb5',
11109: localauth => 'loc',
11110: );
11111: $value = $authnames{$shortauth{$value}};
11112: }
11113: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
11114: $mailmsgtext .= "$title->{$item} set to $value\n";
1.43 raeburn 11115: }
11116: }
11117: $resulttext .= '</ul>';
11118: $mailmsgtext .= "\n";
11119: my $cachetime = 24*60*60;
1.72 raeburn 11120: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 11121: if (ref($lastactref) eq 'HASH') {
11122: $lastactref->{'domdefaults'} = 1;
11123: }
1.68 raeburn 11124: if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
1.203 raeburn 11125: my $notify = 1;
11126: if (ref($domconfig{'contacts'}) eq 'HASH') {
11127: if ($domconfig{'contacts'}{'reportupdates'} == 0) {
11128: $notify = 0;
11129: }
11130: }
11131: if ($notify) {
11132: &Apache::lonmsg::sendemail('installrecord@loncapa.org',
11133: "LON-CAPA Domain Settings Change - $dom",
11134: $mailmsgtext);
11135: }
1.54 raeburn 11136: }
1.43 raeburn 11137: } else {
1.54 raeburn 11138: $resulttext = &mt('No changes made to default authentication/language/timezone settings');
1.43 raeburn 11139: }
11140: } else {
11141: $resulttext = '<span class="LC_error">'.
11142: &mt('An error occurred: [_1]',$putresult).'</span>';
11143: }
11144: if (@errors > 0) {
11145: $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
11146: foreach my $item (@errors) {
11147: $resulttext .= ' "'.$title->{$item}.'",';
11148: }
11149: $resulttext =~ s/,$//;
11150: }
11151: return $resulttext;
11152: }
11153:
1.46 raeburn 11154: sub modify_scantron {
1.205 raeburn 11155: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.46 raeburn 11156: my ($resulttext,%confhash,%changes,$errors);
11157: my $custom = 'custom.tab';
11158: my $default = 'default.tab';
11159: my $servadm = $r->dir_config('lonAdmEMail');
11160: my ($configuserok,$author_ok,$switchserver) =
11161: &config_check($dom,$confname,$servadm);
11162: if ($env{'form.scantronformat.filename'} ne '') {
11163: my $error;
11164: if ($configuserok eq 'ok') {
11165: if ($switchserver) {
1.130 raeburn 11166: $error = &mt("Upload of bubblesheet format file is not permitted to this server: [_1]",$switchserver);
1.46 raeburn 11167: } else {
11168: if ($author_ok eq 'ok') {
11169: my ($result,$scantronurl) =
11170: &publishlogo($r,'upload','scantronformat',$dom,
11171: $confname,'scantron','','',$custom);
11172: if ($result eq 'ok') {
11173: $confhash{'scantron'}{'scantronformat'} = $scantronurl;
1.48 raeburn 11174: $changes{'scantronformat'} = 1;
1.46 raeburn 11175: } else {
11176: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
11177: }
11178: } else {
11179: $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);
11180: }
11181: }
11182: } else {
11183: $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);
11184: }
11185: if ($error) {
11186: &Apache::lonnet::logthis($error);
11187: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
11188: }
11189: }
1.48 raeburn 11190: if (ref($domconfig{'scantron'}) eq 'HASH') {
11191: if ($domconfig{'scantron'}{'scantronformat'} ne '') {
11192: if ($env{'form.scantronformat_del'}) {
11193: $confhash{'scantron'}{'scantronformat'} = '';
11194: $changes{'scantronformat'} = 1;
1.46 raeburn 11195: }
11196: }
11197: }
11198: if (keys(%confhash) > 0) {
11199: my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
11200: $dom);
11201: if ($putresult eq 'ok') {
11202: if (keys(%changes) > 0) {
1.48 raeburn 11203: if (ref($confhash{'scantron'}) eq 'HASH') {
11204: $resulttext = &mt('Changes made:').'<ul>';
11205: if ($confhash{'scantron'}{'scantronformat'} eq '') {
1.130 raeburn 11206: $resulttext .= '<li>'.&mt('[_1] bubblesheet format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
1.48 raeburn 11207: } else {
1.130 raeburn 11208: $resulttext .= '<li>'.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
1.46 raeburn 11209: }
1.48 raeburn 11210: $resulttext .= '</ul>';
11211: } else {
1.130 raeburn 11212: $resulttext = &mt('Changes made to bubblesheet format file.');
1.46 raeburn 11213: }
11214: $resulttext .= '</ul>';
11215: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 11216: if (ref($lastactref) eq 'HASH') {
11217: $lastactref->{'domainconfig'} = 1;
11218: }
1.46 raeburn 11219: } else {
1.130 raeburn 11220: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 11221: }
11222: } else {
11223: $resulttext = '<span class="LC_error">'.
11224: &mt('An error occurred: [_1]',$putresult).'</span>';
11225: }
11226: } else {
1.130 raeburn 11227: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 11228: }
11229: if ($errors) {
11230: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
11231: $errors.'</ul>';
11232: }
11233: return $resulttext;
11234: }
11235:
1.48 raeburn 11236: sub modify_coursecategories {
1.239 raeburn 11237: my ($dom,$lastactref,%domconfig) = @_;
1.57 raeburn 11238: my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
11239: $cathash);
1.48 raeburn 11240: my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
1.238 raeburn 11241: my @catitems = ('unauth','auth');
11242: my @cattypes = ('std','domonly','codesrch','none');
1.55 raeburn 11243: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
1.57 raeburn 11244: $cathash = $domconfig{'coursecategories'}{'cats'};
11245: if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
11246: $changes{'togglecats'} = 1;
11247: $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
11248: }
11249: if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
11250: $changes{'categorize'} = 1;
11251: $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
11252: }
1.120 raeburn 11253: if ($domconfig{'coursecategories'}{'togglecatscomm'} ne $env{'form.togglecatscomm'}) {
11254: $changes{'togglecatscomm'} = 1;
11255: $domconfig{'coursecategories'}{'togglecatscomm'} = $env{'form.togglecatscomm'};
11256: }
11257: if ($domconfig{'coursecategories'}{'categorizecomm'} ne $env{'form.categorizecomm'}) {
11258: $changes{'categorizecomm'} = 1;
11259: $domconfig{'coursecategories'}{'categorizecomm'} = $env{'form.categorizecomm'};
1.272 raeburn 11260:
11261: }
11262: if ($domconfig{'coursecategories'}{'togglecatsplace'} ne $env{'form.togglecatsplace'}) {
11263: $changes{'togglecatsplace'} = 1;
11264: $domconfig{'coursecategories'}{'togglecatsplace'} = $env{'form.togglecatsplace'};
11265: }
11266: if ($domconfig{'coursecategories'}{'categorizeplace'} ne $env{'form.categorizeplace'}) {
11267: $changes{'categorizeplace'} = 1;
11268: $domconfig{'coursecategories'}{'categorizeplace'} = $env{'form.categorizeplace'};
1.120 raeburn 11269: }
1.238 raeburn 11270: foreach my $item (@catitems) {
11271: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
11272: if ($domconfig{'coursecategories'}{$item} ne $env{'form.coursecat_'.$item}) {
11273: $changes{$item} = 1;
11274: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
11275: }
11276: }
11277: }
1.57 raeburn 11278: } else {
11279: $changes{'togglecats'} = 1;
11280: $changes{'categorize'} = 1;
1.124 raeburn 11281: $changes{'togglecatscomm'} = 1;
11282: $changes{'categorizecomm'} = 1;
1.272 raeburn 11283: $changes{'togglecatsplace'} = 1;
11284: $changes{'categorizeplace'} = 1;
1.87 raeburn 11285: $domconfig{'coursecategories'} = {
11286: togglecats => $env{'form.togglecats'},
11287: categorize => $env{'form.categorize'},
1.124 raeburn 11288: togglecatscomm => $env{'form.togglecatscomm'},
11289: categorizecomm => $env{'form.categorizecomm'},
1.272 raeburn 11290: togglecatsplace => $env{'form.togglecatsplace'},
11291: categorizeplace => $env{'form.categorizeplace'},
1.120 raeburn 11292: };
1.238 raeburn 11293: foreach my $item (@catitems) {
11294: if ($env{'form.coursecat_'.$item} ne 'std') {
11295: $changes{$item} = 1;
11296: }
11297: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
11298: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
11299: }
11300: }
1.57 raeburn 11301: }
11302: if (ref($cathash) eq 'HASH') {
11303: if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '') && ($env{'form.instcode'} == 0)) {
1.55 raeburn 11304: push (@deletecategory,'instcode::0');
11305: }
1.120 raeburn 11306: if (($domconfig{'coursecategories'}{'cats'}{'communities::0'} ne '') && ($env{'form.communities'} == 0)) {
11307: push(@deletecategory,'communities::0');
11308: }
1.272 raeburn 11309: if (($domconfig{'coursecategories'}{'cats'}{'placement::0'} ne '') && ($env{'form.placement'} == 0)) {
11310: push(@deletecategory,'placement::0');
11311: }
1.48 raeburn 11312: }
1.57 raeburn 11313: my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
11314: if (ref($cathash) eq 'HASH') {
1.48 raeburn 11315: if (@deletecategory > 0) {
11316: #FIXME Need to remove category from all courses using a deleted category
1.57 raeburn 11317: &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
1.48 raeburn 11318: foreach my $item (@deletecategory) {
1.57 raeburn 11319: if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
11320: delete($domconfig{'coursecategories'}{'cats'}{$item});
1.48 raeburn 11321: $deletions{$item} = 1;
1.57 raeburn 11322: &recurse_cat_deletes($item,$cathash,\%deletions);
1.48 raeburn 11323: }
11324: }
11325: }
1.57 raeburn 11326: foreach my $item (keys(%{$cathash})) {
1.48 raeburn 11327: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
1.57 raeburn 11328: if ($cathash->{$item} ne $env{'form.'.$item}) {
1.48 raeburn 11329: $reorderings{$item} = 1;
1.57 raeburn 11330: $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
1.48 raeburn 11331: }
11332: if ($env{'form.addcategory_name_'.$item} ne '') {
11333: my $newcat = $env{'form.addcategory_name_'.$item};
11334: my $newdepth = $depth+1;
11335: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 11336: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
1.48 raeburn 11337: $adds{$newitem} = 1;
11338: }
11339: if ($env{'form.subcat_'.$item} ne '') {
11340: my $newcat = $env{'form.subcat_'.$item};
11341: my $newdepth = $depth+1;
11342: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 11343: $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
1.48 raeburn 11344: $adds{$newitem} = 1;
11345: }
11346: }
11347: }
11348: if ($env{'form.instcode'} eq '1') {
1.57 raeburn 11349: if (ref($cathash) eq 'HASH') {
1.48 raeburn 11350: my $newitem = 'instcode::0';
1.57 raeburn 11351: if ($cathash->{$newitem} eq '') {
11352: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 11353: $adds{$newitem} = 1;
11354: }
11355: } else {
11356: my $newitem = 'instcode::0';
1.57 raeburn 11357: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 11358: $adds{$newitem} = 1;
11359: }
11360: }
1.120 raeburn 11361: if ($env{'form.communities'} eq '1') {
11362: if (ref($cathash) eq 'HASH') {
11363: my $newitem = 'communities::0';
11364: if ($cathash->{$newitem} eq '') {
11365: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
11366: $adds{$newitem} = 1;
11367: }
11368: } else {
11369: my $newitem = 'communities::0';
11370: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
11371: $adds{$newitem} = 1;
11372: }
11373: }
1.272 raeburn 11374: if ($env{'form.placement'} eq '1') {
11375: if (ref($cathash) eq 'HASH') {
11376: my $newitem = 'placement::0';
11377: if ($cathash->{$newitem} eq '') {
11378: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.placement_pos'};
11379: $adds{$newitem} = 1;
11380: }
11381: } else {
11382: my $newitem = 'placement::0';
11383: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.placement_pos'};
11384: $adds{$newitem} = 1;
11385: }
11386: }
1.48 raeburn 11387: if ($env{'form.addcategory_name'} ne '') {
1.120 raeburn 11388: if (($env{'form.addcategory_name'} ne 'instcode') &&
1.272 raeburn 11389: ($env{'form.addcategory_name'} ne 'communities') &&
11390: ($env{'form.addcategory_name'} ne 'placement')) {
1.120 raeburn 11391: my $newitem = &escape($env{'form.addcategory_name'}).'::0';
11392: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
11393: $adds{$newitem} = 1;
11394: }
1.48 raeburn 11395: }
1.57 raeburn 11396: my $putresult;
1.48 raeburn 11397: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
11398: if (keys(%deletions) > 0) {
11399: foreach my $key (keys(%deletions)) {
11400: if ($predelallitems{$key} ne '') {
11401: $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
11402: }
11403: }
11404: }
11405: my (@chkcats,@chktrails,%chkallitems);
1.57 raeburn 11406: &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
1.48 raeburn 11407: if (ref($chkcats[0]) eq 'ARRAY') {
11408: my $depth = 0;
11409: my $chg = 0;
11410: for (my $i=0; $i<@{$chkcats[0]}; $i++) {
11411: my $name = $chkcats[0][$i];
11412: my $item;
11413: if ($name eq '') {
11414: $chg ++;
11415: } else {
11416: $item = &escape($name).'::0';
11417: if ($chg) {
1.57 raeburn 11418: $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
1.48 raeburn 11419: }
11420: $depth ++;
1.57 raeburn 11421: &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
1.48 raeburn 11422: $depth --;
11423: }
11424: }
11425: }
1.57 raeburn 11426: }
11427: if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
11428: $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
1.48 raeburn 11429: if ($putresult eq 'ok') {
1.57 raeburn 11430: my %title = (
1.120 raeburn 11431: togglecats => 'Show/Hide a course in catalog',
11432: categorize => 'Assign a category to a course',
11433: togglecatscomm => 'Show/Hide a community in catalog',
11434: categorizecomm => 'Assign a category to a community',
1.57 raeburn 11435: );
11436: my %level = (
1.120 raeburn 11437: dom => 'set in Domain ("Modify Course/Community")',
11438: crs => 'set in Course ("Course Configuration")',
11439: comm => 'set in Community ("Community Configuration")',
1.238 raeburn 11440: none => 'No catalog',
11441: std => 'Standard catalog',
11442: domonly => 'Domain-only catalog',
11443: codesrch => 'Code search form',
1.57 raeburn 11444: );
1.48 raeburn 11445: $resulttext = &mt('Changes made:').'<ul>';
1.57 raeburn 11446: if ($changes{'togglecats'}) {
11447: $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>';
11448: }
11449: if ($changes{'categorize'}) {
11450: $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
1.48 raeburn 11451: }
1.120 raeburn 11452: if ($changes{'togglecatscomm'}) {
11453: $resulttext .= '<li>'.&mt("$title{'togglecatscomm'} $level{$env{'form.togglecatscomm'}}").'</li>';
11454: }
11455: if ($changes{'categorizecomm'}) {
11456: $resulttext .= '<li>'.&mt("$title{'categorizecomm'} $level{$env{'form.categorizecomm'}}").'</li>';
11457: }
1.238 raeburn 11458: if ($changes{'unauth'}) {
11459: $resulttext .= '<li>'.&mt('Catalog type for unauthenticated users set to "'.$level{$env{'form.coursecat_unauth'}}.'"').'</li>';
11460: }
11461: if ($changes{'auth'}) {
11462: $resulttext .= '<li>'.&mt('Catalog type for authenticated users set to "'.$level{$env{'form.coursecat_auth'}}.'"').'</li>';
11463: }
1.57 raeburn 11464: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
11465: my $cathash;
11466: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
11467: $cathash = $domconfig{'coursecategories'}{'cats'};
11468: } else {
11469: $cathash = {};
11470: }
11471: my (@cats,@trails,%allitems);
11472: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
11473: if (keys(%deletions) > 0) {
11474: $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
11475: foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) {
11476: $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
11477: }
11478: $resulttext .= '</ul></li>';
11479: }
11480: if (keys(%reorderings) > 0) {
11481: my %sort_by_trail;
11482: $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
11483: foreach my $key (keys(%reorderings)) {
11484: if ($allitems{$key} ne '') {
11485: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
11486: }
1.48 raeburn 11487: }
1.57 raeburn 11488: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
11489: $resulttext .= '<li>'.$trails[$trail].'</li>';
11490: }
11491: $resulttext .= '</ul></li>';
1.48 raeburn 11492: }
1.57 raeburn 11493: if (keys(%adds) > 0) {
11494: my %sort_by_trail;
11495: $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
11496: foreach my $key (keys(%adds)) {
11497: if ($allitems{$key} ne '') {
11498: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
11499: }
11500: }
11501: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
11502: $resulttext .= '<li>'.$trails[$trail].'</li>';
1.48 raeburn 11503: }
1.57 raeburn 11504: $resulttext .= '</ul></li>';
1.48 raeburn 11505: }
11506: }
11507: $resulttext .= '</ul>';
1.239 raeburn 11508: if ($changes{'unauth'} || $changes{'auth'}) {
1.246 raeburn 11509: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
11510: if ($changes{'auth'}) {
11511: $domdefaults{'catauth'} = $domconfig{'coursecategories'}{'auth'};
11512: }
11513: if ($changes{'unauth'}) {
11514: $domdefaults{'catunauth'} = $domconfig{'coursecategories'}{'unauth'};
11515: }
11516: my $cachetime = 24*60*60;
11517: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.239 raeburn 11518: if (ref($lastactref) eq 'HASH') {
1.246 raeburn 11519: $lastactref->{'domdefaults'} = 1;
1.239 raeburn 11520: }
11521: }
1.48 raeburn 11522: } else {
11523: $resulttext = '<span class="LC_error">'.
1.57 raeburn 11524: &mt('An error occurred: [_1]',$putresult).'</span>';
1.48 raeburn 11525: }
11526: } else {
1.120 raeburn 11527: $resulttext = &mt('No changes made to course and community categories');
1.48 raeburn 11528: }
11529: return $resulttext;
11530: }
11531:
1.69 raeburn 11532: sub modify_serverstatuses {
11533: my ($dom,%domconfig) = @_;
11534: my ($resulttext,%changes,%currserverstatus,%newserverstatus);
11535: if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
11536: %currserverstatus = %{$domconfig{'serverstatuses'}};
11537: }
11538: my @pages = &serverstatus_pages();
11539: foreach my $type (@pages) {
11540: $newserverstatus{$type}{'namedusers'} = '';
11541: $newserverstatus{$type}{'machines'} = '';
11542: if (defined($env{'form.'.$type.'_namedusers'})) {
11543: my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
11544: my @okusers;
11545: foreach my $user (@users) {
11546: my ($uname,$udom) = split(/:/,$user);
11547: if (($udom =~ /^$match_domain$/) &&
11548: (&Apache::lonnet::domain($udom)) &&
11549: ($uname =~ /^$match_username$/)) {
11550: if (!grep(/^\Q$user\E/,@okusers)) {
11551: push(@okusers,$user);
11552: }
11553: }
11554: }
11555: if (@okusers > 0) {
11556: @okusers = sort(@okusers);
11557: $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
11558: }
11559: }
11560: if (defined($env{'form.'.$type.'_machines'})) {
11561: my @machines = split(/,/,$env{'form.'.$type.'_machines'});
11562: my @okmachines;
11563: foreach my $ip (@machines) {
11564: my @parts = split(/\./,$ip);
11565: next if (@parts < 4);
11566: my $badip = 0;
11567: for (my $i=0; $i<4; $i++) {
11568: if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
11569: $badip = 1;
11570: last;
11571: }
11572: }
11573: if (!$badip) {
11574: push(@okmachines,$ip);
11575: }
11576: }
11577: @okmachines = sort(@okmachines);
11578: $newserverstatus{$type}{'machines'} = join(',',@okmachines);
11579: }
11580: }
11581: my %serverstatushash = (
11582: serverstatuses => \%newserverstatus,
11583: );
11584: foreach my $type (@pages) {
1.83 raeburn 11585: foreach my $setting ('namedusers','machines') {
1.84 raeburn 11586: my (@current,@new);
1.83 raeburn 11587: if (ref($currserverstatus{$type}) eq 'HASH') {
1.84 raeburn 11588: if ($currserverstatus{$type}{$setting} ne '') {
11589: @current = split(/,/,$currserverstatus{$type}{$setting});
11590: }
11591: }
11592: if ($newserverstatus{$type}{$setting} ne '') {
11593: @new = split(/,/,$newserverstatus{$type}{$setting});
1.83 raeburn 11594: }
11595: if (@current > 0) {
11596: if (@new > 0) {
11597: foreach my $item (@current) {
11598: if (!grep(/^\Q$item\E$/,@new)) {
11599: $changes{$type}{$setting} = 1;
1.82 raeburn 11600: last;
11601: }
11602: }
1.84 raeburn 11603: foreach my $item (@new) {
11604: if (!grep(/^\Q$item\E$/,@current)) {
11605: $changes{$type}{$setting} = 1;
11606: last;
1.82 raeburn 11607: }
11608: }
11609: } else {
1.83 raeburn 11610: $changes{$type}{$setting} = 1;
1.69 raeburn 11611: }
1.83 raeburn 11612: } elsif (@new > 0) {
11613: $changes{$type}{$setting} = 1;
1.69 raeburn 11614: }
11615: }
11616: }
11617: if (keys(%changes) > 0) {
1.81 raeburn 11618: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 11619: my $putresult = &Apache::lonnet::put_dom('configuration',
11620: \%serverstatushash,$dom);
11621: if ($putresult eq 'ok') {
11622: $resulttext .= &mt('Changes made:').'<ul>';
11623: foreach my $type (@pages) {
1.84 raeburn 11624: if (ref($changes{$type}) eq 'HASH') {
1.69 raeburn 11625: $resulttext .= '<li>'.$titles->{$type}.'<ul>';
1.84 raeburn 11626: if ($changes{$type}{'namedusers'}) {
1.69 raeburn 11627: if ($newserverstatus{$type}{'namedusers'} eq '') {
11628: $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n";
11629: } else {
11630: $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n";
11631: }
1.84 raeburn 11632: }
11633: if ($changes{$type}{'machines'}) {
1.69 raeburn 11634: if ($newserverstatus{$type}{'machines'} eq '') {
11635: $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n";
11636: } else {
11637: $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n";
11638: }
11639:
11640: }
11641: $resulttext .= '</ul></li>';
11642: }
11643: }
11644: $resulttext .= '</ul>';
11645: } else {
11646: $resulttext = '<span class="LC_error">'.
11647: &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>';
11648:
11649: }
11650: } else {
11651: $resulttext = &mt('No changes made to access to server status pages');
11652: }
11653: return $resulttext;
11654: }
11655:
1.118 jms 11656: sub modify_helpsettings {
1.122 jms 11657: my ($r,$dom,$confname,%domconfig) = @_;
1.166 raeburn 11658: my ($resulttext,$errors,%changes,%helphash);
11659: my %defaultchecked = ('submitbugs' => 'on');
11660: my @offon = ('off','on');
1.118 jms 11661: my @toggles = ('submitbugs');
11662: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
11663: foreach my $item (@toggles) {
1.166 raeburn 11664: if ($defaultchecked{$item} eq 'on') {
11665: if ($domconfig{'helpsettings'}{$item} eq '') {
11666: if ($env{'form.'.$item} eq '0') {
11667: $changes{$item} = 1;
11668: }
11669: } elsif ($domconfig{'helpsettings'}{$item} ne $env{'form.'.$item}) {
11670: $changes{$item} = 1;
11671: }
11672: } elsif ($defaultchecked{$item} eq 'off') {
11673: if ($domconfig{'helpsettings'}{$item} eq '') {
11674: if ($env{'form.'.$item} eq '1') {
11675: $changes{$item} = 1;
11676: }
11677: } elsif ($domconfig{'helpsettings'}{$item} ne $env{'form.'.$item}) {
11678: $changes{$item} = 1;
11679: }
11680: }
1.210 raeburn 11681: if (($env{'form.'.$item} eq '0') || ($env{'form.'.$item} eq '1')) {
1.166 raeburn 11682: $helphash{'helpsettings'}{$item} = $env{'form.'.$item};
11683: }
11684: }
1.118 jms 11685: }
1.123 jms 11686: my $putresult;
11687: if (keys(%changes) > 0) {
1.166 raeburn 11688: $putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom);
1.168 raeburn 11689: if ($putresult eq 'ok') {
1.166 raeburn 11690: $resulttext = &mt('Changes made:').'<ul>';
11691: foreach my $item (sort(keys(%changes))) {
11692: if ($item eq 'submitbugs') {
11693: $resulttext .= '<li>'.&mt('Display link to: [_1] set to "'.$offon[$env{'form.'.$item}].'".',
11694: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
11695: &mt('LON-CAPA bug tracker'),600,500)).'</li>';
11696: }
11697: }
11698: $resulttext .= '</ul>';
11699: } else {
11700: $resulttext = &mt('No changes made to help settings');
1.168 raeburn 11701: $errors .= '<li><span class="LC_error">'.
11702: &mt('An error occurred storing the settings: [_1]',
11703: $putresult).'</span></li>';
1.166 raeburn 11704: }
1.118 jms 11705: }
11706: if ($errors) {
1.168 raeburn 11707: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.118 jms 11708: $errors.'</ul>';
11709: }
11710: return $resulttext;
11711: }
11712:
1.121 raeburn 11713: sub modify_coursedefaults {
1.212 raeburn 11714: my ($dom,$lastactref,%domconfig) = @_;
1.121 raeburn 11715: my ($resulttext,$errors,%changes,%defaultshash);
1.257 raeburn 11716: my %defaultchecked = (
11717: 'canuse_pdfforms' => 'off',
11718: 'uselcmath' => 'on',
11719: 'usejsme' => 'on'
11720: );
11721: my @toggles = ('canuse_pdfforms','uselcmath','usejsme');
1.198 raeburn 11722: my @numbers = ('anonsurvey_threshold','uploadquota_official','uploadquota_unofficial',
1.276 raeburn 11723: 'uploadquota_community','uploadquota_textbook','uploadquota_placement',
11724: 'mysqltables_official','mysqltables_unofficial','mysqltables_community',
11725: 'mysqltables_textbook','mysqltables_placement');
1.271 raeburn 11726: my @types = ('official','unofficial','community','textbook','placement');
1.198 raeburn 11727: my %staticdefaults = (
11728: anonsurvey_threshold => 10,
11729: uploadquota => 500,
1.257 raeburn 11730: postsubmit => 60,
1.276 raeburn 11731: mysqltables => 172800,
1.198 raeburn 11732: );
1.121 raeburn 11733:
11734: $defaultshash{'coursedefaults'} = {};
11735:
11736: if (ref($domconfig{'coursedefaults'}) ne 'HASH') {
11737: if ($domconfig{'coursedefaults'} eq '') {
11738: $domconfig{'coursedefaults'} = {};
11739: }
11740: }
11741:
11742: if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
11743: foreach my $item (@toggles) {
11744: if ($defaultchecked{$item} eq 'on') {
11745: if (($domconfig{'coursedefaults'}{$item} eq '') &&
11746: ($env{'form.'.$item} eq '0')) {
11747: $changes{$item} = 1;
1.192 raeburn 11748: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
1.121 raeburn 11749: $changes{$item} = 1;
11750: }
11751: } elsif ($defaultchecked{$item} eq 'off') {
11752: if (($domconfig{'coursedefaults'}{$item} eq '') &&
11753: ($env{'form.'.$item} eq '1')) {
11754: $changes{$item} = 1;
11755: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
11756: $changes{$item} = 1;
11757: }
11758: }
11759: $defaultshash{'coursedefaults'}{$item} = $env{'form.'.$item};
11760: }
1.198 raeburn 11761: foreach my $item (@numbers) {
11762: my ($currdef,$newdef);
1.208 raeburn 11763: $newdef = $env{'form.'.$item};
1.198 raeburn 11764: if ($item eq 'anonsurvey_threshold') {
11765: $currdef = $domconfig{'coursedefaults'}{$item};
11766: $newdef =~ s/\D//g;
11767: if ($newdef eq '' || $newdef < 1) {
11768: $newdef = 1;
11769: }
11770: $defaultshash{'coursedefaults'}{$item} = $newdef;
11771: } else {
1.276 raeburn 11772: my ($setting,$type) = ($item =~ /^(uploadquota|mysqltables)_(\w+)$/);
11773: if (ref($domconfig{'coursedefaults'}{$setting}) eq 'HASH') {
11774: $currdef = $domconfig{'coursedefaults'}{$setting}{$type};
1.198 raeburn 11775: }
11776: $newdef =~ s/[^\w.\-]//g;
1.276 raeburn 11777: $defaultshash{'coursedefaults'}{$setting}{$type} = $newdef;
1.198 raeburn 11778: }
11779: if ($currdef ne $newdef) {
11780: my $staticdef;
11781: if ($item eq 'anonsurvey_threshold') {
11782: unless (($currdef eq '') && ($newdef == $staticdefaults{$item})) {
11783: $changes{$item} = 1;
11784: }
1.276 raeburn 11785: } elsif ($item =~ /^(uploadquota|mysqltables)_/) {
11786: my $setting = $1;
11787: unless (($currdef eq '') && ($newdef == $staticdefaults{$setting})) {
11788: $changes{$setting} = 1;
1.198 raeburn 11789: }
11790: }
1.139 raeburn 11791: }
11792: }
1.264 raeburn 11793: my $currclone = $domconfig{'coursedefaults'}{'canclone'};
11794: my @currclonecode;
11795: if (ref($currclone) eq 'HASH') {
11796: if (ref($currclone->{'instcode'}) eq 'ARRAY') {
11797: @currclonecode = @{$currclone->{'instcode'}};
11798: }
11799: }
11800: my $newclone;
11801: if ($env{'form.canclone'} =~ /^(none|domain|instcode)$/) {
11802: $newclone = $env{'form.canclone'};
11803: }
11804: if ($newclone eq 'instcode') {
11805: my @newcodes = &Apache::loncommon::get_env_multiple('form.clonecode');
11806: my (%codedefaults,@code_order,@clonecode);
11807: &Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
11808: \@code_order);
11809: foreach my $item (@code_order) {
11810: if (grep(/^\Q$item\E$/,@newcodes)) {
11811: push(@clonecode,$item);
11812: }
11813: }
11814: if (@clonecode) {
11815: $defaultshash{'coursedefaults'}{'canclone'} = { $newclone => \@clonecode };
11816: my @diffs = &Apache::loncommon::compare_arrays(\@currclonecode,\@clonecode);
11817: if (@diffs) {
11818: $changes{'canclone'} = 1;
11819: }
11820: } else {
11821: $newclone eq '';
11822: }
11823: } elsif ($newclone ne '') {
11824: $defaultshash{'coursedefaults'}{'canclone'} = $newclone;
11825: }
11826: if ($newclone ne $currclone) {
11827: $changes{'canclone'} = 1;
11828: }
1.257 raeburn 11829: my %credits;
11830: foreach my $type (@types) {
11831: unless ($type eq 'community') {
11832: $credits{$type} = $env{'form.'.$type.'_credits'};
11833: $credits{$type} =~ s/[^\d.]+//g;
11834: }
11835: }
11836: if ((ref($domconfig{'coursedefaults'}{'coursecredits'}) ne 'HASH') &&
11837: ($env{'form.coursecredits'} eq '1')) {
11838: $changes{'coursecredits'} = 1;
11839: foreach my $type (keys(%credits)) {
11840: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
11841: }
11842: } else {
11843: if ($env{'form.coursecredits'} eq '1') {
11844: foreach my $type (@types) {
11845: unless ($type eq 'community') {
11846: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type} ne $credits{$type}) {
11847: $changes{'coursecredits'} = 1;
11848: }
11849: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
11850: }
11851: }
11852: } elsif (ref($domconfig{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
11853: foreach my $type (@types) {
11854: unless ($type eq 'community') {
11855: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type}) {
11856: $changes{'coursecredits'} = 1;
11857: last;
11858: }
11859: }
11860: }
11861: }
11862: }
11863: if ($env{'form.postsubmit'} eq '1') {
11864: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'on';
11865: my %currtimeout;
11866: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
11867: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'off') {
11868: $changes{'postsubmit'} = 1;
11869: }
11870: if (ref($domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
11871: %currtimeout = %{$domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}};
11872: }
11873: } else {
11874: $changes{'postsubmit'} = 1;
11875: }
11876: foreach my $type (@types) {
11877: my $timeout = $env{'form.'.$type.'_timeout'};
11878: $timeout =~ s/\D//g;
11879: if ($timeout == $staticdefaults{'postsubmit'}) {
11880: $timeout = '';
11881: } elsif (($timeout eq '') || ($timeout =~ /^0+$/)) {
11882: $timeout = '0';
11883: }
11884: unless ($timeout eq '') {
11885: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type} = $timeout;
11886: }
11887: if (exists($currtimeout{$type})) {
11888: if ($timeout ne $currtimeout{$type}) {
11889: $changes{'postsubmit'} = 1;
11890: }
11891: } elsif ($timeout ne '') {
11892: $changes{'postsubmit'} = 1;
11893: }
11894: }
11895: } else {
11896: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'off';
11897: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
11898: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'on') {
11899: $changes{'postsubmit'} = 1;
11900: }
11901: } else {
11902: $changes{'postsubmit'} = 1;
11903: }
1.192 raeburn 11904: }
1.121 raeburn 11905: }
11906: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
11907: $dom);
11908: if ($putresult eq 'ok') {
11909: if (keys(%changes) > 0) {
1.213 raeburn 11910: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.257 raeburn 11911: if (($changes{'canuse_pdfforms'}) || ($changes{'uploadquota'}) || ($changes{'postsubmit'}) ||
1.264 raeburn 11912: ($changes{'coursecredits'}) || ($changes{'uselcmath'}) || ($changes{'usejsme'}) ||
1.276 raeburn 11913: ($changes{'canclone'}) || ($changes{'mysqltables'})) {
1.257 raeburn 11914: foreach my $item ('canuse_pdfforms','uselcmath','usejsme') {
11915: if ($changes{$item}) {
11916: $domdefaults{$item}=$defaultshash{'coursedefaults'}{$item};
11917: }
11918: }
1.192 raeburn 11919: if ($changes{'coursecredits'}) {
11920: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
1.257 raeburn 11921: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'coursecredits'}})) {
11922: $domdefaults{$type.'credits'} =
11923: $defaultshash{'coursedefaults'}{'coursecredits'}{$type};
11924: }
11925: }
11926: }
11927: if ($changes{'postsubmit'}) {
11928: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
11929: $domdefaults{'postsubmit'} = $defaultshash{'coursedefaults'}{'postsubmit'}{'client'};
11930: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
11931: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}})) {
11932: $domdefaults{$type.'postsubtimeout'} =
11933: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
11934: }
11935: }
1.192 raeburn 11936: }
11937: }
1.198 raeburn 11938: if ($changes{'uploadquota'}) {
11939: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
11940: foreach my $type (@types) {
11941: $domdefaults{$type.'quota'}=$defaultshash{'coursedefaults'}{'uploadquota'}{$type};
11942: }
11943: }
11944: }
1.264 raeburn 11945: if ($changes{'canclone'}) {
11946: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
11947: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
11948: my @clonecodes = @{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}};
11949: if (@clonecodes) {
11950: $domdefaults{'canclone'} = join('+',@clonecodes);
11951: }
11952: }
11953: } else {
11954: $domdefaults{'canclone'}=$defaultshash{'coursedefaults'}{'canclone'};
11955: }
11956: }
1.121 raeburn 11957: my $cachetime = 24*60*60;
11958: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 11959: if (ref($lastactref) eq 'HASH') {
11960: $lastactref->{'domdefaults'} = 1;
11961: }
1.121 raeburn 11962: }
11963: $resulttext = &mt('Changes made:').'<ul>';
11964: foreach my $item (sort(keys(%changes))) {
11965: if ($item eq 'canuse_pdfforms') {
11966: if ($env{'form.'.$item} eq '1') {
11967: $resulttext .= '<li>'.&mt("Course/Community users can create/upload PDF forms set to 'on'").'</li>';
11968: } else {
11969: $resulttext .= '<li>'.&mt('Course/Community users can create/upload PDF forms set to "off"').'</li>';
11970: }
1.257 raeburn 11971: } elsif ($item eq 'uselcmath') {
11972: if ($env{'form.'.$item} eq '1') {
11973: $resulttext .= '<li>'.&mt('Math preview uses LON-CAPA previewer (javascript), if supported by browser.').'</li>';
11974: } else {
11975: $resulttext .= '<li>'.&mt('Math preview uses DragMath (Java), if supported by client OS.').'</li>';
11976: }
11977: } elsif ($item eq 'usejsme') {
11978: if ($env{'form.'.$item} eq '1') {
11979: $resulttext .= '<li>'.&mt('Molecule editor uses JSME (HTML5), if supported by browser.').'</li>';
11980: } else {
11981: $resulttext .= '<li>'.&mt('Molecule editor uses JME (Java), if supported by client OS.').'</li>';
11982: }
1.139 raeburn 11983: } elsif ($item eq 'anonsurvey_threshold') {
1.192 raeburn 11984: $resulttext .= '<li>'.&mt('Responder count required for display of anonymous survey submissions set to [_1].',$defaultshash{'coursedefaults'}{'anonsurvey_threshold'}).'</li>';
1.198 raeburn 11985: } elsif ($item eq 'uploadquota') {
11986: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
11987: $resulttext .= '<li>'.&mt('Default quota for content uploaded to a course/community via Course Editor set as follows:').'<ul>'.
11988: '<li>'.&mt('Official courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'official'}.'</b>').'</li>'.
11989: '<li>'.&mt('Unofficial courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'unofficial'}.'</b>').'</li>'.
1.216 raeburn 11990: '<li>'.&mt('Textbook courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'textbook'}.'</b>').'</li>'.
1.271 raeburn 11991: '<li>'.&mt('Placement tests: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'placement'}.'</b>').'</li>'.
1.198 raeburn 11992: '<li>'.&mt('Communities: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'community'}.'</b>').'</li>'.
11993: '</ul>'.
11994: '</li>';
11995: } else {
11996: $resulttext .= '<li>'.&mt('Default quota for content uploaded via Course Editor remains default: [_1] MB',$staticdefaults{'uploadquota'}).'</li>';
11997: }
1.276 raeburn 11998: } elsif ($item eq 'mysqltables') {
11999: if (ref($defaultshash{'coursedefaults'}{'mysqltables'}) eq 'HASH') {
12000: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver').'<ul>'.
12001: '<li>'.&mt('Official courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'official'}.'</b>').'</li>'.
12002: '<li>'.&mt('Unofficial courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'unofficial'}.'</b>').'</li>'.
12003: '<li>'.&mt('Textbook courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'textbook'}.'</b>').'</li>'.
12004: '<li>'.&mt('Placement tests: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'placement'}.'</b>').'</li>'.
12005: '<li>'.&mt('Communities: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'community'}.'</b>').'</li>'.
12006: '</ul>'.
12007: '</li>';
12008: } else {
12009: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver remains default: [_1] s',$staticdefaults{'uploadquota'}).'</li>';
12010: }
1.257 raeburn 12011: } elsif ($item eq 'postsubmit') {
12012: if ($domdefaults{'postsubmit'} eq 'off') {
12013: $resulttext .= '<li>'.&mt('Submit button(s) remain enabled on page after student makes submission.');
12014: } else {
12015: $resulttext .= '<li>'.&mt('Submit button(s) disabled on page after student makes submission').'; ';
12016: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
12017: $resulttext .= &mt('durations:').'<ul>';
12018: foreach my $type (@types) {
12019: $resulttext .= '<li>';
12020: my $timeout;
12021: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
12022: $timeout = $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
12023: }
12024: my $display;
12025: if ($timeout eq '0') {
12026: $display = &mt('unlimited');
12027: } elsif ($timeout eq '') {
12028: $display = &mt('[quant,_1,second] (default)',$staticdefaults{'postsubmit'});
12029: } else {
12030: $display = &mt('[quant,_1,second]',$timeout);
12031: }
12032: if ($type eq 'community') {
12033: $resulttext .= &mt('Communities');
12034: } elsif ($type eq 'official') {
12035: $resulttext .= &mt('Official courses');
12036: } elsif ($type eq 'unofficial') {
12037: $resulttext .= &mt('Unofficial courses');
12038: } elsif ($type eq 'textbook') {
12039: $resulttext .= &mt('Textbook courses');
1.271 raeburn 12040: } elsif ($type eq 'placement') {
12041: $resulttext .= &mt('Placement tests');
1.257 raeburn 12042: }
12043: $resulttext .= ' -- '.$display.'</li>';
12044: }
12045: $resulttext .= '</ul>';
12046: }
12047: $resulttext .= '</li>';
12048: }
1.192 raeburn 12049: } elsif ($item eq 'coursecredits') {
12050: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
12051: if (($domdefaults{'officialcredits'} eq '') &&
1.216 raeburn 12052: ($domdefaults{'unofficialcredits'} eq '') &&
12053: ($domdefaults{'textbookcredits'} eq '')) {
1.192 raeburn 12054: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
12055: } else {
12056: $resulttext .= '<li>'.&mt('Student credits can be set per course by a Domain Coordinator, with the following defaults applying:').'<ul>'.
12057: '<li>'.&mt('Official courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'official'}).'</li>'.
12058: '<li>'.&mt('Unofficial courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'}).'</li>'.
1.216 raeburn 12059: '<li>'.&mt('Textbook courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'textbook'}).'</li>'.
1.192 raeburn 12060: '</ul>'.
12061: '</li>';
12062: }
12063: } else {
12064: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
12065: }
1.264 raeburn 12066: } elsif ($item eq 'canclone') {
12067: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
12068: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
12069: my $clonecodes = join(' '.&mt('and').' ',@{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}});
12070: $resulttext .= '<li>'.&mt('By default, official courses can be cloned from existing courses with the same: [_1]','<b>'.$clonecodes.'</b>').'</li>';
12071: }
12072: } elsif ($defaultshash{'coursedefaults'}{'canclone'} eq 'domain') {
12073: $resulttext .= '<li>'.&mt('By default, a course requester can clone any course from his/her domain.').'</li>';
12074: } else {
12075: $resulttext .= '<li>'.&mt('By default, only course owner and coordinators may clone a course.').'</li>';
12076: }
1.140 raeburn 12077: }
1.121 raeburn 12078: }
12079: $resulttext .= '</ul>';
12080: } else {
12081: $resulttext = &mt('No changes made to course defaults');
12082: }
12083: } else {
12084: $resulttext = '<span class="LC_error">'.
12085: &mt('An error occurred: [_1]',$putresult).'</span>';
12086: }
12087: return $resulttext;
12088: }
12089:
1.231 raeburn 12090: sub modify_selfenrollment {
12091: my ($dom,$lastactref,%domconfig) = @_;
12092: my ($resulttext,$errors,%changes,%selfenrollhash,%ordered);
1.271 raeburn 12093: my @types = ('official','unofficial','community','textbook','placement');
1.231 raeburn 12094: my %titles = &tool_titles();
1.232 raeburn 12095: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
12096: ($ordered{'admin'},my $titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
1.231 raeburn 12097: $ordered{'default'} = ['types','registered','approval','limit'];
12098:
12099: my (%roles,%shown,%toplevel);
12100: $roles{'0'} = &Apache::lonnet::plaintext('dc');
12101:
12102: if (ref($domconfig{'selfenrollment'}) ne 'HASH') {
12103: if ($domconfig{'selfenrollment'} eq '') {
12104: $domconfig{'selfenrollment'} = {};
12105: }
12106: }
12107: %toplevel = (
12108: admin => 'Configuration Rights',
12109: default => 'Default settings',
12110: validation => 'Validation of self-enrollment requests',
12111: );
1.233 raeburn 12112: my ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
1.231 raeburn 12113:
12114: if (ref($ordered{'admin'}) eq 'ARRAY') {
12115: foreach my $item (@{$ordered{'admin'}}) {
12116: foreach my $type (@types) {
12117: if ($env{'form.selfenrolladmin_'.$item.'_'.$type}) {
12118: $selfenrollhash{'admin'}{$type}{$item} = 1;
12119: } else {
12120: $selfenrollhash{'admin'}{$type}{$item} = 0;
12121: }
12122: if (ref($domconfig{'selfenrollment'}{'admin'}) eq 'HASH') {
12123: if (ref($domconfig{'selfenrollment'}{'admin'}{$type}) eq 'HASH') {
12124: if ($selfenrollhash{'admin'}{$type}{$item} ne
12125: $domconfig{'selfenrollment'}{'admin'}{$type}{$item}) {
12126: push(@{$changes{'admin'}{$type}},$item);
12127: }
12128: } else {
12129: if (!$selfenrollhash{'admin'}{$type}{$item}) {
12130: push(@{$changes{'admin'}{$type}},$item);
12131: }
12132: }
12133: } elsif (!$selfenrollhash{'admin'}{$type}{$item}) {
12134: push(@{$changes{'admin'}{$type}},$item);
12135: }
12136: }
12137: }
12138: }
12139:
12140: foreach my $item (@{$ordered{'default'}}) {
12141: foreach my $type (@types) {
12142: my $value = $env{'form.selfenrolldefault_'.$item.'_'.$type};
12143: if ($item eq 'types') {
12144: unless (($value eq 'all') || ($value eq 'dom')) {
12145: $value = '';
12146: }
12147: } elsif ($item eq 'registered') {
12148: unless ($value eq '1') {
12149: $value = 0;
12150: }
12151: } elsif ($item eq 'approval') {
12152: unless ($value =~ /^[012]$/) {
12153: $value = 0;
12154: }
12155: } else {
12156: unless (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
12157: $value = 'none';
12158: }
12159: }
12160: $selfenrollhash{'default'}{$type}{$item} = $value;
12161: if (ref($domconfig{'selfenrollment'}{'default'}) eq 'HASH') {
12162: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
12163: if ($selfenrollhash{'default'}{$type}{$item} ne
12164: $domconfig{'selfenrollment'}{'default'}{$type}{$item}) {
12165: push(@{$changes{'default'}{$type}},$item);
12166: }
12167: } else {
12168: push(@{$changes{'default'}{$type}},$item);
12169: }
12170: } else {
12171: push(@{$changes{'default'}{$type}},$item);
12172: }
12173: if ($item eq 'limit') {
12174: if (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
12175: $env{'form.selfenrolldefault_cap_'.$type} =~ s/\D//g;
12176: if ($env{'form.selfenrolldefault_cap_'.$type} ne '') {
12177: $selfenrollhash{'default'}{$type}{'cap'} = $env{'form.selfenrolldefault_cap_'.$type};
12178: }
12179: } else {
12180: $selfenrollhash{'default'}{$type}{'cap'} = '';
12181: }
12182: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
12183: if ($selfenrollhash{'default'}{$type}{'cap'} ne
12184: $domconfig{'selfenrollment'}{'admin'}{$type}{'cap'}) {
12185: push(@{$changes{'default'}{$type}},'cap');
12186: }
12187: } elsif ($selfenrollhash{'default'}{$type}{'cap'} ne '') {
12188: push(@{$changes{'default'}{$type}},'cap');
12189: }
12190: }
12191: }
12192: }
12193:
12194: foreach my $item (@{$itemsref}) {
12195: if ($item eq 'fields') {
12196: my @changed;
12197: @{$selfenrollhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.selfenroll_validation_'.$item);
12198: if (@{$selfenrollhash{'validation'}{$item}} > 0) {
12199: @{$selfenrollhash{'validation'}{$item}} = sort(@{$selfenrollhash{'validation'}{$item}});
12200: }
12201: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
12202: if (ref($domconfig{'selfenrollment'}{'validation'}{$item}) eq 'ARRAY') {
12203: @changed = &Apache::loncommon::compare_arrays($selfenrollhash{'validation'}{$item},
12204: $domconfig{'selfenrollment'}{'validation'}{$item});
12205: } else {
12206: @changed = @{$selfenrollhash{'validation'}{$item}};
12207: }
12208: } else {
12209: @changed = @{$selfenrollhash{'validation'}{$item}};
12210: }
12211: if (@changed) {
12212: if ($selfenrollhash{'validation'}{$item}) {
12213: $changes{'validation'}{$item} = join(', ',@{$selfenrollhash{'validation'}{$item}});
12214: } else {
12215: $changes{'validation'}{$item} = &mt('None');
12216: }
12217: }
12218: } else {
12219: $selfenrollhash{'validation'}{$item} = $env{'form.selfenroll_validation_'.$item};
12220: if ($item eq 'markup') {
12221: if ($env{'form.selfenroll_validation_'.$item}) {
12222: $env{'form.selfenroll_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
12223: }
12224: }
12225: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
12226: if ($domconfig{'selfenrollment'}{'validation'}{$item} ne $selfenrollhash{'validation'}{$item}) {
12227: $changes{'validation'}{$item} = $selfenrollhash{'validation'}{$item};
12228: }
12229: }
12230: }
12231: }
12232:
12233: my $putresult = &Apache::lonnet::put_dom('configuration',{'selfenrollment' => \%selfenrollhash},
12234: $dom);
12235: if ($putresult eq 'ok') {
12236: if (keys(%changes) > 0) {
12237: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
12238: $resulttext = &mt('Changes made:').'<ul>';
12239: foreach my $key ('admin','default','validation') {
12240: if (ref($changes{$key}) eq 'HASH') {
12241: $resulttext .= '<li>'.$toplevel{$key}.'<ul>';
12242: if ($key eq 'validation') {
12243: foreach my $item (@{$itemsref}) {
12244: if (exists($changes{$key}{$item})) {
12245: if ($item eq 'markup') {
12246: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
12247: '<br /><pre>'.$changes{$key}{$item}.'</pre>').'</li>';
12248: } else {
12249: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
12250: '<b>'.$changes{$key}{$item}.'</b>').'</li>';
12251: }
12252: }
12253: }
12254: } else {
12255: foreach my $type (@types) {
12256: if ($type eq 'community') {
12257: $roles{'1'} = &mt('Community personnel');
12258: } else {
12259: $roles{'1'} = &mt('Course personnel');
12260: }
12261: if (ref($changes{$key}{$type}) eq 'ARRAY') {
1.232 raeburn 12262: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
12263: if ($key eq 'admin') {
12264: my @mgrdc = ();
12265: if (ref($ordered{$key}) eq 'ARRAY') {
12266: foreach my $item (@{$ordered{'admin'}}) {
12267: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
12268: if ($selfenrollhash{$key}{$type}{$item} eq '0') {
12269: push(@mgrdc,$item);
12270: }
12271: }
12272: }
12273: if (@mgrdc) {
12274: $domdefaults{$type.'selfenrolladmdc'} = join(',',@mgrdc);
12275: } else {
12276: delete($domdefaults{$type.'selfenrolladmdc'});
12277: }
12278: }
12279: } else {
12280: if (ref($ordered{$key}) eq 'ARRAY') {
12281: foreach my $item (@{$ordered{$key}}) {
12282: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
12283: $domdefaults{$type.'selfenroll'.$item} =
12284: $selfenrollhash{$key}{$type}{$item};
12285: }
12286: }
12287: }
12288: }
12289: }
1.231 raeburn 12290: $resulttext .= '<li>'.$titles{$type}.'<ul>';
12291: foreach my $item (@{$ordered{$key}}) {
12292: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
12293: $resulttext .= '<li>';
12294: if ($key eq 'admin') {
12295: $resulttext .= &mt('[_1] -- management by: [_2]',$titlesref->{$item},
12296: '<b>'.$roles{$selfenrollhash{'admin'}{$type}{$item}}.'</b>');
12297: } else {
12298: $resulttext .= &mt('[_1] set to: [_2]',$titlesref->{$item},
12299: '<b>'.$descs{$item}{$selfenrollhash{'default'}{$type}{$item}}.'</b>');
12300: }
12301: $resulttext .= '</li>';
12302: }
12303: }
12304: $resulttext .= '</ul></li>';
12305: }
12306: }
12307: $resulttext .= '</ul></li>';
12308: }
12309: }
1.232 raeburn 12310: if ((exists($changes{'admin'})) || (exists($changes{'default'}))) {
12311: my $cachetime = 24*60*60;
12312: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
12313: if (ref($lastactref) eq 'HASH') {
12314: $lastactref->{'domdefaults'} = 1;
12315: }
12316: }
1.231 raeburn 12317: }
12318: $resulttext .= '</ul>';
12319: } else {
12320: $resulttext = &mt('No changes made to self-enrollment settings');
12321: }
12322: } else {
12323: $resulttext = '<span class="LC_error">'.
12324: &mt('An error occurred: [_1]',$putresult).'</span>';
12325: }
12326: return $resulttext;
12327: }
12328:
1.137 raeburn 12329: sub modify_usersessions {
1.212 raeburn 12330: my ($dom,$lastactref,%domconfig) = @_;
1.145 raeburn 12331: my @hostingtypes = ('version','excludedomain','includedomain');
12332: my @offloadtypes = ('primary','default');
12333: my %types = (
12334: remote => \@hostingtypes,
12335: hosted => \@hostingtypes,
12336: spares => \@offloadtypes,
12337: );
12338: my @prefixes = ('remote','hosted','spares');
1.137 raeburn 12339: my @lcversions = &Apache::lonnet::all_loncaparevs();
1.275 raeburn 12340: my (%by_ip,%by_location,@intdoms,@instdoms);
12341: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
1.138 raeburn 12342: my @locations = sort(keys(%by_location));
1.137 raeburn 12343: my (%defaultshash,%changes);
12344: foreach my $prefix (@prefixes) {
12345: $defaultshash{'usersessions'}{$prefix} = {};
12346: }
1.212 raeburn 12347: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.137 raeburn 12348: my $resulttext;
1.138 raeburn 12349: my %iphost = &Apache::lonnet::get_iphost();
1.137 raeburn 12350: foreach my $prefix (@prefixes) {
1.145 raeburn 12351: next if ($prefix eq 'spares');
12352: foreach my $type (@{$types{$prefix}}) {
1.137 raeburn 12353: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
12354: if ($type eq 'version') {
12355: my $value = $env{'form.'.$prefix.'_'.$type};
12356: my $okvalue;
12357: if ($value ne '') {
12358: if (grep(/^\Q$value\E$/,@lcversions)) {
12359: $okvalue = $value;
12360: }
12361: }
12362: if (ref($domconfig{'usersessions'}) eq 'HASH') {
12363: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
12364: if ($domconfig{'usersessions'}{$prefix}{$type} ne '') {
12365: if ($inuse == 0) {
12366: $changes{$prefix}{$type} = 1;
12367: } else {
12368: if ($okvalue ne $domconfig{'usersessions'}{$prefix}{$type}) {
12369: $changes{$prefix}{$type} = 1;
12370: }
12371: if ($okvalue ne '') {
12372: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
12373: }
12374: }
12375: } else {
12376: if (($inuse == 1) && ($okvalue ne '')) {
12377: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
12378: $changes{$prefix}{$type} = 1;
12379: }
12380: }
12381: } else {
12382: if (($inuse == 1) && ($okvalue ne '')) {
12383: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
12384: $changes{$prefix}{$type} = 1;
12385: }
12386: }
12387: } else {
12388: if (($inuse == 1) && ($okvalue ne '')) {
12389: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
12390: $changes{$prefix}{$type} = 1;
12391: }
12392: }
12393: } else {
12394: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
12395: my @okvals;
12396: foreach my $val (@vals) {
1.138 raeburn 12397: if ($val =~ /:/) {
12398: my @items = split(/:/,$val);
12399: foreach my $item (@items) {
12400: if (ref($by_location{$item}) eq 'ARRAY') {
12401: push(@okvals,$item);
12402: }
12403: }
12404: } else {
12405: if (ref($by_location{$val}) eq 'ARRAY') {
12406: push(@okvals,$val);
12407: }
1.137 raeburn 12408: }
12409: }
12410: @okvals = sort(@okvals);
12411: if (ref($domconfig{'usersessions'}) eq 'HASH') {
12412: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
12413: if (ref($domconfig{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
12414: if ($inuse == 0) {
12415: $changes{$prefix}{$type} = 1;
12416: } else {
12417: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
12418: my @changed = &Apache::loncommon::compare_arrays($domconfig{'usersessions'}{$prefix}{$type},$defaultshash{'usersessions'}{$prefix}{$type});
12419: if (@changed > 0) {
12420: $changes{$prefix}{$type} = 1;
12421: }
12422: }
12423: } else {
12424: if ($inuse == 1) {
12425: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
12426: $changes{$prefix}{$type} = 1;
12427: }
12428: }
12429: } else {
12430: if ($inuse == 1) {
12431: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
12432: $changes{$prefix}{$type} = 1;
12433: }
12434: }
12435: } else {
12436: if ($inuse == 1) {
12437: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
12438: $changes{$prefix}{$type} = 1;
12439: }
12440: }
12441: }
12442: }
12443: }
1.145 raeburn 12444:
12445: my @alldoms = &Apache::lonnet::all_domains();
1.149 raeburn 12446: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.145 raeburn 12447: my %spareid = ¤t_offloads_to($dom,$domconfig{'usersessions'},\%servers);
12448: my $savespares;
12449:
12450: foreach my $lonhost (sort(keys(%servers))) {
12451: my $serverhomeID =
12452: &Apache::lonnet::get_server_homeID($servers{$lonhost});
1.152 raeburn 12453: my $serverhostname = &Apache::lonnet::hostname($lonhost);
1.145 raeburn 12454: $defaultshash{'usersessions'}{'spares'}{$lonhost} = {};
12455: my %spareschg;
12456: foreach my $type (@{$types{'spares'}}) {
12457: my @okspares;
12458: my @checked = &Apache::loncommon::get_env_multiple('form.spare_'.$type.'_'.$lonhost);
12459: foreach my $server (@checked) {
1.152 raeburn 12460: if (&Apache::lonnet::hostname($server) ne '') {
12461: unless (&Apache::lonnet::hostname($server) eq $serverhostname) {
12462: unless (grep(/^\Q$server\E$/,@okspares)) {
12463: push(@okspares,$server);
12464: }
1.145 raeburn 12465: }
12466: }
12467: }
12468: my $new = $env{'form.newspare_'.$type.'_'.$lonhost};
12469: my $newspare;
1.152 raeburn 12470: if (($new ne '') && (&Apache::lonnet::hostname($new))) {
12471: unless (&Apache::lonnet::hostname($new) eq $serverhostname) {
1.145 raeburn 12472: $newspare = $new;
12473: }
12474: }
1.152 raeburn 12475: my @spares;
12476: if (($newspare ne '') && (!grep(/^\Q$newspare\E$/,@okspares))) {
12477: @spares = sort(@okspares,$newspare);
12478: } else {
12479: @spares = sort(@okspares);
12480: }
12481: $defaultshash{'usersessions'}{'spares'}{$lonhost}{$type} = \@spares;
1.145 raeburn 12482: if (ref($spareid{$lonhost}) eq 'HASH') {
12483: if (ref($spareid{$lonhost}{$type}) eq 'ARRAY') {
1.152 raeburn 12484: my @diffs = &Apache::loncommon::compare_arrays($spareid{$lonhost}{$type},\@spares);
1.145 raeburn 12485: if (@diffs > 0) {
12486: $spareschg{$type} = 1;
12487: }
12488: }
12489: }
12490: }
12491: if (keys(%spareschg) > 0) {
12492: $changes{'spares'}{$lonhost} = \%spareschg;
12493: }
12494: }
1.261 raeburn 12495: $defaultshash{'usersessions'}{'offloadnow'} = {};
12496: my @offloadnow = &Apache::loncommon::get_env_multiple('form.offloadnow');
12497: my @okoffload;
12498: if (@offloadnow) {
12499: foreach my $server (@offloadnow) {
12500: if (&Apache::lonnet::hostname($server) ne '') {
12501: unless (grep(/^\Q$server\E$/,@okoffload)) {
12502: push(@okoffload,$server);
12503: }
12504: }
12505: }
12506: if (@okoffload) {
12507: foreach my $lonhost (@okoffload) {
12508: $defaultshash{'usersessions'}{'offloadnow'}{$lonhost} = 1;
12509: }
12510: }
12511: }
1.145 raeburn 12512: if (ref($domconfig{'usersessions'}) eq 'HASH') {
12513: if (ref($domconfig{'usersessions'}{'spares'}) eq 'HASH') {
12514: if (ref($changes{'spares'}) eq 'HASH') {
12515: if (keys(%{$changes{'spares'}}) > 0) {
12516: $savespares = 1;
12517: }
12518: }
12519: } else {
12520: $savespares = 1;
12521: }
1.261 raeburn 12522: if (ref($domconfig{'usersessions'}{'offloadnow'}) eq 'HASH') {
12523: foreach my $lonhost (keys(%{$domconfig{'usersessions'}{'offloadnow'}})) {
12524: unless ($defaultshash{'usersessions'}{'offloadnow'}{$lonhost}) {
12525: $changes{'offloadnow'} = 1;
12526: last;
12527: }
12528: }
12529: unless ($changes{'offloadnow'}) {
12530: foreach my $lonhost (keys(%{$defaultshash{'usersessions'}{'offloadnow'}})) {
12531: unless ($domconfig{'usersessions'}{'offloadnow'}{$lonhost}) {
12532: $changes{'offloadnow'} = 1;
12533: last;
12534: }
12535: }
12536: }
12537: } elsif (@okoffload) {
12538: $changes{'offloadnow'} = 1;
12539: }
12540: } elsif (@okoffload) {
12541: $changes{'offloadnow'} = 1;
1.145 raeburn 12542: }
1.147 raeburn 12543: my $nochgmsg = &mt('No changes made to settings for user session hosting/offloading.');
12544: if ((keys(%changes) > 0) || ($savespares)) {
1.137 raeburn 12545: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
12546: $dom);
12547: if ($putresult eq 'ok') {
12548: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
12549: if (ref($defaultshash{'usersessions'}{'remote'}) eq 'HASH') {
12550: $domdefaults{'remotesessions'} = $defaultshash{'usersessions'}{'remote'};
12551: }
12552: if (ref($defaultshash{'usersessions'}{'hosted'}) eq 'HASH') {
12553: $domdefaults{'hostedsessions'} = $defaultshash{'usersessions'}{'hosted'};
12554: }
1.261 raeburn 12555: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
12556: $domdefaults{'offloadnow'} = $defaultshash{'usersessions'}{'offloadnow'};
12557: }
1.137 raeburn 12558: }
12559: my $cachetime = 24*60*60;
12560: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 12561: if (ref($lastactref) eq 'HASH') {
12562: $lastactref->{'domdefaults'} = 1;
12563: }
1.147 raeburn 12564: if (keys(%changes) > 0) {
12565: my %lt = &usersession_titles();
12566: $resulttext = &mt('Changes made:').'<ul>';
12567: foreach my $prefix (@prefixes) {
12568: if (ref($changes{$prefix}) eq 'HASH') {
12569: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
12570: if ($prefix eq 'spares') {
12571: if (ref($changes{$prefix}) eq 'HASH') {
12572: foreach my $lonhost (sort(keys(%{$changes{$prefix}}))) {
12573: $resulttext .= '<li><b>'.$lonhost.'</b> ';
1.148 raeburn 12574: my $lonhostdom = &Apache::lonnet::host_domain($lonhost);
1.211 raeburn 12575: my $cachekey = &escape('spares').':'.&escape($lonhostdom);
12576: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
1.147 raeburn 12577: if (ref($changes{$prefix}{$lonhost}) eq 'HASH') {
12578: foreach my $type (@{$types{$prefix}}) {
12579: if ($changes{$prefix}{$lonhost}{$type}) {
12580: my $offloadto = &mt('None');
12581: if (ref($defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}) eq 'ARRAY') {
12582: if (@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}} > 0) {
12583: $offloadto = join(', ',@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}});
12584: }
1.145 raeburn 12585: }
1.147 raeburn 12586: $resulttext .= &mt('[_1] set to: [_2].','<i>'.$lt{$type}.'</i>',$offloadto).(' 'x3);
1.145 raeburn 12587: }
1.137 raeburn 12588: }
12589: }
1.147 raeburn 12590: $resulttext .= '</li>';
1.137 raeburn 12591: }
12592: }
1.147 raeburn 12593: } else {
12594: foreach my $type (@{$types{$prefix}}) {
12595: if (defined($changes{$prefix}{$type})) {
12596: my $newvalue;
12597: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
12598: if (ref($defaultshash{'usersessions'}{$prefix})) {
12599: if ($type eq 'version') {
12600: $newvalue = $defaultshash{'usersessions'}{$prefix}{$type};
12601: } elsif (ref($defaultshash{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
12602: if (@{$defaultshash{'usersessions'}{$prefix}{$type}} > 0) {
12603: $newvalue = join(', ',@{$defaultshash{'usersessions'}{$prefix}{$type}});
12604: }
1.145 raeburn 12605: }
12606: }
12607: }
1.147 raeburn 12608: if ($newvalue eq '') {
12609: if ($type eq 'version') {
12610: $resulttext .= '<li>'.&mt('[_1] set to: off',$lt{$type}).'</li>';
12611: } else {
12612: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
12613: }
1.145 raeburn 12614: } else {
1.147 raeburn 12615: if ($type eq 'version') {
12616: $newvalue .= ' '.&mt('(or later)');
12617: }
12618: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
1.145 raeburn 12619: }
1.137 raeburn 12620: }
12621: }
12622: }
1.147 raeburn 12623: $resulttext .= '</ul>';
1.137 raeburn 12624: }
12625: }
1.261 raeburn 12626: if ($changes{'offloadnow'}) {
12627: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
12628: if (keys(%{$defaultshash{'usersessions'}{'offloadnow'}}) > 0) {
12629: $resulttext .= '<li>'.&mt('Switch active users on next access, for server(s):').'<ul>';
12630: foreach my $lonhost (sort(keys(%{$defaultshash{'usersessions'}{'offloadnow'}}))) {
12631: $resulttext .= '<li>'.$lonhost.'</li>';
12632: }
12633: $resulttext .= '</ul>';
12634: } else {
12635: $resulttext .= '<li>'.&mt('No servers now set to switch active users on next access.');
12636: }
12637: } else {
12638: $resulttext .= '<li>'.&mt('No servers now set to switch active users on next access.').'</li>';
12639: }
12640: }
1.147 raeburn 12641: $resulttext .= '</ul>';
12642: } else {
12643: $resulttext = $nochgmsg;
1.137 raeburn 12644: }
12645: } else {
12646: $resulttext = '<span class="LC_error">'.
12647: &mt('An error occurred: [_1]',$putresult).'</span>';
12648: }
12649: } else {
1.147 raeburn 12650: $resulttext = $nochgmsg;
1.137 raeburn 12651: }
12652: return $resulttext;
12653: }
12654:
1.275 raeburn 12655: sub modify_ssl {
12656: my ($dom,$lastactref,%domconfig) = @_;
12657: my (%by_ip,%by_location,@intdoms,@instdoms);
12658: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
12659: my @locations = sort(keys(%by_location));
12660: my %servers = &Apache::lonnet::internet_dom_servers($dom);
12661: my (%defaultshash,%changes);
12662: my $action = 'ssl';
12663: my @prefixes = ('connect','replication');
12664: foreach my $prefix (@prefixes) {
12665: $defaultshash{$action}{$prefix} = {};
12666: }
12667: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
12668: my $resulttext;
12669: my %iphost = &Apache::lonnet::get_iphost();
12670: my @reptypes = ('certreq','nocertreq');
12671: my @connecttypes = ('dom','intdom','other');
12672: my %types = (
12673: connect => \@connecttypes,
12674: replication => \@reptypes,
12675: );
12676: my $action = 'ssl';
12677: foreach my $prefix (sort(keys(%types))) {
12678: foreach my $type (@{$types{$prefix}}) {
12679: if ($prefix eq 'connect') {
12680: my $value = 'yes';
12681: if ($env{'form.'.$prefix.'_'.$type} =~ /^(no|req)$/) {
12682: $value = $env{'form.'.$prefix.'_'.$type};
12683: }
12684: if (ref($domconfig{$action}{$prefix}) eq 'HASH') {
12685: if ($domconfig{$action}{$prefix}{$type} ne '') {
12686: if ($value ne $domconfig{$action}{$prefix}{$type}) {
12687: $changes{$prefix}{$type} = 1;
12688: }
12689: $defaultshash{$action}{$prefix}{$type} = $value;
12690: } else {
12691: $defaultshash{$action}{$prefix}{$type} = $value;
12692: $changes{$prefix}{$type} = 1;
12693: }
12694: } else {
12695: $defaultshash{$action}{$prefix}{$type} = $value;
12696: $changes{$prefix}{$type} = 1;
12697: }
12698: if (($type eq 'dom') && (keys(%servers) == 1)) {
12699: delete($changes{$prefix}{$type});
12700: } elsif (($type eq 'intdom') && (@instdoms == 1)) {
12701: delete($changes{$prefix}{$type});
12702: } elsif (($type eq 'other') && (keys(%by_location) == 0)) {
12703: delete($changes{$prefix}{$type});
12704: }
12705: } elsif ($prefix eq 'replication') {
12706: if (@locations > 0) {
12707: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
12708: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
12709: my @okvals;
12710: foreach my $val (@vals) {
12711: if ($val =~ /:/) {
12712: my @items = split(/:/,$val);
12713: foreach my $item (@items) {
12714: if (ref($by_location{$item}) eq 'ARRAY') {
12715: push(@okvals,$item);
12716: }
12717: }
12718: } else {
12719: if (ref($by_location{$val}) eq 'ARRAY') {
12720: push(@okvals,$val);
12721: }
12722: }
12723: }
12724: @okvals = sort(@okvals);
12725: if (ref($domconfig{$action}) eq 'HASH') {
12726: if (ref($domconfig{$action}{$prefix}) eq 'HASH') {
12727: if (ref($domconfig{$action}{$prefix}{$type}) eq 'ARRAY') {
12728: if ($inuse == 0) {
12729: $changes{$prefix}{$type} = 1;
12730: } else {
12731: $defaultshash{$action}{$prefix}{$type} = \@okvals;
12732: my @changed = &Apache::loncommon::compare_arrays($domconfig{$action}{$prefix}{$type},$defaultshash{$action}{$prefix}{$type});
12733: if (@changed > 0) {
12734: $changes{$prefix}{$type} = 1;
12735: }
12736: }
12737: } else {
12738: if ($inuse == 1) {
12739: $defaultshash{$action}{$prefix}{$type} = \@okvals;
12740: $changes{$prefix}{$type} = 1;
12741: }
12742: }
12743: } else {
12744: if ($inuse == 1) {
12745: $defaultshash{$action}{$prefix}{$type} = \@okvals;
12746: $changes{$prefix}{$type} = 1;
12747: }
12748: }
12749: } else {
12750: if ($inuse == 1) {
12751: $defaultshash{$action}{$prefix}{$type} = \@okvals;
12752: $changes{$prefix}{$type} = 1;
12753: }
12754: }
12755: }
12756: }
12757: }
12758: }
12759: my $nochgmsg = &mt('No changes made to LON-CAPA SSL settings');
12760: if (keys(%changes) > 0) {
12761: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
12762: $dom);
12763: if ($putresult eq 'ok') {
12764: if (ref($defaultshash{$action}) eq 'HASH') {
12765: if (ref($defaultshash{$action}{'replication'}) eq 'HASH') {
12766: $domdefaults{'replication'} = $defaultshash{$action}{'replication'};
12767: }
12768: if (ref($defaultshash{$action}{'connect'}) eq 'HASH') {
12769: $domdefaults{'connect'} = $domconfig{$action}{'connect'};
12770: }
12771: }
12772: my $cachetime = 24*60*60;
12773: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
12774: if (ref($lastactref) eq 'HASH') {
12775: $lastactref->{'domdefaults'} = 1;
12776: }
12777: if (keys(%changes) > 0) {
12778: my %titles = &ssl_titles();
12779: $resulttext = &mt('Changes made:').'<ul>';
12780: foreach my $prefix (@prefixes) {
12781: if (ref($changes{$prefix}) eq 'HASH') {
12782: $resulttext .= '<li>'.$titles{$prefix}.'<ul>';
12783: foreach my $type (@{$types{$prefix}}) {
12784: if (defined($changes{$prefix}{$type})) {
12785: my $newvalue;
12786: if (ref($defaultshash{$action}) eq 'HASH') {
12787: if (ref($defaultshash{$action}{$prefix})) {
12788: if ($prefix eq 'connect') {
12789: $newvalue = $titles{$defaultshash{$action}{$prefix}{$type}};
12790: } elsif (ref($defaultshash{$action}{$prefix}{$type}) eq 'ARRAY') {
12791: if (@{$defaultshash{$action}{$prefix}{$type}} > 0) {
12792: $newvalue = join(', ',@{$defaultshash{$action}{$prefix}{$type}});
12793: }
12794: }
12795: }
12796: if ($newvalue eq '') {
12797: $resulttext .= '<li>'.&mt('[_1] set to: none',$titles{$type}).'</li>';
12798: } else {
12799: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$titles{$type},$newvalue).'</li>';
12800: }
12801: }
12802: }
12803: }
12804: $resulttext .= '</ul>';
12805: }
12806: }
12807: } else {
12808: $resulttext = $nochgmsg;
12809: }
12810: } else {
12811: $resulttext = '<span class="LC_error">'.
12812: &mt('An error occurred: [_1]',$putresult).'</span>';
12813: }
12814: } else {
12815: $resulttext = $nochgmsg;
12816: }
12817: return $resulttext;
12818: }
12819:
1.150 raeburn 12820: sub modify_loadbalancing {
12821: my ($dom,%domconfig) = @_;
12822: my $primary_id = &Apache::lonnet::domain($dom,'primary');
12823: my $intdom = &Apache::lonnet::internet_dom($primary_id);
12824: my ($othertitle,$usertypes,$types) =
12825: &Apache::loncommon::sorted_inst_types($dom);
12826: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.253 raeburn 12827: my %libraryservers = &Apache::lonnet::get_servers($dom,'library');
1.150 raeburn 12828: my @sparestypes = ('primary','default');
12829: my %typetitles = &sparestype_titles();
12830: my $resulttext;
1.171 raeburn 12831: my (%currbalancer,%currtargets,%currrules,%existing);
12832: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
12833: %existing = %{$domconfig{'loadbalancing'}};
12834: }
12835: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
12836: \%currtargets,\%currrules);
12837: my ($saveloadbalancing,%defaultshash,%changes);
12838: my ($alltypes,$othertypes,$titles) =
12839: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
12840: my %ruletitles = &offloadtype_text();
12841: my @deletions = &Apache::loncommon::get_env_multiple('form.loadbalancing_delete');
12842: for (my $i=0; $i<$env{'form.loadbalancing_total'}; $i++) {
12843: my $balancer = $env{'form.loadbalancing_lonhost_'.$i};
12844: if ($balancer eq '') {
12845: next;
12846: }
1.210 raeburn 12847: if (!exists($servers{$balancer})) {
1.171 raeburn 12848: if (exists($currbalancer{$balancer})) {
12849: push(@{$changes{'delete'}},$balancer);
1.150 raeburn 12850: }
1.171 raeburn 12851: next;
12852: }
12853: if ((@deletions > 0) && (grep(/^\Q$i\E$/,@deletions))) {
12854: push(@{$changes{'delete'}},$balancer);
12855: next;
12856: }
12857: if (!exists($currbalancer{$balancer})) {
12858: push(@{$changes{'add'}},$balancer);
12859: }
12860: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'} = [];
12861: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'default'} = [];
12862: $defaultshash{'loadbalancing'}{$balancer}{'rules'} = {};
12863: unless (ref($domconfig{'loadbalancing'}) eq 'HASH') {
12864: $saveloadbalancing = 1;
12865: }
12866: foreach my $sparetype (@sparestypes) {
12867: my @targets = &Apache::loncommon::get_env_multiple('form.loadbalancing_target_'.$i.'_'.$sparetype);
12868: my @offloadto;
12869: foreach my $target (@targets) {
12870: if (($servers{$target}) && ($target ne $balancer)) {
12871: if ($sparetype eq 'default') {
12872: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}) eq 'ARRAY') {
12873: next if (grep(/^\Q$target\E$/,@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}}));
1.150 raeburn 12874: }
12875: }
1.171 raeburn 12876: unless(grep(/^\Q$target\E$/,@offloadto)) {
12877: push(@offloadto,$target);
12878: }
1.150 raeburn 12879: }
1.171 raeburn 12880: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype} = \@offloadto;
1.150 raeburn 12881: }
12882: }
1.171 raeburn 12883: if (ref($currtargets{$balancer}) eq 'HASH') {
1.150 raeburn 12884: foreach my $sparetype (@sparestypes) {
1.171 raeburn 12885: if (ref($currtargets{$balancer}{$sparetype}) eq 'ARRAY') {
12886: my @targetdiffs = &Apache::loncommon::compare_arrays($currtargets{$balancer}{$sparetype},$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype});
1.150 raeburn 12887: if (@targetdiffs > 0) {
1.171 raeburn 12888: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 12889: }
1.171 raeburn 12890: } elsif (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
12891: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
12892: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 12893: }
12894: }
12895: }
12896: } else {
1.171 raeburn 12897: if (ref($defaultshash{'loadbalancing'}{$balancer}) eq 'HASH') {
1.210 raeburn 12898: foreach my $sparetype (@sparestypes) {
1.171 raeburn 12899: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
12900: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
12901: $changes{'curr'}{$balancer}{'targets'} = 1;
12902: }
1.150 raeburn 12903: }
12904: }
1.210 raeburn 12905: }
1.150 raeburn 12906: }
12907: my $ishomedom;
1.171 raeburn 12908: if (&Apache::lonnet::host_domain($balancer) eq $dom) {
12909: $ishomedom = 1;
1.150 raeburn 12910: }
12911: if (ref($alltypes) eq 'ARRAY') {
12912: foreach my $type (@{$alltypes}) {
12913: my $rule;
1.210 raeburn 12914: unless ((($type eq '_LC_external') || ($type eq '_LC_internetdom')) &&
1.150 raeburn 12915: (!$ishomedom)) {
1.171 raeburn 12916: $rule = $env{'form.loadbalancing_rules_'.$i.'_'.$type};
12917: }
12918: if ($rule eq 'specific') {
1.255 raeburn 12919: my $specifiedhost = $env{'form.loadbalancing_singleserver_'.$i.'_'.$type};
12920: if (exists($servers{$specifiedhost})) {
12921: $rule = $specifiedhost;
12922: }
1.150 raeburn 12923: }
1.171 raeburn 12924: $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type} = $rule;
12925: if (ref($currrules{$balancer}) eq 'HASH') {
12926: if ($rule ne $currrules{$balancer}{$type}) {
12927: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 12928: }
12929: } elsif ($rule ne '') {
1.171 raeburn 12930: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 12931: }
12932: }
12933: }
1.171 raeburn 12934: }
12935: my $nochgmsg = &mt('No changes made to Load Balancer settings.');
12936: if ((keys(%changes) > 0) || ($saveloadbalancing)) {
12937: unless (ref($defaultshash{'loadbalancing'}) eq 'HASH') {
12938: $defaultshash{'loadbalancing'} = {};
12939: }
12940: my $putresult = &Apache::lonnet::put_dom('configuration',
12941: \%defaultshash,$dom);
12942: if ($putresult eq 'ok') {
12943: if (keys(%changes) > 0) {
1.252 raeburn 12944: my %toupdate;
1.171 raeburn 12945: if (ref($changes{'delete'}) eq 'ARRAY') {
12946: foreach my $balancer (sort(@{$changes{'delete'}})) {
12947: $resulttext .= '<li>'.&mt('Load Balancing discontinued for: [_1]',$balancer).'</li>';
1.252 raeburn 12948: $toupdate{$balancer} = 1;
1.150 raeburn 12949: }
1.171 raeburn 12950: }
12951: if (ref($changes{'add'}) eq 'ARRAY') {
1.210 raeburn 12952: foreach my $balancer (sort(@{$changes{'add'}})) {
1.171 raeburn 12953: $resulttext .= '<li>'.&mt('Load Balancing enabled for: [_1]',$balancer);
1.252 raeburn 12954: $toupdate{$balancer} = 1;
1.171 raeburn 12955: }
12956: }
12957: if (ref($changes{'curr'}) eq 'HASH') {
12958: foreach my $balancer (sort(keys(%{$changes{'curr'}}))) {
1.253 raeburn 12959: $toupdate{$balancer} = 1;
1.171 raeburn 12960: if (ref($changes{'curr'}{$balancer}) eq 'HASH') {
12961: if ($changes{'curr'}{$balancer}{'targets'}) {
12962: my %offloadstr;
12963: foreach my $sparetype (@sparestypes) {
12964: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
12965: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
12966: $offloadstr{$sparetype} = join(', ',@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
12967: }
12968: }
1.150 raeburn 12969: }
1.171 raeburn 12970: if (keys(%offloadstr) == 0) {
12971: $resulttext .= '<li>'.&mt("Servers to which Load Balance server offloads set to 'None', by default").'</li>';
1.150 raeburn 12972: } else {
1.171 raeburn 12973: my $showoffload;
12974: foreach my $sparetype (@sparestypes) {
12975: $showoffload .= '<i>'.$typetitles{$sparetype}.'</i>: ';
12976: if (defined($offloadstr{$sparetype})) {
12977: $showoffload .= $offloadstr{$sparetype};
12978: } else {
12979: $showoffload .= &mt('None');
12980: }
12981: $showoffload .= (' 'x3);
12982: }
12983: $resulttext .= '<li>'.&mt('By default, Load Balancer: [_1] set to offload to - [_2]',$balancer,$showoffload).'</li>';
1.150 raeburn 12984: }
12985: }
12986: }
1.171 raeburn 12987: if (ref($changes{'curr'}{$balancer}{'rules'}) eq 'HASH') {
12988: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
12989: foreach my $type (@{$alltypes}) {
12990: if ($changes{'curr'}{$balancer}{'rules'}{$type}) {
12991: my $rule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
12992: my $balancetext;
12993: if ($rule eq '') {
12994: $balancetext = $ruletitles{'default'};
1.209 raeburn 12995: } elsif (($rule eq 'homeserver') || ($rule eq 'externalbalancer') ||
1.254 raeburn 12996: ($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
12997: if (($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
1.252 raeburn 12998: foreach my $sparetype (@sparestypes) {
12999: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
13000: map { $toupdate{$_} = 1; } (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
13001: }
13002: }
1.253 raeburn 13003: foreach my $item (@{$alltypes}) {
13004: next if ($item =~ /^_LC_ipchange/);
13005: my $hasrule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$item};
13006: if ($hasrule eq 'homeserver') {
13007: map { $toupdate{$_} = 1; } (keys(%libraryservers));
13008: } else {
13009: unless (($hasrule eq 'default') || ($hasrule eq 'none') || ($hasrule eq 'externalbalancer')) {
13010: if ($servers{$hasrule}) {
13011: $toupdate{$hasrule} = 1;
13012: }
13013: }
13014: }
13015: }
1.254 raeburn 13016: if (($rule eq 'balancer') || ($rule eq 'offloadedto')) {
13017: $balancetext = $ruletitles{$rule};
13018: } else {
13019: my $receiver = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
13020: $balancetext = $ruletitles{'particular'}.' '.$receiver;
13021: if ($receiver) {
13022: $toupdate{$receiver};
13023: }
13024: }
13025: } else {
13026: $balancetext = $ruletitles{$rule};
1.252 raeburn 13027: }
1.171 raeburn 13028: } else {
13029: $balancetext = &mt('offload to [_1]',$defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type});
13030: }
1.210 raeburn 13031: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- balancing for [_2] set to - "[_3]"',$balancer,$titles->{$type},$balancetext).'</li>';
1.150 raeburn 13032: }
13033: }
13034: }
13035: }
1.252 raeburn 13036: if (keys(%toupdate)) {
13037: my %thismachine;
13038: my $updatedhere;
13039: my $cachetime = 60*60*24;
13040: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
13041: foreach my $lonhost (keys(%toupdate)) {
13042: if ($thismachine{$lonhost}) {
13043: unless ($updatedhere) {
13044: &Apache::lonnet::do_cache_new('loadbalancing',$dom,
13045: $defaultshash{'loadbalancing'},
13046: $cachetime);
13047: $updatedhere = 1;
13048: }
13049: } else {
13050: my $cachekey = &escape('loadbalancing').':'.&escape($dom);
13051: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
13052: }
13053: }
13054: }
1.150 raeburn 13055: }
1.171 raeburn 13056: }
13057: if ($resulttext ne '') {
13058: $resulttext = &mt('Changes made:').'<ul>'.$resulttext.'</ul>';
1.150 raeburn 13059: } else {
13060: $resulttext = $nochgmsg;
13061: }
13062: } else {
1.171 raeburn 13063: $resulttext = $nochgmsg;
1.150 raeburn 13064: }
13065: } else {
1.171 raeburn 13066: $resulttext = '<span class="LC_error">'.
13067: &mt('An error occurred: [_1]',$putresult).'</span>';
1.150 raeburn 13068: }
13069: } else {
1.171 raeburn 13070: $resulttext = $nochgmsg;
1.150 raeburn 13071: }
13072: return $resulttext;
13073: }
13074:
1.48 raeburn 13075: sub recurse_check {
13076: my ($chkcats,$categories,$depth,$name) = @_;
13077: if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
13078: my $chg = 0;
13079: for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
13080: my $category = $chkcats->[$depth]{$name}[$j];
13081: my $item;
13082: if ($category eq '') {
13083: $chg ++;
13084: } else {
13085: my $deeper = $depth + 1;
13086: $item = &escape($category).':'.&escape($name).':'.$depth;
13087: if ($chg) {
13088: $categories->{$item} -= $chg;
13089: }
13090: &recurse_check($chkcats,$categories,$deeper,$category);
13091: $deeper --;
13092: }
13093: }
13094: }
13095: return;
13096: }
13097:
13098: sub recurse_cat_deletes {
13099: my ($item,$coursecategories,$deletions) = @_;
13100: my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
13101: my $subdepth = $depth + 1;
13102: if (ref($coursecategories) eq 'HASH') {
13103: foreach my $subitem (keys(%{$coursecategories})) {
13104: my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
13105: if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
13106: delete($coursecategories->{$subitem});
13107: $deletions->{$subitem} = 1;
13108: &recurse_cat_deletes($subitem,$coursecategories,$deletions);
1.168 raeburn 13109: }
1.48 raeburn 13110: }
13111: }
13112: return;
13113: }
13114:
1.125 raeburn 13115: sub get_active_dcs {
13116: my ($dom) = @_;
1.191 raeburn 13117: my $now = time;
13118: my %dompersonnel = &Apache::lonnet::get_domain_roles($dom,['dc'],$now,$now);
1.125 raeburn 13119: my %domcoords;
13120: my $numdcs = 0;
13121: foreach my $server (keys(%dompersonnel)) {
13122: foreach my $user (sort(keys(%{$dompersonnel{$server}}))) {
13123: my ($trole,$uname,$udom,$runame,$rudom,$rsec) = split(/:/,$user);
1.191 raeburn 13124: $domcoords{$uname.':'.$udom} = $dompersonnel{$server}{$user};
1.125 raeburn 13125: }
13126: }
13127: return %domcoords;
13128: }
13129:
13130: sub active_dc_picker {
1.191 raeburn 13131: my ($dom,$numinrow,$inputtype,$name,%currhash) = @_;
1.235 raeburn 13132: my %domcoords = &get_active_dcs($dom);
1.191 raeburn 13133: my @domcoord = keys(%domcoords);
13134: if (keys(%currhash)) {
13135: foreach my $dc (keys(%currhash)) {
13136: unless (exists($domcoords{$dc})) {
13137: push(@domcoord,$dc);
13138: }
13139: }
13140: }
13141: @domcoord = sort(@domcoord);
1.210 raeburn 13142: my $numdcs = scalar(@domcoord);
1.191 raeburn 13143: my $rows = 0;
13144: my $table;
1.125 raeburn 13145: if ($numdcs > 1) {
1.191 raeburn 13146: $table = '<table>';
13147: for (my $i=0; $i<@domcoord; $i++) {
1.125 raeburn 13148: my $rem = $i%($numinrow);
13149: if ($rem == 0) {
13150: if ($i > 0) {
1.191 raeburn 13151: $table .= '</tr>';
1.125 raeburn 13152: }
1.191 raeburn 13153: $table .= '<tr>';
13154: $rows ++;
1.125 raeburn 13155: }
1.191 raeburn 13156: my $check = '';
13157: if ($inputtype eq 'radio') {
13158: if (keys(%currhash) == 0) {
13159: if (!$i) {
13160: $check = ' checked="checked"';
13161: }
13162: } elsif (exists($currhash{$domcoord[$i]})) {
13163: $check = ' checked="checked"';
13164: }
13165: } else {
13166: if (exists($currhash{$domcoord[$i]})) {
13167: $check = ' checked="checked"';
1.125 raeburn 13168: }
13169: }
1.191 raeburn 13170: if ($i == @domcoord - 1) {
1.125 raeburn 13171: my $colsleft = $numinrow - $rem;
13172: if ($colsleft > 1) {
1.191 raeburn 13173: $table .= '<td class="LC_left_item" colspan="'.$colsleft.'">';
1.125 raeburn 13174: } else {
1.191 raeburn 13175: $table .= '<td class="LC_left_item">';
1.125 raeburn 13176: }
13177: } else {
1.191 raeburn 13178: $table .= '<td class="LC_left_item">';
13179: }
13180: my ($dcname,$dcdom) = split(':',$domcoord[$i]);
13181: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
13182: $table .= '<span class="LC_nobreak"><label>'.
13183: '<input type="'.$inputtype.'" name="'.$name.'"'.
13184: ' value="'.$domcoord[$i].'"'.$check.' />'.$user;
13185: if ($user ne $dcname.':'.$dcdom) {
1.219 raeburn 13186: $table .= ' ('.$dcname.':'.$dcdom.')';
1.191 raeburn 13187: }
1.219 raeburn 13188: $table .= '</label></span></td>';
1.191 raeburn 13189: }
13190: $table .= '</tr></table>';
13191: } elsif ($numdcs == 1) {
1.219 raeburn 13192: my ($dcname,$dcdom) = split(':',$domcoord[0]);
13193: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
1.191 raeburn 13194: if ($inputtype eq 'radio') {
1.247 raeburn 13195: $table = '<input type="hidden" name="'.$name.'" value="'.$domcoord[0].'" />'.$user;
1.219 raeburn 13196: if ($user ne $dcname.':'.$dcdom) {
13197: $table .= ' ('.$dcname.':'.$dcdom.')';
13198: }
1.191 raeburn 13199: } else {
13200: my $check;
13201: if (exists($currhash{$domcoord[0]})) {
13202: $check = ' checked="checked"';
1.125 raeburn 13203: }
1.247 raeburn 13204: $table = '<span class="LC_nobreak"><label>'.
13205: '<input type="checkbox" name="'.$name.'" '.
13206: 'value="'.$domcoord[0].'"'.$check.' />'.$user;
1.219 raeburn 13207: if ($user ne $dcname.':'.$dcdom) {
1.220 raeburn 13208: $table .= ' ('.$dcname.':'.$dcdom.')';
1.219 raeburn 13209: }
1.220 raeburn 13210: $table .= '</label></span>';
1.191 raeburn 13211: $rows ++;
1.125 raeburn 13212: }
13213: }
1.191 raeburn 13214: return ($numdcs,$table,$rows);
1.125 raeburn 13215: }
13216:
1.137 raeburn 13217: sub usersession_titles {
13218: return &Apache::lonlocal::texthash(
13219: hosted => 'Hosting of sessions for users from other domains on servers in this domain',
13220: remote => 'Hosting of sessions for users in this domain on servers in other domains',
1.145 raeburn 13221: spares => 'Servers offloaded to, when busy',
1.137 raeburn 13222: version => 'LON-CAPA version requirement',
1.138 raeburn 13223: excludedomain => 'Allow all, but exclude specific domains',
13224: includedomain => 'Deny all, but include specific domains',
1.145 raeburn 13225: primary => 'Primary (checked first)',
1.154 raeburn 13226: default => 'Default',
1.137 raeburn 13227: );
13228: }
13229:
1.152 raeburn 13230: sub id_for_thisdom {
13231: my (%servers) = @_;
13232: my %altids;
13233: foreach my $server (keys(%servers)) {
13234: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
13235: if ($serverhome ne $server) {
13236: $altids{$serverhome} = $server;
13237: }
13238: }
13239: return %altids;
13240: }
13241:
1.150 raeburn 13242: sub count_servers {
13243: my ($currbalancer,%servers) = @_;
13244: my (@spares,$numspares);
13245: foreach my $lonhost (sort(keys(%servers))) {
13246: next if ($currbalancer eq $lonhost);
13247: push(@spares,$lonhost);
13248: }
13249: if ($currbalancer) {
13250: $numspares = scalar(@spares);
13251: } else {
13252: $numspares = scalar(@spares) - 1;
13253: }
13254: return ($numspares,@spares);
13255: }
13256:
13257: sub lonbalance_targets_js {
1.171 raeburn 13258: my ($dom,$types,$servers,$settings) = @_;
1.150 raeburn 13259: my $select = &mt('Select');
13260: my ($alltargets,$allishome,$allinsttypes,@alltypes);
13261: if (ref($servers) eq 'HASH') {
13262: $alltargets = join("','",sort(keys(%{$servers})));
13263: my @homedoms;
13264: foreach my $server (sort(keys(%{$servers}))) {
13265: if (&Apache::lonnet::host_domain($server) eq $dom) {
13266: push(@homedoms,'1');
13267: } else {
13268: push(@homedoms,'0');
13269: }
13270: }
13271: $allishome = join("','",@homedoms);
13272: }
13273: if (ref($types) eq 'ARRAY') {
13274: if (@{$types} > 0) {
13275: @alltypes = @{$types};
13276: }
13277: }
13278: push(@alltypes,'default','_LC_adv','_LC_author','_LC_internetdom','_LC_external');
13279: $allinsttypes = join("','",@alltypes);
1.171 raeburn 13280: my (%currbalancer,%currtargets,%currrules,%existing);
13281: if (ref($settings) eq 'HASH') {
13282: %existing = %{$settings};
13283: }
13284: &get_loadbalancers_config($servers,\%existing,\%currbalancer,
13285: \%currtargets,\%currrules);
1.210 raeburn 13286: my $balancers = join("','",sort(keys(%currbalancer)));
1.150 raeburn 13287: return <<"END";
13288:
13289: <script type="text/javascript">
13290: // <![CDATA[
13291:
1.171 raeburn 13292: currBalancers = new Array('$balancers');
13293:
13294: function toggleTargets(balnum) {
13295: var lonhostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
13296: var prevhostitem = document.getElementById('loadbalancing_prevlonhost_'+balnum);
13297: var balancer = lonhostitem.options[lonhostitem.selectedIndex].value;
13298: var prevbalancer = prevhostitem.value;
13299: var baltotal = document.getElementById('loadbalancing_total').value;
13300: prevhostitem.value = balancer;
13301: if (prevbalancer != '') {
13302: var prevIdx = currBalancers.indexOf(prevbalancer);
13303: if (prevIdx != -1) {
13304: currBalancers.splice(prevIdx,1);
13305: }
13306: }
1.150 raeburn 13307: if (balancer == '') {
1.171 raeburn 13308: hideSpares(balnum);
1.150 raeburn 13309: } else {
1.171 raeburn 13310: var currIdx = currBalancers.indexOf(balancer);
13311: if (currIdx == -1) {
13312: currBalancers.push(balancer);
13313: }
1.150 raeburn 13314: var homedoms = new Array('$allishome');
1.171 raeburn 13315: var ishomedom = homedoms[lonhostitem.selectedIndex];
13316: showSpares(balancer,ishomedom,balnum);
1.150 raeburn 13317: }
1.171 raeburn 13318: balancerChange(balnum,baltotal,'change',prevbalancer,balancer);
1.150 raeburn 13319: return;
13320: }
13321:
1.171 raeburn 13322: function showSpares(balancer,ishomedom,balnum) {
1.150 raeburn 13323: var alltargets = new Array('$alltargets');
13324: var insttypes = new Array('$allinsttypes');
1.151 raeburn 13325: var offloadtypes = new Array('primary','default');
13326:
1.171 raeburn 13327: document.getElementById('loadbalancing_targets_'+balnum).style.display='block';
13328: document.getElementById('loadbalancing_disabled_'+balnum).style.display='none';
1.152 raeburn 13329:
1.151 raeburn 13330: for (var i=0; i<offloadtypes.length; i++) {
13331: var count = 0;
13332: for (var j=0; j<alltargets.length; j++) {
13333: if (alltargets[j] != balancer) {
1.171 raeburn 13334: var item = document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+count);
13335: item.value = alltargets[j];
13336: item.style.textAlign='left';
13337: item.style.textFace='normal';
13338: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+count).innerHTML = alltargets[j];
13339: if (currBalancers.indexOf(alltargets[j]) == -1) {
13340: item.disabled = '';
13341: } else {
13342: item.disabled = 'disabled';
13343: item.checked = false;
13344: }
1.151 raeburn 13345: count ++;
13346: }
1.150 raeburn 13347: }
13348: }
1.151 raeburn 13349: for (var k=0; k<insttypes.length; k++) {
13350: if ((insttypes[k] == '_LC_external') || (insttypes[k] == '_LC_internetdom')) {
1.150 raeburn 13351: if (ishomedom == 1) {
1.171 raeburn 13352: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
13353: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 13354: } else {
1.171 raeburn 13355: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
13356: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.150 raeburn 13357: }
13358: } else {
1.171 raeburn 13359: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
13360: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 13361: }
1.151 raeburn 13362: if ((insttypes[k] != '_LC_external') &&
13363: ((insttypes[k] != '_LC_internetdom') ||
13364: ((insttypes[k] == '_LC_internetdom') && (ishomedom == 1)))) {
1.171 raeburn 13365: var item = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]);
13366: item.options.length = 0;
13367: item.options[0] = new Option("","",true,true);
1.210 raeburn 13368: var idx = 0;
1.151 raeburn 13369: for (var m=0; m<alltargets.length; m++) {
1.171 raeburn 13370: if ((currBalancers.indexOf(alltargets[m]) == -1) && (alltargets[m] != balancer)) {
13371: idx ++;
13372: item.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
1.150 raeburn 13373: }
13374: }
13375: }
13376: }
13377: return;
13378: }
13379:
1.171 raeburn 13380: function hideSpares(balnum) {
1.150 raeburn 13381: var alltargets = new Array('$alltargets');
13382: var insttypes = new Array('$allinsttypes');
13383: var offloadtypes = new Array('primary','default');
13384:
1.171 raeburn 13385: document.getElementById('loadbalancing_targets_'+balnum).style.display='none';
13386: document.getElementById('loadbalancing_disabled_'+balnum).style.display='block';
1.150 raeburn 13387:
13388: var total = alltargets.length - 1;
13389: for (var i=0; i<offloadtypes; i++) {
13390: for (var j=0; j<total; j++) {
1.171 raeburn 13391: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).checked = false;
13392: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).value = '';
13393: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+j).innerHTML = '';
1.151 raeburn 13394: }
1.150 raeburn 13395: }
13396: for (var k=0; k<insttypes.length; k++) {
1.171 raeburn 13397: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
13398: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.151 raeburn 13399: if (insttypes[k] != '_LC_external') {
1.171 raeburn 13400: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).length = 0;
13401: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).options[0] = new Option("","",true,true);
1.150 raeburn 13402: }
13403: }
13404: return;
13405: }
13406:
1.171 raeburn 13407: function checkOffloads(item,balnum,type) {
1.150 raeburn 13408: var alltargets = new Array('$alltargets');
13409: var offloadtypes = new Array('primary','default');
13410: if (item.checked) {
13411: var total = alltargets.length - 1;
13412: var other;
13413: if (type == offloadtypes[0]) {
1.151 raeburn 13414: other = offloadtypes[1];
1.150 raeburn 13415: } else {
1.151 raeburn 13416: other = offloadtypes[0];
1.150 raeburn 13417: }
13418: for (var i=0; i<total; i++) {
1.171 raeburn 13419: var server = document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).value;
1.150 raeburn 13420: if (server == item.value) {
1.171 raeburn 13421: if (document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked) {
13422: document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked = false;
1.150 raeburn 13423: }
13424: }
13425: }
13426: }
13427: return;
13428: }
13429:
1.171 raeburn 13430: function singleServerToggle(balnum,type) {
13431: var offloadtoSelIdx = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex;
1.150 raeburn 13432: if (offloadtoSelIdx == 0) {
1.171 raeburn 13433: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_0').checked = true;
13434: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 13435:
13436: } else {
1.171 raeburn 13437: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_2').checked = true;
13438: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
1.150 raeburn 13439: }
13440: return;
13441: }
13442:
1.171 raeburn 13443: function balanceruleChange(formname,balnum,type) {
1.150 raeburn 13444: if (type == '_LC_external') {
1.171 raeburn 13445: return;
1.150 raeburn 13446: }
1.171 raeburn 13447: var typesRules = getIndicesByName(formname,'loadbalancing_rules_'+balnum+'_'+type);
1.150 raeburn 13448: for (var i=0; i<typesRules.length; i++) {
13449: if (formname.elements[typesRules[i]].checked) {
13450: if (formname.elements[typesRules[i]].value != 'specific') {
1.171 raeburn 13451: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex = 0;
13452: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 13453: } else {
1.171 raeburn 13454: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
13455: }
13456: }
13457: }
13458: return;
13459: }
13460:
13461: function balancerDeleteChange(balnum) {
13462: var hostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
13463: var baltotal = document.getElementById('loadbalancing_total').value;
13464: var addtarget;
13465: var removetarget;
13466: var action = 'delete';
13467: if (document.getElementById('loadbalancing_delete_'+balnum)) {
13468: var lonhost = hostitem.value;
13469: var currIdx = currBalancers.indexOf(lonhost);
13470: if (document.getElementById('loadbalancing_delete_'+balnum).checked) {
13471: if (currIdx != -1) {
13472: currBalancers.splice(currIdx,1);
13473: }
13474: addtarget = lonhost;
13475: } else {
13476: if (currIdx == -1) {
13477: currBalancers.push(lonhost);
13478: }
13479: removetarget = lonhost;
13480: action = 'undelete';
13481: }
13482: balancerChange(balnum,baltotal,action,addtarget,removetarget);
13483: }
13484: return;
13485: }
13486:
13487: function balancerChange(balnum,baltotal,action,addtarget,removetarget) {
13488: if (baltotal > 1) {
13489: var offloadtypes = new Array('primary','default');
13490: var alltargets = new Array('$alltargets');
13491: var insttypes = new Array('$allinsttypes');
13492: for (var i=0; i<baltotal; i++) {
13493: if (i != balnum) {
13494: for (var j=0; j<offloadtypes.length; j++) {
13495: var total = alltargets.length - 1;
13496: for (var k=0; k<total; k++) {
13497: var serveritem = document.getElementById('loadbalancing_target_'+i+'_'+offloadtypes[j]+'_'+k);
13498: var server = serveritem.value;
13499: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
13500: if (server == addtarget) {
13501: serveritem.disabled = '';
13502: }
13503: }
13504: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
13505: if (server == removetarget) {
13506: serveritem.disabled = 'disabled';
13507: serveritem.checked = false;
13508: }
13509: }
13510: }
13511: }
13512: for (var j=0; j<insttypes.length; j++) {
13513: if (insttypes[j] != '_LC_external') {
13514: if (document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j])) {
13515: var singleserver = document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j]);
13516: var currSel = singleserver.selectedIndex;
13517: var currVal = singleserver.options[currSel].value;
13518: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
13519: var numoptions = singleserver.options.length;
13520: var needsnew = 1;
13521: for (var k=0; k<numoptions; k++) {
13522: if (singleserver.options[k] == addtarget) {
13523: needsnew = 0;
13524: break;
13525: }
13526: }
13527: if (needsnew == 1) {
13528: singleserver.options[numoptions] = new Option(addtarget,addtarget,false,false);
13529: }
13530: }
13531: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
13532: singleserver.options.length = 0;
13533: if ((currVal) && (currVal != removetarget)) {
13534: singleserver.options[0] = new Option("","",false,false);
13535: } else {
13536: singleserver.options[0] = new Option("","",true,true);
13537: }
13538: var idx = 0;
13539: for (var m=0; m<alltargets.length; m++) {
13540: if (currBalancers.indexOf(alltargets[m]) == -1) {
13541: idx ++;
13542: if (currVal == alltargets[m]) {
13543: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],true,true);
13544: } else {
13545: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
13546: }
13547: }
13548: }
13549: }
13550: }
13551: }
13552: }
1.150 raeburn 13553: }
13554: }
13555: }
13556: return;
13557: }
13558:
1.152 raeburn 13559: // ]]>
13560: </script>
13561:
13562: END
13563: }
13564:
13565: sub new_spares_js {
13566: my @sparestypes = ('primary','default');
13567: my $types = join("','",@sparestypes);
13568: my $select = &mt('Select');
13569: return <<"END";
13570:
13571: <script type="text/javascript">
13572: // <![CDATA[
13573:
13574: function updateNewSpares(formname,lonhost) {
13575: var types = new Array('$types');
13576: var include = new Array();
13577: var exclude = new Array();
13578: for (var i=0; i<types.length; i++) {
13579: var spareboxes = getIndicesByName(formname,'spare_'+types[i]+'_'+lonhost);
13580: for (var j=0; j<spareboxes.length; j++) {
13581: if (formname.elements[spareboxes[j]].checked) {
13582: exclude.push(formname.elements[spareboxes[j]].value);
13583: } else {
13584: include.push(formname.elements[spareboxes[j]].value);
13585: }
13586: }
13587: }
13588: for (var i=0; i<types.length; i++) {
13589: var newSpare = document.getElementById('newspare_'+types[i]+'_'+lonhost);
13590: var selIdx = newSpare.selectedIndex;
13591: var currnew = newSpare.options[selIdx].value;
13592: var okSpares = new Array();
13593: for (var j=0; j<newSpare.options.length; j++) {
13594: var possible = newSpare.options[j].value;
13595: if (possible != '') {
13596: if (exclude.indexOf(possible) == -1) {
13597: okSpares.push(possible);
13598: } else {
13599: if (currnew == possible) {
13600: selIdx = 0;
13601: }
13602: }
13603: }
13604: }
13605: for (var k=0; k<include.length; k++) {
13606: if (okSpares.indexOf(include[k]) == -1) {
13607: okSpares.push(include[k]);
13608: }
13609: }
13610: okSpares.sort();
13611: newSpare.options.length = 0;
13612: if (selIdx == 0) {
13613: newSpare.options[0] = new Option("$select","",true,true);
13614: } else {
13615: newSpare.options[0] = new Option("$select","",false,false);
13616: }
13617: for (var m=0; m<okSpares.length; m++) {
13618: var idx = m+1;
13619: var selThis = 0;
13620: if (selIdx != 0) {
13621: if (okSpares[m] == currnew) {
13622: selThis = 1;
13623: }
13624: }
13625: if (selThis == 1) {
13626: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],true,true);
13627: } else {
13628: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],false,false);
13629: }
13630: }
13631: }
13632: return;
13633: }
13634:
13635: function checkNewSpares(lonhost,type) {
13636: var newSpare = document.getElementById('newspare_'+type+'_'+lonhost);
13637: var chosen = newSpare.options[newSpare.selectedIndex].value;
13638: if (chosen != '') {
13639: var othertype;
13640: var othernewSpare;
13641: if (type == 'primary') {
13642: othernewSpare = document.getElementById('newspare_default_'+lonhost);
13643: }
13644: if (type == 'default') {
13645: othernewSpare = document.getElementById('newspare_primary_'+lonhost);
13646: }
13647: if (othernewSpare.options[othernewSpare.selectedIndex].value == chosen) {
13648: othernewSpare.selectedIndex = 0;
13649: }
13650: }
13651: return;
13652: }
13653:
13654: // ]]>
13655: </script>
13656:
13657: END
13658:
13659: }
13660:
13661: sub common_domprefs_js {
13662: return <<"END";
13663:
13664: <script type="text/javascript">
13665: // <![CDATA[
13666:
1.150 raeburn 13667: function getIndicesByName(formname,item) {
1.152 raeburn 13668: var group = new Array();
1.150 raeburn 13669: for (var i=0;i<formname.elements.length;i++) {
13670: if (formname.elements[i].name == item) {
1.152 raeburn 13671: group.push(formname.elements[i].id);
1.150 raeburn 13672: }
13673: }
1.152 raeburn 13674: return group;
1.150 raeburn 13675: }
13676:
13677: // ]]>
13678: </script>
13679:
13680: END
1.152 raeburn 13681:
1.150 raeburn 13682: }
13683:
1.165 raeburn 13684: sub recaptcha_js {
13685: my %lt = &captcha_phrases();
13686: return <<"END";
13687:
13688: <script type="text/javascript">
13689: // <![CDATA[
13690:
13691: function updateCaptcha(caller,context) {
13692: var privitem;
13693: var pubitem;
13694: var privtext;
13695: var pubtext;
1.269 raeburn 13696: var versionitem;
13697: var versiontext;
1.165 raeburn 13698: if (document.getElementById(context+'_recaptchapub')) {
13699: pubitem = document.getElementById(context+'_recaptchapub');
13700: } else {
13701: return;
13702: }
13703: if (document.getElementById(context+'_recaptchapriv')) {
13704: privitem = document.getElementById(context+'_recaptchapriv');
13705: } else {
13706: return;
13707: }
13708: if (document.getElementById(context+'_recaptchapubtxt')) {
13709: pubtext = document.getElementById(context+'_recaptchapubtxt');
13710: } else {
13711: return;
13712: }
13713: if (document.getElementById(context+'_recaptchaprivtxt')) {
13714: privtext = document.getElementById(context+'_recaptchaprivtxt');
13715: } else {
13716: return;
13717: }
1.269 raeburn 13718: if (document.getElementById(context+'_recaptchaversion')) {
13719: versionitem = document.getElementById(context+'_recaptchaversion');
13720: } else {
13721: return;
13722: }
13723: if (document.getElementById(context+'_recaptchavertxt')) {
13724: versiontext = document.getElementById(context+'_recaptchavertxt');
13725: } else {
13726: return;
13727: }
1.165 raeburn 13728: if (caller.checked) {
13729: if (caller.value == 'recaptcha') {
13730: pubitem.type = 'text';
13731: privitem.type = 'text';
13732: pubitem.size = '40';
13733: privitem.size = '40';
13734: pubtext.innerHTML = "$lt{'pub'}";
13735: privtext.innerHTML = "$lt{'priv'}";
1.269 raeburn 13736: versionitem.type = 'text';
13737: versionitem.size = '3';
13738: versiontext.innerHTML = "$lt{'ver'}";
1.165 raeburn 13739: } else {
13740: pubitem.type = 'hidden';
13741: privitem.type = 'hidden';
1.269 raeburn 13742: versionitem.type = 'hidden';
1.165 raeburn 13743: pubtext.innerHTML = '';
13744: privtext.innerHTML = '';
1.269 raeburn 13745: versiontext.innerHTML = '';
1.165 raeburn 13746: }
13747: }
13748: return;
13749: }
13750:
13751: // ]]>
13752: </script>
13753:
13754: END
13755:
13756: }
13757:
1.236 raeburn 13758: sub toggle_display_js {
1.192 raeburn 13759: return <<"END";
13760:
13761: <script type="text/javascript">
13762: // <![CDATA[
13763:
1.236 raeburn 13764: function toggleDisplay(domForm,caller) {
13765: if (document.getElementById(caller)) {
13766: var divitem = document.getElementById(caller);
13767: var optionsElement = domForm.coursecredits;
1.264 raeburn 13768: var checkval = 1;
13769: var dispval = 'block';
1.236 raeburn 13770: if (caller == 'emailoptions') {
13771: optionsElement = domForm.cancreate_email;
13772: }
1.257 raeburn 13773: if (caller == 'studentsubmission') {
13774: optionsElement = domForm.postsubmit;
13775: }
1.264 raeburn 13776: if (caller == 'cloneinstcode') {
13777: optionsElement = domForm.canclone;
13778: checkval = 'instcode';
13779: }
1.236 raeburn 13780: if (optionsElement.length) {
1.192 raeburn 13781: var currval;
1.236 raeburn 13782: for (var i=0; i<optionsElement.length; i++) {
13783: if (optionsElement[i].checked) {
13784: currval = optionsElement[i].value;
1.192 raeburn 13785: }
13786: }
1.264 raeburn 13787: if (currval == checkval) {
13788: divitem.style.display = dispval;
1.192 raeburn 13789: } else {
1.236 raeburn 13790: divitem.style.display = 'none';
1.192 raeburn 13791: }
13792: }
13793: }
13794: return;
13795: }
13796:
13797: // ]]>
13798: </script>
13799:
13800: END
13801:
13802: }
13803:
1.165 raeburn 13804: sub captcha_phrases {
13805: return &Apache::lonlocal::texthash (
13806: priv => 'Private key',
13807: pub => 'Public key',
13808: original => 'original (CAPTCHA)',
13809: recaptcha => 'successor (ReCAPTCHA)',
13810: notused => 'unused',
1.269 raeburn 13811: ver => 'ReCAPTCHA version (1 or 2)',
1.165 raeburn 13812: );
13813: }
13814:
1.205 raeburn 13815: sub devalidate_remote_domconfs {
1.212 raeburn 13816: my ($dom,$cachekeys) = @_;
13817: return unless (ref($cachekeys) eq 'HASH');
1.205 raeburn 13818: my %servers = &Apache::lonnet::internet_dom_servers($dom);
13819: my %thismachine;
13820: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
1.267 raeburn 13821: my @posscached = ('domainconfig','domdefaults','ltitools');
1.260 raeburn 13822: if (keys(%servers)) {
1.205 raeburn 13823: foreach my $server (keys(%servers)) {
13824: next if ($thismachine{$server});
1.212 raeburn 13825: my @cached;
13826: foreach my $name (@posscached) {
13827: if ($cachekeys->{$name}) {
13828: push(@cached,&escape($name).':'.&escape($dom));
13829: }
13830: }
13831: if (@cached) {
13832: &Apache::lonnet::remote_devalidate_cache($server,\@cached);
13833: }
1.205 raeburn 13834: }
13835: }
13836: return;
13837: }
13838:
1.3 raeburn 13839: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>