Annotation of loncom/interface/domainprefs.pm, revision 1.275
1.1 raeburn 1: # The LearningOnline Network with CAPA
2: # Handler to set domain-wide configuration settings
3: #
1.275 ! raeburn 4: # $Id: domainprefs.pm,v 1.274 2016/07/24 14:34:59 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' =>
310: { text => 'Institutional directory searches',
1.67 raeburn 311: help => 'Domain_Configuration_InstDirectory_Search',
1.30 raeburn 312: header => [{col1 => 'Setting',
313: col2 => 'Value',}],
1.230 raeburn 314: print => \&print_directorysrch,
315: modify => \&modify_directorysrch,
1.30 raeburn 316: },
317: 'contacts' =>
318: { text => 'Contact Information',
1.67 raeburn 319: help => 'Domain_Configuration_Contact_Info',
1.30 raeburn 320: header => [{col1 => 'Setting',
321: col2 => 'Value',}],
1.230 raeburn 322: print => \&print_contacts,
323: modify => \&modify_contacts,
1.30 raeburn 324: },
325: 'usercreation' =>
326: { text => 'User creation',
1.67 raeburn 327: help => 'Domain_Configuration_User_Creation',
1.43 raeburn 328: header => [{col1 => 'Format rule type',
329: col2 => 'Format rules in force'},
1.34 raeburn 330: {col1 => 'User account creation',
331: col2 => 'Usernames which may be created',},
1.30 raeburn 332: {col1 => 'Context',
1.43 raeburn 333: col2 => 'Assignable authentication types'}],
1.230 raeburn 334: print => \&print_usercreation,
335: modify => \&modify_usercreation,
1.30 raeburn 336: },
1.224 raeburn 337: 'selfcreation' =>
338: { text => 'Users self-creating accounts',
339: help => 'Domain_Configuration_Self_Creation',
340: header => [{col1 => 'Self-creation with institutional username',
341: col2 => 'Enabled?'},
342: {col1 => 'Institutional user type (login/SSO self-creation)',
343: col2 => 'Information user can enter'},
344: {col1 => 'Self-creation with e-mail as username',
345: col2 => 'Settings'}],
1.230 raeburn 346: print => \&print_selfcreation,
347: modify => \&modify_selfcreation,
1.224 raeburn 348: },
1.69 raeburn 349: 'usermodification' =>
1.33 raeburn 350: { text => 'User modification',
1.67 raeburn 351: help => 'Domain_Configuration_User_Modification',
1.33 raeburn 352: header => [{col1 => 'Target user has role',
1.227 bisitz 353: col2 => 'User information updatable in author context'},
1.33 raeburn 354: {col1 => 'Target user has role',
1.227 bisitz 355: col2 => 'User information updatable in course context'}],
1.230 raeburn 356: print => \&print_usermodification,
357: modify => \&modify_usermodification,
1.33 raeburn 358: },
1.69 raeburn 359: 'scantron' =>
1.95 www 360: { text => 'Bubblesheet format file',
1.67 raeburn 361: help => 'Domain_Configuration_Scantron_Format',
1.46 raeburn 362: header => [ {col1 => 'Item',
363: col2 => '',
364: }],
1.230 raeburn 365: print => \&print_scantron,
366: modify => \&modify_scantron,
1.46 raeburn 367: },
1.86 raeburn 368: 'requestcourses' =>
369: {text => 'Request creation of courses',
370: help => 'Domain_Configuration_Request_Courses',
371: header => [{col1 => 'User affiliation',
1.102 raeburn 372: col2 => 'Availability/Processing of requests',},
373: {col1 => 'Setting',
1.216 raeburn 374: col2 => 'Value'},
375: {col1 => 'Available textbooks',
1.235 raeburn 376: col2 => ''},
1.242 raeburn 377: {col1 => 'Available templates',
378: col2 => ''},
1.235 raeburn 379: {col1 => 'Validation (not official courses)',
380: col2 => 'Value'},],
1.230 raeburn 381: print => \&print_quotas,
382: modify => \&modify_quotas,
1.86 raeburn 383: },
1.163 raeburn 384: 'requestauthor' =>
1.223 bisitz 385: {text => 'Request Authoring Space',
1.163 raeburn 386: help => 'Domain_Configuration_Request_Author',
387: header => [{col1 => 'User affiliation',
388: col2 => 'Availability/Processing of requests',},
389: {col1 => 'Setting',
390: col2 => 'Value'}],
1.230 raeburn 391: print => \&print_quotas,
392: modify => \&modify_quotas,
1.163 raeburn 393: },
1.69 raeburn 394: 'coursecategories' =>
1.120 raeburn 395: { text => 'Cataloging of courses/communities',
1.67 raeburn 396: help => 'Domain_Configuration_Cataloging_Courses',
1.238 raeburn 397: header => [{col1 => 'Catalog type/availability',
398: col2 => '',},
399: {col1 => 'Category settings for standard catalog',
1.57 raeburn 400: col2 => '',},
401: {col1 => 'Categories',
402: col2 => '',
403: }],
1.230 raeburn 404: print => \&print_coursecategories,
405: modify => \&modify_coursecategories,
1.69 raeburn 406: },
407: 'serverstatuses' =>
1.77 raeburn 408: {text => 'Access to server status pages',
1.69 raeburn 409: help => 'Domain_Configuration_Server_Status',
410: header => [{col1 => 'Status Page',
411: col2 => 'Other named users',
412: col3 => 'Specific IPs',
413: }],
1.230 raeburn 414: print => \&print_serverstatuses,
415: modify => \&modify_serverstatuses,
1.69 raeburn 416: },
1.118 jms 417: 'helpsettings' =>
418: {text => 'Help page settings',
419: help => 'Domain_Configuration_Help_Settings',
1.166 raeburn 420: header => [{col1 => 'Help Settings (logged-in users)',
421: col2 => 'Value'}],
1.230 raeburn 422: print => \&print_helpsettings,
423: modify => \&modify_helpsettings,
1.118 jms 424: },
1.121 raeburn 425: 'coursedefaults' =>
426: {text => 'Course/Community defaults',
427: help => 'Domain_Configuration_Course_Defaults',
1.139 raeburn 428: header => [{col1 => 'Defaults which can be overridden in each course by a CC',
429: col2 => 'Value',},
430: {col1 => 'Defaults which can be overridden for each course by a DC',
431: col2 => 'Value',},],
1.230 raeburn 432: print => \&print_coursedefaults,
433: modify => \&modify_coursedefaults,
1.121 raeburn 434: },
1.231 raeburn 435: 'selfenrollment' =>
436: {text => 'Self-enrollment in Course/Community',
437: help => 'Domain_Configuration_Selfenrollment',
438: header => [{col1 => 'Configuration Rights',
439: col2 => 'Configured by Course Personnel or Domain Coordinator?'},
440: {col1 => 'Defaults',
441: col2 => 'Value'},
442: {col1 => 'Self-enrollment validation (optional)',
443: col2 => 'Value'},],
444: print => \&print_selfenrollment,
445: modify => \&modify_selfenrollment,
446: },
1.120 raeburn 447: 'privacy' =>
448: {text => 'User Privacy',
449: help => 'Domain_Configuration_User_Privacy',
450: header => [{col1 => 'Setting',
451: col2 => 'Value',}],
1.230 raeburn 452: print => \&print_privacy,
453: modify => \&modify_privacy,
1.120 raeburn 454: },
1.141 raeburn 455: 'usersessions' =>
1.145 raeburn 456: {text => 'User session hosting/offloading',
1.137 raeburn 457: help => 'Domain_Configuration_User_Sessions',
1.145 raeburn 458: header => [{col1 => 'Domain server',
459: col2 => 'Servers to offload sessions to when busy'},
460: {col1 => 'Hosting of users from other domains',
1.137 raeburn 461: col2 => 'Rules'},
462: {col1 => "Hosting domain's own users elsewhere",
463: col2 => 'Rules'}],
1.230 raeburn 464: print => \&print_usersessions,
465: modify => \&modify_usersessions,
1.137 raeburn 466: },
1.150 raeburn 467: 'loadbalancing' =>
1.185 raeburn 468: {text => 'Dedicated Load Balancer(s)',
1.150 raeburn 469: help => 'Domain_Configuration_Load_Balancing',
1.171 raeburn 470: header => [{col1 => 'Balancers',
1.150 raeburn 471: col2 => 'Default destinations',
1.183 bisitz 472: col3 => 'User affiliation',
1.150 raeburn 473: col4 => 'Overrides'},
474: ],
1.230 raeburn 475: print => \&print_loadbalancing,
476: modify => \&modify_loadbalancing,
1.150 raeburn 477: },
1.267 raeburn 478: 'ltitools' =>
479: {text => 'External Tools (LTI)',
480: help => 'Domain_configuration_LTI_Tools',
481: header => [{col1 => 'Setting',
482: col2 => 'Value',}],
483: print => \&print_ltitools,
484: modify => \&modify_ltitools,
485: },
1.275 ! raeburn 486: 'ssl' =>
! 487: {text => 'LON-CAPA Network (SSL)',
! 488: help => 'Domain_Configuration_Network_SSL',
! 489: header => [{col1 => 'Server',
! 490: col2 => 'Certificate Status'},
! 491: {col1 => 'Connections to other servers',
! 492: col2 => 'Rules'},
! 493: {col1 => "Replicating domain's published content",
! 494: col2 => 'Rules'}],
! 495: print => \&print_ssl,
! 496: modify => \&modify_ssl,
! 497: },
1.3 raeburn 498: );
1.110 raeburn 499: if (keys(%servers) > 1) {
500: $prefs{'login'} = { text => 'Log-in page options',
501: help => 'Domain_Configuration_Login_Page',
502: header => [{col1 => 'Log-in Service',
503: col2 => 'Server Setting',},
504: {col1 => 'Log-in Page Items',
1.168 raeburn 505: col2 => ''},
506: {col1 => 'Log-in Help',
1.256 raeburn 507: col2 => 'Value'},
508: {col1 => 'Custom HTML in document head',
1.168 raeburn 509: col2 => 'Value'}],
1.230 raeburn 510: print => \&print_login,
511: modify => \&modify_login,
1.110 raeburn 512: };
513: }
1.174 foxr 514:
1.6 raeburn 515: my @roles = ('student','coordinator','author','admin');
1.30 raeburn 516: my @actions = &Apache::loncommon::get_env_multiple('form.actions');
1.3 raeburn 517: &Apache::lonhtmlcommon::add_breadcrumb
1.30 raeburn 518: ({href=>"javascript:changePage(document.$phase,'pickactions')",
1.133 raeburn 519: text=>"Settings to display/modify"});
1.9 raeburn 520: my $confname = $dom.'-domainconfig';
1.174 foxr 521:
1.3 raeburn 522: if ($phase eq 'process') {
1.212 raeburn 523: my $result = &Apache::lonconfigsettings::make_changes($r,$dom,$phase,$context,\@prefs_order,
524: \%prefs,\%domconfig,$confname,\@roles);
1.224 raeburn 525: if ((ref($result) eq 'HASH') && (keys(%{$result}))) {
1.205 raeburn 526: $r->rflush();
1.212 raeburn 527: &devalidate_remote_domconfs($dom,$result);
1.205 raeburn 528: }
1.30 raeburn 529: } elsif ($phase eq 'display') {
1.192 raeburn 530: my $js = &recaptcha_js().
1.236 raeburn 531: &toggle_display_js();
1.171 raeburn 532: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
1.152 raeburn 533: my ($othertitle,$usertypes,$types) =
534: &Apache::loncommon::sorted_inst_types($dom);
1.171 raeburn 535: $js .= &lonbalance_targets_js($dom,$types,\%servers,
536: $domconfig{'loadbalancing'}).
1.170 raeburn 537: &new_spares_js().
538: &common_domprefs_js().
539: &Apache::loncommon::javascript_array_indexof();
1.152 raeburn 540: }
1.216 raeburn 541: if (grep(/^requestcourses$/,@actions)) {
542: my $javascript_validations;
543: my $coursebrowserjs=&Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'});
544: $js .= <<END;
545: <script type="text/javascript">
546: $javascript_validations
547: </script>
548: $coursebrowserjs
549: END
550: }
1.150 raeburn 551: &Apache::lonconfigsettings::display_settings($r,$dom,$phase,$context,\@prefs_order,\%prefs,\%domconfig,$confname,$js);
1.1 raeburn 552: } else {
1.180 raeburn 553: # check if domconfig user exists for the domain.
554: my $servadm = $r->dir_config('lonAdmEMail');
555: my ($configuserok,$author_ok,$switchserver) =
556: &config_check($dom,$confname,$servadm);
557: unless ($configuserok eq 'ok') {
1.181 raeburn 558: &Apache::lonconfigsettings::print_header($r,$phase,$context);
559: $r->print(&mt('The domain configuration user "[_1]" has yet to be created.',
1.210 raeburn 560: $confname).
1.181 raeburn 561: '<br />'
562: );
1.180 raeburn 563: if ($switchserver) {
1.181 raeburn 564: $r->print(&mt('Ordinarily, that domain configuration user is created when the ./UPDATE script is run to install LON-CAPA for the first time.').
565: '<br />'.
566: &mt('However, that does not apply when new domains are added to a multi-domain server, and ./UPDATE has not been run recently.').
567: '<br />'.
568: &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).
569: '<br />'.
570: &mt('To do that now, use the following link: [_1]',$switchserver)
571: );
572: } else {
573: $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.').
574: '<br />'.
575: &mt('Once that is done, you will be able to use the web-based "Set domain configuration" to configure the domain')
576: );
1.180 raeburn 577: }
578: $r->print(&Apache::loncommon::end_page());
579: return OK;
580: }
1.21 raeburn 581: if (keys(%domconfig) == 0) {
582: my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
1.29 raeburn 583: my @ids=&Apache::lonnet::current_machine_ids();
584: if (!grep(/^\Q$primarylibserv\E$/,@ids)) {
1.21 raeburn 585: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.41 raeburn 586: my @loginimages = ('img','logo','domlogo','login');
1.21 raeburn 587: my $custom_img_count = 0;
588: foreach my $img (@loginimages) {
589: if ($designhash{$dom.'.login.'.$img} ne '') {
590: $custom_img_count ++;
591: }
592: }
593: foreach my $role (@roles) {
594: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
595: $custom_img_count ++;
596: }
597: }
598: if ($custom_img_count > 0) {
1.94 raeburn 599: &Apache::lonconfigsettings::print_header($r,$phase,$context);
1.21 raeburn 600: my $switch_server = &check_switchserver($dom,$confname);
1.29 raeburn 601: $r->print(
602: &mt('Domain configuration settings have yet to be saved for this domain via the web-based domain preferences interface.').'<br />'.
603: &mt("While this remains so, you must switch to the domain's primary library server in order to update settings.").'<br /><br />'.
604: &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 />'.
605: &mt("However, you will still need to switch to the domain's primary library server to upload new images or logos.").'<br /><br />');
606: if ($switch_server) {
1.30 raeburn 607: $r->print($switch_server.' '.&mt('to primary library server for domain: [_1]',$dom));
1.29 raeburn 608: }
1.91 raeburn 609: $r->print(&Apache::loncommon::end_page());
1.21 raeburn 610: return OK;
611: }
612: }
613: }
1.91 raeburn 614: &Apache::lonconfigsettings::display_choices($r,$phase,$context,\@prefs_order,\%prefs);
1.3 raeburn 615: }
616: return OK;
617: }
618:
619: sub process_changes {
1.205 raeburn 620: my ($r,$dom,$confname,$action,$roles,$values,$lastactref) = @_;
1.92 raeburn 621: my %domconfig;
622: if (ref($values) eq 'HASH') {
623: %domconfig = %{$values};
624: }
1.3 raeburn 625: my $output;
626: if ($action eq 'login') {
1.205 raeburn 627: $output = &modify_login($r,$dom,$confname,$lastactref,%domconfig);
1.6 raeburn 628: } elsif ($action eq 'rolecolors') {
1.9 raeburn 629: $output = &modify_rolecolors($r,$dom,$confname,$roles,
1.205 raeburn 630: $lastactref,%domconfig);
1.3 raeburn 631: } elsif ($action eq 'quotas') {
1.216 raeburn 632: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.3 raeburn 633: } elsif ($action eq 'autoenroll') {
1.205 raeburn 634: $output = &modify_autoenroll($dom,$lastactref,%domconfig);
1.3 raeburn 635: } elsif ($action eq 'autoupdate') {
636: $output = &modify_autoupdate($dom,%domconfig);
1.125 raeburn 637: } elsif ($action eq 'autocreate') {
638: $output = &modify_autocreate($dom,%domconfig);
1.23 raeburn 639: } elsif ($action eq 'directorysrch') {
640: $output = &modify_directorysrch($dom,%domconfig);
1.27 raeburn 641: } elsif ($action eq 'usercreation') {
1.28 raeburn 642: $output = &modify_usercreation($dom,%domconfig);
1.224 raeburn 643: } elsif ($action eq 'selfcreation') {
644: $output = &modify_selfcreation($dom,%domconfig);
1.33 raeburn 645: } elsif ($action eq 'usermodification') {
646: $output = &modify_usermodification($dom,%domconfig);
1.28 raeburn 647: } elsif ($action eq 'contacts') {
1.205 raeburn 648: $output = &modify_contacts($dom,$lastactref,%domconfig);
1.43 raeburn 649: } elsif ($action eq 'defaults') {
1.212 raeburn 650: $output = &modify_defaults($dom,$lastactref,%domconfig);
1.46 raeburn 651: } elsif ($action eq 'scantron') {
1.205 raeburn 652: $output = &modify_scantron($r,$dom,$confname,$lastactref,%domconfig);
1.48 raeburn 653: } elsif ($action eq 'coursecategories') {
1.239 raeburn 654: $output = &modify_coursecategories($dom,$lastactref,%domconfig);
1.69 raeburn 655: } elsif ($action eq 'serverstatuses') {
656: $output = &modify_serverstatuses($dom,%domconfig);
1.86 raeburn 657: } elsif ($action eq 'requestcourses') {
1.216 raeburn 658: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.163 raeburn 659: } elsif ($action eq 'requestauthor') {
1.216 raeburn 660: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.118 jms 661: } elsif ($action eq 'helpsettings') {
1.122 jms 662: $output = &modify_helpsettings($r,$dom,$confname,%domconfig);
1.121 raeburn 663: } elsif ($action eq 'coursedefaults') {
1.212 raeburn 664: $output = &modify_coursedefaults($dom,$lastactref,%domconfig);
1.231 raeburn 665: } elsif ($action eq 'selfenrollment') {
666: $output = &modify_selfenrollment($dom,$lastactref,%domconfig)
1.137 raeburn 667: } elsif ($action eq 'usersessions') {
1.212 raeburn 668: $output = &modify_usersessions($dom,$lastactref,%domconfig);
1.150 raeburn 669: } elsif ($action eq 'loadbalancing') {
670: $output = &modify_loadbalancing($dom,%domconfig);
1.267 raeburn 671: } elsif ($action eq 'ltitools') {
672: $output = &modify_ltitools($r,$dom,$action,$lastactref,%domconfig);
1.275 ! raeburn 673: } elsif ($action eq 'ssl') {
! 674: $output = &modify_ssl($dom,$lastactref,%domconfig);
1.3 raeburn 675: }
676: return $output;
677: }
678:
679: sub print_config_box {
1.9 raeburn 680: my ($r,$dom,$confname,$phase,$action,$item,$settings) = @_;
1.30 raeburn 681: my $rowtotal = 0;
1.49 raeburn 682: my $output;
683: if ($action eq 'coursecategories') {
684: $output = &coursecategories_javascript($settings);
1.236 raeburn 685: } elsif ($action eq 'defaults') {
686: $output = &defaults_javascript($settings);
1.91 raeburn 687: }
1.236 raeburn 688: $output .=
1.30 raeburn 689: '<table class="LC_nested_outer">
1.3 raeburn 690: <tr>
1.66 raeburn 691: <th align="left" valign="middle"><span class="LC_nobreak">'.
692: &mt($item->{text}).' '.
693: &Apache::loncommon::help_open_topic($item->{'help'}).'</span></th>'."\n".
694: '</tr>';
1.30 raeburn 695: $rowtotal ++;
1.110 raeburn 696: my $numheaders = 1;
697: if (ref($item->{'header'}) eq 'ARRAY') {
698: $numheaders = scalar(@{$item->{'header'}});
699: }
700: if ($numheaders > 1) {
1.64 raeburn 701: my $colspan = '';
1.145 raeburn 702: my $rightcolspan = '';
1.238 raeburn 703: if (($action eq 'rolecolors') || ($action eq 'defaults') ||
1.256 raeburn 704: (($action eq 'login') && ($numheaders < 4))) {
1.64 raeburn 705: $colspan = ' colspan="2"';
706: }
1.145 raeburn 707: if ($action eq 'usersessions') {
708: $rightcolspan = ' colspan="3"';
709: }
1.30 raeburn 710: $output .= '
1.3 raeburn 711: <tr>
712: <td>
713: <table class="LC_nested">
714: <tr class="LC_info_row">
1.59 bisitz 715: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[0]->{'col1'}).'</td>
1.145 raeburn 716: <td class="LC_right_item"'.$rightcolspan.'>'.&mt($item->{'header'}->[0]->{'col2'}).'</td>
1.30 raeburn 717: </tr>';
1.69 raeburn 718: $rowtotal ++;
1.230 raeburn 719: if (($action eq 'autoupdate') || ($action eq 'usercreation') || ($action eq 'selfcreation') ||
1.236 raeburn 720: ($action eq 'usermodification') || ($action eq 'defaults') || ($action eq 'coursedefaults') ||
1.275 ! raeburn 721: ($action eq 'selfenrollment') || ($action eq 'usersessions') || ($action eq 'ssl')) {
1.230 raeburn 722: $output .= $item->{'print'}->('top',$dom,$settings,\$rowtotal);
1.57 raeburn 723: } elsif ($action eq 'coursecategories') {
1.230 raeburn 724: $output .= $item->{'print'}->('top',$dom,$item,$settings,\$rowtotal);
1.110 raeburn 725: } elsif ($action eq 'login') {
1.256 raeburn 726: if ($numheaders == 4) {
1.168 raeburn 727: $colspan = ' colspan="2"';
728: $output .= &print_login('service',$dom,$confname,$phase,$settings,\$rowtotal);
729: } else {
730: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal);
731: }
1.230 raeburn 732: } elsif (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.163 raeburn 733: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.122 jms 734: } elsif ($action eq 'rolecolors') {
1.30 raeburn 735: $output .= &print_rolecolors($phase,'student',$dom,$confname,$settings,\$rowtotal);
1.6 raeburn 736: }
1.30 raeburn 737: $output .= '
1.6 raeburn 738: </table>
739: </td>
740: </tr>
741: <tr>
742: <td>
743: <table class="LC_nested">
744: <tr class="LC_info_row">
1.230 raeburn 745: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col1'}).'</td>
1.59 bisitz 746: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col2'}).'</td>
1.30 raeburn 747: </tr>';
748: $rowtotal ++;
1.230 raeburn 749: if (($action eq 'autoupdate') || ($action eq 'usercreation') ||
750: ($action eq 'selfcreation') || ($action eq 'selfenrollment') ||
1.275 ! raeburn 751: ($action eq 'usersessions') || ($action eq 'coursecategories') ||
! 752: ($action eq 'ssl')) {
1.238 raeburn 753: if ($action eq 'coursecategories') {
754: $output .= &print_coursecategories('middle',$dom,$item,$settings,\$rowtotal);
755: $colspan = ' colspan="2"';
756: } else {
757: $output .= $item->{'print'}->('middle',$dom,$settings,\$rowtotal);
758: }
759: $output .= '
1.63 raeburn 760: </table>
761: </td>
762: </tr>
763: <tr>
764: <td>
765: <table class="LC_nested">
766: <tr class="LC_info_row">
767: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1.224 raeburn 768: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
1.238 raeburn 769: </tr>'."\n";
770: if ($action eq 'coursecategories') {
771: $output .= &print_coursecategories('bottom',$dom,$item,$settings,\$rowtotal);
772: } else {
773: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
774: }
1.63 raeburn 775: $rowtotal ++;
1.236 raeburn 776: } elsif (($action eq 'usermodification') || ($action eq 'coursedefaults') ||
777: ($action eq 'defaults')) {
1.230 raeburn 778: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1.110 raeburn 779: } elsif ($action eq 'login') {
1.256 raeburn 780: if ($numheaders == 4) {
1.168 raeburn 781: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal).'
782: </table>
783: </td>
784: </tr>
785: <tr>
786: <td>
787: <table class="LC_nested">
788: <tr class="LC_info_row">
789: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1.216 raeburn 790: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td></tr>'.
1.168 raeburn 791: &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
792: $rowtotal ++;
793: } else {
794: $output .= &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
795: }
1.256 raeburn 796: $output .= '
797: </table>
798: </td>
799: </tr>
800: <tr>
801: <td>
802: <table class="LC_nested">
803: <tr class="LC_info_row">';
804: if ($numheaders == 4) {
805: $output .= '
806: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
807: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
808: </tr>';
809: } else {
810: $output .= '
811: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
812: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
813: </tr>';
814: }
815: $rowtotal ++;
816: $output .= &print_login('headtag',$dom,$confname,$phase,$settings,\$rowtotal);
1.102 raeburn 817: } elsif ($action eq 'requestcourses') {
1.247 raeburn 818: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
819: $rowtotal ++;
820: $output .= &print_studentcode($settings,\$rowtotal).'
1.216 raeburn 821: </table>
822: </td>
823: </tr>
824: <tr>
825: <td>
826: <table class="LC_nested">
827: <tr class="LC_info_row">
828: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
829: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
1.242 raeburn 830: &textbookcourses_javascript($settings).
831: &print_textbookcourses($dom,'textbooks',$settings,\$rowtotal).'
832: </table>
833: </td>
834: </tr>
835: <tr>
836: <td>
837: <table class="LC_nested">
838: <tr class="LC_info_row">
839: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
840: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td> </tr>'.
841: &print_textbookcourses($dom,'templates',$settings,\$rowtotal).'
1.235 raeburn 842: </table>
843: </td>
844: </tr>
845: <tr>
846: <td>
847: <table class="LC_nested">
848: <tr class="LC_info_row">
1.242 raeburn 849: <td class="LC_left_item"'.$colspan.' valign="top">'.&mt($item->{'header'}->[4]->{'col1'}).'</td>
850: <td class="LC_right_item" valign="top">'.&mt($item->{'header'}->[4]->{'col2'}).'</td>
1.235 raeburn 851: </tr>'.
852: &print_validation_rows('requestcourses',$dom,$settings,\$rowtotal);
1.163 raeburn 853: } elsif ($action eq 'requestauthor') {
854: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
1.247 raeburn 855: $rowtotal ++;
1.122 jms 856: } elsif ($action eq 'rolecolors') {
1.30 raeburn 857: $output .= &print_rolecolors($phase,'coordinator',$dom,$confname,$settings,\$rowtotal).'
1.6 raeburn 858: </table>
859: </td>
860: </tr>
861: <tr>
862: <td>
863: <table class="LC_nested">
864: <tr class="LC_info_row">
1.69 raeburn 865: <td class="LC_left_item"'.$colspan.' valign="top">'.
866: &mt($item->{'header'}->[2]->{'col1'}).'</td>
867: <td class="LC_right_item" valign="top">'.
868: &mt($item->{'header'}->[2]->{'col2'}).'</td>
1.3 raeburn 869: </tr>'.
1.30 raeburn 870: &print_rolecolors($phase,'author',$dom,$confname,$settings,\$rowtotal).'
1.3 raeburn 871: </table>
872: </td>
873: </tr>
874: <tr>
875: <td>
876: <table class="LC_nested">
877: <tr class="LC_info_row">
1.59 bisitz 878: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
879: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
1.3 raeburn 880: </tr>'.
1.30 raeburn 881: &print_rolecolors($phase,'admin',$dom,$confname,$settings,\$rowtotal);
882: $rowtotal += 2;
1.6 raeburn 883: }
1.3 raeburn 884: } else {
1.30 raeburn 885: $output .= '
1.3 raeburn 886: <tr>
887: <td>
888: <table class="LC_nested">
1.30 raeburn 889: <tr class="LC_info_row">';
1.24 raeburn 890: if (($action eq 'login') || ($action eq 'directorysrch')) {
1.30 raeburn 891: $output .= '
1.59 bisitz 892: <td class="LC_left_item" colspan="2">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
1.69 raeburn 893: } elsif ($action eq 'serverstatuses') {
894: $output .= '
895: <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).
896: '<br />('.&mt('Automatic access for Dom. Coords.').')</td>';
897:
1.6 raeburn 898: } else {
1.30 raeburn 899: $output .= '
1.69 raeburn 900: <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
901: }
1.72 raeburn 902: if (defined($item->{'header'}->[0]->{'col3'})) {
903: $output .= '<td class="LC_left_item" valign="top">'.
904: &mt($item->{'header'}->[0]->{'col2'});
905: if ($action eq 'serverstatuses') {
906: $output .= '<br />(<tt>'.&mt('user1:domain1,user2:domain2 etc.').'</tt>)';
907: }
1.69 raeburn 908: } else {
909: $output .= '<td class="LC_right_item" valign="top">'.
910: &mt($item->{'header'}->[0]->{'col2'});
911: }
912: $output .= '</td>';
913: if ($item->{'header'}->[0]->{'col3'}) {
1.150 raeburn 914: if (defined($item->{'header'}->[0]->{'col4'})) {
915: $output .= '<td class="LC_left_item" valign="top">'.
916: &mt($item->{'header'}->[0]->{'col3'});
917: } else {
918: $output .= '<td class="LC_right_item" valign="top">'.
919: &mt($item->{'header'}->[0]->{'col3'});
920: }
1.69 raeburn 921: if ($action eq 'serverstatuses') {
922: $output .= '<br />(<tt>'.&mt('IP1,IP2 etc.').'</tt>)';
923: }
924: $output .= '</td>';
1.6 raeburn 925: }
1.150 raeburn 926: if ($item->{'header'}->[0]->{'col4'}) {
927: $output .= '<td class="LC_right_item" valign="top">'.
928: &mt($item->{'header'}->[0]->{'col4'});
929: }
1.69 raeburn 930: $output .= '</tr>';
1.48 raeburn 931: $rowtotal ++;
1.168 raeburn 932: if ($action eq 'quotas') {
1.86 raeburn 933: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.230 raeburn 934: } elsif (($action eq 'autoenroll') || ($action eq 'autocreate') || ($action eq 'directorysrch') ||
1.267 raeburn 935: ($action eq 'contacts') || ($action eq 'serverstatuses') || ($action eq 'loadbalancing') ||
936: ($action eq 'ltitools')) {
1.230 raeburn 937: $output .= $item->{'print'}->($dom,$settings,\$rowtotal);
1.46 raeburn 938: } elsif ($action eq 'scantron') {
939: $output .= &print_scantronformat($r,$dom,$confname,$settings,\$rowtotal);
1.118 jms 940: } elsif ($action eq 'helpsettings') {
1.168 raeburn 941: $output .= &print_helpsettings($dom,$confname,$settings,\$rowtotal);
1.121 raeburn 942: }
1.3 raeburn 943: }
1.30 raeburn 944: $output .= '
1.3 raeburn 945: </table>
946: </td>
947: </tr>
1.30 raeburn 948: </table><br />';
949: return ($output,$rowtotal);
1.1 raeburn 950: }
951:
1.3 raeburn 952: sub print_login {
1.168 raeburn 953: my ($caller,$dom,$confname,$phase,$settings,$rowtotal) = @_;
1.110 raeburn 954: my ($css_class,$datatable);
1.6 raeburn 955: my %choices = &login_choices();
1.110 raeburn 956:
1.168 raeburn 957: if ($caller eq 'service') {
1.149 raeburn 958: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.110 raeburn 959: my $choice = $choices{'disallowlogin'};
960: $css_class = ' class="LC_odd_row"';
1.128 raeburn 961: $datatable .= '<tr'.$css_class.'><td>'.$choice.'</td>'.
1.110 raeburn 962: '<td align="right"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1.128 raeburn 963: '<th>'.$choices{'server'}.'</th>'.
964: '<th>'.$choices{'serverpath'}.'</th>'.
965: '<th>'.$choices{'custompath'}.'</th>'.
966: '<th><span class="LC_nobreak">'.$choices{'exempt'}.'</span></th></tr>'."\n";
1.110 raeburn 967: my %disallowed;
968: if (ref($settings) eq 'HASH') {
969: if (ref($settings->{'loginvia'}) eq 'HASH') {
970: %disallowed = %{$settings->{'loginvia'}};
971: }
972: }
973: foreach my $lonhost (sort(keys(%servers))) {
974: my $direct = 'selected="selected"';
1.128 raeburn 975: if (ref($disallowed{$lonhost}) eq 'HASH') {
976: if ($disallowed{$lonhost}{'server'} ne '') {
977: $direct = '';
978: }
1.110 raeburn 979: }
1.115 raeburn 980: $datatable .= '<tr><td>'.$servers{$lonhost}.'</td>'.
1.128 raeburn 981: '<td><select name="'.$lonhost.'_server">'.
1.110 raeburn 982: '<option value=""'.$direct.'>'.$choices{'directlogin'}.
983: '</option>';
1.184 raeburn 984: foreach my $hostid (sort(keys(%servers))) {
1.115 raeburn 985: next if ($servers{$hostid} eq $servers{$lonhost});
1.110 raeburn 986: my $selected = '';
1.128 raeburn 987: if (ref($disallowed{$lonhost}) eq 'HASH') {
988: if ($hostid eq $disallowed{$lonhost}{'server'}) {
989: $selected = 'selected="selected"';
990: }
1.110 raeburn 991: }
992: $datatable .= '<option value="'.$hostid.'"'.$selected.'>'.
993: $servers{$hostid}.'</option>';
994: }
1.128 raeburn 995: $datatable .= '</select></td>'.
996: '<td><select name="'.$lonhost.'_serverpath">';
997: foreach my $path ('','/','/adm/login','/adm/roles','custom') {
998: my $pathname = $path;
999: if ($path eq 'custom') {
1000: $pathname = &mt('Custom Path').' ->';
1001: }
1002: my $selected = '';
1003: if (ref($disallowed{$lonhost}) eq 'HASH') {
1004: if ($path eq $disallowed{$lonhost}{'serverpath'}) {
1005: $selected = 'selected="selected"';
1006: }
1007: } elsif ($path eq '') {
1008: $selected = 'selected="selected"';
1009: }
1010: $datatable .= '<option value="'.$path.'"'.$selected.'>'.$pathname.'</option>';
1011: }
1012: $datatable .= '</select></td>';
1013: my ($custom,$exempt);
1014: if (ref($disallowed{$lonhost}) eq 'HASH') {
1015: $custom = $disallowed{$lonhost}{'custompath'};
1016: $exempt = $disallowed{$lonhost}{'exempt'};
1017: }
1018: $datatable .= '<td><input type="text" name="'.$lonhost.'_custompath" size="6" value="'.$custom.'" /></td>'.
1019: '<td><input type="text" name="'.$lonhost.'_exempt" size="8" value="'.$exempt.'" /></td>'.
1020: '</tr>';
1.110 raeburn 1021: }
1022: $datatable .= '</table></td></tr>';
1023: return $datatable;
1.168 raeburn 1024: } elsif ($caller eq 'page') {
1025: my %defaultchecked = (
1026: 'coursecatalog' => 'on',
1.188 raeburn 1027: 'helpdesk' => 'on',
1.168 raeburn 1028: 'adminmail' => 'off',
1029: 'newuser' => 'off',
1030: );
1.188 raeburn 1031: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.168 raeburn 1032: my (%checkedon,%checkedoff);
1.42 raeburn 1033: foreach my $item (@toggles) {
1.168 raeburn 1034: if ($defaultchecked{$item} eq 'on') {
1035: $checkedon{$item} = ' checked="checked" ';
1.42 raeburn 1036: $checkedoff{$item} = ' ';
1.168 raeburn 1037: } elsif ($defaultchecked{$item} eq 'off') {
1038: $checkedoff{$item} = ' checked="checked" ';
1.42 raeburn 1039: $checkedon{$item} = ' ';
1040: }
1.1 raeburn 1041: }
1.168 raeburn 1042: my @images = ('img','logo','domlogo','login');
1043: my @logintext = ('textcol','bgcol');
1044: my @bgs = ('pgbg','mainbg','sidebg');
1045: my @links = ('link','alink','vlink');
1046: my %designhash = &Apache::loncommon::get_domainconf($dom);
1047: my %defaultdesign = %Apache::loncommon::defaultdesign;
1048: my (%is_custom,%designs);
1049: my %defaults = (
1050: font => $defaultdesign{'login.font'},
1051: );
1.6 raeburn 1052: foreach my $item (@images) {
1.168 raeburn 1053: $defaults{$item} = $defaultdesign{'login.'.$item};
1054: $defaults{'showlogo'}{$item} = 1;
1055: }
1056: foreach my $item (@bgs) {
1057: $defaults{'bgs'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 1058: }
1.41 raeburn 1059: foreach my $item (@logintext) {
1.168 raeburn 1060: $defaults{'logintext'}{$item} = $defaultdesign{'login.'.$item};
1.41 raeburn 1061: }
1.168 raeburn 1062: foreach my $item (@links) {
1063: $defaults{'links'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 1064: }
1.168 raeburn 1065: if (ref($settings) eq 'HASH') {
1066: foreach my $item (@toggles) {
1067: if ($settings->{$item} eq '1') {
1068: $checkedon{$item} = ' checked="checked" ';
1069: $checkedoff{$item} = ' ';
1070: } elsif ($settings->{$item} eq '0') {
1071: $checkedoff{$item} = ' checked="checked" ';
1072: $checkedon{$item} = ' ';
1073: }
1074: }
1075: foreach my $item (@images) {
1076: if (defined($settings->{$item})) {
1077: $designs{$item} = $settings->{$item};
1078: $is_custom{$item} = 1;
1079: }
1080: if (defined($settings->{'showlogo'}{$item})) {
1081: $designs{'showlogo'}{$item} = $settings->{'showlogo'}{$item};
1082: }
1083: }
1084: foreach my $item (@logintext) {
1085: if ($settings->{$item} ne '') {
1086: $designs{'logintext'}{$item} = $settings->{$item};
1087: $is_custom{$item} = 1;
1088: }
1089: }
1090: if ($settings->{'font'} ne '') {
1091: $designs{'font'} = $settings->{'font'};
1092: $is_custom{'font'} = 1;
1093: }
1094: foreach my $item (@bgs) {
1095: if ($settings->{$item} ne '') {
1096: $designs{'bgs'}{$item} = $settings->{$item};
1097: $is_custom{$item} = 1;
1098: }
1099: }
1100: foreach my $item (@links) {
1101: if ($settings->{$item} ne '') {
1102: $designs{'links'}{$item} = $settings->{$item};
1103: $is_custom{$item} = 1;
1104: }
1105: }
1106: } else {
1107: if ($designhash{$dom.'.login.font'} ne '') {
1108: $designs{'font'} = $designhash{$dom.'.login.font'};
1109: $is_custom{'font'} = 1;
1110: }
1111: foreach my $item (@images) {
1112: if ($designhash{$dom.'.login.'.$item} ne '') {
1113: $designs{$item} = $designhash{$dom.'.login.'.$item};
1114: $is_custom{$item} = 1;
1115: }
1116: }
1117: foreach my $item (@bgs) {
1118: if ($designhash{$dom.'.login.'.$item} ne '') {
1119: $designs{'bgs'}{$item} = $designhash{$dom.'.login.'.$item};
1120: $is_custom{$item} = 1;
1121: }
1.6 raeburn 1122: }
1.168 raeburn 1123: foreach my $item (@links) {
1124: if ($designhash{$dom.'.login.'.$item} ne '') {
1125: $designs{'links'}{$item} = $designhash{$dom.'.login.'.$item};
1126: $is_custom{$item} = 1;
1127: }
1.6 raeburn 1128: }
1129: }
1.168 raeburn 1130: my %alt_text = &Apache::lonlocal::texthash ( img => 'Log-in banner',
1131: logo => 'Institution Logo',
1132: domlogo => 'Domain Logo',
1133: login => 'Login box');
1134: my $itemcount = 1;
1135: foreach my $item (@toggles) {
1136: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1137: $datatable .=
1138: '<tr'.$css_class.'><td colspan="2">'.$choices{$item}.
1139: '</td><td>'.
1140: '<span class="LC_nobreak"><label><input type="radio" name="'.
1141: $item.'"'.$checkedon{$item}.' value="1" />'.&mt('Yes').
1142: '</label> <label><input type="radio" name="'.$item.'"'.
1143: $checkedoff{$item}.' value="0" />'.&mt('No').'</label></span></td>'.
1144: '</tr>';
1145: $itemcount ++;
1.6 raeburn 1146: }
1.168 raeburn 1147: $datatable .= &display_color_options($dom,$confname,$phase,'login',$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal,\@logintext);
1148: $datatable .= '</tr></table></td></tr>';
1149: } elsif ($caller eq 'help') {
1150: my ($defaulturl,$defaulttype,%url,%type,%lt,%langchoices);
1151: my $switchserver = &check_switchserver($dom,$confname);
1152: my $itemcount = 1;
1153: $defaulturl = '/adm/loginproblems.html';
1154: $defaulttype = 'default';
1155: %lt = &Apache::lonlocal::texthash (
1156: del => 'Delete?',
1157: rep => 'Replace:',
1158: upl => 'Upload:',
1159: default => 'Default',
1160: custom => 'Custom',
1161: );
1162: %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
1163: my @currlangs;
1164: if (ref($settings) eq 'HASH') {
1165: if (ref($settings->{'helpurl'}) eq 'HASH') {
1166: foreach my $key (sort(keys(%{$settings->{'helpurl'}}))) {
1167: next if ($settings->{'helpurl'}{$key} eq '');
1168: $url{$key} = $settings->{'helpurl'}{$key}.'?inhibitmenu=yes';
1169: $type{$key} = 'custom';
1170: unless ($key eq 'nolang') {
1171: push(@currlangs,$key);
1172: }
1173: }
1174: } elsif ($settings->{'helpurl'} ne '') {
1175: $type{'nolang'} = 'custom';
1176: $url{'nolang'} = $settings->{'helpurl'}.'?inhibitmenu=yes';
1.8 raeburn 1177: }
1178: }
1.168 raeburn 1179: foreach my $lang ('nolang',sort(@currlangs)) {
1180: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1181: $datatable .= '<tr'.$css_class.'>';
1182: if ($url{$lang} eq '') {
1183: $url{$lang} = $defaulturl;
1184: }
1185: if ($type{$lang} eq '') {
1186: $type{$lang} = $defaulttype;
1187: }
1188: $datatable .= '<td colspan="2"><span class="LC_nobreak">';
1189: if ($lang eq 'nolang') {
1190: $datatable .= &mt('Log-in help page if no specific language file: [_1]',
1191: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1192: } else {
1193: $datatable .= &mt('Log-in help page for language: [_1] is [_2]',
1194: $langchoices{$lang},
1195: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1196: }
1197: $datatable .= '</span></td>'."\n".
1198: '<td class="LC_left_item">';
1199: if ($type{$lang} eq 'custom') {
1200: $datatable .= '<span class="LC_nobreak"><label>'.
1201: '<input type="checkbox" name="loginhelpurl_del" value="'.$lang.'" />'.
1202: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1203: } else {
1204: $datatable .= $lt{'upl'};
1205: }
1206: $datatable .='<br />';
1207: if ($switchserver) {
1208: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1209: } else {
1210: $datatable .= '<input type="file" name="loginhelpurl_'.$lang.'" />';
1.6 raeburn 1211: }
1.168 raeburn 1212: $datatable .= '</td></tr>';
1213: $itemcount ++;
1.6 raeburn 1214: }
1.168 raeburn 1215: my @addlangs;
1216: foreach my $lang (sort(keys(%langchoices))) {
1217: next if ((grep(/^\Q$lang\E$/,@currlangs)) || ($lang eq 'x_chef'));
1218: push(@addlangs,$lang);
1219: }
1220: if (@addlangs > 0) {
1221: my %toadd;
1222: map { $toadd{$_} = $langchoices{$_} ; } @addlangs;
1223: $toadd{''} = &mt('Select');
1224: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1225: $datatable .= '<tr'.$css_class.'><td class="LC_left_item" colspan="2">'.
1226: &mt('Add log-in help page for a specific language:').' '.
1227: &Apache::loncommon::select_form('','loginhelpurl_add_lang',\%toadd).
1228: '</td><td class="LC_left_item">'.$lt{'upl'}.'<br />';
1229: if ($switchserver) {
1230: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1231: } else {
1232: $datatable .= '<input type="file" name="loginhelpurl_add_file" />';
1.6 raeburn 1233: }
1.168 raeburn 1234: $datatable .= '</td></tr>';
1.169 raeburn 1235: $itemcount ++;
1.6 raeburn 1236: }
1.169 raeburn 1237: $datatable .= &captcha_choice('login',$settings,$itemcount);
1.256 raeburn 1238: } elsif ($caller eq 'headtag') {
1239: my %domservers = &Apache::lonnet::get_servers($dom);
1240: my $choice = $choices{'headtag'};
1241: $css_class = ' class="LC_odd_row"';
1242: $datatable .= '<tr'.$css_class.'><td colspan="2">'.$choice.'</td>'.
1243: '<td align="left"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1244: '<th>'.$choices{'current'}.'</th>'.
1245: '<th>'.$choices{'action'}.'</th>'.
1246: '<th>'.$choices{'exempt'}.'</th></tr>'."\n";
1247: my (%currurls,%currexempt);
1248: if (ref($settings) eq 'HASH') {
1249: if (ref($settings->{'headtag'}) eq 'HASH') {
1250: foreach my $lonhost (keys(%{$settings->{'headtag'}})) {
1251: if (ref($settings->{'headtag'}{$lonhost}) eq 'HASH') {
1252: $currurls{$lonhost} = $settings->{'headtag'}{$lonhost}{'url'};
1253: $currexempt{$lonhost} = $settings->{'headtag'}{$lonhost}{'exempt'};
1254: }
1255: }
1256: }
1257: }
1258: my %lt = &Apache::lonlocal::texthash(
1259: del => 'Delete?',
1260: rep => 'Replace:',
1261: upl => 'Upload:',
1262: curr => 'View contents',
1263: none => 'None',
1264: );
1265: my $switchserver = &check_switchserver($dom,$confname);
1266: foreach my $lonhost (sort(keys(%domservers))) {
1267: my $exempt = &check_exempt_addresses($currexempt{$lonhost});
1268: $datatable .= '<tr><td>'.$domservers{$lonhost}.'</td>';
1269: if ($currurls{$lonhost}) {
1270: $datatable .= '<td class="LC_right_item"><a href="'.
1271: "javascript:void(open('$currurls{$lonhost}?inhibitmenu=yes','Custom_HeadTag',
1272: 'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
1273: '">'.$lt{'curr'}.'</a></td>'.
1274: '<td><span class="LC_nobreak"><label>'.
1275: '<input type="checkbox" name="loginheadtag_del" value="'.$lonhost.'" />'.
1276: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1277: } else {
1278: $datatable .= '<td class="LC_right_item">'.$lt{'none'}.'</td><td>'.$lt{'upl'};
1279: }
1280: $datatable .='<br />';
1281: if ($switchserver) {
1282: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1283: } else {
1284: $datatable .= '<input type="file" name="loginheadtag_'.$lonhost.'" />';
1285: }
1286: $datatable .= '</td><td><input type="textbox" name="loginheadtagexempt_'.$lonhost.'" value="'.$exempt.'" /></td></tr>';
1287: }
1288: $datatable .= '</table></td></tr>';
1.1 raeburn 1289: }
1.6 raeburn 1290: return $datatable;
1291: }
1292:
1293: sub login_choices {
1294: my %choices =
1295: &Apache::lonlocal::texthash (
1.116 bisitz 1296: coursecatalog => 'Display Course/Community Catalog link?',
1.110 raeburn 1297: adminmail => "Display Administrator's E-mail Address?",
1.188 raeburn 1298: helpdesk => 'Display "Contact Helpdesk" link',
1.110 raeburn 1299: disallowlogin => "Login page requests redirected",
1300: hostid => "Server",
1.128 raeburn 1301: server => "Redirect to:",
1302: serverpath => "Path",
1303: custompath => "Custom",
1304: exempt => "Exempt IP(s)",
1.110 raeburn 1305: directlogin => "No redirect",
1306: newuser => "Link to create a user account",
1307: img => "Header",
1308: logo => "Main Logo",
1309: domlogo => "Domain Logo",
1310: login => "Log-in Header",
1311: textcol => "Text color",
1312: bgcol => "Box color",
1313: bgs => "Background colors",
1314: links => "Link colors",
1315: font => "Font color",
1316: pgbg => "Header",
1317: mainbg => "Page",
1318: sidebg => "Login box",
1319: link => "Link",
1320: alink => "Active link",
1321: vlink => "Visited link",
1.256 raeburn 1322: headtag => "Custom markup",
1323: action => "Action",
1324: current => "Current",
1.6 raeburn 1325: );
1326: return %choices;
1327: }
1328:
1329: sub print_rolecolors {
1.30 raeburn 1330: my ($phase,$role,$dom,$confname,$settings,$rowtotal) = @_;
1.6 raeburn 1331: my %choices = &color_font_choices();
1332: my @bgs = ('pgbg','tabbg','sidebg');
1333: my @links = ('link','alink','vlink');
1334: my @images = ('img');
1335: my %alt_text = &Apache::lonlocal::texthash(img => "Banner for $role role");
1.7 albertel 1336: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.6 raeburn 1337: my %defaultdesign = %Apache::loncommon::defaultdesign;
1338: my (%is_custom,%designs);
1.200 raeburn 1339: my %defaults = &role_defaults($role,\@bgs,\@links,\@images);
1.6 raeburn 1340: if (ref($settings) eq 'HASH') {
1341: if (ref($settings->{$role}) eq 'HASH') {
1342: if ($settings->{$role}->{'img'} ne '') {
1343: $designs{'img'} = $settings->{$role}->{'img'};
1344: $is_custom{'img'} = 1;
1345: }
1346: if ($settings->{$role}->{'font'} ne '') {
1347: $designs{'font'} = $settings->{$role}->{'font'};
1348: $is_custom{'font'} = 1;
1349: }
1.97 tempelho 1350: if ($settings->{$role}->{'fontmenu'} ne '') {
1351: $designs{'fontmenu'} = $settings->{$role}->{'fontmenu'};
1352: $is_custom{'fontmenu'} = 1;
1353: }
1.6 raeburn 1354: foreach my $item (@bgs) {
1355: if ($settings->{$role}->{$item} ne '') {
1356: $designs{'bgs'}{$item} = $settings->{$role}->{$item};
1357: $is_custom{$item} = 1;
1358: }
1359: }
1360: foreach my $item (@links) {
1361: if ($settings->{$role}->{$item} ne '') {
1362: $designs{'links'}{$item} = $settings->{$role}->{$item};
1363: $is_custom{$item} = 1;
1364: }
1365: }
1366: }
1367: } else {
1368: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
1369: $designs{img} = $designhash{$dom.'.'.$role.'.img'};
1370: $is_custom{'img'} = 1;
1371: }
1.97 tempelho 1372: if ($designhash{$dom.'.'.$role.'.fontmenu'} ne '') {
1373: $designs{fontmenu} = $designhash{$dom.'.'.$role.'.fontmenu'};
1374: $is_custom{'fontmenu'} = 1;
1375: }
1.6 raeburn 1376: if ($designhash{$dom.'.'.$role.'.font'} ne '') {
1377: $designs{font} = $designhash{$dom.'.'.$role.'.font'};
1378: $is_custom{'font'} = 1;
1379: }
1380: foreach my $item (@bgs) {
1381: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1382: $designs{'bgs'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1383: $is_custom{$item} = 1;
1384:
1385: }
1386: }
1387: foreach my $item (@links) {
1388: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1389: $designs{'links'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1390: $is_custom{$item} = 1;
1391: }
1392: }
1393: }
1394: my $itemcount = 1;
1.30 raeburn 1395: my $datatable = &display_color_options($dom,$confname,$phase,$role,$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal);
1.6 raeburn 1396: $datatable .= '</tr></table></td></tr>';
1397: return $datatable;
1398: }
1399:
1.200 raeburn 1400: sub role_defaults {
1401: my ($role,$bgs,$links,$images,$logintext) = @_;
1.202 raeburn 1402: my %defaults;
1403: unless ((ref($bgs) eq 'ARRAY') && (ref($links) eq 'ARRAY') && (ref($images) eq 'ARRAY')) {
1.200 raeburn 1404: return %defaults;
1405: }
1406: my %defaultdesign = %Apache::loncommon::defaultdesign;
1407: if ($role eq 'login') {
1408: %defaults = (
1409: font => $defaultdesign{$role.'.font'},
1410: );
1411: if (ref($logintext) eq 'ARRAY') {
1412: foreach my $item (@{$logintext}) {
1413: $defaults{'logintext'}{$item} = $defaultdesign{$role.'.'.$item};
1414: }
1415: }
1416: foreach my $item (@{$images}) {
1417: $defaults{'showlogo'}{$item} = 1;
1418: }
1419: } else {
1420: %defaults = (
1421: img => $defaultdesign{$role.'.img'},
1422: font => $defaultdesign{$role.'.font'},
1423: fontmenu => $defaultdesign{$role.'.fontmenu'},
1424: );
1425: }
1426: foreach my $item (@{$bgs}) {
1427: $defaults{'bgs'}{$item} = $defaultdesign{$role.'.'.$item};
1428: }
1429: foreach my $item (@{$links}) {
1430: $defaults{'links'}{$item} = $defaultdesign{$role.'.'.$item};
1431: }
1432: foreach my $item (@{$images}) {
1433: $defaults{$item} = $defaultdesign{$role.'.'.$item};
1434: }
1435: return %defaults;
1436: }
1437:
1.6 raeburn 1438: sub display_color_options {
1.9 raeburn 1439: my ($dom,$confname,$phase,$role,$itemcount,$choices,$is_custom,$defaults,$designs,
1.135 bisitz 1440: $images,$bgs,$links,$alt_text,$rowtotal,$logintext) = @_;
1.159 raeburn 1441: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.6 raeburn 1442: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.176 raeburn 1443: my $datatable = '<tr'.$css_class.'>'.
1.6 raeburn 1444: '<td>'.$choices->{'font'}.'</td>';
1445: if (!$is_custom->{'font'}) {
1.30 raeburn 1446: $datatable .= '<td>'.&mt('Default in use:').' <span id="css_default_'.$role.'_font" style="color: '.$defaults->{'font'}.';">'.$defaults->{'font'}.'</span></td>';
1.6 raeburn 1447: } else {
1448: $datatable .= '<td> </td>';
1449: }
1.174 foxr 1450: my $current_color = $designs->{'font'} ? $designs->{'font'} : $defaults->{'font'};
1451:
1.8 raeburn 1452: $datatable .= '<td><span class="LC_nobreak">'.
1.174 foxr 1453: '<input type="text" class="colorchooser" size="10" name="'.$role.'_font"'.
1.202 raeburn 1454: ' value="'.$current_color.'" /> '.
1.174 foxr 1455: ' </td></tr>';
1.107 raeburn 1456: unless ($role eq 'login') {
1457: $datatable .= '<tr'.$css_class.'>'.
1458: '<td>'.$choices->{'fontmenu'}.'</td>';
1459: if (!$is_custom->{'fontmenu'}) {
1460: $datatable .= '<td>'.&mt('Default in use:').' <span id="css_default_'.$role.'_font" style="color: '.$defaults->{'fontmenu'}.';">'.$defaults->{'fontmenu'}.'</span></td>';
1461: } else {
1462: $datatable .= '<td> </td>';
1463: }
1.202 raeburn 1464: $current_color = $designs->{'fontmenu'} ?
1.174 foxr 1465: $designs->{'fontmenu'} : $defaults->{'fontmenu'};
1.107 raeburn 1466: $datatable .= '<td><span class="LC_nobreak">'.
1.174 foxr 1467: '<input class="colorchooser" type="text" size="10" name="'
1468: .$role.'_fontmenu"'.
1469: ' value="'.$current_color.'" /> '.
1470: ' </td></tr>';
1.97 tempelho 1471: }
1.9 raeburn 1472: my $switchserver = &check_switchserver($dom,$confname);
1.6 raeburn 1473: foreach my $img (@{$images}) {
1.18 albertel 1474: $itemcount ++;
1.6 raeburn 1475: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.8 raeburn 1476: $datatable .= '<tr'.$css_class.'>'.
1.70 raeburn 1477: '<td>'.$choices->{$img};
1.41 raeburn 1478: my ($imgfile,$img_import,$login_hdr_pick,$logincolors);
1.70 raeburn 1479: if ($role eq 'login') {
1480: if ($img eq 'login') {
1481: $login_hdr_pick =
1.135 bisitz 1482: &login_header_options($img,$role,$defaults,$is_custom,$choices);
1.70 raeburn 1483: $logincolors =
1484: &login_text_colors($img,$role,$logintext,$phase,$choices,
1.201 raeburn 1485: $designs,$defaults);
1.70 raeburn 1486: } elsif ($img ne 'domlogo') {
1487: $datatable.= &logo_display_options($img,$defaults,$designs);
1488: }
1489: }
1490: $datatable .= '</td>';
1.6 raeburn 1491: if ($designs->{$img} ne '') {
1492: $imgfile = $designs->{$img};
1.18 albertel 1493: $img_import = ($imgfile =~ m{^/adm/});
1.6 raeburn 1494: } else {
1495: $imgfile = $defaults->{$img};
1496: }
1497: if ($imgfile) {
1.9 raeburn 1498: my ($showfile,$fullsize);
1499: if ($imgfile =~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
1.6 raeburn 1500: my $urldir = $1;
1501: my $filename = $2;
1502: my @info = &Apache::lonnet::stat_file($designs->{$img});
1503: if (@info) {
1504: my $thumbfile = 'tn-'.$filename;
1505: my @thumb=&Apache::lonnet::stat_file($urldir.'/'.$thumbfile);
1506: if (@thumb) {
1507: $showfile = $urldir.'/'.$thumbfile;
1508: } else {
1509: $showfile = $imgfile;
1510: }
1511: } else {
1512: $showfile = '';
1513: }
1514: } elsif ($imgfile =~ m-^/(adm/[^/]+)/([^/]+)$-) {
1.16 raeburn 1515: $showfile = $imgfile;
1.6 raeburn 1516: my $imgdir = $1;
1517: my $filename = $2;
1.159 raeburn 1518: if (-e "$londocroot/$imgdir/tn-".$filename) {
1.6 raeburn 1519: $showfile = "/$imgdir/tn-".$filename;
1520: } else {
1.159 raeburn 1521: my $input = $londocroot.$imgfile;
1522: my $output = "$londocroot/$imgdir/tn-".$filename;
1.6 raeburn 1523: if (!-e $output) {
1.9 raeburn 1524: my ($width,$height) = &thumb_dimensions();
1.16 raeburn 1525: my ($fullwidth,$fullheight) = &check_dimensions($input);
1526: if ($fullwidth ne '' && $fullheight ne '') {
1527: if ($fullwidth > $width && $fullheight > $height) {
1528: my $size = $width.'x'.$height;
1529: system("convert -sample $size $input $output");
1.159 raeburn 1530: $showfile = "/$imgdir/tn-".$filename;
1.16 raeburn 1531: }
1532: }
1.6 raeburn 1533: }
1534: }
1.16 raeburn 1535: }
1.6 raeburn 1536: if ($showfile) {
1.40 raeburn 1537: if ($showfile =~ m{^/(adm|res)/}) {
1538: if ($showfile =~ m{^/res/}) {
1539: my $local_showfile =
1540: &Apache::lonnet::filelocation('',$showfile);
1541: &Apache::lonnet::repcopy($local_showfile);
1542: }
1543: $showfile = &Apache::loncommon::lonhttpdurl($showfile);
1544: }
1545: if ($imgfile) {
1546: if ($imgfile =~ m{^/(adm|res)/}) {
1547: if ($imgfile =~ m{^/res/}) {
1548: my $local_imgfile =
1549: &Apache::lonnet::filelocation('',$imgfile);
1550: &Apache::lonnet::repcopy($local_imgfile);
1551: }
1552: $fullsize = &Apache::loncommon::lonhttpdurl($imgfile);
1553: } else {
1554: $fullsize = $imgfile;
1555: }
1556: }
1.41 raeburn 1557: $datatable .= '<td>';
1558: if ($img eq 'login') {
1.135 bisitz 1559: $datatable .= $login_hdr_pick;
1560: }
1.41 raeburn 1561: $datatable .= &image_changes($is_custom->{$img},$alt_text->{$img},$img_import,
1562: $showfile,$fullsize,$role,$img,$imgfile,$logincolors);
1.6 raeburn 1563: } else {
1.201 raeburn 1564: $datatable .= '<td> </td><td class="LC_left_item">'.
1565: &mt('Upload:').'<br />';
1.6 raeburn 1566: }
1567: } else {
1.201 raeburn 1568: $datatable .= '<td> </td><td class="LC_left_item">'.
1569: &mt('Upload:').'<br />';
1.6 raeburn 1570: }
1.9 raeburn 1571: if ($switchserver) {
1572: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1573: } else {
1.135 bisitz 1574: if ($img ne 'login') { # suppress file selection for Log-in header
1575: $datatable .=' <input type="file" name="'.$role.'_'.$img.'" />';
1576: }
1.9 raeburn 1577: }
1578: $datatable .= '</td></tr>';
1.6 raeburn 1579: }
1580: $itemcount ++;
1581: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1582: $datatable .= '<tr'.$css_class.'>'.
1583: '<td>'.$choices->{'bgs'}.'</td>';
1584: my $bgs_def;
1585: foreach my $item (@{$bgs}) {
1586: if (!$is_custom->{$item}) {
1.70 raeburn 1587: $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 1588: }
1589: }
1590: if ($bgs_def) {
1.8 raeburn 1591: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$bgs_def.'</tr></table></td>';
1.6 raeburn 1592: } else {
1593: $datatable .= '<td> </td>';
1594: }
1595: $datatable .= '<td class="LC_right_item">'.
1596: '<table border="0"><tr>';
1.174 foxr 1597:
1.6 raeburn 1598: foreach my $item (@{$bgs}) {
1.201 raeburn 1599: $datatable .= '<td align="center">'.$choices->{$item};
1.174 foxr 1600: my $color = $designs->{'bgs'}{$item} ? $designs->{'bgs'}{$item} : $defaults->{'bgs'}{$item};
1.6 raeburn 1601: if ($designs->{'bgs'}{$item}) {
1.174 foxr 1602: $datatable .= ' ';
1.6 raeburn 1603: }
1.174 foxr 1604: $datatable .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1.41 raeburn 1605: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.6 raeburn 1606: }
1607: $datatable .= '</tr></table></td></tr>';
1608: $itemcount ++;
1609: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1610: $datatable .= '<tr'.$css_class.'>'.
1611: '<td>'.$choices->{'links'}.'</td>';
1612: my $links_def;
1613: foreach my $item (@{$links}) {
1614: if (!$is_custom->{$item}) {
1.30 raeburn 1615: $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 1616: }
1617: }
1618: if ($links_def) {
1.8 raeburn 1619: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$links_def.'</tr></table></td>';
1.6 raeburn 1620: } else {
1621: $datatable .= '<td> </td>';
1622: }
1623: $datatable .= '<td class="LC_right_item">'.
1624: '<table border="0"><tr>';
1625: foreach my $item (@{$links}) {
1.234 raeburn 1626: my $color = $designs->{'links'}{$item} ? $designs->{'links'}{$item} : $defaults->{'links'}{$item};
1.201 raeburn 1627: $datatable .= '<td align="center">'.$choices->{$item}."\n";
1.6 raeburn 1628: if ($designs->{'links'}{$item}) {
1.174 foxr 1629: $datatable.=' ';
1.6 raeburn 1630: }
1.174 foxr 1631: $datatable .= '<br /><input type="text" size="8" class="colorchooser" name="'.$role.'_'.$item.'" value="'.$color.
1.6 raeburn 1632: '" /></td>';
1633: }
1.30 raeburn 1634: $$rowtotal += $itemcount;
1.3 raeburn 1635: return $datatable;
1636: }
1637:
1.70 raeburn 1638: sub logo_display_options {
1639: my ($img,$defaults,$designs) = @_;
1640: my $checkedon;
1641: if (ref($defaults) eq 'HASH') {
1642: if (ref($defaults->{'showlogo'}) eq 'HASH') {
1643: if ($defaults->{'showlogo'}{$img}) {
1644: $checkedon = 'checked="checked" ';
1645: }
1646: }
1647: }
1648: if (ref($designs) eq 'HASH') {
1649: if (ref($designs->{'showlogo'}) eq 'HASH') {
1650: if (defined($designs->{'showlogo'}{$img})) {
1651: if ($designs->{'showlogo'}{$img} == 0) {
1652: $checkedon = '';
1653: } elsif ($designs->{'showlogo'}{$img} == 1) {
1654: $checkedon = 'checked="checked" ';
1655: }
1656: }
1657: }
1658: }
1659: return '<br /><label> <input type="checkbox" name="'.
1660: 'login_showlogo_'.$img.'" value="1" '.$checkedon.'/>'.
1661: &mt('show').'</label>'."\n";
1662: }
1663:
1.41 raeburn 1664: sub login_header_options {
1.135 bisitz 1665: my ($img,$role,$defaults,$is_custom,$choices) = @_;
1666: my $output = '';
1.41 raeburn 1667: if ((!$is_custom->{'textcol'}) || (!$is_custom->{'bgcol'})) {
1.135 bisitz 1668: $output .= &mt('Text default(s):').'<br />';
1.41 raeburn 1669: if (!$is_custom->{'textcol'}) {
1670: $output .= $choices->{'textcol'}.': '.$defaults->{'logintext'}{'textcol'}.
1671: ' ';
1672: }
1673: if (!$is_custom->{'bgcol'}) {
1674: $output .= $choices->{'bgcol'}.': '.
1675: '<span id="css_'.$role.'_font" style="background-color: '.
1676: $defaults->{'logintext'}{'bgcol'}.';"> </span>';
1677: }
1678: $output .= '<br />';
1679: }
1680: $output .='<br />';
1681: return $output;
1682: }
1683:
1684: sub login_text_colors {
1.201 raeburn 1685: my ($img,$role,$logintext,$phase,$choices,$designs,$defaults) = @_;
1.41 raeburn 1686: my $color_menu = '<table border="0"><tr>';
1687: foreach my $item (@{$logintext}) {
1.201 raeburn 1688: $color_menu .= '<td align="center">'.$choices->{$item};
1689: my $color = $designs->{'logintext'}{$item} ? $designs->{'logintext'}{$item} : $defaults->{'logintext'}{$item};
1690: $color_menu .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1691: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.41 raeburn 1692: }
1693: $color_menu .= '</tr></table><br />';
1694: return $color_menu;
1695: }
1696:
1697: sub image_changes {
1698: my ($is_custom,$alt_text,$img_import,$showfile,$fullsize,$role,$img,$imgfile,$logincolors) = @_;
1699: my $output;
1.135 bisitz 1700: if ($img eq 'login') {
1701: # suppress image for Log-in header
1702: } elsif (!$is_custom) {
1.70 raeburn 1703: if ($img ne 'domlogo') {
1.41 raeburn 1704: $output .= &mt('Default image:').'<br />';
1705: } else {
1706: $output .= &mt('Default in use:').'<br />';
1707: }
1708: }
1.135 bisitz 1709: if ($img eq 'login') { # suppress image for Log-in header
1710: $output .= '<td>'.$logincolors;
1.41 raeburn 1711: } else {
1.135 bisitz 1712: if ($img_import) {
1713: $output .= '<input type="hidden" name="'.$role.'_import_'.$img.'" value="'.$imgfile.'" />';
1714: }
1715: $output .= '<a href="'.$fullsize.'" target="_blank"><img src="'.
1716: $showfile.'" alt="'.$alt_text.'" border="0" /></a></td>';
1717: if ($is_custom) {
1718: $output .= '<td>'.$logincolors.'<span class="LC_nobreak"><label>'.
1719: '<input type="checkbox" name="'.
1720: $role.'_del_'.$img.'" value="1" />'.&mt('Delete?').
1721: '</label> '.&mt('Replace:').'</span><br />';
1722: } else {
1.201 raeburn 1723: $output .= '<td valign="middle">'.$logincolors.&mt('Upload:').'<br />';
1.135 bisitz 1724: }
1.41 raeburn 1725: }
1726: return $output;
1727: }
1728:
1.3 raeburn 1729: sub print_quotas {
1.86 raeburn 1730: my ($dom,$settings,$rowtotal,$action) = @_;
1731: my $context;
1732: if ($action eq 'quotas') {
1733: $context = 'tools';
1734: } else {
1735: $context = $action;
1736: }
1.197 raeburn 1737: my ($datatable,$defaultquota,$authorquota,@usertools,@options,%validations);
1.44 raeburn 1738: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.3 raeburn 1739: my $typecount = 0;
1.101 raeburn 1740: my ($css_class,%titles);
1.86 raeburn 1741: if ($context eq 'requestcourses') {
1.271 raeburn 1742: @usertools = ('official','unofficial','community','textbook','placement');
1.106 raeburn 1743: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 1744: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
1745: %titles = &courserequest_titles();
1.163 raeburn 1746: } elsif ($context eq 'requestauthor') {
1747: @usertools = ('author');
1748: @options = ('norequest','approval','automatic');
1.210 raeburn 1749: %titles = &authorrequest_titles();
1.86 raeburn 1750: } else {
1.162 raeburn 1751: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 1752: %titles = &tool_titles();
1.86 raeburn 1753: }
1.26 raeburn 1754: if (ref($types) eq 'ARRAY') {
1.23 raeburn 1755: foreach my $type (@{$types}) {
1.197 raeburn 1756: my ($currdefquota,$currauthorquota);
1.163 raeburn 1757: unless (($context eq 'requestcourses') ||
1758: ($context eq 'requestauthor')) {
1.86 raeburn 1759: if (ref($settings) eq 'HASH') {
1760: if (ref($settings->{defaultquota}) eq 'HASH') {
1.197 raeburn 1761: $currdefquota = $settings->{defaultquota}->{$type};
1.86 raeburn 1762: } else {
1763: $currdefquota = $settings->{$type};
1764: }
1.197 raeburn 1765: if (ref($settings->{authorquota}) eq 'HASH') {
1766: $currauthorquota = $settings->{authorquota}->{$type};
1767: }
1.78 raeburn 1768: }
1.72 raeburn 1769: }
1.3 raeburn 1770: if (defined($usertypes->{$type})) {
1771: $typecount ++;
1772: $css_class = $typecount%2?' class="LC_odd_row"':'';
1.72 raeburn 1773: $datatable .= '<tr'.$css_class.'>'.
1.3 raeburn 1774: '<td>'.$usertypes->{$type}.'</td>'.
1.72 raeburn 1775: '<td class="LC_left_item">';
1.101 raeburn 1776: if ($context eq 'requestcourses') {
1777: $datatable .= '<table><tr>';
1778: }
1779: my %cell;
1.72 raeburn 1780: foreach my $item (@usertools) {
1.101 raeburn 1781: if ($context eq 'requestcourses') {
1782: my ($curroption,$currlimit);
1783: if (ref($settings) eq 'HASH') {
1784: if (ref($settings->{$item}) eq 'HASH') {
1785: $curroption = $settings->{$item}->{$type};
1786: if ($curroption =~ /^autolimit=(\d*)$/) {
1787: $currlimit = $1;
1788: }
1789: }
1790: }
1791: if (!$curroption) {
1792: $curroption = 'norequest';
1793: }
1794: $datatable .= '<th>'.$titles{$item}.'</th>';
1795: foreach my $option (@options) {
1796: my $val = $option;
1797: if ($option eq 'norequest') {
1798: $val = 0;
1799: }
1800: if ($option eq 'validate') {
1801: my $canvalidate = 0;
1802: if (ref($validations{$item}) eq 'HASH') {
1803: if ($validations{$item}{$type}) {
1804: $canvalidate = 1;
1805: }
1806: }
1807: next if (!$canvalidate);
1808: }
1809: my $checked = '';
1810: if ($option eq $curroption) {
1811: $checked = ' checked="checked"';
1812: } elsif ($option eq 'autolimit') {
1813: if ($curroption =~ /^autolimit/) {
1814: $checked = ' checked="checked"';
1815: }
1816: }
1817: $cell{$item} .= '<span class="LC_nobreak"><label>'.
1818: '<input type="radio" name="crsreq_'.$item.
1819: '_'.$type.'" value="'.$val.'"'.$checked.' />'.
1.127 raeburn 1820: $titles{$option}.'</label>';
1.101 raeburn 1821: if ($option eq 'autolimit') {
1.127 raeburn 1822: $cell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 1823: $item.'_limit_'.$type.'" size="1" '.
1.103 raeburn 1824: 'value="'.$currlimit.'" />';
1.101 raeburn 1825: }
1.127 raeburn 1826: $cell{$item} .= '</span> ';
1.103 raeburn 1827: if ($option eq 'autolimit') {
1.127 raeburn 1828: $cell{$item} .= $titles{'unlimited'};
1.103 raeburn 1829: }
1.101 raeburn 1830: }
1.163 raeburn 1831: } elsif ($context eq 'requestauthor') {
1832: my $curroption;
1833: if (ref($settings) eq 'HASH') {
1834: $curroption = $settings->{$type};
1835: }
1836: if (!$curroption) {
1837: $curroption = 'norequest';
1838: }
1839: foreach my $option (@options) {
1840: my $val = $option;
1841: if ($option eq 'norequest') {
1842: $val = 0;
1843: }
1844: my $checked = '';
1845: if ($option eq $curroption) {
1846: $checked = ' checked="checked"';
1847: }
1848: $datatable .= '<span class="LC_nobreak"><label>'.
1849: '<input type="radio" name="authorreq_'.$type.
1850: '" value="'.$val.'"'.$checked.' />'.
1851: $titles{$option}.'</label></span> ';
1852: }
1.101 raeburn 1853: } else {
1854: my $checked = 'checked="checked" ';
1855: if (ref($settings) eq 'HASH') {
1856: if (ref($settings->{$item}) eq 'HASH') {
1857: if ($settings->{$item}->{$type} == 0) {
1858: $checked = '';
1859: } elsif ($settings->{$item}->{$type} == 1) {
1860: $checked = 'checked="checked" ';
1861: }
1.78 raeburn 1862: }
1.72 raeburn 1863: }
1.101 raeburn 1864: $datatable .= '<span class="LC_nobreak"><label>'.
1865: '<input type="checkbox" name="'.$context.'_'.$item.
1866: '" value="'.$type.'" '.$checked.'/>'.$titles{$item}.
1867: '</label></span> ';
1.72 raeburn 1868: }
1.101 raeburn 1869: }
1870: if ($context eq 'requestcourses') {
1871: $datatable .= '</tr><tr>';
1872: foreach my $item (@usertools) {
1.106 raeburn 1873: $datatable .= '<td style="vertical-align: top">'.$cell{$item}.'</td>';
1.101 raeburn 1874: }
1875: $datatable .= '</tr></table>';
1.72 raeburn 1876: }
1.86 raeburn 1877: $datatable .= '</td>';
1.163 raeburn 1878: unless (($context eq 'requestcourses') ||
1879: ($context eq 'requestauthor')) {
1.86 raeburn 1880: $datatable .=
1.197 raeburn 1881: '<td class="LC_right_item">'.
1882: '<span class="LC_nobreak">'.&mt('Portfolio').': '.
1.3 raeburn 1883: '<input type="text" name="quota_'.$type.
1.72 raeburn 1884: '" value="'.$currdefquota.
1.197 raeburn 1885: '" size="5" /></span>'.(' ' x 2).
1886: '<span class="LC_nobreak">'.&mt('Authoring').': '.
1887: '<input type="text" name="authorquota_'.$type.
1888: '" value="'.$currauthorquota.
1889: '" size="5" /></span></td>';
1.86 raeburn 1890: }
1891: $datatable .= '</tr>';
1.3 raeburn 1892: }
1893: }
1894: }
1.163 raeburn 1895: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 1896: $defaultquota = '20';
1.197 raeburn 1897: $authorquota = '500';
1.86 raeburn 1898: if (ref($settings) eq 'HASH') {
1899: if (ref($settings->{'defaultquota'}) eq 'HASH') {
1900: $defaultquota = $settings->{'defaultquota'}->{'default'};
1901: } elsif (defined($settings->{'default'})) {
1902: $defaultquota = $settings->{'default'};
1903: }
1.197 raeburn 1904: if (ref($settings->{'authorquota'}) eq 'HASH') {
1905: $authorquota = $settings->{'authorquota'}->{'default'};
1906: }
1.3 raeburn 1907: }
1908: }
1909: $typecount ++;
1910: $css_class = $typecount%2?' class="LC_odd_row"':'';
1911: $datatable .= '<tr'.$css_class.'>'.
1.26 raeburn 1912: '<td>'.$othertitle.'</td>'.
1.72 raeburn 1913: '<td class="LC_left_item">';
1.101 raeburn 1914: if ($context eq 'requestcourses') {
1915: $datatable .= '<table><tr>';
1916: }
1917: my %defcell;
1.72 raeburn 1918: foreach my $item (@usertools) {
1.101 raeburn 1919: if ($context eq 'requestcourses') {
1920: my ($curroption,$currlimit);
1921: if (ref($settings) eq 'HASH') {
1922: if (ref($settings->{$item}) eq 'HASH') {
1923: $curroption = $settings->{$item}->{'default'};
1924: if ($curroption =~ /^autolimit=(\d*)$/) {
1925: $currlimit = $1;
1926: }
1927: }
1928: }
1929: if (!$curroption) {
1930: $curroption = 'norequest';
1931: }
1932: $datatable .= '<th>'.$titles{$item}.'</th>';
1933: foreach my $option (@options) {
1934: my $val = $option;
1935: if ($option eq 'norequest') {
1936: $val = 0;
1937: }
1938: if ($option eq 'validate') {
1939: my $canvalidate = 0;
1940: if (ref($validations{$item}) eq 'HASH') {
1941: if ($validations{$item}{'default'}) {
1942: $canvalidate = 1;
1943: }
1944: }
1945: next if (!$canvalidate);
1946: }
1947: my $checked = '';
1948: if ($option eq $curroption) {
1949: $checked = ' checked="checked"';
1950: } elsif ($option eq 'autolimit') {
1951: if ($curroption =~ /^autolimit/) {
1952: $checked = ' checked="checked"';
1953: }
1954: }
1955: $defcell{$item} .= '<span class="LC_nobreak"><label>'.
1956: '<input type="radio" name="crsreq_'.$item.
1957: '_default" value="'.$val.'"'.$checked.' />'.
1958: $titles{$option}.'</label>';
1959: if ($option eq 'autolimit') {
1.127 raeburn 1960: $defcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 1961: $item.'_limit_default" size="1" '.
1962: 'value="'.$currlimit.'" />';
1963: }
1.127 raeburn 1964: $defcell{$item} .= '</span> ';
1.104 raeburn 1965: if ($option eq 'autolimit') {
1.127 raeburn 1966: $defcell{$item} .= $titles{'unlimited'};
1.104 raeburn 1967: }
1.101 raeburn 1968: }
1.163 raeburn 1969: } elsif ($context eq 'requestauthor') {
1970: my $curroption;
1971: if (ref($settings) eq 'HASH') {
1.172 raeburn 1972: $curroption = $settings->{'default'};
1.163 raeburn 1973: }
1974: if (!$curroption) {
1975: $curroption = 'norequest';
1976: }
1977: foreach my $option (@options) {
1978: my $val = $option;
1979: if ($option eq 'norequest') {
1980: $val = 0;
1981: }
1982: my $checked = '';
1983: if ($option eq $curroption) {
1984: $checked = ' checked="checked"';
1985: }
1986: $datatable .= '<span class="LC_nobreak"><label>'.
1987: '<input type="radio" name="authorreq_default"'.
1988: ' value="'.$val.'"'.$checked.' />'.
1989: $titles{$option}.'</label></span> ';
1990: }
1.101 raeburn 1991: } else {
1992: my $checked = 'checked="checked" ';
1993: if (ref($settings) eq 'HASH') {
1994: if (ref($settings->{$item}) eq 'HASH') {
1995: if ($settings->{$item}->{'default'} == 0) {
1996: $checked = '';
1997: } elsif ($settings->{$item}->{'default'} == 1) {
1998: $checked = 'checked="checked" ';
1999: }
1.78 raeburn 2000: }
1.72 raeburn 2001: }
1.101 raeburn 2002: $datatable .= '<span class="LC_nobreak"><label>'.
2003: '<input type="checkbox" name="'.$context.'_'.$item.
2004: '" value="default" '.$checked.'/>'.$titles{$item}.
2005: '</label></span> ';
2006: }
2007: }
2008: if ($context eq 'requestcourses') {
2009: $datatable .= '</tr><tr>';
2010: foreach my $item (@usertools) {
1.106 raeburn 2011: $datatable .= '<td style="vertical-align: top">'.$defcell{$item}.'</td>';
1.72 raeburn 2012: }
1.101 raeburn 2013: $datatable .= '</tr></table>';
1.72 raeburn 2014: }
1.86 raeburn 2015: $datatable .= '</td>';
1.163 raeburn 2016: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.197 raeburn 2017: $datatable .= '<td class="LC_right_item">'.
2018: '<span class="LC_nobreak">'.&mt('Portfolio').': '.
1.86 raeburn 2019: '<input type="text" name="defaultquota" value="'.
1.197 raeburn 2020: $defaultquota.'" size="5" /></span>'.(' ' x2).
2021: '<span class="LC_nobreak">'.&mt('Authoring').': '.
2022: '<input type="text" name="authorquota" value="'.
2023: $authorquota.'" size="5" /></span></td>';
1.86 raeburn 2024: }
2025: $datatable .= '</tr>';
1.72 raeburn 2026: $typecount ++;
2027: $css_class = $typecount%2?' class="LC_odd_row"':'';
2028: $datatable .= '<tr'.$css_class.'>'.
1.197 raeburn 2029: '<td>'.&mt('LON-CAPA Advanced Users').'<br />';
1.104 raeburn 2030: if ($context eq 'requestcourses') {
1.109 raeburn 2031: $datatable .= &mt('(overrides affiliation, if set)').
2032: '</td>'.
2033: '<td class="LC_left_item">'.
2034: '<table><tr>';
1.101 raeburn 2035: } else {
1.109 raeburn 2036: $datatable .= &mt('(overrides affiliation, if checked)').
2037: '</td>'.
2038: '<td class="LC_left_item" colspan="2">'.
2039: '<br />';
1.101 raeburn 2040: }
2041: my %advcell;
1.72 raeburn 2042: foreach my $item (@usertools) {
1.101 raeburn 2043: if ($context eq 'requestcourses') {
2044: my ($curroption,$currlimit);
2045: if (ref($settings) eq 'HASH') {
2046: if (ref($settings->{$item}) eq 'HASH') {
2047: $curroption = $settings->{$item}->{'_LC_adv'};
2048: if ($curroption =~ /^autolimit=(\d*)$/) {
2049: $currlimit = $1;
2050: }
2051: }
2052: }
2053: $datatable .= '<th>'.$titles{$item}.'</th>';
1.104 raeburn 2054: my $checked = '';
2055: if ($curroption eq '') {
2056: $checked = ' checked="checked"';
2057: }
2058: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
2059: '<input type="radio" name="crsreq_'.$item.
2060: '__LC_adv" value=""'.$checked.' />'.
2061: &mt('No override set').'</label></span> ';
1.101 raeburn 2062: foreach my $option (@options) {
2063: my $val = $option;
2064: if ($option eq 'norequest') {
2065: $val = 0;
2066: }
2067: if ($option eq 'validate') {
2068: my $canvalidate = 0;
2069: if (ref($validations{$item}) eq 'HASH') {
2070: if ($validations{$item}{'_LC_adv'}) {
2071: $canvalidate = 1;
2072: }
2073: }
2074: next if (!$canvalidate);
2075: }
2076: my $checked = '';
1.104 raeburn 2077: if ($val eq $curroption) {
1.101 raeburn 2078: $checked = ' checked="checked"';
2079: } elsif ($option eq 'autolimit') {
2080: if ($curroption =~ /^autolimit/) {
2081: $checked = ' checked="checked"';
2082: }
2083: }
2084: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
2085: '<input type="radio" name="crsreq_'.$item.
2086: '__LC_adv" value="'.$val.'"'.$checked.' />'.
2087: $titles{$option}.'</label>';
2088: if ($option eq 'autolimit') {
1.127 raeburn 2089: $advcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 2090: $item.'_limit__LC_adv" size="1" '.
2091: 'value="'.$currlimit.'" />';
2092: }
1.127 raeburn 2093: $advcell{$item} .= '</span> ';
1.104 raeburn 2094: if ($option eq 'autolimit') {
1.127 raeburn 2095: $advcell{$item} .= $titles{'unlimited'};
1.104 raeburn 2096: }
1.101 raeburn 2097: }
1.163 raeburn 2098: } elsif ($context eq 'requestauthor') {
2099: my $curroption;
2100: if (ref($settings) eq 'HASH') {
2101: $curroption = $settings->{'_LC_adv'};
2102: }
2103: my $checked = '';
2104: if ($curroption eq '') {
2105: $checked = ' checked="checked"';
2106: }
2107: $datatable .= '<span class="LC_nobreak"><label>'.
2108: '<input type="radio" name="authorreq__LC_adv"'.
2109: ' value=""'.$checked.' />'.
2110: &mt('No override set').'</label></span> ';
2111: foreach my $option (@options) {
2112: my $val = $option;
2113: if ($option eq 'norequest') {
2114: $val = 0;
2115: }
2116: my $checked = '';
2117: if ($val eq $curroption) {
2118: $checked = ' checked="checked"';
2119: }
2120: $datatable .= '<span class="LC_nobreak"><label>'.
1.173 raeburn 2121: '<input type="radio" name="authorreq__LC_adv"'.
2122: ' value="'.$val.'"'.$checked.' />'.
1.163 raeburn 2123: $titles{$option}.'</label></span> ';
2124: }
1.101 raeburn 2125: } else {
2126: my $checked = 'checked="checked" ';
2127: if (ref($settings) eq 'HASH') {
2128: if (ref($settings->{$item}) eq 'HASH') {
2129: if ($settings->{$item}->{'_LC_adv'} == 0) {
2130: $checked = '';
2131: } elsif ($settings->{$item}->{'_LC_adv'} == 1) {
2132: $checked = 'checked="checked" ';
2133: }
1.79 raeburn 2134: }
1.72 raeburn 2135: }
1.101 raeburn 2136: $datatable .= '<span class="LC_nobreak"><label>'.
2137: '<input type="checkbox" name="'.$context.'_'.$item.
2138: '" value="_LC_adv" '.$checked.'/>'.$titles{$item}.
2139: '</label></span> ';
2140: }
2141: }
2142: if ($context eq 'requestcourses') {
2143: $datatable .= '</tr><tr>';
2144: foreach my $item (@usertools) {
1.106 raeburn 2145: $datatable .= '<td style="vertical-align: top">'.$advcell{$item}.'</td>';
1.72 raeburn 2146: }
1.101 raeburn 2147: $datatable .= '</tr></table>';
1.72 raeburn 2148: }
1.98 raeburn 2149: $datatable .= '</td></tr>';
1.30 raeburn 2150: $$rowtotal += $typecount;
1.3 raeburn 2151: return $datatable;
2152: }
2153:
1.163 raeburn 2154: sub print_requestmail {
2155: my ($dom,$action,$settings,$rowtotal) = @_;
1.208 raeburn 2156: my ($now,$datatable,%currapp);
1.102 raeburn 2157: $now = time;
2158: if (ref($settings) eq 'HASH') {
2159: if (ref($settings->{'notify'}) eq 'HASH') {
2160: if ($settings->{'notify'}{'approval'} ne '') {
1.224 raeburn 2161: map {$currapp{$_}=1;} split(/,/,$settings->{'notify'}{'approval'});
1.102 raeburn 2162: }
2163: }
2164: }
1.191 raeburn 2165: my $numinrow = 2;
1.224 raeburn 2166: my $css_class;
2167: $css_class = ($$rowtotal%2? ' class="LC_odd_row"':'');
1.163 raeburn 2168: my $text;
2169: if ($action eq 'requestcourses') {
2170: $text = &mt('Receive notification of course requests requiring approval');
1.224 raeburn 2171: } elsif ($action eq 'requestauthor') {
2172: $text = &mt('Receive notification of Authoring Space requests requiring approval');
1.163 raeburn 2173: } else {
1.224 raeburn 2174: $text = &mt('Receive notification of queued requests for self-created user accounts requiring approval');
1.163 raeburn 2175: }
1.224 raeburn 2176: $datatable = '<tr'.$css_class.'>'.
1.163 raeburn 2177: ' <td>'.$text.'</td>'.
1.102 raeburn 2178: ' <td class="LC_left_item">';
1.191 raeburn 2179: my ($numdc,$table,$rows) = &active_dc_picker($dom,$numinrow,'checkbox',
1.224 raeburn 2180: $action.'notifyapproval',%currapp);
1.191 raeburn 2181: if ($numdc > 0) {
2182: $datatable .= $table;
1.102 raeburn 2183: } else {
2184: $datatable .= &mt('There are no active Domain Coordinators');
2185: }
2186: $datatable .='</td></tr>';
2187: return $datatable;
2188: }
2189:
1.216 raeburn 2190: sub print_studentcode {
2191: my ($settings,$rowtotal) = @_;
2192: my $rownum = 0;
1.218 raeburn 2193: my ($output,%current);
1.271 raeburn 2194: my @crstypes = ('official','unofficial','community','textbook','placement');
1.248 raeburn 2195: if (ref($settings) eq 'HASH') {
2196: if (ref($settings->{'uniquecode'}) eq 'HASH') {
2197: foreach my $type (@crstypes) {
2198: $current{$type} = $settings->{'uniquecode'}{$type};
2199: }
1.218 raeburn 2200: }
2201: }
2202: $output .= '<tr>'.
2203: '<td class="LC_left_item">'.&mt('Generate unique six character code as course identifier?').'</td>'.
2204: '<td class="LC_left_item">';
2205: foreach my $type (@crstypes) {
2206: my $check = ' ';
2207: if ($current{$type}) {
2208: $check = ' checked="checked" ';
2209: }
2210: $output .= '<span class="LC_nobreak"><label>'.
2211: '<input type="checkbox" name="uniquecode" value="'.$type.'"'.$check.'/>'.
2212: &mt($type).'</label></span>'.(' 'x2).' ';
2213: }
2214: $output .= '</td></tr>';
2215: $$rowtotal ++;
2216: return $output;
1.216 raeburn 2217: }
2218:
2219: sub print_textbookcourses {
1.242 raeburn 2220: my ($dom,$type,$settings,$rowtotal) = @_;
1.216 raeburn 2221: my $rownum = 0;
2222: my $css_class;
2223: my $itemcount = 1;
2224: my $maxnum = 0;
2225: my $bookshash;
2226: if (ref($settings) eq 'HASH') {
1.242 raeburn 2227: $bookshash = $settings->{$type};
1.216 raeburn 2228: }
2229: my %ordered;
2230: if (ref($bookshash) eq 'HASH') {
2231: foreach my $item (keys(%{$bookshash})) {
2232: if (ref($bookshash->{$item}) eq 'HASH') {
2233: my $num = $bookshash->{$item}{'order'};
2234: $ordered{$num} = $item;
2235: }
2236: }
2237: }
2238: my $confname = $dom.'-domainconfig';
2239: my $switchserver = &check_switchserver($dom,$confname);
1.242 raeburn 2240: my $maxnum = scalar(keys(%ordered));
2241: my $datatable;
1.216 raeburn 2242: if (keys(%ordered)) {
2243: my @items = sort { $a <=> $b } keys(%ordered);
2244: for (my $i=0; $i<@items; $i++) {
2245: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2246: my $key = $ordered{$items[$i]};
2247: my %coursehash=&Apache::lonnet::coursedescription($key);
2248: my $coursetitle = $coursehash{'description'};
1.243 raeburn 2249: my ($subject,$title,$author,$publisher,$image,$imgsrc,$cdom,$cnum);
1.216 raeburn 2250: if (ref($bookshash->{$key}) eq 'HASH') {
2251: $subject = $bookshash->{$key}->{'subject'};
2252: $title = $bookshash->{$key}->{'title'};
1.242 raeburn 2253: if ($type eq 'textbooks') {
1.243 raeburn 2254: $publisher = $bookshash->{$key}->{'publisher'};
1.242 raeburn 2255: $author = $bookshash->{$key}->{'author'};
2256: $image = $bookshash->{$key}->{'image'};
2257: if ($image ne '') {
2258: my ($path,$imagefile) = ($image =~ m{^(.+)/([^/]+)$});
2259: my $imagethumb = "$path/tn-".$imagefile;
2260: $imgsrc = '<img src="'.$imagethumb.'" alt="'.&mt('Textbook image').'" />';
2261: }
1.216 raeburn 2262: }
2263: }
1.242 raeburn 2264: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type".'_'."$key','$type'".');"';
1.216 raeburn 2265: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.242 raeburn 2266: .'<select name="'.$type.'_'.$key.'"'.$chgstr.'>';
1.216 raeburn 2267: for (my $k=0; $k<=$maxnum; $k++) {
2268: my $vpos = $k+1;
2269: my $selstr;
2270: if ($k == $i) {
2271: $selstr = ' selected="selected" ';
2272: }
2273: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2274: }
2275: $datatable .= '</select>'.(' 'x2).
1.242 raeburn 2276: '<label><input type="checkbox" name="'.$type.'_del" value="'.$key.'" />'.
1.216 raeburn 2277: &mt('Delete?').'</label></span></td>'.
2278: '<td colspan="2">'.
1.242 raeburn 2279: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_subject_'.$i.'" value="'.$subject.'" /></span> '.
1.216 raeburn 2280: (' 'x2).
1.242 raeburn 2281: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_title_'.$i.'" value="'.$title.'" /></span> ';
2282: if ($type eq 'textbooks') {
2283: $datatable .= (' 'x2).
1.243 raeburn 2284: '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_publisher_'.$i.'" value="'.$publisher.'" /></span> '.
2285: (' 'x2).
1.242 raeburn 2286: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_author_'.$i.'" value="'.$author.'" /></span> '.
2287: (' 'x2).
2288: '<span class="LC_nobreak">'.&mt('Thumbnail:');
2289: if ($image) {
1.267 raeburn 2290: $datatable .= $imgsrc.
1.242 raeburn 2291: '<label><input type="checkbox" name="'.$type.'_image_del"'.
2292: ' value="'.$key.'" />'.&mt('Delete?').'</label></span> '.
2293: '<span class="LC_nobreak"> '.&mt('Replace:').' ';
2294: }
2295: if ($switchserver) {
2296: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2297: } else {
2298: $datatable .= '<input type="file" name="'.$type.'_image_'.$i.'" value="" />';
2299: }
1.216 raeburn 2300: }
1.242 raeburn 2301: $datatable .= '<input type="hidden" name="'.$type.'_id_'.$i.'" value="'.$type.'_'.$key.'" /></span> '.
1.216 raeburn 2302: '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
2303: $coursetitle.'</span></td></tr>'."\n";
2304: $itemcount ++;
2305: }
2306: }
2307: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.242 raeburn 2308: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type"."_addbook_pos','$type'".');"';
1.216 raeburn 2309: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
1.242 raeburn 2310: '<input type="hidden" name="'.$type.'_maxnum" value="'.$maxnum.'" />'."\n".
2311: '<select name="'.$type.'_addbook_pos"'.$chgstr.'>';
1.216 raeburn 2312: for (my $k=0; $k<$maxnum+1; $k++) {
2313: my $vpos = $k+1;
2314: my $selstr;
2315: if ($k == $maxnum) {
2316: $selstr = ' selected="selected" ';
2317: }
2318: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2319: }
2320: $datatable .= '</select> '."\n".
1.242 raeburn 2321: '<input type="checkbox" name="'.$type.'_addbook" value="1" />'.&mt('Add').'</td>'."\n".
1.216 raeburn 2322: '<td colspan="2">'.
1.242 raeburn 2323: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_addbook_subject" value="" /></span> '."\n".
1.216 raeburn 2324: (' 'x2).
1.242 raeburn 2325: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_addbook_title" value="" /></span> '."\n".
2326: (' 'x2);
2327: if ($type eq 'textbooks') {
1.243 raeburn 2328: $datatable .= '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_addbook_publisher" value="" /></span> '."\n".
2329: (' 'x2).
2330: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_addbook_author" value="" /></span> '."\n".
1.242 raeburn 2331: (' 'x2).
2332: '<span class="LC_nobreak">'.&mt('Image:').' ';
2333: if ($switchserver) {
2334: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2335: } else {
2336: $datatable .= '<input type="file" name="'.$type.'_addbook_image" value="" />';
2337: }
1.216 raeburn 2338: }
2339: $datatable .= '</span>'."\n".
2340: '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
1.242 raeburn 2341: &Apache::loncommon::select_dom_form($env{'request.role.domain'},$type.'_addbook_cdom').
2342: '<input type="text" size="25" name="'.$type.'_addbook_cnum" value="" />'.
1.216 raeburn 2343: &Apache::loncommon::selectcourse_link
1.242 raeburn 2344: ('display',$type.'_addbook_cnum',$type.'_addbook_cdom',undef,undef,undef,'Course');
1.216 raeburn 2345: '</span></td>'."\n".
2346: '</tr>'."\n";
2347: $itemcount ++;
2348: return $datatable;
2349: }
2350:
1.217 raeburn 2351: sub textbookcourses_javascript {
1.242 raeburn 2352: my ($settings) = @_;
2353: return unless(ref($settings) eq 'HASH');
2354: my (%ordered,%total,%jstext);
2355: foreach my $type ('textbooks','templates') {
2356: $total{$type} = 0;
2357: if (ref($settings->{$type}) eq 'HASH') {
2358: foreach my $item (keys(%{$settings->{$type}})) {
2359: if (ref($settings->{$type}->{$item}) eq 'HASH') {
2360: my $num = $settings->{$type}->{$item}{'order'};
2361: $ordered{$type}{$num} = $item;
2362: }
2363: }
2364: $total{$type} = scalar(keys(%{$settings->{$type}}));
2365: }
2366: my @jsarray = ();
2367: foreach my $item (sort {$a <=> $b } (keys(%{$ordered{$type}}))) {
2368: push(@jsarray,$ordered{$type}{$item});
2369: }
2370: $jstext{$type} = ' var '.$type.' = Array('."'".join("','",@jsarray)."'".');'."\n";
1.217 raeburn 2371: }
2372: return <<"ENDSCRIPT";
2373: <script type="text/javascript">
2374: // <![CDATA[
1.242 raeburn 2375: function reorderBooks(form,item,caller) {
1.217 raeburn 2376: var changedVal;
1.242 raeburn 2377: $jstext{'textbooks'};
2378: $jstext{'templates'};
2379: var newpos;
2380: var maxh;
2381: if (caller == 'textbooks') {
2382: newpos = 'textbooks_addbook_pos';
2383: maxh = 1 + $total{'textbooks'};
2384: } else {
2385: newpos = 'templates_addbook_pos';
2386: maxh = 1 + $total{'templates'};
2387: }
1.217 raeburn 2388: var current = new Array;
2389: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
2390: if (item == newpos) {
2391: changedVal = newitemVal;
2392: } else {
2393: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
2394: current[newitemVal] = newpos;
2395: }
1.242 raeburn 2396: if (caller == 'textbooks') {
2397: for (var i=0; i<textbooks.length; i++) {
2398: var elementName = 'textbooks_'+textbooks[i];
2399: if (elementName != item) {
2400: if (form.elements[elementName]) {
2401: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2402: current[currVal] = elementName;
2403: }
2404: }
2405: }
2406: }
2407: if (caller == 'templates') {
2408: for (var i=0; i<templates.length; i++) {
2409: var elementName = 'templates_'+templates[i];
2410: if (elementName != item) {
2411: if (form.elements[elementName]) {
2412: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2413: current[currVal] = elementName;
2414: }
1.217 raeburn 2415: }
2416: }
2417: }
2418: var oldVal;
2419: for (var j=0; j<maxh; j++) {
2420: if (current[j] == undefined) {
2421: oldVal = j;
2422: }
2423: }
2424: if (oldVal < changedVal) {
2425: for (var k=oldVal+1; k<=changedVal ; k++) {
2426: var elementName = current[k];
2427: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
2428: }
2429: } else {
2430: for (var k=changedVal; k<oldVal; k++) {
2431: var elementName = current[k];
2432: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
2433: }
2434: }
2435: return;
2436: }
2437:
2438: // ]]>
2439: </script>
2440:
2441: ENDSCRIPT
2442: }
2443:
1.267 raeburn 2444: sub ltitools_javascript {
2445: my ($settings) = @_;
2446: return unless(ref($settings) eq 'HASH');
2447: my (%ordered,$total,%jstext);
2448: $total = 0;
2449: foreach my $item (keys(%{$settings})) {
2450: if (ref($settings->{$item}) eq 'HASH') {
2451: my $num = $settings->{$item}{'order'};
2452: $ordered{$num} = $item;
2453: }
2454: }
2455: $total = scalar(keys(%{$settings}));
2456: my @jsarray = ();
2457: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
2458: push(@jsarray,$ordered{$item});
2459: }
2460: my $jstext = ' var ltitools = Array('."'".join("','",@jsarray)."'".');'."\n";
2461: return <<"ENDSCRIPT";
2462: <script type="text/javascript">
2463: // <![CDATA[
2464: function reorderLTI(form,item) {
2465: var changedVal;
2466: $jstext
2467: var newpos = 'ltitools_add_pos';
2468: var maxh = 1 + $total;
2469: var current = new Array;
2470: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
2471: if (item == newpos) {
2472: changedVal = newitemVal;
2473: } else {
2474: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
2475: current[newitemVal] = newpos;
2476: }
2477: for (var i=0; i<ltitools.length; i++) {
2478: var elementName = 'ltitools_'+ltitools[i];
2479: if (elementName != item) {
2480: if (form.elements[elementName]) {
2481: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2482: current[currVal] = elementName;
2483: }
2484: }
2485: }
2486: var oldVal;
2487: for (var j=0; j<maxh; j++) {
2488: if (current[j] == undefined) {
2489: oldVal = j;
2490: }
2491: }
2492: if (oldVal < changedVal) {
2493: for (var k=oldVal+1; k<=changedVal ; k++) {
2494: var elementName = current[k];
2495: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
2496: }
2497: } else {
2498: for (var k=changedVal; k<oldVal; k++) {
2499: var elementName = current[k];
2500: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
2501: }
2502: }
2503: return;
2504: }
2505:
2506: // ]]>
2507: </script>
2508:
2509: ENDSCRIPT
2510: }
2511:
1.3 raeburn 2512: sub print_autoenroll {
1.30 raeburn 2513: my ($dom,$settings,$rowtotal) = @_;
1.3 raeburn 2514: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
1.274 raeburn 2515: my ($defdom,$runon,$runoff,$coownerson,$coownersoff,$failsafe);
1.3 raeburn 2516: if (ref($settings) eq 'HASH') {
2517: if (exists($settings->{'run'})) {
2518: if ($settings->{'run'} eq '0') {
2519: $runoff = ' checked="checked" ';
2520: $runon = ' ';
2521: } else {
2522: $runon = ' checked="checked" ';
2523: $runoff = ' ';
2524: }
2525: } else {
2526: if ($autorun) {
2527: $runon = ' checked="checked" ';
2528: $runoff = ' ';
2529: } else {
2530: $runoff = ' checked="checked" ';
2531: $runon = ' ';
2532: }
2533: }
1.129 raeburn 2534: if (exists($settings->{'co-owners'})) {
2535: if ($settings->{'co-owners'} eq '0') {
2536: $coownersoff = ' checked="checked" ';
2537: $coownerson = ' ';
2538: } else {
2539: $coownerson = ' checked="checked" ';
2540: $coownersoff = ' ';
2541: }
2542: } else {
2543: $coownersoff = ' checked="checked" ';
2544: $coownerson = ' ';
2545: }
1.3 raeburn 2546: if (exists($settings->{'sender_domain'})) {
2547: $defdom = $settings->{'sender_domain'};
2548: }
1.274 raeburn 2549: if (exists($settings->{'autofailsafe'})) {
2550: $failsafe = $settings->{'autofailsafe'};
2551: }
1.14 raeburn 2552: } else {
2553: if ($autorun) {
2554: $runon = ' checked="checked" ';
2555: $runoff = ' ';
2556: } else {
2557: $runoff = ' checked="checked" ';
2558: $runon = ' ';
2559: }
1.3 raeburn 2560: }
2561: my $domform = &Apache::loncommon::select_dom_form($defdom,'sender_domain',1);
1.39 raeburn 2562: my $notif_sender;
2563: if (ref($settings) eq 'HASH') {
2564: $notif_sender = $settings->{'sender_uname'};
2565: }
1.3 raeburn 2566: my $datatable='<tr class="LC_odd_row">'.
2567: '<td>'.&mt('Auto-enrollment active?').'</td>'.
1.8 raeburn 2568: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 2569: '<input type="radio" name="autoenroll_run"'.
1.8 raeburn 2570: $runon.' value="1" />'.&mt('Yes').'</label> '.
2571: '<label><input type="radio" name="autoenroll_run"'.
1.14 raeburn 2572: $runoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 2573: '</tr><tr>'.
2574: '<td>'.&mt('Notification messages - sender').
1.8 raeburn 2575: '</td><td class="LC_right_item"><span class="LC_nobreak">'.
1.3 raeburn 2576: &mt('username').': '.
2577: '<input type="text" name="sender_uname" value="'.
1.39 raeburn 2578: $notif_sender.'" size="10" /> '.&mt('domain').
1.129 raeburn 2579: ': '.$domform.'</span></td></tr>'.
2580: '<tr class="LC_odd_row">'.
2581: '<td>'.&mt('Automatically assign co-ownership').'</td>'.
2582: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2583: '<input type="radio" name="autoassign_coowners"'.
2584: $coownerson.' value="1" />'.&mt('Yes').'</label> '.
2585: '<label><input type="radio" name="autoassign_coowners"'.
2586: $coownersoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.274 raeburn 2587: '</tr><tr>'.
2588: '<td>'.&mt('Failsafe for no drops when institutional data missing').'</td>'.
2589: '<td class="LC_right_item"><span class="LC_nobreak">'.
2590: '<input type="text" name="autoenroll_failsafe"'.
2591: ' value="'.$failsafe.'" size="4" /></td></tr>';
2592: $$rowtotal += 4;
1.3 raeburn 2593: return $datatable;
2594: }
2595:
2596: sub print_autoupdate {
1.30 raeburn 2597: my ($position,$dom,$settings,$rowtotal) = @_;
1.3 raeburn 2598: my $datatable;
2599: if ($position eq 'top') {
2600: my $updateon = ' ';
2601: my $updateoff = ' checked="checked" ';
2602: my $classlistson = ' ';
2603: my $classlistsoff = ' checked="checked" ';
2604: if (ref($settings) eq 'HASH') {
2605: if ($settings->{'run'} eq '1') {
2606: $updateon = $updateoff;
2607: $updateoff = ' ';
2608: }
2609: if ($settings->{'classlists'} eq '1') {
2610: $classlistson = $classlistsoff;
2611: $classlistsoff = ' ';
2612: }
2613: }
2614: my %title = (
2615: run => 'Auto-update active?',
2616: classlists => 'Update information in classlists?',
2617: );
2618: $datatable = '<tr class="LC_odd_row">'.
2619: '<td>'.&mt($title{'run'}).'</td>'.
1.8 raeburn 2620: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 2621: '<input type="radio" name="autoupdate_run"'.
1.8 raeburn 2622: $updateon.' value="1" />'.&mt('Yes').'</label> '.
2623: '<label><input type="radio" name="autoupdate_run"'.
2624: $updateoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 2625: '</tr><tr>'.
2626: '<td>'.&mt($title{'classlists'}).'</td>'.
1.8 raeburn 2627: '<td class="LC_right_item"><span class="LC_nobreak">'.
2628: '<label><input type="radio" name="classlists"'.
2629: $classlistson.' value="1" />'.&mt('Yes').'</label> '.
2630: '<label><input type="radio" name="classlists"'.
2631: $classlistsoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 2632: '</tr>';
1.30 raeburn 2633: $$rowtotal += 2;
1.131 raeburn 2634: } elsif ($position eq 'middle') {
2635: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
2636: my $numinrow = 3;
2637: my $locknamesettings;
2638: $datatable .= &insttypes_row($settings,$types,$usertypes,
2639: $dom,$numinrow,$othertitle,
2640: 'lockablenames');
2641: $$rowtotal ++;
1.3 raeburn 2642: } else {
1.44 raeburn 2643: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.132 raeburn 2644: my @fields = ('lastname','firstname','middlename','generation',
1.20 raeburn 2645: 'permanentemail','id');
1.33 raeburn 2646: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1.3 raeburn 2647: my $numrows = 0;
1.26 raeburn 2648: if (ref($types) eq 'ARRAY') {
2649: if (@{$types} > 0) {
2650: $datatable =
2651: &usertype_update_row($settings,$usertypes,\%fieldtitles,
2652: \@fields,$types,\$numrows);
1.30 raeburn 2653: $$rowtotal += @{$types};
1.26 raeburn 2654: }
1.3 raeburn 2655: }
2656: $datatable .=
2657: &usertype_update_row($settings,{'default' => $othertitle},
2658: \%fieldtitles,\@fields,['default'],
2659: \$numrows);
1.30 raeburn 2660: $$rowtotal ++;
1.3 raeburn 2661: }
2662: return $datatable;
2663: }
2664:
1.125 raeburn 2665: sub print_autocreate {
2666: my ($dom,$settings,$rowtotal) = @_;
1.191 raeburn 2667: my (%createon,%createoff,%currhash);
1.125 raeburn 2668: my @types = ('xml','req');
2669: if (ref($settings) eq 'HASH') {
2670: foreach my $item (@types) {
2671: $createoff{$item} = ' checked="checked" ';
2672: $createon{$item} = ' ';
2673: if (exists($settings->{$item})) {
2674: if ($settings->{$item}) {
2675: $createon{$item} = ' checked="checked" ';
2676: $createoff{$item} = ' ';
2677: }
2678: }
2679: }
1.210 raeburn 2680: if ($settings->{'xmldc'} ne '') {
1.191 raeburn 2681: $currhash{$settings->{'xmldc'}} = 1;
2682: }
1.125 raeburn 2683: } else {
2684: foreach my $item (@types) {
2685: $createoff{$item} = ' checked="checked" ';
2686: $createon{$item} = ' ';
2687: }
2688: }
2689: $$rowtotal += 2;
1.191 raeburn 2690: my $numinrow = 2;
1.125 raeburn 2691: my $datatable='<tr class="LC_odd_row">'.
2692: '<td>'.&mt('Create pending official courses from XML files').'</td>'.
2693: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2694: '<input type="radio" name="autocreate_xml"'.
2695: $createon{'xml'}.' value="1" />'.&mt('Yes').'</label> '.
2696: '<label><input type="radio" name="autocreate_xml"'.
1.143 raeburn 2697: $createoff{'xml'}.' value="0" />'.&mt('No').'</label></span>'.
2698: '</td></tr><tr>'.
2699: '<td>'.&mt('Create pending requests for official courses (if validated)').'</td>'.
2700: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2701: '<input type="radio" name="autocreate_req"'.
2702: $createon{'req'}.' value="1" />'.&mt('Yes').'</label> '.
2703: '<label><input type="radio" name="autocreate_req"'.
2704: $createoff{'req'}.' value="0" />'.&mt('No').'</label></span>';
1.191 raeburn 2705: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
2706: 'autocreate_xmldc',%currhash);
1.247 raeburn 2707: $datatable .= '</td></tr><tr class="LC_odd_row"><td>';
1.125 raeburn 2708: if ($numdc > 1) {
1.247 raeburn 2709: $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)').
2710: '</td><td class="LC_left_item">';
1.125 raeburn 2711: } else {
1.247 raeburn 2712: $datatable .= &mt('Course creation processed as:').
2713: '</td><td class="LC_right_item">';
1.125 raeburn 2714: }
1.247 raeburn 2715: $datatable .= $dctable.'</td></tr>';
1.191 raeburn 2716: $$rowtotal += $rows;
1.125 raeburn 2717: return $datatable;
2718: }
2719:
1.23 raeburn 2720: sub print_directorysrch {
1.30 raeburn 2721: my ($dom,$settings,$rowtotal) = @_;
1.23 raeburn 2722: my $srchon = ' ';
2723: my $srchoff = ' checked="checked" ';
1.25 raeburn 2724: my ($exacton,$containson,$beginson);
1.24 raeburn 2725: my $localon = ' ';
2726: my $localoff = ' checked="checked" ';
1.23 raeburn 2727: if (ref($settings) eq 'HASH') {
2728: if ($settings->{'available'} eq '1') {
2729: $srchon = $srchoff;
2730: $srchoff = ' ';
2731: }
1.24 raeburn 2732: if ($settings->{'localonly'} eq '1') {
2733: $localon = $localoff;
2734: $localoff = ' ';
2735: }
1.25 raeburn 2736: if (ref($settings->{'searchtypes'}) eq 'ARRAY') {
2737: foreach my $type (@{$settings->{'searchtypes'}}) {
2738: if ($type eq 'exact') {
2739: $exacton = ' checked="checked" ';
2740: } elsif ($type eq 'contains') {
2741: $containson = ' checked="checked" ';
2742: } elsif ($type eq 'begins') {
2743: $beginson = ' checked="checked" ';
2744: }
2745: }
2746: } else {
2747: if ($settings->{'searchtypes'} eq 'exact') {
2748: $exacton = ' checked="checked" ';
2749: } elsif ($settings->{'searchtypes'} eq 'contains') {
2750: $containson = ' checked="checked" ';
2751: } elsif ($settings->{'searchtypes'} eq 'specify') {
2752: $exacton = ' checked="checked" ';
2753: $containson = ' checked="checked" ';
2754: }
1.23 raeburn 2755: }
2756: }
2757: my ($searchtitles,$titleorder) = &sorted_searchtitles();
1.45 raeburn 2758: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.23 raeburn 2759:
2760: my $numinrow = 4;
1.26 raeburn 2761: my $cansrchrow = 0;
1.23 raeburn 2762: my $datatable='<tr class="LC_odd_row">'.
1.30 raeburn 2763: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Directory search available?').'</span></td>'.
1.23 raeburn 2764: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2765: '<input type="radio" name="dirsrch_available"'.
2766: $srchon.' value="1" />'.&mt('Yes').'</label> '.
2767: '<label><input type="radio" name="dirsrch_available"'.
2768: $srchoff.' value="0" />'.&mt('No').'</label></span></td>'.
2769: '</tr><tr>'.
1.30 raeburn 2770: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search?').'</span></td>'.
1.24 raeburn 2771: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2772: '<input type="radio" name="dirsrch_localonly"'.
2773: $localoff.' value="0" />'.&mt('Yes').'</label> '.
2774: '<label><input type="radio" name="dirsrch_localonly"'.
2775: $localon.' value="1" />'.&mt('No').'</label></span></td>'.
1.25 raeburn 2776: '</tr>';
1.30 raeburn 2777: $$rowtotal += 2;
1.26 raeburn 2778: if (ref($usertypes) eq 'HASH') {
2779: if (keys(%{$usertypes}) > 0) {
1.93 raeburn 2780: $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
2781: $numinrow,$othertitle,'cansearch');
1.26 raeburn 2782: $cansrchrow = 1;
2783: }
2784: }
2785: if ($cansrchrow) {
1.30 raeburn 2786: $$rowtotal ++;
1.26 raeburn 2787: $datatable .= '<tr>';
2788: } else {
2789: $datatable .= '<tr class="LC_odd_row">';
2790: }
1.30 raeburn 2791: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Supported search methods').
2792: '</span></td><td class="LC_left_item" colspan="2"><table><tr>';
1.25 raeburn 2793: foreach my $title (@{$titleorder}) {
2794: if (defined($searchtitles->{$title})) {
2795: my $check = ' ';
1.93 raeburn 2796: if (ref($settings) eq 'HASH') {
1.39 raeburn 2797: if (ref($settings->{'searchby'}) eq 'ARRAY') {
2798: if (grep(/^\Q$title\E$/,@{$settings->{'searchby'}})) {
2799: $check = ' checked="checked" ';
2800: }
1.25 raeburn 2801: }
2802: }
2803: $datatable .= '<td class="LC_left_item">'.
2804: '<span class="LC_nobreak"><label>'.
2805: '<input type="checkbox" name="searchby" '.
2806: 'value="'.$title.'"'.$check.'/>'.
2807: $searchtitles->{$title}.'</label></span></td>';
2808: }
2809: }
1.26 raeburn 2810: $datatable .= '</tr></table></td></tr>';
1.30 raeburn 2811: $$rowtotal ++;
1.26 raeburn 2812: if ($cansrchrow) {
2813: $datatable .= '<tr class="LC_odd_row">';
2814: } else {
2815: $datatable .= '<tr>';
2816: }
1.30 raeburn 2817: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Search latitude').'</span></td>'.
1.26 raeburn 2818: '<td class="LC_left_item" colspan="2">'.
1.25 raeburn 2819: '<span class="LC_nobreak"><label>'.
2820: '<input type="checkbox" name="searchtypes" '.
2821: $exacton.' value="exact" />'.&mt('Exact match').
2822: '</label> '.
2823: '<label><input type="checkbox" name="searchtypes" '.
2824: $beginson.' value="begins" />'.&mt('Begins with').
2825: '</label> '.
2826: '<label><input type="checkbox" name="searchtypes" '.
2827: $containson.' value="contains" />'.&mt('Contains').
2828: '</label></span></td></tr>';
1.30 raeburn 2829: $$rowtotal ++;
1.25 raeburn 2830: return $datatable;
2831: }
2832:
1.28 raeburn 2833: sub print_contacts {
1.30 raeburn 2834: my ($dom,$settings,$rowtotal) = @_;
1.28 raeburn 2835: my $datatable;
2836: my @contacts = ('adminemail','supportemail');
1.134 raeburn 2837: my (%checked,%to,%otheremails,%bccemails);
1.102 raeburn 2838: my @mailings = ('errormail','packagesmail','lonstatusmail','helpdeskmail',
1.203 raeburn 2839: 'requestsmail','updatesmail','idconflictsmail');
1.28 raeburn 2840: foreach my $type (@mailings) {
2841: $otheremails{$type} = '';
2842: }
1.134 raeburn 2843: $bccemails{'helpdeskmail'} = '';
1.28 raeburn 2844: if (ref($settings) eq 'HASH') {
2845: foreach my $item (@contacts) {
2846: if (exists($settings->{$item})) {
2847: $to{$item} = $settings->{$item};
2848: }
2849: }
2850: foreach my $type (@mailings) {
2851: if (exists($settings->{$type})) {
2852: if (ref($settings->{$type}) eq 'HASH') {
2853: foreach my $item (@contacts) {
2854: if ($settings->{$type}{$item}) {
2855: $checked{$type}{$item} = ' checked="checked" ';
2856: }
2857: }
2858: $otheremails{$type} = $settings->{$type}{'others'};
1.134 raeburn 2859: if ($type eq 'helpdeskmail') {
2860: $bccemails{$type} = $settings->{$type}{'bcc'};
2861: }
1.28 raeburn 2862: }
1.89 raeburn 2863: } elsif ($type eq 'lonstatusmail') {
2864: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
1.28 raeburn 2865: }
2866: }
2867: } else {
2868: $to{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
2869: $to{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
2870: $checked{'errormail'}{'adminemail'} = ' checked="checked" ';
2871: $checked{'packagesmail'}{'adminemail'} = ' checked="checked" ';
1.89 raeburn 2872: $checked{'helpdeskmail'}{'supportemail'} = ' checked="checked" ';
2873: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
1.102 raeburn 2874: $checked{'requestsmail'}{'adminemail'} = ' checked="checked" ';
1.190 raeburn 2875: $checked{'updatesmail'}{'adminemail'} = ' checked="checked" ';
1.203 raeburn 2876: $checked{'idconflictsmail'}{'adminemail'} = ' checked="checked" ';
1.28 raeburn 2877: }
2878: my ($titles,$short_titles) = &contact_titles();
2879: my $rownum = 0;
2880: my $css_class;
2881: foreach my $item (@contacts) {
1.69 raeburn 2882: $css_class = $rownum%2?' class="LC_odd_row"':'';
1.30 raeburn 2883: $datatable .= '<tr'.$css_class.'>'.
2884: '<td><span class="LC_nobreak">'.$titles->{$item}.
2885: '</span></td><td class="LC_right_item">'.
1.28 raeburn 2886: '<input type="text" name="'.$item.'" value="'.
2887: $to{$item}.'" /></td></tr>';
1.203 raeburn 2888: $rownum ++;
1.28 raeburn 2889: }
2890: foreach my $type (@mailings) {
1.69 raeburn 2891: $css_class = $rownum%2?' class="LC_odd_row"':'';
1.28 raeburn 2892: $datatable .= '<tr'.$css_class.'>'.
1.30 raeburn 2893: '<td><span class="LC_nobreak">'.
2894: $titles->{$type}.': </span></td>'.
1.28 raeburn 2895: '<td class="LC_left_item">'.
2896: '<span class="LC_nobreak">';
2897: foreach my $item (@contacts) {
2898: $datatable .= '<label>'.
2899: '<input type="checkbox" name="'.$type.'"'.
2900: $checked{$type}{$item}.
2901: ' value="'.$item.'" />'.$short_titles->{$item}.
2902: '</label> ';
2903: }
2904: $datatable .= '</span><br />'.&mt('Others').': '.
2905: '<input type="text" name="'.$type.'_others" '.
1.134 raeburn 2906: 'value="'.$otheremails{$type}.'" />';
2907: if ($type eq 'helpdeskmail') {
1.136 raeburn 2908: $datatable .= '<br />'.&mt('Bcc:').(' 'x6).
1.134 raeburn 2909: '<input type="text" name="'.$type.'_bcc" '.
2910: 'value="'.$bccemails{$type}.'" />';
2911: }
2912: $datatable .= '</td></tr>'."\n";
1.203 raeburn 2913: $rownum ++;
1.28 raeburn 2914: }
1.203 raeburn 2915: my %choices;
2916: $choices{'reporterrors'} = &mt('E-mail error reports to [_1]',
2917: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
2918: &mt('LON-CAPA core group - MSU'),600,500));
2919: $choices{'reportupdates'} = &mt('E-mail record of completed LON-CAPA updates to [_1]',
2920: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
2921: &mt('LON-CAPA core group - MSU'),600,500));
2922: my @toggles = ('reporterrors','reportupdates');
2923: my %defaultchecked = ('reporterrors' => 'on',
2924: 'reportupdates' => 'on');
2925: (my $reports,$rownum) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
2926: \%choices,$rownum);
2927: $datatable .= $reports;
1.30 raeburn 2928: $$rowtotal += $rownum;
1.28 raeburn 2929: return $datatable;
2930: }
2931:
1.118 jms 2932: sub print_helpsettings {
1.168 raeburn 2933: my ($dom,$confname,$settings,$rowtotal) = @_;
2934: my ($datatable,$itemcount);
1.166 raeburn 2935: $itemcount = 1;
1.168 raeburn 2936: my (%choices,%defaultchecked,@toggles);
2937: $choices{'submitbugs'} = &mt('Display link to: [_1]?',
2938: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
2939: &mt('LON-CAPA bug tracker'),600,500));
2940: %defaultchecked = ('submitbugs' => 'on');
2941: @toggles = ('submitbugs',);
1.166 raeburn 2942:
1.168 raeburn 2943: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
2944: \%choices,$itemcount);
1.166 raeburn 2945: return $datatable;
1.121 raeburn 2946: }
2947:
2948: sub radiobutton_prefs {
1.192 raeburn 2949: my ($settings,$toggles,$defaultchecked,$choices,$itemcount,$onclick,
1.257 raeburn 2950: $additional,$align) = @_;
1.121 raeburn 2951: return unless ((ref($toggles) eq 'ARRAY') && (ref($defaultchecked) eq 'HASH') &&
2952: (ref($choices) eq 'HASH'));
2953:
1.170 raeburn 2954: my (%checkedon,%checkedoff,$datatable,$css_class);
1.121 raeburn 2955:
2956: foreach my $item (@{$toggles}) {
2957: if ($defaultchecked->{$item} eq 'on') {
1.118 jms 2958: $checkedon{$item} = ' checked="checked" ';
2959: $checkedoff{$item} = ' ';
1.121 raeburn 2960: } elsif ($defaultchecked->{$item} eq 'off') {
1.118 jms 2961: $checkedoff{$item} = ' checked="checked" ';
2962: $checkedon{$item} = ' ';
2963: }
2964: }
2965: if (ref($settings) eq 'HASH') {
1.121 raeburn 2966: foreach my $item (@{$toggles}) {
1.118 jms 2967: if ($settings->{$item} eq '1') {
2968: $checkedon{$item} = ' checked="checked" ';
2969: $checkedoff{$item} = ' ';
2970: } elsif ($settings->{$item} eq '0') {
2971: $checkedoff{$item} = ' checked="checked" ';
2972: $checkedon{$item} = ' ';
2973: }
2974: }
1.121 raeburn 2975: }
1.192 raeburn 2976: if ($onclick) {
2977: $onclick = ' onclick="'.$onclick.'"';
2978: }
1.121 raeburn 2979: foreach my $item (@{$toggles}) {
1.118 jms 2980: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.121 raeburn 2981: $datatable .=
1.192 raeburn 2982: '<tr'.$css_class.'><td valign="top">'.
2983: '<span class="LC_nobreak">'.$choices->{$item}.
1.257 raeburn 2984: '</span></td>';
2985: if ($align eq 'left') {
2986: $datatable .= '<td class="LC_left_item">';
2987: } else {
2988: $datatable .= '<td class="LC_right_item">';
2989: }
2990: $datatable .=
2991: '<span class="LC_nobreak">'.
1.118 jms 2992: '<label><input type="radio" name="'.
1.192 raeburn 2993: $item.'" '.$checkedon{$item}.' value="1"'.$onclick.' />'.&mt('Yes').
1.118 jms 2994: '</label> <label><input type="radio" name="'.$item.'" '.
1.192 raeburn 2995: $checkedoff{$item}.' value="0"'.$onclick.' />'.&mt('No').'</label>'.
2996: '</span>'.$additional.
2997: '</td>'.
1.118 jms 2998: '</tr>';
2999: $itemcount ++;
1.121 raeburn 3000: }
3001: return ($datatable,$itemcount);
3002: }
3003:
1.267 raeburn 3004: sub print_ltitools {
3005: my ($dom,$settings,$rowtotal) = @_;
3006: my $rownum = 0;
3007: my $css_class;
3008: my $itemcount = 1;
3009: my $maxnum = 0;
3010: my %ordered;
3011: if (ref($settings) eq 'HASH') {
3012: foreach my $item (keys(%{$settings})) {
3013: if (ref($settings->{$item}) eq 'HASH') {
3014: my $num = $settings->{$item}{'order'};
3015: $ordered{$num} = $item;
3016: }
3017: }
3018: }
3019: my $confname = $dom.'-domainconfig';
3020: my $switchserver = &check_switchserver($dom,$confname);
3021: my $maxnum = scalar(keys(%ordered));
3022: my $datatable = <itools_javascript($settings);
3023: my %lt = <itools_names();
3024: my @courseroles = ('cc','in','ta','ep','st');
3025: my @ltiroles = qw(Instructor ContentDeveloper TeachingAssistant Learner);
3026: my @fields = ('fullname','firstname','lastname','email','user','roles');
3027: if (keys(%ordered)) {
3028: my @items = sort { $a <=> $b } keys(%ordered);
3029: for (my $i=0; $i<@items; $i++) {
3030: $css_class = $itemcount%2?' class="LC_odd_row"':'';
3031: my $item = $ordered{$items[$i]};
3032: my ($title,$key,$secret,$url,$imgsrc,$version);
3033: if (ref($settings->{$item}) eq 'HASH') {
3034: $title = $settings->{$item}->{'title'};
3035: $url = $settings->{$item}->{'url'};
3036: $key = $settings->{$item}->{'key'};
3037: $secret = $settings->{$item}->{'secret'};
3038: my $image = $settings->{$item}->{'image'};
3039: if ($image ne '') {
3040: $imgsrc = '<img src="'.$image.'" alt="'.&mt('Tool Provider icon').'" />';
3041: }
3042: }
3043: my $chgstr = ' onchange="javascript:reorderLTI(this.form,'."'ltitools_".$item."'".');"';
3044: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
3045: .'<select name="ltitools_'.$item.'"'.$chgstr.'>';
3046: for (my $k=0; $k<=$maxnum; $k++) {
3047: my $vpos = $k+1;
3048: my $selstr;
3049: if ($k == $i) {
3050: $selstr = ' selected="selected" ';
3051: }
3052: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
3053: }
3054: $datatable .= '</select>'.(' 'x2).
3055: '<label><input type="checkbox" name="ltitools_del" value="'.$item.'" />'.
3056: &mt('Delete?').'</label></span></td>'.
3057: '<td colspan="2">'.
3058: '<fieldset><legend>'.&mt('Required settings').'</legend>'.
3059: '<span class="LC_nobreak">'.$lt{'title'}.':<input type="text" size="30" name="ltitools_title_'.$i.'" value="'.$title.'" /></span> '.
3060: (' 'x2).
3061: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="ltitools_version_'.$i.'">'.
3062: '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '.
3063: (' 'x2).
3064: '<span class="LC_nobreak">'.$lt{'msgtype'}.':<select name="ltitools_msgtype_'.$i.'">'.
3065: '<option value="basic-lti-launch-request" selected="selected">Launch</option></select></span> '.
3066: '<br /><br />'.
3067: '<span class="LC_nobreak">'.$lt{'url'}.':<input type="text" size="30" name="ltitools_url_'.$i.'"'.
3068: ' value="'.$url.'" /></span>'.
3069: (' 'x2).
3070: '<span class="LC_nobreak">'.$lt{'key'}.
3071: '<input type="text" size="25" name="ltitools_key_'.$i.'" value="'.$key.'" /></span> '.
3072: (' 'x2).
3073: '<span class="LC_nobreak">'.$lt{'secret'}.':'.
3074: '<input type="password" size="20" name="ltitools_secret_'.$i.'" value="'.$secret.'" />'.
3075: '<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>'.
3076: '<input type="hidden" name="ltitools_id_'.$i.'" value="'.$item.'" /></span>'.
3077: '</fieldset>'.
3078: '<fieldset><legend>'.&mt('Optional settings').'</legend>'.
3079: '<span class="LC_nobreak">'.&mt('Display target:');
3080: my %currdisp;
3081: if (ref($settings->{$item}->{'display'}) eq 'HASH') {
3082: if ($settings->{$item}->{'display'}->{'target'} eq 'window') {
3083: $currdisp{'window'} = ' checked="checked"';
3084: } else {
3085: $currdisp{'iframe'} = ' checked="checked"';
3086: }
3087: if ($settings->{$item}->{'display'}->{'width'} =~ /^(\d+)$/) {
3088: $currdisp{'width'} = $1;
3089: }
3090: if ($settings->{$item}->{'display'}->{'height'} =~ /^(\d+)$/) {
3091: $currdisp{'height'} = $1;
3092: }
3093: } else {
3094: $currdisp{'iframe'} = ' checked="checked"';
3095: }
3096: foreach my $disp ('iframe','window') {
3097: $datatable .= '<label><input type="radio" name="ltitools_target_'.$i.'" value="'.$disp.'"'.$currdisp{$disp}.' />'.
3098: $lt{$disp}.'</label>'.(' 'x2);
3099: }
3100: $datatable .= (' 'x4);
3101: foreach my $dimen ('width','height') {
3102: $datatable .= '<label>'.$lt{$dimen}.' '.
3103: '<input type="text" name="ltitools_'.$dimen.'_'.$i.'" size="5" value="'.$currdisp{$dimen}.'" /></label>'.
3104: (' 'x2);
3105: }
3106: $datatable .= '<br />';
3107: foreach my $extra ('passback','roster') {
3108: my $checkedon = '';
3109: my $checkedoff = ' checked="checked"';
3110: if ($settings->{$item}->{$extra}) {
3111: $checkedon = $checkedoff;
3112: $checkedoff = '';
3113: }
3114: $datatable .= $lt{$extra}.' '.
3115: '<label><input type="radio" name="ltitools_'.$extra.'_'.$i.'" value="1"'.$checkedon.' />'.
3116: &mt('Yes').'</label>'.(' 'x2).
3117: '<label><input type="radio" name="ltitools_'.$extra.'_'.$i.'" value="0"'.$checkedoff.' />'.
3118: &mt('No').'</label>'.(' 'x4);
3119: }
3120: $datatable .= '<br /><br /><span class="LC_nobreak">'.$lt{'icon'}.': ';
3121: if ($imgsrc) {
3122: $datatable .= $imgsrc.
3123: '<label><input type="checkbox" name="ltitools_image_del"'.
3124: ' value="'.$item.'" />'.&mt('Delete?').'</label></span> '.
3125: '<span class="LC_nobreak"> '.&mt('Replace:').' ';
3126: } else {
3127: $datatable .= '('.&mt('if larger than 21x21 pixels, image will be scaled').') ';
3128: }
3129: if ($switchserver) {
3130: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
3131: } else {
3132: $datatable .= '<input type="file" name="ltitools_image_'.$i.'" value="" />';
3133: }
3134: $datatable .= '</span></fieldset>';
3135: my (%checkedfields,%rolemaps);
3136: if (ref($settings->{$item}) eq 'HASH') {
3137: if (ref($settings->{$item}->{'fields'}) eq 'HASH') {
3138: %checkedfields = %{$settings->{$item}->{'fields'}};
3139: }
3140: if (ref($settings->{$item}->{'roles'}) eq 'HASH') {
3141: %rolemaps = %{$settings->{$item}->{'roles'}};
3142: $checkedfields{'roles'} = 1;
3143: }
3144: }
3145: $datatable .= '<fieldset><legend>'.&mt('User data sent on launch').'</legend>'.
3146: '<span class="LC_nobreak">';
3147: foreach my $field (@fields) {
3148: my $checked;
3149: if ($checkedfields{$field}) {
3150: $checked = ' checked="checked"';
3151: }
3152: $datatable .= '<label>'.
3153: '<input type="checkbox" name="ltitools_fields_'.$i.'" value="'.$field.'"'.$checked.' />'.
3154: $lt{$field}.'</label>'.(' ' x2);
3155: }
3156: $datatable .= '</span></fieldset>'.
3157: '<fieldset><legend>'.&mt('Role mapping').'</legend><table><tr>';
3158: foreach my $role (@courseroles) {
3159: my ($selected,$selectnone);
3160: if (!$rolemaps{$role}) {
3161: $selectnone = ' selected="selected"';
3162: }
3163: $datatable .= '<td align="center">'.
3164: &Apache::lonnet::plaintext($role,'Course').'<br />'.
3165: '<select name="ltitools_roles_'.$role.'_'.$i.'">'.
3166: '<option value=""'.$selectnone.'>'.&mt('Select').'</option>';
3167: foreach my $ltirole (@ltiroles) {
3168: unless ($selectnone) {
3169: if ($rolemaps{$role} eq $ltirole) {
3170: $selected = ' selected="selected"';
3171: } else {
3172: $selected = '';
3173: }
3174: }
3175: $datatable .= '<option value="'.$ltirole.'"'.$selected.'>'.$ltirole.'</option>';
3176: }
3177: $datatable .= '</select></td>';
3178: }
1.273 raeburn 3179: $datatable .= '</tr></table></fieldset>';
3180: my %courseconfig;
3181: if (ref($settings->{$item}) eq 'HASH') {
3182: if (ref($settings->{$item}->{'crsconf'}) eq 'HASH') {
3183: %courseconfig = %{$settings->{$item}->{'crsconf'}};
3184: }
3185: }
3186: $datatable .= '<fieldset><legend>'.&mt('Configurable in course').'</legend><span class="LC_nobreak">';
3187: foreach my $item ('label','title','target') {
3188: my $checked;
3189: if ($courseconfig{$item}) {
3190: $checked = ' checked="checked"';
3191: }
3192: $datatable .= '<label>'.
3193: '<input type="checkbox" name="ltitools_courseconfig_'.$i.'" value="'.$item.'"'.$checked.' />'.
3194: $lt{'crs'.$item}.'</label>'.(' ' x2)."\n";
3195: }
3196: $datatable .= '</span></fieldset>'.
1.267 raeburn 3197: '<fieldset><legend>'.&mt('Custom items sent on launch').'</legend>'.
3198: '<table><tr><th>'.&mt('Action').'</th><th>'.&mt('Name').'</th><th>'.&mt('Value').'</th></tr>';
3199: if (ref($settings->{$item}->{'custom'}) eq 'HASH') {
3200: my %custom = %{$settings->{$item}->{'custom'}};
3201: if (keys(%custom) > 0) {
3202: foreach my $key (sort(keys(%custom))) {
3203: $datatable .= '<tr><td><span class="LC_nobreak">'.
3204: '<label><input type="checkbox" name="ltitools_customdel_'.$i.'" value="'.
3205: $key.'" />'.&mt('Delete').'</label></span></td><td>'.$key.'</td>'.
3206: '<td><input type="text" name="ltitools_customval_'.$key.'_'.$i.'"'.
3207: ' value="'.$custom{$key}.'" /></td></tr>';
3208: }
3209: }
3210: }
3211: $datatable .= '<tr><td><span class="LC_nobreak">'.
3212: '<label><input type="checkbox" name="ltitools_customadd" value="'.$i.'" />'.
3213: &mt('Add').'</label></span></td><td><input type="text" name="ltitools_custom_name_'.$i.'" />'.
3214: '</td><td><input type="text" name="ltitools_custom_value_'.$i.'" /></td></tr>';
3215: $datatable .= '</table></fieldset></td></tr>'."\n";
3216: $itemcount ++;
3217: }
3218: }
3219: $css_class = $itemcount%2?' class="LC_odd_row"':'';
3220: my $chgstr = ' onchange="javascript:reorderLTI(this.form,'."'ltitools_add_pos'".');"';
3221: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
3222: '<input type="hidden" name="ltitools_maxnum" value="'.$maxnum.'" />'."\n".
3223: '<select name="ltitools_add_pos"'.$chgstr.'>';
3224: for (my $k=0; $k<$maxnum+1; $k++) {
3225: my $vpos = $k+1;
3226: my $selstr;
3227: if ($k == $maxnum) {
3228: $selstr = ' selected="selected" ';
3229: }
3230: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
3231: }
3232: $datatable .= '</select> '."\n".
3233: '<input type="checkbox" name="ltitools_add" value="1" />'.&mt('Add').'</td>'."\n".
3234: '<td colspan="2">'.
3235: '<fieldset><legend>'.&mt('Required settings').'</legend>'.
3236: '<span class="LC_nobreak">'.$lt{'title'}.':<input type="text" size="30" name="ltitools_add_title" value="" /></span> '."\n".
3237: (' 'x2).
3238: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="ltitools_add_version">'.
3239: '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '."\n".
3240: (' 'x2).
3241: '<span class="LC_nobreak">'.$lt{'msgtype'}.':<select name="ltitools_add_msgtype">'.
3242: '<option value="basic-lti-launch-request" selected="selected">Launch</option></select></span> '.
3243: '<br />'.
3244: '<span class="LC_nobreak">'.$lt{'url'}.':<input type="text" size="30" name="ltitools_add_url" value="" /></span> '."\n".
3245: (' 'x2).
3246: '<span class="LC_nobreak">'.$lt{'key'}.':<input type="text" size="25" name="ltitools_add_key" value="" /></span> '."\n".
3247: (' 'x2).
3248: '<span class="LC_nobreak">'.$lt{'secret'}.':<input type="password" size="20" name="ltitools_add_secret" value="" />'.
3249: '<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".
3250: '</fieldset>'.
3251: '<fieldset><legend>'.&mt('Optional settings').'</legend>'.
3252: '<span class="LC_nobreak">'.&mt('Display target:');
3253: my %defaultdisp;
3254: $defaultdisp{'iframe'} = ' checked="checked"';
3255: foreach my $disp ('iframe','window') {
3256: $datatable .= '<label><input type="radio" name="ltitools_add_target" value="'.$disp.'"'.$defaultdisp{$disp}.' />'.
3257: $lt{$disp}.'</label>'.(' 'x2);
3258: }
3259: $datatable .= (' 'x4);
3260: foreach my $dimen ('width','height') {
3261: $datatable .= '<label>'.$lt{$dimen}.' '.
3262: '<input type="text" name="ltitools_add_'.$dimen.'" size="5" /></label>'.
3263: (' 'x2);
3264: }
3265: $datatable .= '<br />';
3266: foreach my $extra ('passback','roster') {
3267: $datatable .= $lt{$extra}.' '.
3268: '<label><input type="radio" name="ltitools_add_'.$extra.'" value="1" />'.
3269: &mt('Yes').'</label>'.(' 'x2).
3270: '<label><input type="radio" name="ltitools_add_'.$extra.'" value="0" checked="checked" />'.
3271: &mt('No').'</label>'.(' 'x4);
3272: }
3273: $datatable .= '<br /><br /><span class="LC_nobreak">'.$lt{'icon'}.': '.
3274: '('.&mt('if larger than 21x21 pixels, image will be scaled').') ';
3275: if ($switchserver) {
3276: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
3277: } else {
3278: $datatable .= '<input type="file" name="ltitools_add_image" value="" />';
3279: }
3280: $datatable .= '</span></fieldset>'.
3281: '<fieldset><legend>'.&mt('User data sent on launch').'</legend>'.
3282: '<span class="LC_nobreak">';
3283: foreach my $field (@fields) {
3284: $datatable .= '<label>'.
3285: '<input type="checkbox" name="ltitools_add_fields" value="'.$field.'" />'.
3286: $lt{$field}.'</label>'.(' ' x2);
3287: }
3288: $datatable .= '</span></fieldset>'.
3289: '<fieldset><legend>'.&mt('Role mapping').'</legend><table><tr>';
3290: foreach my $role (@courseroles) {
3291: my ($checked,$checkednone);
3292: $datatable .= '<td align="center">'.
3293: &Apache::lonnet::plaintext($role,'Course').'<br />'.
3294: '<select name="ltitools_add_roles_'.$role.'">'.
3295: '<option value="" selected="selected">'.&mt('Select').'</option>';
3296: foreach my $ltirole (@ltiroles) {
3297: $datatable .= '<option value="'.$ltirole.'">'.$ltirole.'</option>';
3298: }
3299: $datatable .= '</select></td>';
3300: }
3301: $datatable .= '</tr></table></fieldset>'.
1.273 raeburn 3302: '<fieldset><legend>'.&mt('Configurable in course').'</legend><span class="LC_nobreak">';
3303: foreach my $item ('label','title','target') {
3304: $datatable .= '<label>'.
3305: '<input type="checkbox" name="ltitools_courseconfig" value="'.$item.'" checked="checked" />'.
3306: $lt{'crs'.$item}.'</label>'.(' ' x2)."\n";
3307: }
3308: $datatable .= '</span></fieldset>'.
1.267 raeburn 3309: '<fieldset><legend>'.&mt('Custom items sent on launch').'</legend>'.
3310: '<table><tr><th>'.&mt('Action').'</th><th>'.&mt('Name').'</th><th>'.&mt('Value').'</th></tr>'.
3311: '<tr><td><span class="LC_nobreak">'.
3312: '<label><input type="checkbox" name="ltitools_add_custom" value="1" />'.
3313: &mt('Add').'</label></span></td><td><input type="text" name="ltitools_add_custom_name" />'.
3314: '</td><td><input type="text" name="ltitools_add_custom_value" /></td></tr>'.
3315: '</table></fieldset></td></tr>'."\n".
3316: '</td>'."\n".
3317: '</tr>'."\n";
3318: $itemcount ++;
3319: return $datatable;
3320: }
3321:
3322: sub ltitools_names {
3323: my %lt = &Apache::lonlocal::texthash(
3324: 'title' => 'Title',
3325: 'version' => 'Version',
3326: 'msgtype' => 'Message Type',
3327: 'url' => 'URL',
3328: 'key' => 'Key',
3329: 'secret' => 'Secret',
3330: 'icon' => 'Icon',
3331: 'user' => 'Username:domain',
3332: 'fullname' => 'Full Name',
3333: 'firstname' => 'First Name',
3334: 'lastname' => 'Last Name',
3335: 'email' => 'E-mail',
3336: 'roles' => 'Role',
3337: 'window' => 'Window/Tab',
3338: 'iframe' => 'iFrame',
3339: 'height' => 'Height',
3340: 'width' => 'Width',
3341: 'passback' => 'Tool can return grades:',
3342: 'roster' => 'Tool can retrieve roster:',
1.273 raeburn 3343: 'crstarget' => 'Display target',
3344: 'crslabel' => 'Course label',
3345: 'crstitle' => 'Course title',
1.267 raeburn 3346: );
3347: return %lt;
3348: }
3349:
1.121 raeburn 3350: sub print_coursedefaults {
1.139 raeburn 3351: my ($position,$dom,$settings,$rowtotal) = @_;
1.192 raeburn 3352: my ($css_class,$datatable,%checkedon,%checkedoff,%defaultchecked,@toggles);
1.121 raeburn 3353: my $itemcount = 1;
1.192 raeburn 3354: my %choices = &Apache::lonlocal::texthash (
3355: canuse_pdfforms => 'Course/Community users can create/upload PDF forms',
1.198 raeburn 3356: uploadquota => 'Default quota for files uploaded directly to course/community using Course Editor (MB)',
1.192 raeburn 3357: anonsurvey_threshold => 'Responder count needed before showing submissions for anonymous surveys',
3358: coursecredits => 'Credits can be specified for courses',
1.257 raeburn 3359: uselcmath => 'Math preview uses LON-CAPA previewer (javascript) in place of DragMath (Java)',
3360: usejsme => 'Molecule editor uses JSME (HTML5) in place of JME (Java)',
3361: postsubmit => 'Disable submit button/keypress following student submission',
1.264 raeburn 3362: canclone => "People who may clone a course (besides course's owner and coordinators)",
1.192 raeburn 3363: );
1.198 raeburn 3364: my %staticdefaults = (
3365: anonsurvey_threshold => 10,
3366: uploadquota => 500,
1.257 raeburn 3367: postsubmit => 60,
1.198 raeburn 3368: );
1.139 raeburn 3369: if ($position eq 'top') {
1.257 raeburn 3370: %defaultchecked = (
3371: 'canuse_pdfforms' => 'off',
3372: 'uselcmath' => 'on',
3373: 'usejsme' => 'on',
1.264 raeburn 3374: 'canclone' => 'none',
1.257 raeburn 3375: );
3376: @toggles = ('canuse_pdfforms','uselcmath','usejsme');
1.139 raeburn 3377: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
1.257 raeburn 3378: \%choices,$itemcount);
1.264 raeburn 3379: $css_class = $itemcount%2?' class="LC_odd_row"':'';
3380: $datatable .=
3381: '<tr'.$css_class.'><td valign="top">'.
3382: '<span class="LC_nobreak">'.$choices{'canclone'}.
3383: '</span></td><td class="LC_left_item">';
3384: my $currcanclone = 'none';
3385: my $onclick;
3386: my @cloneoptions = ('none','domain');
3387: my %clonetitles = (
3388: none => 'No additional course requesters',
3389: domain => "Any course requester in course's domain",
3390: instcode => 'Course requests for official courses ...',
3391: );
3392: my (%codedefaults,@code_order,@posscodes);
3393: if (&Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
3394: \@code_order) eq 'ok') {
3395: if (@code_order > 0) {
3396: push(@cloneoptions,'instcode');
3397: $onclick = ' onclick="toggleDisplay(this.form,'."'cloneinstcode'".');"';
3398: }
3399: }
3400: if (ref($settings) eq 'HASH') {
3401: if ($settings->{'canclone'}) {
3402: if (ref($settings->{'canclone'}) eq 'HASH') {
3403: if (ref($settings->{'canclone'}{'instcode'}) eq 'ARRAY') {
3404: if (@code_order > 0) {
3405: $currcanclone = 'instcode';
3406: @posscodes = @{$settings->{'canclone'}{'instcode'}};
3407: }
3408: }
3409: } elsif ($settings->{'canclone'} eq 'domain') {
3410: $currcanclone = $settings->{'canclone'};
3411: }
3412: }
3413: }
3414: foreach my $option (@cloneoptions) {
3415: my ($checked,$additional);
3416: if ($currcanclone eq $option) {
3417: $checked = ' checked="checked"';
3418: }
3419: if ($option eq 'instcode') {
3420: if (@code_order) {
3421: my $show = 'none';
3422: if ($checked) {
3423: $show = 'block';
3424: }
3425: $additional = '<div id="cloneinstcode" style="display:'.$show.'" />'.
3426: &mt('Institutional codes for new and cloned course have identical:').
3427: '<br />';
3428: foreach my $item (@code_order) {
3429: my $codechk;
3430: if ($checked) {
3431: if (grep(/^\Q$item\E$/,@posscodes)) {
3432: $codechk = ' checked="checked"';
3433: }
3434: }
3435: $additional .= '<label>'.
3436: '<input type="checkbox" name="clonecode" value="'.$item.'"'.$codechk.' />'.
3437: $item.'</label>';
3438: }
3439: $additional .= (' 'x2).'('.&mt('check as many as needed').')</div>';
3440: }
3441: }
3442: $datatable .=
3443: '<span class="LC_nobreak"><label><input type="radio" name="canclone"'.$checked.
3444: ' value="'.$option.'"'.$onclick.' />'.$clonetitles{$option}.
3445: '</label> '.$additional.'</span><br />';
3446: }
3447: $datatable .= '</td>'.
3448: '</tr>';
3449: $itemcount ++;
1.139 raeburn 3450: } else {
3451: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.257 raeburn 3452: my ($currdefresponder,%defcredits,%curruploadquota,%deftimeout);
1.192 raeburn 3453: my $currusecredits = 0;
1.257 raeburn 3454: my $postsubmitclient = 1;
1.271 raeburn 3455: my @types = ('official','unofficial','community','textbook','placement');
1.139 raeburn 3456: if (ref($settings) eq 'HASH') {
3457: $currdefresponder = $settings->{'anonsurvey_threshold'};
1.198 raeburn 3458: if (ref($settings->{'uploadquota'}) eq 'HASH') {
3459: foreach my $type (keys(%{$settings->{'uploadquota'}})) {
3460: $curruploadquota{$type} = $settings->{'uploadquota'}{$type};
3461: }
3462: }
1.192 raeburn 3463: if (ref($settings->{'coursecredits'}) eq 'HASH') {
1.257 raeburn 3464: foreach my $type (@types) {
3465: next if ($type eq 'community');
3466: $defcredits{$type} = $settings->{'coursecredits'}->{$type};
3467: if ($defcredits{$type} ne '') {
3468: $currusecredits = 1;
3469: }
3470: }
3471: }
3472: if (ref($settings->{'postsubmit'}) eq 'HASH') {
3473: if ($settings->{'postsubmit'}->{'client'} eq 'off') {
3474: $postsubmitclient = 0;
3475: foreach my $type (@types) {
3476: $deftimeout{$type} = $staticdefaults{'postsubmit'};
3477: }
3478: } else {
3479: foreach my $type (@types) {
3480: if (ref($settings->{'postsubmit'}->{'timeout'}) eq 'HASH') {
3481: if ($settings->{'postsubmit'}->{'timeout'}->{$type} =~ /^\d+$/) {
3482: $deftimeout{$type} = $settings->{'postsubmit'}->{'timeout'}->{$type};
3483: } else {
3484: $deftimeout{$type} = $staticdefaults{'postsubmit'};
3485: }
3486: } else {
3487: $deftimeout{$type} = $staticdefaults{'postsubmit'};
3488: }
3489: }
3490: }
3491: } else {
3492: foreach my $type (@types) {
3493: $deftimeout{$type} = $staticdefaults{'postsubmit'};
1.192 raeburn 3494: }
3495: }
1.258 raeburn 3496: } else {
3497: foreach my $type (@types) {
3498: $deftimeout{$type} = $staticdefaults{'postsubmit'};
3499: }
1.139 raeburn 3500: }
3501: if (!$currdefresponder) {
1.198 raeburn 3502: $currdefresponder = $staticdefaults{'anonsurvey_threshold'};
1.139 raeburn 3503: } elsif ($currdefresponder < 1) {
3504: $currdefresponder = 1;
3505: }
1.198 raeburn 3506: foreach my $type (@types) {
3507: if ($curruploadquota{$type} eq '') {
3508: $curruploadquota{$type} = $staticdefaults{'uploadquota'};
3509: }
3510: }
1.139 raeburn 3511: $datatable .=
1.192 raeburn 3512: '<tr'.$css_class.'><td><span class="LC_nobreak">'.
3513: $choices{'anonsurvey_threshold'}.
1.139 raeburn 3514: '</span></td>'.
3515: '<td class="LC_right_item"><span class="LC_nobreak">'.
3516: '<input type="text" name="anonsurvey_threshold"'.
3517: ' value="'.$currdefresponder.'" size="5" /></span>'.
1.230 raeburn 3518: '</td></tr>'."\n";
3519: $itemcount ++;
3520: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
3521: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
3522: $choices{'uploadquota'}.
3523: '</span></td>'.
3524: '<td align="right" class="LC_right_item">'.
3525: '<table><tr>';
1.198 raeburn 3526: foreach my $type (@types) {
3527: $datatable .= '<td align="center">'.&mt($type).'<br />'.
3528: '<input type="text" name="uploadquota_'.$type.'"'.
3529: ' value="'.$curruploadquota{$type}.'" size="5" /></td>';
3530: }
3531: $datatable .= '</tr></table></td></tr>'."\n";
1.230 raeburn 3532: $itemcount ++;
1.236 raeburn 3533: my $onclick = "toggleDisplay(this.form,'credits');";
1.210 raeburn 3534: my $display = 'none';
1.192 raeburn 3535: if ($currusecredits) {
3536: $display = 'block';
3537: }
3538: my $additional = '<div id="credits" style="display: '.$display.'">'.
1.257 raeburn 3539: '<i>'.&mt('Default credits').'</i><br /><table><tr>';
3540: foreach my $type (@types) {
3541: next if ($type eq 'community');
3542: $additional .= '<td align="center">'.&mt($type).'<br />'.
3543: '<input type="text" name="'.$type.'_credits"'.
1.258 raeburn 3544: ' value="'.$defcredits{$type}.'" size="3" /></td>';
1.257 raeburn 3545: }
3546: $additional .= '</tr></table></div>'."\n";
1.192 raeburn 3547: %defaultchecked = ('coursecredits' => 'off');
3548: @toggles = ('coursecredits');
3549: my $current = {
3550: 'coursecredits' => $currusecredits,
3551: };
3552: (my $table,$itemcount) =
3553: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
1.257 raeburn 3554: \%choices,$itemcount,$onclick,$additional,'left');
3555: $datatable .= $table;
3556: $onclick = "toggleDisplay(this.form,'studentsubmission');";
3557: my $display = 'none';
3558: if ($postsubmitclient) {
3559: $display = 'block';
3560: }
3561: $additional = '<div id="studentsubmission" style="display: '.$display.'">'.
1.259 raeburn 3562: &mt('Number of seconds submit is disabled').'<br />'.
3563: '<i>'.&mt('Enter 0 to remain disabled until page reload.').'</i><br />'.
3564: '<table><tr>';
1.257 raeburn 3565: foreach my $type (@types) {
3566: $additional .= '<td align="center">'.&mt($type).'<br />'.
3567: '<input type="text" name="'.$type.'_timeout" value="'.
3568: $deftimeout{$type}.'" size="5" /></td>';
3569: }
3570: $additional .= '</tr></table></div>'."\n";
3571: %defaultchecked = ('postsubmit' => 'on');
3572: @toggles = ('postsubmit');
3573: my $current = {
3574: 'postsubmit' => $postsubmitclient,
3575: };
3576: ($table,$itemcount) =
3577: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
3578: \%choices,$itemcount,$onclick,$additional,'left');
1.192 raeburn 3579: $datatable .= $table;
1.139 raeburn 3580: }
1.192 raeburn 3581: $$rowtotal += $itemcount;
1.121 raeburn 3582: return $datatable;
1.118 jms 3583: }
3584:
1.231 raeburn 3585: sub print_selfenrollment {
3586: my ($position,$dom,$settings,$rowtotal) = @_;
3587: my ($css_class,$datatable);
3588: my $itemcount = 1;
1.271 raeburn 3589: my @types = ('official','unofficial','community','textbook','placement');
1.231 raeburn 3590: if (($position eq 'top') || ($position eq 'middle')) {
1.232 raeburn 3591: my ($rowsref,$titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
3592: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
1.231 raeburn 3593: my @rows;
3594: my $key;
3595: if ($position eq 'top') {
3596: $key = 'admin';
3597: if (ref($rowsref) eq 'ARRAY') {
3598: @rows = @{$rowsref};
3599: }
3600: } elsif ($position eq 'middle') {
3601: $key = 'default';
3602: @rows = ('types','registered','approval','limit');
3603: }
3604: foreach my $row (@rows) {
3605: if (defined($titlesref->{$row})) {
3606: $itemcount ++;
3607: $css_class = $itemcount%2?' class="LC_odd_row"':'';
3608: $datatable .= '<tr'.$css_class.'>'.
3609: '<td>'.$titlesref->{$row}.'</td>'.
3610: '<td class="LC_left_item">'.
3611: '<table><tr>';
3612: my (%current,%currentcap);
3613: if (ref($settings) eq 'HASH') {
3614: if (ref($settings->{$key}) eq 'HASH') {
3615: foreach my $type (@types) {
3616: if (ref($settings->{$key}->{$type}) eq 'HASH') {
3617: $current{$type} = $settings->{$key}->{$type}->{$row};
3618: }
3619: if (($row eq 'limit') && ($key eq 'default')) {
3620: if (ref($settings->{$key}->{$type}) eq 'HASH') {
3621: $currentcap{$type} = $settings->{$key}->{$type}->{'cap'};
3622: }
3623: }
3624: }
3625: }
3626: }
3627: my %roles = (
3628: '0' => &Apache::lonnet::plaintext('dc'),
3629: );
3630:
3631: foreach my $type (@types) {
3632: unless (($row eq 'registered') && ($key eq 'default')) {
3633: $datatable .= '<th>'.&mt($type).'</th>';
3634: }
3635: }
3636: unless (($row eq 'registered') && ($key eq 'default')) {
3637: $datatable .= '</tr><tr>';
3638: }
3639: foreach my $type (@types) {
3640: if ($type eq 'community') {
3641: $roles{'1'} = &mt('Community personnel');
3642: } else {
3643: $roles{'1'} = &mt('Course personnel');
3644: }
3645: $datatable .= '<td style="vertical-align: top">';
3646: if ($position eq 'top') {
3647: my %checked;
3648: if ($current{$type} eq '0') {
3649: $checked{'0'} = ' checked="checked"';
3650: } else {
3651: $checked{'1'} = ' checked="checked"';
3652: }
3653: foreach my $role ('1','0') {
3654: $datatable .= '<span class="LC_nobreak"><label>'.
3655: '<input type="radio" name="selfenrolladmin_'.$row.'_'.$type.'" '.
3656: 'value="'.$role.'"'.$checked{$role}.' />'.
3657: $roles{$role}.'</label></span> ';
3658: }
3659: } else {
3660: if ($row eq 'types') {
3661: my %checked;
3662: if ($current{$type} =~ /^(all|dom)$/) {
3663: $checked{$1} = ' checked="checked"';
3664: } else {
3665: $checked{''} = ' checked="checked"';
3666: }
3667: foreach my $val ('','dom','all') {
3668: $datatable .= '<span class="LC_nobreak"><label>'.
3669: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
3670: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
3671: }
3672: } elsif ($row eq 'registered') {
3673: my %checked;
3674: if ($current{$type} eq '1') {
3675: $checked{'1'} = ' checked="checked"';
3676: } else {
3677: $checked{'0'} = ' checked="checked"';
3678: }
3679: foreach my $val ('0','1') {
3680: $datatable .= '<span class="LC_nobreak"><label>'.
3681: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
3682: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
3683: }
3684: } elsif ($row eq 'approval') {
3685: my %checked;
3686: if ($current{$type} =~ /^([12])$/) {
3687: $checked{$1} = ' checked="checked"';
3688: } else {
3689: $checked{'0'} = ' checked="checked"';
3690: }
3691: for my $val (0..2) {
3692: $datatable .= '<span class="LC_nobreak"><label>'.
3693: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
3694: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
3695: }
3696: } elsif ($row eq 'limit') {
3697: my %checked;
3698: if ($current{$type} =~ /^(allstudents|selfenrolled)$/) {
3699: $checked{$1} = ' checked="checked"';
3700: } else {
3701: $checked{'none'} = ' checked="checked"';
3702: }
3703: my $cap;
3704: if ($currentcap{$type} =~ /^\d+$/) {
3705: $cap = $currentcap{$type};
3706: }
3707: foreach my $val ('none','allstudents','selfenrolled') {
3708: $datatable .= '<span class="LC_nobreak"><label>'.
3709: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
3710: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
3711: }
3712: $datatable .= '<br />'.
3713: '<span class="LC_nobreak">'.&mt('Maximum allowed: ').
3714: '<input type="text" name="selfenrolldefault_cap_'.$type.'" size = "5" value="'.$cap.'" />'.
3715: '</span>';
3716: }
3717: }
3718: $datatable .= '</td>';
3719: }
3720: $datatable .= '</tr>';
3721: }
3722: $datatable .= '</table></td></tr>';
3723: }
3724: } elsif ($position eq 'bottom') {
1.235 raeburn 3725: $datatable .= &print_validation_rows('selfenroll',$dom,$settings,\$itemcount);
3726: }
3727: $$rowtotal += $itemcount;
3728: return $datatable;
3729: }
3730:
3731: sub print_validation_rows {
3732: my ($caller,$dom,$settings,$rowtotal) = @_;
3733: my ($itemsref,$namesref,$fieldsref);
3734: if ($caller eq 'selfenroll') {
3735: ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
3736: } elsif ($caller eq 'requestcourses') {
3737: ($itemsref,$namesref,$fieldsref) = &Apache::loncoursequeueadmin::requestcourses_validation_types();
3738: }
3739: my %currvalidation;
3740: if (ref($settings) eq 'HASH') {
3741: if (ref($settings->{'validation'}) eq 'HASH') {
3742: %currvalidation = %{$settings->{'validation'}};
1.231 raeburn 3743: }
1.235 raeburn 3744: }
3745: my $datatable;
3746: my $itemcount = 0;
3747: foreach my $item (@{$itemsref}) {
3748: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
3749: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
3750: $namesref->{$item}.
3751: '</span></td>'.
3752: '<td class="LC_left_item">';
3753: if (($item eq 'url') || ($item eq 'button')) {
3754: $datatable .= '<span class="LC_nobreak">'.
3755: '<input type="text" name="'.$caller.'_validation_'.$item.'"'.
3756: ' value="'.$currvalidation{$item}.'" size="50" /></span>';
3757: } elsif ($item eq 'fields') {
3758: my @currfields;
3759: if (ref($currvalidation{$item}) eq 'ARRAY') {
3760: @currfields = @{$currvalidation{$item}};
3761: }
3762: foreach my $field (@{$fieldsref}) {
3763: my $check = '';
3764: if (grep(/^\Q$field\E$/,@currfields)) {
3765: $check = ' checked="checked"';
3766: }
3767: $datatable .= '<span class="LC_nobreak"><label>'.
3768: '<input type="checkbox" name="'.$caller.'_validation_fields"'.
3769: ' value="'.$field.'"'.$check.' />'.$field.
3770: '</label></span> ';
3771: }
3772: } elsif ($item eq 'markup') {
3773: $datatable .= '<textarea name="'.$caller.'_validation_markup" cols="50" rows="5" wrap="soft">'.
3774: $currvalidation{$item}.
1.231 raeburn 3775: '</textarea>';
1.235 raeburn 3776: }
3777: $datatable .= '</td></tr>'."\n";
3778: if (ref($rowtotal)) {
1.231 raeburn 3779: $itemcount ++;
3780: }
3781: }
1.235 raeburn 3782: if ($caller eq 'requestcourses') {
3783: my %currhash;
1.248 raeburn 3784: if (ref($settings) eq 'HASH') {
3785: if (ref($settings->{'validation'}) eq 'HASH') {
3786: if ($settings->{'validation'}{'dc'} ne '') {
3787: $currhash{$settings->{'validation'}{'dc'}} = 1;
3788: }
1.235 raeburn 3789: }
3790: }
3791: my $numinrow = 2;
3792: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
3793: 'validationdc',%currhash);
1.247 raeburn 3794: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
3795: $datatable .= '</td></tr><tr'.$css_class.'><td>';
1.235 raeburn 3796: if ($numdc > 1) {
1.247 raeburn 3797: $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)');
1.235 raeburn 3798: } else {
1.247 raeburn 3799: $datatable .= &mt('Course creation processed as: ');
1.235 raeburn 3800: }
1.247 raeburn 3801: $datatable .= '</td><td class="LC_left_item">'.$dctable.'</td></tr>';
1.235 raeburn 3802: $itemcount ++;
3803: }
3804: if (ref($rowtotal)) {
3805: $$rowtotal += $itemcount;
3806: }
1.231 raeburn 3807: return $datatable;
3808: }
3809:
1.137 raeburn 3810: sub print_usersessions {
3811: my ($position,$dom,$settings,$rowtotal) = @_;
3812: my ($css_class,$datatable,%checked,%choices);
1.275 ! raeburn 3813: my (%by_ip,%by_location,@intdoms,@instdoms);
! 3814: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
1.145 raeburn 3815:
3816: my @alldoms = &Apache::lonnet::all_domains();
1.152 raeburn 3817: my %serverhomes = %Apache::lonnet::serverhomeIDs;
1.149 raeburn 3818: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.152 raeburn 3819: my %altids = &id_for_thisdom(%servers);
1.145 raeburn 3820: my $itemcount = 1;
3821: if ($position eq 'top') {
1.152 raeburn 3822: if (keys(%serverhomes) > 1) {
1.145 raeburn 3823: my %spareid = ¤t_offloads_to($dom,$settings,\%servers);
1.261 raeburn 3824: my $curroffloadnow;
3825: if (ref($settings) eq 'HASH') {
3826: if (ref($settings->{'offloadnow'}) eq 'HASH') {
3827: $curroffloadnow = $settings->{'offloadnow'};
3828: }
3829: }
3830: $datatable .= &spares_row($dom,\%servers,\%spareid,\%serverhomes,\%altids,$curroffloadnow,$rowtotal);
1.145 raeburn 3831: } else {
1.140 raeburn 3832: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.150 raeburn 3833: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one server.');
1.140 raeburn 3834: }
1.137 raeburn 3835: } else {
1.145 raeburn 3836: if (keys(%by_location) == 0) {
3837: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.150 raeburn 3838: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one institution.');
1.145 raeburn 3839: } else {
3840: my %lt = &usersession_titles();
3841: my $numinrow = 5;
3842: my $prefix;
3843: my @types;
3844: if ($position eq 'bottom') {
3845: $prefix = 'remote';
3846: @types = ('version','excludedomain','includedomain');
3847: } else {
3848: $prefix = 'hosted';
3849: @types = ('excludedomain','includedomain');
3850: }
3851: my (%current,%checkedon,%checkedoff);
3852: my @lcversions = &Apache::lonnet::all_loncaparevs();
3853: my @locations = sort(keys(%by_location));
3854: foreach my $type (@types) {
3855: $checkedon{$type} = '';
3856: $checkedoff{$type} = ' checked="checked"';
3857: }
3858: if (ref($settings) eq 'HASH') {
3859: if (ref($settings->{$prefix}) eq 'HASH') {
3860: foreach my $key (keys(%{$settings->{$prefix}})) {
3861: $current{$key} = $settings->{$prefix}{$key};
3862: if ($key eq 'version') {
3863: if ($current{$key} ne '') {
3864: $checkedon{$key} = ' checked="checked"';
3865: $checkedoff{$key} = '';
3866: }
3867: } elsif (ref($current{$key}) eq 'ARRAY') {
3868: $checkedon{$key} = ' checked="checked"';
3869: $checkedoff{$key} = '';
3870: }
1.137 raeburn 3871: }
3872: }
3873: }
1.145 raeburn 3874: foreach my $type (@types) {
3875: next if ($type ne 'version' && !@locations);
3876: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
3877: $datatable .= '<tr'.$css_class.'>
3878: <td><span class="LC_nobreak">'.$lt{$type}.'</span><br />
3879: <span class="LC_nobreak">
3880: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedoff{$type}.' value="0" />'.&mt('Not in use').'</label>
3881: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedon{$type}.' value="1" />'.&mt('In use').'</label></span></td><td>';
3882: if ($type eq 'version') {
3883: my $selector = '<select name="'.$prefix.'_version">';
3884: foreach my $version (@lcversions) {
3885: my $selected = '';
3886: if ($current{'version'} eq $version) {
3887: $selected = ' selected="selected"';
3888: }
3889: $selector .= ' <option value="'.$version.'"'.
3890: $selected.'>'.$version.'</option>';
3891: }
3892: $selector .= '</select> ';
3893: $datatable .= &mt('remote server must be version: [_1] or later',$selector);
3894: } else {
3895: $datatable.= '<div><input type="button" value="'.&mt('check all').'" '.
3896: 'onclick="javascript:checkAll(document.display.'.$prefix.'_'.$type.')"'.
3897: ' />'.(' 'x2).
3898: '<input type="button" value="'.&mt('uncheck all').'" '.
3899: 'onclick="javascript:uncheckAll(document.display.'.$prefix.'_'.$type.')" />'.
3900: "\n".
3901: '</div><div><table>';
3902: my $rem;
3903: for (my $i=0; $i<@locations; $i++) {
3904: my ($showloc,$value,$checkedtype);
3905: if (ref($by_location{$locations[$i]}) eq 'ARRAY') {
3906: my $ip = $by_location{$locations[$i]}->[0];
3907: if (ref($by_ip{$ip}) eq 'ARRAY') {
3908: $value = join(':',@{$by_ip{$ip}});
3909: $showloc = join(', ',@{$by_ip{$ip}});
3910: if (ref($current{$type}) eq 'ARRAY') {
3911: foreach my $loc (@{$by_ip{$ip}}) {
3912: if (grep(/^\Q$loc\E$/,@{$current{$type}})) {
3913: $checkedtype = ' checked="checked"';
3914: last;
3915: }
3916: }
1.138 raeburn 3917: }
3918: }
3919: }
1.145 raeburn 3920: $rem = $i%($numinrow);
3921: if ($rem == 0) {
3922: if ($i > 0) {
3923: $datatable .= '</tr>';
3924: }
3925: $datatable .= '<tr>';
3926: }
3927: $datatable .= '<td class="LC_left_item">'.
3928: '<span class="LC_nobreak"><label>'.
3929: '<input type="checkbox" name="'.$prefix.'_'.$type.
3930: '" value="'.$value.'"'.$checkedtype.' />'.$showloc.
3931: '</label></span></td>';
1.137 raeburn 3932: }
1.145 raeburn 3933: $rem = @locations%($numinrow);
3934: my $colsleft = $numinrow - $rem;
3935: if ($colsleft > 1 ) {
3936: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
3937: ' </td>';
3938: } elsif ($colsleft == 1) {
3939: $datatable .= '<td class="LC_left_item"> </td>';
1.137 raeburn 3940: }
1.145 raeburn 3941: $datatable .= '</tr></table>';
1.137 raeburn 3942: }
1.145 raeburn 3943: $datatable .= '</td></tr>';
3944: $itemcount ++;
1.137 raeburn 3945: }
3946: }
3947: }
3948: $$rowtotal += $itemcount;
3949: return $datatable;
3950: }
3951:
1.275 ! raeburn 3952: sub print_ssl {
! 3953: my ($position,$dom,$settings,$rowtotal) = @_;
! 3954: my ($css_class,$datatable);
! 3955: my $lonhost = '';
! 3956: my $itemcount = 1;
! 3957: if ($position eq 'top') {
! 3958: my %domservers = &Apache::lonnet::get_servers($dom);
! 3959: $css_class = $itemcount%2?' class="LC_odd_row"':'';
! 3960: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
! 3961: &LONCAPA::SSL::print_certstatus(\%domservers,'web','domprefs').
! 3962: '</td></tr>';
! 3963: $itemcount ++;
! 3964: } else {
! 3965: my %titles = &ssl_titles();
! 3966: my (%by_ip,%by_location,@intdoms,@instdoms);
! 3967: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
! 3968: my @alldoms = &Apache::lonnet::all_domains();
! 3969: my %serverhomes = %Apache::lonnet::serverhomeIDs;
! 3970: my @domservers = &Apache::lonnet::get_servers($dom);
! 3971: my %servers = &Apache::lonnet::internet_dom_servers($dom);
! 3972: my %altids = &id_for_thisdom(%servers);
! 3973: if ($position eq 'middle') {
! 3974: foreach my $type ('dom','intdom','other') {
! 3975: my %checked;
! 3976: $css_class = $itemcount%2?' class="LC_odd_row"':'';
! 3977: $datatable .= '<tr'.$css_class.'><td>'.$titles{$type}.'</td>'.
! 3978: '<td class="LC_right_item">';
! 3979: my $skip;
! 3980: if ($type eq 'dom') {
! 3981: unless (keys(%servers) > 1) {
! 3982: $datatable .= &mt('Nothing to set here, as there are no other servers/VMs');
! 3983: $skip = 1;
! 3984: }
! 3985: }
! 3986: if ($type eq 'intdom') {
! 3987: unless (@instdoms > 1) {
! 3988: $datatable .= &mt('Nothing to set here, as there are no other domains for this institution');
! 3989: $skip = 1;
! 3990: }
! 3991: } elsif ($type eq 'other') {
! 3992: if (keys(%by_location) == 0) {
! 3993: $datatable .= &mt('Nothing to set here, as there are no other institutions');
! 3994: $skip = 1;
! 3995: }
! 3996: }
! 3997: unless ($skip) {
! 3998: $checked{'yes'} = ' checked="checked"';
! 3999: if (ref($settings) eq 'HASH') {
! 4000: if (ref($settings->{'connect'}) eq 'HASH') {
! 4001: if ($settings->{'connect'}->{$type} =~ /^(no|req)$/) {
! 4002: $checked{$1} = $checked{'yes'};
! 4003: delete($checked{'yes'});
! 4004: }
! 4005: }
! 4006: }
! 4007: foreach my $option ('no','yes','req') {
! 4008: $datatable .= '<span class="LC_nobreak"><label>'.
! 4009: '<input type="radio" name="connect_'.$type.'" '.
! 4010: 'value="'.$option.'"'.$checked{$option}.' />'.$titles{$option}.
! 4011: '</label></span>'.(' 'x2);
! 4012: }
! 4013: }
! 4014: $datatable .= '</td></tr>';
! 4015: $itemcount ++;
! 4016: }
! 4017: } else {
! 4018: my $numinrow = 5;
! 4019: my $prefix = 'replication';
! 4020: my @types = ('certreq','nocertreq');
! 4021: my (%current,%checkedon,%checkedoff);
! 4022: my @locations = sort(keys(%by_location));
! 4023: foreach my $type (@types) {
! 4024: $checkedon{$type} = '';
! 4025: $checkedoff{$type} = ' checked="checked"';
! 4026: }
! 4027: if (ref($settings) eq 'HASH') {
! 4028: if (ref($settings->{$prefix}) eq 'HASH') {
! 4029: foreach my $key (keys(%{$settings->{$prefix}})) {
! 4030: $current{$key} = $settings->{$prefix}{$key};
! 4031: if (ref($current{$key}) eq 'ARRAY') {
! 4032: $checkedon{$key} = ' checked="checked"';
! 4033: $checkedoff{$key} = '';
! 4034: }
! 4035: }
! 4036: }
! 4037: }
! 4038: if (@locations > 0) {
! 4039: foreach my $type (@types) {
! 4040: $css_class = $itemcount%2?' class="LC_odd_row"':'';
! 4041: $datatable .= '<tr'.$css_class.'>
! 4042: <td><span class="LC_nobreak LC_right_item">'.$titles{$type}.'</span><br />
! 4043: <span class="LC_nobreak">
! 4044: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedoff{$type}.' value="0" />'.&mt('Not in use').'</label>
! 4045: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedon{$type}.' value="1" />'.&mt('In use').'</label></span></td><td>
! 4046: <div><input type="button" value="'.&mt('check all').'" '.
! 4047: 'onclick="javascript:checkAll(document.display.'.$prefix.'_'.$type.')"'.
! 4048: ' />'.(' 'x2)."\n".
! 4049: '<input type="button" value="'.&mt('uncheck all').'" '.
! 4050: 'onclick="javascript:uncheckAll(document.display.'.$prefix.'_'.$type.')" />'.
! 4051: "\n".
! 4052: '</div><div><table>';
! 4053: my $rem;
! 4054: for (my $i=0; $i<@locations; $i++) {
! 4055: my ($showloc,$value,$checkedtype);
! 4056: if (ref($by_location{$locations[$i]}) eq 'ARRAY') {
! 4057: my $ip = $by_location{$locations[$i]}->[0];
! 4058: if (ref($by_ip{$ip}) eq 'ARRAY') {
! 4059: $value = join(':',@{$by_ip{$ip}});
! 4060: $showloc = join(', ',@{$by_ip{$ip}});
! 4061: if (ref($current{$type}) eq 'ARRAY') {
! 4062: foreach my $loc (@{$by_ip{$ip}}) {
! 4063: if (grep(/^\Q$loc\E$/,@{$current{$type}})) {
! 4064: $checkedtype = ' checked="checked"';
! 4065: last;
! 4066: }
! 4067: }
! 4068: }
! 4069: }
! 4070: }
! 4071: $rem = $i%($numinrow);
! 4072: if ($rem == 0) {
! 4073: if ($i > 0) {
! 4074: $datatable .= '</tr>';
! 4075: }
! 4076: $datatable .= '<tr>';
! 4077: }
! 4078: $datatable .= '<td class="LC_left_item">'.
! 4079: '<span class="LC_nobreak"><label>'.
! 4080: '<input type="checkbox" name="'.$prefix.'_'.$type.
! 4081: '" value="'.$value.'"'.$checkedtype.' />'.$showloc.
! 4082: '</label></span></td>';
! 4083: }
! 4084: $rem = @locations%($numinrow);
! 4085: my $colsleft = $numinrow - $rem;
! 4086: if ($colsleft > 1 ) {
! 4087: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
! 4088: ' </td>';
! 4089: } elsif ($colsleft == 1) {
! 4090: $datatable .= '<td class="LC_left_item"> </td>';
! 4091: }
! 4092: $datatable .= '</tr></table></td></tr>';
! 4093: $itemcount ++;
! 4094: }
! 4095: } else {
! 4096: $datatable .= '<tr'.$css_class.'><td>'.&mt('Nothing to set here, as there are no other institutions').'</td></tr>';
! 4097: $itemcount ++;
! 4098: }
! 4099: }
! 4100: }
! 4101: $$rowtotal += $itemcount;
! 4102: return $datatable;
! 4103: }
! 4104:
! 4105: sub ssl_titles {
! 4106: return &Apache::lonlocal::texthash (
! 4107: dom => 'LON-CAPA servers/VMs from same domain',
! 4108: intdom => 'LON-CAPA servers/VMs from same "internet" domain',
! 4109: other => 'External LON-CAPA servers/VMs',
! 4110: connect => 'Connections to other servers',
! 4111: replication => 'Replicating content to other institutions',
! 4112: certreq => 'Client certificate required, but specific domains exempt',
! 4113: nocertreq => 'No client certificate required, except for specific domains',
! 4114: no => 'SSL not used',
! 4115: yes => 'SSL Optional (used if available)',
! 4116: req => 'SSL Required',
! 4117: );
! 4118: }
! 4119:
1.138 raeburn 4120: sub build_location_hashes {
1.275 ! raeburn 4121: my ($intdoms,$by_ip,$by_location,$instdoms) = @_;
1.138 raeburn 4122: return unless((ref($intdoms) eq 'ARRAY') && (ref($by_ip) eq 'HASH') &&
1.275 ! raeburn 4123: (ref($by_location) eq 'HASH') && (ref($instdoms) eq 'ARRAY'));
1.138 raeburn 4124: my %iphost = &Apache::lonnet::get_iphost();
4125: my $primary_id = &Apache::lonnet::domain($env{'request.role.domain'},'primary');
4126: my $primary_ip = &Apache::lonnet::get_host_ip($primary_id);
4127: if (ref($iphost{$primary_ip}) eq 'ARRAY') {
4128: foreach my $id (@{$iphost{$primary_ip}}) {
4129: my $intdom = &Apache::lonnet::internet_dom($id);
4130: unless(grep(/^\Q$intdom\E$/,@{$intdoms})) {
4131: push(@{$intdoms},$intdom);
4132: }
4133: }
4134: }
4135: foreach my $ip (keys(%iphost)) {
4136: if (ref($iphost{$ip}) eq 'ARRAY') {
4137: foreach my $id (@{$iphost{$ip}}) {
4138: my $location = &Apache::lonnet::internet_dom($id);
4139: if ($location) {
1.275 ! raeburn 4140: if (grep(/^\Q$location\E$/,@{$intdoms})) {
! 4141: my $dom = &Apache::lonnet::host_domain($id);
! 4142: unless (grep(/^\Q$dom\E/,@{$instdoms})) {
! 4143: push(@{$instdoms},$dom);
! 4144: }
! 4145: next;
! 4146: }
1.138 raeburn 4147: if (ref($by_ip->{$ip}) eq 'ARRAY') {
4148: unless(grep(/^\Q$location\E$/,@{$by_ip->{$ip}})) {
4149: push(@{$by_ip->{$ip}},$location);
4150: }
4151: } else {
4152: $by_ip->{$ip} = [$location];
4153: }
4154: }
4155: }
4156: }
4157: }
4158: foreach my $ip (sort(keys(%{$by_ip}))) {
4159: if (ref($by_ip->{$ip}) eq 'ARRAY') {
4160: @{$by_ip->{$ip}} = sort(@{$by_ip->{$ip}});
4161: my $first = $by_ip->{$ip}->[0];
4162: if (ref($by_location->{$first}) eq 'ARRAY') {
4163: unless (grep(/^\Q$ip\E$/,@{$by_location->{$first}})) {
4164: push(@{$by_location->{$first}},$ip);
4165: }
4166: } else {
4167: $by_location->{$first} = [$ip];
4168: }
4169: }
4170: }
4171: return;
4172: }
4173:
1.145 raeburn 4174: sub current_offloads_to {
4175: my ($dom,$settings,$servers) = @_;
4176: my (%spareid,%otherdomconfigs);
1.152 raeburn 4177: if (ref($servers) eq 'HASH') {
1.145 raeburn 4178: foreach my $lonhost (sort(keys(%{$servers}))) {
4179: my $gotspares;
1.152 raeburn 4180: if (ref($settings) eq 'HASH') {
4181: if (ref($settings->{'spares'}) eq 'HASH') {
4182: if (ref($settings->{'spares'}{$lonhost}) eq 'HASH') {
4183: $spareid{$lonhost}{'primary'} = $settings->{'spares'}{$lonhost}{'primary'};
4184: $spareid{$lonhost}{'default'} = $settings->{'spares'}{$lonhost}{'default'};
4185: $gotspares = 1;
4186: }
1.145 raeburn 4187: }
4188: }
4189: unless ($gotspares) {
4190: my $gotspares;
4191: my $serverhomeID =
4192: &Apache::lonnet::get_server_homeID($servers->{$lonhost});
4193: my $serverhomedom =
4194: &Apache::lonnet::host_domain($serverhomeID);
4195: if ($serverhomedom ne $dom) {
4196: if (ref($otherdomconfigs{$serverhomedom} eq 'HASH')) {
4197: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
4198: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
4199: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
4200: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
4201: $gotspares = 1;
4202: }
4203: }
4204: } else {
4205: $otherdomconfigs{$serverhomedom} =
4206: &Apache::lonnet::get_dom('configuration',['usersessions'],$serverhomedom);
4207: if (ref($otherdomconfigs{$serverhomedom}) eq 'HASH') {
4208: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
4209: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
4210: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{$lonhost}) eq 'HASH') {
4211: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
4212: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
4213: $gotspares = 1;
4214: }
4215: }
4216: }
4217: }
4218: }
4219: }
4220: }
4221: unless ($gotspares) {
4222: if ($lonhost eq $Apache::lonnet::perlvar{'lonHostID'}) {
4223: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
4224: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
4225: } else {
4226: my $server_hostname = &Apache::lonnet::hostname($lonhost);
4227: my $server_homeID = &Apache::lonnet::get_server_homeID($server_hostname);
4228: if ($server_homeID eq $Apache::lonnet::perlvar{'lonHostID'}) {
4229: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
4230: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
4231: } else {
1.150 raeburn 4232: my %what = (
4233: spareid => 1,
4234: );
4235: my ($result,$returnhash) =
4236: &Apache::lonnet::get_remote_globals($lonhost,\%what);
4237: if ($result eq 'ok') {
4238: if (ref($returnhash) eq 'HASH') {
4239: if (ref($returnhash->{'spareid'}) eq 'HASH') {
4240: $spareid{$lonhost}{'primary'} = $returnhash->{'spareid'}->{'primary'};
4241: $spareid{$lonhost}{'default'} = $returnhash->{'spareid'}->{'default'};
4242: }
4243: }
1.145 raeburn 4244: }
4245: }
4246: }
4247: }
4248: }
4249: }
4250: return %spareid;
4251: }
4252:
4253: sub spares_row {
1.261 raeburn 4254: my ($dom,$servers,$spareid,$serverhomes,$altids,$curroffloadnow,$rowtotal) = @_;
1.145 raeburn 4255: my $css_class;
4256: my $numinrow = 4;
4257: my $itemcount = 1;
4258: my $datatable;
1.152 raeburn 4259: my %typetitles = &sparestype_titles();
4260: if ((ref($servers) eq 'HASH') && (ref($spareid) eq 'HASH') && (ref($altids) eq 'HASH')) {
1.145 raeburn 4261: foreach my $server (sort(keys(%{$servers}))) {
1.152 raeburn 4262: my $serverhome = &Apache::lonnet::get_server_homeID($servers->{$server});
4263: my ($othercontrol,$serverdom);
4264: if ($serverhome ne $server) {
4265: $serverdom = &Apache::lonnet::host_domain($serverhome);
4266: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
4267: } else {
4268: $serverdom = &Apache::lonnet::host_domain($server);
4269: if ($serverdom ne $dom) {
4270: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
4271: }
4272: }
4273: next unless (ref($spareid->{$server}) eq 'HASH');
1.261 raeburn 4274: my $checkednow;
4275: if (ref($curroffloadnow) eq 'HASH') {
4276: if ($curroffloadnow->{$server}) {
4277: $checkednow = ' checked="checked"';
4278: }
4279: }
1.145 raeburn 4280: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
4281: $datatable .= '<tr'.$css_class.'>
4282: <td rowspan="2">
1.183 bisitz 4283: <span class="LC_nobreak">'.
4284: &mt('[_1] when busy, offloads to:'
1.261 raeburn 4285: ,'<b>'.$server.'</b>').'</span><br />'.
4286: '<span class="LC_nobreak">'."\n".
4287: '<label><input type="checkbox" name="offloadnow" value="'.$server.'"'.$checkednow.' />'.
4288: ' '.&mt('Switch active users on next access').'</label></span>'.
1.183 bisitz 4289: "\n";
1.145 raeburn 4290: my (%current,%canselect);
1.152 raeburn 4291: my @choices =
4292: &possible_newspares($server,$spareid->{$server},$serverhomes,$altids);
4293: foreach my $type ('primary','default') {
4294: if (ref($spareid->{$server}) eq 'HASH') {
1.145 raeburn 4295: if (ref($spareid->{$server}{$type}) eq 'ARRAY') {
4296: my @spares = @{$spareid->{$server}{$type}};
4297: if (@spares > 0) {
1.152 raeburn 4298: if ($othercontrol) {
4299: $current{$type} = join(', ',@spares);
4300: } else {
4301: $current{$type} .= '<table>';
4302: my $numspares = scalar(@spares);
4303: for (my $i=0; $i<@spares; $i++) {
4304: my $rem = $i%($numinrow);
4305: if ($rem == 0) {
4306: if ($i > 0) {
4307: $current{$type} .= '</tr>';
4308: }
4309: $current{$type} .= '<tr>';
1.145 raeburn 4310: }
1.152 raeburn 4311: $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'".');" /> '.
4312: $spareid->{$server}{$type}[$i].
4313: '</label></td>'."\n";
4314: }
4315: my $rem = @spares%($numinrow);
4316: my $colsleft = $numinrow - $rem;
4317: if ($colsleft > 1 ) {
4318: $current{$type} .= '<td colspan="'.$colsleft.
4319: '" class="LC_left_item">'.
4320: ' </td>';
4321: } elsif ($colsleft == 1) {
4322: $current{$type} .= '<td class="LC_left_item"> </td>'."\n";
1.145 raeburn 4323: }
1.152 raeburn 4324: $current{$type} .= '</tr></table>';
1.150 raeburn 4325: }
1.145 raeburn 4326: }
4327: }
4328: if ($current{$type} eq '') {
4329: $current{$type} = &mt('None specified');
4330: }
1.152 raeburn 4331: if ($othercontrol) {
4332: if ($type eq 'primary') {
4333: $canselect{$type} = $othercontrol;
4334: }
4335: } else {
4336: $canselect{$type} =
4337: &mt('Add new [_1]'.$type.'[_2]:','<i>','</i>').' '.
4338: '<select name="newspare_'.$type.'_'.$server.'" '.
4339: 'id="newspare_'.$type.'_'.$server.'" onchange="checkNewSpares('."'$server','$type'".');">'."\n".
4340: '<option value="" selected ="selected">'.&mt('Select').'</option>'."\n";
4341: if (@choices > 0) {
4342: foreach my $lonhost (@choices) {
4343: $canselect{$type} .= '<option value="'.$lonhost.'">'.$lonhost.'</option>'."\n";
4344: }
4345: }
4346: $canselect{$type} .= '</select>'."\n";
4347: }
4348: } else {
4349: $current{$type} = &mt('Could not be determined');
4350: if ($type eq 'primary') {
4351: $canselect{$type} = $othercontrol;
4352: }
1.145 raeburn 4353: }
1.152 raeburn 4354: if ($type eq 'default') {
4355: $datatable .= '<tr'.$css_class.'>';
4356: }
4357: $datatable .= '<td><i>'.$typetitles{$type}.'</i></td>'."\n".
4358: '<td>'.$current{$type}.'</td>'."\n".
4359: '<td>'.$canselect{$type}.'</td></tr>'."\n";
1.145 raeburn 4360: }
4361: $itemcount ++;
4362: }
4363: }
4364: $$rowtotal += $itemcount;
4365: return $datatable;
4366: }
4367:
1.152 raeburn 4368: sub possible_newspares {
4369: my ($server,$currspares,$serverhomes,$altids) = @_;
4370: my $serverhostname = &Apache::lonnet::hostname($server);
4371: my %excluded;
4372: if ($serverhostname ne '') {
4373: %excluded = (
4374: $serverhostname => 1,
4375: );
4376: }
4377: if (ref($currspares) eq 'HASH') {
4378: foreach my $type (keys(%{$currspares})) {
4379: if (ref($currspares->{$type}) eq 'ARRAY') {
4380: if (@{$currspares->{$type}} > 0) {
4381: foreach my $curr (@{$currspares->{$type}}) {
4382: my $hostname = &Apache::lonnet::hostname($curr);
4383: $excluded{$hostname} = 1;
4384: }
4385: }
4386: }
4387: }
4388: }
4389: my @choices;
4390: if ((ref($serverhomes) eq 'HASH') && (ref($altids) eq 'HASH')) {
4391: if (keys(%{$serverhomes}) > 1) {
4392: foreach my $name (sort(keys(%{$serverhomes}))) {
4393: unless ($excluded{$name}) {
4394: if (exists($altids->{$serverhomes->{$name}})) {
4395: push(@choices,$altids->{$serverhomes->{$name}});
4396: } else {
4397: push(@choices,$serverhomes->{$name});
1.145 raeburn 4398: }
4399: }
4400: }
4401: }
4402: }
1.152 raeburn 4403: return sort(@choices);
1.145 raeburn 4404: }
4405:
1.150 raeburn 4406: sub print_loadbalancing {
4407: my ($dom,$settings,$rowtotal) = @_;
4408: my $primary_id = &Apache::lonnet::domain($dom,'primary');
4409: my $intdom = &Apache::lonnet::internet_dom($primary_id);
4410: my $numinrow = 1;
4411: my $datatable;
4412: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.171 raeburn 4413: my (%currbalancer,%currtargets,%currrules,%existing);
4414: if (ref($settings) eq 'HASH') {
4415: %existing = %{$settings};
4416: }
4417: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
4418: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
4419: \%currtargets,\%currrules);
1.150 raeburn 4420: } else {
4421: return;
4422: }
4423: my ($othertitle,$usertypes,$types) =
4424: &Apache::loncommon::sorted_inst_types($dom);
1.209 raeburn 4425: my $rownum = 8;
1.150 raeburn 4426: if (ref($types) eq 'ARRAY') {
4427: $rownum += scalar(@{$types});
4428: }
1.171 raeburn 4429: my @css_class = ('LC_odd_row','LC_even_row');
4430: my $balnum = 0;
4431: my $islast;
4432: my (@toshow,$disabledtext);
4433: if (keys(%currbalancer) > 0) {
4434: @toshow = sort(keys(%currbalancer));
4435: if (scalar(@toshow) < scalar(keys(%servers)) + 1) {
4436: push(@toshow,'');
4437: }
4438: } else {
4439: @toshow = ('');
4440: $disabledtext = &mt('No existing load balancer');
4441: }
4442: foreach my $lonhost (@toshow) {
4443: if ($balnum == scalar(@toshow)-1) {
4444: $islast = 1;
4445: } else {
4446: $islast = 0;
4447: }
4448: my $cssidx = $balnum%2;
4449: my $targets_div_style = 'display: none';
4450: my $disabled_div_style = 'display: block';
4451: my $homedom_div_style = 'display: none';
4452: $datatable .= '<tr class="'.$css_class[$cssidx].'">'.
4453: '<td rowspan="'.$rownum.'" valign="top">'.
4454: '<p>';
4455: if ($lonhost eq '') {
1.210 raeburn 4456: $datatable .= '<span class="LC_nobreak">';
1.171 raeburn 4457: if (keys(%currbalancer) > 0) {
4458: $datatable .= &mt('Add balancer:');
4459: } else {
4460: $datatable .= &mt('Enable balancer:');
4461: }
4462: $datatable .= ' '.
4463: '<select name="loadbalancing_lonhost_'.$balnum.'"'.
4464: ' id="loadbalancing_lonhost_'.$balnum.'"'.
4465: ' onchange="toggleTargets('."'$balnum'".');">'."\n".
4466: '<option value="" selected="selected">'.&mt('None').
4467: '</option>'."\n";
4468: foreach my $server (sort(keys(%servers))) {
4469: next if ($currbalancer{$server});
4470: $datatable .= '<option value="'.$server.'">'.$server.'</option>'."\n";
4471: }
1.210 raeburn 4472: $datatable .=
1.171 raeburn 4473: '</select>'."\n".
4474: '<input type="hidden" name="loadbalancing_prevlonhost_'.$balnum.'" id="loadbalancing_prevlonhost_'.$balnum.'" value="" /> </span>'."\n";
4475: } else {
4476: $datatable .= '<i>'.$lonhost.'</i><br /><span class="LC_nobreak">'.
4477: '<label><input type="checkbox" name="loadbalancing_delete" value="'.$balnum.'" id="loadbalancing_delete_'.$balnum.'" onclick="javascript:balancerDeleteChange('."'$balnum'".');" /> '.
4478: &mt('Stop balancing').'</label>'.
4479: '<input type="hidden" name="loadbalancing_lonhost_'.$balnum.'" value="'.$lonhost.'" id="loadbalancing_lonhost_'.$balnum.'" /></span>';
4480: $targets_div_style = 'display: block';
4481: $disabled_div_style = 'display: none';
4482: if ($dom eq &Apache::lonnet::host_domain($lonhost)) {
4483: $homedom_div_style = 'display: block';
4484: }
4485: }
4486: $datatable .= '</p></td><td rowspan="'.$rownum.'" valign="top">'.
4487: '<div id="loadbalancing_disabled_'.$balnum.'" style="'.
4488: $disabled_div_style.'">'.$disabledtext.'</div>'."\n".
4489: '<div id="loadbalancing_targets_'.$balnum.'" style="'.$targets_div_style.'">'.&mt('Offloads to:').'<br />';
4490: my ($numspares,@spares) = &count_servers($lonhost,%servers);
4491: my @sparestypes = ('primary','default');
4492: my %typetitles = &sparestype_titles();
4493: foreach my $sparetype (@sparestypes) {
4494: my $targettable;
4495: for (my $i=0; $i<$numspares; $i++) {
4496: my $checked;
4497: if (ref($currtargets{$lonhost}) eq 'HASH') {
4498: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
4499: if (grep(/^\Q$spares[$i]\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
4500: $checked = ' checked="checked"';
4501: }
4502: }
4503: }
4504: my ($chkboxval,$disabled);
4505: if (($lonhost ne '') && (exists($servers{$lonhost}))) {
4506: $chkboxval = $spares[$i];
4507: }
4508: if (exists($currbalancer{$spares[$i]})) {
4509: $disabled = ' disabled="disabled"';
4510: }
1.210 raeburn 4511: $targettable .=
1.253 raeburn 4512: '<td><span class="LC_nobreak"><label>'.
4513: '<input type="checkbox" name="loadbalancing_target_'.$balnum.'_'.$sparetype.'"'.
1.171 raeburn 4514: $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 4515: '</span></label></span></td>';
1.171 raeburn 4516: my $rem = $i%($numinrow);
4517: if ($rem == 0) {
4518: if (($i > 0) && ($i < $numspares-1)) {
4519: $targettable .= '</tr>';
4520: }
4521: if ($i < $numspares-1) {
4522: $targettable .= '<tr>';
1.150 raeburn 4523: }
4524: }
4525: }
1.171 raeburn 4526: if ($targettable ne '') {
4527: my $rem = $numspares%($numinrow);
4528: my $colsleft = $numinrow - $rem;
4529: if ($colsleft > 1 ) {
4530: $targettable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
4531: ' </td>';
4532: } elsif ($colsleft == 1) {
4533: $targettable .= '<td class="LC_left_item"> </td>';
4534: }
4535: $datatable .= '<i>'.$typetitles{$sparetype}.'</i><br />'.
4536: '<table><tr>'.$targettable.'</tr></table><br />';
4537: }
4538: }
4539: $datatable .= '</div></td></tr>'.
4540: &loadbalancing_rules($dom,$intdom,$currrules{$lonhost},
4541: $othertitle,$usertypes,$types,\%servers,
4542: \%currbalancer,$lonhost,
4543: $targets_div_style,$homedom_div_style,
4544: $css_class[$cssidx],$balnum,$islast);
4545: $$rowtotal += $rownum;
4546: $balnum ++;
4547: }
4548: $datatable .= '<input type="hidden" name="loadbalancing_total" id="loadbalancing_total" value="'.$balnum.'" />';
4549: return $datatable;
4550: }
4551:
4552: sub get_loadbalancers_config {
4553: my ($servers,$existing,$currbalancer,$currtargets,$currrules) = @_;
4554: return unless ((ref($servers) eq 'HASH') &&
4555: (ref($existing) eq 'HASH') && (ref($currbalancer) eq 'HASH') &&
4556: (ref($currtargets) eq 'HASH') && (ref($currrules) eq 'HASH'));
4557: if (keys(%{$existing}) > 0) {
4558: my $oldlonhost;
4559: foreach my $key (sort(keys(%{$existing}))) {
4560: if ($key eq 'lonhost') {
4561: $oldlonhost = $existing->{'lonhost'};
4562: $currbalancer->{$oldlonhost} = 1;
4563: } elsif ($key eq 'targets') {
4564: if ($oldlonhost) {
4565: $currtargets->{$oldlonhost} = $existing->{'targets'};
4566: }
4567: } elsif ($key eq 'rules') {
4568: if ($oldlonhost) {
4569: $currrules->{$oldlonhost} = $existing->{'rules'};
4570: }
4571: } elsif (ref($existing->{$key}) eq 'HASH') {
4572: $currbalancer->{$key} = 1;
4573: $currtargets->{$key} = $existing->{$key}{'targets'};
4574: $currrules->{$key} = $existing->{$key}{'rules'};
1.150 raeburn 4575: }
4576: }
1.171 raeburn 4577: } else {
4578: my ($balancerref,$targetsref) =
4579: &Apache::lonnet::get_lonbalancer_config($servers);
4580: if ((ref($balancerref) eq 'HASH') && (ref($targetsref) eq 'HASH')) {
4581: foreach my $server (sort(keys(%{$balancerref}))) {
4582: $currbalancer->{$server} = 1;
4583: $currtargets->{$server} = $targetsref->{$server};
1.150 raeburn 4584: }
4585: }
4586: }
1.171 raeburn 4587: return;
1.150 raeburn 4588: }
4589:
4590: sub loadbalancing_rules {
4591: my ($dom,$intdom,$currrules,$othertitle,$usertypes,$types,$servers,
1.171 raeburn 4592: $currbalancer,$lonhost,$targets_div_style,$homedom_div_style,
4593: $css_class,$balnum,$islast) = @_;
1.150 raeburn 4594: my $output;
1.171 raeburn 4595: my $num = 0;
1.210 raeburn 4596: my ($alltypes,$othertypes,$titles) =
1.150 raeburn 4597: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
4598: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
4599: foreach my $type (@{$alltypes}) {
1.171 raeburn 4600: $num ++;
1.150 raeburn 4601: my $current;
4602: if (ref($currrules) eq 'HASH') {
4603: $current = $currrules->{$type};
4604: }
1.253 raeburn 4605: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.171 raeburn 4606: if ($dom ne &Apache::lonnet::host_domain($lonhost)) {
1.150 raeburn 4607: $current = '';
4608: }
4609: }
4610: $output .= &loadbalance_rule_row($type,$titles->{$type},$current,
1.171 raeburn 4611: $servers,$currbalancer,$lonhost,$dom,
4612: $targets_div_style,$homedom_div_style,
4613: $css_class,$balnum,$num,$islast);
1.150 raeburn 4614: }
4615: }
4616: return $output;
4617: }
4618:
4619: sub loadbalancing_titles {
4620: my ($dom,$intdom,$usertypes,$types) = @_;
4621: my %othertypes = (
4622: '_LC_adv' => &mt('Advanced users from [_1]',$dom),
4623: '_LC_author' => &mt('Users from [_1] with author role',$dom),
4624: '_LC_internetdom' => &mt('Users not from [_1], but from [_2]',$dom,$intdom),
4625: '_LC_external' => &mt('Users not from [_1]',$intdom),
1.209 raeburn 4626: '_LC_ipchangesso' => &mt('SSO users from [_1], with IP mismatch',$dom),
4627: '_LC_ipchange' => &mt('Non-SSO users with IP mismatch'),
1.150 raeburn 4628: );
1.209 raeburn 4629: my @alltypes = ('_LC_adv','_LC_author','_LC_internetdom','_LC_external','_LC_ipchangesso','_LC_ipchange');
1.150 raeburn 4630: if (ref($types) eq 'ARRAY') {
4631: unshift(@alltypes,@{$types},'default');
4632: }
4633: my %titles;
4634: foreach my $type (@alltypes) {
4635: if ($type =~ /^_LC_/) {
4636: $titles{$type} = $othertypes{$type};
4637: } elsif ($type eq 'default') {
4638: $titles{$type} = &mt('All users from [_1]',$dom);
4639: if (ref($types) eq 'ARRAY') {
4640: if (@{$types} > 0) {
4641: $titles{$type} = &mt('Other users from [_1]',$dom);
4642: }
4643: }
4644: } elsif (ref($usertypes) eq 'HASH') {
4645: $titles{$type} = $usertypes->{$type};
4646: }
4647: }
4648: return (\@alltypes,\%othertypes,\%titles);
4649: }
4650:
4651: sub loadbalance_rule_row {
1.171 raeburn 4652: my ($type,$title,$current,$servers,$currbalancer,$lonhost,$dom,
4653: $targets_div_style,$homedom_div_style,$css_class,$balnum,$num,$islast) = @_;
1.209 raeburn 4654: my @rulenames;
1.150 raeburn 4655: my %ruletitles = &offloadtype_text();
1.209 raeburn 4656: if (($type eq '_LC_ipchangesso') || ($type eq '_LC_ipchange')) {
1.254 raeburn 4657: @rulenames = ('balancer','offloadedto','specific');
1.150 raeburn 4658: } else {
1.209 raeburn 4659: @rulenames = ('default','homeserver');
4660: if ($type eq '_LC_external') {
4661: push(@rulenames,'externalbalancer');
4662: } else {
4663: push(@rulenames,'specific');
4664: }
4665: push(@rulenames,'none');
1.150 raeburn 4666: }
4667: my $style = $targets_div_style;
1.253 raeburn 4668: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.150 raeburn 4669: $style = $homedom_div_style;
4670: }
1.171 raeburn 4671: my $space;
4672: if ($islast && $num == 1) {
4673: $space = '<div display="inline-block"> </div>';
4674: }
1.210 raeburn 4675: my $output =
1.171 raeburn 4676: '<tr class="'.$css_class.'" id="balanceruletr_'.$balnum.'_'.$num.'"><td valign="top">'.$space.
4677: '<div id="balanceruletitle_'.$balnum.'_'.$type.'" style="'.$style.'">'.$title.'</div></td>'."\n".
4678: '<td valaign="top">'.$space.
4679: '<div id="balancerule_'.$balnum.'_'.$type.'" style="'.$style.'">'."\n";
1.150 raeburn 4680: for (my $i=0; $i<@rulenames; $i++) {
4681: my $rule = $rulenames[$i];
4682: my ($checked,$extra);
4683: if ($rulenames[$i] eq 'default') {
4684: $rule = '';
4685: }
4686: if ($rulenames[$i] eq 'specific') {
4687: if (ref($servers) eq 'HASH') {
4688: my $default;
4689: if (($current ne '') && (exists($servers->{$current}))) {
4690: $checked = ' checked="checked"';
4691: }
4692: unless ($checked) {
4693: $default = ' selected="selected"';
4694: }
1.210 raeburn 4695: $extra =
1.171 raeburn 4696: ': <select name="loadbalancing_singleserver_'.$balnum.'_'.$type.
4697: '" id="loadbalancing_singleserver_'.$balnum.'_'.$type.
4698: '" onchange="singleServerToggle('."'$balnum','$type'".')">'."\n".
4699: '<option value=""'.$default.'></option>'."\n";
4700: foreach my $server (sort(keys(%{$servers}))) {
4701: if (ref($currbalancer) eq 'HASH') {
4702: next if (exists($currbalancer->{$server}));
4703: }
1.150 raeburn 4704: my $selected;
1.171 raeburn 4705: if ($server eq $current) {
1.150 raeburn 4706: $selected = ' selected="selected"';
4707: }
1.171 raeburn 4708: $extra .= '<option value="'.$server.'"'.$selected.'>'.$server.'</option>';
1.150 raeburn 4709: }
4710: $extra .= '</select>';
4711: }
4712: } elsif ($rule eq $current) {
4713: $checked = ' checked="checked"';
4714: }
4715: $output .= '<span class="LC_nobreak"><label>'.
1.171 raeburn 4716: '<input type="radio" name="loadbalancing_rules_'.$balnum.'_'.$type.
4717: '" id="loadbalancing_rules_'.$balnum.'_'.$type.'_'.$i.'" value="'.
4718: $rule.'" onclick="balanceruleChange('."this.form,'$balnum','$type'".
1.254 raeburn 4719: ')"'.$checked.' /> ';
4720: if (($rulenames[$i] eq 'specific') && ($type =~ /^_LC_ipchange/)) {
4721: $output .= $ruletitles{'particular'};
4722: } else {
4723: $output .= $ruletitles{$rulenames[$i]};
4724: }
4725: $output .= '</label>'.$extra.'</span><br />'."\n";
1.150 raeburn 4726: }
4727: $output .= '</div></td></tr>'."\n";
4728: return $output;
4729: }
4730:
4731: sub offloadtype_text {
4732: my %ruletitles = &Apache::lonlocal::texthash (
4733: 'default' => 'Offloads to default destinations',
4734: 'homeserver' => "Offloads to user's home server",
4735: 'externalbalancer' => "Offloads to Load Balancer in user's domain",
4736: 'specific' => 'Offloads to specific server',
1.161 raeburn 4737: 'none' => 'No offload',
1.209 raeburn 4738: 'balancer' => 'Session hosted on Load Balancer, after re-authentication',
4739: 'offloadedto' => 'Session hosted on offload server, after re-authentication',
1.254 raeburn 4740: 'particular' => 'Session hosted (after re-auth) on server:',
1.150 raeburn 4741: );
4742: return %ruletitles;
4743: }
4744:
4745: sub sparestype_titles {
4746: my %typestitles = &Apache::lonlocal::texthash (
4747: 'primary' => 'primary',
4748: 'default' => 'default',
4749: );
4750: return %typestitles;
4751: }
4752:
1.28 raeburn 4753: sub contact_titles {
4754: my %titles = &Apache::lonlocal::texthash (
4755: 'supportemail' => 'Support E-mail address',
1.69 raeburn 4756: 'adminemail' => 'Default Server Admin E-mail address',
1.28 raeburn 4757: 'errormail' => 'Error reports to be e-mailed to',
4758: 'packagesmail' => 'Package update alerts to be e-mailed to',
1.89 raeburn 4759: 'helpdeskmail' => 'Helpdesk requests to be e-mailed to',
4760: 'lonstatusmail' => 'E-mail from nightly status check (warnings/errors)',
1.102 raeburn 4761: 'requestsmail' => 'E-mail from course requests requiring approval',
1.190 raeburn 4762: 'updatesmail' => 'E-mail from nightly check of LON-CAPA module integrity/updates',
1.203 raeburn 4763: 'idconflictsmail' => 'E-mail from bi-nightly check for multiple users sharing same student/employee ID',
1.28 raeburn 4764: );
4765: my %short_titles = &Apache::lonlocal::texthash (
4766: adminemail => 'Admin E-mail address',
4767: supportemail => 'Support E-mail',
4768: );
4769: return (\%titles,\%short_titles);
4770: }
4771:
1.72 raeburn 4772: sub tool_titles {
4773: my %titles = &Apache::lonlocal::texthash (
1.162 raeburn 4774: aboutme => 'Personal web page',
1.86 raeburn 4775: blog => 'Blog',
1.162 raeburn 4776: webdav => 'WebDAV',
1.86 raeburn 4777: portfolio => 'Portfolio',
1.88 bisitz 4778: official => 'Official courses (with institutional codes)',
4779: unofficial => 'Unofficial courses',
1.98 raeburn 4780: community => 'Communities',
1.216 raeburn 4781: textbook => 'Textbook courses',
1.271 raeburn 4782: placement => 'Placement tests',
1.86 raeburn 4783: );
1.72 raeburn 4784: return %titles;
4785: }
4786:
1.101 raeburn 4787: sub courserequest_titles {
4788: my %titles = &Apache::lonlocal::texthash (
4789: official => 'Official',
4790: unofficial => 'Unofficial',
4791: community => 'Communities',
1.216 raeburn 4792: textbook => 'Textbook',
1.271 raeburn 4793: placement => 'Placement tests',
1.101 raeburn 4794: norequest => 'Not allowed',
1.104 raeburn 4795: approval => 'Approval by Dom. Coord.',
1.101 raeburn 4796: validate => 'With validation',
4797: autolimit => 'Numerical limit',
1.103 raeburn 4798: unlimited => '(blank for unlimited)',
1.101 raeburn 4799: );
4800: return %titles;
4801: }
4802:
1.163 raeburn 4803: sub authorrequest_titles {
4804: my %titles = &Apache::lonlocal::texthash (
4805: norequest => 'Not allowed',
4806: approval => 'Approval by Dom. Coord.',
4807: automatic => 'Automatic approval',
4808: );
4809: return %titles;
1.210 raeburn 4810: }
1.163 raeburn 4811:
1.101 raeburn 4812: sub courserequest_conditions {
4813: my %conditions = &Apache::lonlocal::texthash (
1.104 raeburn 4814: approval => '(Processing of request subject to approval by Domain Coordinator).',
1.193 bisitz 4815: validate => '(Processing of request subject to institutional validation).',
1.101 raeburn 4816: );
4817: return %conditions;
4818: }
4819:
4820:
1.27 raeburn 4821: sub print_usercreation {
1.30 raeburn 4822: my ($position,$dom,$settings,$rowtotal) = @_;
1.27 raeburn 4823: my $numinrow = 4;
1.28 raeburn 4824: my $datatable;
4825: if ($position eq 'top') {
1.30 raeburn 4826: $$rowtotal ++;
1.34 raeburn 4827: my $rowcount = 0;
1.32 raeburn 4828: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username');
1.28 raeburn 4829: if (ref($rules) eq 'HASH') {
4830: if (keys(%{$rules}) > 0) {
1.32 raeburn 4831: $datatable .= &user_formats_row('username',$settings,$rules,
4832: $ruleorder,$numinrow,$rowcount);
1.30 raeburn 4833: $$rowtotal ++;
1.32 raeburn 4834: $rowcount ++;
4835: }
4836: }
4837: my ($idrules,$idruleorder) = &Apache::lonnet::inst_userrules($dom,'id');
4838: if (ref($idrules) eq 'HASH') {
4839: if (keys(%{$idrules}) > 0) {
4840: $datatable .= &user_formats_row('id',$settings,$idrules,
4841: $idruleorder,$numinrow,$rowcount);
4842: $$rowtotal ++;
4843: $rowcount ++;
1.28 raeburn 4844: }
4845: }
1.39 raeburn 4846: if ($rowcount == 0) {
4847: $datatable .= '<tr><td colspan="2">'.&mt('No format rules have been defined for usernames or IDs in this domain.').'</td></tr>';
4848: $$rowtotal ++;
4849: $rowcount ++;
4850: }
1.34 raeburn 4851: } elsif ($position eq 'middle') {
1.224 raeburn 4852: my @creators = ('author','course','requestcrs');
1.37 raeburn 4853: my ($rules,$ruleorder) =
4854: &Apache::lonnet::inst_userrules($dom,'username');
1.34 raeburn 4855: my %lt = &usercreation_types();
4856: my %checked;
4857: if (ref($settings) eq 'HASH') {
4858: if (ref($settings->{'cancreate'}) eq 'HASH') {
4859: foreach my $item (@creators) {
4860: $checked{$item} = $settings->{'cancreate'}{$item};
4861: }
4862: } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {
4863: foreach my $item (@creators) {
4864: if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {
4865: $checked{$item} = 'none';
4866: }
4867: }
4868: }
4869: }
4870: my $rownum = 0;
4871: foreach my $item (@creators) {
4872: $rownum ++;
1.224 raeburn 4873: if ($checked{$item} eq '') {
4874: $checked{$item} = 'any';
1.34 raeburn 4875: }
4876: my $css_class;
4877: if ($rownum%2) {
4878: $css_class = '';
4879: } else {
4880: $css_class = ' class="LC_odd_row" ';
4881: }
4882: $datatable .= '<tr'.$css_class.'>'.
4883: '<td><span class="LC_nobreak">'.$lt{$item}.
4884: '</span></td><td align="right">';
1.224 raeburn 4885: my @options = ('any');
4886: if (ref($rules) eq 'HASH') {
4887: if (keys(%{$rules}) > 0) {
4888: push(@options,('official','unofficial'));
1.37 raeburn 4889: }
4890: }
1.224 raeburn 4891: push(@options,'none');
1.37 raeburn 4892: foreach my $option (@options) {
1.50 raeburn 4893: my $type = 'radio';
1.34 raeburn 4894: my $check = ' ';
1.224 raeburn 4895: if ($checked{$item} eq $option) {
4896: $check = ' checked="checked" ';
1.34 raeburn 4897: }
4898: $datatable .= '<span class="LC_nobreak"><label>'.
1.50 raeburn 4899: '<input type="'.$type.'" name="can_createuser_'.
1.34 raeburn 4900: $item.'" value="'.$option.'"'.$check.'/> '.
4901: $lt{$option}.'</label> </span>';
4902: }
4903: $datatable .= '</td></tr>';
4904: }
1.28 raeburn 4905: } else {
4906: my @contexts = ('author','course','domain');
4907: my @authtypes = ('int','krb4','krb5','loc');
4908: my %checked;
4909: if (ref($settings) eq 'HASH') {
4910: if (ref($settings->{'authtypes'}) eq 'HASH') {
4911: foreach my $item (@contexts) {
4912: if (ref($settings->{'authtypes'}{$item}) eq 'HASH') {
4913: foreach my $auth (@authtypes) {
4914: if ($settings->{'authtypes'}{$item}{$auth}) {
4915: $checked{$item}{$auth} = ' checked="checked" ';
4916: }
4917: }
4918: }
4919: }
1.27 raeburn 4920: }
1.35 raeburn 4921: } else {
4922: foreach my $item (@contexts) {
1.36 raeburn 4923: foreach my $auth (@authtypes) {
1.35 raeburn 4924: $checked{$item}{$auth} = ' checked="checked" ';
4925: }
4926: }
1.27 raeburn 4927: }
1.28 raeburn 4928: my %title = &context_names();
4929: my %authname = &authtype_names();
4930: my $rownum = 0;
4931: my $css_class;
4932: foreach my $item (@contexts) {
4933: if ($rownum%2) {
4934: $css_class = '';
4935: } else {
4936: $css_class = ' class="LC_odd_row" ';
4937: }
1.30 raeburn 4938: $datatable .= '<tr'.$css_class.'>'.
1.28 raeburn 4939: '<td>'.$title{$item}.
4940: '</td><td class="LC_left_item">'.
4941: '<span class="LC_nobreak">';
4942: foreach my $auth (@authtypes) {
4943: $datatable .= '<label>'.
4944: '<input type="checkbox" name="'.$item.'_auth" '.
4945: $checked{$item}{$auth}.' value="'.$auth.'" />'.
4946: $authname{$auth}.'</label> ';
4947: }
4948: $datatable .= '</span></td></tr>';
4949: $rownum ++;
1.27 raeburn 4950: }
1.30 raeburn 4951: $$rowtotal += $rownum;
1.27 raeburn 4952: }
4953: return $datatable;
4954: }
4955:
1.224 raeburn 4956: sub print_selfcreation {
4957: my ($position,$dom,$settings,$rowtotal) = @_;
1.236 raeburn 4958: my (@selfcreate,$createsettings,$processing,$datatable);
1.224 raeburn 4959: if (ref($settings) eq 'HASH') {
4960: if (ref($settings->{'cancreate'}) eq 'HASH') {
4961: $createsettings = $settings->{'cancreate'};
1.236 raeburn 4962: if (ref($createsettings) eq 'HASH') {
4963: if (ref($createsettings->{'selfcreate'}) eq 'ARRAY') {
4964: @selfcreate = @{$createsettings->{'selfcreate'}};
4965: } elsif ($createsettings->{'selfcreate'} ne '') {
4966: if ($settings->{'cancreate'}{'selfcreate'} eq 'any') {
4967: @selfcreate = ('email','login','sso');
4968: } elsif ($createsettings->{'selfcreate'} ne 'none') {
4969: @selfcreate = ($createsettings->{'selfcreate'});
4970: }
4971: }
4972: if (ref($createsettings->{'selfcreateprocessing'}) eq 'HASH') {
4973: $processing = $createsettings->{'selfcreateprocessing'};
1.224 raeburn 4974: }
4975: }
4976: }
4977: }
4978: my %radiohash;
4979: my $numinrow = 4;
4980: map { $radiohash{'cancreate_'.$_} = 1; } @selfcreate;
4981: if ($position eq 'top') {
4982: my %choices = &Apache::lonlocal::texthash (
4983: cancreate_login => 'Institutional Login',
4984: cancreate_sso => 'Institutional Single Sign On',
4985: );
4986: my @toggles = sort(keys(%choices));
4987: my %defaultchecked = (
4988: 'cancreate_login' => 'off',
4989: 'cancreate_sso' => 'off',
4990: );
1.228 raeburn 4991: my ($onclick,$itemcount);
1.224 raeburn 4992: ($datatable,$itemcount) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
4993: \%choices,$itemcount,$onclick);
1.228 raeburn 4994: $$rowtotal += $itemcount;
4995:
1.224 raeburn 4996: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
4997:
4998: if (ref($usertypes) eq 'HASH') {
4999: if (keys(%{$usertypes}) > 0) {
5000: $datatable .= &insttypes_row($createsettings,$types,$usertypes,
5001: $dom,$numinrow,$othertitle,
1.228 raeburn 5002: 'statustocreate',$$rowtotal);
1.224 raeburn 5003: $$rowtotal ++;
5004: }
5005: }
1.240 raeburn 5006: my @fields = ('lastname','firstname','middlename','permanentemail','id','inststatus');
5007: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
5008: $fieldtitles{'inststatus'} = &mt('Institutional status');
5009: my $rem;
5010: my $numperrow = 2;
5011: my $css_class = $$rowtotal%2?' class="LC_odd_row"':'';
5012: $datatable .= '<tr'.$css_class.'>'.
1.241 raeburn 5013: '<td class="LC_left_item">'.&mt('Mapping of Shibboleth environment variable names to user data fields (SSO auth)').'</td>'.
1.240 raeburn 5014: '<td class="LC_left_item">'."\n".
5015: '<table><tr><td>'."\n";
5016: for (my $i=0; $i<@fields; $i++) {
5017: $rem = $i%($numperrow);
5018: if ($rem == 0) {
5019: if ($i > 0) {
5020: $datatable .= '</tr>';
5021: }
5022: $datatable .= '<tr>';
5023: }
5024: my $currval;
1.248 raeburn 5025: if (ref($createsettings) eq 'HASH') {
5026: if (ref($createsettings->{'shibenv'}) eq 'HASH') {
5027: $currval = $createsettings->{'shibenv'}{$fields[$i]};
5028: }
1.240 raeburn 5029: }
5030: $datatable .= '<td class="LC_left_item">'.
5031: '<span class="LC_nobreak">'.
5032: '<input type="text" name="shibenv_'.$fields[$i].'" '.
5033: 'value="'.$currval.'" size="10" /> '.
5034: $fieldtitles{$fields[$i]}.'</span></td>';
5035: }
5036: my $colsleft = $numperrow - $rem;
5037: if ($colsleft > 1 ) {
5038: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
5039: ' </td>';
5040: } elsif ($colsleft == 1) {
5041: $datatable .= '<td class="LC_left_item"> </td>';
5042: }
5043: $datatable .= '</tr></table></td></tr>';
5044: $$rowtotal ++;
1.224 raeburn 5045: } elsif ($position eq 'middle') {
5046: my %domconf = &Apache::lonnet::get_dom('configuration',['usermodification'],$dom);
5047: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
5048: $usertypes->{'default'} = $othertitle;
5049: if (ref($types) eq 'ARRAY') {
5050: push(@{$types},'default');
5051: $usertypes->{'default'} = $othertitle;
5052: foreach my $status (@{$types}) {
5053: $datatable .= &modifiable_userdata_row('selfcreate',$status,$domconf{'usermodification'},
1.228 raeburn 5054: $numinrow,$$rowtotal,$usertypes);
1.240 raeburn 5055: $$rowtotal ++;
1.224 raeburn 5056: }
5057: }
5058: } else {
1.236 raeburn 5059: my %choices = &Apache::lonlocal::texthash (
5060: cancreate_email => 'E-mail address as username',
5061: );
5062: my @toggles = sort(keys(%choices));
5063: my %defaultchecked = (
5064: 'cancreate_email' => 'off',
5065: );
5066: my $itemcount = 0;
5067: my $display = 'none';
5068: if (grep(/^\Qemail\E$/,@selfcreate)) {
5069: $display = 'block';
5070: }
5071: my $onclick = "toggleDisplay(this.form,'emailoptions');";
5072: my $additional = '<div id="emailoptions" style="display: '.$display.'">';
5073: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
5074: my $usertypes = {};
5075: my $order = [];
5076: if ((ref($domdefaults{'inststatustypes'}) eq 'HASH') && (ref($domdefaults{'inststatusguest'}) eq 'ARRAY')) {
5077: $usertypes = $domdefaults{'inststatustypes'};
5078: $order = $domdefaults{'inststatusguest'};
5079: }
5080: if (ref($order) eq 'ARRAY') {
5081: push(@{$order},'default');
5082: if (@{$order} > 1) {
5083: $usertypes->{'default'} = &mt('Other users');
5084: $additional .= '<table><tr>';
5085: foreach my $status (@{$order}) {
5086: $additional .= '<th>'.$usertypes->{$status}.'</th>';
5087: }
5088: $additional .= '</tr><tr>';
5089: foreach my $status (@{$order}) {
5090: $additional .= '<td>'.&email_as_username($rowtotal,$processing,$status).'</td>';
1.224 raeburn 5091: }
1.236 raeburn 5092: $additional .= '</tr></table>';
1.224 raeburn 5093: } else {
1.236 raeburn 5094: $usertypes->{'default'} = &mt('All users');
5095: $additional .= &email_as_username($rowtotal,$processing);
1.224 raeburn 5096: }
5097: }
1.236 raeburn 5098: $additional .= '</div>'."\n";
5099:
5100: ($datatable,$itemcount) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
1.240 raeburn 5101: \%choices,$$rowtotal,$onclick,$additional);
5102: $$rowtotal ++;
1.236 raeburn 5103: $datatable .= &print_requestmail($dom,'selfcreation',$createsettings,$rowtotal);
1.228 raeburn 5104: $$rowtotal ++;
1.224 raeburn 5105: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
1.228 raeburn 5106: $numinrow = 1;
1.236 raeburn 5107: if (ref($order) eq 'ARRAY') {
5108: foreach my $status (@{$order}) {
1.228 raeburn 5109: $datatable .= &modifiable_userdata_row('cancreate','emailusername_'.$status,$settings,
5110: $numinrow,$$rowtotal,$usertypes,$infofields,$infotitles);
5111: $$rowtotal ++;
5112: }
5113: }
1.224 raeburn 5114: my ($emailrules,$emailruleorder) =
5115: &Apache::lonnet::inst_userrules($dom,'email');
5116: if (ref($emailrules) eq 'HASH') {
5117: if (keys(%{$emailrules}) > 0) {
5118: $datatable .= &user_formats_row('email',$settings,$emailrules,
1.228 raeburn 5119: $emailruleorder,$numinrow,$$rowtotal);
1.224 raeburn 5120: $$rowtotal ++;
5121: }
5122: }
1.228 raeburn 5123: $datatable .= &captcha_choice('cancreate',$createsettings,$$rowtotal);
1.224 raeburn 5124: }
5125: return $datatable;
5126: }
5127:
1.236 raeburn 5128: sub email_as_username {
5129: my ($rowtotal,$processing,$type) = @_;
5130: my %choices =
5131: &Apache::lonlocal::texthash (
5132: automatic => 'Automatic approval',
5133: approval => 'Queued for approval',
5134: );
5135: my $output;
5136: foreach my $option ('automatic','approval') {
5137: my $checked;
5138: if (ref($processing) eq 'HASH') {
5139: if ($type eq '') {
5140: if (!exists($processing->{'default'})) {
5141: if ($option eq 'automatic') {
5142: $checked = ' checked="checked"';
5143: }
5144: } else {
5145: if ($processing->{'default'} eq $option) {
5146: $checked = ' checked="checked"';
5147: }
5148: }
5149: } else {
5150: if (!exists($processing->{$type})) {
5151: if ($option eq 'automatic') {
5152: $checked = ' checked="checked"';
5153: }
5154: } else {
5155: if ($processing->{$type} eq $option) {
5156: $checked = ' checked="checked"';
5157: }
5158: }
5159: }
5160: } elsif ($option eq 'automatic') {
5161: $checked = ' checked="checked"';
5162: }
5163: my $name = 'cancreate_emailprocess';
5164: if (($type ne '') && ($type ne 'default')) {
5165: $name .= '_'.$type;
5166: }
5167: $output .= '<span class="LC_nobreak"><label>'.
5168: '<input type="radio" name="'.$name.'"'.
5169: $checked.' value="'.$option.'" />'.
5170: $choices{$option}.'</label></span>';
5171: if ($type eq '') {
5172: $output .= ' ';
5173: } else {
5174: $output .= '<br />';
5175: }
5176: }
5177: $$rowtotal ++;
5178: return $output;
5179: }
5180:
1.165 raeburn 5181: sub captcha_choice {
1.169 raeburn 5182: my ($context,$settings,$itemcount) = @_;
1.269 raeburn 5183: my ($keyentry,$currpub,$currpriv,%checked,$rowname,$pubtext,$privtext,
5184: $vertext,$currver);
1.165 raeburn 5185: my %lt = &captcha_phrases();
5186: $keyentry = 'hidden';
5187: if ($context eq 'cancreate') {
1.224 raeburn 5188: $rowname = &mt('CAPTCHA validation');
1.169 raeburn 5189: } elsif ($context eq 'login') {
5190: $rowname = &mt('"Contact helpdesk" CAPTCHA validation');
1.165 raeburn 5191: }
5192: if (ref($settings) eq 'HASH') {
5193: if ($settings->{'captcha'}) {
5194: $checked{$settings->{'captcha'}} = ' checked="checked"';
5195: } else {
5196: $checked{'original'} = ' checked="checked"';
5197: }
5198: if ($settings->{'captcha'} eq 'recaptcha') {
5199: $pubtext = $lt{'pub'};
5200: $privtext = $lt{'priv'};
5201: $keyentry = 'text';
1.269 raeburn 5202: $vertext = $lt{'ver'};
5203: $currver = $settings->{'recaptchaversion'};
5204: if ($currver ne '2') {
5205: $currver = 1;
5206: }
1.165 raeburn 5207: }
5208: if (ref($settings->{'recaptchakeys'}) eq 'HASH') {
5209: $currpub = $settings->{'recaptchakeys'}{'public'};
5210: $currpriv = $settings->{'recaptchakeys'}{'private'};
5211: }
5212: } else {
5213: $checked{'original'} = ' checked="checked"';
5214: }
1.169 raeburn 5215: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
5216: my $output = '<tr'.$css_class.'>'.
5217: '<td class="LC_left_item">'.$rowname.'</td><td class="LC_left_item" colspan="2">'."\n".
1.165 raeburn 5218: '<table><tr><td>'."\n";
5219: foreach my $option ('original','recaptcha','notused') {
5220: $output .= '<span class="LC_nobreak"><label><input type="radio" name="'.$context.'_captcha" value="'.
5221: $option.'" '.$checked{$option}.' onchange="javascript:updateCaptcha('."this,'$context'".');" />'.
5222: $lt{$option}.'</label></span>';
5223: unless ($option eq 'notused') {
5224: $output .= (' 'x2)."\n";
5225: }
5226: }
5227: #
5228: # Note: If reCAPTCHA is to be used for LON-CAPA servers in a domain, a domain coordinator should visit:
5229: # https://www.google.com/recaptcha and generate a Public and Private key. For domains with multiple
1.210 raeburn 5230: # servers a single key pair will be used for all servers, so the internet domain (e.g., yourcollege.edu)
1.165 raeburn 5231: # specified for use with the key should be broad enough to accommodate all servers in the LON-CAPA domain.
1.210 raeburn 5232: #
1.165 raeburn 5233: $output .= '</td></tr>'."\n".
5234: '<tr><td>'."\n".
5235: '<span class="LC_nobreak"><span id="'.$context.'_recaptchapubtxt">'.$pubtext.'</span> '."\n".
5236: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapub" name="'.$context.'_recaptchapub" value="'.
5237: $currpub.'" size="40" /></span><br />'."\n".
5238: '<span class="LC_nobreak"><span id="'.$context.'_recaptchaprivtxt">'.$privtext.'</span> '."\n".
5239: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapriv" name="'.$context.'_recaptchapriv" value="'.
1.269 raeburn 5240: $currpriv.'" size="40" /></span><br />'.
5241: '<span class="LC_nobreak"><span id="'.$context.'_recaptchavertxt">'.$vertext.'</span> '."\n".
5242: '<input type="'.$keyentry.'" id="'.$context.'_recaptchaversion" name="'.$context.'_recaptchaversion" value="'.
5243: $currver.'" size="3" /></span><br />'.
5244: '</td></tr></table>'."\n".
1.165 raeburn 5245: '</td></tr>';
5246: return $output;
5247: }
5248:
1.32 raeburn 5249: sub user_formats_row {
5250: my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount) = @_;
5251: my $output;
5252: my %text = (
5253: 'username' => 'new usernames',
5254: 'id' => 'IDs',
1.45 raeburn 5255: 'email' => 'self-created accounts (e-mail)',
1.32 raeburn 5256: );
5257: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
5258: $output = '<tr '.$css_class.'>'.
1.63 raeburn 5259: '<td><span class="LC_nobreak">';
5260: if ($type eq 'email') {
5261: $output .= &mt("Formats disallowed for $text{$type}: ");
5262: } else {
5263: $output .= &mt("Format rules to check for $text{$type}: ");
5264: }
5265: $output .= '</span></td>'.
5266: '<td class="LC_left_item" colspan="2"><table>';
1.27 raeburn 5267: my $rem;
5268: if (ref($ruleorder) eq 'ARRAY') {
5269: for (my $i=0; $i<@{$ruleorder}; $i++) {
5270: if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
5271: my $rem = $i%($numinrow);
5272: if ($rem == 0) {
5273: if ($i > 0) {
5274: $output .= '</tr>';
5275: }
5276: $output .= '<tr>';
5277: }
5278: my $check = ' ';
1.39 raeburn 5279: if (ref($settings) eq 'HASH') {
5280: if (ref($settings->{$type.'_rule'}) eq 'ARRAY') {
5281: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) {
5282: $check = ' checked="checked" ';
5283: }
1.27 raeburn 5284: }
5285: }
5286: $output .= '<td class="LC_left_item">'.
5287: '<span class="LC_nobreak"><label>'.
1.32 raeburn 5288: '<input type="checkbox" name="'.$type.'_rule" '.
1.27 raeburn 5289: 'value="'.$ruleorder->[$i].'"'.$check.'/>'.
5290: $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
5291: }
5292: }
5293: $rem = @{$ruleorder}%($numinrow);
5294: }
5295: my $colsleft = $numinrow - $rem;
5296: if ($colsleft > 1 ) {
5297: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
5298: ' </td>';
5299: } elsif ($colsleft == 1) {
5300: $output .= '<td class="LC_left_item"> </td>';
5301: }
5302: $output .= '</tr></table></td></tr>';
5303: return $output;
5304: }
5305:
1.34 raeburn 5306: sub usercreation_types {
5307: my %lt = &Apache::lonlocal::texthash (
5308: author => 'When adding a co-author',
5309: course => 'When adding a user to a course',
1.100 raeburn 5310: requestcrs => 'When requesting a course',
1.34 raeburn 5311: any => 'Any',
5312: official => 'Institutional only ',
5313: unofficial => 'Non-institutional only',
5314: none => 'None',
5315: );
5316: return %lt;
1.48 raeburn 5317: }
1.34 raeburn 5318:
1.224 raeburn 5319: sub selfcreation_types {
5320: my %lt = &Apache::lonlocal::texthash (
5321: selfcreate => 'User creates own account',
5322: any => 'Any',
5323: official => 'Institutional only ',
5324: unofficial => 'Non-institutional only',
5325: email => 'E-mail address',
5326: login => 'Institutional Login',
5327: sso => 'SSO',
5328: );
5329: }
5330:
1.28 raeburn 5331: sub authtype_names {
5332: my %lt = &Apache::lonlocal::texthash(
5333: int => 'Internal',
5334: krb4 => 'Kerberos 4',
5335: krb5 => 'Kerberos 5',
5336: loc => 'Local',
5337: );
5338: return %lt;
5339: }
5340:
5341: sub context_names {
5342: my %context_title = &Apache::lonlocal::texthash(
5343: author => 'Creating users when an Author',
5344: course => 'Creating users when in a course',
5345: domain => 'Creating users when a Domain Coordinator',
5346: );
5347: return %context_title;
5348: }
5349:
1.33 raeburn 5350: sub print_usermodification {
5351: my ($position,$dom,$settings,$rowtotal) = @_;
5352: my $numinrow = 4;
5353: my ($context,$datatable,$rowcount);
5354: if ($position eq 'top') {
5355: $rowcount = 0;
5356: $context = 'author';
5357: foreach my $role ('ca','aa') {
5358: $datatable .= &modifiable_userdata_row($context,$role,$settings,
5359: $numinrow,$rowcount);
5360: $$rowtotal ++;
5361: $rowcount ++;
5362: }
1.230 raeburn 5363: } elsif ($position eq 'bottom') {
1.33 raeburn 5364: $context = 'course';
5365: $rowcount = 0;
5366: foreach my $role ('st','ep','ta','in','cr') {
5367: $datatable .= &modifiable_userdata_row($context,$role,$settings,
5368: $numinrow,$rowcount);
5369: $$rowtotal ++;
5370: $rowcount ++;
5371: }
5372: }
5373: return $datatable;
5374: }
5375:
1.43 raeburn 5376: sub print_defaults {
1.236 raeburn 5377: my ($position,$dom,$settings,$rowtotal) = @_;
1.43 raeburn 5378: my $rownum = 0;
5379: my ($datatable,$css_class);
1.236 raeburn 5380: if ($position eq 'top') {
5381: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def',
5382: 'datelocale_def','portal_def');
5383: my %defaults;
5384: if (ref($settings) eq 'HASH') {
5385: %defaults = %{$settings};
1.43 raeburn 5386: } else {
1.236 raeburn 5387: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
5388: foreach my $item (@items) {
5389: $defaults{$item} = $domdefaults{$item};
5390: }
1.43 raeburn 5391: }
1.236 raeburn 5392: my $titles = &defaults_titles($dom);
5393: foreach my $item (@items) {
5394: if ($rownum%2) {
5395: $css_class = '';
5396: } else {
5397: $css_class = ' class="LC_odd_row" ';
5398: }
5399: $datatable .= '<tr'.$css_class.'>'.
5400: '<td><span class="LC_nobreak">'.$titles->{$item}.
5401: '</span></td><td class="LC_right_item" colspan="3">';
5402: if ($item eq 'auth_def') {
5403: my @authtypes = ('internal','krb4','krb5','localauth');
5404: my %shortauth = (
5405: internal => 'int',
5406: krb4 => 'krb4',
5407: krb5 => 'krb5',
5408: localauth => 'loc'
5409: );
5410: my %authnames = &authtype_names();
5411: foreach my $auth (@authtypes) {
5412: my $checked = ' ';
5413: if ($defaults{$item} eq $auth) {
5414: $checked = ' checked="checked" ';
5415: }
5416: $datatable .= '<label><input type="radio" name="'.$item.
5417: '" value="'.$auth.'"'.$checked.'/>'.
5418: $authnames{$shortauth{$auth}}.'</label> ';
5419: }
5420: } elsif ($item eq 'timezone_def') {
5421: my $includeempty = 1;
5422: $datatable .= &Apache::loncommon::select_timezone($item,$defaults{$item},undef,$includeempty);
5423: } elsif ($item eq 'datelocale_def') {
5424: my $includeempty = 1;
5425: $datatable .= &Apache::loncommon::select_datelocale($item,$defaults{$item},undef,$includeempty);
5426: } elsif ($item eq 'lang_def') {
1.263 raeburn 5427: my $includeempty = 1;
5428: $datatable .= &Apache::loncommon::select_language($item,$defaults{$item},$includeempty);
1.236 raeburn 5429: } else {
5430: my $size;
5431: if ($item eq 'portal_def') {
5432: $size = ' size="25"';
5433: }
5434: $datatable .= '<input type="text" name="'.$item.'" value="'.
5435: $defaults{$item}.'"'.$size.' />';
1.43 raeburn 5436: }
1.236 raeburn 5437: $datatable .= '</td></tr>';
5438: $rownum ++;
5439: }
5440: } else {
5441: my (%defaults);
5442: if (ref($settings) eq 'HASH') {
5443: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH') &&
5444: (ref($settings->{'inststatusguest'}) eq 'ARRAY')) {
5445: my $maxnum = @{$settings->{'inststatusorder'}};
5446: for (my $i=0; $i<$maxnum; $i++) {
5447: $css_class = $rownum%2?' class="LC_odd_row"':'';
5448: my $item = $settings->{'inststatusorder'}->[$i];
5449: my $title = $settings->{'inststatustypes'}->{$item};
5450: my $guestok;
5451: if (grep(/^\Q$item\E$/,@{$settings->{'inststatusguest'}})) {
5452: $guestok = 1;
5453: }
5454: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'$item'".');"';
5455: $datatable .= '<tr'.$css_class.'>'.
5456: '<td><span class="LC_nobreak">'.
5457: '<select name="inststatus_pos_'.$item.'"'.$chgstr.'>';
5458: for (my $k=0; $k<=$maxnum; $k++) {
5459: my $vpos = $k+1;
5460: my $selstr;
5461: if ($k == $i) {
5462: $selstr = ' selected="selected" ';
5463: }
5464: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
5465: }
5466: my ($checkedon,$checkedoff);
5467: $checkedoff = ' checked="checked"';
5468: if ($guestok) {
5469: $checkedon = $checkedoff;
5470: $checkedoff = '';
5471: }
5472: $datatable .= '</select> '.&mt('Internal ID:').' <b>'.$item.'</b> '.
5473: '<input type="checkbox" name="inststatus_delete" value="'.$item.'" />'.
5474: &mt('delete').'</span></td>'.
5475: '<td class="LC_left_item"><span class="LC_nobreak">'.&mt('Name displayed:').
5476: '<input type="text" size="20" name="inststatus_title_'.$item.'" value="'.$title.'" />'.
5477: '</span></td>'.
5478: '<td class="LC_right_item"><span class="LC_nobreak">'.
5479: '<label><input type="radio" value="1" name="inststatus_guest_'.$item.'"'.$checkedon.' />'.
5480: &mt('Yes').'</label>'.(' 'x2).
5481: '<label><input type="radio" value="0" name="inststatus_guest_'.$item.'"'.$checkedoff.' />'.
5482: &mt('No').'</label></span></td></tr>';
5483: }
5484: $css_class = $rownum%2?' class="LC_odd_row"':'';
5485: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'addinststatus_pos'".');"';
5486: $datatable .= '<tr '.$css_class.'>'.
5487: '<td><span class="LC_nobreak"><select name="addinststatus_pos"'.$chgstr.'>';
5488: for (my $k=0; $k<=$maxnum; $k++) {
5489: my $vpos = $k+1;
5490: my $selstr;
5491: if ($k == $maxnum) {
5492: $selstr = ' selected="selected" ';
5493: }
5494: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
5495: }
5496: $datatable .= '</select> '.&mt('Internal ID:').
1.263 raeburn 5497: '<input type="text" size="10" name="addinststatus" value="" />'.
1.236 raeburn 5498: ' '.&mt('(new)').
5499: '</span></td><td class="LC_left_item"><span class="LC_nobreak">'.
5500: &mt('Name displayed:').
5501: '<input type="text" size="20" name="addinststatus_title" value="" /></span></td>'.
5502: '<td class="LC_right_item"><span class="LC_nobreak">'.
5503: '<label><input type="radio" value="1" name="addinststatus_guest" />'.
5504: &mt('Yes').'</label>'.(' 'x2).
5505: '<label><input type="radio" value="0" name="addinststatus_guest" />'.
5506: &mt('No').'</label></span></td></tr>';
5507: '</tr>'."\n";
5508: $rownum ++;
1.141 raeburn 5509: }
1.43 raeburn 5510: }
5511: }
5512: $$rowtotal += $rownum;
5513: return $datatable;
5514: }
5515:
1.168 raeburn 5516: sub get_languages_hash {
5517: my %langchoices;
5518: foreach my $id (&Apache::loncommon::languageids()) {
5519: my $code = &Apache::loncommon::supportedlanguagecode($id);
5520: if ($code ne '') {
5521: $langchoices{$code} = &Apache::loncommon::plainlanguagedescription($id);
5522: }
5523: }
5524: return %langchoices;
5525: }
5526:
1.43 raeburn 5527: sub defaults_titles {
1.141 raeburn 5528: my ($dom) = @_;
1.43 raeburn 5529: my %titles = &Apache::lonlocal::texthash (
5530: 'auth_def' => 'Default authentication type',
5531: 'auth_arg_def' => 'Default authentication argument',
5532: 'lang_def' => 'Default language',
1.54 raeburn 5533: 'timezone_def' => 'Default timezone',
1.68 raeburn 5534: 'datelocale_def' => 'Default locale for dates',
1.141 raeburn 5535: 'portal_def' => 'Portal/Default URL',
1.43 raeburn 5536: );
1.141 raeburn 5537: if ($dom) {
5538: my $uprimary_id = &Apache::lonnet::domain($dom,'primary');
5539: my $uint_dom = &Apache::lonnet::internet_dom($uprimary_id);
5540: my $protocol = $Apache::lonnet::protocol{$uprimary_id};
5541: $protocol = 'http' if ($protocol ne 'https');
5542: if ($uint_dom) {
5543: $titles{'portal_def'} .= ' '.&mt('(for example: [_1])',$protocol.'://loncapa.'.
5544: $uint_dom);
5545: }
5546: }
1.43 raeburn 5547: return (\%titles);
5548: }
5549:
1.46 raeburn 5550: sub print_scantronformat {
5551: my ($r,$dom,$confname,$settings,$rowtotal) = @_;
5552: my $itemcount = 1;
1.60 raeburn 5553: my ($datatable,$css_class,$scantronurl,$is_custom,%error,%scantronurls,
5554: %confhash);
1.46 raeburn 5555: my $switchserver = &check_switchserver($dom,$confname);
5556: my %lt = &Apache::lonlocal::texthash (
1.95 www 5557: default => 'Default bubblesheet format file error',
5558: custom => 'Custom bubblesheet format file error',
1.46 raeburn 5559: );
5560: my %scantronfiles = (
5561: default => 'default.tab',
5562: custom => 'custom.tab',
5563: );
5564: foreach my $key (keys(%scantronfiles)) {
5565: $scantronurls{$key} = '/res/'.$dom.'/'.$confname.'/scantron/'
5566: .$scantronfiles{$key};
5567: }
5568: my @defaultinfo = &Apache::lonnet::stat_file($scantronurls{'default'});
5569: if ((!@defaultinfo) || ($defaultinfo[0] eq 'no_such_dir')) {
5570: if (!$switchserver) {
5571: my $servadm = $r->dir_config('lonAdmEMail');
5572: my ($configuserok,$author_ok) = &config_check($dom,$confname,$servadm);
5573: if ($configuserok eq 'ok') {
5574: if ($author_ok eq 'ok') {
5575: my %legacyfile = (
5576: default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab',
5577: custom => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab',
5578: );
5579: my %md5chk;
5580: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 5581: ($md5chk{$type}) = split(/ /,`md5sum $legacyfile{$type}`);
5582: chomp($md5chk{$type});
1.46 raeburn 5583: }
5584: if ($md5chk{'default'} ne $md5chk{'custom'}) {
5585: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 5586: ($scantronurls{$type},my $error) =
1.46 raeburn 5587: &legacy_scantronformat($r,$dom,$confname,
5588: $type,$legacyfile{$type},
5589: $scantronurls{$type},
5590: $scantronfiles{$type});
1.60 raeburn 5591: if ($error ne '') {
5592: $error{$type} = $error;
5593: }
5594: }
5595: if (keys(%error) == 0) {
5596: $is_custom = 1;
5597: $confhash{'scantron'}{'scantronformat'} =
5598: $scantronurls{'custom'};
5599: my $putresult =
5600: &Apache::lonnet::put_dom('configuration',
5601: \%confhash,$dom);
5602: if ($putresult ne 'ok') {
5603: $error{'custom'} =
5604: '<span class="LC_error">'.
5605: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
5606: }
1.46 raeburn 5607: }
5608: } else {
1.60 raeburn 5609: ($scantronurls{'default'},my $error) =
1.46 raeburn 5610: &legacy_scantronformat($r,$dom,$confname,
5611: 'default',$legacyfile{'default'},
5612: $scantronurls{'default'},
5613: $scantronfiles{'default'});
1.60 raeburn 5614: if ($error eq '') {
5615: $confhash{'scantron'}{'scantronformat'} = '';
5616: my $putresult =
5617: &Apache::lonnet::put_dom('configuration',
5618: \%confhash,$dom);
5619: if ($putresult ne 'ok') {
5620: $error{'default'} =
5621: '<span class="LC_error">'.
5622: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
5623: }
5624: } else {
5625: $error{'default'} = $error;
5626: }
1.46 raeburn 5627: }
5628: }
5629: }
5630: } else {
1.95 www 5631: $error{'default'} = &mt("Unable to copy default bubblesheet formatfile to domain's RES space: [_1]",$switchserver);
1.46 raeburn 5632: }
5633: }
5634: if (ref($settings) eq 'HASH') {
5635: if ($settings->{'scantronformat'} eq "/res/$dom/$confname/scantron/custom.tab") {
5636: my @info = &Apache::lonnet::stat_file($settings->{'scantronformat'});
5637: if ((!@info) || ($info[0] eq 'no_such_dir')) {
5638: $scantronurl = '';
5639: } else {
5640: $scantronurl = $settings->{'scantronformat'};
5641: }
5642: $is_custom = 1;
5643: } else {
5644: $scantronurl = $scantronurls{'default'};
5645: }
5646: } else {
1.60 raeburn 5647: if ($is_custom) {
5648: $scantronurl = $scantronurls{'custom'};
5649: } else {
5650: $scantronurl = $scantronurls{'default'};
5651: }
1.46 raeburn 5652: }
5653: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5654: $datatable .= '<tr'.$css_class.'>';
5655: if (!$is_custom) {
1.65 raeburn 5656: $datatable .= '<td>'.&mt('Default in use:').'<br />'.
5657: '<span class="LC_nobreak">';
1.46 raeburn 5658: if ($scantronurl) {
1.199 raeburn 5659: $datatable .= &Apache::loncommon::modal_link($scantronurl,&mt('Default bubblesheet format file'),600,500,
5660: undef,undef,undef,undef,'background-color:#ffffff');
1.46 raeburn 5661: } else {
5662: $datatable = &mt('File unavailable for display');
5663: }
1.65 raeburn 5664: $datatable .= '</span></td>';
1.60 raeburn 5665: if (keys(%error) == 0) {
5666: $datatable .= '<td valign="bottom">';
5667: if (!$switchserver) {
5668: $datatable .= &mt('Upload:').'<br />';
5669: }
5670: } else {
5671: my $errorstr;
5672: foreach my $key (sort(keys(%error))) {
5673: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
5674: }
5675: $datatable .= '<td>'.$errorstr;
5676: }
1.46 raeburn 5677: } else {
5678: if (keys(%error) > 0) {
5679: my $errorstr;
5680: foreach my $key (sort(keys(%error))) {
5681: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
5682: }
1.60 raeburn 5683: $datatable .= '<td>'.$errorstr.'</td><td> ';
1.46 raeburn 5684: } elsif ($scantronurl) {
1.199 raeburn 5685: my $link = &Apache::loncommon::modal_link($scantronurl,&mt('Custom bubblesheet format file'),600,500,
5686: undef,undef,undef,undef,'background-color:#ffffff');
1.65 raeburn 5687: $datatable .= '<td><span class="LC_nobreak">'.
1.199 raeburn 5688: $link.
5689: '<label><input type="checkbox" name="scantronformat_del"'.
5690: ' value="1" />'.&mt('Delete?').'</label></span></td>'.
1.65 raeburn 5691: '<td><span class="LC_nobreak"> '.
5692: &mt('Replace:').'</span><br />';
1.46 raeburn 5693: }
5694: }
5695: if (keys(%error) == 0) {
5696: if ($switchserver) {
5697: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
5698: } else {
1.65 raeburn 5699: $datatable .='<span class="LC_nobreak"> '.
5700: '<input type="file" name="scantronformat" /></span>';
1.46 raeburn 5701: }
5702: }
5703: $datatable .= '</td></tr>';
5704: $$rowtotal ++;
5705: return $datatable;
5706: }
5707:
5708: sub legacy_scantronformat {
5709: my ($r,$dom,$confname,$file,$legacyfile,$newurl,$newfile) = @_;
5710: my ($url,$error);
5711: my @statinfo = &Apache::lonnet::stat_file($newurl);
5712: if ((!@statinfo) || ($statinfo[0] eq 'no_such_dir')) {
5713: (my $result,$url) =
5714: &publishlogo($r,'copy',$legacyfile,$dom,$confname,'scantron',
5715: '','',$newfile);
5716: if ($result ne 'ok') {
1.130 raeburn 5717: $error = &mt("An error occurred publishing the [_1] bubblesheet format file in RES space. Error was: [_2].",$newfile,$result);
1.46 raeburn 5718: }
5719: }
5720: return ($url,$error);
5721: }
1.43 raeburn 5722:
1.49 raeburn 5723: sub print_coursecategories {
1.57 raeburn 5724: my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;
5725: my $datatable;
5726: if ($position eq 'top') {
1.238 raeburn 5727: my (%checked);
5728: my @catitems = ('unauth','auth');
5729: my @cattypes = ('std','domonly','codesrch','none');
5730: $checked{'unauth'} = 'std';
5731: $checked{'auth'} = 'std';
5732: if (ref($settings) eq 'HASH') {
5733: foreach my $type (@cattypes) {
5734: if ($type eq $settings->{'unauth'}) {
5735: $checked{'unauth'} = $type;
5736: }
5737: if ($type eq $settings->{'auth'}) {
5738: $checked{'auth'} = $type;
5739: }
5740: }
5741: }
5742: my %lt = &Apache::lonlocal::texthash (
5743: unauth => 'Catalog type for unauthenticated users',
5744: auth => 'Catalog type for authenticated users',
5745: none => 'No catalog',
5746: std => 'Standard catalog',
5747: domonly => 'Domain-only catalog',
5748: codesrch => "Code search form",
5749: );
5750: my $itemcount = 0;
5751: foreach my $item (@catitems) {
5752: my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
5753: $datatable .= '<tr '.$css_class.'>'.
5754: '<td>'.$lt{$item}.'</td>'.
5755: '<td class="LC_right_item"><span class="LC_nobreak">';
5756: foreach my $type (@cattypes) {
5757: my $ischecked;
5758: if ($checked{$item} eq $type) {
5759: $ischecked=' checked="checked"';
5760: }
5761: $datatable .= '<label>'.
5762: '<input type="radio" name="coursecat_'.$item.'" value="'.$type.'"'.$ischecked.
5763: ' />'.$lt{$type}.'</label> ';
5764: }
5765: $datatable .= '</td></tr>';
5766: $itemcount ++;
5767: }
5768: $$rowtotal += $itemcount;
5769: } elsif ($position eq 'middle') {
1.57 raeburn 5770: my $toggle_cats_crs = ' ';
5771: my $toggle_cats_dom = ' checked="checked" ';
5772: my $can_cat_crs = ' ';
5773: my $can_cat_dom = ' checked="checked" ';
1.120 raeburn 5774: my $toggle_catscomm_comm = ' ';
5775: my $toggle_catscomm_dom = ' checked="checked" ';
5776: my $can_catcomm_comm = ' ';
5777: my $can_catcomm_dom = ' checked="checked" ';
1.272 raeburn 5778: my $toggle_catsplace_place = ' ';
5779: my $toggle_catsplace_dom = ' checked="checked" ';
5780: my $can_catplace_place = ' ';
5781: my $can_catplace_dom = ' checked="checked" ';
1.120 raeburn 5782:
1.57 raeburn 5783: if (ref($settings) eq 'HASH') {
5784: if ($settings->{'togglecats'} eq 'crs') {
5785: $toggle_cats_crs = $toggle_cats_dom;
5786: $toggle_cats_dom = ' ';
5787: }
5788: if ($settings->{'categorize'} eq 'crs') {
5789: $can_cat_crs = $can_cat_dom;
5790: $can_cat_dom = ' ';
5791: }
1.120 raeburn 5792: if ($settings->{'togglecatscomm'} eq 'comm') {
5793: $toggle_catscomm_comm = $toggle_catscomm_dom;
5794: $toggle_catscomm_dom = ' ';
5795: }
5796: if ($settings->{'categorizecomm'} eq 'comm') {
5797: $can_catcomm_comm = $can_catcomm_dom;
5798: $can_catcomm_dom = ' ';
5799: }
1.272 raeburn 5800: if ($settings->{'togglecatsplace'} eq 'place') {
5801: $toggle_catsplace_place = $toggle_catsplace_dom;
5802: $toggle_catsplace_dom = ' ';
5803: }
5804: if ($settings->{'categorizeplace'} eq 'place') {
5805: $can_catplace_place = $can_catplace_dom;
5806: $can_catplace_dom = ' ';
5807: }
1.57 raeburn 5808: }
5809: my %title = &Apache::lonlocal::texthash (
1.272 raeburn 5810: togglecats => 'Show/Hide a course in catalog',
5811: togglecatscomm => 'Show/Hide a community in catalog',
5812: togglecatsplace => 'Show/Hide a placement test in catalog',
5813: categorize => 'Assign a category to a course',
5814: categorizecomm => 'Assign a category to a community',
5815: categorizeplace => 'Assign a category to a placement test',
1.57 raeburn 5816: );
5817: my %level = &Apache::lonlocal::texthash (
1.272 raeburn 5818: dom => 'Set in Domain',
5819: crs => 'Set in Course',
5820: comm => 'Set in Community',
5821: place => 'Set in Placement Test',
1.57 raeburn 5822: );
5823: $datatable = '<tr class="LC_odd_row">'.
5824: '<td>'.$title{'togglecats'}.'</td>'.
5825: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
5826: '<input type="radio" name="togglecats"'.
5827: $toggle_cats_dom.' value="dom" />'.$level{'dom'}.'</label> '.
5828: '<label><input type="radio" name="togglecats"'.
5829: $toggle_cats_crs.' value="crs" />'.$level{'crs'}.'</label></span></td>'.
5830: '</tr><tr>'.
5831: '<td>'.$title{'categorize'}.'</td>'.
5832: '<td class="LC_right_item"><span class="LC_nobreak">'.
5833: '<label><input type="radio" name="categorize"'.
5834: $can_cat_dom.' value="dom" />'.$level{'dom'}.'</label> '.
5835: '<label><input type="radio" name="categorize"'.
5836: $can_cat_crs.'value="crs" />'.$level{'crs'}.'</label></span></td>'.
1.120 raeburn 5837: '</tr><tr class="LC_odd_row">'.
5838: '<td>'.$title{'togglecatscomm'}.'</td>'.
5839: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
5840: '<input type="radio" name="togglecatscomm"'.
5841: $toggle_catscomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
5842: '<label><input type="radio" name="togglecatscomm"'.
5843: $toggle_catscomm_comm.' value="comm" />'.$level{'comm'}.'</label></span></td>'.
5844: '</tr><tr>'.
5845: '<td>'.$title{'categorizecomm'}.'</td>'.
5846: '<td class="LC_right_item"><span class="LC_nobreak">'.
5847: '<label><input type="radio" name="categorizecomm"'.
5848: $can_catcomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
5849: '<label><input type="radio" name="categorizecomm"'.
5850: $can_catcomm_comm.'value="comm" />'.$level{'comm'}.'</label></span></td>'.
1.272 raeburn 5851: '</tr><tr>'.
5852: '<td>'.$title{'togglecatsplace'}.'</td>'.
5853: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
5854: '<input type="radio" name="togglecatsplace"'.
5855: $toggle_catsplace_dom.' value="dom" />'.$level{'dom'}.'</label> '.
5856: '<label><input type="radio" name="togglecatscomm"'.
5857: $toggle_catsplace_place.' value="comm" />'.$level{'place'}.'</label></span></td>'.
5858: '</tr><tr>'.
5859: '<td>'.$title{'categorizeplace'}.'</td>'.
5860: '<td class="LC_right_item"><span class="LC_nobreak">'.
5861: '<label><input type="radio" name="categorizeplace"'.
5862: $can_catplace_dom.' value="dom" />'.$level{'dom'}.'</label> '.
5863: '<label><input type="radio" name="categorizeplace"'.
5864: $can_catplace_place.'value="place" />'.$level{'place'}.'</label></span></td>'.
1.57 raeburn 5865: '</tr>';
1.272 raeburn 5866: $$rowtotal += 6;
1.57 raeburn 5867: } else {
5868: my $css_class;
5869: my $itemcount = 1;
5870: my $cathash;
5871: if (ref($settings) eq 'HASH') {
5872: $cathash = $settings->{'cats'};
5873: }
5874: if (ref($cathash) eq 'HASH') {
5875: my (@cats,@trails,%allitems,%idx,@jsarray);
5876: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
5877: \%allitems,\%idx,\@jsarray);
5878: my $maxdepth = scalar(@cats);
5879: my $colattrib = '';
5880: if ($maxdepth > 2) {
5881: $colattrib = ' colspan="2" ';
5882: }
5883: my @path;
5884: if (@cats > 0) {
5885: if (ref($cats[0]) eq 'ARRAY') {
5886: my $numtop = @{$cats[0]};
5887: my $maxnum = $numtop;
1.120 raeburn 5888: my %default_names = (
5889: instcode => &mt('Official courses'),
5890: communities => &mt('Communities'),
1.272 raeburn 5891: placement => &mt('Placement Tests'),
1.120 raeburn 5892: );
5893:
5894: if ((!grep(/^instcode$/,@{$cats[0]})) ||
5895: ($cathash->{'instcode::0'} eq '') ||
5896: (!grep(/^communities$/,@{$cats[0]})) ||
1.272 raeburn 5897: ($cathash->{'communities::0'} eq '') ||
5898: (!grep(/^placement$/,@{$cats[0]})) ||
5899: ($cathash->{'placement::0'} eq '')) {
1.57 raeburn 5900: $maxnum ++;
5901: }
5902: my $lastidx;
5903: for (my $i=0; $i<$numtop; $i++) {
5904: my $parent = $cats[0][$i];
5905: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5906: my $item = &escape($parent).'::0';
5907: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$item','$idx{$item}'".');"';
5908: $lastidx = $idx{$item};
5909: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
5910: .'<select name="'.$item.'"'.$chgstr.'>';
5911: for (my $k=0; $k<=$maxnum; $k++) {
5912: my $vpos = $k+1;
5913: my $selstr;
5914: if ($k == $i) {
5915: $selstr = ' selected="selected" ';
5916: }
5917: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
5918: }
1.214 raeburn 5919: $datatable .= '</select></span></td><td>';
1.272 raeburn 5920: if ($parent eq 'instcode' || $parent eq 'communities' || $parent eq 'placement') {
1.120 raeburn 5921: $datatable .= '<span class="LC_nobreak">'
5922: .$default_names{$parent}.'</span>';
5923: if ($parent eq 'instcode') {
5924: $datatable .= '<br /><span class="LC_nobreak">('
5925: .&mt('with institutional codes')
5926: .')</span></td><td'.$colattrib.'>';
5927: } else {
5928: $datatable .= '<table><tr><td>';
5929: }
5930: $datatable .= '<span class="LC_nobreak">'
5931: .'<label><input type="radio" name="'
5932: .$parent.'" value="1" checked="checked" />'
5933: .&mt('Display').'</label>';
5934: if ($parent eq 'instcode') {
5935: $datatable .= ' ';
5936: } else {
5937: $datatable .= '</span></td></tr><tr><td>'
5938: .'<span class="LC_nobreak">';
5939: }
5940: $datatable .= '<label><input type="radio" name="'
5941: .$parent.'" value="0" />'
5942: .&mt('Do not display').'</label></span>';
1.272 raeburn 5943: if (($parent eq 'communities') || ($parent eq 'placement')) {
1.120 raeburn 5944: $datatable .= '</td></tr></table>';
5945: }
5946: $datatable .= '</td>';
1.57 raeburn 5947: } else {
5948: $datatable .= $parent
1.214 raeburn 5949: .' <span class="LC_nobreak"><label>'
5950: .'<input type="checkbox" name="deletecategory" '
1.57 raeburn 5951: .'value="'.$item.'" />'.&mt('Delete').'</label></span></td>';
5952: }
5953: my $depth = 1;
5954: push(@path,$parent);
5955: $datatable .= &build_category_rows($itemcount,\@cats,$depth,$parent,\@path,\%idx);
5956: pop(@path);
5957: $datatable .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
5958: $itemcount ++;
5959: }
1.48 raeburn 5960: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.57 raeburn 5961: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','$lastidx'".');"';
5962: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="addcategory_pos"'.$chgstr.'>';
1.48 raeburn 5963: for (my $k=0; $k<=$maxnum; $k++) {
5964: my $vpos = $k+1;
5965: my $selstr;
1.57 raeburn 5966: if ($k == $numtop) {
1.48 raeburn 5967: $selstr = ' selected="selected" ';
5968: }
5969: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
5970: }
1.59 bisitz 5971: $datatable .= '</select></span></td><td colspan="2">'.&mt('Add category:').' '
1.57 raeburn 5972: .'<input type="text" size="20" name="addcategory_name" value="" /></td>'
5973: .'</tr>'."\n";
1.48 raeburn 5974: $itemcount ++;
1.272 raeburn 5975: foreach my $default ('instcode','communities','placement') {
1.120 raeburn 5976: if ((!grep(/^\Q$default\E$/,@{$cats[0]})) || ($cathash->{$default.'::0'} eq '')) {
5977: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5978: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','$lastidx'".');"';
5979: $datatable .= '<tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr><tr '.$css_class.'><td>'.
5980: '<span class="LC_nobreak"><select name="'.$default.'_pos"'.$chgstr.'>';
5981: for (my $k=0; $k<=$maxnum; $k++) {
5982: my $vpos = $k+1;
5983: my $selstr;
5984: if ($k == $maxnum) {
5985: $selstr = ' selected="selected" ';
5986: }
5987: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.57 raeburn 5988: }
1.120 raeburn 5989: $datatable .= '</select></span></td>'.
5990: '<td><span class="LC_nobreak">'.
5991: $default_names{$default}.'</span>';
5992: if ($default eq 'instcode') {
5993: $datatable .= '<br /><span class="LC_nobreak">('
5994: .&mt('with institutional codes').')</span>';
5995: }
5996: $datatable .= '</td>'
5997: .'<td><span class="LC_nobreak"><label><input type="radio" name="'.$default.'" value="1" />'
5998: .&mt('Display').'</label> '
5999: .'<label><input type="radio" name="'.$default.'" value="0" checked="checked"/>'
6000: .&mt('Do not display').'</label></span></td></tr>';
1.48 raeburn 6001: }
6002: }
6003: }
1.57 raeburn 6004: } else {
6005: $datatable .= &initialize_categories($itemcount);
1.48 raeburn 6006: }
6007: } else {
1.238 raeburn 6008: $datatable .= '<td class="LC_right_item">'.$hdritem->{'header'}->[1]->{'col2'}.'</td>'
1.57 raeburn 6009: .&initialize_categories($itemcount);
1.48 raeburn 6010: }
1.57 raeburn 6011: $$rowtotal += $itemcount;
1.48 raeburn 6012: }
6013: return $datatable;
6014: }
6015:
1.69 raeburn 6016: sub print_serverstatuses {
6017: my ($dom,$settings,$rowtotal) = @_;
6018: my $datatable;
6019: my @pages = &serverstatus_pages();
6020: my (%namedaccess,%machineaccess);
6021: foreach my $type (@pages) {
6022: $namedaccess{$type} = '';
6023: $machineaccess{$type}= '';
6024: }
6025: if (ref($settings) eq 'HASH') {
6026: foreach my $type (@pages) {
6027: if (exists($settings->{$type})) {
6028: if (ref($settings->{$type}) eq 'HASH') {
6029: foreach my $key (keys(%{$settings->{$type}})) {
6030: if ($key eq 'namedusers') {
6031: $namedaccess{$type} = $settings->{$type}->{$key};
6032: } elsif ($key eq 'machines') {
6033: $machineaccess{$type} = $settings->{$type}->{$key};
6034: }
6035: }
6036: }
6037: }
6038: }
6039: }
1.81 raeburn 6040: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 6041: my $rownum = 0;
6042: my $css_class;
6043: foreach my $type (@pages) {
6044: $rownum ++;
6045: $css_class = $rownum%2?' class="LC_odd_row"':'';
6046: $datatable .= '<tr'.$css_class.'>'.
6047: '<td><span class="LC_nobreak">'.
6048: $titles->{$type}.'</span></td>'.
6049: '<td class="LC_left_item">'.
6050: '<input type="text" name="'.$type.'_namedusers" '.
6051: 'value="'.$namedaccess{$type}.'" size="30" /></td>'.
6052: '<td class="LC_right_item">'.
6053: '<span class="LC_nobreak">'.
6054: '<input type="text" name="'.$type.'_machines" '.
6055: 'value="'.$machineaccess{$type}.'" size="10" />'.
6056: '</td></tr>'."\n";
6057: }
6058: $$rowtotal += $rownum;
6059: return $datatable;
6060: }
6061:
6062: sub serverstatus_pages {
6063: return ('userstatus','lonstatus','loncron','server-status','codeversions',
1.275 ! raeburn 6064: 'checksums','clusterstatus','certstatus','metadata_keywords',
! 6065: 'metadata_harvest','takeoffline','takeonline','showenv','toggledebug',
! 6066: 'ping','domconf','uniquecodes','diskusage','coursecatalog');
1.69 raeburn 6067: }
6068:
1.236 raeburn 6069: sub defaults_javascript {
6070: my ($settings) = @_;
1.248 raeburn 6071: return unless (ref($settings) eq 'HASH');
1.236 raeburn 6072: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
6073: my $maxnum = scalar(@{$settings->{'inststatusorder'}});
6074: if ($maxnum eq '') {
6075: $maxnum = 0;
6076: }
6077: $maxnum ++;
1.249 raeburn 6078: my $jstext = ' var inststatuses = Array('."'".join("','",@{$settings->{'inststatusorder'}})."'".');';
1.236 raeburn 6079: return <<"ENDSCRIPT";
6080: <script type="text/javascript">
6081: // <![CDATA[
6082: function reorderTypes(form,caller) {
6083: var changedVal;
6084: $jstext
6085: var newpos = 'addinststatus_pos';
6086: var current = new Array;
6087: var maxh = $maxnum;
6088: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
6089: var oldVal;
6090: if (caller == newpos) {
6091: changedVal = newitemVal;
6092: } else {
6093: var curritem = 'inststatus_pos_'+caller;
6094: changedVal = form.elements[curritem].options[form.elements[curritem].selectedIndex].value;
6095: current[newitemVal] = newpos;
6096: }
6097: for (var i=0; i<inststatuses.length; i++) {
6098: if (inststatuses[i] != caller) {
6099: var elementName = 'inststatus_pos_'+inststatuses[i];
6100: if (form.elements[elementName]) {
6101: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
6102: current[currVal] = elementName;
6103: }
6104: }
6105: }
6106: for (var j=0; j<maxh; j++) {
6107: if (current[j] == undefined) {
6108: oldVal = j;
6109: }
6110: }
6111: if (oldVal < changedVal) {
6112: for (var k=oldVal+1; k<=changedVal ; k++) {
6113: var elementName = current[k];
6114: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
6115: }
6116: } else {
6117: for (var k=changedVal; k<oldVal; k++) {
6118: var elementName = current[k];
6119: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
6120: }
6121: }
6122: return;
6123: }
6124:
6125: // ]]>
6126: </script>
6127:
6128: ENDSCRIPT
6129: }
6130: }
6131:
1.49 raeburn 6132: sub coursecategories_javascript {
6133: my ($settings) = @_;
1.57 raeburn 6134: my ($output,$jstext,$cathash);
1.49 raeburn 6135: if (ref($settings) eq 'HASH') {
1.57 raeburn 6136: $cathash = $settings->{'cats'};
6137: }
6138: if (ref($cathash) eq 'HASH') {
1.49 raeburn 6139: my (@cats,@jsarray,%idx);
1.57 raeburn 6140: &Apache::loncommon::gather_categories($cathash,\@cats,\%idx,\@jsarray);
1.49 raeburn 6141: if (@jsarray > 0) {
6142: $jstext = ' var categories = Array('.scalar(@jsarray).');'."\n";
6143: for (my $i=0; $i<@jsarray; $i++) {
6144: if (ref($jsarray[$i]) eq 'ARRAY') {
6145: my $catstr = join('","',@{$jsarray[$i]});
6146: $jstext .= ' categories['.$i.'] = Array("'.$catstr.'");'."\n";
6147: }
6148: }
6149: }
6150: } else {
6151: $jstext = ' var categories = Array(1);'."\n".
6152: ' categories[0] = Array("instcode_pos");'."\n";
6153: }
1.237 bisitz 6154: my $instcode_reserved = &mt('The name: [_1] is a reserved category.','"instcode"');
6155: my $communities_reserved = &mt('The name: [_1] is a reserved category.','"communities"');
1.272 raeburn 6156: my $placement_reserved = &mt('The name: [_1] is a reserved category.','"placement"');
1.265 damieng 6157: my $choose_again = "\n".&mt('Please use a different name for the new top level category.');
6158: &js_escape(\$instcode_reserved);
6159: &js_escape(\$communities_reserved);
1.272 raeburn 6160: &js_escape(\$placement_reserved);
1.265 damieng 6161: &js_escape(\$choose_again);
1.49 raeburn 6162: $output = <<"ENDSCRIPT";
6163: <script type="text/javascript">
1.109 raeburn 6164: // <![CDATA[
1.49 raeburn 6165: function reorderCats(form,parent,item,idx) {
6166: var changedVal;
6167: $jstext
6168: var newpos = 'addcategory_pos';
6169: if (parent == '') {
6170: var has_instcode = 0;
6171: var maxtop = categories[idx].length;
6172: for (var j=0; j<maxtop; j++) {
6173: if (categories[idx][j] == 'instcode::0') {
6174: has_instcode == 1;
6175: }
6176: }
6177: if (has_instcode == 0) {
6178: categories[idx][maxtop] = 'instcode_pos';
6179: }
6180: } else {
6181: newpos += '_'+parent;
6182: }
6183: var maxh = 1 + categories[idx].length;
6184: var current = new Array;
6185: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
6186: if (item == newpos) {
6187: changedVal = newitemVal;
6188: } else {
6189: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
6190: current[newitemVal] = newpos;
6191: }
6192: for (var i=0; i<categories[idx].length; i++) {
6193: var elementName = categories[idx][i];
6194: if (elementName != item) {
6195: if (form.elements[elementName]) {
6196: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
6197: current[currVal] = elementName;
6198: }
6199: }
6200: }
6201: var oldVal;
6202: for (var j=0; j<maxh; j++) {
6203: if (current[j] == undefined) {
6204: oldVal = j;
6205: }
6206: }
6207: if (oldVal < changedVal) {
6208: for (var k=oldVal+1; k<=changedVal ; k++) {
6209: var elementName = current[k];
6210: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
6211: }
6212: } else {
6213: for (var k=changedVal; k<oldVal; k++) {
6214: var elementName = current[k];
6215: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
6216: }
6217: }
6218: return;
6219: }
1.120 raeburn 6220:
6221: function categoryCheck(form) {
6222: if (form.elements['addcategory_name'].value == 'instcode') {
6223: alert('$instcode_reserved\\n$choose_again');
6224: return false;
6225: }
6226: if (form.elements['addcategory_name'].value == 'communities') {
6227: alert('$communities_reserved\\n$choose_again');
6228: return false;
6229: }
1.272 raeburn 6230: if (form.elements['addcategory_name'].value == 'placement') {
6231: alert('$placement_reserved\\n$choose_again');
6232: return false;
6233: }
1.120 raeburn 6234: return true;
6235: }
6236:
1.109 raeburn 6237: // ]]>
1.49 raeburn 6238: </script>
6239:
6240: ENDSCRIPT
6241: return $output;
6242: }
6243:
1.48 raeburn 6244: sub initialize_categories {
6245: my ($itemcount) = @_;
1.120 raeburn 6246: my ($datatable,$css_class,$chgstr);
6247: my %default_names = (
6248: instcode => 'Official courses (with institutional codes)',
6249: communities => 'Communities',
1.272 raeburn 6250: placement => 'Placement Tests',
1.120 raeburn 6251: );
6252: my $select0 = ' selected="selected"';
6253: my $select1 = '';
1.272 raeburn 6254: foreach my $default ('instcode','communities','placement') {
1.120 raeburn 6255: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6256: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'',$default"."_pos','0'".');"';
1.272 raeburn 6257: if (($default eq 'communities') || ($default eq 'placement')) {
1.120 raeburn 6258: $select1 = $select0;
6259: $select0 = '';
6260: }
6261: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
6262: .'<select name="'.$default.'_pos">'
6263: .'<option value="0"'.$select0.'>1</option>'
6264: .'<option value="1"'.$select1.'>2</option>'
6265: .'<option value="2">3</option></select> '
6266: .$default_names{$default}
6267: .'</span></td><td><span class="LC_nobreak">'
6268: .'<label><input type="radio" name="'.$default.'" value="1" checked="checked" />'
6269: .&mt('Display').'</label> <label>'
6270: .'<input type="radio" name="'.$default.'" value="0" />'.&mt('Do not display')
1.48 raeburn 6271: .'</label></span></td></tr>';
1.120 raeburn 6272: $itemcount ++;
6273: }
1.48 raeburn 6274: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.49 raeburn 6275: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','0'".');"';
1.48 raeburn 6276: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.120 raeburn 6277: .'<select name="addcategory_pos"'.$chgstr.'>'
6278: .'<option value="0">1</option>'
6279: .'<option value="1">2</option>'
6280: .'<option value="2" selected="selected">3</option></select> '
1.48 raeburn 6281: .&mt('Add category').'</td><td>'.&mt('Name:')
6282: .' <input type="text" size="20" name="addcategory_name" value="" /></td></tr>';
6283: return $datatable;
6284: }
6285:
6286: sub build_category_rows {
1.49 raeburn 6287: my ($itemcount,$cats,$depth,$parent,$path,$idx) = @_;
6288: my ($text,$name,$item,$chgstr);
1.48 raeburn 6289: if (ref($cats) eq 'ARRAY') {
6290: my $maxdepth = scalar(@{$cats});
6291: if (ref($cats->[$depth]) eq 'HASH') {
6292: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
6293: my $numchildren = @{$cats->[$depth]{$parent}};
6294: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.204 raeburn 6295: $text .= '<td><table class="LC_data_table">';
1.49 raeburn 6296: my ($idxnum,$parent_name,$parent_item);
6297: my $higher = $depth - 1;
6298: if ($higher == 0) {
6299: $parent_name = &escape($parent).'::'.$higher;
6300: } else {
6301: if (ref($path) eq 'ARRAY') {
6302: $parent_name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
6303: }
6304: }
6305: $parent_item = 'addcategory_pos_'.$parent_name;
1.48 raeburn 6306: for (my $j=0; $j<=$numchildren; $j++) {
1.49 raeburn 6307: if ($j < $numchildren) {
1.48 raeburn 6308: $name = $cats->[$depth]{$parent}[$j];
6309: $item = &escape($name).':'.&escape($parent).':'.$depth;
1.49 raeburn 6310: $idxnum = $idx->{$item};
6311: } else {
6312: $name = $parent_name;
6313: $item = $parent_item;
1.48 raeburn 6314: }
1.49 raeburn 6315: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'$parent_name','$item','$idxnum'".');"';
6316: $text .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="'.$item.'"'.$chgstr.'>';
1.48 raeburn 6317: for (my $i=0; $i<=$numchildren; $i++) {
6318: my $vpos = $i+1;
6319: my $selstr;
6320: if ($j == $i) {
6321: $selstr = ' selected="selected" ';
6322: }
6323: $text .= '<option value="'.$i.'"'.$selstr.'>'.$vpos.'</option>';
6324: }
6325: $text .= '</select> ';
6326: if ($j < $numchildren) {
6327: my $deeper = $depth+1;
6328: $text .= $name.' '
6329: .'<label><input type="checkbox" name="deletecategory" value="'
6330: .$item.'" />'.&mt('Delete').'</label></span></td><td>';
6331: if(ref($path) eq 'ARRAY') {
6332: push(@{$path},$name);
1.49 raeburn 6333: $text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path,$idx);
1.48 raeburn 6334: pop(@{$path});
6335: }
6336: } else {
1.59 bisitz 6337: $text .= &mt('Add subcategory:').' </span><input type="textbox" size="20" name="addcategory_name_';
1.48 raeburn 6338: if ($j == $numchildren) {
6339: $text .= $name;
6340: } else {
6341: $text .= $item;
6342: }
6343: $text .= '" value="" />';
6344: }
6345: $text .= '</td></tr>';
6346: }
6347: $text .= '</table></td>';
6348: } else {
6349: my $higher = $depth-1;
6350: if ($higher == 0) {
6351: $name = &escape($parent).'::'.$higher;
6352: } else {
6353: if (ref($path) eq 'ARRAY') {
6354: $name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
6355: }
6356: }
6357: my $colspan;
6358: if ($parent ne 'instcode') {
6359: $colspan = $maxdepth - $depth - 1;
6360: $text .= '<td colspan="'.$colspan.'">'.&mt('Add subcategory:').'<input type="textbox" size="20" name="subcat_'.$name.'" value="" /></td>';
6361: }
6362: }
6363: }
6364: }
6365: return $text;
6366: }
6367:
1.33 raeburn 6368: sub modifiable_userdata_row {
1.228 raeburn 6369: my ($context,$item,$settings,$numinrow,$rowcount,$usertypes,$fieldsref,$titlesref) = @_;
6370: my ($role,$rolename,$statustype);
6371: $role = $item;
1.224 raeburn 6372: if ($context eq 'cancreate') {
1.228 raeburn 6373: if ($item =~ /^emailusername_(.+)$/) {
6374: $statustype = $1;
6375: $role = 'emailusername';
6376: if (ref($usertypes) eq 'HASH') {
6377: if ($usertypes->{$statustype}) {
6378: $rolename = &mt('Data provided by [_1]',$usertypes->{$statustype});
6379: } else {
6380: $rolename = &mt('Data provided by user');
6381: }
6382: }
1.224 raeburn 6383: }
6384: } elsif ($context eq 'selfcreate') {
1.63 raeburn 6385: if (ref($usertypes) eq 'HASH') {
6386: $rolename = $usertypes->{$role};
6387: } else {
6388: $rolename = $role;
6389: }
1.33 raeburn 6390: } else {
1.63 raeburn 6391: if ($role eq 'cr') {
6392: $rolename = &mt('Custom role');
6393: } else {
6394: $rolename = &Apache::lonnet::plaintext($role);
6395: }
1.33 raeburn 6396: }
1.224 raeburn 6397: my (@fields,%fieldtitles);
6398: if (ref($fieldsref) eq 'ARRAY') {
6399: @fields = @{$fieldsref};
6400: } else {
6401: @fields = ('lastname','firstname','middlename','generation',
6402: 'permanentemail','id');
6403: }
6404: if ((ref($titlesref) eq 'HASH')) {
6405: %fieldtitles = %{$titlesref};
6406: } else {
6407: %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
6408: }
1.33 raeburn 6409: my $output;
6410: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
6411: $output = '<tr '.$css_class.'>'.
6412: '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
6413: '<td class="LC_left_item" colspan="2"><table>';
6414: my $rem;
6415: my %checks;
6416: if (ref($settings) eq 'HASH') {
6417: if (ref($settings->{$context}) eq 'HASH') {
6418: if (ref($settings->{$context}->{$role}) eq 'HASH') {
1.228 raeburn 6419: my $hashref = $settings->{$context}->{$role};
6420: if ($role eq 'emailusername') {
6421: if ($statustype) {
6422: if (ref($settings->{$context}->{$role}->{$statustype}) eq 'HASH') {
6423: $hashref = $settings->{$context}->{$role}->{$statustype};
6424: if (ref($hashref) eq 'HASH') {
6425: foreach my $field (@fields) {
6426: if ($hashref->{$field}) {
6427: $checks{$field} = $hashref->{$field};
6428: }
6429: }
6430: }
6431: }
6432: }
6433: } else {
6434: if (ref($hashref) eq 'HASH') {
6435: foreach my $field (@fields) {
6436: if ($hashref->{$field}) {
6437: $checks{$field} = ' checked="checked" ';
6438: }
6439: }
1.33 raeburn 6440: }
6441: }
6442: }
6443: }
6444: }
1.228 raeburn 6445:
1.33 raeburn 6446: for (my $i=0; $i<@fields; $i++) {
6447: my $rem = $i%($numinrow);
6448: if ($rem == 0) {
6449: if ($i > 0) {
6450: $output .= '</tr>';
6451: }
6452: $output .= '<tr>';
6453: }
6454: my $check = ' ';
1.228 raeburn 6455: unless ($role eq 'emailusername') {
6456: if (exists($checks{$fields[$i]})) {
6457: $check = $checks{$fields[$i]}
6458: } else {
6459: if ($role eq 'st') {
6460: if (ref($settings) ne 'HASH') {
6461: $check = ' checked="checked" ';
6462: }
1.33 raeburn 6463: }
6464: }
6465: }
6466: $output .= '<td class="LC_left_item">'.
1.228 raeburn 6467: '<span class="LC_nobreak">';
6468: if ($role eq 'emailusername') {
6469: unless ($checks{$fields[$i]} =~ /^(required|optional)$/) {
6470: $checks{$fields[$i]} = 'omit';
6471: }
6472: foreach my $option ('required','optional','omit') {
6473: my $checked='';
6474: if ($checks{$fields[$i]} eq $option) {
6475: $checked='checked="checked" ';
6476: }
6477: $output .= '<label>'.
6478: '<input type="radio" name="canmodify_'.$item.'_'.$fields[$i].'" value="'.$option.'" '.$checked.'/>'.
6479: &mt($option).'</label>'.(' ' x2);
6480: }
6481: $output .= '<i>'.$fieldtitles{$fields[$i]}.'</i>';
6482: } else {
6483: $output .= '<label>'.
6484: '<input type="checkbox" name="canmodify_'.$role.'" '.
6485: 'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
6486: '</label>';
6487: }
6488: $output .= '</span></td>';
1.33 raeburn 6489: $rem = @fields%($numinrow);
6490: }
6491: my $colsleft = $numinrow - $rem;
6492: if ($colsleft > 1 ) {
6493: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
6494: ' </td>';
6495: } elsif ($colsleft == 1) {
6496: $output .= '<td class="LC_left_item"> </td>';
6497: }
6498: $output .= '</tr></table></td></tr>';
6499: return $output;
6500: }
1.28 raeburn 6501:
1.93 raeburn 6502: sub insttypes_row {
1.224 raeburn 6503: my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle,$context,$rownum) = @_;
1.93 raeburn 6504: my %lt = &Apache::lonlocal::texthash (
6505: cansearch => 'Users allowed to search',
6506: statustocreate => 'Institutional affiliation(s) able to create own account (login/SSO)',
1.131 raeburn 6507: lockablenames => 'User preference to lock name',
1.93 raeburn 6508: );
6509: my $showdom;
6510: if ($context eq 'cansearch') {
6511: $showdom = ' ('.$dom.')';
6512: }
1.165 raeburn 6513: my $class = 'LC_left_item';
6514: if ($context eq 'statustocreate') {
6515: $class = 'LC_right_item';
6516: }
1.224 raeburn 6517: my $css_class = ' class="LC_odd_row"';
6518: if ($rownum ne '') {
6519: $css_class = ($rownum%2? ' class="LC_odd_row"':'');
6520: }
6521: my $output = '<tr'.$css_class.'>'.
6522: '<td>'.$lt{$context}.$showdom.
6523: '</td><td class="'.$class.'" colspan="2"><table>';
1.26 raeburn 6524: my $rem;
6525: if (ref($types) eq 'ARRAY') {
6526: for (my $i=0; $i<@{$types}; $i++) {
6527: if (defined($usertypes->{$types->[$i]})) {
6528: my $rem = $i%($numinrow);
6529: if ($rem == 0) {
6530: if ($i > 0) {
6531: $output .= '</tr>';
6532: }
6533: $output .= '<tr>';
1.23 raeburn 6534: }
1.26 raeburn 6535: my $check = ' ';
1.99 raeburn 6536: if (ref($settings) eq 'HASH') {
6537: if (ref($settings->{$context}) eq 'ARRAY') {
6538: if (grep(/^\Q$types->[$i]\E$/,@{$settings->{$context}})) {
6539: $check = ' checked="checked" ';
6540: }
6541: } elsif ($context eq 'statustocreate') {
1.26 raeburn 6542: $check = ' checked="checked" ';
6543: }
1.23 raeburn 6544: }
1.26 raeburn 6545: $output .= '<td class="LC_left_item">'.
6546: '<span class="LC_nobreak"><label>'.
1.93 raeburn 6547: '<input type="checkbox" name="'.$context.'" '.
1.26 raeburn 6548: 'value="'.$types->[$i].'"'.$check.'/>'.
6549: $usertypes->{$types->[$i]}.'</label></span></td>';
1.23 raeburn 6550: }
6551: }
1.26 raeburn 6552: $rem = @{$types}%($numinrow);
1.23 raeburn 6553: }
6554: my $colsleft = $numinrow - $rem;
1.131 raeburn 6555: if (($rem == 0) && (@{$types} > 0)) {
6556: $output .= '<tr>';
6557: }
1.23 raeburn 6558: if ($colsleft > 1) {
1.25 raeburn 6559: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
1.23 raeburn 6560: } else {
1.25 raeburn 6561: $output .= '<td class="LC_left_item">';
1.23 raeburn 6562: }
6563: my $defcheck = ' ';
1.99 raeburn 6564: if (ref($settings) eq 'HASH') {
6565: if (ref($settings->{$context}) eq 'ARRAY') {
6566: if (grep(/^default$/,@{$settings->{$context}})) {
6567: $defcheck = ' checked="checked" ';
6568: }
6569: } elsif ($context eq 'statustocreate') {
1.26 raeburn 6570: $defcheck = ' checked="checked" ';
6571: }
1.23 raeburn 6572: }
1.25 raeburn 6573: $output .= '<span class="LC_nobreak"><label>'.
1.93 raeburn 6574: '<input type="checkbox" name="'.$context.'" '.
1.25 raeburn 6575: 'value="default"'.$defcheck.'/>'.
6576: $othertitle.'</label></span></td>'.
6577: '</tr></table></td></tr>';
6578: return $output;
1.23 raeburn 6579: }
6580:
6581: sub sorted_searchtitles {
6582: my %searchtitles = &Apache::lonlocal::texthash(
6583: 'uname' => 'username',
6584: 'lastname' => 'last name',
6585: 'lastfirst' => 'last name, first name',
6586: );
6587: my @titleorder = ('uname','lastname','lastfirst');
6588: return (\%searchtitles,\@titleorder);
6589: }
6590:
1.25 raeburn 6591: sub sorted_searchtypes {
6592: my %srchtypes_desc = (
6593: exact => 'is exact match',
6594: contains => 'contains ..',
6595: begins => 'begins with ..',
6596: );
6597: my @srchtypeorder = ('exact','begins','contains');
6598: return (\%srchtypes_desc,\@srchtypeorder);
6599: }
6600:
1.3 raeburn 6601: sub usertype_update_row {
6602: my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
6603: my $datatable;
6604: my $numinrow = 4;
6605: foreach my $type (@{$types}) {
6606: if (defined($usertypes->{$type})) {
6607: $$rownums ++;
6608: my $css_class = $$rownums%2?' class="LC_odd_row"':'';
6609: $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
6610: '</td><td class="LC_left_item"><table>';
6611: for (my $i=0; $i<@{$fields}; $i++) {
6612: my $rem = $i%($numinrow);
6613: if ($rem == 0) {
6614: if ($i > 0) {
6615: $datatable .= '</tr>';
6616: }
6617: $datatable .= '<tr>';
6618: }
6619: my $check = ' ';
1.39 raeburn 6620: if (ref($settings) eq 'HASH') {
6621: if (ref($settings->{'fields'}) eq 'HASH') {
6622: if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
6623: if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
6624: $check = ' checked="checked" ';
6625: }
1.3 raeburn 6626: }
6627: }
6628: }
6629:
6630: if ($i == @{$fields}-1) {
6631: my $colsleft = $numinrow - $rem;
6632: if ($colsleft > 1) {
6633: $datatable .= '<td colspan="'.$colsleft.'">';
6634: } else {
6635: $datatable .= '<td>';
6636: }
6637: } else {
6638: $datatable .= '<td>';
6639: }
1.8 raeburn 6640: $datatable .= '<span class="LC_nobreak"><label>'.
6641: '<input type="checkbox" name="updateable_'.$type.
6642: '_'.$fields->[$i].'" value="1"'.$check.'/>'.
6643: $fieldtitles->{$fields->[$i]}.'</label></span></td>';
1.3 raeburn 6644: }
6645: $datatable .= '</tr></table></td></tr>';
6646: }
6647: }
6648: return $datatable;
1.1 raeburn 6649: }
6650:
6651: sub modify_login {
1.205 raeburn 6652: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.168 raeburn 6653: my ($resulttext,$errors,$colchgtext,%changes,%colchanges,%newfile,%newurl,
6654: %curr_loginvia,%loginhash,@currlangs,@newlangs,$addedfile,%title,@offon);
6655: %title = ( coursecatalog => 'Display course catalog',
6656: adminmail => 'Display administrator E-mail address',
1.188 raeburn 6657: helpdesk => 'Display "Contact Helpdesk" link',
1.168 raeburn 6658: newuser => 'Link for visitors to create a user account',
6659: loginheader => 'Log-in box header');
6660: @offon = ('off','on');
1.112 raeburn 6661: if (ref($domconfig{login}) eq 'HASH') {
6662: if (ref($domconfig{login}{loginvia}) eq 'HASH') {
6663: foreach my $lonhost (keys(%{$domconfig{login}{loginvia}})) {
6664: $curr_loginvia{$lonhost} = $domconfig{login}{loginvia}{$lonhost};
6665: }
6666: }
6667: }
1.9 raeburn 6668: ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
6669: \%domconfig,\%loginhash);
1.188 raeburn 6670: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 6671: foreach my $item (@toggles) {
6672: $loginhash{login}{$item} = $env{'form.'.$item};
6673: }
1.41 raeburn 6674: $loginhash{login}{loginheader} = $env{'form.loginheader'};
1.6 raeburn 6675: if (ref($colchanges{'login'}) eq 'HASH') {
6676: $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
6677: \%loginhash);
6678: }
1.110 raeburn 6679:
1.149 raeburn 6680: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.256 raeburn 6681: my %domservers = &Apache::lonnet::get_servers($dom);
1.128 raeburn 6682: my @loginvia_attribs = ('serverpath','custompath','exempt');
1.110 raeburn 6683: if (keys(%servers) > 1) {
6684: foreach my $lonhost (keys(%servers)) {
1.128 raeburn 6685: next if ($env{'form.'.$lonhost.'_server'} eq $lonhost);
6686: if (ref($curr_loginvia{$lonhost}) eq 'HASH') {
6687: if ($env{'form.'.$lonhost.'_server'} eq $curr_loginvia{$lonhost}{'server'}) {
6688: $loginhash{login}{loginvia}{$lonhost}{'server'} = $curr_loginvia{$lonhost}{'server'};
6689: } elsif ($curr_loginvia{$lonhost}{'server'} ne '') {
6690: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
6691: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
6692: $changes{'loginvia'}{$lonhost} = 1;
6693: } else {
6694: $loginhash{login}{loginvia}{$lonhost}{'server'} = '';
6695: $changes{'loginvia'}{$lonhost} = 1;
6696: }
6697: } else {
6698: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
6699: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
6700: $changes{'loginvia'}{$lonhost} = 1;
6701: }
6702: }
6703: if ($loginhash{login}{loginvia}{$lonhost}{'server'} eq '') {
6704: foreach my $item (@loginvia_attribs) {
6705: $loginhash{login}{loginvia}{$lonhost}{$item} = '';
6706: }
6707: } else {
6708: foreach my $item (@loginvia_attribs) {
6709: my $new = $env{'form.'.$lonhost.'_'.$item};
6710: if (($item eq 'serverpath') && ($new eq 'custom')) {
6711: $env{'form.'.$lonhost.'_custompath'} =~ s/\s+//g;
6712: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
6713: $new = '/';
6714: }
6715: }
6716: if (($item eq 'custompath') &&
6717: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
6718: $new = '';
6719: }
6720: if ($new ne $curr_loginvia{$lonhost}{$item}) {
6721: $changes{'loginvia'}{$lonhost} = 1;
6722: }
6723: if ($item eq 'exempt') {
1.256 raeburn 6724: $new = &check_exempt_addresses($new);
1.128 raeburn 6725: }
6726: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
6727: }
6728: }
1.112 raeburn 6729: } else {
1.128 raeburn 6730: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
6731: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
1.112 raeburn 6732: $changes{'loginvia'}{$lonhost} = 1;
1.128 raeburn 6733: foreach my $item (@loginvia_attribs) {
6734: my $new = $env{'form.'.$lonhost.'_'.$item};
6735: if (($item eq 'serverpath') && ($new eq 'custom')) {
6736: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
6737: $new = '/';
6738: }
6739: }
6740: if (($item eq 'custompath') &&
6741: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
6742: $new = '';
6743: }
6744: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
6745: }
1.110 raeburn 6746: }
6747: }
6748: }
6749: }
1.119 raeburn 6750:
1.168 raeburn 6751: my $servadm = $r->dir_config('lonAdmEMail');
6752: my %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
6753: if (ref($domconfig{'login'}) eq 'HASH') {
6754: if (ref($domconfig{'login'}{'helpurl'}) eq 'HASH') {
6755: foreach my $lang (sort(keys(%{$domconfig{'login'}{'helpurl'}}))) {
6756: if ($lang eq 'nolang') {
6757: push(@currlangs,$lang);
6758: } elsif (defined($langchoices{$lang})) {
6759: push(@currlangs,$lang);
6760: } else {
6761: next;
6762: }
6763: }
6764: }
6765: }
6766: my @delurls = &Apache::loncommon::get_env_multiple('form.loginhelpurl_del');
6767: if (@currlangs > 0) {
6768: foreach my $lang (@currlangs) {
6769: if (grep(/^\Q$lang\E$/,@delurls)) {
6770: $changes{'helpurl'}{$lang} = 1;
6771: } elsif ($env{'form.loginhelpurl_'.$lang.'.filename'}) {
6772: $changes{'helpurl'}{$lang} = 1;
6773: $newfile{$lang} = $env{'form.loginhelpurl_'.$lang.'.filename'};
6774: push(@newlangs,$lang);
6775: } else {
6776: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
6777: }
6778: }
6779: }
6780: unless (grep(/^nolang$/,@currlangs)) {
6781: if ($env{'form.loginhelpurl_nolang.filename'}) {
6782: $changes{'helpurl'}{'nolang'} = 1;
6783: $newfile{'nolang'} = $env{'form.loginhelpurl_nolang.filename'};
6784: push(@newlangs,'nolang');
6785: }
6786: }
6787: if ($env{'form.loginhelpurl_add_lang'}) {
6788: if ((defined($langchoices{$env{'form.loginhelpurl_add_lang'}})) &&
6789: ($env{'form.loginhelpurl_add_file.filename'})) {
6790: $newfile{$env{'form.loginhelpurl_add_lang'}} = $env{'form.loginhelpurl_add_file.filename'};
6791: $addedfile = $env{'form.loginhelpurl_add_lang'};
6792: }
6793: }
6794: if ((@newlangs > 0) || ($addedfile)) {
6795: my $error;
6796: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
6797: if ($configuserok eq 'ok') {
6798: if ($switchserver) {
6799: $error = &mt("Upload of custom help file is not permitted to this server: [_1]",$switchserver);
6800: } elsif ($author_ok eq 'ok') {
6801: my @allnew = @newlangs;
6802: if ($addedfile ne '') {
6803: push(@allnew,$addedfile);
6804: }
6805: foreach my $lang (@allnew) {
6806: my $formelem = 'loginhelpurl_'.$lang;
6807: if ($lang eq $env{'form.loginhelpurl_add_lang'}) {
6808: $formelem = 'loginhelpurl_add_file';
6809: }
6810: (my $result,$newurl{$lang}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
6811: "help/$lang",'','',$newfile{$lang});
6812: if ($result eq 'ok') {
6813: $loginhash{'login'}{'helpurl'}{$lang} = $newurl{$lang};
6814: $changes{'helpurl'}{$lang} = 1;
6815: } else {
6816: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$newfile{$lang},$result);
6817: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
1.210 raeburn 6818: if ((grep(/^\Q$lang\E$/,@currlangs)) &&
1.168 raeburn 6819: (!grep(/^\Q$lang\E$/,@delurls))) {
6820: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
6821: }
6822: }
6823: }
6824: } else {
6825: $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);
6826: }
6827: } else {
6828: $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);
6829: }
6830: if ($error) {
6831: &Apache::lonnet::logthis($error);
6832: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
6833: }
6834: }
1.256 raeburn 6835:
6836: my (%currheadtagurls,%currexempt,@newhosts,%newheadtagurls,%possexempt);
6837: if (ref($domconfig{'login'}) eq 'HASH') {
6838: if (ref($domconfig{'login'}{'headtag'}) eq 'HASH') {
6839: foreach my $lonhost (keys(%{$domconfig{'login'}{'headtag'}})) {
6840: if ($domservers{$lonhost}) {
6841: if (ref($domconfig{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
6842: $currheadtagurls{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'url'};
1.268 raeburn 6843: $currexempt{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'exempt'};
1.256 raeburn 6844: }
6845: }
6846: }
6847: }
6848: }
6849: my @delheadtagurls = &Apache::loncommon::get_env_multiple('form.loginheadtag_del');
6850: foreach my $lonhost (sort(keys(%domservers))) {
6851: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
6852: $changes{'headtag'}{$lonhost} = 1;
6853: } else {
6854: if ($env{'form.loginheadtagexempt_'.$lonhost}) {
6855: $possexempt{$lonhost} = &check_exempt_addresses($env{'form.loginheadtagexempt_'.$lonhost});
6856: }
6857: if ($env{'form.loginheadtag_'.$lonhost.'.filename'}) {
6858: push(@newhosts,$lonhost);
6859: } elsif ($currheadtagurls{$lonhost}) {
6860: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $currheadtagurls{$lonhost};
6861: if ($currexempt{$lonhost}) {
6862: if ((!exists($possexempt{$lonhost})) || ($possexempt{$lonhost} ne $currexempt{$lonhost})) {
6863: $changes{'headtag'}{$lonhost} = 1;
6864: }
6865: } elsif ($possexempt{$lonhost}) {
6866: $changes{'headtag'}{$lonhost} = 1;
6867: }
6868: if ($possexempt{$lonhost}) {
6869: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
6870: }
6871: }
6872: }
6873: }
6874: if (@newhosts) {
6875: my $error;
6876: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
6877: if ($configuserok eq 'ok') {
6878: if ($switchserver) {
6879: $error = &mt("Upload of custom markup is not permitted to this server: [_1]",$switchserver);
6880: } elsif ($author_ok eq 'ok') {
6881: foreach my $lonhost (@newhosts) {
6882: my $formelem = 'loginheadtag_'.$lonhost;
6883: (my $result,$newheadtagurls{$lonhost}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
6884: "login/headtag/$lonhost",'','',
6885: $env{'form.loginheadtag_'.$lonhost.'.filename'});
6886: if ($result eq 'ok') {
6887: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $newheadtagurls{$lonhost};
6888: $changes{'headtag'}{$lonhost} = 1;
6889: if ($possexempt{$lonhost}) {
6890: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
6891: }
6892: } else {
6893: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",
6894: $newheadtagurls{$lonhost},$result);
6895: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
6896: if ((grep(/^\Q$lonhost\E$/,keys(%currheadtagurls))) &&
6897: (!grep(/^\Q$lonhost\E$/,@delheadtagurls))) {
6898: $loginhash{'login'}{'headtag'}{$lonhost} = $currheadtagurls{$lonhost};
6899: }
6900: }
6901: }
6902: } else {
6903: $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);
6904: }
6905: } else {
6906: $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);
6907: }
6908: if ($error) {
6909: &Apache::lonnet::logthis($error);
6910: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
6911: }
6912: }
1.169 raeburn 6913: &process_captcha('login',\%changes,$loginhash{'login'},$domconfig{'login'});
1.168 raeburn 6914:
6915: my $defaulthelpfile = '/adm/loginproblems.html';
6916: my $defaulttext = &mt('Default in use');
6917:
1.1 raeburn 6918: my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
6919: $dom);
6920: if ($putresult eq 'ok') {
1.188 raeburn 6921: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 6922: my %defaultchecked = (
6923: 'coursecatalog' => 'on',
1.188 raeburn 6924: 'helpdesk' => 'on',
1.42 raeburn 6925: 'adminmail' => 'off',
1.43 raeburn 6926: 'newuser' => 'off',
1.42 raeburn 6927: );
1.55 raeburn 6928: if (ref($domconfig{'login'}) eq 'HASH') {
6929: foreach my $item (@toggles) {
6930: if ($defaultchecked{$item} eq 'on') {
6931: if (($domconfig{'login'}{$item} eq '0') &&
6932: ($env{'form.'.$item} eq '1')) {
6933: $changes{$item} = 1;
6934: } elsif (($domconfig{'login'}{$item} eq '' ||
6935: $domconfig{'login'}{$item} eq '1') &&
6936: ($env{'form.'.$item} eq '0')) {
6937: $changes{$item} = 1;
6938: }
6939: } elsif ($defaultchecked{$item} eq 'off') {
6940: if (($domconfig{'login'}{$item} eq '1') &&
6941: ($env{'form.'.$item} eq '0')) {
6942: $changes{$item} = 1;
6943: } elsif (($domconfig{'login'}{$item} eq '' ||
6944: $domconfig{'login'}{$item} eq '0') &&
6945: ($env{'form.'.$item} eq '1')) {
6946: $changes{$item} = 1;
6947: }
1.42 raeburn 6948: }
6949: }
1.41 raeburn 6950: }
1.6 raeburn 6951: if (keys(%changes) > 0 || $colchgtext) {
1.41 raeburn 6952: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 6953: if (ref($lastactref) eq 'HASH') {
6954: $lastactref->{'domainconfig'} = 1;
6955: }
1.1 raeburn 6956: $resulttext = &mt('Changes made:').'<ul>';
6957: foreach my $item (sort(keys(%changes))) {
1.135 bisitz 6958: if ($item eq 'loginvia') {
1.112 raeburn 6959: if (ref($changes{$item}) eq 'HASH') {
6960: $resulttext .= '<li>'.&mt('Log-in page availability:').'<ul>';
6961: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
1.128 raeburn 6962: if (defined($servers{$loginhash{login}{loginvia}{$lonhost}{'server'}})) {
6963: if (ref($loginhash{login}{loginvia}{$lonhost}) eq 'HASH') {
6964: my $protocol = $Apache::lonnet::protocol{$env{'form.'.$lonhost.'_server'}};
6965: $protocol = 'http' if ($protocol ne 'https');
6966: my $target = $protocol.'://'.$servers{$env{'form.'.$lonhost.'_server'}};
6967:
6968: if ($loginhash{login}{loginvia}{$lonhost}{'serverpath'} eq 'custom') {
6969: $target .= $loginhash{login}{loginvia}{$lonhost}{'custompath'};
6970: } else {
6971: $target .= $loginhash{login}{loginvia}{$lonhost}{'serverpath'};
6972: }
6973: $resulttext .= '<li>'.&mt('Server: [_1] log-in page redirects to [_2].',$servers{$lonhost},'<a href="'.$target.'">'.$target.'</a>');
6974: if ($loginhash{login}{loginvia}{$lonhost}{'exempt'} ne '') {
6975: $resulttext .= ' '.&mt('No redirection for clients from following IPs:').' '.$loginhash{login}{loginvia}{$lonhost}{'exempt'};
6976: }
6977: $resulttext .= '</li>';
6978: } else {
6979: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$lonhost).'</li>';
6980: }
1.112 raeburn 6981: } else {
1.128 raeburn 6982: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$servers{$lonhost}).'</li>';
1.112 raeburn 6983: }
6984: }
1.128 raeburn 6985: $resulttext .= '</ul></li>';
1.112 raeburn 6986: }
1.168 raeburn 6987: } elsif ($item eq 'helpurl') {
6988: if (ref($changes{$item}) eq 'HASH') {
6989: foreach my $lang (sort(keys(%{$changes{$item}}))) {
6990: if (grep(/^\Q$lang\E$/,@delurls)) {
6991: my ($chg,$link);
6992: $link = &Apache::loncommon::modal_link($defaulthelpfile,$defaulttext,600,500);
6993: if ($lang eq 'nolang') {
6994: $chg = &mt('custom log-in help file removed for no preferred language; [_1]',$link);
6995: } else {
6996: $chg = &mt('custom log-in help file removed for specific language: [_1]; [_2]',$langchoices{$lang},$link);
6997: }
6998: $resulttext .= '<li>'.$chg.'</li>';
6999: } else {
7000: my $chg;
7001: if ($lang eq 'nolang') {
7002: $chg = &mt('custom log-in help file for no preferred language');
7003: } else {
7004: $chg = &mt('custom log-in help file for specific language: [_1]',$langchoices{$lang});
7005: }
7006: $resulttext .= '<li>'.&Apache::loncommon::modal_link(
7007: $loginhash{'login'}{'helpurl'}{$lang}.
7008: '?inhibitmenu=yes',$chg,600,500).
7009: '</li>';
7010: }
7011: }
7012: }
1.256 raeburn 7013: } elsif ($item eq 'headtag') {
7014: if (ref($changes{$item}) eq 'HASH') {
7015: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
7016: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
7017: $resulttext .= '<li>'.&mt('custom markup file removed for [_1]',$domservers{$lonhost}).'</li>';
7018: } elsif (ref($loginhash{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
7019: $resulttext .= '<li><a href="'.
7020: "javascript:void(open('$loginhash{'login'}{'headtag'}{$lonhost}{'url'}?inhibitmenu=yes','Custom_HeadTag',
7021: 'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
7022: '">'.&mt('custom markup').'</a> '.&mt('(for [_1])',$servers{$lonhost}).' ';
7023: if ($possexempt{$lonhost}) {
7024: $resulttext .= &mt('not included for client IP(s): [_1]',$possexempt{$lonhost});
7025: } else {
7026: $resulttext .= &mt('included for any client IP');
7027: }
7028: $resulttext .= '</li>';
7029: }
7030: }
7031: }
1.169 raeburn 7032: } elsif ($item eq 'captcha') {
7033: if (ref($loginhash{'login'}) eq 'HASH') {
1.210 raeburn 7034: my $chgtxt;
1.169 raeburn 7035: if ($loginhash{'login'}{$item} eq 'notused') {
7036: $chgtxt .= &mt('No CAPTCHA validation in use for helpdesk form.');
7037: } else {
7038: my %captchas = &captcha_phrases();
7039: if ($captchas{$loginhash{'login'}{$item}}) {
7040: $chgtxt .= &mt("Validation for helpdesk form set to $captchas{$loginhash{'login'}{$item}}.");
7041: } else {
7042: $chgtxt .= &mt('Validation for helpdesk form set to unknown type.');
7043: }
7044: }
7045: $resulttext .= '<li>'.$chgtxt.'</li>';
7046: }
7047: } elsif ($item eq 'recaptchakeys') {
7048: if (ref($loginhash{'login'}) eq 'HASH') {
7049: my ($privkey,$pubkey);
7050: if (ref($loginhash{'login'}{$item}) eq 'HASH') {
7051: $pubkey = $loginhash{'login'}{$item}{'public'};
7052: $privkey = $loginhash{'login'}{$item}{'private'};
7053: }
7054: my $chgtxt .= &mt('ReCAPTCHA keys changes').'<ul>';
7055: if (!$pubkey) {
7056: $chgtxt .= '<li>'.&mt('Public key deleted').'</li>';
7057: } else {
7058: $chgtxt .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
7059: }
7060: if (!$privkey) {
7061: $chgtxt .= '<li>'.&mt('Private key deleted').'</li>';
7062: } else {
1.251 raeburn 7063: $chgtxt .= '<li>'.&mt('Private key set to [_1]',$privkey).'</li>';
1.169 raeburn 7064: }
7065: $chgtxt .= '</ul>';
7066: $resulttext .= '<li>'.$chgtxt.'</li>';
7067: }
1.269 raeburn 7068: } elsif ($item eq 'recaptchaversion') {
7069: if (ref($loginhash{'login'}) eq 'HASH') {
7070: if ($loginhash{'login'}{'captcha'} eq 'recaptcha') {
1.270 raeburn 7071: $resulttext .= '<li>'.&mt('ReCAPTCHA for helpdesk form set to version [_1]',$loginhash{'login'}{'recaptchaversion'}).
1.269 raeburn 7072: '</li>';
7073: }
7074: }
1.41 raeburn 7075: } else {
7076: $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
7077: }
1.1 raeburn 7078: }
1.6 raeburn 7079: $resulttext .= $colchgtext.'</ul>';
1.1 raeburn 7080: } else {
7081: $resulttext = &mt('No changes made to log-in page settings');
7082: }
7083: } else {
1.11 albertel 7084: $resulttext = '<span class="LC_error">'.
7085: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 7086: }
1.6 raeburn 7087: if ($errors) {
1.9 raeburn 7088: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.6 raeburn 7089: $errors.'</ul>';
7090: }
7091: return $resulttext;
7092: }
7093:
1.256 raeburn 7094:
7095: sub check_exempt_addresses {
7096: my ($iplist) = @_;
7097: $iplist =~ s/^\s+//;
7098: $iplist =~ s/\s+$//;
7099: my @poss_ips = split(/\s*[,:]\s*/,$iplist);
7100: my (@okips,$new);
7101: foreach my $ip (@poss_ips) {
7102: if ($ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
7103: if (($1 <= 255) && ($2 <= 255) && ($3 <= 255) && ($4 <= 255)) {
7104: push(@okips,$ip);
7105: }
7106: }
7107: }
7108: if (@okips > 0) {
7109: $new = join(',',@okips);
7110: } else {
7111: $new = '';
7112: }
7113: return $new;
7114: }
7115:
1.6 raeburn 7116: sub color_font_choices {
7117: my %choices =
7118: &Apache::lonlocal::texthash (
7119: img => "Header",
7120: bgs => "Background colors",
7121: links => "Link colors",
1.55 raeburn 7122: images => "Images",
1.6 raeburn 7123: font => "Font color",
1.201 raeburn 7124: fontmenu => "Font menu",
1.76 raeburn 7125: pgbg => "Page",
1.6 raeburn 7126: tabbg => "Header",
7127: sidebg => "Border",
7128: link => "Link",
7129: alink => "Active link",
7130: vlink => "Visited link",
7131: );
7132: return %choices;
7133: }
7134:
7135: sub modify_rolecolors {
1.205 raeburn 7136: my ($r,$dom,$confname,$roles,$lastactref,%domconfig) = @_;
1.6 raeburn 7137: my ($resulttext,%rolehash);
7138: $rolehash{'rolecolors'} = {};
1.55 raeburn 7139: if (ref($domconfig{'rolecolors'}) ne 'HASH') {
7140: if ($domconfig{'rolecolors'} eq '') {
7141: $domconfig{'rolecolors'} = {};
7142: }
7143: }
1.9 raeburn 7144: my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
1.6 raeburn 7145: $domconfig{'rolecolors'},$rolehash{'rolecolors'});
7146: my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
7147: $dom);
7148: if ($putresult eq 'ok') {
7149: if (keys(%changes) > 0) {
1.41 raeburn 7150: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 7151: if (ref($lastactref) eq 'HASH') {
7152: $lastactref->{'domainconfig'} = 1;
7153: }
1.6 raeburn 7154: $resulttext = &display_colorchgs($dom,\%changes,$roles,
7155: $rolehash{'rolecolors'});
7156: } else {
7157: $resulttext = &mt('No changes made to default color schemes');
7158: }
7159: } else {
1.11 albertel 7160: $resulttext = '<span class="LC_error">'.
7161: &mt('An error occurred: [_1]',$putresult).'</span>';
1.6 raeburn 7162: }
7163: if ($errors) {
7164: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
7165: $errors.'</ul>';
7166: }
7167: return $resulttext;
7168: }
7169:
7170: sub modify_colors {
1.9 raeburn 7171: my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
1.12 raeburn 7172: my (%changes,%choices);
1.51 raeburn 7173: my @bgs;
1.6 raeburn 7174: my @links = ('link','alink','vlink');
1.41 raeburn 7175: my @logintext;
1.6 raeburn 7176: my @images;
7177: my $servadm = $r->dir_config('lonAdmEMail');
7178: my $errors;
1.200 raeburn 7179: my %defaults;
1.6 raeburn 7180: foreach my $role (@{$roles}) {
7181: if ($role eq 'login') {
1.12 raeburn 7182: %choices = &login_choices();
1.41 raeburn 7183: @logintext = ('textcol','bgcol');
1.12 raeburn 7184: } else {
7185: %choices = &color_font_choices();
7186: }
7187: if ($role eq 'login') {
1.41 raeburn 7188: @images = ('img','logo','domlogo','login');
1.51 raeburn 7189: @bgs = ('pgbg','mainbg','sidebg');
1.6 raeburn 7190: } else {
7191: @images = ('img');
1.200 raeburn 7192: @bgs = ('pgbg','tabbg','sidebg');
7193: }
7194: my %defaults = &role_defaults($role,\@bgs,\@links,\@images,\@logintext);
7195: unless ($env{'form.'.$role.'_font'} eq $defaults{'font'}) {
7196: $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
7197: }
7198: if ($role eq 'login') {
7199: foreach my $item (@logintext) {
1.234 raeburn 7200: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
7201: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
7202: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
7203: }
7204: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'logintext'}{$item})) {
1.200 raeburn 7205: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
7206: }
7207: }
7208: } else {
1.234 raeburn 7209: $env{'form.'.$role.'_fontmenu'} = lc($env{'form.'.$role.'_fontmenu'});
7210: if ($env{'form.'.$role.'_fontmenu'} =~ /^\w+/) {
7211: $env{'form.'.$role.'_fontmenu'} = '#'.$env{'form.'.$role.'_fontmenu'};
7212: }
7213: unless($env{'form.'.$role.'_fontmenu'} eq lc($defaults{'fontmenu'})) {
1.200 raeburn 7214: $confhash->{$role}{'fontmenu'} = $env{'form.'.$role.'_fontmenu'};
7215: }
1.6 raeburn 7216: }
1.200 raeburn 7217: foreach my $item (@bgs) {
1.234 raeburn 7218: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
7219: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
7220: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
7221: }
7222: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'bgs'}{$item})) {
1.200 raeburn 7223: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
7224: }
7225: }
7226: foreach my $item (@links) {
1.234 raeburn 7227: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
7228: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
7229: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
7230: }
7231: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'links'}{$item})) {
1.200 raeburn 7232: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
7233: }
1.6 raeburn 7234: }
1.46 raeburn 7235: my ($configuserok,$author_ok,$switchserver) =
7236: &config_check($dom,$confname,$servadm);
1.9 raeburn 7237: my ($width,$height) = &thumb_dimensions();
1.40 raeburn 7238: if (ref($domconfig->{$role}) ne 'HASH') {
7239: $domconfig->{$role} = {};
7240: }
1.8 raeburn 7241: foreach my $img (@images) {
1.70 raeburn 7242: if (($role eq 'login') && (($img eq 'img') || ($img eq 'logo'))) {
7243: if (defined($env{'form.login_showlogo_'.$img})) {
7244: $confhash->{$role}{'showlogo'}{$img} = 1;
7245: } else {
7246: $confhash->{$role}{'showlogo'}{$img} = 0;
7247: }
7248: }
1.18 albertel 7249: if ( ! $env{'form.'.$role.'_'.$img.'.filename'}
7250: && !defined($domconfig->{$role}{$img})
7251: && !$env{'form.'.$role.'_del_'.$img}
7252: && $env{'form.'.$role.'_import_'.$img}) {
7253: # import the old configured image from the .tab setting
7254: # if they haven't provided a new one
7255: $domconfig->{$role}{$img} =
7256: $env{'form.'.$role.'_import_'.$img};
7257: }
1.6 raeburn 7258: if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
1.9 raeburn 7259: my $error;
1.6 raeburn 7260: if ($configuserok eq 'ok') {
1.9 raeburn 7261: if ($switchserver) {
1.12 raeburn 7262: $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
1.9 raeburn 7263: } else {
7264: if ($author_ok eq 'ok') {
7265: my ($result,$logourl) =
7266: &publishlogo($r,'upload',$role.'_'.$img,
7267: $dom,$confname,$img,$width,$height);
7268: if ($result eq 'ok') {
7269: $confhash->{$role}{$img} = $logourl;
1.12 raeburn 7270: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 7271: } else {
1.12 raeburn 7272: $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 7273: }
7274: } else {
1.46 raeburn 7275: $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 7276: }
7277: }
7278: } else {
1.46 raeburn 7279: $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 7280: }
7281: if ($error) {
1.8 raeburn 7282: &Apache::lonnet::logthis($error);
1.11 albertel 7283: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
1.8 raeburn 7284: }
7285: } elsif ($domconfig->{$role}{$img} ne '') {
1.9 raeburn 7286: if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
7287: my $error;
7288: if ($configuserok eq 'ok') {
7289: # is confname an author?
7290: if ($switchserver eq '') {
7291: if ($author_ok eq 'ok') {
7292: my ($result,$logourl) =
7293: &publishlogo($r,'copy',$domconfig->{$role}{$img},
7294: $dom,$confname,$img,$width,$height);
7295: if ($result eq 'ok') {
7296: $confhash->{$role}{$img} = $logourl;
1.18 albertel 7297: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 7298: }
7299: }
7300: }
7301: }
1.6 raeburn 7302: }
7303: }
7304: }
7305: if (ref($domconfig) eq 'HASH') {
7306: if (ref($domconfig->{$role}) eq 'HASH') {
7307: foreach my $img (@images) {
7308: if ($domconfig->{$role}{$img} ne '') {
7309: if ($env{'form.'.$role.'_del_'.$img}) {
7310: $confhash->{$role}{$img} = '';
1.12 raeburn 7311: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 7312: } else {
1.9 raeburn 7313: if ($confhash->{$role}{$img} eq '') {
7314: $confhash->{$role}{$img} = $domconfig->{$role}{$img};
7315: }
1.6 raeburn 7316: }
7317: } else {
7318: if ($env{'form.'.$role.'_del_'.$img}) {
7319: $confhash->{$role}{$img} = '';
1.12 raeburn 7320: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 7321: }
7322: }
1.70 raeburn 7323: if (($role eq 'login') && (($img eq 'logo') || ($img eq 'img'))) {
7324: if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') {
7325: if ($confhash->{$role}{'showlogo'}{$img} ne
7326: $domconfig->{$role}{'showlogo'}{$img}) {
7327: $changes{$role}{'showlogo'}{$img} = 1;
7328: }
7329: } else {
7330: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
7331: $changes{$role}{'showlogo'}{$img} = 1;
7332: }
7333: }
7334: }
7335: }
1.6 raeburn 7336: if ($domconfig->{$role}{'font'} ne '') {
7337: if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
7338: $changes{$role}{'font'} = 1;
7339: }
7340: } else {
7341: if ($confhash->{$role}{'font'}) {
7342: $changes{$role}{'font'} = 1;
7343: }
7344: }
1.107 raeburn 7345: if ($role ne 'login') {
7346: if ($domconfig->{$role}{'fontmenu'} ne '') {
7347: if ($confhash->{$role}{'fontmenu'} ne $domconfig->{$role}{'fontmenu'}) {
7348: $changes{$role}{'fontmenu'} = 1;
7349: }
7350: } else {
7351: if ($confhash->{$role}{'fontmenu'}) {
7352: $changes{$role}{'fontmenu'} = 1;
7353: }
1.97 tempelho 7354: }
7355: }
1.6 raeburn 7356: foreach my $item (@bgs) {
7357: if ($domconfig->{$role}{$item} ne '') {
7358: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
7359: $changes{$role}{'bgs'}{$item} = 1;
7360: }
7361: } else {
7362: if ($confhash->{$role}{$item}) {
7363: $changes{$role}{'bgs'}{$item} = 1;
7364: }
7365: }
7366: }
7367: foreach my $item (@links) {
7368: if ($domconfig->{$role}{$item} ne '') {
7369: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
7370: $changes{$role}{'links'}{$item} = 1;
7371: }
7372: } else {
7373: if ($confhash->{$role}{$item}) {
7374: $changes{$role}{'links'}{$item} = 1;
7375: }
7376: }
7377: }
1.41 raeburn 7378: foreach my $item (@logintext) {
7379: if ($domconfig->{$role}{$item} ne '') {
7380: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
7381: $changes{$role}{'logintext'}{$item} = 1;
7382: }
7383: } else {
7384: if ($confhash->{$role}{$item}) {
7385: $changes{$role}{'logintext'}{$item} = 1;
7386: }
7387: }
7388: }
1.6 raeburn 7389: } else {
7390: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 7391: \@logintext,$confhash,\%changes);
1.6 raeburn 7392: }
7393: } else {
7394: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 7395: \@logintext,$confhash,\%changes);
1.6 raeburn 7396: }
7397: }
7398: return ($errors,%changes);
7399: }
7400:
1.46 raeburn 7401: sub config_check {
7402: my ($dom,$confname,$servadm) = @_;
7403: my ($configuserok,$author_ok,$switchserver,%currroles);
7404: my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
7405: ($configuserok,%currroles) = &check_configuser($uhome,$dom,
7406: $confname,$servadm);
7407: if ($configuserok eq 'ok') {
7408: $switchserver = &check_switchserver($dom,$confname);
7409: if ($switchserver eq '') {
7410: $author_ok = &check_authorstatus($dom,$confname,%currroles);
7411: }
7412: }
7413: return ($configuserok,$author_ok,$switchserver);
7414: }
7415:
1.6 raeburn 7416: sub default_change_checker {
1.41 raeburn 7417: my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
1.6 raeburn 7418: foreach my $item (@{$links}) {
7419: if ($confhash->{$role}{$item}) {
7420: $changes->{$role}{'links'}{$item} = 1;
7421: }
7422: }
7423: foreach my $item (@{$bgs}) {
7424: if ($confhash->{$role}{$item}) {
7425: $changes->{$role}{'bgs'}{$item} = 1;
7426: }
7427: }
1.41 raeburn 7428: foreach my $item (@{$logintext}) {
7429: if ($confhash->{$role}{$item}) {
7430: $changes->{$role}{'logintext'}{$item} = 1;
7431: }
7432: }
1.6 raeburn 7433: foreach my $img (@{$images}) {
7434: if ($env{'form.'.$role.'_del_'.$img}) {
7435: $confhash->{$role}{$img} = '';
1.12 raeburn 7436: $changes->{$role}{'images'}{$img} = 1;
1.6 raeburn 7437: }
1.70 raeburn 7438: if ($role eq 'login') {
7439: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
7440: $changes->{$role}{'showlogo'}{$img} = 1;
7441: }
7442: }
1.6 raeburn 7443: }
7444: if ($confhash->{$role}{'font'}) {
7445: $changes->{$role}{'font'} = 1;
7446: }
1.48 raeburn 7447: }
1.6 raeburn 7448:
7449: sub display_colorchgs {
7450: my ($dom,$changes,$roles,$confhash) = @_;
7451: my (%choices,$resulttext);
7452: if (!grep(/^login$/,@{$roles})) {
7453: $resulttext = &mt('Changes made:').'<br />';
7454: }
7455: foreach my $role (@{$roles}) {
7456: if ($role eq 'login') {
7457: %choices = &login_choices();
7458: } else {
7459: %choices = &color_font_choices();
7460: }
7461: if (ref($changes->{$role}) eq 'HASH') {
7462: if ($role ne 'login') {
7463: $resulttext .= '<h4>'.&mt($role).'</h4>';
7464: }
7465: foreach my $key (sort(keys(%{$changes->{$role}}))) {
7466: if ($role ne 'login') {
7467: $resulttext .= '<ul>';
7468: }
7469: if (ref($changes->{$role}{$key}) eq 'HASH') {
7470: if ($role ne 'login') {
7471: $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
7472: }
7473: foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
1.70 raeburn 7474: if (($role eq 'login') && ($key eq 'showlogo')) {
7475: if ($confhash->{$role}{$key}{$item}) {
7476: $resulttext .= '<li>'.&mt("$choices{$item} set to be displayed").'</li>';
7477: } else {
7478: $resulttext .= '<li>'.&mt("$choices{$item} set to not be displayed").'</li>';
7479: }
7480: } elsif ($confhash->{$role}{$item} eq '') {
1.6 raeburn 7481: $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
7482: } else {
1.12 raeburn 7483: my $newitem = $confhash->{$role}{$item};
7484: if ($key eq 'images') {
7485: $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" valign="bottom" />';
7486: }
7487: $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
1.6 raeburn 7488: }
7489: }
7490: if ($role ne 'login') {
7491: $resulttext .= '</ul></li>';
7492: }
7493: } else {
7494: if ($confhash->{$role}{$key} eq '') {
7495: $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
7496: } else {
7497: $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
7498: }
7499: }
7500: if ($role ne 'login') {
7501: $resulttext .= '</ul>';
7502: }
7503: }
7504: }
7505: }
1.3 raeburn 7506: return $resulttext;
1.1 raeburn 7507: }
7508:
1.9 raeburn 7509: sub thumb_dimensions {
7510: return ('200','50');
7511: }
7512:
1.16 raeburn 7513: sub check_dimensions {
7514: my ($inputfile) = @_;
7515: my ($fullwidth,$fullheight);
7516: if ($inputfile =~ m|^[/\w.\-]+$|) {
7517: if (open(PIPE,"identify $inputfile 2>&1 |")) {
7518: my $imageinfo = <PIPE>;
7519: if (!close(PIPE)) {
7520: &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
7521: }
7522: chomp($imageinfo);
7523: my ($fullsize) =
1.21 raeburn 7524: ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
1.16 raeburn 7525: if ($fullsize) {
7526: ($fullwidth,$fullheight) = split(/x/,$fullsize);
7527: }
7528: }
7529: }
7530: return ($fullwidth,$fullheight);
7531: }
7532:
1.9 raeburn 7533: sub check_configuser {
7534: my ($uhome,$dom,$confname,$servadm) = @_;
7535: my ($configuserok,%currroles);
7536: if ($uhome eq 'no_host') {
7537: srand( time() ^ ($$ + ($$ << 15)) ); # Seed rand.
7538: my $configpass = &LONCAPA::Enrollment::create_password();
7539: $configuserok =
7540: &Apache::lonnet::modifyuser($dom,$confname,'','internal',
7541: $configpass,'','','','','',undef,$servadm);
7542: } else {
7543: $configuserok = 'ok';
7544: %currroles =
7545: &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
7546: }
7547: return ($configuserok,%currroles);
7548: }
7549:
7550: sub check_authorstatus {
7551: my ($dom,$confname,%currroles) = @_;
7552: my $author_ok;
1.40 raeburn 7553: if (!$currroles{':'.$dom.':au'}) {
1.9 raeburn 7554: my $start = time;
7555: my $end = 0;
7556: $author_ok =
7557: &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
1.47 raeburn 7558: 'au',$end,$start,'','','domconfig');
1.9 raeburn 7559: } else {
7560: $author_ok = 'ok';
7561: }
7562: return $author_ok;
7563: }
7564:
7565: sub publishlogo {
1.46 raeburn 7566: my ($r,$action,$formname,$dom,$confname,$subdir,$thumbwidth,$thumbheight,$savefileas) = @_;
1.267 raeburn 7567: my ($output,$fname,$logourl,$madethumb);
1.9 raeburn 7568: if ($action eq 'upload') {
7569: $fname=$env{'form.'.$formname.'.filename'};
7570: chop($env{'form.'.$formname});
7571: } else {
7572: ($fname) = ($formname =~ /([^\/]+)$/);
7573: }
1.46 raeburn 7574: if ($savefileas ne '') {
7575: $fname = $savefileas;
7576: }
1.9 raeburn 7577: $fname=&Apache::lonnet::clean_filename($fname);
7578: # See if there is anything left
7579: unless ($fname) { return ('error: no uploaded file'); }
7580: $fname="$subdir/$fname";
1.210 raeburn 7581: my $docroot=$r->dir_config('lonDocRoot');
1.164 raeburn 7582: my $filepath="$docroot/priv";
7583: my $relpath = "$dom/$confname";
1.9 raeburn 7584: my ($fnamepath,$file,$fetchthumb);
7585: $file=$fname;
7586: if ($fname=~m|/|) {
7587: ($fnamepath,$file) = ($fname =~ m|^(.*)/([^/]+)$|);
7588: }
1.164 raeburn 7589: my @parts=split(/\//,"$filepath/$relpath/$fnamepath");
1.9 raeburn 7590: my $count;
1.164 raeburn 7591: for ($count=5;$count<=$#parts;$count++) {
1.9 raeburn 7592: $filepath.="/$parts[$count]";
7593: if ((-e $filepath)!=1) {
7594: mkdir($filepath,02770);
7595: }
7596: }
7597: # Check for bad extension and disallow upload
7598: if ($file=~/\.(\w+)$/ &&
7599: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
7600: $output =
1.207 bisitz 7601: &mt('Invalid file extension ([_1]) - reserved for internal use.',$1);
1.9 raeburn 7602: } elsif ($file=~/\.(\w+)$/ &&
7603: !defined(&Apache::loncommon::fileembstyle($1))) {
7604: $output = &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
7605: } elsif ($file=~/\.(\d+)\.(\w+)$/) {
1.195 bisitz 7606: $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 7607: } elsif (-d "$filepath/$file") {
1.195 bisitz 7608: $output = &mt('Filename is a directory name - rename the file and re-upload');
1.9 raeburn 7609: } else {
7610: my $source = $filepath.'/'.$file;
7611: my $logfile;
7612: if (!open($logfile,">>$source".'.log')) {
1.196 raeburn 7613: return (&mt('No write permission to Authoring Space'));
1.9 raeburn 7614: }
7615: print $logfile
7616: "\n================= Publish ".localtime()." ================\n".
7617: $env{'user.name'}.':'.$env{'user.domain'}."\n";
7618: # Save the file
7619: if (!open(FH,'>'.$source)) {
7620: &Apache::lonnet::logthis('Failed to create '.$source);
7621: return (&mt('Failed to create file'));
7622: }
7623: if ($action eq 'upload') {
7624: if (!print FH ($env{'form.'.$formname})) {
7625: &Apache::lonnet::logthis('Failed to write to '.$source);
7626: return (&mt('Failed to write file'));
7627: }
7628: } else {
7629: my $original = &Apache::lonnet::filelocation('',$formname);
7630: if(!copy($original,$source)) {
7631: &Apache::lonnet::logthis('Failed to copy '.$original.' to '.$source);
7632: return (&mt('Failed to write file'));
7633: }
7634: }
7635: close(FH);
7636: chmod(0660, $source); # Permissions to rw-rw---.
7637:
7638: my $targetdir=$docroot.'/res/'.$dom.'/'.$confname .'/'.$fnamepath;
7639: my $copyfile=$targetdir.'/'.$file;
7640:
7641: my @parts=split(/\//,$targetdir);
7642: my $path="/$parts[1]/$parts[2]/$parts[3]/$parts[4]";
7643: for (my $count=5;$count<=$#parts;$count++) {
7644: $path.="/$parts[$count]";
7645: if (!-e $path) {
7646: print $logfile "\nCreating directory ".$path;
7647: mkdir($path,02770);
7648: }
7649: }
7650: my $versionresult;
7651: if (-e $copyfile) {
7652: $versionresult = &logo_versioning($targetdir,$file,$logfile);
7653: } else {
7654: $versionresult = 'ok';
7655: }
7656: if ($versionresult eq 'ok') {
7657: if (copy($source,$copyfile)) {
7658: print $logfile "\nCopied original source to ".$copyfile."\n";
7659: $output = 'ok';
7660: $logourl = '/res/'.$dom.'/'.$confname.'/'.$fname;
1.155 raeburn 7661: push(@{$modified_urls},[$copyfile,$source]);
7662: my $metaoutput =
7663: &write_metadata($dom,$confname,$formname,$targetdir,$file,$logfile);
7664: unless ($registered_cleanup) {
7665: my $handlers = $r->get_handlers('PerlCleanupHandler');
7666: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
7667: $registered_cleanup=1;
7668: }
1.9 raeburn 7669: } else {
7670: print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";
7671: $output = &mt('Failed to copy file to RES space').", $!";
7672: }
7673: if (($thumbwidth =~ /^\d+$/) && ($thumbheight =~ /^\d+$/)) {
7674: my $inputfile = $filepath.'/'.$file;
7675: my $outfile = $filepath.'/'.'tn-'.$file;
1.16 raeburn 7676: my ($fullwidth,$fullheight) = &check_dimensions($inputfile);
7677: if ($fullwidth ne '' && $fullheight ne '') {
7678: if ($fullwidth > $thumbwidth && $fullheight > $thumbheight) {
7679: my $thumbsize = $thumbwidth.'x'.$thumbheight;
7680: system("convert -sample $thumbsize $inputfile $outfile");
7681: chmod(0660, $filepath.'/tn-'.$file);
7682: if (-e $outfile) {
7683: my $copyfile=$targetdir.'/tn-'.$file;
7684: if (copy($outfile,$copyfile)) {
7685: print $logfile "\nCopied source to ".$copyfile."\n";
1.155 raeburn 7686: my $thumb_metaoutput =
7687: &write_metadata($dom,$confname,$formname,
7688: $targetdir,'tn-'.$file,$logfile);
7689: push(@{$modified_urls},[$copyfile,$outfile]);
7690: unless ($registered_cleanup) {
7691: my $handlers = $r->get_handlers('PerlCleanupHandler');
7692: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
7693: $registered_cleanup=1;
7694: }
1.267 raeburn 7695: $madethumb = 1;
1.16 raeburn 7696: } else {
7697: print $logfile "\nUnable to write ".$copyfile.
7698: ':'.$!."\n";
7699: }
7700: }
1.9 raeburn 7701: }
7702: }
7703: }
7704: } else {
7705: $output = $versionresult;
7706: }
7707: }
1.267 raeburn 7708: return ($output,$logourl,$madethumb);
1.9 raeburn 7709: }
7710:
7711: sub logo_versioning {
7712: my ($targetdir,$file,$logfile) = @_;
7713: my $target = $targetdir.'/'.$file;
7714: my ($maxversion,$fn,$extn,$output);
7715: $maxversion = 0;
7716: if ($file =~ /^(.+)\.(\w+)$/) {
7717: $fn=$1;
7718: $extn=$2;
7719: }
7720: opendir(DIR,$targetdir);
7721: while (my $filename=readdir(DIR)) {
7722: if ($filename=~/\Q$fn\E\.(\d+)\.\Q$extn\E$/) {
7723: $maxversion=($1>$maxversion)?$1:$maxversion;
7724: }
7725: }
7726: $maxversion++;
7727: print $logfile "\nCreating old version ".$maxversion."\n";
7728: my $copyfile=$targetdir.'/'.$fn.'.'.$maxversion.'.'.$extn;
7729: if (copy($target,$copyfile)) {
7730: print $logfile "Copied old target to ".$copyfile."\n";
7731: $copyfile=$copyfile.'.meta';
7732: if (copy($target.'.meta',$copyfile)) {
7733: print $logfile "Copied old target metadata to ".$copyfile."\n";
7734: $output = 'ok';
7735: } else {
7736: print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";
7737: $output = &mt('Failed to copy old meta').", $!, ";
7738: }
7739: } else {
7740: print $logfile "Unable to write ".$copyfile.':'.$!."\n";
7741: $output = &mt('Failed to copy old target').", $!, ";
7742: }
7743: return $output;
7744: }
7745:
7746: sub write_metadata {
7747: my ($dom,$confname,$formname,$targetdir,$file,$logfile) = @_;
7748: my (%metadatafields,%metadatakeys,$output);
7749: $metadatafields{'title'}=$formname;
7750: $metadatafields{'creationdate'}=time;
7751: $metadatafields{'lastrevisiondate'}=time;
7752: $metadatafields{'copyright'}='public';
7753: $metadatafields{'modifyinguser'}=$env{'user.name'}.':'.
7754: $env{'user.domain'};
7755: $metadatafields{'authorspace'}=$confname.':'.$dom;
7756: $metadatafields{'domain'}=$dom;
7757: {
7758: print $logfile "\nWrite metadata file for ".$targetdir.'/'.$file;
7759: my $mfh;
1.155 raeburn 7760: if (open($mfh,'>'.$targetdir.'/'.$file.'.meta')) {
1.184 raeburn 7761: foreach (sort(keys(%metadatafields))) {
1.155 raeburn 7762: unless ($_=~/\./) {
7763: my $unikey=$_;
7764: $unikey=~/^([A-Za-z]+)/;
7765: my $tag=$1;
7766: $tag=~tr/A-Z/a-z/;
7767: print $mfh "\n\<$tag";
7768: foreach (split(/\,/,$metadatakeys{$unikey})) {
7769: my $value=$metadatafields{$unikey.'.'.$_};
7770: $value=~s/\"/\'\'/g;
7771: print $mfh ' '.$_.'="'.$value.'"';
7772: }
7773: print $mfh '>'.
7774: &HTML::Entities::encode($metadatafields{$unikey},'<>&"')
7775: .'</'.$tag.'>';
7776: }
7777: }
7778: $output = 'ok';
7779: print $logfile "\nWrote metadata";
7780: close($mfh);
7781: } else {
7782: print $logfile "\nFailed to open metadata file";
1.9 raeburn 7783: $output = &mt('Could not write metadata');
7784: }
7785: }
1.155 raeburn 7786: return $output;
7787: }
7788:
7789: sub notifysubscribed {
7790: foreach my $targetsource (@{$modified_urls}){
7791: next unless (ref($targetsource) eq 'ARRAY');
7792: my ($target,$source)=@{$targetsource};
7793: if ($source ne '') {
7794: if (open(my $logfh,'>>'.$source.'.log')) {
7795: print $logfh "\nCleanup phase: Notifications\n";
7796: my @subscribed=&subscribed_hosts($target);
7797: foreach my $subhost (@subscribed) {
7798: print $logfh "\nNotifying host ".$subhost.':';
7799: my $reply=&Apache::lonnet::critical('update:'.$target,$subhost);
7800: print $logfh $reply;
7801: }
7802: my @subscribedmeta=&subscribed_hosts("$target.meta");
7803: foreach my $subhost (@subscribedmeta) {
7804: print $logfh "\nNotifying host for metadata only ".$subhost.':';
7805: my $reply=&Apache::lonnet::critical('update:'.$target.'.meta',
7806: $subhost);
7807: print $logfh $reply;
7808: }
7809: print $logfh "\n============ Done ============\n";
1.160 raeburn 7810: close($logfh);
1.155 raeburn 7811: }
7812: }
7813: }
7814: return OK;
7815: }
7816:
7817: sub subscribed_hosts {
7818: my ($target) = @_;
7819: my @subscribed;
7820: if (open(my $fh,"<$target.subscription")) {
7821: while (my $subline=<$fh>) {
7822: if ($subline =~ /^($match_lonid):/) {
7823: my $host = $1;
7824: if ($host ne $Apache::lonnet::perlvar{'lonHostID'}) {
7825: unless (grep(/^\Q$host\E$/,@subscribed)) {
7826: push(@subscribed,$host);
7827: }
7828: }
7829: }
7830: }
7831: }
7832: return @subscribed;
1.9 raeburn 7833: }
7834:
7835: sub check_switchserver {
7836: my ($dom,$confname) = @_;
7837: my ($allowed,$switchserver);
7838: my $home = &Apache::lonnet::homeserver($confname,$dom);
7839: if ($home eq 'no_host') {
7840: $home = &Apache::lonnet::domain($dom,'primary');
7841: }
7842: my @ids=&Apache::lonnet::current_machine_ids();
1.10 albertel 7843: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
7844: if (!$allowed) {
1.180 raeburn 7845: $switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role=dc./'.$dom.'/&destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
1.9 raeburn 7846: }
7847: return $switchserver;
7848: }
7849:
1.1 raeburn 7850: sub modify_quotas {
1.216 raeburn 7851: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
1.101 raeburn 7852: my ($context,@usertools,@options,%validations,%titles,%confhash,%toolshash,
1.216 raeburn 7853: %limithash,$toolregexp,%conditions,$resulttext,%changes,$confname,$configuserok,
1.235 raeburn 7854: $author_ok,$switchserver,$errors,$validationitemsref,$validationnamesref,
7855: $validationfieldsref);
1.86 raeburn 7856: if ($action eq 'quotas') {
7857: $context = 'tools';
1.163 raeburn 7858: } else {
1.86 raeburn 7859: $context = $action;
7860: }
7861: if ($context eq 'requestcourses') {
1.271 raeburn 7862: @usertools = ('official','unofficial','community','textbook','placement');
1.106 raeburn 7863: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 7864: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
7865: %titles = &courserequest_titles();
7866: $toolregexp = join('|',@usertools);
7867: %conditions = &courserequest_conditions();
1.216 raeburn 7868: $confname = $dom.'-domainconfig';
7869: my $servadm = $r->dir_config('lonAdmEMail');
7870: ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
1.235 raeburn 7871: ($validationitemsref,$validationnamesref,$validationfieldsref) =
7872: &Apache::loncoursequeueadmin::requestcourses_validation_types();
1.163 raeburn 7873: } elsif ($context eq 'requestauthor') {
7874: @usertools = ('author');
7875: %titles = &authorrequest_titles();
1.86 raeburn 7876: } else {
1.162 raeburn 7877: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 7878: %titles = &tool_titles();
1.86 raeburn 7879: }
1.212 raeburn 7880: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.44 raeburn 7881: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 7882: foreach my $key (keys(%env)) {
1.101 raeburn 7883: if ($context eq 'requestcourses') {
7884: if ($key =~ /^form\.crsreq_($toolregexp)_(.+)$/) {
7885: my $item = $1;
7886: my $type = $2;
7887: if ($type =~ /^limit_(.+)/) {
7888: $limithash{$item}{$1} = $env{$key};
7889: } else {
7890: $confhash{$item}{$type} = $env{$key};
7891: }
7892: }
1.163 raeburn 7893: } elsif ($context eq 'requestauthor') {
7894: if ($key =~ /^\Qform.authorreq_\E(.+)$/) {
7895: $confhash{$1} = $env{$key};
7896: }
1.101 raeburn 7897: } else {
1.86 raeburn 7898: if ($key =~ /^form\.quota_(.+)$/) {
7899: $confhash{'defaultquota'}{$1} = $env{$key};
1.197 raeburn 7900: } elsif ($key =~ /^form\.authorquota_(.+)$/) {
7901: $confhash{'authorquota'}{$1} = $env{$key};
7902: } elsif ($key =~ /^form\.\Q$context\E_(.+)$/) {
1.101 raeburn 7903: @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key);
7904: }
1.72 raeburn 7905: }
7906: }
1.163 raeburn 7907: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.224 raeburn 7908: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.'.$context.'notifyapproval');
1.102 raeburn 7909: @approvalnotify = sort(@approvalnotify);
7910: $confhash{'notify'}{'approval'} = join(',',@approvalnotify);
1.271 raeburn 7911: my @crstypes = ('official','unofficial','community','textbook','placement');
1.218 raeburn 7912: my @hasuniquecode = &Apache::loncommon::get_env_multiple('form.uniquecode');
7913: foreach my $type (@hasuniquecode) {
7914: if (grep(/^\Q$type\E$/,@crstypes)) {
7915: $confhash{'uniquecode'}{$type} = 1;
7916: }
1.216 raeburn 7917: }
1.242 raeburn 7918: my (%newbook,%allpos);
1.216 raeburn 7919: if ($context eq 'requestcourses') {
1.242 raeburn 7920: foreach my $type ('textbooks','templates') {
7921: @{$allpos{$type}} = ();
7922: my $invalid;
7923: if ($type eq 'textbooks') {
7924: $invalid = &mt('Invalid LON-CAPA course for textbook');
7925: } else {
7926: $invalid = &mt('Invalid LON-CAPA course for template');
7927: }
7928: if ($env{'form.'.$type.'_addbook'}) {
7929: if (($env{'form.'.$type.'_addbook_cnum'} =~ /^$match_courseid$/) &&
7930: ($env{'form.'.$type.'_addbook_cdom'} =~ /^$match_domain$/)) {
7931: if (&Apache::lonnet::homeserver($env{'form.'.$type.'_addbook_cnum'},
7932: $env{'form.'.$type.'_addbook_cdom'}) eq 'no_host') {
7933: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
7934: } else {
7935: $newbook{$type} = $env{'form.'.$type.'_addbook_cdom'}.'_'.$env{'form.'.$type.'_addbook_cnum'};
7936: my $position = $env{'form.'.$type.'_addbook_pos'};
7937: $position =~ s/\D+//g;
7938: if ($position ne '') {
7939: $allpos{$type}[$position] = $newbook{$type};
7940: }
1.216 raeburn 7941: }
1.242 raeburn 7942: } else {
7943: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
1.216 raeburn 7944: }
7945: }
1.242 raeburn 7946: }
1.216 raeburn 7947: }
1.102 raeburn 7948: if (ref($domconfig{$action}) eq 'HASH') {
7949: if (ref($domconfig{$action}{'notify'}) eq 'HASH') {
7950: if ($domconfig{$action}{'notify'}{'approval'} ne $confhash{'notify'}{'approval'}) {
7951: $changes{'notify'}{'approval'} = 1;
7952: }
7953: } else {
1.144 raeburn 7954: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 7955: $changes{'notify'}{'approval'} = 1;
7956: }
7957: }
1.218 raeburn 7958: if (ref($domconfig{$action}{'uniquecode'}) eq 'HASH') {
7959: if (ref($confhash{'uniquecode'}) eq 'HASH') {
7960: foreach my $crstype (keys(%{$domconfig{$action}{'uniquecode'}})) {
7961: unless ($confhash{'uniquecode'}{$crstype}) {
7962: $changes{'uniquecode'} = 1;
7963: }
7964: }
7965: unless ($changes{'uniquecode'}) {
7966: foreach my $crstype (keys(%{$confhash{'uniquecode'}})) {
7967: unless ($domconfig{$action}{'uniquecode'}{$crstype}) {
7968: $changes{'uniquecode'} = 1;
7969: }
7970: }
7971: }
7972: } else {
7973: $changes{'uniquecode'} = 1;
7974: }
7975: } elsif (ref($confhash{'uniquecode'}) eq 'HASH') {
7976: $changes{'uniquecode'} = 1;
1.216 raeburn 7977: }
7978: if ($context eq 'requestcourses') {
1.242 raeburn 7979: foreach my $type ('textbooks','templates') {
7980: if (ref($domconfig{$action}{$type}) eq 'HASH') {
7981: my %deletions;
7982: my @todelete = &Apache::loncommon::get_env_multiple('form.'.$type.'_del');
7983: if (@todelete) {
7984: map { $deletions{$_} = 1; } @todelete;
7985: }
7986: my %imgdeletions;
7987: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.'.$type.'_image_del');
7988: if (@todeleteimages) {
7989: map { $imgdeletions{$_} = 1; } @todeleteimages;
7990: }
7991: my $maxnum = $env{'form.'.$type.'_maxnum'};
7992: for (my $i=0; $i<=$maxnum; $i++) {
7993: my $itemid = $env{'form.'.$type.'_id_'.$i};
7994: my ($key) = ($itemid =~ /^\Q$type\E_(\w+)$/);
7995: if (ref($domconfig{$action}{$type}{$key}) eq 'HASH') {
7996: if ($deletions{$key}) {
7997: if ($domconfig{$action}{$type}{$key}{'image'}) {
7998: #FIXME need to obsolete item in RES space
7999: }
8000: next;
8001: } else {
8002: my $newpos = $env{'form.'.$itemid};
8003: $newpos =~ s/\D+//g;
1.243 raeburn 8004: foreach my $item ('subject','title','publisher','author') {
8005: next if ((($item eq 'author') || ($item eq 'publisher')) &&
8006: ($type eq 'templates'));
1.242 raeburn 8007: $confhash{$type}{$key}{$item} = $env{'form.'.$type.'_'.$item.'_'.$i};
8008: if ($domconfig{$action}{$type}{$key}{$item} ne $confhash{$type}{$key}{$item}) {
8009: $changes{$type}{$key} = 1;
8010: }
8011: }
8012: $allpos{$type}[$newpos] = $key;
8013: }
8014: if ($imgdeletions{$key}) {
8015: $changes{$type}{$key} = 1;
1.216 raeburn 8016: #FIXME need to obsolete item in RES space
1.242 raeburn 8017: } elsif ($env{'form.'.$type.'_image_'.$i.'.filename'}) {
8018: my ($cdom,$cnum) = split(/_/,$key);
8019: my ($imgurl,$error) = &process_textbook_image($r,$dom,$confname,$type.'_image_'.$i,
8020: $cdom,$cnum,$type,$configuserok,
8021: $switchserver,$author_ok);
8022: if ($imgurl) {
8023: $confhash{$type}{$key}{'image'} = $imgurl;
8024: $changes{$type}{$key} = 1;
1.216 raeburn 8025: }
1.242 raeburn 8026: if ($error) {
8027: &Apache::lonnet::logthis($error);
8028: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
8029: }
8030: } elsif ($domconfig{$action}{$type}{$key}{'image'}) {
8031: $confhash{$type}{$key}{'image'} =
8032: $domconfig{$action}{$type}{$key}{'image'};
1.216 raeburn 8033: }
8034: }
8035: }
8036: }
8037: }
8038: }
1.102 raeburn 8039: } else {
1.144 raeburn 8040: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 8041: $changes{'notify'}{'approval'} = 1;
8042: }
1.218 raeburn 8043: if (ref($confhash{'uniquecode'} eq 'HASH')) {
1.216 raeburn 8044: $changes{'uniquecode'} = 1;
8045: }
8046: }
8047: if ($context eq 'requestcourses') {
1.242 raeburn 8048: foreach my $type ('textbooks','templates') {
8049: if ($newbook{$type}) {
8050: $changes{$type}{$newbook{$type}} = 1;
1.243 raeburn 8051: foreach my $item ('subject','title','publisher','author') {
8052: next if ((($item eq 'author') || ($item eq 'publisher')) &&
8053: ($type eq 'template'));
1.242 raeburn 8054: $env{'form.'.$type.'_addbook_'.$item} =~ s/(`)/'/g;
8055: if ($env{'form.'.$type.'_addbook_'.$item}) {
8056: $confhash{$type}{$newbook{$type}}{$item} = $env{'form.'.$type.'_addbook_'.$item};
8057: }
8058: }
8059: if ($type eq 'textbooks') {
8060: if ($env{'form.'.$type.'_addbook_image.filename'} ne '') {
8061: my ($cdom,$cnum) = split(/_/,$newbook{$type});
8062: my ($imageurl,$error) =
8063: &process_textbook_image($r,$dom,$confname,$type.'_addbook_image',$cdom,$cnum,$type,
8064: $configuserok,$switchserver,$author_ok);
8065: if ($imageurl) {
8066: $confhash{$type}{$newbook{$type}}{'image'} = $imageurl;
8067: }
8068: if ($error) {
8069: &Apache::lonnet::logthis($error);
8070: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
8071: }
8072: }
1.216 raeburn 8073: }
8074: }
1.242 raeburn 8075: if (@{$allpos{$type}} > 0) {
8076: my $idx = 0;
8077: foreach my $item (@{$allpos{$type}}) {
8078: if ($item ne '') {
8079: $confhash{$type}{$item}{'order'} = $idx;
8080: if (ref($domconfig{$action}) eq 'HASH') {
8081: if (ref($domconfig{$action}{$type}) eq 'HASH') {
8082: if (ref($domconfig{$action}{$type}{$item}) eq 'HASH') {
8083: if ($domconfig{$action}{$type}{$item}{'order'} ne $idx) {
8084: $changes{$type}{$item} = 1;
8085: }
1.216 raeburn 8086: }
8087: }
8088: }
1.242 raeburn 8089: $idx ++;
1.216 raeburn 8090: }
8091: }
8092: }
8093: }
1.235 raeburn 8094: if (ref($validationitemsref) eq 'ARRAY') {
8095: foreach my $item (@{$validationitemsref}) {
8096: if ($item eq 'fields') {
8097: my @changed;
8098: @{$confhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.requestcourses_validation_'.$item);
8099: if (@{$confhash{'validation'}{$item}} > 0) {
8100: @{$confhash{'validation'}{$item}} = sort(@{$confhash{'validation'}{$item}});
8101: }
1.266 raeburn 8102: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
8103: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
8104: if (ref($domconfig{'requestcourses'}{'validation'}{$item}) eq 'ARRAY') {
8105: @changed = &Apache::loncommon::compare_arrays($confhash{'validation'}{$item},
8106: $domconfig{'requestcourses'}{'validation'}{$item});
8107: } else {
8108: @changed = @{$confhash{'validation'}{$item}};
8109: }
1.235 raeburn 8110: } else {
8111: @changed = @{$confhash{'validation'}{$item}};
8112: }
8113: } else {
8114: @changed = @{$confhash{'validation'}{$item}};
8115: }
8116: if (@changed) {
8117: if ($confhash{'validation'}{$item}) {
8118: $changes{'validation'}{$item} = join(', ',@{$confhash{'validation'}{$item}});
8119: } else {
8120: $changes{'validation'}{$item} = &mt('None');
8121: }
8122: }
8123: } else {
8124: $confhash{'validation'}{$item} = $env{'form.requestcourses_validation_'.$item};
8125: if ($item eq 'markup') {
8126: if ($env{'form.requestcourses_validation_'.$item}) {
8127: $env{'form.requestcourses_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
8128: }
8129: }
1.266 raeburn 8130: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
8131: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
8132: if ($domconfig{'requestcourses'}{'validation'}{$item} ne $confhash{'validation'}{$item}) {
8133: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
8134: }
8135: } else {
8136: if ($confhash{'validation'}{$item} ne '') {
8137: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
8138: }
1.235 raeburn 8139: }
8140: } else {
8141: if ($confhash{'validation'}{$item} ne '') {
8142: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
8143: }
8144: }
8145: }
8146: }
8147: }
8148: if ($env{'form.validationdc'}) {
8149: my $newval = $env{'form.validationdc'};
8150: my %domcoords = &get_active_dcs($dom);
8151: if (exists($domcoords{$newval})) {
8152: $confhash{'validation'}{'dc'} = $newval;
8153: }
8154: }
8155: if (ref($confhash{'validation'}) eq 'HASH') {
1.266 raeburn 8156: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
8157: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
8158: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
8159: unless ($confhash{'validation'}{'dc'} eq $domconfig{'requestcourses'}{'validation'}{'dc'}) {
8160: if ($confhash{'validation'}{'dc'} eq '') {
8161: $changes{'validation'}{'dc'} = &mt('None');
8162: } else {
8163: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
8164: }
1.235 raeburn 8165: }
1.266 raeburn 8166: } elsif ($confhash{'validation'}{'dc'} ne '') {
8167: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
1.235 raeburn 8168: }
8169: } elsif ($confhash{'validation'}{'dc'} ne '') {
8170: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
8171: }
8172: } elsif ($confhash{'validation'}{'dc'} ne '') {
8173: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
1.266 raeburn 8174: }
8175: } else {
8176: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
8177: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
8178: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
8179: $changes{'validation'}{'dc'} = &mt('None');
8180: }
8181: }
1.235 raeburn 8182: }
8183: }
1.102 raeburn 8184: }
8185: } else {
1.86 raeburn 8186: $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
1.197 raeburn 8187: $confhash{'authorquota'}{'default'} = $env{'form.authorquota'};
1.86 raeburn 8188: }
1.72 raeburn 8189: foreach my $item (@usertools) {
8190: foreach my $type (@{$types},'default','_LC_adv') {
1.104 raeburn 8191: my $unset;
1.101 raeburn 8192: if ($context eq 'requestcourses') {
1.104 raeburn 8193: $unset = '0';
8194: if ($type eq '_LC_adv') {
8195: $unset = '';
8196: }
1.101 raeburn 8197: if ($confhash{$item}{$type} eq 'autolimit') {
8198: $confhash{$item}{$type} .= '=';
8199: unless ($limithash{$item}{$type} =~ /\D/) {
8200: $confhash{$item}{$type} .= $limithash{$item}{$type};
8201: }
8202: }
1.163 raeburn 8203: } elsif ($context eq 'requestauthor') {
8204: $unset = '0';
8205: if ($type eq '_LC_adv') {
8206: $unset = '';
8207: }
1.72 raeburn 8208: } else {
1.101 raeburn 8209: if (grep(/^\Q$type\E$/,@{$toolshash{$item}})) {
8210: $confhash{$item}{$type} = 1;
8211: } else {
8212: $confhash{$item}{$type} = 0;
8213: }
1.72 raeburn 8214: }
1.86 raeburn 8215: if (ref($domconfig{$action}) eq 'HASH') {
1.163 raeburn 8216: if ($action eq 'requestauthor') {
8217: if ($domconfig{$action}{$type} ne $confhash{$type}) {
8218: $changes{$type} = 1;
8219: }
8220: } elsif (ref($domconfig{$action}{$item}) eq 'HASH') {
1.86 raeburn 8221: if ($domconfig{$action}{$item}{$type} ne $confhash{$item}{$type}) {
8222: $changes{$item}{$type} = 1;
8223: }
8224: } else {
8225: if ($context eq 'requestcourses') {
1.104 raeburn 8226: if ($confhash{$item}{$type} ne $unset) {
1.86 raeburn 8227: $changes{$item}{$type} = 1;
8228: }
8229: } else {
8230: if (!$confhash{$item}{$type}) {
8231: $changes{$item}{$type} = 1;
8232: }
8233: }
8234: }
8235: } else {
8236: if ($context eq 'requestcourses') {
1.104 raeburn 8237: if ($confhash{$item}{$type} ne $unset) {
1.72 raeburn 8238: $changes{$item}{$type} = 1;
8239: }
1.163 raeburn 8240: } elsif ($context eq 'requestauthor') {
8241: if ($confhash{$type} ne $unset) {
8242: $changes{$type} = 1;
8243: }
1.72 raeburn 8244: } else {
8245: if (!$confhash{$item}{$type}) {
8246: $changes{$item}{$type} = 1;
8247: }
8248: }
8249: }
1.1 raeburn 8250: }
8251: }
1.163 raeburn 8252: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 8253: if (ref($domconfig{'quotas'}) eq 'HASH') {
8254: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
8255: foreach my $key (keys(%{$domconfig{'quotas'}{'defaultquota'}})) {
8256: if (exists($confhash{'defaultquota'}{$key})) {
8257: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{'defaultquota'}{$key}) {
8258: $changes{'defaultquota'}{$key} = 1;
8259: }
8260: } else {
8261: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{'defaultquota'}{$key};
1.72 raeburn 8262: }
8263: }
1.86 raeburn 8264: } else {
8265: foreach my $key (keys(%{$domconfig{'quotas'}})) {
8266: if (exists($confhash{'defaultquota'}{$key})) {
8267: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{$key}) {
8268: $changes{'defaultquota'}{$key} = 1;
8269: }
8270: } else {
8271: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{$key};
1.72 raeburn 8272: }
1.1 raeburn 8273: }
8274: }
1.197 raeburn 8275: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
8276: foreach my $key (keys(%{$domconfig{'quotas'}{'authorquota'}})) {
8277: if (exists($confhash{'authorquota'}{$key})) {
8278: if ($confhash{'authorquota'}{$key} ne $domconfig{'quotas'}{'authorquota'}{$key}) {
8279: $changes{'authorquota'}{$key} = 1;
8280: }
8281: } else {
8282: $confhash{'authorquota'}{$key} = $domconfig{'quotas'}{'authorquota'}{$key};
8283: }
8284: }
8285: }
1.1 raeburn 8286: }
1.86 raeburn 8287: if (ref($confhash{'defaultquota'}) eq 'HASH') {
8288: foreach my $key (keys(%{$confhash{'defaultquota'}})) {
8289: if (ref($domconfig{'quotas'}) eq 'HASH') {
8290: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
8291: if (!exists($domconfig{'quotas'}{'defaultquota'}{$key})) {
8292: $changes{'defaultquota'}{$key} = 1;
8293: }
8294: } else {
8295: if (!exists($domconfig{'quotas'}{$key})) {
8296: $changes{'defaultquota'}{$key} = 1;
8297: }
1.72 raeburn 8298: }
8299: } else {
1.86 raeburn 8300: $changes{'defaultquota'}{$key} = 1;
1.55 raeburn 8301: }
1.1 raeburn 8302: }
8303: }
1.197 raeburn 8304: if (ref($confhash{'authorquota'}) eq 'HASH') {
8305: foreach my $key (keys(%{$confhash{'authorquota'}})) {
8306: if (ref($domconfig{'quotas'}) eq 'HASH') {
8307: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
8308: if (!exists($domconfig{'quotas'}{'authorquota'}{$key})) {
8309: $changes{'authorquota'}{$key} = 1;
8310: }
8311: } else {
8312: $changes{'authorquota'}{$key} = 1;
8313: }
8314: } else {
8315: $changes{'authorquota'}{$key} = 1;
8316: }
8317: }
8318: }
1.1 raeburn 8319: }
1.72 raeburn 8320:
1.163 raeburn 8321: if ($context eq 'requestauthor') {
8322: $domdefaults{'requestauthor'} = \%confhash;
8323: } else {
8324: foreach my $key (keys(%confhash)) {
1.242 raeburn 8325: unless (($context eq 'requestcourses') && (($key eq 'textbooks') || ($key eq 'templates'))) {
1.216 raeburn 8326: $domdefaults{$key} = $confhash{$key};
8327: }
1.163 raeburn 8328: }
1.72 raeburn 8329: }
1.163 raeburn 8330:
1.1 raeburn 8331: my %quotahash = (
1.86 raeburn 8332: $action => { %confhash }
1.1 raeburn 8333: );
8334: my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
8335: $dom);
8336: if ($putresult eq 'ok') {
8337: if (keys(%changes) > 0) {
1.72 raeburn 8338: my $cachetime = 24*60*60;
8339: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 8340: if (ref($lastactref) eq 'HASH') {
8341: $lastactref->{'domdefaults'} = 1;
8342: }
1.1 raeburn 8343: $resulttext = &mt('Changes made:').'<ul>';
1.210 raeburn 8344: unless (($context eq 'requestcourses') ||
1.163 raeburn 8345: ($context eq 'requestauthor')) {
1.86 raeburn 8346: if (ref($changes{'defaultquota'}) eq 'HASH') {
8347: $resulttext .= '<li>'.&mt('Portfolio default quotas').'<ul>';
8348: foreach my $type (@{$types},'default') {
8349: if (defined($changes{'defaultquota'}{$type})) {
8350: my $typetitle = $usertypes->{$type};
8351: if ($type eq 'default') {
8352: $typetitle = $othertitle;
8353: }
1.213 raeburn 8354: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'defaultquota'}{$type}).'</li>';
1.72 raeburn 8355: }
8356: }
1.86 raeburn 8357: $resulttext .= '</ul></li>';
1.72 raeburn 8358: }
1.197 raeburn 8359: if (ref($changes{'authorquota'}) eq 'HASH') {
1.223 bisitz 8360: $resulttext .= '<li>'.&mt('Authoring Space default quotas').'<ul>';
1.197 raeburn 8361: foreach my $type (@{$types},'default') {
8362: if (defined($changes{'authorquota'}{$type})) {
8363: my $typetitle = $usertypes->{$type};
8364: if ($type eq 'default') {
8365: $typetitle = $othertitle;
8366: }
1.213 raeburn 8367: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'authorquota'}{$type}).'</li>';
1.197 raeburn 8368: }
8369: }
8370: $resulttext .= '</ul></li>';
8371: }
1.72 raeburn 8372: }
1.80 raeburn 8373: my %newenv;
1.72 raeburn 8374: foreach my $item (@usertools) {
1.163 raeburn 8375: my (%haschgs,%inconf);
8376: if ($context eq 'requestauthor') {
8377: %haschgs = %changes;
1.210 raeburn 8378: %inconf = %confhash;
1.163 raeburn 8379: } else {
8380: if (ref($changes{$item}) eq 'HASH') {
8381: %haschgs = %{$changes{$item}};
8382: }
8383: if (ref($confhash{$item}) eq 'HASH') {
8384: %inconf = %{$confhash{$item}};
8385: }
8386: }
8387: if (keys(%haschgs) > 0) {
1.80 raeburn 8388: my $newacc =
8389: &Apache::lonnet::usertools_access($env{'user.name'},
8390: $env{'user.domain'},
1.86 raeburn 8391: $item,'reload',$context);
1.210 raeburn 8392: if (($context eq 'requestcourses') ||
1.163 raeburn 8393: ($context eq 'requestauthor')) {
1.108 raeburn 8394: if ($env{'environment.canrequest.'.$item} ne $newacc) {
8395: $newenv{'environment.canrequest.'.$item} = $newacc;
1.86 raeburn 8396: }
8397: } else {
8398: if ($env{'environment.availabletools.'.$item} ne $newacc) {
8399: $newenv{'environment.availabletools.'.$item} = $newacc;
8400: }
1.80 raeburn 8401: }
1.163 raeburn 8402: unless ($context eq 'requestauthor') {
8403: $resulttext .= '<li>'.$titles{$item}.'<ul>';
8404: }
1.72 raeburn 8405: foreach my $type (@{$types},'default','_LC_adv') {
1.163 raeburn 8406: if ($haschgs{$type}) {
1.72 raeburn 8407: my $typetitle = $usertypes->{$type};
8408: if ($type eq 'default') {
8409: $typetitle = $othertitle;
8410: } elsif ($type eq '_LC_adv') {
8411: $typetitle = 'LON-CAPA Advanced Users';
8412: }
1.163 raeburn 8413: if ($inconf{$type}) {
1.101 raeburn 8414: if ($context eq 'requestcourses') {
8415: my $cond;
1.163 raeburn 8416: if ($inconf{$type} =~ /^autolimit=(\d*)$/) {
1.101 raeburn 8417: if ($1 eq '') {
8418: $cond = &mt('(Automatic processing of any request).');
8419: } else {
8420: $cond = &mt('(Automatic processing of requests up to limit of [quant,_1,request] per user).',$1);
8421: }
8422: } else {
1.163 raeburn 8423: $cond = $conditions{$inconf{$type}};
1.101 raeburn 8424: }
8425: $resulttext .= '<li>'.&mt('Set to be available to [_1].',$typetitle).' '.$cond.'</li>';
1.172 raeburn 8426: } elsif ($context eq 'requestauthor') {
8427: $resulttext .= '<li>'.&mt('Set to "[_1]" for "[_2]".',
8428: $titles{$inconf{$type}},$typetitle);
8429:
1.101 raeburn 8430: } else {
8431: $resulttext .= '<li>'.&mt('Set to be available to [_1]',$typetitle).'</li>';
8432: }
1.72 raeburn 8433: } else {
1.104 raeburn 8434: if ($type eq '_LC_adv') {
1.163 raeburn 8435: if ($inconf{$type} eq '0') {
1.104 raeburn 8436: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
8437: } else {
8438: $resulttext .= '<li>'.&mt('No override set for [_1]',$typetitle).'</li>';
8439: }
8440: } else {
8441: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
8442: }
1.72 raeburn 8443: }
8444: }
1.26 raeburn 8445: }
1.163 raeburn 8446: unless ($context eq 'requestauthor') {
8447: $resulttext .= '</ul></li>';
8448: }
1.26 raeburn 8449: }
1.1 raeburn 8450: }
1.163 raeburn 8451: if (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.102 raeburn 8452: if (ref($changes{'notify'}) eq 'HASH') {
8453: if ($changes{'notify'}{'approval'}) {
8454: if (ref($confhash{'notify'}) eq 'HASH') {
8455: if ($confhash{'notify'}{'approval'}) {
8456: $resulttext .= '<li>'.&mt('Notification of requests requiring approval will be sent to: ').$confhash{'notify'}{'approval'}.'</li>';
8457: } else {
1.163 raeburn 8458: $resulttext .= '<li>'.&mt('No Domain Coordinators will receive notification of requests requiring approval.').'</li>';
1.102 raeburn 8459: }
8460: }
8461: }
8462: }
8463: }
1.216 raeburn 8464: if ($action eq 'requestcourses') {
8465: my @offon = ('off','on');
8466: if ($changes{'uniquecode'}) {
1.218 raeburn 8467: if (ref($confhash{'uniquecode'}) eq 'HASH') {
8468: my $codestr = join(' ',map{ &mt($_); } sort(keys(%{$confhash{'uniquecode'}})));
8469: $resulttext .= '<li>'.
8470: &mt('Generation of six character code as course identifier for distribution to students set to on for: [_1].','<b>'.$codestr.'</b>').
8471: '</li>';
8472: } else {
8473: $resulttext .= '<li>'.&mt('Generation of six character code as course identifier for distribution to students set to off.').
8474: '</li>';
8475: }
1.216 raeburn 8476: }
1.242 raeburn 8477: foreach my $type ('textbooks','templates') {
8478: if (ref($changes{$type}) eq 'HASH') {
8479: $resulttext .= '<li>'.&mt("Available $type updated").'<ul>';
8480: foreach my $key (sort(keys(%{$changes{$type}}))) {
8481: my %coursehash = &Apache::lonnet::coursedescription($key);
8482: my $coursetitle = $coursehash{'description'};
8483: my $position = $confhash{$type}{$key}{'order'} + 1;
8484: $resulttext .= '<li>';
1.243 raeburn 8485: foreach my $item ('subject','title','publisher','author') {
8486: next if ((($item eq 'author') || ($item eq 'publisher')) &&
8487: ($type eq 'templates'));
1.242 raeburn 8488: my $name = $item.':';
8489: $name =~ s/^(\w)/\U$1/;
8490: $resulttext .= &mt($name).' '.$confhash{$type}{$key}{$item}.'<br />';
8491: }
8492: $resulttext .= ' '.&mt('Order: [_1]',$position).'<br />';
8493: if ($type eq 'textbooks') {
8494: if ($confhash{$type}{$key}{'image'}) {
8495: $resulttext .= ' '.&mt('Image: [_1]',
8496: '<img src="'.$confhash{$type}{$key}{'image'}.'"'.
8497: ' alt="Textbook cover" />').'<br />';
8498: }
8499: }
8500: $resulttext .= ' '.&mt('LON-CAPA Course: [_1]',$coursetitle).'</li>';
1.216 raeburn 8501: }
1.242 raeburn 8502: $resulttext .= '</ul></li>';
1.216 raeburn 8503: }
8504: }
1.235 raeburn 8505: if (ref($changes{'validation'}) eq 'HASH') {
8506: if ((ref($validationitemsref) eq 'ARRAY') && (ref($validationnamesref) eq 'HASH')) {
8507: $resulttext .= '<li>'.&mt('Validation of courses/communities updated').'<ul>';
8508: foreach my $item (@{$validationitemsref}) {
8509: if (exists($changes{'validation'}{$item})) {
8510: if ($item eq 'markup') {
8511: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
8512: '<br /><pre>'.$changes{'validation'}{$item}.'</pre>').'</li>';
8513: } else {
8514: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
8515: '<b>'.$changes{'validation'}{$item}.'</b>').'</li>';
8516: }
8517: }
8518: }
8519: if (exists($changes{'validation'}{'dc'})) {
8520: $resulttext .= '<li>'.&mt('Validated course requests identified as processed by: [_1]',
8521: '<b>'.$changes{'validation'}{'dc'}.'</b>').'</li>';
8522: }
8523: }
8524: }
1.216 raeburn 8525: }
1.1 raeburn 8526: $resulttext .= '</ul>';
1.80 raeburn 8527: if (keys(%newenv)) {
8528: &Apache::lonnet::appenv(\%newenv);
8529: }
1.1 raeburn 8530: } else {
1.86 raeburn 8531: if ($context eq 'requestcourses') {
8532: $resulttext = &mt('No changes made to rights to request creation of courses.');
1.163 raeburn 8533: } elsif ($context eq 'requestauthor') {
8534: $resulttext = &mt('No changes made to rights to request author space.');
1.86 raeburn 8535: } else {
1.90 weissno 8536: $resulttext = &mt('No changes made to availability of personal information pages, blogs, portfolios or default quotas');
1.86 raeburn 8537: }
1.1 raeburn 8538: }
8539: } else {
1.11 albertel 8540: $resulttext = '<span class="LC_error">'.
8541: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 8542: }
1.216 raeburn 8543: if ($errors) {
8544: $resulttext .= '<p>'.&mt('The following errors occurred when modifying Textbook settings.').
8545: '<ul>'.$errors.'</ul></p>';
8546: }
1.3 raeburn 8547: return $resulttext;
1.1 raeburn 8548: }
8549:
1.216 raeburn 8550: sub process_textbook_image {
1.242 raeburn 8551: my ($r,$dom,$confname,$caller,$cdom,$cnum,$type,$configuserok,$switchserver,$author_ok) = @_;
1.216 raeburn 8552: my $filename = $env{'form.'.$caller.'.filename'};
8553: my ($error,$url);
8554: my ($width,$height) = (50,50);
8555: if ($configuserok eq 'ok') {
8556: if ($switchserver) {
8557: $error = &mt('Upload of textbook image is not permitted to this server: [_1]',
8558: $switchserver);
8559: } elsif ($author_ok eq 'ok') {
8560: my ($result,$imageurl) =
8561: &publishlogo($r,'upload',$caller,$dom,$confname,
1.242 raeburn 8562: "$type/$dom/$cnum/cover",$width,$height);
1.216 raeburn 8563: if ($result eq 'ok') {
8564: $url = $imageurl;
8565: } else {
8566: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
8567: }
8568: } else {
8569: $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);
8570: }
8571: } else {
8572: $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);
8573: }
8574: return ($url,$error);
8575: }
8576:
1.267 raeburn 8577: sub modify_ltitools {
8578: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
8579: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
8580: my ($newid,@allpos,%changes,%confhash,$errors,$resulttext);
8581: my $confname = $dom.'-domainconfig';
8582: my $servadm = $r->dir_config('lonAdmEMail');
8583: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
8584: my (%posslti,%possfield);
8585: my @courseroles = ('cc','in','ta','ep','st');
8586: my @ltiroles = qw(Instructor ContentDeveloper TeachingAssistant Learner);
8587: map { $posslti{$_} = 1; } @ltiroles;
8588: my @allfields = ('fullname','firstname','lastname','email','user','roles');
8589: map { $possfield{$_} = 1; } @allfields;
8590: my %lt = <itools_names();
8591: if ($env{'form.ltitools_add'}) {
8592: my $title = $env{'form.ltitools_add_title'};
8593: $title =~ s/(`)/'/g;
8594: ($newid,my $error) = &get_ltitools_id($dom,$title);
8595: if ($newid) {
8596: my $position = $env{'form.ltitools_add_pos'};
8597: $position =~ s/\D+//g;
8598: if ($position ne '') {
8599: $allpos[$position] = $newid;
8600: }
8601: $changes{$newid} = 1;
8602: foreach my $item ('title','url','key','secret') {
8603: $env{'form.ltitools_add_'.$item} =~ s/(`)/'/g;
8604: if ($env{'form.ltitools_add_'.$item}) {
8605: $confhash{$newid}{$item} = $env{'form.ltitools_add_'.$item};
8606: }
8607: }
8608: if ($env{'form.ltitools_add_version'} eq 'LTI-1p0') {
8609: $confhash{$newid}{'version'} = $env{'form.ltitools_add_version'};
8610: }
8611: if ($env{'form.ltitools_add_msgtype'} eq 'basic-lti-launch-request') {
8612: $confhash{$newid}{'msgtype'} = $env{'form.ltitools_add_msgtype'};
8613: }
8614: foreach my $item ('width','height') {
8615: $env{'form.ltitools_add_'.$item} =~ s/^\s+//;
8616: $env{'form.ltitools_add_'.$item} =~ s/\s+$//;
8617: if ($env{'form.ltitools_add_'.$item} =~ /^\d+$/) {
8618: $confhash{$newid}{'display'}{$item} = $env{'form.ltitools_add_'.$item};
8619: }
8620: }
8621: if ($env{'form.ltitools_add_target'} eq 'window') {
8622: $confhash{$newid}{'display'}{'target'} = $env{'form.ltitools_add_target'};
8623: } else {
8624: $confhash{$newid}{'display'}{'target'} = 'iframe';
8625: }
8626: foreach my $item ('passback','roster') {
8627: if ($env{'form.ltitools_add_'.$item}) {
8628: $confhash{$newid}{$item} = 1;
8629: }
8630: }
8631: if ($env{'form.ltitools_add_image.filename'} ne '') {
8632: my ($imageurl,$error) =
8633: &process_ltitools_image($r,$dom,$confname,'ltitools_add_image',$dom,
8634: $configuserok,$switchserver,$author_ok);
8635: if ($imageurl) {
8636: $confhash{$newid}{'image'} = $imageurl;
8637: }
8638: if ($error) {
8639: &Apache::lonnet::logthis($error);
8640: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
8641: }
8642: }
8643: my @fields = &Apache::loncommon::get_env_multiple('form.ltitools_add_fields');
8644: foreach my $field (@fields) {
8645: if ($possfield{$field}) {
8646: if ($field eq 'roles') {
8647: foreach my $role (@courseroles) {
8648: my $choice = $env{'form.ltitools_add_roles_'.$role};
8649: if (($choice ne '') && ($posslti{$choice})) {
8650: $confhash{$newid}{'roles'}{$role} = $choice;
8651: if ($role eq 'cc') {
8652: $confhash{$newid}{'roles'}{'co'} = $choice;
8653: }
8654: }
8655: }
8656: } else {
8657: $confhash{$newid}{'fields'}{$field} = 1;
8658: }
8659: }
8660: }
1.273 raeburn 8661: my @courseconfig = &Apache::loncommon::get_env_multiple('form.ltitools_courseconfig');
8662: foreach my $item (@courseconfig) {
8663: $confhash{$newid}{'crsconf'}{$item} = 1;
8664: }
1.267 raeburn 8665: if ($env{'form.ltitools_add_custom'}) {
8666: my $name = $env{'form.ltitools_add_custom_name'};
8667: my $value = $env{'form.ltitools_add_custom_value'};
8668: $value =~ s/(`)/'/g;
8669: $name =~ s/(`)/'/g;
8670: $confhash{$newid}{'custom'}{$name} = $value;
8671: }
8672: } else {
8673: my $error = &mt('Failed to acquire unique ID for new external tool');
8674: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
8675: }
8676: }
8677: if (ref($domconfig{$action}) eq 'HASH') {
8678: my %deletions;
8679: my @todelete = &Apache::loncommon::get_env_multiple('form.ltitools_del');
8680: if (@todelete) {
8681: map { $deletions{$_} = 1; } @todelete;
8682: }
8683: my %customadds;
8684: my @newcustom = &Apache::loncommon::get_env_multiple('form.ltitools_customadd');
8685: if (@newcustom) {
8686: map { $customadds{$_} = 1; } @newcustom;
8687: }
8688: my %imgdeletions;
8689: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.ltitools_image_del');
8690: if (@todeleteimages) {
8691: map { $imgdeletions{$_} = 1; } @todeleteimages;
8692: }
8693: my $maxnum = $env{'form.ltitools_maxnum'};
8694: for (my $i=0; $i<=$maxnum; $i++) {
8695: my $itemid = $env{'form.ltitools_id_'.$i};
8696: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
8697: if ($deletions{$itemid}) {
8698: if ($domconfig{$action}{$itemid}{'image'}) {
8699: #FIXME need to obsolete item in RES space
8700: }
8701: $changes{$itemid} = $domconfig{$action}{$itemid}{'title'};
8702: next;
8703: } else {
8704: my $newpos = $env{'form.ltitools_'.$itemid};
8705: $newpos =~ s/\D+//g;
8706: foreach my $item ('title','url','key','secret') {
8707: $confhash{$itemid}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
8708: if ($domconfig{$action}{$itemid}{$item} ne $confhash{$itemid}{$item}) {
8709: $changes{$itemid} = 1;
8710: }
8711: }
8712: if ($env{'form.ltitools_version_'.$i} eq 'LTI-1p0') {
8713: $confhash{$itemid}{'version'} = $env{'form.ltitools_version_'.$i};
8714: }
8715: if ($env{'form.ltitools_msgtype_'.$i} eq 'basic-lti-launch-request') {
8716: $confhash{$itemid}{'msgtype'} = $env{'form.ltitools_msgtype_'.$i};
8717: }
8718: foreach my $size ('width','height') {
8719: $env{'form.ltitools_'.$size.'_'.$i} =~ s/^\s+//;
8720: $env{'form.ltitools_'.$size.'_'.$i} =~ s/\s+$//;
8721: if ($env{'form.ltitools_'.$size.'_'.$i} =~ /^\d+$/) {
8722: $confhash{$itemid}{'display'}{$size} = $env{'form.ltitools_'.$size.'_'.$i};
8723: if (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
8724: if ($domconfig{$action}{$itemid}{'display'}{$size} ne $confhash{$itemid}{'display'}{$size}) {
8725: $changes{$itemid} = 1;
8726: }
8727: } else {
8728: $changes{$itemid} = 1;
8729: }
8730: }
8731: }
8732: if ($env{'form.ltitools_target_'.$i} eq 'window') {
8733: $confhash{$itemid}{'display'}{'target'} = $env{'form.ltitools_target_'.$i};
8734: } else {
8735: $confhash{$itemid}{'display'}{'target'} = 'iframe';
8736: }
8737: if (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
8738: if ($domconfig{$action}{$itemid}{'display'}{'target'} ne $confhash{$itemid}{'display'}{'target'}) {
8739: $changes{$itemid} = 1;
8740: }
8741: } else {
8742: $changes{$itemid} = 1;
8743: }
8744: foreach my $extra ('passback','roster') {
8745: if ($env{'form.ltitools_'.$extra.'_'.$i}) {
8746: $confhash{$itemid}{$extra} = 1;
8747: }
8748: if ($domconfig{$action}{$itemid}{$extra} ne $confhash{$itemid}{$extra}) {
8749: $changes{$itemid} = 1;
8750: }
8751: }
1.273 raeburn 8752: my @courseconfig = &Apache::loncommon::get_env_multiple('form.ltitools_courseconfig_'.$i);
8753: foreach my $item ('label','title','target') {
8754: if (grep(/^\Q$item\E$/,@courseconfig)) {
8755: $confhash{$itemid}{'crsconf'}{$item} = 1;
8756: if (ref($domconfig{$action}{$itemid}{'crsconf'}) eq 'HASH') {
8757: if ($domconfig{$action}{$itemid}{'crsconf'}{$item} ne $confhash{$itemid}{'crsconf'}{$item}) {
8758: $changes{$itemid} = 1;
8759: }
8760: } else {
8761: $changes{$itemid} = 1;
8762: }
8763: }
8764: }
1.267 raeburn 8765: my @fields = &Apache::loncommon::get_env_multiple('form.ltitools_fields_'.$i);
8766: foreach my $field (@fields) {
8767: if ($possfield{$field}) {
8768: if ($field eq 'roles') {
8769: foreach my $role (@courseroles) {
8770: my $choice = $env{'form.ltitools_roles_'.$role.'_'.$i};
8771: if (($choice ne '') && ($posslti{$choice})) {
8772: $confhash{$itemid}{'roles'}{$role} = $choice;
8773: if ($role eq 'cc') {
8774: $confhash{$itemid}{'roles'}{'co'} = $choice;
8775: }
8776: }
8777: if (ref($domconfig{$action}{$itemid}{'roles'}) eq 'HASH') {
8778: if ($domconfig{$action}{$itemid}{'roles'}{$role} ne $confhash{$itemid}{'roles'}{$role}) {
8779: $changes{$itemid} = 1;
8780: }
8781: } elsif ($confhash{$itemid}{'roles'}{$role}) {
8782: $changes{$itemid} = 1;
8783: }
8784: }
8785: } else {
8786: $confhash{$itemid}{'fields'}{$field} = 1;
8787: if (ref($domconfig{$action}{$itemid}{'fields'}) eq 'HASH') {
8788: if ($domconfig{$action}{$itemid}{'fields'}{$field} ne $confhash{$itemid}{'fields'}{$field}) {
8789: $changes{$itemid} = 1;
8790: }
8791: } else {
8792: $changes{$itemid} = 1;
8793: }
8794: }
8795: }
8796: }
8797: $allpos[$newpos] = $itemid;
8798: }
8799: if ($imgdeletions{$itemid}) {
8800: $changes{$itemid} = 1;
8801: #FIXME need to obsolete item in RES space
8802: } elsif ($env{'form.ltitools_image_'.$i.'.filename'}) {
8803: my ($imgurl,$error) = &process_ltitools_image($r,$dom,$confname,'ltitools_image_'.$i,
8804: $itemid,$configuserok,$switchserver,
8805: $author_ok);
8806: if ($imgurl) {
8807: $confhash{$itemid}{'image'} = $imgurl;
8808: $changes{$itemid} = 1;
8809: }
8810: if ($error) {
8811: &Apache::lonnet::logthis($error);
8812: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
8813: }
8814: } elsif ($domconfig{$action}{$itemid}{'image'}) {
8815: $confhash{$itemid}{'image'} =
8816: $domconfig{$action}{$itemid}{'image'};
8817: }
8818: if ($customadds{$i}) {
8819: my $name = $env{'form.ltitools_custom_name_'.$i};
8820: $name =~ s/(`)/'/g;
8821: $name =~ s/^\s+//;
8822: $name =~ s/\s+$//;
8823: my $value = $env{'form.ltitools_custom_value_'.$i};
8824: $value =~ s/(`)/'/g;
8825: $value =~ s/^\s+//;
8826: $value =~ s/\s+$//;
8827: if ($name ne '') {
8828: $confhash{$itemid}{'custom'}{$name} = $value;
8829: $changes{$itemid} = 1;
8830: }
8831: }
8832: my %customdels;
8833: my @customdeletions = &Apache::loncommon::get_env_multiple('form.ltitools_customdel_'.$i);
8834: if (@customdeletions) {
8835: $changes{$itemid} = 1;
8836: }
8837: map { $customdels{$_} = 1; } @customdeletions;
8838: if (ref($domconfig{$action}{$itemid}{'custom'}) eq 'HASH') {
8839: foreach my $key (keys(%{$domconfig{$action}{$itemid}{'custom'}})) {
8840: unless ($customdels{$key}) {
8841: if ($env{'form.ltitools_customval_'.$key.'_'.$i} ne '') {
8842: $confhash{$itemid}{'custom'}{$key} = $env{'form.ltitools_customval_'.$key.'_'.$i};
8843: }
8844: if ($domconfig{$action}{$itemid}{'custom'}{$key} ne $env{'form.ltitools_customval_'.$key.'_'.$i}) {
8845: $changes{$itemid} = 1;
8846: }
8847: }
8848: }
8849: }
8850: unless ($changes{$itemid}) {
8851: foreach my $key (keys(%{$domconfig{$action}{$itemid}})) {
8852: if (ref($domconfig{$action}{$itemid}{$key}) eq 'HASH') {
8853: if (ref($confhash{$itemid}{$key}) eq 'HASH') {
8854: foreach my $innerkey (keys(%{$domconfig{$action}{$itemid}{$key}})) {
8855: unless (exists($confhash{$itemid}{$key}{$innerkey})) {
8856: $changes{$itemid} = 1;
8857: last;
8858: }
8859: }
8860: } elsif (keys(%{$domconfig{$action}{$itemid}{$key}}) > 0) {
8861: $changes{$itemid} = 1;
8862: }
8863: }
8864: last if ($changes{$itemid});
8865: }
8866: }
8867: }
8868: }
8869: }
8870: if (@allpos > 0) {
8871: my $idx = 0;
8872: foreach my $itemid (@allpos) {
8873: if ($itemid ne '') {
8874: $confhash{$itemid}{'order'} = $idx;
8875: if (ref($domconfig{$action}) eq 'HASH') {
8876: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
8877: if ($domconfig{$action}{$itemid}{'order'} ne $idx) {
8878: $changes{$itemid} = 1;
8879: }
8880: }
8881: }
8882: $idx ++;
8883: }
8884: }
8885: }
8886: my %ltitoolshash = (
8887: $action => { %confhash }
8888: );
8889: my $putresult = &Apache::lonnet::put_dom('configuration',\%ltitoolshash,
8890: $dom);
8891: if ($putresult eq 'ok') {
8892: if (keys(%changes) > 0) {
8893: my $cachetime = 24*60*60;
8894: &Apache::lonnet::do_cache_new('ltitools',$dom,\%confhash,$cachetime);
8895: if (ref($lastactref) eq 'HASH') {
8896: $lastactref->{'ltitools'} = 1;
8897: }
8898: $resulttext = &mt('Changes made:').'<ul>';
8899: my %bynum;
8900: foreach my $itemid (sort(keys(%changes))) {
8901: my $position = $confhash{$itemid}{'order'};
8902: $bynum{$position} = $itemid;
8903: }
8904: foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
8905: my $itemid = $bynum{$pos};
8906: if (ref($confhash{$itemid}) ne 'HASH') {
8907: $resulttext .= '<li>'.&mt('Deleted: [_1]',$changes{$itemid}).'</li>';
8908: } else {
8909: $resulttext .= '<li><b>'.$confhash{$itemid}{'title'}.'</b>';
8910: if ($confhash{$itemid}{'image'}) {
8911: $resulttext .= ' '.
8912: '<img src="'.$confhash{$itemid}{'image'}.'"'.
8913: ' alt="'.&mt('Tool Provider icon').'" />';
8914: }
8915: $resulttext .= '</li><ul>';
8916: my $position = $pos + 1;
8917: $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
8918: foreach my $item ('version','msgtype','url','key') {
8919: if ($confhash{$itemid}{$item} ne '') {
8920: $resulttext .= '<li>'.$lt{$item}.': '.$confhash{$itemid}{$item}.'</li>';
8921: }
8922: }
8923: if ($confhash{$itemid}{'secret'} ne '') {
8924: $resulttext .= '<li>'.$lt{'secret'}.': ';
8925: my $num = length($confhash{$itemid}{'secret'});
8926: $resulttext .= ('*'x$num).'</li>';
8927: }
1.273 raeburn 8928: $resulttext .= '<li>'.&mt('Configurable in course:');
8929: my @possconfig = ('label','title','target');
8930: my $numconfig = 0;
8931: if (ref($confhash{$itemid}{'crsconf'}) eq 'HASH') {
8932: foreach my $item (@possconfig) {
8933: if ($confhash{$itemid}{'crsconf'}{$item}) {
8934: $numconfig ++;
8935: $resulttext .= ' '.$lt{'crs'.$item};
8936: }
8937: }
8938: }
8939: if (!$numconfig) {
8940: $resulttext .= &mt('None');
8941: }
8942: $resulttext .= '</li>';
1.267 raeburn 8943: foreach my $item ('passback','roster') {
8944: $resulttext .= '<li>'.$lt{$item}.' ';
8945: if ($confhash{$itemid}{$item}) {
8946: $resulttext .= &mt('Yes');
8947: } else {
8948: $resulttext .= &mt('No');
8949: }
8950: $resulttext .= '</li>';
8951: }
8952: if (ref($confhash{$itemid}{'display'}) eq 'HASH') {
8953: my $displaylist;
8954: if ($confhash{$itemid}{'display'}{'target'}) {
8955: $displaylist = &mt('Display target').': '.
8956: $confhash{$itemid}{'display'}{'target'}.',';
8957: }
8958: foreach my $size ('width','height') {
8959: if ($confhash{$itemid}{'display'}{$size}) {
8960: $displaylist .= (' 'x2).$lt{$size}.': '.
8961: $confhash{$itemid}{'display'}{$size}.',';
8962: }
8963: }
8964: if ($displaylist) {
8965: $displaylist =~ s/,$//;
8966: $resulttext .= '<li>'.$displaylist.'</li>';
8967: }
8968: }
8969: if (ref($confhash{$itemid}{'fields'}) eq 'HASH') {
8970: my $fieldlist;
8971: foreach my $field (@allfields) {
8972: if ($confhash{$itemid}{'fields'}{$field}) {
8973: $fieldlist .= (' 'x2).$lt{$field}.',';
8974: }
8975: }
8976: if ($fieldlist) {
8977: $fieldlist =~ s/,$//;
8978: $resulttext .= '<li>'.&mt('Data sent').':'.$fieldlist.'</li>';
8979: }
8980: }
8981: if (ref($confhash{$itemid}{'roles'}) eq 'HASH') {
8982: my $rolemaps;
8983: foreach my $role (@courseroles) {
8984: if ($confhash{$itemid}{'roles'}{$role}) {
8985: $rolemaps .= (' 'x2).&Apache::lonnet::plaintext($role,'Course').'='.
8986: $confhash{$itemid}{'roles'}{$role}.',';
8987: }
8988: }
8989: if ($rolemaps) {
8990: $rolemaps =~ s/,$//;
8991: $resulttext .= '<li>'.&mt('Role mapping:').$rolemaps.'</li>';
8992: }
8993: }
8994: if (ref($confhash{$itemid}{'custom'}) eq 'HASH') {
8995: my $customlist;
8996: if (keys(%{$confhash{$itemid}{'custom'}})) {
8997: foreach my $key (sort(keys(%{$confhash{$itemid}{'custom'}}))) {
8998: $customlist .= $key.':'.$confhash{$itemid}{'custom'}{$key}.(' 'x2);
8999: }
9000: }
9001: if ($customlist) {
9002: $resulttext .= '<li>'.&mt('Custom items').':'.$customlist.'</li>';
9003: }
9004: }
9005: $resulttext .= '</ul></li>';
9006: }
9007: }
9008: $resulttext .= '</ul>';
9009: } else {
9010: $resulttext = &mt('No changes made.');
9011: }
9012: } else {
9013: $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
9014: }
9015: if ($errors) {
9016: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
9017: $errors.'</ul>';
9018: }
9019: return $resulttext;
9020: }
9021:
9022: sub process_ltitools_image {
9023: my ($r,$dom,$confname,$caller,$itemid,$configuserok,$switchserver,$author_ok) = @_;
9024: my $filename = $env{'form.'.$caller.'.filename'};
9025: my ($error,$url);
9026: my ($width,$height) = (21,21);
9027: if ($configuserok eq 'ok') {
9028: if ($switchserver) {
9029: $error = &mt('Upload of Tool Provider (LTI) icon is not permitted to this server: [_1]',
9030: $switchserver);
9031: } elsif ($author_ok eq 'ok') {
9032: my ($result,$imageurl,$madethumb) =
9033: &publishlogo($r,'upload',$caller,$dom,$confname,
9034: "ltitools/$itemid/icon",$width,$height);
9035: if ($result eq 'ok') {
9036: if ($madethumb) {
9037: my ($path,$imagefile) = ($imageurl =~ m{^(.+)/([^/]+)$});
9038: my $imagethumb = "$path/tn-".$imagefile;
9039: $url = $imagethumb;
9040: } else {
9041: $url = $imageurl;
9042: }
9043: } else {
9044: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
9045: }
9046: } else {
9047: $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);
9048: }
9049: } else {
9050: $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);
9051: }
9052: return ($url,$error);
9053: }
9054:
9055: sub get_ltitools_id {
9056: my ($cdom,$title) = @_;
9057: # get lock on ltitools db
9058: my $lockhash = {
9059: lock => $env{'user.name'}.
9060: ':'.$env{'user.domain'},
9061: };
9062: my $tries = 0;
9063: my $gotlock = &Apache::lonnet::newput_dom('ltitools',$lockhash,$cdom);
9064: my ($id,$error);
9065:
9066: while (($gotlock ne 'ok') && ($tries<10)) {
9067: $tries ++;
9068: sleep (0.1);
9069: $gotlock = &Apache::lonnet::newput_dom('ltitools',$lockhash,$cdom);
9070: }
9071: if ($gotlock eq 'ok') {
9072: my %currids = &Apache::lonnet::dump_dom('ltitools',$cdom);
9073: if ($currids{'lock'}) {
9074: delete($currids{'lock'});
9075: if (keys(%currids)) {
9076: my @curr = sort { $a <=> $b } keys(%currids);
9077: if ($curr[-1] =~ /^\d+$/) {
9078: $id = 1 + $curr[-1];
9079: }
9080: } else {
9081: $id = 1;
9082: }
9083: if ($id) {
9084: unless (&Apache::lonnet::newput_dom('ltitools',{ $id => $title },$cdom) eq 'ok') {
9085: $error = 'nostore';
9086: }
9087: } else {
9088: $error = 'nonumber';
9089: }
9090: }
9091: my $dellockoutcome = &Apache::lonnet::del_dom('ltitools',['lock'],$cdom);
9092: } else {
9093: $error = 'nolock';
9094: }
9095: return ($id,$error);
9096: }
9097:
1.3 raeburn 9098: sub modify_autoenroll {
1.205 raeburn 9099: my ($dom,$lastactref,%domconfig) = @_;
1.1 raeburn 9100: my ($resulttext,%changes);
9101: my %currautoenroll;
9102: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
9103: foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
9104: $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
9105: }
9106: }
9107: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
9108: my %title = ( run => 'Auto-enrollment active',
1.129 raeburn 9109: sender => 'Sender for notification messages',
1.274 raeburn 9110: coowners => 'Automatic assignment of co-ownership to instructors of record (institutional data)',
9111: failsafe => 'Failsafe for no drops if institutional data missing for a section');
1.1 raeburn 9112: my @offon = ('off','on');
1.17 raeburn 9113: my $sender_uname = $env{'form.sender_uname'};
9114: my $sender_domain = $env{'form.sender_domain'};
9115: if ($sender_domain eq '') {
9116: $sender_uname = '';
9117: } elsif ($sender_uname eq '') {
9118: $sender_domain = '';
9119: }
1.129 raeburn 9120: my $coowners = $env{'form.autoassign_coowners'};
1.274 raeburn 9121: my $failsafe = $env{'form.autoenroll_failsafe'};
9122: $failsafe =~ s{^\s+|\s+$}{}g;
9123: if ($failsafe =~ /\D/) {
9124: undef($failsafe);
9125: }
1.1 raeburn 9126: my %autoenrollhash = (
1.129 raeburn 9127: autoenroll => { 'run' => $env{'form.autoenroll_run'},
9128: 'sender_uname' => $sender_uname,
9129: 'sender_domain' => $sender_domain,
9130: 'co-owners' => $coowners,
1.274 raeburn 9131: 'autofailsafe' => $failsafe,
1.1 raeburn 9132: }
9133: );
1.4 raeburn 9134: my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
9135: $dom);
1.1 raeburn 9136: if ($putresult eq 'ok') {
9137: if (exists($currautoenroll{'run'})) {
9138: if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
9139: $changes{'run'} = 1;
9140: }
9141: } elsif ($autorun) {
9142: if ($env{'form.autoenroll_run'} ne '1') {
1.23 raeburn 9143: $changes{'run'} = 1;
1.1 raeburn 9144: }
9145: }
1.17 raeburn 9146: if ($currautoenroll{'sender_uname'} ne $sender_uname) {
1.1 raeburn 9147: $changes{'sender'} = 1;
9148: }
1.17 raeburn 9149: if ($currautoenroll{'sender_domain'} ne $sender_domain) {
1.1 raeburn 9150: $changes{'sender'} = 1;
9151: }
1.129 raeburn 9152: if ($currautoenroll{'co-owners'} ne '') {
9153: if ($currautoenroll{'co-owners'} ne $coowners) {
9154: $changes{'coowners'} = 1;
9155: }
9156: } elsif ($coowners) {
9157: $changes{'coowners'} = 1;
1.274 raeburn 9158: }
9159: if ($currautoenroll{'autofailsafe'} ne $failsafe) {
9160: $changes{'autofailsafe'} = 1;
9161: }
1.1 raeburn 9162: if (keys(%changes) > 0) {
9163: $resulttext = &mt('Changes made:').'<ul>';
1.3 raeburn 9164: if ($changes{'run'}) {
1.1 raeburn 9165: $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
9166: }
9167: if ($changes{'sender'}) {
1.17 raeburn 9168: if ($sender_uname eq '' || $sender_domain eq '') {
9169: $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
9170: } else {
9171: $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
9172: }
1.1 raeburn 9173: }
1.129 raeburn 9174: if ($changes{'coowners'}) {
9175: $resulttext .= '<li>'.&mt("$title{'coowners'} set to $offon[$env{'form.autoassign_coowners'}]").'</li>';
9176: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 9177: if (ref($lastactref) eq 'HASH') {
9178: $lastactref->{'domainconfig'} = 1;
9179: }
1.129 raeburn 9180: }
1.274 raeburn 9181: if ($changes{'autofailsafe'}) {
9182: if ($failsafe ne '') {
9183: $resulttext .= '<li>'.&mt("$title{'failsafe'} set to [_1]",$failsafe).'</li>';
9184: } else {
9185: $resulttext .= '<li>'.&mt("$title{'failsafe'} deleted");
9186: }
9187: &Apache::lonnet::get_domain_defaults($dom,1);
9188: if (ref($lastactref) eq 'HASH') {
9189: $lastactref->{'domdefaults'} = 1;
9190: }
9191: }
1.1 raeburn 9192: $resulttext .= '</ul>';
9193: } else {
9194: $resulttext = &mt('No changes made to auto-enrollment settings');
9195: }
9196: } else {
1.11 albertel 9197: $resulttext = '<span class="LC_error">'.
9198: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 9199: }
1.3 raeburn 9200: return $resulttext;
1.1 raeburn 9201: }
9202:
9203: sub modify_autoupdate {
1.3 raeburn 9204: my ($dom,%domconfig) = @_;
1.1 raeburn 9205: my ($resulttext,%currautoupdate,%fields,%changes);
9206: if (ref($domconfig{'autoupdate'}) eq 'HASH') {
9207: foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
9208: $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
9209: }
9210: }
9211: my @offon = ('off','on');
9212: my %title = &Apache::lonlocal::texthash (
9213: run => 'Auto-update:',
9214: classlists => 'Updates to user information in classlists?'
9215: );
1.44 raeburn 9216: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 9217: my %fieldtitles = &Apache::lonlocal::texthash (
9218: id => 'Student/Employee ID',
1.20 raeburn 9219: permanentemail => 'E-mail address',
1.1 raeburn 9220: lastname => 'Last Name',
9221: firstname => 'First Name',
9222: middlename => 'Middle Name',
1.132 raeburn 9223: generation => 'Generation',
1.1 raeburn 9224: );
1.142 raeburn 9225: $othertitle = &mt('All users');
1.1 raeburn 9226: if (keys(%{$usertypes}) > 0) {
1.26 raeburn 9227: $othertitle = &mt('Other users');
1.1 raeburn 9228: }
9229: foreach my $key (keys(%env)) {
9230: if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
1.132 raeburn 9231: my ($usertype,$item) = ($1,$2);
9232: if (grep(/^\Q$item\E$/,keys(%fieldtitles))) {
9233: if ($usertype eq 'default') {
9234: push(@{$fields{$1}},$2);
9235: } elsif (ref($types) eq 'ARRAY') {
9236: if (grep(/^\Q$usertype\E$/,@{$types})) {
9237: push(@{$fields{$1}},$2);
9238: }
9239: }
9240: }
1.1 raeburn 9241: }
9242: }
1.131 raeburn 9243: my @lockablenames = &Apache::loncommon::get_env_multiple('form.lockablenames');
9244: @lockablenames = sort(@lockablenames);
9245: if (ref($currautoupdate{'lockablenames'}) eq 'ARRAY') {
9246: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
9247: if (@changed) {
9248: $changes{'lockablenames'} = 1;
9249: }
9250: } else {
9251: if (@lockablenames) {
9252: $changes{'lockablenames'} = 1;
9253: }
9254: }
1.1 raeburn 9255: my %updatehash = (
9256: autoupdate => { run => $env{'form.autoupdate_run'},
9257: classlists => $env{'form.classlists'},
9258: fields => {%fields},
1.131 raeburn 9259: lockablenames => \@lockablenames,
1.1 raeburn 9260: }
9261: );
9262: foreach my $key (keys(%currautoupdate)) {
9263: if (($key eq 'run') || ($key eq 'classlists')) {
9264: if (exists($updatehash{autoupdate}{$key})) {
9265: if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
9266: $changes{$key} = 1;
9267: }
9268: }
9269: } elsif ($key eq 'fields') {
9270: if (ref($currautoupdate{$key}) eq 'HASH') {
1.26 raeburn 9271: foreach my $item (@{$types},'default') {
1.1 raeburn 9272: if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
9273: my $change = 0;
9274: foreach my $type (@{$currautoupdate{$key}{$item}}) {
9275: if (!exists($fields{$item})) {
9276: $change = 1;
1.132 raeburn 9277: last;
1.1 raeburn 9278: } elsif (ref($fields{$item}) eq 'ARRAY') {
1.26 raeburn 9279: if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
1.1 raeburn 9280: $change = 1;
1.132 raeburn 9281: last;
1.1 raeburn 9282: }
9283: }
9284: }
9285: if ($change) {
9286: push(@{$changes{$key}},$item);
9287: }
1.26 raeburn 9288: }
1.1 raeburn 9289: }
9290: }
1.131 raeburn 9291: } elsif ($key eq 'lockablenames') {
9292: if (ref($currautoupdate{$key}) eq 'ARRAY') {
9293: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
9294: if (@changed) {
9295: $changes{'lockablenames'} = 1;
9296: }
9297: } else {
9298: if (@lockablenames) {
9299: $changes{'lockablenames'} = 1;
9300: }
9301: }
9302: }
9303: }
9304: unless (grep(/^\Qlockablenames\E$/,keys(%currautoupdate))) {
9305: if (@lockablenames) {
9306: $changes{'lockablenames'} = 1;
1.1 raeburn 9307: }
9308: }
1.26 raeburn 9309: foreach my $item (@{$types},'default') {
9310: if (defined($fields{$item})) {
9311: if (ref($currautoupdate{'fields'}) eq 'HASH') {
1.132 raeburn 9312: if (ref($currautoupdate{'fields'}{$item}) eq 'ARRAY') {
9313: my $change = 0;
9314: if (ref($fields{$item}) eq 'ARRAY') {
9315: foreach my $type (@{$fields{$item}}) {
9316: if (!grep(/^\Q$type\E$/,@{$currautoupdate{'fields'}{$item}})) {
9317: $change = 1;
9318: last;
9319: }
9320: }
9321: }
9322: if ($change) {
9323: push(@{$changes{'fields'}},$item);
9324: }
9325: } else {
1.26 raeburn 9326: push(@{$changes{'fields'}},$item);
9327: }
9328: } else {
9329: push(@{$changes{'fields'}},$item);
1.1 raeburn 9330: }
9331: }
9332: }
9333: my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
9334: $dom);
9335: if ($putresult eq 'ok') {
9336: if (keys(%changes) > 0) {
9337: $resulttext = &mt('Changes made:').'<ul>';
9338: foreach my $key (sort(keys(%changes))) {
1.131 raeburn 9339: if ($key eq 'lockablenames') {
9340: $resulttext .= '<li>';
9341: if (@lockablenames) {
9342: $usertypes->{'default'} = $othertitle;
9343: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update), available for the following affiliations:").' '.
9344: join(', ', map { $usertypes->{$_}; } @lockablenames).'</li>';
9345: } else {
9346: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update) is unavailable.");
9347: }
9348: $resulttext .= '</li>';
9349: } elsif (ref($changes{$key}) eq 'ARRAY') {
1.1 raeburn 9350: foreach my $item (@{$changes{$key}}) {
9351: my @newvalues;
9352: foreach my $type (@{$fields{$item}}) {
9353: push(@newvalues,$fieldtitles{$type});
9354: }
1.3 raeburn 9355: my $newvaluestr;
9356: if (@newvalues > 0) {
9357: $newvaluestr = join(', ',@newvalues);
9358: } else {
9359: $newvaluestr = &mt('none');
1.6 raeburn 9360: }
1.1 raeburn 9361: if ($item eq 'default') {
1.26 raeburn 9362: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
1.1 raeburn 9363: } else {
1.26 raeburn 9364: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
1.1 raeburn 9365: }
9366: }
9367: } else {
9368: my $newvalue;
9369: if ($key eq 'run') {
9370: $newvalue = $offon[$env{'form.autoupdate_run'}];
9371: } else {
9372: $newvalue = $offon[$env{'form.'.$key}];
1.3 raeburn 9373: }
1.1 raeburn 9374: $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
9375: }
9376: }
9377: $resulttext .= '</ul>';
9378: } else {
1.3 raeburn 9379: $resulttext = &mt('No changes made to autoupdates');
1.1 raeburn 9380: }
9381: } else {
1.11 albertel 9382: $resulttext = '<span class="LC_error">'.
9383: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 9384: }
1.3 raeburn 9385: return $resulttext;
1.1 raeburn 9386: }
9387:
1.125 raeburn 9388: sub modify_autocreate {
9389: my ($dom,%domconfig) = @_;
9390: my ($resulttext,%changes,%currautocreate,%newvals,%autocreatehash);
9391: if (ref($domconfig{'autocreate'}) eq 'HASH') {
9392: foreach my $key (keys(%{$domconfig{'autocreate'}})) {
9393: $currautocreate{$key} = $domconfig{'autocreate'}{$key};
9394: }
9395: }
9396: my %title= ( xml => 'Auto-creation of courses in XML course description files',
9397: req => 'Auto-creation of validated requests for official courses',
9398: xmldc => 'Identity of course creator of courses from XML files',
9399: );
9400: my @types = ('xml','req');
9401: foreach my $item (@types) {
9402: $newvals{$item} = $env{'form.autocreate_'.$item};
9403: $newvals{$item} =~ s/\D//g;
9404: $newvals{$item} = 0 if ($newvals{$item} eq '');
9405: }
9406: $newvals{'xmldc'} = $env{'form.autocreate_xmldc'};
9407: my %domcoords = &get_active_dcs($dom);
9408: unless (exists($domcoords{$newvals{'xmldc'}})) {
9409: $newvals{'xmldc'} = '';
9410: }
9411: %autocreatehash = (
9412: autocreate => { xml => $newvals{'xml'},
9413: req => $newvals{'req'},
9414: }
9415: );
9416: if ($newvals{'xmldc'} ne '') {
9417: $autocreatehash{'autocreate'}{'xmldc'} = $newvals{'xmldc'};
9418: }
9419: my $putresult = &Apache::lonnet::put_dom('configuration',\%autocreatehash,
9420: $dom);
9421: if ($putresult eq 'ok') {
9422: my @items = @types;
9423: if ($newvals{'xml'}) {
9424: push(@items,'xmldc');
9425: }
9426: foreach my $item (@items) {
9427: if (exists($currautocreate{$item})) {
9428: if ($currautocreate{$item} ne $newvals{$item}) {
9429: $changes{$item} = 1;
9430: }
9431: } elsif ($newvals{$item}) {
9432: $changes{$item} = 1;
9433: }
9434: }
9435: if (keys(%changes) > 0) {
9436: my @offon = ('off','on');
9437: $resulttext = &mt('Changes made:').'<ul>';
9438: foreach my $item (@types) {
9439: if ($changes{$item}) {
9440: my $newtxt = $offon[$newvals{$item}];
1.178 raeburn 9441: $resulttext .= '<li>'.
9442: &mt("$title{$item} set to [_1]$newtxt [_2]",
9443: '<b>','</b>').
9444: '</li>';
1.125 raeburn 9445: }
9446: }
9447: if ($changes{'xmldc'}) {
9448: my ($dcname,$dcdom) = split(':',$newvals{'xmldc'});
9449: my $newtxt = &Apache::loncommon::plainname($dcname,$dcdom);
1.178 raeburn 9450: $resulttext .= '<li>'.&mt("$title{'xmldc'} set to [_1]",'<b>'.$newtxt.'</b>').'</li>';
1.125 raeburn 9451: }
9452: $resulttext .= '</ul>';
9453: } else {
9454: $resulttext = &mt('No changes made to auto-creation settings');
9455: }
9456: } else {
9457: $resulttext = '<span class="LC_error">'.
9458: &mt('An error occurred: [_1]',$putresult).'</span>';
9459: }
9460: return $resulttext;
9461: }
9462:
1.23 raeburn 9463: sub modify_directorysrch {
9464: my ($dom,%domconfig) = @_;
9465: my ($resulttext,%changes);
9466: my %currdirsrch;
9467: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
9468: foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
9469: $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
9470: }
9471: }
9472: my %title = ( available => 'Directory search available',
1.24 raeburn 9473: localonly => 'Other domains can search',
1.23 raeburn 9474: searchby => 'Search types',
9475: searchtypes => 'Search latitude');
9476: my @offon = ('off','on');
1.24 raeburn 9477: my @otherdoms = ('Yes','No');
1.23 raeburn 9478:
1.25 raeburn 9479: my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');
1.23 raeburn 9480: my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
9481: my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
9482:
1.44 raeburn 9483: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.26 raeburn 9484: if (keys(%{$usertypes}) == 0) {
9485: @cansearch = ('default');
9486: } else {
9487: if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
9488: foreach my $type (@{$currdirsrch{'cansearch'}}) {
9489: if (!grep(/^\Q$type\E$/,@cansearch)) {
9490: push(@{$changes{'cansearch'}},$type);
9491: }
1.23 raeburn 9492: }
1.26 raeburn 9493: foreach my $type (@cansearch) {
9494: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
9495: push(@{$changes{'cansearch'}},$type);
9496: }
1.23 raeburn 9497: }
1.26 raeburn 9498: } else {
9499: push(@{$changes{'cansearch'}},@cansearch);
1.23 raeburn 9500: }
9501: }
9502:
9503: if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
9504: foreach my $by (@{$currdirsrch{'searchby'}}) {
9505: if (!grep(/^\Q$by\E$/,@searchby)) {
9506: push(@{$changes{'searchby'}},$by);
9507: }
9508: }
9509: foreach my $by (@searchby) {
9510: if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
9511: push(@{$changes{'searchby'}},$by);
9512: }
9513: }
9514: } else {
9515: push(@{$changes{'searchby'}},@searchby);
9516: }
1.25 raeburn 9517:
9518: if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
9519: foreach my $type (@{$currdirsrch{'searchtypes'}}) {
9520: if (!grep(/^\Q$type\E$/,@searchtypes)) {
9521: push(@{$changes{'searchtypes'}},$type);
9522: }
9523: }
9524: foreach my $type (@searchtypes) {
9525: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
9526: push(@{$changes{'searchtypes'}},$type);
9527: }
9528: }
9529: } else {
9530: if (exists($currdirsrch{'searchtypes'})) {
9531: foreach my $type (@searchtypes) {
9532: if ($type ne $currdirsrch{'searchtypes'}) {
9533: push(@{$changes{'searchtypes'}},$type);
9534: }
9535: }
9536: if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
9537: push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
9538: }
9539: } else {
9540: push(@{$changes{'searchtypes'}},@searchtypes);
9541: }
9542: }
9543:
1.23 raeburn 9544: my %dirsrch_hash = (
9545: directorysrch => { available => $env{'form.dirsrch_available'},
9546: cansearch => \@cansearch,
1.24 raeburn 9547: localonly => $env{'form.dirsrch_localonly'},
1.23 raeburn 9548: searchby => \@searchby,
1.25 raeburn 9549: searchtypes => \@searchtypes,
1.23 raeburn 9550: }
9551: );
9552: my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
9553: $dom);
9554: if ($putresult eq 'ok') {
9555: if (exists($currdirsrch{'available'})) {
9556: if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
9557: $changes{'available'} = 1;
9558: }
9559: } else {
9560: if ($env{'form.dirsrch_available'} eq '1') {
9561: $changes{'available'} = 1;
9562: }
9563: }
1.24 raeburn 9564: if (exists($currdirsrch{'localonly'})) {
9565: if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_localonly'}) {
9566: $changes{'localonly'} = 1;
9567: }
9568: } else {
9569: if ($env{'form.dirsrch_localonly'} eq '1') {
9570: $changes{'localonly'} = 1;
9571: }
9572: }
1.23 raeburn 9573: if (keys(%changes) > 0) {
9574: $resulttext = &mt('Changes made:').'<ul>';
9575: if ($changes{'available'}) {
9576: $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
9577: }
1.24 raeburn 9578: if ($changes{'localonly'}) {
9579: $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_localonly'}]").'</li>';
9580: }
9581:
1.23 raeburn 9582: if (ref($changes{'cansearch'}) eq 'ARRAY') {
9583: my $chgtext;
1.26 raeburn 9584: if (ref($usertypes) eq 'HASH') {
9585: if (keys(%{$usertypes}) > 0) {
9586: foreach my $type (@{$types}) {
9587: if (grep(/^\Q$type\E$/,@cansearch)) {
9588: $chgtext .= $usertypes->{$type}.'; ';
9589: }
9590: }
9591: if (grep(/^default$/,@cansearch)) {
9592: $chgtext .= $othertitle;
9593: } else {
9594: $chgtext =~ s/\; $//;
9595: }
1.210 raeburn 9596: $resulttext .=
1.178 raeburn 9597: '<li>'.
9598: &mt("Users from domain '[_1]' permitted to search the institutional directory set to: [_2]",
9599: '<span class="LC_cusr_emph">'.$dom.'</span>',$chgtext).
9600: '</li>';
1.23 raeburn 9601: }
9602: }
9603: }
9604: if (ref($changes{'searchby'}) eq 'ARRAY') {
9605: my ($searchtitles,$titleorder) = &sorted_searchtitles();
9606: my $chgtext;
9607: foreach my $type (@{$titleorder}) {
9608: if (grep(/^\Q$type\E$/,@searchby)) {
9609: if (defined($searchtitles->{$type})) {
9610: $chgtext .= $searchtitles->{$type}.'; ';
9611: }
9612: }
9613: }
9614: $chgtext =~ s/\; $//;
9615: $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
9616: }
1.25 raeburn 9617: if (ref($changes{'searchtypes'}) eq 'ARRAY') {
9618: my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes();
9619: my $chgtext;
9620: foreach my $type (@{$srchtypeorder}) {
9621: if (grep(/^\Q$type\E$/,@searchtypes)) {
9622: if (defined($srchtypes_desc->{$type})) {
9623: $chgtext .= $srchtypes_desc->{$type}.'; ';
9624: }
9625: }
9626: }
9627: $chgtext =~ s/\; $//;
1.178 raeburn 9628: $resulttext .= '<li>'.&mt($title{'searchtypes'}.' set to: "[_1]"',$chgtext).'</li>';
1.23 raeburn 9629: }
9630: $resulttext .= '</ul>';
9631: } else {
9632: $resulttext = &mt('No changes made to institution directory search settings');
9633: }
9634: } else {
9635: $resulttext = '<span class="LC_error">'.
1.27 raeburn 9636: &mt('An error occurred: [_1]',$putresult).'</span>';
9637: }
9638: return $resulttext;
9639: }
9640:
1.28 raeburn 9641: sub modify_contacts {
1.205 raeburn 9642: my ($dom,$lastactref,%domconfig) = @_;
1.28 raeburn 9643: my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
9644: if (ref($domconfig{'contacts'}) eq 'HASH') {
9645: foreach my $key (keys(%{$domconfig{'contacts'}})) {
9646: $currsetting{$key} = $domconfig{'contacts'}{$key};
9647: }
9648: }
1.134 raeburn 9649: my (%others,%to,%bcc);
1.28 raeburn 9650: my @contacts = ('supportemail','adminemail');
1.102 raeburn 9651: my @mailings = ('errormail','packagesmail','helpdeskmail','lonstatusmail',
1.203 raeburn 9652: 'requestsmail','updatesmail','idconflictsmail');
9653: my @toggles = ('reporterrors','reportupdates');
1.28 raeburn 9654: foreach my $type (@mailings) {
9655: @{$newsetting{$type}} =
9656: &Apache::loncommon::get_env_multiple('form.'.$type);
9657: foreach my $item (@contacts) {
9658: if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
9659: $contacts_hash{contacts}{$type}{$item} = 1;
9660: } else {
9661: $contacts_hash{contacts}{$type}{$item} = 0;
9662: }
9663: }
9664: $others{$type} = $env{'form.'.$type.'_others'};
9665: $contacts_hash{contacts}{$type}{'others'} = $others{$type};
1.134 raeburn 9666: if ($type eq 'helpdeskmail') {
9667: $bcc{$type} = $env{'form.'.$type.'_bcc'};
9668: $contacts_hash{contacts}{$type}{'bcc'} = $bcc{$type};
9669: }
1.28 raeburn 9670: }
9671: foreach my $item (@contacts) {
9672: $to{$item} = $env{'form.'.$item};
9673: $contacts_hash{'contacts'}{$item} = $to{$item};
9674: }
1.203 raeburn 9675: foreach my $item (@toggles) {
9676: if ($env{'form.'.$item} =~ /^(0|1)$/) {
9677: $contacts_hash{'contacts'}{$item} = $env{'form.'.$item};
9678: }
9679: }
1.28 raeburn 9680: if (keys(%currsetting) > 0) {
9681: foreach my $item (@contacts) {
9682: if ($to{$item} ne $currsetting{$item}) {
9683: $changes{$item} = 1;
9684: }
9685: }
9686: foreach my $type (@mailings) {
9687: foreach my $item (@contacts) {
9688: if (ref($currsetting{$type}) eq 'HASH') {
9689: if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
9690: push(@{$changes{$type}},$item);
9691: }
9692: } else {
9693: push(@{$changes{$type}},@{$newsetting{$type}});
9694: }
9695: }
9696: if ($others{$type} ne $currsetting{$type}{'others'}) {
9697: push(@{$changes{$type}},'others');
9698: }
1.134 raeburn 9699: if ($type eq 'helpdeskmail') {
9700: if ($bcc{$type} ne $currsetting{$type}{'bcc'}) {
9701: push(@{$changes{$type}},'bcc');
9702: }
9703: }
1.28 raeburn 9704: }
9705: } else {
9706: my %default;
9707: $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
9708: $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
9709: $default{'errormail'} = 'adminemail';
9710: $default{'packagesmail'} = 'adminemail';
9711: $default{'helpdeskmail'} = 'supportemail';
1.89 raeburn 9712: $default{'lonstatusmail'} = 'adminemail';
1.102 raeburn 9713: $default{'requestsmail'} = 'adminemail';
1.190 raeburn 9714: $default{'updatesmail'} = 'adminemail';
1.28 raeburn 9715: foreach my $item (@contacts) {
9716: if ($to{$item} ne $default{$item}) {
9717: $changes{$item} = 1;
1.203 raeburn 9718: }
1.28 raeburn 9719: }
9720: foreach my $type (@mailings) {
9721: if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
9722:
9723: push(@{$changes{$type}},@{$newsetting{$type}});
9724: }
9725: if ($others{$type} ne '') {
9726: push(@{$changes{$type}},'others');
1.134 raeburn 9727: }
9728: if ($type eq 'helpdeskmail') {
9729: if ($bcc{$type} ne '') {
9730: push(@{$changes{$type}},'bcc');
9731: }
9732: }
1.28 raeburn 9733: }
9734: }
1.203 raeburn 9735: foreach my $item (@toggles) {
9736: if (($env{'form.'.$item} == 1) && ($currsetting{$item} == 0)) {
9737: $changes{$item} = 1;
9738: } elsif ((!$env{'form.'.$item}) &&
9739: (($currsetting{$item} eq '') || ($currsetting{$item} == 1))) {
9740: $changes{$item} = 1;
9741: }
9742: }
1.28 raeburn 9743: my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
9744: $dom);
9745: if ($putresult eq 'ok') {
9746: if (keys(%changes) > 0) {
1.205 raeburn 9747: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 9748: if (ref($lastactref) eq 'HASH') {
9749: $lastactref->{'domainconfig'} = 1;
9750: }
1.28 raeburn 9751: my ($titles,$short_titles) = &contact_titles();
9752: $resulttext = &mt('Changes made:').'<ul>';
9753: foreach my $item (@contacts) {
9754: if ($changes{$item}) {
9755: $resulttext .= '<li>'.$titles->{$item}.
9756: &mt(' set to: ').
9757: '<span class="LC_cusr_emph">'.
9758: $to{$item}.'</span></li>';
9759: }
9760: }
9761: foreach my $type (@mailings) {
9762: if (ref($changes{$type}) eq 'ARRAY') {
9763: $resulttext .= '<li>'.$titles->{$type}.': ';
9764: my @text;
9765: foreach my $item (@{$newsetting{$type}}) {
9766: push(@text,$short_titles->{$item});
9767: }
9768: if ($others{$type} ne '') {
9769: push(@text,$others{$type});
9770: }
9771: $resulttext .= '<span class="LC_cusr_emph">'.
1.134 raeburn 9772: join(', ',@text).'</span>';
9773: if ($type eq 'helpdeskmail') {
9774: if ($bcc{$type} ne '') {
9775: $resulttext .= ' '.&mt('with Bcc to').': <span class="LC_cusr_emph">'.$bcc{$type}.'</span>';
9776: }
9777: }
9778: $resulttext .= '</li>';
1.28 raeburn 9779: }
9780: }
1.203 raeburn 9781: my @offon = ('off','on');
9782: if ($changes{'reporterrors'}) {
9783: $resulttext .= '<li>'.
9784: &mt('E-mail error reports to [_1] set to "'.
9785: $offon[$env{'form.reporterrors'}].'".',
9786: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
9787: &mt('LON-CAPA core group - MSU'),600,500)).
9788: '</li>';
9789: }
9790: if ($changes{'reportupdates'}) {
9791: $resulttext .= '<li>'.
9792: &mt('E-mail record of completed LON-CAPA updates to [_1] set to "'.
9793: $offon[$env{'form.reportupdates'}].'".',
9794: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
9795: &mt('LON-CAPA core group - MSU'),600,500)).
9796: '</li>';
9797: }
1.28 raeburn 9798: $resulttext .= '</ul>';
9799: } else {
1.34 raeburn 9800: $resulttext = &mt('No changes made to contact information');
1.28 raeburn 9801: }
9802: } else {
9803: $resulttext = '<span class="LC_error">'.
9804: &mt('An error occurred: [_1].',$putresult).'</span>';
9805: }
9806: return $resulttext;
9807: }
9808:
9809: sub modify_usercreation {
1.27 raeburn 9810: my ($dom,%domconfig) = @_;
1.224 raeburn 9811: my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate,%save_usercreate);
1.43 raeburn 9812: my $warningmsg;
1.27 raeburn 9813: if (ref($domconfig{'usercreation'}) eq 'HASH') {
9814: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
1.224 raeburn 9815: if ($key eq 'cancreate') {
9816: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
9817: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
9818: if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
1.269 raeburn 9819: ($item eq 'captcha') || ($item eq 'recaptchakeys') ||
9820: ($item eq 'recaptchaversion')) {
1.224 raeburn 9821: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
9822: } else {
9823: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
9824: }
9825: }
9826: }
9827: } elsif ($key eq 'email_rule') {
9828: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
9829: } else {
9830: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
9831: }
1.27 raeburn 9832: }
9833: }
9834: my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
1.32 raeburn 9835: my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
1.224 raeburn 9836: my @contexts = ('author','course','requestcrs');
1.34 raeburn 9837: foreach my $item(@contexts) {
1.224 raeburn 9838: $cancreate{$item} = $env{'form.can_createuser_'.$item};
1.93 raeburn 9839: }
1.34 raeburn 9840: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
9841: foreach my $item (@contexts) {
1.224 raeburn 9842: if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
9843: push(@{$changes{'cancreate'}},$item);
1.50 raeburn 9844: }
1.27 raeburn 9845: }
1.34 raeburn 9846: } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
9847: foreach my $item (@contexts) {
1.43 raeburn 9848: if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
1.34 raeburn 9849: if ($cancreate{$item} ne 'any') {
9850: push(@{$changes{'cancreate'}},$item);
9851: }
9852: } else {
9853: if ($cancreate{$item} ne 'none') {
9854: push(@{$changes{'cancreate'}},$item);
9855: }
1.27 raeburn 9856: }
9857: }
9858: } else {
1.43 raeburn 9859: foreach my $item (@contexts) {
1.34 raeburn 9860: push(@{$changes{'cancreate'}},$item);
9861: }
1.27 raeburn 9862: }
1.34 raeburn 9863:
1.27 raeburn 9864: if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
9865: foreach my $type (@{$curr_usercreation{'username_rule'}}) {
9866: if (!grep(/^\Q$type\E$/,@username_rule)) {
9867: push(@{$changes{'username_rule'}},$type);
9868: }
9869: }
9870: foreach my $type (@username_rule) {
9871: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
9872: push(@{$changes{'username_rule'}},$type);
9873: }
9874: }
9875: } else {
9876: push(@{$changes{'username_rule'}},@username_rule);
9877: }
9878:
1.32 raeburn 9879: if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
9880: foreach my $type (@{$curr_usercreation{'id_rule'}}) {
9881: if (!grep(/^\Q$type\E$/,@id_rule)) {
9882: push(@{$changes{'id_rule'}},$type);
9883: }
9884: }
9885: foreach my $type (@id_rule) {
9886: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
9887: push(@{$changes{'id_rule'}},$type);
9888: }
9889: }
9890: } else {
9891: push(@{$changes{'id_rule'}},@id_rule);
9892: }
9893:
1.43 raeburn 9894: my @authen_contexts = ('author','course','domain');
1.28 raeburn 9895: my @authtypes = ('int','krb4','krb5','loc');
9896: my %authhash;
1.43 raeburn 9897: foreach my $item (@authen_contexts) {
1.28 raeburn 9898: my @authallowed = &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
9899: foreach my $auth (@authtypes) {
9900: if (grep(/^\Q$auth\E$/,@authallowed)) {
9901: $authhash{$item}{$auth} = 1;
9902: } else {
9903: $authhash{$item}{$auth} = 0;
9904: }
9905: }
9906: }
9907: if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
1.43 raeburn 9908: foreach my $item (@authen_contexts) {
1.28 raeburn 9909: if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
9910: foreach my $auth (@authtypes) {
9911: if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
9912: push(@{$changes{'authtypes'}},$item);
9913: last;
9914: }
9915: }
9916: }
9917: }
9918: } else {
1.43 raeburn 9919: foreach my $item (@authen_contexts) {
1.28 raeburn 9920: push(@{$changes{'authtypes'}},$item);
9921: }
9922: }
9923:
1.224 raeburn 9924: $save_usercreate{'cancreate'}{'course'} = $cancreate{'course'};
9925: $save_usercreate{'cancreate'}{'author'} = $cancreate{'author'};
9926: $save_usercreate{'cancreate'}{'requestcrs'} = $cancreate{'requestcrs'};
9927: $save_usercreate{'id_rule'} = \@id_rule;
9928: $save_usercreate{'username_rule'} = \@username_rule,
9929: $save_usercreate{'authtypes'} = \%authhash;
9930:
1.27 raeburn 9931: my %usercreation_hash = (
1.224 raeburn 9932: usercreation => \%save_usercreate,
9933: );
1.27 raeburn 9934:
9935: my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
9936: $dom);
1.50 raeburn 9937:
1.224 raeburn 9938: if ($putresult eq 'ok') {
9939: if (keys(%changes) > 0) {
9940: $resulttext = &mt('Changes made:').'<ul>';
9941: if (ref($changes{'cancreate'}) eq 'ARRAY') {
9942: my %lt = &usercreation_types();
9943: foreach my $type (@{$changes{'cancreate'}}) {
9944: my $chgtext = $lt{$type}.', ';
9945: if ($cancreate{$type} eq 'none') {
9946: $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
9947: } elsif ($cancreate{$type} eq 'any') {
9948: $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
9949: } elsif ($cancreate{$type} eq 'official') {
9950: $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
9951: } elsif ($cancreate{$type} eq 'unofficial') {
9952: $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
9953: }
9954: $resulttext .= '<li>'.$chgtext.'</li>';
9955: }
9956: }
9957: if (ref($changes{'username_rule'}) eq 'ARRAY') {
9958: my ($rules,$ruleorder) =
9959: &Apache::lonnet::inst_userrules($dom,'username');
9960: my $chgtext = '<ul>';
9961: foreach my $type (@username_rule) {
9962: if (ref($rules->{$type}) eq 'HASH') {
9963: $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
9964: }
9965: }
9966: $chgtext .= '</ul>';
9967: if (@username_rule > 0) {
9968: $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
9969: } else {
9970: $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>';
9971: }
9972: }
9973: if (ref($changes{'id_rule'}) eq 'ARRAY') {
9974: my ($idrules,$idruleorder) =
9975: &Apache::lonnet::inst_userrules($dom,'id');
9976: my $chgtext = '<ul>';
9977: foreach my $type (@id_rule) {
9978: if (ref($idrules->{$type}) eq 'HASH') {
9979: $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
9980: }
9981: }
9982: $chgtext .= '</ul>';
9983: if (@id_rule > 0) {
9984: $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
9985: } else {
9986: $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
9987: }
9988: }
9989: my %authname = &authtype_names();
9990: my %context_title = &context_names();
9991: if (ref($changes{'authtypes'}) eq 'ARRAY') {
9992: my $chgtext = '<ul>';
9993: foreach my $type (@{$changes{'authtypes'}}) {
9994: my @allowed;
9995: $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
9996: foreach my $auth (@authtypes) {
9997: if ($authhash{$type}{$auth}) {
9998: push(@allowed,$authname{$auth});
9999: }
10000: }
10001: if (@allowed > 0) {
10002: $chgtext .= join(', ',@allowed).'</li>';
10003: } else {
10004: $chgtext .= &mt('none').'</li>';
10005: }
10006: }
10007: $chgtext .= '</ul>';
10008: $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
10009: $resulttext .= '</li>';
10010: }
10011: $resulttext .= '</ul>';
10012: } else {
10013: $resulttext = &mt('No changes made to user creation settings');
10014: }
10015: } else {
10016: $resulttext = '<span class="LC_error">'.
10017: &mt('An error occurred: [_1]',$putresult).'</span>';
10018: }
10019: if ($warningmsg ne '') {
10020: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
10021: }
10022: return $resulttext;
10023: }
10024:
10025: sub modify_selfcreation {
10026: my ($dom,%domconfig) = @_;
10027: my ($resulttext,$warningmsg,%curr_usercreation,%curr_usermodify,%changes,%cancreate);
10028: my (%save_usercreate,%save_usermodify);
1.228 raeburn 10029: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
10030: if (ref($types) eq 'ARRAY') {
10031: $usertypes->{'default'} = $othertitle;
10032: push(@{$types},'default');
10033: }
1.224 raeburn 10034: #
10035: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usercreation'}.
10036: #
10037: if (ref($domconfig{'usercreation'}) eq 'HASH') {
10038: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
10039: if ($key eq 'cancreate') {
10040: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
10041: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
10042: if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
10043: ($item eq 'captcha') || ($item eq 'recaptchakeys') ||
1.269 raeburn 10044: ($item eq 'recaptchaversion') ||
1.236 raeburn 10045: ($item eq 'emailusername') || ($item eq 'notify') ||
1.240 raeburn 10046: ($item eq 'selfcreateprocessing') || ($item eq 'shibenv')) {
1.224 raeburn 10047: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
10048: } else {
10049: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
10050: }
10051: }
10052: }
10053: } elsif ($key eq 'email_rule') {
10054: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
10055: } else {
10056: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
10057: }
10058: }
10059: }
10060: #
10061: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usermodification'}.
10062: #
10063: if (ref($domconfig{'usermodification'}) eq 'HASH') {
10064: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
10065: if ($key eq 'selfcreate') {
10066: $curr_usermodify{$key} = $domconfig{'usermodification'}{$key};
10067: } else {
10068: $save_usermodify{$key} = $domconfig{'usermodification'}{$key};
10069: }
10070: }
10071: }
10072:
10073: my @contexts = ('selfcreate');
10074: @{$cancreate{'selfcreate'}} = ();
10075: %{$cancreate{'emailusername'}} = ();
10076: @{$cancreate{'statustocreate'}} = ();
1.236 raeburn 10077: %{$cancreate{'selfcreateprocessing'}} = ();
1.240 raeburn 10078: %{$cancreate{'shibenv'}} = ();
1.50 raeburn 10079: my %selfcreatetypes = (
10080: sso => 'users authenticated by institutional single sign on',
10081: login => 'users authenticated by institutional log-in',
1.236 raeburn 10082: email => 'users who provide a valid e-mail address for use as username',
1.50 raeburn 10083: );
1.224 raeburn 10084: #
10085: # Populate $cancreate{'selfcreate'} array reference with types of user, for which self-creation of user accounts
10086: # is permitted.
10087: #
1.236 raeburn 10088:
10089: my @statuses;
10090: if (ref($domconfig{'inststatus'}) eq 'HASH') {
10091: if (ref($domconfig{'inststatus'}{'inststatusguest'}) eq 'ARRAY') {
10092: @statuses = @{$domconfig{'inststatus'}{'inststatusguest'}};
10093: }
10094: }
10095: push(@statuses,'default');
10096:
1.228 raeburn 10097: foreach my $item ('login','sso','email') {
1.224 raeburn 10098: if ($item eq 'email') {
1.236 raeburn 10099: if ($env{'form.cancreate_email'}) {
1.224 raeburn 10100: push(@{$cancreate{'selfcreate'}},'email');
1.236 raeburn 10101: push(@contexts,'selfcreateprocessing');
10102: foreach my $type (@statuses) {
10103: if ($type eq 'default') {
10104: $cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess'};
10105: } else {
10106: $cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess_'.$type};
10107: }
10108: }
1.224 raeburn 10109: }
10110: } else {
10111: if ($env{'form.cancreate_'.$item}) {
10112: push(@{$cancreate{'selfcreate'}},$item);
10113: }
10114: }
10115: }
10116: my (@email_rule,%userinfo,%savecaptcha);
10117: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
10118: #
1.228 raeburn 10119: # Populate $cancreate{'emailusername'}{$type} hash ref with information fields (if new user will provide data
10120: # value set to one), if self-creation with e-mail address permitted, where $type is user type: faculty, staff, student etc.
1.224 raeburn 10121: #
1.236 raeburn 10122:
1.244 raeburn 10123: if ($env{'form.cancreate_email'}) {
1.228 raeburn 10124: push(@contexts,'emailusername');
10125: if (ref($types) eq 'ARRAY') {
10126: foreach my $type (@{$types}) {
10127: if (ref($infofields) eq 'ARRAY') {
10128: foreach my $field (@{$infofields}) {
10129: if ($env{'form.canmodify_emailusername_'.$type.'_'.$field} =~ /^(required|optional)$/) {
10130: $cancreate{'emailusername'}{$type}{$field} = $1;
10131: }
10132: }
1.224 raeburn 10133: }
10134: }
10135: }
10136: #
10137: # Populate $cancreate{'notify'} hash ref with names of Domain Coordinators who are to be notified of
10138: # queued requests for self-creation of account using e-mail address as username
10139: #
10140:
10141: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.selfcreationnotifyapproval');
10142: @approvalnotify = sort(@approvalnotify);
10143: $cancreate{'notify'}{'approval'} = join(',',@approvalnotify);
10144: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
10145: if (ref($curr_usercreation{'cancreate'}{'notify'}) eq 'HASH') {
10146: if ($curr_usercreation{'cancreate'}{'notify'}{'approval'} ne $cancreate{'notify'}{'approval'}) {
10147: push(@{$changes{'cancreate'}},'notify');
10148: }
10149: } else {
10150: if ($cancreate{'notify'}{'approval'}) {
10151: push(@{$changes{'cancreate'}},'notify');
10152: }
10153: }
10154: } elsif ($cancreate{'notify'}{'approval'}) {
10155: push(@{$changes{'cancreate'}},'notify');
10156: }
10157:
10158: #
10159: # Retrieve rules (if any) governing types of e-mail address which may be used as a username
10160: #
10161: @email_rule = &Apache::loncommon::get_env_multiple('form.email_rule');
10162: &process_captcha('cancreate',\%changes,\%savecaptcha,$curr_usercreation{'cancreate'});
10163: if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
10164: if (@{$curr_usercreation{'email_rule'}} > 0) {
10165: foreach my $type (@{$curr_usercreation{'email_rule'}}) {
10166: if (!grep(/^\Q$type\E$/,@email_rule)) {
10167: push(@{$changes{'email_rule'}},$type);
10168: }
10169: }
10170: }
10171: if (@email_rule > 0) {
10172: foreach my $type (@email_rule) {
10173: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'email_rule'}})) {
10174: push(@{$changes{'email_rule'}},$type);
10175: }
10176: }
10177: }
10178: } elsif (@email_rule > 0) {
10179: push(@{$changes{'email_rule'}},@email_rule);
10180: }
10181: }
10182: #
1.236 raeburn 10183: # Check if domain default is set appropriately, if self-creation of accounts is to be available for
1.224 raeburn 10184: # institutional log-in.
10185: #
10186: if (grep(/^login$/,@{$cancreate{'selfcreate'}})) {
10187: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
10188: if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) ||
10189: ($domdefaults{'auth_def'} eq 'localauth'))) {
10190: $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.').' '.
10191: &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.');
10192: }
10193: }
10194: my @fields = ('lastname','firstname','middlename','generation',
10195: 'permanentemail','id');
1.240 raeburn 10196: my @shibfields = (@fields,'inststatus');
1.224 raeburn 10197: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
10198: #
10199: # Where usernames may created for institutional log-in and/or institutional single sign on:
10200: # (a) populate $cancreate{'statustocreate'} array reference with institutional status types who
10201: # may self-create accounts
10202: # (b) populate $save_usermodify{'selfcreate'} hash reference with status types, and information fields
10203: # which the user may supply, if institutional data is unavailable.
10204: #
10205: if (($env{'form.cancreate_login'}) || ($env{'form.cancreate_sso'})) {
10206: if (ref($types) eq 'ARRAY') {
1.228 raeburn 10207: if (@{$types} > 1) {
1.224 raeburn 10208: @{$cancreate{'statustocreate'}} = &Apache::loncommon::get_env_multiple('form.statustocreate');
10209: push(@contexts,'statustocreate');
10210: } else {
10211: undef($cancreate{'statustocreate'});
10212: }
10213: foreach my $type (@{$types}) {
10214: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$type);
10215: foreach my $field (@fields) {
10216: if (grep(/^\Q$field\E$/,@modifiable)) {
10217: $save_usermodify{'selfcreate'}{$type}{$field} = 1;
10218: } else {
10219: $save_usermodify{'selfcreate'}{$type}{$field} = 0;
10220: }
10221: }
10222: }
10223: if (ref($curr_usermodify{'selfcreate'}) eq 'HASH') {
10224: foreach my $type (@{$types}) {
10225: if (ref($curr_usermodify{'selfcreate'}{$type}) eq 'HASH') {
10226: foreach my $field (@fields) {
10227: if ($save_usermodify{'selfcreate'}{$type}{$field} ne
10228: $curr_usermodify{'selfcreate'}{$type}{$field}) {
10229: push(@{$changes{'selfcreate'}},$type);
10230: last;
10231: }
10232: }
10233: }
10234: }
10235: } else {
10236: foreach my $type (@{$types}) {
10237: push(@{$changes{'selfcreate'}},$type);
10238: }
10239: }
10240: }
1.240 raeburn 10241: foreach my $field (@shibfields) {
10242: if ($env{'form.shibenv_'.$field} ne '') {
10243: $cancreate{'shibenv'}{$field} = $env{'form.shibenv_'.$field};
10244: }
10245: }
10246: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
10247: if (ref($curr_usercreation{'cancreate'}{'shibenv'}) eq 'HASH') {
10248: foreach my $field (@shibfields) {
10249: if ($env{'form.shibenv_'.$field} ne $curr_usercreation{'cancreate'}{'shibenv'}{$field}) {
10250: push(@{$changes{'cancreate'}},'shibenv');
10251: }
10252: }
10253: } else {
10254: foreach my $field (@shibfields) {
10255: if ($env{'form.shibenv_'.$field}) {
10256: push(@{$changes{'cancreate'}},'shibenv');
10257: last;
10258: }
10259: }
10260: }
10261: }
1.224 raeburn 10262: }
10263: foreach my $item (@contexts) {
10264: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
10265: foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
10266: if (ref($cancreate{$item}) eq 'ARRAY') {
10267: if (!grep(/^$curr$/,@{$cancreate{$item}})) {
10268: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
10269: push(@{$changes{'cancreate'}},$item);
10270: }
10271: }
10272: }
10273: }
10274: if (ref($cancreate{$item}) eq 'ARRAY') {
10275: foreach my $type (@{$cancreate{$item}}) {
10276: if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
10277: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
10278: push(@{$changes{'cancreate'}},$item);
10279: }
10280: }
10281: }
10282: }
10283: } elsif (ref($curr_usercreation{'cancreate'}{$item}) eq 'HASH') {
10284: if (ref($cancreate{$item}) eq 'HASH') {
10285: foreach my $curr (keys(%{$curr_usercreation{'cancreate'}{$item}})) {
1.228 raeburn 10286: if (ref($curr_usercreation{'cancreate'}{$item}{$curr}) eq 'HASH') {
10287: foreach my $field (keys(%{$curr_usercreation{'cancreate'}{$item}{$curr}})) {
10288: unless ($curr_usercreation{'cancreate'}{$item}{$curr}{$field} eq $cancreate{$item}{$curr}{$field}) {
10289: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
10290: push(@{$changes{'cancreate'}},$item);
10291: }
10292: }
10293: }
1.236 raeburn 10294: } elsif ($item eq 'selfcreateprocessing') {
10295: if ($cancreate{$item}{$curr} ne $curr_usercreation{'cancreate'}{$item}{$curr}) {
10296: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
10297: push(@{$changes{'cancreate'}},$item);
10298: }
10299: }
1.228 raeburn 10300: } else {
10301: if (!$cancreate{$item}{$curr}) {
10302: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
10303: push(@{$changes{'cancreate'}},$item);
10304: }
1.224 raeburn 10305: }
10306: }
10307: }
10308: foreach my $field (keys(%{$cancreate{$item}})) {
1.228 raeburn 10309: if (ref($cancreate{$item}{$field}) eq 'HASH') {
10310: foreach my $inner (keys(%{$cancreate{$item}{$field}})) {
10311: if (ref($curr_usercreation{'cancreate'}{$item}{$field}) eq 'HASH') {
10312: unless ($curr_usercreation{'cancreate'}{$item}{$field}{$inner} eq $cancreate{$item}{$field}{$inner}) {
10313: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
10314: push(@{$changes{'cancreate'}},$item);
10315: }
10316: }
10317: } else {
10318: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
10319: push(@{$changes{'cancreate'}},$item);
10320: }
10321: }
10322: }
1.236 raeburn 10323: } elsif ($item eq 'selfcreateprocessing') {
10324: if ($cancreate{$item}{$field} ne $curr_usercreation{'cancreate'}{$item}{$field}) {
10325: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
10326: push(@{$changes{'cancreate'}},$item);
10327: }
10328: }
1.228 raeburn 10329: } else {
10330: if (!$curr_usercreation{'cancreate'}{$item}{$field}) {
10331: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
10332: push(@{$changes{'cancreate'}},$item);
10333: }
1.224 raeburn 10334: }
10335: }
10336: }
10337: }
10338: } elsif ($curr_usercreation{'cancreate'}{$item}) {
10339: if (ref($cancreate{$item}) eq 'ARRAY') {
10340: if (!grep(/^\Q$curr_usercreation{'cancreate'}{$item}\E$/,@{$cancreate{$item}})) {
10341: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
10342: push(@{$changes{'cancreate'}},$item);
10343: }
10344: }
10345: } elsif (ref($cancreate{$item}) eq 'HASH') {
10346: if (!$cancreate{$item}{$curr_usercreation{'cancreate'}{$item}}) {
10347: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
10348: push(@{$changes{'cancreate'}},$item);
10349: }
10350: }
10351: }
10352: } elsif ($item eq 'emailusername') {
1.228 raeburn 10353: if (ref($cancreate{$item}) eq 'HASH') {
10354: foreach my $type (keys(%{$cancreate{$item}})) {
10355: if (ref($cancreate{$item}{$type}) eq 'HASH') {
10356: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
10357: if ($cancreate{$item}{$type}{$field}) {
10358: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
10359: push(@{$changes{'cancreate'}},$item);
10360: }
10361: last;
10362: }
10363: }
10364: }
10365: }
1.224 raeburn 10366: }
10367: }
10368: }
10369: #
10370: # Populate %save_usercreate hash with updates to self-creation configuration.
10371: #
10372: $save_usercreate{'cancreate'}{'captcha'} = $savecaptcha{'captcha'};
10373: $save_usercreate{'cancreate'}{'recaptchakeys'} = $savecaptcha{'recaptchakeys'};
1.269 raeburn 10374: $save_usercreate{'cancreate'}{'recaptchaversion'} = $savecaptcha{'recaptchaversion'};
1.224 raeburn 10375: $save_usercreate{'cancreate'}{'selfcreate'} = $cancreate{'selfcreate'};
10376: if (ref($cancreate{'notify'}) eq 'HASH') {
10377: $save_usercreate{'cancreate'}{'notify'} = $cancreate{'notify'};
10378: }
1.236 raeburn 10379: if (ref($cancreate{'selfcreateprocessing'}) eq 'HASH') {
10380: $save_usercreate{'cancreate'}{'selfcreateprocessing'} = $cancreate{'selfcreateprocessing'};
10381: }
1.224 raeburn 10382: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
10383: $save_usercreate{'cancreate'}{'statustocreate'} = $cancreate{'statustocreate'};
10384: }
1.240 raeburn 10385: if (ref($cancreate{'shibenv'}) eq 'HASH') {
10386: $save_usercreate{'cancreate'}{'shibenv'} = $cancreate{'shibenv'};
10387: }
1.224 raeburn 10388: $save_usercreate{'cancreate'}{'emailusername'} = $cancreate{'emailusername'};
10389: $save_usercreate{'emailrule'} = \@email_rule;
10390:
10391: my %userconfig_hash = (
10392: usercreation => \%save_usercreate,
10393: usermodification => \%save_usermodify,
10394: );
10395: my $putresult = &Apache::lonnet::put_dom('configuration',\%userconfig_hash,
10396: $dom);
10397: #
10398: # Accumulate details of changes to domain cofiguration for self-creation of usernames in $resulttext
10399: #
1.27 raeburn 10400: if ($putresult eq 'ok') {
10401: if (keys(%changes) > 0) {
10402: $resulttext = &mt('Changes made:').'<ul>';
10403: if (ref($changes{'cancreate'}) eq 'ARRAY') {
1.224 raeburn 10404: my %lt = &selfcreation_types();
1.34 raeburn 10405: foreach my $type (@{$changes{'cancreate'}}) {
1.100 raeburn 10406: my $chgtext;
1.45 raeburn 10407: if ($type eq 'selfcreate') {
1.50 raeburn 10408: if (@{$cancreate{$type}} == 0) {
1.224 raeburn 10409: $chgtext .= &mt('Self creation of a new user account is not permitted.');
1.50 raeburn 10410: } else {
1.224 raeburn 10411: $chgtext .= &mt('Self-creation of a new account is permitted for:').
10412: '<ul>';
1.50 raeburn 10413: foreach my $case (@{$cancreate{$type}}) {
10414: $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
10415: }
10416: $chgtext .= '</ul>';
1.100 raeburn 10417: if (ref($cancreate{$type}) eq 'ARRAY') {
10418: if (grep(/^(login|sso)$/,@{$cancreate{$type}})) {
10419: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
10420: if (@{$cancreate{'statustocreate'}} == 0) {
1.224 raeburn 10421: $chgtext .= '<br />'.
10422: '<span class="LC_warning">'.
10423: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
10424: '</span>';
1.100 raeburn 10425: }
10426: }
10427: }
10428: }
1.43 raeburn 10429: }
1.240 raeburn 10430: } elsif ($type eq 'shibenv') {
10431: if (keys(%{$cancreate{$type}}) == 0) {
10432: $chgtext .= &mt('Shibboleth-autheticated user does not use environment variables to set user information');
10433: } else {
10434: $chgtext .= &mt('Shibboleth-autheticated user information set from environment variables, as follows:').
10435: '<ul>';
10436: foreach my $field (@shibfields) {
10437: next if ($cancreate{$type}{$field} eq '');
10438: if ($field eq 'inststatus') {
10439: $chgtext .= '<li>'.&mt('Institutional status').' -- '.$cancreate{$type}{$field}.'</li>';
10440: } else {
10441: $chgtext .= '<li>'.$fieldtitles{$field}.' -- '.$cancreate{$type}{$field}.'</li>';
10442: }
10443: }
10444: $chgtext .= '</ul>';
10445: }
1.93 raeburn 10446: } elsif ($type eq 'statustocreate') {
1.96 raeburn 10447: if ((ref($cancreate{'selfcreate'}) eq 'ARRAY') &&
10448: (ref($cancreate{'statustocreate'}) eq 'ARRAY')) {
10449: if (@{$cancreate{'selfcreate'}} > 0) {
10450: if (@{$cancreate{'statustocreate'}} == 0) {
1.100 raeburn 10451: $chgtext .= &mt("Institutional affiliations permitted to create accounts set to 'None'.");
1.96 raeburn 10452: if (!grep(/^email$/,@{$cancreate{'selfcreate'}})) {
1.224 raeburn 10453: $chgtext .= '<br />'.
10454: '<span class="LC_warning">'.
10455: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
10456: '</span>';
10457: }
1.96 raeburn 10458: } elsif (ref($usertypes) eq 'HASH') {
10459: if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.100 raeburn 10460: $chgtext .= &mt('Creation of a new account for an institutional user is restricted to the following institutional affiliation(s):');
10461: } else {
10462: $chgtext .= &mt('Institutional affiliations permitted to create accounts with institutional authentication were set as follows:');
10463: }
10464: $chgtext .= '<ul>';
10465: foreach my $case (@{$cancreate{$type}}) {
10466: if ($case eq 'default') {
10467: $chgtext .= '<li>'.$othertitle.'</li>';
10468: } else {
10469: $chgtext .= '<li>'.$usertypes->{$case}.'</li>';
1.93 raeburn 10470: }
10471: }
1.100 raeburn 10472: $chgtext .= '</ul>';
10473: if (!grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.224 raeburn 10474: $chgtext .= '<br /><span class="LC_warning">'.
10475: &mt('However, users authenticated by institutional login/single sign on are not currently permitted to create accounts.').
10476: '</span>';
1.100 raeburn 10477: }
10478: }
10479: } else {
10480: if (@{$cancreate{$type}} == 0) {
10481: $chgtext .= &mt("Institutional affiliations permitted to create accounts were set to 'none'.");
10482: } else {
10483: $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 10484: }
10485: }
10486: }
1.236 raeburn 10487: } elsif ($type eq 'selfcreateprocessing') {
10488: my %choices = &Apache::lonlocal::texthash (
10489: automatic => 'Automatic approval',
10490: approval => 'Queued for approval',
10491: );
10492: if (@statuses > 1) {
10493: $chgtext .= &mt('Processing of requests to create account with e-mail address as username set as follows:').
10494: '<ul>';
10495: foreach my $type (@statuses) {
10496: if ($type eq 'default') {
10497: $chgtext .= '<li>'.$othertitle.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$type}}.'</li>';
10498: } else {
10499: $chgtext .= '<li>'.$usertypes->{$type}.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$type}}.'</li>';
10500: }
10501: }
10502: $chgtext .= '</ul>';
10503: } else {
10504: $chgtext .= &mt('Processing of requests to create account with e-mail address as username set to: "[_1]"',
10505: $choices{$cancreate{'selfcreateprocessing'}{'default'}});
10506: }
1.165 raeburn 10507: } elsif ($type eq 'captcha') {
1.224 raeburn 10508: if ($savecaptcha{$type} eq 'notused') {
1.165 raeburn 10509: $chgtext .= &mt('No CAPTCHA validation in use for self-creation screen.');
10510: } else {
10511: my %captchas = &captcha_phrases();
1.224 raeburn 10512: if ($captchas{$savecaptcha{$type}}) {
10513: $chgtext .= &mt("Validation for self-creation screen set to $captchas{$savecaptcha{$type}}.");
1.165 raeburn 10514: } else {
1.210 raeburn 10515: $chgtext .= &mt('Validation for self-creation screen set to unknown type.');
1.165 raeburn 10516: }
10517: }
10518: } elsif ($type eq 'recaptchakeys') {
10519: my ($privkey,$pubkey);
1.224 raeburn 10520: if (ref($savecaptcha{$type}) eq 'HASH') {
10521: $pubkey = $savecaptcha{$type}{'public'};
10522: $privkey = $savecaptcha{$type}{'private'};
1.165 raeburn 10523: }
10524: $chgtext .= &mt('ReCAPTCHA keys changes').'<ul>';
10525: if (!$pubkey) {
10526: $chgtext .= '<li>'.&mt('Public key deleted').'</li>';
10527: } else {
10528: $chgtext .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
10529: }
10530: if (!$privkey) {
10531: $chgtext .= '<li>'.&mt('Private key deleted').'</li>';
10532: } else {
10533: $chgtext .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
10534: }
10535: $chgtext .= '</ul>';
1.269 raeburn 10536: } elsif ($type eq 'recaptchaversion') {
10537: if ($savecaptcha{'captcha'} eq 'recaptcha') {
1.270 raeburn 10538: $chgtext .= &mt('ReCAPTCHA set to version [_1]',$savecaptcha{$type});
1.269 raeburn 10539: }
1.224 raeburn 10540: } elsif ($type eq 'emailusername') {
10541: if (ref($cancreate{'emailusername'}) eq 'HASH') {
1.228 raeburn 10542: if (ref($types) eq 'ARRAY') {
10543: foreach my $type (@{$types}) {
10544: if (ref($cancreate{'emailusername'}{$type}) eq 'HASH') {
10545: if (keys(%{$cancreate{'emailusername'}{$type}}) > 0) {
1.245 raeburn 10546: $chgtext .= &mt('When self-creating account with e-mail as username, the following information will be provided by [_1]:',"'$usertypes->{$type}'").
1.228 raeburn 10547: '<ul>';
10548: foreach my $field (@{$infofields}) {
10549: if ($cancreate{'emailusername'}{$type}{$field}) {
10550: $chgtext .= '<li>'.$infotitles->{$field}.'</li>';
10551: }
10552: }
1.245 raeburn 10553: $chgtext .= '</ul>';
10554: } else {
10555: $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 10556: }
10557: } else {
1.245 raeburn 10558: $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 10559: }
10560: }
10561: }
10562: }
10563: } elsif ($type eq 'notify') {
10564: $chgtext = &mt('No Domain Coordinators will receive notification of username requests requiring approval.');
10565: if (ref($changes{'cancreate'}) eq 'ARRAY') {
10566: if ((grep(/^notify$/,@{$changes{'cancreate'}})) && (ref($cancreate{'notify'}) eq 'HASH')) {
10567: if ($cancreate{'notify'}{'approval'}) {
10568: $chgtext = &mt('Notification of username requests requiring approval will be sent to: ').$cancreate{'notify'}{'approval'};
10569: }
10570: }
1.43 raeburn 10571: }
1.34 raeburn 10572: }
1.224 raeburn 10573: if ($chgtext) {
10574: $resulttext .= '<li>'.$chgtext.'</li>';
1.32 raeburn 10575: }
10576: }
10577: }
1.43 raeburn 10578: if (ref($changes{'email_rule'}) eq 'ARRAY') {
10579: my ($emailrules,$emailruleorder) =
10580: &Apache::lonnet::inst_userrules($dom,'email');
10581: my $chgtext = '<ul>';
10582: foreach my $type (@email_rule) {
10583: if (ref($emailrules->{$type}) eq 'HASH') {
10584: $chgtext .= '<li>'.$emailrules->{$type}{'name'}.'</li>';
10585: }
10586: }
10587: $chgtext .= '</ul>';
10588: if (@email_rule > 0) {
1.224 raeburn 10589: $resulttext .= '<li>'.
10590: &mt('Accounts may not be created by users self-enrolling with e-mail addresses of the following types: ').
10591: $chgtext.
10592: '</li>';
1.43 raeburn 10593: } else {
1.224 raeburn 10594: $resulttext .= '<li>'.
10595: &mt('There are now no restrictions on e-mail addresses which may be used as a username when self-enrolling.').
10596: '</li>';
1.43 raeburn 10597: }
10598: }
1.224 raeburn 10599: if (ref($changes{'selfcreate'}) eq 'ARRAY') {
10600: $resulttext .= '<li>'.&mt('When self-creating institutional account:').'<ul>';
10601: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
10602: foreach my $type (@{$changes{'selfcreate'}}) {
10603: my $typename = $type;
10604: if (ref($usertypes) eq 'HASH') {
10605: if ($usertypes->{$type} ne '') {
10606: $typename = $usertypes->{$type};
10607: }
10608: }
10609: my @modifiable;
10610: $resulttext .= '<li>'.
10611: &mt('Self-creation of account by users with status: [_1]',
10612: '<span class="LC_cusr_emph">'.$typename.'</span>').
10613: ' - '.&mt('modifiable fields (if institutional data blank): ');
10614: foreach my $field (@fields) {
10615: if ($save_usermodify{'selfcreate'}{$type}{$field}) {
10616: push(@modifiable,'<b>'.$fieldtitles{$field}.'</b>');
1.28 raeburn 10617: }
10618: }
1.224 raeburn 10619: if (@modifiable > 0) {
10620: $resulttext .= join(', ',@modifiable);
1.43 raeburn 10621: } else {
1.224 raeburn 10622: $resulttext .= &mt('none');
1.43 raeburn 10623: }
1.224 raeburn 10624: $resulttext .= '</li>';
1.28 raeburn 10625: }
1.224 raeburn 10626: $resulttext .= '</ul></li>';
1.28 raeburn 10627: }
1.27 raeburn 10628: $resulttext .= '</ul>';
10629: } else {
1.224 raeburn 10630: $resulttext = &mt('No changes made to self-creation settings');
1.27 raeburn 10631: }
10632: } else {
10633: $resulttext = '<span class="LC_error">'.
1.23 raeburn 10634: &mt('An error occurred: [_1]',$putresult).'</span>';
10635: }
1.43 raeburn 10636: if ($warningmsg ne '') {
10637: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
10638: }
1.23 raeburn 10639: return $resulttext;
10640: }
10641:
1.165 raeburn 10642: sub process_captcha {
10643: my ($container,$changes,$newsettings,$current) = @_;
10644: return unless ((ref($changes) eq 'HASH') && (ref($newsettings) eq 'HASH') || (ref($current) eq 'HASH'));
10645: $newsettings->{'captcha'} = $env{'form.'.$container.'_captcha'};
10646: unless ($newsettings->{'captcha'} eq 'recaptcha' || $newsettings->{'captcha'} eq 'notused') {
10647: $newsettings->{'captcha'} = 'original';
10648: }
10649: if ($current->{'captcha'} ne $newsettings->{'captcha'}) {
1.210 raeburn 10650: if ($container eq 'cancreate') {
1.169 raeburn 10651: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
10652: push(@{$changes->{'cancreate'}},'captcha');
10653: } elsif (!defined($changes->{'cancreate'})) {
10654: $changes->{'cancreate'} = ['captcha'];
10655: }
10656: } else {
10657: $changes->{'captcha'} = 1;
1.165 raeburn 10658: }
10659: }
1.269 raeburn 10660: my ($newpub,$newpriv,$currpub,$currpriv,$newversion,$currversion);
1.165 raeburn 10661: if ($newsettings->{'captcha'} eq 'recaptcha') {
10662: $newpub = $env{'form.'.$container.'_recaptchapub'};
10663: $newpriv = $env{'form.'.$container.'_recaptchapriv'};
1.250 raeburn 10664: $newpub =~ s/[^\w\-]//g;
10665: $newpriv =~ s/[^\w\-]//g;
1.169 raeburn 10666: $newsettings->{'recaptchakeys'} = {
10667: public => $newpub,
10668: private => $newpriv,
10669: };
1.269 raeburn 10670: $newversion = $env{'form.'.$container.'_recaptchaversion'};
10671: $newversion =~ s/\D//g;
10672: if ($newversion ne '2') {
10673: $newversion = 1;
10674: }
10675: $newsettings->{'recaptchaversion'} = $newversion;
1.165 raeburn 10676: }
10677: if (ref($current->{'recaptchakeys'}) eq 'HASH') {
10678: $currpub = $current->{'recaptchakeys'}{'public'};
10679: $currpriv = $current->{'recaptchakeys'}{'private'};
1.179 raeburn 10680: unless ($newsettings->{'captcha'} eq 'recaptcha') {
10681: $newsettings->{'recaptchakeys'} = {
10682: public => '',
10683: private => '',
10684: }
10685: }
1.165 raeburn 10686: }
1.269 raeburn 10687: if ($current->{'captcha'} eq 'recaptcha') {
10688: $currversion = $current->{'recaptchaversion'};
10689: if ($currversion ne '2') {
10690: $currversion = 1;
10691: }
10692: }
10693: if ($currversion ne $newversion) {
10694: if ($container eq 'cancreate') {
10695: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
10696: push(@{$changes->{'cancreate'}},'recaptchaversion');
10697: } elsif (!defined($changes->{'cancreate'})) {
10698: $changes->{'cancreate'} = ['recaptchaversion'];
10699: }
10700: } else {
10701: $changes->{'recaptchaversion'} = 1;
10702: }
10703: }
1.165 raeburn 10704: if (($newpub ne $currpub) || ($newpriv ne $currpriv)) {
1.169 raeburn 10705: if ($container eq 'cancreate') {
10706: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
10707: push(@{$changes->{'cancreate'}},'recaptchakeys');
10708: } elsif (!defined($changes->{'cancreate'})) {
10709: $changes->{'cancreate'} = ['recaptchakeys'];
10710: }
10711: } else {
1.210 raeburn 10712: $changes->{'recaptchakeys'} = 1;
1.165 raeburn 10713: }
10714: }
10715: return;
10716: }
10717:
1.33 raeburn 10718: sub modify_usermodification {
10719: my ($dom,%domconfig) = @_;
1.224 raeburn 10720: my ($resulttext,%curr_usermodification,%changes,%modifyhash);
1.33 raeburn 10721: if (ref($domconfig{'usermodification'}) eq 'HASH') {
10722: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
1.224 raeburn 10723: if ($key eq 'selfcreate') {
10724: $modifyhash{$key} = $domconfig{'usermodification'}{$key};
10725: } else {
10726: $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
10727: }
1.33 raeburn 10728: }
10729: }
1.224 raeburn 10730: my @contexts = ('author','course');
1.33 raeburn 10731: my %context_title = (
10732: author => 'In author context',
10733: course => 'In course context',
10734: );
10735: my @fields = ('lastname','firstname','middlename','generation',
10736: 'permanentemail','id');
10737: my %roles = (
10738: author => ['ca','aa'],
10739: course => ['st','ep','ta','in','cr'],
10740: );
10741: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
10742: foreach my $context (@contexts) {
10743: foreach my $role (@{$roles{$context}}) {
10744: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$role);
10745: foreach my $item (@fields) {
10746: if (grep(/^\Q$item\E$/,@modifiable)) {
10747: $modifyhash{$context}{$role}{$item} = 1;
10748: } else {
10749: $modifyhash{$context}{$role}{$item} = 0;
10750: }
10751: }
10752: }
10753: if (ref($curr_usermodification{$context}) eq 'HASH') {
10754: foreach my $role (@{$roles{$context}}) {
10755: if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
10756: foreach my $field (@fields) {
10757: if ($modifyhash{$context}{$role}{$field} ne
10758: $curr_usermodification{$context}{$role}{$field}) {
10759: push(@{$changes{$context}},$role);
10760: last;
10761: }
10762: }
10763: }
10764: }
10765: } else {
10766: foreach my $context (@contexts) {
10767: foreach my $role (@{$roles{$context}}) {
10768: push(@{$changes{$context}},$role);
10769: }
10770: }
10771: }
10772: }
10773: my %usermodification_hash = (
10774: usermodification => \%modifyhash,
10775: );
10776: my $putresult = &Apache::lonnet::put_dom('configuration',
10777: \%usermodification_hash,$dom);
10778: if ($putresult eq 'ok') {
10779: if (keys(%changes) > 0) {
10780: $resulttext = &mt('Changes made: ').'<ul>';
10781: foreach my $context (@contexts) {
10782: if (ref($changes{$context}) eq 'ARRAY') {
10783: $resulttext .= '<li>'.$context_title{$context}.':<ul>';
10784: if (ref($changes{$context}) eq 'ARRAY') {
10785: foreach my $role (@{$changes{$context}}) {
10786: my $rolename;
1.224 raeburn 10787: if ($role eq 'cr') {
10788: $rolename = &mt('Custom');
1.33 raeburn 10789: } else {
1.224 raeburn 10790: $rolename = &Apache::lonnet::plaintext($role);
1.33 raeburn 10791: }
10792: my @modifiable;
1.224 raeburn 10793: $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
1.33 raeburn 10794: foreach my $field (@fields) {
10795: if ($modifyhash{$context}{$role}{$field}) {
10796: push(@modifiable,$fieldtitles{$field});
10797: }
10798: }
10799: if (@modifiable > 0) {
10800: $resulttext .= join(', ',@modifiable);
10801: } else {
10802: $resulttext .= &mt('none');
10803: }
10804: $resulttext .= '</li>';
10805: }
10806: $resulttext .= '</ul></li>';
10807: }
10808: }
10809: }
10810: $resulttext .= '</ul>';
10811: } else {
10812: $resulttext = &mt('No changes made to user modification settings');
10813: }
10814: } else {
10815: $resulttext = '<span class="LC_error">'.
10816: &mt('An error occurred: [_1]',$putresult).'</span>';
10817: }
10818: return $resulttext;
10819: }
10820:
1.43 raeburn 10821: sub modify_defaults {
1.212 raeburn 10822: my ($dom,$lastactref,%domconfig) = @_;
1.43 raeburn 10823: my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
1.212 raeburn 10824: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.141 raeburn 10825: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def','portal_def');
1.43 raeburn 10826: my @authtypes = ('internal','krb4','krb5','localauth');
10827: foreach my $item (@items) {
10828: $newvalues{$item} = $env{'form.'.$item};
10829: if ($item eq 'auth_def') {
10830: if ($newvalues{$item} ne '') {
10831: if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
10832: push(@errors,$item);
10833: }
10834: }
10835: } elsif ($item eq 'lang_def') {
10836: if ($newvalues{$item} ne '') {
10837: if ($newvalues{$item} =~ /^(\w+)/) {
10838: my $langcode = $1;
1.103 raeburn 10839: if ($langcode ne 'x_chef') {
10840: if (code2language($langcode) eq '') {
10841: push(@errors,$item);
10842: }
1.43 raeburn 10843: }
10844: } else {
10845: push(@errors,$item);
10846: }
10847: }
1.54 raeburn 10848: } elsif ($item eq 'timezone_def') {
10849: if ($newvalues{$item} ne '') {
1.62 raeburn 10850: if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
1.54 raeburn 10851: push(@errors,$item);
10852: }
10853: }
1.68 raeburn 10854: } elsif ($item eq 'datelocale_def') {
10855: if ($newvalues{$item} ne '') {
10856: my @datelocale_ids = DateTime::Locale->ids();
10857: if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
10858: push(@errors,$item);
10859: }
10860: }
1.141 raeburn 10861: } elsif ($item eq 'portal_def') {
10862: if ($newvalues{$item} ne '') {
10863: 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])\/?$/) {
10864: push(@errors,$item);
10865: }
10866: }
1.43 raeburn 10867: }
10868: if (grep(/^\Q$item\E$/,@errors)) {
10869: $newvalues{$item} = $domdefaults{$item};
10870: } elsif ($domdefaults{$item} ne $newvalues{$item}) {
10871: $changes{$item} = 1;
10872: }
1.72 raeburn 10873: $domdefaults{$item} = $newvalues{$item};
1.43 raeburn 10874: }
10875: my %defaults_hash = (
1.72 raeburn 10876: defaults => \%newvalues,
10877: );
1.43 raeburn 10878: my $title = &defaults_titles();
1.236 raeburn 10879:
10880: my $currinststatus;
10881: if (ref($domconfig{'inststatus'}) eq 'HASH') {
10882: $currinststatus = $domconfig{'inststatus'};
10883: } else {
10884: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
10885: $currinststatus = {
10886: inststatustypes => $usertypes,
10887: inststatusorder => $types,
10888: inststatusguest => [],
10889: };
10890: }
10891: my @todelete = &Apache::loncommon::get_env_multiple('form.inststatus_delete');
10892: my @allpos;
10893: my %guests;
10894: my %alltypes;
10895: my ($currtitles,$currguests,$currorder);
10896: if (ref($currinststatus) eq 'HASH') {
10897: if (ref($currinststatus->{'inststatusorder'}) eq 'ARRAY') {
10898: foreach my $type (@{$currinststatus->{'inststatusorder'}}) {
10899: if (ref($currinststatus->{inststatustypes}) eq 'HASH') {
10900: if ($currinststatus->{inststatustypes}->{$type} ne '') {
10901: $currtitles .= $currinststatus->{inststatustypes}->{$type}.',';
10902: }
10903: }
10904: unless (grep(/^\Q$type\E$/,@todelete)) {
10905: my $position = $env{'form.inststatus_pos_'.$type};
10906: $position =~ s/\D+//g;
10907: $allpos[$position] = $type;
10908: $alltypes{$type} = $env{'form.inststatus_title_'.$type};
10909: $alltypes{$type} =~ s/`//g;
10910: if ($env{'form.inststatus_guest_'.$type}) {
10911: $guests{$type} = 1;
10912: }
10913: }
10914: }
10915: if (ref($currinststatus->{'inststatusguest'}) eq 'ARRAY') {
10916: $currguests = join(',',@{$currinststatus->{'inststatusguest'}});
10917: }
10918: $currorder = join(',',@{$currinststatus->{'inststatusorder'}});
10919: $currtitles =~ s/,$//;
10920: }
10921: }
10922: if ($env{'form.addinststatus'}) {
10923: my $newtype = $env{'form.addinststatus'};
10924: $newtype =~ s/\W//g;
10925: unless (exists($alltypes{$newtype})) {
10926: if ($env{'form.addinststatus_guest'}) {
10927: $guests{$newtype} = 1;
10928: }
10929: $alltypes{$newtype} = $env{'form.addinststatus_title'};
10930: $alltypes{$newtype} =~ s/`//g;
10931: my $position = $env{'form.addinststatus_pos'};
10932: $position =~ s/\D+//g;
10933: if ($position ne '') {
10934: $allpos[$position] = $newtype;
10935: }
10936: }
10937: }
10938: my (@orderedstatus,@orderedguests);
10939: foreach my $type (@allpos) {
10940: unless (($type eq '') || (grep(/^\Q$type\E$/,@orderedstatus))) {
10941: push(@orderedstatus,$type);
10942: if ($guests{$type}) {
10943: push(@orderedguests,$type);
10944: }
10945: }
10946: }
10947: foreach my $type (keys(%alltypes)) {
10948: unless (grep(/^\Q$type\E$/,@orderedstatus)) {
10949: delete($alltypes{$type});
10950: }
10951: }
10952: $defaults_hash{'inststatus'} = {
10953: inststatustypes => \%alltypes,
10954: inststatusorder => \@orderedstatus,
10955: inststatusguest => \@orderedguests,
10956: };
10957: if (ref($defaults_hash{'inststatus'}) eq 'HASH') {
10958: foreach my $item ('inststatustypes','inststatusorder','inststatusguest') {
10959: $domdefaults{$item} = $defaults_hash{'inststatus'}{$item};
10960: }
10961: }
10962: if ($currorder ne join(',',@orderedstatus)) {
10963: $changes{'inststatus'}{'inststatusorder'} = 1;
10964: }
10965: if ($currguests ne join(',',@orderedguests)) {
10966: $changes{'inststatus'}{'inststatusguest'} = 1;
10967: }
10968: my $newtitles;
10969: foreach my $item (@orderedstatus) {
10970: $newtitles .= $alltypes{$item}.',';
10971: }
10972: $newtitles =~ s/,$//;
10973: if ($currtitles ne $newtitles) {
10974: $changes{'inststatus'}{'inststatustypes'} = 1;
10975: }
1.43 raeburn 10976: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
10977: $dom);
10978: if ($putresult eq 'ok') {
10979: if (keys(%changes) > 0) {
10980: $resulttext = &mt('Changes made:').'<ul>';
1.212 raeburn 10981: my $version = &Apache::lonnet::get_server_loncaparev($dom);
1.43 raeburn 10982: 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";
10983: foreach my $item (sort(keys(%changes))) {
1.236 raeburn 10984: if ($item eq 'inststatus') {
10985: if (ref($changes{'inststatus'}) eq 'HASH') {
10986: if (($changes{'inststatus'}{'inststatustypes'}) || $changes{'inststatus'}{'inststatusorder'}) {
10987: $resulttext .= '<li>'.&mt('Institutional user status types set to:').' ';
10988: foreach my $type (@orderedstatus) {
10989: $resulttext .= $alltypes{$type}.', ';
10990: }
10991: $resulttext =~ s/, $//;
10992: $resulttext .= '</li>';
10993: }
10994: if ($changes{'inststatus'}{'inststatusguest'}) {
10995: $resulttext .= '<li>';
10996: if (@orderedguests) {
10997: $resulttext .= &mt('Types assignable to "non-institutional" usernames set to:').' ';
10998: foreach my $type (@orderedguests) {
10999: $resulttext .= $alltypes{$type}.', ';
11000: }
11001: $resulttext =~ s/, $//;
11002: } else {
11003: $resulttext .= &mt('Types assignable to "non-institutional" usernames set to none.');
11004: }
11005: $resulttext .= '</li>';
11006: }
11007: }
11008: } else {
11009: my $value = $env{'form.'.$item};
11010: if ($value eq '') {
11011: $value = &mt('none');
11012: } elsif ($item eq 'auth_def') {
11013: my %authnames = &authtype_names();
11014: my %shortauth = (
11015: internal => 'int',
11016: krb4 => 'krb4',
11017: krb5 => 'krb5',
11018: localauth => 'loc',
11019: );
11020: $value = $authnames{$shortauth{$value}};
11021: }
11022: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
11023: $mailmsgtext .= "$title->{$item} set to $value\n";
1.43 raeburn 11024: }
11025: }
11026: $resulttext .= '</ul>';
11027: $mailmsgtext .= "\n";
11028: my $cachetime = 24*60*60;
1.72 raeburn 11029: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 11030: if (ref($lastactref) eq 'HASH') {
11031: $lastactref->{'domdefaults'} = 1;
11032: }
1.68 raeburn 11033: if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
1.203 raeburn 11034: my $notify = 1;
11035: if (ref($domconfig{'contacts'}) eq 'HASH') {
11036: if ($domconfig{'contacts'}{'reportupdates'} == 0) {
11037: $notify = 0;
11038: }
11039: }
11040: if ($notify) {
11041: &Apache::lonmsg::sendemail('installrecord@loncapa.org',
11042: "LON-CAPA Domain Settings Change - $dom",
11043: $mailmsgtext);
11044: }
1.54 raeburn 11045: }
1.43 raeburn 11046: } else {
1.54 raeburn 11047: $resulttext = &mt('No changes made to default authentication/language/timezone settings');
1.43 raeburn 11048: }
11049: } else {
11050: $resulttext = '<span class="LC_error">'.
11051: &mt('An error occurred: [_1]',$putresult).'</span>';
11052: }
11053: if (@errors > 0) {
11054: $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
11055: foreach my $item (@errors) {
11056: $resulttext .= ' "'.$title->{$item}.'",';
11057: }
11058: $resulttext =~ s/,$//;
11059: }
11060: return $resulttext;
11061: }
11062:
1.46 raeburn 11063: sub modify_scantron {
1.205 raeburn 11064: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.46 raeburn 11065: my ($resulttext,%confhash,%changes,$errors);
11066: my $custom = 'custom.tab';
11067: my $default = 'default.tab';
11068: my $servadm = $r->dir_config('lonAdmEMail');
11069: my ($configuserok,$author_ok,$switchserver) =
11070: &config_check($dom,$confname,$servadm);
11071: if ($env{'form.scantronformat.filename'} ne '') {
11072: my $error;
11073: if ($configuserok eq 'ok') {
11074: if ($switchserver) {
1.130 raeburn 11075: $error = &mt("Upload of bubblesheet format file is not permitted to this server: [_1]",$switchserver);
1.46 raeburn 11076: } else {
11077: if ($author_ok eq 'ok') {
11078: my ($result,$scantronurl) =
11079: &publishlogo($r,'upload','scantronformat',$dom,
11080: $confname,'scantron','','',$custom);
11081: if ($result eq 'ok') {
11082: $confhash{'scantron'}{'scantronformat'} = $scantronurl;
1.48 raeburn 11083: $changes{'scantronformat'} = 1;
1.46 raeburn 11084: } else {
11085: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
11086: }
11087: } else {
11088: $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);
11089: }
11090: }
11091: } else {
11092: $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);
11093: }
11094: if ($error) {
11095: &Apache::lonnet::logthis($error);
11096: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
11097: }
11098: }
1.48 raeburn 11099: if (ref($domconfig{'scantron'}) eq 'HASH') {
11100: if ($domconfig{'scantron'}{'scantronformat'} ne '') {
11101: if ($env{'form.scantronformat_del'}) {
11102: $confhash{'scantron'}{'scantronformat'} = '';
11103: $changes{'scantronformat'} = 1;
1.46 raeburn 11104: }
11105: }
11106: }
11107: if (keys(%confhash) > 0) {
11108: my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
11109: $dom);
11110: if ($putresult eq 'ok') {
11111: if (keys(%changes) > 0) {
1.48 raeburn 11112: if (ref($confhash{'scantron'}) eq 'HASH') {
11113: $resulttext = &mt('Changes made:').'<ul>';
11114: if ($confhash{'scantron'}{'scantronformat'} eq '') {
1.130 raeburn 11115: $resulttext .= '<li>'.&mt('[_1] bubblesheet format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
1.48 raeburn 11116: } else {
1.130 raeburn 11117: $resulttext .= '<li>'.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
1.46 raeburn 11118: }
1.48 raeburn 11119: $resulttext .= '</ul>';
11120: } else {
1.130 raeburn 11121: $resulttext = &mt('Changes made to bubblesheet format file.');
1.46 raeburn 11122: }
11123: $resulttext .= '</ul>';
11124: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 11125: if (ref($lastactref) eq 'HASH') {
11126: $lastactref->{'domainconfig'} = 1;
11127: }
1.46 raeburn 11128: } else {
1.130 raeburn 11129: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 11130: }
11131: } else {
11132: $resulttext = '<span class="LC_error">'.
11133: &mt('An error occurred: [_1]',$putresult).'</span>';
11134: }
11135: } else {
1.130 raeburn 11136: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 11137: }
11138: if ($errors) {
11139: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
11140: $errors.'</ul>';
11141: }
11142: return $resulttext;
11143: }
11144:
1.48 raeburn 11145: sub modify_coursecategories {
1.239 raeburn 11146: my ($dom,$lastactref,%domconfig) = @_;
1.57 raeburn 11147: my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
11148: $cathash);
1.48 raeburn 11149: my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
1.238 raeburn 11150: my @catitems = ('unauth','auth');
11151: my @cattypes = ('std','domonly','codesrch','none');
1.55 raeburn 11152: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
1.57 raeburn 11153: $cathash = $domconfig{'coursecategories'}{'cats'};
11154: if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
11155: $changes{'togglecats'} = 1;
11156: $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
11157: }
11158: if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
11159: $changes{'categorize'} = 1;
11160: $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
11161: }
1.120 raeburn 11162: if ($domconfig{'coursecategories'}{'togglecatscomm'} ne $env{'form.togglecatscomm'}) {
11163: $changes{'togglecatscomm'} = 1;
11164: $domconfig{'coursecategories'}{'togglecatscomm'} = $env{'form.togglecatscomm'};
11165: }
11166: if ($domconfig{'coursecategories'}{'categorizecomm'} ne $env{'form.categorizecomm'}) {
11167: $changes{'categorizecomm'} = 1;
11168: $domconfig{'coursecategories'}{'categorizecomm'} = $env{'form.categorizecomm'};
1.272 raeburn 11169:
11170: }
11171: if ($domconfig{'coursecategories'}{'togglecatsplace'} ne $env{'form.togglecatsplace'}) {
11172: $changes{'togglecatsplace'} = 1;
11173: $domconfig{'coursecategories'}{'togglecatsplace'} = $env{'form.togglecatsplace'};
11174: }
11175: if ($domconfig{'coursecategories'}{'categorizeplace'} ne $env{'form.categorizeplace'}) {
11176: $changes{'categorizeplace'} = 1;
11177: $domconfig{'coursecategories'}{'categorizeplace'} = $env{'form.categorizeplace'};
1.120 raeburn 11178: }
1.238 raeburn 11179: foreach my $item (@catitems) {
11180: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
11181: if ($domconfig{'coursecategories'}{$item} ne $env{'form.coursecat_'.$item}) {
11182: $changes{$item} = 1;
11183: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
11184: }
11185: }
11186: }
1.57 raeburn 11187: } else {
11188: $changes{'togglecats'} = 1;
11189: $changes{'categorize'} = 1;
1.124 raeburn 11190: $changes{'togglecatscomm'} = 1;
11191: $changes{'categorizecomm'} = 1;
1.272 raeburn 11192: $changes{'togglecatsplace'} = 1;
11193: $changes{'categorizeplace'} = 1;
1.87 raeburn 11194: $domconfig{'coursecategories'} = {
11195: togglecats => $env{'form.togglecats'},
11196: categorize => $env{'form.categorize'},
1.124 raeburn 11197: togglecatscomm => $env{'form.togglecatscomm'},
11198: categorizecomm => $env{'form.categorizecomm'},
1.272 raeburn 11199: togglecatsplace => $env{'form.togglecatsplace'},
11200: categorizeplace => $env{'form.categorizeplace'},
1.120 raeburn 11201: };
1.238 raeburn 11202: foreach my $item (@catitems) {
11203: if ($env{'form.coursecat_'.$item} ne 'std') {
11204: $changes{$item} = 1;
11205: }
11206: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
11207: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
11208: }
11209: }
1.57 raeburn 11210: }
11211: if (ref($cathash) eq 'HASH') {
11212: if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '') && ($env{'form.instcode'} == 0)) {
1.55 raeburn 11213: push (@deletecategory,'instcode::0');
11214: }
1.120 raeburn 11215: if (($domconfig{'coursecategories'}{'cats'}{'communities::0'} ne '') && ($env{'form.communities'} == 0)) {
11216: push(@deletecategory,'communities::0');
11217: }
1.272 raeburn 11218: if (($domconfig{'coursecategories'}{'cats'}{'placement::0'} ne '') && ($env{'form.placement'} == 0)) {
11219: push(@deletecategory,'placement::0');
11220: }
1.48 raeburn 11221: }
1.57 raeburn 11222: my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
11223: if (ref($cathash) eq 'HASH') {
1.48 raeburn 11224: if (@deletecategory > 0) {
11225: #FIXME Need to remove category from all courses using a deleted category
1.57 raeburn 11226: &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
1.48 raeburn 11227: foreach my $item (@deletecategory) {
1.57 raeburn 11228: if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
11229: delete($domconfig{'coursecategories'}{'cats'}{$item});
1.48 raeburn 11230: $deletions{$item} = 1;
1.57 raeburn 11231: &recurse_cat_deletes($item,$cathash,\%deletions);
1.48 raeburn 11232: }
11233: }
11234: }
1.57 raeburn 11235: foreach my $item (keys(%{$cathash})) {
1.48 raeburn 11236: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
1.57 raeburn 11237: if ($cathash->{$item} ne $env{'form.'.$item}) {
1.48 raeburn 11238: $reorderings{$item} = 1;
1.57 raeburn 11239: $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
1.48 raeburn 11240: }
11241: if ($env{'form.addcategory_name_'.$item} ne '') {
11242: my $newcat = $env{'form.addcategory_name_'.$item};
11243: my $newdepth = $depth+1;
11244: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 11245: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
1.48 raeburn 11246: $adds{$newitem} = 1;
11247: }
11248: if ($env{'form.subcat_'.$item} ne '') {
11249: my $newcat = $env{'form.subcat_'.$item};
11250: my $newdepth = $depth+1;
11251: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 11252: $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
1.48 raeburn 11253: $adds{$newitem} = 1;
11254: }
11255: }
11256: }
11257: if ($env{'form.instcode'} eq '1') {
1.57 raeburn 11258: if (ref($cathash) eq 'HASH') {
1.48 raeburn 11259: my $newitem = 'instcode::0';
1.57 raeburn 11260: if ($cathash->{$newitem} eq '') {
11261: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 11262: $adds{$newitem} = 1;
11263: }
11264: } else {
11265: my $newitem = 'instcode::0';
1.57 raeburn 11266: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 11267: $adds{$newitem} = 1;
11268: }
11269: }
1.120 raeburn 11270: if ($env{'form.communities'} eq '1') {
11271: if (ref($cathash) eq 'HASH') {
11272: my $newitem = 'communities::0';
11273: if ($cathash->{$newitem} eq '') {
11274: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
11275: $adds{$newitem} = 1;
11276: }
11277: } else {
11278: my $newitem = 'communities::0';
11279: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
11280: $adds{$newitem} = 1;
11281: }
11282: }
1.272 raeburn 11283: if ($env{'form.placement'} eq '1') {
11284: if (ref($cathash) eq 'HASH') {
11285: my $newitem = 'placement::0';
11286: if ($cathash->{$newitem} eq '') {
11287: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.placement_pos'};
11288: $adds{$newitem} = 1;
11289: }
11290: } else {
11291: my $newitem = 'placement::0';
11292: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.placement_pos'};
11293: $adds{$newitem} = 1;
11294: }
11295: }
1.48 raeburn 11296: if ($env{'form.addcategory_name'} ne '') {
1.120 raeburn 11297: if (($env{'form.addcategory_name'} ne 'instcode') &&
1.272 raeburn 11298: ($env{'form.addcategory_name'} ne 'communities') &&
11299: ($env{'form.addcategory_name'} ne 'placement')) {
1.120 raeburn 11300: my $newitem = &escape($env{'form.addcategory_name'}).'::0';
11301: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
11302: $adds{$newitem} = 1;
11303: }
1.48 raeburn 11304: }
1.57 raeburn 11305: my $putresult;
1.48 raeburn 11306: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
11307: if (keys(%deletions) > 0) {
11308: foreach my $key (keys(%deletions)) {
11309: if ($predelallitems{$key} ne '') {
11310: $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
11311: }
11312: }
11313: }
11314: my (@chkcats,@chktrails,%chkallitems);
1.57 raeburn 11315: &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
1.48 raeburn 11316: if (ref($chkcats[0]) eq 'ARRAY') {
11317: my $depth = 0;
11318: my $chg = 0;
11319: for (my $i=0; $i<@{$chkcats[0]}; $i++) {
11320: my $name = $chkcats[0][$i];
11321: my $item;
11322: if ($name eq '') {
11323: $chg ++;
11324: } else {
11325: $item = &escape($name).'::0';
11326: if ($chg) {
1.57 raeburn 11327: $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
1.48 raeburn 11328: }
11329: $depth ++;
1.57 raeburn 11330: &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
1.48 raeburn 11331: $depth --;
11332: }
11333: }
11334: }
1.57 raeburn 11335: }
11336: if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
11337: $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
1.48 raeburn 11338: if ($putresult eq 'ok') {
1.57 raeburn 11339: my %title = (
1.120 raeburn 11340: togglecats => 'Show/Hide a course in catalog',
11341: categorize => 'Assign a category to a course',
11342: togglecatscomm => 'Show/Hide a community in catalog',
11343: categorizecomm => 'Assign a category to a community',
1.57 raeburn 11344: );
11345: my %level = (
1.120 raeburn 11346: dom => 'set in Domain ("Modify Course/Community")',
11347: crs => 'set in Course ("Course Configuration")',
11348: comm => 'set in Community ("Community Configuration")',
1.238 raeburn 11349: none => 'No catalog',
11350: std => 'Standard catalog',
11351: domonly => 'Domain-only catalog',
11352: codesrch => 'Code search form',
1.57 raeburn 11353: );
1.48 raeburn 11354: $resulttext = &mt('Changes made:').'<ul>';
1.57 raeburn 11355: if ($changes{'togglecats'}) {
11356: $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>';
11357: }
11358: if ($changes{'categorize'}) {
11359: $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
1.48 raeburn 11360: }
1.120 raeburn 11361: if ($changes{'togglecatscomm'}) {
11362: $resulttext .= '<li>'.&mt("$title{'togglecatscomm'} $level{$env{'form.togglecatscomm'}}").'</li>';
11363: }
11364: if ($changes{'categorizecomm'}) {
11365: $resulttext .= '<li>'.&mt("$title{'categorizecomm'} $level{$env{'form.categorizecomm'}}").'</li>';
11366: }
1.238 raeburn 11367: if ($changes{'unauth'}) {
11368: $resulttext .= '<li>'.&mt('Catalog type for unauthenticated users set to "'.$level{$env{'form.coursecat_unauth'}}.'"').'</li>';
11369: }
11370: if ($changes{'auth'}) {
11371: $resulttext .= '<li>'.&mt('Catalog type for authenticated users set to "'.$level{$env{'form.coursecat_auth'}}.'"').'</li>';
11372: }
1.57 raeburn 11373: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
11374: my $cathash;
11375: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
11376: $cathash = $domconfig{'coursecategories'}{'cats'};
11377: } else {
11378: $cathash = {};
11379: }
11380: my (@cats,@trails,%allitems);
11381: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
11382: if (keys(%deletions) > 0) {
11383: $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
11384: foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) {
11385: $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
11386: }
11387: $resulttext .= '</ul></li>';
11388: }
11389: if (keys(%reorderings) > 0) {
11390: my %sort_by_trail;
11391: $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
11392: foreach my $key (keys(%reorderings)) {
11393: if ($allitems{$key} ne '') {
11394: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
11395: }
1.48 raeburn 11396: }
1.57 raeburn 11397: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
11398: $resulttext .= '<li>'.$trails[$trail].'</li>';
11399: }
11400: $resulttext .= '</ul></li>';
1.48 raeburn 11401: }
1.57 raeburn 11402: if (keys(%adds) > 0) {
11403: my %sort_by_trail;
11404: $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
11405: foreach my $key (keys(%adds)) {
11406: if ($allitems{$key} ne '') {
11407: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
11408: }
11409: }
11410: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
11411: $resulttext .= '<li>'.$trails[$trail].'</li>';
1.48 raeburn 11412: }
1.57 raeburn 11413: $resulttext .= '</ul></li>';
1.48 raeburn 11414: }
11415: }
11416: $resulttext .= '</ul>';
1.239 raeburn 11417: if ($changes{'unauth'} || $changes{'auth'}) {
1.246 raeburn 11418: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
11419: if ($changes{'auth'}) {
11420: $domdefaults{'catauth'} = $domconfig{'coursecategories'}{'auth'};
11421: }
11422: if ($changes{'unauth'}) {
11423: $domdefaults{'catunauth'} = $domconfig{'coursecategories'}{'unauth'};
11424: }
11425: my $cachetime = 24*60*60;
11426: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.239 raeburn 11427: if (ref($lastactref) eq 'HASH') {
1.246 raeburn 11428: $lastactref->{'domdefaults'} = 1;
1.239 raeburn 11429: }
11430: }
1.48 raeburn 11431: } else {
11432: $resulttext = '<span class="LC_error">'.
1.57 raeburn 11433: &mt('An error occurred: [_1]',$putresult).'</span>';
1.48 raeburn 11434: }
11435: } else {
1.120 raeburn 11436: $resulttext = &mt('No changes made to course and community categories');
1.48 raeburn 11437: }
11438: return $resulttext;
11439: }
11440:
1.69 raeburn 11441: sub modify_serverstatuses {
11442: my ($dom,%domconfig) = @_;
11443: my ($resulttext,%changes,%currserverstatus,%newserverstatus);
11444: if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
11445: %currserverstatus = %{$domconfig{'serverstatuses'}};
11446: }
11447: my @pages = &serverstatus_pages();
11448: foreach my $type (@pages) {
11449: $newserverstatus{$type}{'namedusers'} = '';
11450: $newserverstatus{$type}{'machines'} = '';
11451: if (defined($env{'form.'.$type.'_namedusers'})) {
11452: my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
11453: my @okusers;
11454: foreach my $user (@users) {
11455: my ($uname,$udom) = split(/:/,$user);
11456: if (($udom =~ /^$match_domain$/) &&
11457: (&Apache::lonnet::domain($udom)) &&
11458: ($uname =~ /^$match_username$/)) {
11459: if (!grep(/^\Q$user\E/,@okusers)) {
11460: push(@okusers,$user);
11461: }
11462: }
11463: }
11464: if (@okusers > 0) {
11465: @okusers = sort(@okusers);
11466: $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
11467: }
11468: }
11469: if (defined($env{'form.'.$type.'_machines'})) {
11470: my @machines = split(/,/,$env{'form.'.$type.'_machines'});
11471: my @okmachines;
11472: foreach my $ip (@machines) {
11473: my @parts = split(/\./,$ip);
11474: next if (@parts < 4);
11475: my $badip = 0;
11476: for (my $i=0; $i<4; $i++) {
11477: if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
11478: $badip = 1;
11479: last;
11480: }
11481: }
11482: if (!$badip) {
11483: push(@okmachines,$ip);
11484: }
11485: }
11486: @okmachines = sort(@okmachines);
11487: $newserverstatus{$type}{'machines'} = join(',',@okmachines);
11488: }
11489: }
11490: my %serverstatushash = (
11491: serverstatuses => \%newserverstatus,
11492: );
11493: foreach my $type (@pages) {
1.83 raeburn 11494: foreach my $setting ('namedusers','machines') {
1.84 raeburn 11495: my (@current,@new);
1.83 raeburn 11496: if (ref($currserverstatus{$type}) eq 'HASH') {
1.84 raeburn 11497: if ($currserverstatus{$type}{$setting} ne '') {
11498: @current = split(/,/,$currserverstatus{$type}{$setting});
11499: }
11500: }
11501: if ($newserverstatus{$type}{$setting} ne '') {
11502: @new = split(/,/,$newserverstatus{$type}{$setting});
1.83 raeburn 11503: }
11504: if (@current > 0) {
11505: if (@new > 0) {
11506: foreach my $item (@current) {
11507: if (!grep(/^\Q$item\E$/,@new)) {
11508: $changes{$type}{$setting} = 1;
1.82 raeburn 11509: last;
11510: }
11511: }
1.84 raeburn 11512: foreach my $item (@new) {
11513: if (!grep(/^\Q$item\E$/,@current)) {
11514: $changes{$type}{$setting} = 1;
11515: last;
1.82 raeburn 11516: }
11517: }
11518: } else {
1.83 raeburn 11519: $changes{$type}{$setting} = 1;
1.69 raeburn 11520: }
1.83 raeburn 11521: } elsif (@new > 0) {
11522: $changes{$type}{$setting} = 1;
1.69 raeburn 11523: }
11524: }
11525: }
11526: if (keys(%changes) > 0) {
1.81 raeburn 11527: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 11528: my $putresult = &Apache::lonnet::put_dom('configuration',
11529: \%serverstatushash,$dom);
11530: if ($putresult eq 'ok') {
11531: $resulttext .= &mt('Changes made:').'<ul>';
11532: foreach my $type (@pages) {
1.84 raeburn 11533: if (ref($changes{$type}) eq 'HASH') {
1.69 raeburn 11534: $resulttext .= '<li>'.$titles->{$type}.'<ul>';
1.84 raeburn 11535: if ($changes{$type}{'namedusers'}) {
1.69 raeburn 11536: if ($newserverstatus{$type}{'namedusers'} eq '') {
11537: $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n";
11538: } else {
11539: $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n";
11540: }
1.84 raeburn 11541: }
11542: if ($changes{$type}{'machines'}) {
1.69 raeburn 11543: if ($newserverstatus{$type}{'machines'} eq '') {
11544: $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n";
11545: } else {
11546: $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n";
11547: }
11548:
11549: }
11550: $resulttext .= '</ul></li>';
11551: }
11552: }
11553: $resulttext .= '</ul>';
11554: } else {
11555: $resulttext = '<span class="LC_error">'.
11556: &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>';
11557:
11558: }
11559: } else {
11560: $resulttext = &mt('No changes made to access to server status pages');
11561: }
11562: return $resulttext;
11563: }
11564:
1.118 jms 11565: sub modify_helpsettings {
1.122 jms 11566: my ($r,$dom,$confname,%domconfig) = @_;
1.166 raeburn 11567: my ($resulttext,$errors,%changes,%helphash);
11568: my %defaultchecked = ('submitbugs' => 'on');
11569: my @offon = ('off','on');
1.118 jms 11570: my @toggles = ('submitbugs');
11571: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
11572: foreach my $item (@toggles) {
1.166 raeburn 11573: if ($defaultchecked{$item} eq 'on') {
11574: if ($domconfig{'helpsettings'}{$item} eq '') {
11575: if ($env{'form.'.$item} eq '0') {
11576: $changes{$item} = 1;
11577: }
11578: } elsif ($domconfig{'helpsettings'}{$item} ne $env{'form.'.$item}) {
11579: $changes{$item} = 1;
11580: }
11581: } elsif ($defaultchecked{$item} eq 'off') {
11582: if ($domconfig{'helpsettings'}{$item} eq '') {
11583: if ($env{'form.'.$item} eq '1') {
11584: $changes{$item} = 1;
11585: }
11586: } elsif ($domconfig{'helpsettings'}{$item} ne $env{'form.'.$item}) {
11587: $changes{$item} = 1;
11588: }
11589: }
1.210 raeburn 11590: if (($env{'form.'.$item} eq '0') || ($env{'form.'.$item} eq '1')) {
1.166 raeburn 11591: $helphash{'helpsettings'}{$item} = $env{'form.'.$item};
11592: }
11593: }
1.118 jms 11594: }
1.123 jms 11595: my $putresult;
11596: if (keys(%changes) > 0) {
1.166 raeburn 11597: $putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom);
1.168 raeburn 11598: if ($putresult eq 'ok') {
1.166 raeburn 11599: $resulttext = &mt('Changes made:').'<ul>';
11600: foreach my $item (sort(keys(%changes))) {
11601: if ($item eq 'submitbugs') {
11602: $resulttext .= '<li>'.&mt('Display link to: [_1] set to "'.$offon[$env{'form.'.$item}].'".',
11603: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
11604: &mt('LON-CAPA bug tracker'),600,500)).'</li>';
11605: }
11606: }
11607: $resulttext .= '</ul>';
11608: } else {
11609: $resulttext = &mt('No changes made to help settings');
1.168 raeburn 11610: $errors .= '<li><span class="LC_error">'.
11611: &mt('An error occurred storing the settings: [_1]',
11612: $putresult).'</span></li>';
1.166 raeburn 11613: }
1.118 jms 11614: }
11615: if ($errors) {
1.168 raeburn 11616: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.118 jms 11617: $errors.'</ul>';
11618: }
11619: return $resulttext;
11620: }
11621:
1.121 raeburn 11622: sub modify_coursedefaults {
1.212 raeburn 11623: my ($dom,$lastactref,%domconfig) = @_;
1.121 raeburn 11624: my ($resulttext,$errors,%changes,%defaultshash);
1.257 raeburn 11625: my %defaultchecked = (
11626: 'canuse_pdfforms' => 'off',
11627: 'uselcmath' => 'on',
11628: 'usejsme' => 'on'
11629: );
11630: my @toggles = ('canuse_pdfforms','uselcmath','usejsme');
1.198 raeburn 11631: my @numbers = ('anonsurvey_threshold','uploadquota_official','uploadquota_unofficial',
1.271 raeburn 11632: 'uploadquota_community','uploadquota_textbook','uploadquota_placement');
11633: my @types = ('official','unofficial','community','textbook','placement');
1.198 raeburn 11634: my %staticdefaults = (
11635: anonsurvey_threshold => 10,
11636: uploadquota => 500,
1.257 raeburn 11637: postsubmit => 60,
1.198 raeburn 11638: );
1.121 raeburn 11639:
11640: $defaultshash{'coursedefaults'} = {};
11641:
11642: if (ref($domconfig{'coursedefaults'}) ne 'HASH') {
11643: if ($domconfig{'coursedefaults'} eq '') {
11644: $domconfig{'coursedefaults'} = {};
11645: }
11646: }
11647:
11648: if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
11649: foreach my $item (@toggles) {
11650: if ($defaultchecked{$item} eq 'on') {
11651: if (($domconfig{'coursedefaults'}{$item} eq '') &&
11652: ($env{'form.'.$item} eq '0')) {
11653: $changes{$item} = 1;
1.192 raeburn 11654: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
1.121 raeburn 11655: $changes{$item} = 1;
11656: }
11657: } elsif ($defaultchecked{$item} eq 'off') {
11658: if (($domconfig{'coursedefaults'}{$item} eq '') &&
11659: ($env{'form.'.$item} eq '1')) {
11660: $changes{$item} = 1;
11661: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
11662: $changes{$item} = 1;
11663: }
11664: }
11665: $defaultshash{'coursedefaults'}{$item} = $env{'form.'.$item};
11666: }
1.198 raeburn 11667: foreach my $item (@numbers) {
11668: my ($currdef,$newdef);
1.208 raeburn 11669: $newdef = $env{'form.'.$item};
1.198 raeburn 11670: if ($item eq 'anonsurvey_threshold') {
11671: $currdef = $domconfig{'coursedefaults'}{$item};
11672: $newdef =~ s/\D//g;
11673: if ($newdef eq '' || $newdef < 1) {
11674: $newdef = 1;
11675: }
11676: $defaultshash{'coursedefaults'}{$item} = $newdef;
11677: } else {
11678: my ($type) = ($item =~ /^\Quploadquota_\E(\w+)$/);
11679: if (ref($domconfig{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
11680: $currdef = $domconfig{'coursedefaults'}{'uploadquota'}{$type};
11681: }
11682: $newdef =~ s/[^\w.\-]//g;
11683: $defaultshash{'coursedefaults'}{'uploadquota'}{$type} = $newdef;
11684: }
11685: if ($currdef ne $newdef) {
11686: my $staticdef;
11687: if ($item eq 'anonsurvey_threshold') {
11688: unless (($currdef eq '') && ($newdef == $staticdefaults{$item})) {
11689: $changes{$item} = 1;
11690: }
11691: } else {
11692: unless (($currdef eq '') && ($newdef == $staticdefaults{'uploadquota'})) {
11693: $changes{'uploadquota'} = 1;
11694: }
11695: }
1.139 raeburn 11696: }
11697: }
1.264 raeburn 11698: my $currclone = $domconfig{'coursedefaults'}{'canclone'};
11699: my @currclonecode;
11700: if (ref($currclone) eq 'HASH') {
11701: if (ref($currclone->{'instcode'}) eq 'ARRAY') {
11702: @currclonecode = @{$currclone->{'instcode'}};
11703: }
11704: }
11705: my $newclone;
11706: if ($env{'form.canclone'} =~ /^(none|domain|instcode)$/) {
11707: $newclone = $env{'form.canclone'};
11708: }
11709: if ($newclone eq 'instcode') {
11710: my @newcodes = &Apache::loncommon::get_env_multiple('form.clonecode');
11711: my (%codedefaults,@code_order,@clonecode);
11712: &Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
11713: \@code_order);
11714: foreach my $item (@code_order) {
11715: if (grep(/^\Q$item\E$/,@newcodes)) {
11716: push(@clonecode,$item);
11717: }
11718: }
11719: if (@clonecode) {
11720: $defaultshash{'coursedefaults'}{'canclone'} = { $newclone => \@clonecode };
11721: my @diffs = &Apache::loncommon::compare_arrays(\@currclonecode,\@clonecode);
11722: if (@diffs) {
11723: $changes{'canclone'} = 1;
11724: }
11725: } else {
11726: $newclone eq '';
11727: }
11728: } elsif ($newclone ne '') {
11729: $defaultshash{'coursedefaults'}{'canclone'} = $newclone;
11730: }
11731: if ($newclone ne $currclone) {
11732: $changes{'canclone'} = 1;
11733: }
1.257 raeburn 11734: my %credits;
11735: foreach my $type (@types) {
11736: unless ($type eq 'community') {
11737: $credits{$type} = $env{'form.'.$type.'_credits'};
11738: $credits{$type} =~ s/[^\d.]+//g;
11739: }
11740: }
11741: if ((ref($domconfig{'coursedefaults'}{'coursecredits'}) ne 'HASH') &&
11742: ($env{'form.coursecredits'} eq '1')) {
11743: $changes{'coursecredits'} = 1;
11744: foreach my $type (keys(%credits)) {
11745: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
11746: }
11747: } else {
11748: if ($env{'form.coursecredits'} eq '1') {
11749: foreach my $type (@types) {
11750: unless ($type eq 'community') {
11751: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type} ne $credits{$type}) {
11752: $changes{'coursecredits'} = 1;
11753: }
11754: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
11755: }
11756: }
11757: } elsif (ref($domconfig{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
11758: foreach my $type (@types) {
11759: unless ($type eq 'community') {
11760: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type}) {
11761: $changes{'coursecredits'} = 1;
11762: last;
11763: }
11764: }
11765: }
11766: }
11767: }
11768: if ($env{'form.postsubmit'} eq '1') {
11769: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'on';
11770: my %currtimeout;
11771: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
11772: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'off') {
11773: $changes{'postsubmit'} = 1;
11774: }
11775: if (ref($domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
11776: %currtimeout = %{$domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}};
11777: }
11778: } else {
11779: $changes{'postsubmit'} = 1;
11780: }
11781: foreach my $type (@types) {
11782: my $timeout = $env{'form.'.$type.'_timeout'};
11783: $timeout =~ s/\D//g;
11784: if ($timeout == $staticdefaults{'postsubmit'}) {
11785: $timeout = '';
11786: } elsif (($timeout eq '') || ($timeout =~ /^0+$/)) {
11787: $timeout = '0';
11788: }
11789: unless ($timeout eq '') {
11790: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type} = $timeout;
11791: }
11792: if (exists($currtimeout{$type})) {
11793: if ($timeout ne $currtimeout{$type}) {
11794: $changes{'postsubmit'} = 1;
11795: }
11796: } elsif ($timeout ne '') {
11797: $changes{'postsubmit'} = 1;
11798: }
11799: }
11800: } else {
11801: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'off';
11802: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
11803: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'on') {
11804: $changes{'postsubmit'} = 1;
11805: }
11806: } else {
11807: $changes{'postsubmit'} = 1;
11808: }
1.192 raeburn 11809: }
1.121 raeburn 11810: }
11811: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
11812: $dom);
11813: if ($putresult eq 'ok') {
11814: if (keys(%changes) > 0) {
1.213 raeburn 11815: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.257 raeburn 11816: if (($changes{'canuse_pdfforms'}) || ($changes{'uploadquota'}) || ($changes{'postsubmit'}) ||
1.264 raeburn 11817: ($changes{'coursecredits'}) || ($changes{'uselcmath'}) || ($changes{'usejsme'}) ||
11818: ($changes{'canclone'})) {
1.257 raeburn 11819: foreach my $item ('canuse_pdfforms','uselcmath','usejsme') {
11820: if ($changes{$item}) {
11821: $domdefaults{$item}=$defaultshash{'coursedefaults'}{$item};
11822: }
11823: }
1.192 raeburn 11824: if ($changes{'coursecredits'}) {
11825: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
1.257 raeburn 11826: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'coursecredits'}})) {
11827: $domdefaults{$type.'credits'} =
11828: $defaultshash{'coursedefaults'}{'coursecredits'}{$type};
11829: }
11830: }
11831: }
11832: if ($changes{'postsubmit'}) {
11833: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
11834: $domdefaults{'postsubmit'} = $defaultshash{'coursedefaults'}{'postsubmit'}{'client'};
11835: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
11836: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}})) {
11837: $domdefaults{$type.'postsubtimeout'} =
11838: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
11839: }
11840: }
1.192 raeburn 11841: }
11842: }
1.198 raeburn 11843: if ($changes{'uploadquota'}) {
11844: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
11845: foreach my $type (@types) {
11846: $domdefaults{$type.'quota'}=$defaultshash{'coursedefaults'}{'uploadquota'}{$type};
11847: }
11848: }
11849: }
1.264 raeburn 11850: if ($changes{'canclone'}) {
11851: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
11852: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
11853: my @clonecodes = @{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}};
11854: if (@clonecodes) {
11855: $domdefaults{'canclone'} = join('+',@clonecodes);
11856: }
11857: }
11858: } else {
11859: $domdefaults{'canclone'}=$defaultshash{'coursedefaults'}{'canclone'};
11860: }
11861: }
1.121 raeburn 11862: my $cachetime = 24*60*60;
11863: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 11864: if (ref($lastactref) eq 'HASH') {
11865: $lastactref->{'domdefaults'} = 1;
11866: }
1.121 raeburn 11867: }
11868: $resulttext = &mt('Changes made:').'<ul>';
11869: foreach my $item (sort(keys(%changes))) {
11870: if ($item eq 'canuse_pdfforms') {
11871: if ($env{'form.'.$item} eq '1') {
11872: $resulttext .= '<li>'.&mt("Course/Community users can create/upload PDF forms set to 'on'").'</li>';
11873: } else {
11874: $resulttext .= '<li>'.&mt('Course/Community users can create/upload PDF forms set to "off"').'</li>';
11875: }
1.257 raeburn 11876: } elsif ($item eq 'uselcmath') {
11877: if ($env{'form.'.$item} eq '1') {
11878: $resulttext .= '<li>'.&mt('Math preview uses LON-CAPA previewer (javascript), if supported by browser.').'</li>';
11879: } else {
11880: $resulttext .= '<li>'.&mt('Math preview uses DragMath (Java), if supported by client OS.').'</li>';
11881: }
11882: } elsif ($item eq 'usejsme') {
11883: if ($env{'form.'.$item} eq '1') {
11884: $resulttext .= '<li>'.&mt('Molecule editor uses JSME (HTML5), if supported by browser.').'</li>';
11885: } else {
11886: $resulttext .= '<li>'.&mt('Molecule editor uses JME (Java), if supported by client OS.').'</li>';
11887: }
1.139 raeburn 11888: } elsif ($item eq 'anonsurvey_threshold') {
1.192 raeburn 11889: $resulttext .= '<li>'.&mt('Responder count required for display of anonymous survey submissions set to [_1].',$defaultshash{'coursedefaults'}{'anonsurvey_threshold'}).'</li>';
1.198 raeburn 11890: } elsif ($item eq 'uploadquota') {
11891: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
11892: $resulttext .= '<li>'.&mt('Default quota for content uploaded to a course/community via Course Editor set as follows:').'<ul>'.
11893: '<li>'.&mt('Official courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'official'}.'</b>').'</li>'.
11894: '<li>'.&mt('Unofficial courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'unofficial'}.'</b>').'</li>'.
1.216 raeburn 11895: '<li>'.&mt('Textbook courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'textbook'}.'</b>').'</li>'.
1.271 raeburn 11896: '<li>'.&mt('Placement tests: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'placement'}.'</b>').'</li>'.
1.198 raeburn 11897: '<li>'.&mt('Communities: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'community'}.'</b>').'</li>'.
11898: '</ul>'.
11899: '</li>';
11900: } else {
11901: $resulttext .= '<li>'.&mt('Default quota for content uploaded via Course Editor remains default: [_1] MB',$staticdefaults{'uploadquota'}).'</li>';
11902: }
1.257 raeburn 11903: } elsif ($item eq 'postsubmit') {
11904: if ($domdefaults{'postsubmit'} eq 'off') {
11905: $resulttext .= '<li>'.&mt('Submit button(s) remain enabled on page after student makes submission.');
11906: } else {
11907: $resulttext .= '<li>'.&mt('Submit button(s) disabled on page after student makes submission').'; ';
11908: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
11909: $resulttext .= &mt('durations:').'<ul>';
11910: foreach my $type (@types) {
11911: $resulttext .= '<li>';
11912: my $timeout;
11913: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
11914: $timeout = $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
11915: }
11916: my $display;
11917: if ($timeout eq '0') {
11918: $display = &mt('unlimited');
11919: } elsif ($timeout eq '') {
11920: $display = &mt('[quant,_1,second] (default)',$staticdefaults{'postsubmit'});
11921: } else {
11922: $display = &mt('[quant,_1,second]',$timeout);
11923: }
11924: if ($type eq 'community') {
11925: $resulttext .= &mt('Communities');
11926: } elsif ($type eq 'official') {
11927: $resulttext .= &mt('Official courses');
11928: } elsif ($type eq 'unofficial') {
11929: $resulttext .= &mt('Unofficial courses');
11930: } elsif ($type eq 'textbook') {
11931: $resulttext .= &mt('Textbook courses');
1.271 raeburn 11932: } elsif ($type eq 'placement') {
11933: $resulttext .= &mt('Placement tests');
1.257 raeburn 11934: }
11935: $resulttext .= ' -- '.$display.'</li>';
11936: }
11937: $resulttext .= '</ul>';
11938: }
11939: $resulttext .= '</li>';
11940: }
1.192 raeburn 11941: } elsif ($item eq 'coursecredits') {
11942: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
11943: if (($domdefaults{'officialcredits'} eq '') &&
1.216 raeburn 11944: ($domdefaults{'unofficialcredits'} eq '') &&
11945: ($domdefaults{'textbookcredits'} eq '')) {
1.192 raeburn 11946: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
11947: } else {
11948: $resulttext .= '<li>'.&mt('Student credits can be set per course by a Domain Coordinator, with the following defaults applying:').'<ul>'.
11949: '<li>'.&mt('Official courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'official'}).'</li>'.
11950: '<li>'.&mt('Unofficial courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'}).'</li>'.
1.216 raeburn 11951: '<li>'.&mt('Textbook courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'textbook'}).'</li>'.
1.192 raeburn 11952: '</ul>'.
11953: '</li>';
11954: }
11955: } else {
11956: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
11957: }
1.264 raeburn 11958: } elsif ($item eq 'canclone') {
11959: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
11960: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
11961: my $clonecodes = join(' '.&mt('and').' ',@{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}});
11962: $resulttext .= '<li>'.&mt('By default, official courses can be cloned from existing courses with the same: [_1]','<b>'.$clonecodes.'</b>').'</li>';
11963: }
11964: } elsif ($defaultshash{'coursedefaults'}{'canclone'} eq 'domain') {
11965: $resulttext .= '<li>'.&mt('By default, a course requester can clone any course from his/her domain.').'</li>';
11966: } else {
11967: $resulttext .= '<li>'.&mt('By default, only course owner and coordinators may clone a course.').'</li>';
11968: }
1.140 raeburn 11969: }
1.121 raeburn 11970: }
11971: $resulttext .= '</ul>';
11972: } else {
11973: $resulttext = &mt('No changes made to course defaults');
11974: }
11975: } else {
11976: $resulttext = '<span class="LC_error">'.
11977: &mt('An error occurred: [_1]',$putresult).'</span>';
11978: }
11979: return $resulttext;
11980: }
11981:
1.231 raeburn 11982: sub modify_selfenrollment {
11983: my ($dom,$lastactref,%domconfig) = @_;
11984: my ($resulttext,$errors,%changes,%selfenrollhash,%ordered);
1.271 raeburn 11985: my @types = ('official','unofficial','community','textbook','placement');
1.231 raeburn 11986: my %titles = &tool_titles();
1.232 raeburn 11987: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
11988: ($ordered{'admin'},my $titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
1.231 raeburn 11989: $ordered{'default'} = ['types','registered','approval','limit'];
11990:
11991: my (%roles,%shown,%toplevel);
11992: $roles{'0'} = &Apache::lonnet::plaintext('dc');
11993:
11994: if (ref($domconfig{'selfenrollment'}) ne 'HASH') {
11995: if ($domconfig{'selfenrollment'} eq '') {
11996: $domconfig{'selfenrollment'} = {};
11997: }
11998: }
11999: %toplevel = (
12000: admin => 'Configuration Rights',
12001: default => 'Default settings',
12002: validation => 'Validation of self-enrollment requests',
12003: );
1.233 raeburn 12004: my ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
1.231 raeburn 12005:
12006: if (ref($ordered{'admin'}) eq 'ARRAY') {
12007: foreach my $item (@{$ordered{'admin'}}) {
12008: foreach my $type (@types) {
12009: if ($env{'form.selfenrolladmin_'.$item.'_'.$type}) {
12010: $selfenrollhash{'admin'}{$type}{$item} = 1;
12011: } else {
12012: $selfenrollhash{'admin'}{$type}{$item} = 0;
12013: }
12014: if (ref($domconfig{'selfenrollment'}{'admin'}) eq 'HASH') {
12015: if (ref($domconfig{'selfenrollment'}{'admin'}{$type}) eq 'HASH') {
12016: if ($selfenrollhash{'admin'}{$type}{$item} ne
12017: $domconfig{'selfenrollment'}{'admin'}{$type}{$item}) {
12018: push(@{$changes{'admin'}{$type}},$item);
12019: }
12020: } else {
12021: if (!$selfenrollhash{'admin'}{$type}{$item}) {
12022: push(@{$changes{'admin'}{$type}},$item);
12023: }
12024: }
12025: } elsif (!$selfenrollhash{'admin'}{$type}{$item}) {
12026: push(@{$changes{'admin'}{$type}},$item);
12027: }
12028: }
12029: }
12030: }
12031:
12032: foreach my $item (@{$ordered{'default'}}) {
12033: foreach my $type (@types) {
12034: my $value = $env{'form.selfenrolldefault_'.$item.'_'.$type};
12035: if ($item eq 'types') {
12036: unless (($value eq 'all') || ($value eq 'dom')) {
12037: $value = '';
12038: }
12039: } elsif ($item eq 'registered') {
12040: unless ($value eq '1') {
12041: $value = 0;
12042: }
12043: } elsif ($item eq 'approval') {
12044: unless ($value =~ /^[012]$/) {
12045: $value = 0;
12046: }
12047: } else {
12048: unless (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
12049: $value = 'none';
12050: }
12051: }
12052: $selfenrollhash{'default'}{$type}{$item} = $value;
12053: if (ref($domconfig{'selfenrollment'}{'default'}) eq 'HASH') {
12054: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
12055: if ($selfenrollhash{'default'}{$type}{$item} ne
12056: $domconfig{'selfenrollment'}{'default'}{$type}{$item}) {
12057: push(@{$changes{'default'}{$type}},$item);
12058: }
12059: } else {
12060: push(@{$changes{'default'}{$type}},$item);
12061: }
12062: } else {
12063: push(@{$changes{'default'}{$type}},$item);
12064: }
12065: if ($item eq 'limit') {
12066: if (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
12067: $env{'form.selfenrolldefault_cap_'.$type} =~ s/\D//g;
12068: if ($env{'form.selfenrolldefault_cap_'.$type} ne '') {
12069: $selfenrollhash{'default'}{$type}{'cap'} = $env{'form.selfenrolldefault_cap_'.$type};
12070: }
12071: } else {
12072: $selfenrollhash{'default'}{$type}{'cap'} = '';
12073: }
12074: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
12075: if ($selfenrollhash{'default'}{$type}{'cap'} ne
12076: $domconfig{'selfenrollment'}{'admin'}{$type}{'cap'}) {
12077: push(@{$changes{'default'}{$type}},'cap');
12078: }
12079: } elsif ($selfenrollhash{'default'}{$type}{'cap'} ne '') {
12080: push(@{$changes{'default'}{$type}},'cap');
12081: }
12082: }
12083: }
12084: }
12085:
12086: foreach my $item (@{$itemsref}) {
12087: if ($item eq 'fields') {
12088: my @changed;
12089: @{$selfenrollhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.selfenroll_validation_'.$item);
12090: if (@{$selfenrollhash{'validation'}{$item}} > 0) {
12091: @{$selfenrollhash{'validation'}{$item}} = sort(@{$selfenrollhash{'validation'}{$item}});
12092: }
12093: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
12094: if (ref($domconfig{'selfenrollment'}{'validation'}{$item}) eq 'ARRAY') {
12095: @changed = &Apache::loncommon::compare_arrays($selfenrollhash{'validation'}{$item},
12096: $domconfig{'selfenrollment'}{'validation'}{$item});
12097: } else {
12098: @changed = @{$selfenrollhash{'validation'}{$item}};
12099: }
12100: } else {
12101: @changed = @{$selfenrollhash{'validation'}{$item}};
12102: }
12103: if (@changed) {
12104: if ($selfenrollhash{'validation'}{$item}) {
12105: $changes{'validation'}{$item} = join(', ',@{$selfenrollhash{'validation'}{$item}});
12106: } else {
12107: $changes{'validation'}{$item} = &mt('None');
12108: }
12109: }
12110: } else {
12111: $selfenrollhash{'validation'}{$item} = $env{'form.selfenroll_validation_'.$item};
12112: if ($item eq 'markup') {
12113: if ($env{'form.selfenroll_validation_'.$item}) {
12114: $env{'form.selfenroll_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
12115: }
12116: }
12117: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
12118: if ($domconfig{'selfenrollment'}{'validation'}{$item} ne $selfenrollhash{'validation'}{$item}) {
12119: $changes{'validation'}{$item} = $selfenrollhash{'validation'}{$item};
12120: }
12121: }
12122: }
12123: }
12124:
12125: my $putresult = &Apache::lonnet::put_dom('configuration',{'selfenrollment' => \%selfenrollhash},
12126: $dom);
12127: if ($putresult eq 'ok') {
12128: if (keys(%changes) > 0) {
12129: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
12130: $resulttext = &mt('Changes made:').'<ul>';
12131: foreach my $key ('admin','default','validation') {
12132: if (ref($changes{$key}) eq 'HASH') {
12133: $resulttext .= '<li>'.$toplevel{$key}.'<ul>';
12134: if ($key eq 'validation') {
12135: foreach my $item (@{$itemsref}) {
12136: if (exists($changes{$key}{$item})) {
12137: if ($item eq 'markup') {
12138: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
12139: '<br /><pre>'.$changes{$key}{$item}.'</pre>').'</li>';
12140: } else {
12141: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
12142: '<b>'.$changes{$key}{$item}.'</b>').'</li>';
12143: }
12144: }
12145: }
12146: } else {
12147: foreach my $type (@types) {
12148: if ($type eq 'community') {
12149: $roles{'1'} = &mt('Community personnel');
12150: } else {
12151: $roles{'1'} = &mt('Course personnel');
12152: }
12153: if (ref($changes{$key}{$type}) eq 'ARRAY') {
1.232 raeburn 12154: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
12155: if ($key eq 'admin') {
12156: my @mgrdc = ();
12157: if (ref($ordered{$key}) eq 'ARRAY') {
12158: foreach my $item (@{$ordered{'admin'}}) {
12159: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
12160: if ($selfenrollhash{$key}{$type}{$item} eq '0') {
12161: push(@mgrdc,$item);
12162: }
12163: }
12164: }
12165: if (@mgrdc) {
12166: $domdefaults{$type.'selfenrolladmdc'} = join(',',@mgrdc);
12167: } else {
12168: delete($domdefaults{$type.'selfenrolladmdc'});
12169: }
12170: }
12171: } else {
12172: if (ref($ordered{$key}) eq 'ARRAY') {
12173: foreach my $item (@{$ordered{$key}}) {
12174: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
12175: $domdefaults{$type.'selfenroll'.$item} =
12176: $selfenrollhash{$key}{$type}{$item};
12177: }
12178: }
12179: }
12180: }
12181: }
1.231 raeburn 12182: $resulttext .= '<li>'.$titles{$type}.'<ul>';
12183: foreach my $item (@{$ordered{$key}}) {
12184: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
12185: $resulttext .= '<li>';
12186: if ($key eq 'admin') {
12187: $resulttext .= &mt('[_1] -- management by: [_2]',$titlesref->{$item},
12188: '<b>'.$roles{$selfenrollhash{'admin'}{$type}{$item}}.'</b>');
12189: } else {
12190: $resulttext .= &mt('[_1] set to: [_2]',$titlesref->{$item},
12191: '<b>'.$descs{$item}{$selfenrollhash{'default'}{$type}{$item}}.'</b>');
12192: }
12193: $resulttext .= '</li>';
12194: }
12195: }
12196: $resulttext .= '</ul></li>';
12197: }
12198: }
12199: $resulttext .= '</ul></li>';
12200: }
12201: }
1.232 raeburn 12202: if ((exists($changes{'admin'})) || (exists($changes{'default'}))) {
12203: my $cachetime = 24*60*60;
12204: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
12205: if (ref($lastactref) eq 'HASH') {
12206: $lastactref->{'domdefaults'} = 1;
12207: }
12208: }
1.231 raeburn 12209: }
12210: $resulttext .= '</ul>';
12211: } else {
12212: $resulttext = &mt('No changes made to self-enrollment settings');
12213: }
12214: } else {
12215: $resulttext = '<span class="LC_error">'.
12216: &mt('An error occurred: [_1]',$putresult).'</span>';
12217: }
12218: return $resulttext;
12219: }
12220:
1.137 raeburn 12221: sub modify_usersessions {
1.212 raeburn 12222: my ($dom,$lastactref,%domconfig) = @_;
1.145 raeburn 12223: my @hostingtypes = ('version','excludedomain','includedomain');
12224: my @offloadtypes = ('primary','default');
12225: my %types = (
12226: remote => \@hostingtypes,
12227: hosted => \@hostingtypes,
12228: spares => \@offloadtypes,
12229: );
12230: my @prefixes = ('remote','hosted','spares');
1.137 raeburn 12231: my @lcversions = &Apache::lonnet::all_loncaparevs();
1.275 ! raeburn 12232: my (%by_ip,%by_location,@intdoms,@instdoms);
! 12233: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
1.138 raeburn 12234: my @locations = sort(keys(%by_location));
1.137 raeburn 12235: my (%defaultshash,%changes);
12236: foreach my $prefix (@prefixes) {
12237: $defaultshash{'usersessions'}{$prefix} = {};
12238: }
1.212 raeburn 12239: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.137 raeburn 12240: my $resulttext;
1.138 raeburn 12241: my %iphost = &Apache::lonnet::get_iphost();
1.137 raeburn 12242: foreach my $prefix (@prefixes) {
1.145 raeburn 12243: next if ($prefix eq 'spares');
12244: foreach my $type (@{$types{$prefix}}) {
1.137 raeburn 12245: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
12246: if ($type eq 'version') {
12247: my $value = $env{'form.'.$prefix.'_'.$type};
12248: my $okvalue;
12249: if ($value ne '') {
12250: if (grep(/^\Q$value\E$/,@lcversions)) {
12251: $okvalue = $value;
12252: }
12253: }
12254: if (ref($domconfig{'usersessions'}) eq 'HASH') {
12255: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
12256: if ($domconfig{'usersessions'}{$prefix}{$type} ne '') {
12257: if ($inuse == 0) {
12258: $changes{$prefix}{$type} = 1;
12259: } else {
12260: if ($okvalue ne $domconfig{'usersessions'}{$prefix}{$type}) {
12261: $changes{$prefix}{$type} = 1;
12262: }
12263: if ($okvalue ne '') {
12264: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
12265: }
12266: }
12267: } else {
12268: if (($inuse == 1) && ($okvalue ne '')) {
12269: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
12270: $changes{$prefix}{$type} = 1;
12271: }
12272: }
12273: } else {
12274: if (($inuse == 1) && ($okvalue ne '')) {
12275: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
12276: $changes{$prefix}{$type} = 1;
12277: }
12278: }
12279: } else {
12280: if (($inuse == 1) && ($okvalue ne '')) {
12281: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
12282: $changes{$prefix}{$type} = 1;
12283: }
12284: }
12285: } else {
12286: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
12287: my @okvals;
12288: foreach my $val (@vals) {
1.138 raeburn 12289: if ($val =~ /:/) {
12290: my @items = split(/:/,$val);
12291: foreach my $item (@items) {
12292: if (ref($by_location{$item}) eq 'ARRAY') {
12293: push(@okvals,$item);
12294: }
12295: }
12296: } else {
12297: if (ref($by_location{$val}) eq 'ARRAY') {
12298: push(@okvals,$val);
12299: }
1.137 raeburn 12300: }
12301: }
12302: @okvals = sort(@okvals);
12303: if (ref($domconfig{'usersessions'}) eq 'HASH') {
12304: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
12305: if (ref($domconfig{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
12306: if ($inuse == 0) {
12307: $changes{$prefix}{$type} = 1;
12308: } else {
12309: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
12310: my @changed = &Apache::loncommon::compare_arrays($domconfig{'usersessions'}{$prefix}{$type},$defaultshash{'usersessions'}{$prefix}{$type});
12311: if (@changed > 0) {
12312: $changes{$prefix}{$type} = 1;
12313: }
12314: }
12315: } else {
12316: if ($inuse == 1) {
12317: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
12318: $changes{$prefix}{$type} = 1;
12319: }
12320: }
12321: } else {
12322: if ($inuse == 1) {
12323: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
12324: $changes{$prefix}{$type} = 1;
12325: }
12326: }
12327: } else {
12328: if ($inuse == 1) {
12329: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
12330: $changes{$prefix}{$type} = 1;
12331: }
12332: }
12333: }
12334: }
12335: }
1.145 raeburn 12336:
12337: my @alldoms = &Apache::lonnet::all_domains();
1.149 raeburn 12338: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.145 raeburn 12339: my %spareid = ¤t_offloads_to($dom,$domconfig{'usersessions'},\%servers);
12340: my $savespares;
12341:
12342: foreach my $lonhost (sort(keys(%servers))) {
12343: my $serverhomeID =
12344: &Apache::lonnet::get_server_homeID($servers{$lonhost});
1.152 raeburn 12345: my $serverhostname = &Apache::lonnet::hostname($lonhost);
1.145 raeburn 12346: $defaultshash{'usersessions'}{'spares'}{$lonhost} = {};
12347: my %spareschg;
12348: foreach my $type (@{$types{'spares'}}) {
12349: my @okspares;
12350: my @checked = &Apache::loncommon::get_env_multiple('form.spare_'.$type.'_'.$lonhost);
12351: foreach my $server (@checked) {
1.152 raeburn 12352: if (&Apache::lonnet::hostname($server) ne '') {
12353: unless (&Apache::lonnet::hostname($server) eq $serverhostname) {
12354: unless (grep(/^\Q$server\E$/,@okspares)) {
12355: push(@okspares,$server);
12356: }
1.145 raeburn 12357: }
12358: }
12359: }
12360: my $new = $env{'form.newspare_'.$type.'_'.$lonhost};
12361: my $newspare;
1.152 raeburn 12362: if (($new ne '') && (&Apache::lonnet::hostname($new))) {
12363: unless (&Apache::lonnet::hostname($new) eq $serverhostname) {
1.145 raeburn 12364: $newspare = $new;
12365: }
12366: }
1.152 raeburn 12367: my @spares;
12368: if (($newspare ne '') && (!grep(/^\Q$newspare\E$/,@okspares))) {
12369: @spares = sort(@okspares,$newspare);
12370: } else {
12371: @spares = sort(@okspares);
12372: }
12373: $defaultshash{'usersessions'}{'spares'}{$lonhost}{$type} = \@spares;
1.145 raeburn 12374: if (ref($spareid{$lonhost}) eq 'HASH') {
12375: if (ref($spareid{$lonhost}{$type}) eq 'ARRAY') {
1.152 raeburn 12376: my @diffs = &Apache::loncommon::compare_arrays($spareid{$lonhost}{$type},\@spares);
1.145 raeburn 12377: if (@diffs > 0) {
12378: $spareschg{$type} = 1;
12379: }
12380: }
12381: }
12382: }
12383: if (keys(%spareschg) > 0) {
12384: $changes{'spares'}{$lonhost} = \%spareschg;
12385: }
12386: }
1.261 raeburn 12387: $defaultshash{'usersessions'}{'offloadnow'} = {};
12388: my @offloadnow = &Apache::loncommon::get_env_multiple('form.offloadnow');
12389: my @okoffload;
12390: if (@offloadnow) {
12391: foreach my $server (@offloadnow) {
12392: if (&Apache::lonnet::hostname($server) ne '') {
12393: unless (grep(/^\Q$server\E$/,@okoffload)) {
12394: push(@okoffload,$server);
12395: }
12396: }
12397: }
12398: if (@okoffload) {
12399: foreach my $lonhost (@okoffload) {
12400: $defaultshash{'usersessions'}{'offloadnow'}{$lonhost} = 1;
12401: }
12402: }
12403: }
1.145 raeburn 12404: if (ref($domconfig{'usersessions'}) eq 'HASH') {
12405: if (ref($domconfig{'usersessions'}{'spares'}) eq 'HASH') {
12406: if (ref($changes{'spares'}) eq 'HASH') {
12407: if (keys(%{$changes{'spares'}}) > 0) {
12408: $savespares = 1;
12409: }
12410: }
12411: } else {
12412: $savespares = 1;
12413: }
1.261 raeburn 12414: if (ref($domconfig{'usersessions'}{'offloadnow'}) eq 'HASH') {
12415: foreach my $lonhost (keys(%{$domconfig{'usersessions'}{'offloadnow'}})) {
12416: unless ($defaultshash{'usersessions'}{'offloadnow'}{$lonhost}) {
12417: $changes{'offloadnow'} = 1;
12418: last;
12419: }
12420: }
12421: unless ($changes{'offloadnow'}) {
12422: foreach my $lonhost (keys(%{$defaultshash{'usersessions'}{'offloadnow'}})) {
12423: unless ($domconfig{'usersessions'}{'offloadnow'}{$lonhost}) {
12424: $changes{'offloadnow'} = 1;
12425: last;
12426: }
12427: }
12428: }
12429: } elsif (@okoffload) {
12430: $changes{'offloadnow'} = 1;
12431: }
12432: } elsif (@okoffload) {
12433: $changes{'offloadnow'} = 1;
1.145 raeburn 12434: }
1.147 raeburn 12435: my $nochgmsg = &mt('No changes made to settings for user session hosting/offloading.');
12436: if ((keys(%changes) > 0) || ($savespares)) {
1.137 raeburn 12437: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
12438: $dom);
12439: if ($putresult eq 'ok') {
12440: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
12441: if (ref($defaultshash{'usersessions'}{'remote'}) eq 'HASH') {
12442: $domdefaults{'remotesessions'} = $defaultshash{'usersessions'}{'remote'};
12443: }
12444: if (ref($defaultshash{'usersessions'}{'hosted'}) eq 'HASH') {
12445: $domdefaults{'hostedsessions'} = $defaultshash{'usersessions'}{'hosted'};
12446: }
1.261 raeburn 12447: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
12448: $domdefaults{'offloadnow'} = $defaultshash{'usersessions'}{'offloadnow'};
12449: }
1.137 raeburn 12450: }
12451: my $cachetime = 24*60*60;
12452: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 12453: if (ref($lastactref) eq 'HASH') {
12454: $lastactref->{'domdefaults'} = 1;
12455: }
1.147 raeburn 12456: if (keys(%changes) > 0) {
12457: my %lt = &usersession_titles();
12458: $resulttext = &mt('Changes made:').'<ul>';
12459: foreach my $prefix (@prefixes) {
12460: if (ref($changes{$prefix}) eq 'HASH') {
12461: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
12462: if ($prefix eq 'spares') {
12463: if (ref($changes{$prefix}) eq 'HASH') {
12464: foreach my $lonhost (sort(keys(%{$changes{$prefix}}))) {
12465: $resulttext .= '<li><b>'.$lonhost.'</b> ';
1.148 raeburn 12466: my $lonhostdom = &Apache::lonnet::host_domain($lonhost);
1.211 raeburn 12467: my $cachekey = &escape('spares').':'.&escape($lonhostdom);
12468: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
1.147 raeburn 12469: if (ref($changes{$prefix}{$lonhost}) eq 'HASH') {
12470: foreach my $type (@{$types{$prefix}}) {
12471: if ($changes{$prefix}{$lonhost}{$type}) {
12472: my $offloadto = &mt('None');
12473: if (ref($defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}) eq 'ARRAY') {
12474: if (@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}} > 0) {
12475: $offloadto = join(', ',@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}});
12476: }
1.145 raeburn 12477: }
1.147 raeburn 12478: $resulttext .= &mt('[_1] set to: [_2].','<i>'.$lt{$type}.'</i>',$offloadto).(' 'x3);
1.145 raeburn 12479: }
1.137 raeburn 12480: }
12481: }
1.147 raeburn 12482: $resulttext .= '</li>';
1.137 raeburn 12483: }
12484: }
1.147 raeburn 12485: } else {
12486: foreach my $type (@{$types{$prefix}}) {
12487: if (defined($changes{$prefix}{$type})) {
12488: my $newvalue;
12489: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
12490: if (ref($defaultshash{'usersessions'}{$prefix})) {
12491: if ($type eq 'version') {
12492: $newvalue = $defaultshash{'usersessions'}{$prefix}{$type};
12493: } elsif (ref($defaultshash{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
12494: if (@{$defaultshash{'usersessions'}{$prefix}{$type}} > 0) {
12495: $newvalue = join(', ',@{$defaultshash{'usersessions'}{$prefix}{$type}});
12496: }
1.145 raeburn 12497: }
12498: }
12499: }
1.147 raeburn 12500: if ($newvalue eq '') {
12501: if ($type eq 'version') {
12502: $resulttext .= '<li>'.&mt('[_1] set to: off',$lt{$type}).'</li>';
12503: } else {
12504: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
12505: }
1.145 raeburn 12506: } else {
1.147 raeburn 12507: if ($type eq 'version') {
12508: $newvalue .= ' '.&mt('(or later)');
12509: }
12510: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
1.145 raeburn 12511: }
1.137 raeburn 12512: }
12513: }
12514: }
1.147 raeburn 12515: $resulttext .= '</ul>';
1.137 raeburn 12516: }
12517: }
1.261 raeburn 12518: if ($changes{'offloadnow'}) {
12519: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
12520: if (keys(%{$defaultshash{'usersessions'}{'offloadnow'}}) > 0) {
12521: $resulttext .= '<li>'.&mt('Switch active users on next access, for server(s):').'<ul>';
12522: foreach my $lonhost (sort(keys(%{$defaultshash{'usersessions'}{'offloadnow'}}))) {
12523: $resulttext .= '<li>'.$lonhost.'</li>';
12524: }
12525: $resulttext .= '</ul>';
12526: } else {
12527: $resulttext .= '<li>'.&mt('No servers now set to switch active users on next access.');
12528: }
12529: } else {
12530: $resulttext .= '<li>'.&mt('No servers now set to switch active users on next access.').'</li>';
12531: }
12532: }
1.147 raeburn 12533: $resulttext .= '</ul>';
12534: } else {
12535: $resulttext = $nochgmsg;
1.137 raeburn 12536: }
12537: } else {
12538: $resulttext = '<span class="LC_error">'.
12539: &mt('An error occurred: [_1]',$putresult).'</span>';
12540: }
12541: } else {
1.147 raeburn 12542: $resulttext = $nochgmsg;
1.137 raeburn 12543: }
12544: return $resulttext;
12545: }
12546:
1.275 ! raeburn 12547: sub modify_ssl {
! 12548: my ($dom,$lastactref,%domconfig) = @_;
! 12549: my (%by_ip,%by_location,@intdoms,@instdoms);
! 12550: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
! 12551: my @locations = sort(keys(%by_location));
! 12552: my %servers = &Apache::lonnet::internet_dom_servers($dom);
! 12553: my (%defaultshash,%changes);
! 12554: my $action = 'ssl';
! 12555: my @prefixes = ('connect','replication');
! 12556: foreach my $prefix (@prefixes) {
! 12557: $defaultshash{$action}{$prefix} = {};
! 12558: }
! 12559: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
! 12560: my $resulttext;
! 12561: my %iphost = &Apache::lonnet::get_iphost();
! 12562: my @reptypes = ('certreq','nocertreq');
! 12563: my @connecttypes = ('dom','intdom','other');
! 12564: my %types = (
! 12565: connect => \@connecttypes,
! 12566: replication => \@reptypes,
! 12567: );
! 12568: my $action = 'ssl';
! 12569: foreach my $prefix (sort(keys(%types))) {
! 12570: foreach my $type (@{$types{$prefix}}) {
! 12571: if ($prefix eq 'connect') {
! 12572: my $value = 'yes';
! 12573: if ($env{'form.'.$prefix.'_'.$type} =~ /^(no|req)$/) {
! 12574: $value = $env{'form.'.$prefix.'_'.$type};
! 12575: }
! 12576: if (ref($domconfig{$action}{$prefix}) eq 'HASH') {
! 12577: if ($domconfig{$action}{$prefix}{$type} ne '') {
! 12578: if ($value ne $domconfig{$action}{$prefix}{$type}) {
! 12579: $changes{$prefix}{$type} = 1;
! 12580: }
! 12581: $defaultshash{$action}{$prefix}{$type} = $value;
! 12582: } else {
! 12583: $defaultshash{$action}{$prefix}{$type} = $value;
! 12584: $changes{$prefix}{$type} = 1;
! 12585: }
! 12586: } else {
! 12587: $defaultshash{$action}{$prefix}{$type} = $value;
! 12588: $changes{$prefix}{$type} = 1;
! 12589: }
! 12590: if (($type eq 'dom') && (keys(%servers) == 1)) {
! 12591: delete($changes{$prefix}{$type});
! 12592: } elsif (($type eq 'intdom') && (@instdoms == 1)) {
! 12593: delete($changes{$prefix}{$type});
! 12594: } elsif (($type eq 'other') && (keys(%by_location) == 0)) {
! 12595: delete($changes{$prefix}{$type});
! 12596: }
! 12597: } elsif ($prefix eq 'replication') {
! 12598: if (@locations > 0) {
! 12599: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
! 12600: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
! 12601: my @okvals;
! 12602: foreach my $val (@vals) {
! 12603: if ($val =~ /:/) {
! 12604: my @items = split(/:/,$val);
! 12605: foreach my $item (@items) {
! 12606: if (ref($by_location{$item}) eq 'ARRAY') {
! 12607: push(@okvals,$item);
! 12608: }
! 12609: }
! 12610: } else {
! 12611: if (ref($by_location{$val}) eq 'ARRAY') {
! 12612: push(@okvals,$val);
! 12613: }
! 12614: }
! 12615: }
! 12616: @okvals = sort(@okvals);
! 12617: if (ref($domconfig{$action}) eq 'HASH') {
! 12618: if (ref($domconfig{$action}{$prefix}) eq 'HASH') {
! 12619: if (ref($domconfig{$action}{$prefix}{$type}) eq 'ARRAY') {
! 12620: if ($inuse == 0) {
! 12621: $changes{$prefix}{$type} = 1;
! 12622: } else {
! 12623: $defaultshash{$action}{$prefix}{$type} = \@okvals;
! 12624: my @changed = &Apache::loncommon::compare_arrays($domconfig{$action}{$prefix}{$type},$defaultshash{$action}{$prefix}{$type});
! 12625: if (@changed > 0) {
! 12626: $changes{$prefix}{$type} = 1;
! 12627: }
! 12628: }
! 12629: } else {
! 12630: if ($inuse == 1) {
! 12631: $defaultshash{$action}{$prefix}{$type} = \@okvals;
! 12632: $changes{$prefix}{$type} = 1;
! 12633: }
! 12634: }
! 12635: } else {
! 12636: if ($inuse == 1) {
! 12637: $defaultshash{$action}{$prefix}{$type} = \@okvals;
! 12638: $changes{$prefix}{$type} = 1;
! 12639: }
! 12640: }
! 12641: } else {
! 12642: if ($inuse == 1) {
! 12643: $defaultshash{$action}{$prefix}{$type} = \@okvals;
! 12644: $changes{$prefix}{$type} = 1;
! 12645: }
! 12646: }
! 12647: }
! 12648: }
! 12649: }
! 12650: }
! 12651: my $nochgmsg = &mt('No changes made to LON-CAPA SSL settings');
! 12652: if (keys(%changes) > 0) {
! 12653: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
! 12654: $dom);
! 12655: if ($putresult eq 'ok') {
! 12656: if (ref($defaultshash{$action}) eq 'HASH') {
! 12657: if (ref($defaultshash{$action}{'replication'}) eq 'HASH') {
! 12658: $domdefaults{'replication'} = $defaultshash{$action}{'replication'};
! 12659: }
! 12660: if (ref($defaultshash{$action}{'connect'}) eq 'HASH') {
! 12661: $domdefaults{'connect'} = $domconfig{$action}{'connect'};
! 12662: }
! 12663: }
! 12664: my $cachetime = 24*60*60;
! 12665: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
! 12666: if (ref($lastactref) eq 'HASH') {
! 12667: $lastactref->{'domdefaults'} = 1;
! 12668: }
! 12669: if (keys(%changes) > 0) {
! 12670: my %titles = &ssl_titles();
! 12671: $resulttext = &mt('Changes made:').'<ul>';
! 12672: foreach my $prefix (@prefixes) {
! 12673: if (ref($changes{$prefix}) eq 'HASH') {
! 12674: $resulttext .= '<li>'.$titles{$prefix}.'<ul>';
! 12675: foreach my $type (@{$types{$prefix}}) {
! 12676: if (defined($changes{$prefix}{$type})) {
! 12677: my $newvalue;
! 12678: if (ref($defaultshash{$action}) eq 'HASH') {
! 12679: if (ref($defaultshash{$action}{$prefix})) {
! 12680: if ($prefix eq 'connect') {
! 12681: $newvalue = $titles{$defaultshash{$action}{$prefix}{$type}};
! 12682: } elsif (ref($defaultshash{$action}{$prefix}{$type}) eq 'ARRAY') {
! 12683: if (@{$defaultshash{$action}{$prefix}{$type}} > 0) {
! 12684: $newvalue = join(', ',@{$defaultshash{$action}{$prefix}{$type}});
! 12685: }
! 12686: }
! 12687: }
! 12688: if ($newvalue eq '') {
! 12689: $resulttext .= '<li>'.&mt('[_1] set to: none',$titles{$type}).'</li>';
! 12690: } else {
! 12691: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$titles{$type},$newvalue).'</li>';
! 12692: }
! 12693: }
! 12694: }
! 12695: }
! 12696: $resulttext .= '</ul>';
! 12697: }
! 12698: }
! 12699: } else {
! 12700: $resulttext = $nochgmsg;
! 12701: }
! 12702: } else {
! 12703: $resulttext = '<span class="LC_error">'.
! 12704: &mt('An error occurred: [_1]',$putresult).'</span>';
! 12705: }
! 12706: } else {
! 12707: $resulttext = $nochgmsg;
! 12708: }
! 12709: return $resulttext;
! 12710: }
! 12711:
1.150 raeburn 12712: sub modify_loadbalancing {
12713: my ($dom,%domconfig) = @_;
12714: my $primary_id = &Apache::lonnet::domain($dom,'primary');
12715: my $intdom = &Apache::lonnet::internet_dom($primary_id);
12716: my ($othertitle,$usertypes,$types) =
12717: &Apache::loncommon::sorted_inst_types($dom);
12718: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.253 raeburn 12719: my %libraryservers = &Apache::lonnet::get_servers($dom,'library');
1.150 raeburn 12720: my @sparestypes = ('primary','default');
12721: my %typetitles = &sparestype_titles();
12722: my $resulttext;
1.171 raeburn 12723: my (%currbalancer,%currtargets,%currrules,%existing);
12724: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
12725: %existing = %{$domconfig{'loadbalancing'}};
12726: }
12727: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
12728: \%currtargets,\%currrules);
12729: my ($saveloadbalancing,%defaultshash,%changes);
12730: my ($alltypes,$othertypes,$titles) =
12731: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
12732: my %ruletitles = &offloadtype_text();
12733: my @deletions = &Apache::loncommon::get_env_multiple('form.loadbalancing_delete');
12734: for (my $i=0; $i<$env{'form.loadbalancing_total'}; $i++) {
12735: my $balancer = $env{'form.loadbalancing_lonhost_'.$i};
12736: if ($balancer eq '') {
12737: next;
12738: }
1.210 raeburn 12739: if (!exists($servers{$balancer})) {
1.171 raeburn 12740: if (exists($currbalancer{$balancer})) {
12741: push(@{$changes{'delete'}},$balancer);
1.150 raeburn 12742: }
1.171 raeburn 12743: next;
12744: }
12745: if ((@deletions > 0) && (grep(/^\Q$i\E$/,@deletions))) {
12746: push(@{$changes{'delete'}},$balancer);
12747: next;
12748: }
12749: if (!exists($currbalancer{$balancer})) {
12750: push(@{$changes{'add'}},$balancer);
12751: }
12752: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'} = [];
12753: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'default'} = [];
12754: $defaultshash{'loadbalancing'}{$balancer}{'rules'} = {};
12755: unless (ref($domconfig{'loadbalancing'}) eq 'HASH') {
12756: $saveloadbalancing = 1;
12757: }
12758: foreach my $sparetype (@sparestypes) {
12759: my @targets = &Apache::loncommon::get_env_multiple('form.loadbalancing_target_'.$i.'_'.$sparetype);
12760: my @offloadto;
12761: foreach my $target (@targets) {
12762: if (($servers{$target}) && ($target ne $balancer)) {
12763: if ($sparetype eq 'default') {
12764: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}) eq 'ARRAY') {
12765: next if (grep(/^\Q$target\E$/,@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}}));
1.150 raeburn 12766: }
12767: }
1.171 raeburn 12768: unless(grep(/^\Q$target\E$/,@offloadto)) {
12769: push(@offloadto,$target);
12770: }
1.150 raeburn 12771: }
1.171 raeburn 12772: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype} = \@offloadto;
1.150 raeburn 12773: }
12774: }
1.171 raeburn 12775: if (ref($currtargets{$balancer}) eq 'HASH') {
1.150 raeburn 12776: foreach my $sparetype (@sparestypes) {
1.171 raeburn 12777: if (ref($currtargets{$balancer}{$sparetype}) eq 'ARRAY') {
12778: my @targetdiffs = &Apache::loncommon::compare_arrays($currtargets{$balancer}{$sparetype},$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype});
1.150 raeburn 12779: if (@targetdiffs > 0) {
1.171 raeburn 12780: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 12781: }
1.171 raeburn 12782: } elsif (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
12783: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
12784: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 12785: }
12786: }
12787: }
12788: } else {
1.171 raeburn 12789: if (ref($defaultshash{'loadbalancing'}{$balancer}) eq 'HASH') {
1.210 raeburn 12790: foreach my $sparetype (@sparestypes) {
1.171 raeburn 12791: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
12792: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
12793: $changes{'curr'}{$balancer}{'targets'} = 1;
12794: }
1.150 raeburn 12795: }
12796: }
1.210 raeburn 12797: }
1.150 raeburn 12798: }
12799: my $ishomedom;
1.171 raeburn 12800: if (&Apache::lonnet::host_domain($balancer) eq $dom) {
12801: $ishomedom = 1;
1.150 raeburn 12802: }
12803: if (ref($alltypes) eq 'ARRAY') {
12804: foreach my $type (@{$alltypes}) {
12805: my $rule;
1.210 raeburn 12806: unless ((($type eq '_LC_external') || ($type eq '_LC_internetdom')) &&
1.150 raeburn 12807: (!$ishomedom)) {
1.171 raeburn 12808: $rule = $env{'form.loadbalancing_rules_'.$i.'_'.$type};
12809: }
12810: if ($rule eq 'specific') {
1.255 raeburn 12811: my $specifiedhost = $env{'form.loadbalancing_singleserver_'.$i.'_'.$type};
12812: if (exists($servers{$specifiedhost})) {
12813: $rule = $specifiedhost;
12814: }
1.150 raeburn 12815: }
1.171 raeburn 12816: $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type} = $rule;
12817: if (ref($currrules{$balancer}) eq 'HASH') {
12818: if ($rule ne $currrules{$balancer}{$type}) {
12819: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 12820: }
12821: } elsif ($rule ne '') {
1.171 raeburn 12822: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 12823: }
12824: }
12825: }
1.171 raeburn 12826: }
12827: my $nochgmsg = &mt('No changes made to Load Balancer settings.');
12828: if ((keys(%changes) > 0) || ($saveloadbalancing)) {
12829: unless (ref($defaultshash{'loadbalancing'}) eq 'HASH') {
12830: $defaultshash{'loadbalancing'} = {};
12831: }
12832: my $putresult = &Apache::lonnet::put_dom('configuration',
12833: \%defaultshash,$dom);
12834: if ($putresult eq 'ok') {
12835: if (keys(%changes) > 0) {
1.252 raeburn 12836: my %toupdate;
1.171 raeburn 12837: if (ref($changes{'delete'}) eq 'ARRAY') {
12838: foreach my $balancer (sort(@{$changes{'delete'}})) {
12839: $resulttext .= '<li>'.&mt('Load Balancing discontinued for: [_1]',$balancer).'</li>';
1.252 raeburn 12840: $toupdate{$balancer} = 1;
1.150 raeburn 12841: }
1.171 raeburn 12842: }
12843: if (ref($changes{'add'}) eq 'ARRAY') {
1.210 raeburn 12844: foreach my $balancer (sort(@{$changes{'add'}})) {
1.171 raeburn 12845: $resulttext .= '<li>'.&mt('Load Balancing enabled for: [_1]',$balancer);
1.252 raeburn 12846: $toupdate{$balancer} = 1;
1.171 raeburn 12847: }
12848: }
12849: if (ref($changes{'curr'}) eq 'HASH') {
12850: foreach my $balancer (sort(keys(%{$changes{'curr'}}))) {
1.253 raeburn 12851: $toupdate{$balancer} = 1;
1.171 raeburn 12852: if (ref($changes{'curr'}{$balancer}) eq 'HASH') {
12853: if ($changes{'curr'}{$balancer}{'targets'}) {
12854: my %offloadstr;
12855: foreach my $sparetype (@sparestypes) {
12856: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
12857: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
12858: $offloadstr{$sparetype} = join(', ',@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
12859: }
12860: }
1.150 raeburn 12861: }
1.171 raeburn 12862: if (keys(%offloadstr) == 0) {
12863: $resulttext .= '<li>'.&mt("Servers to which Load Balance server offloads set to 'None', by default").'</li>';
1.150 raeburn 12864: } else {
1.171 raeburn 12865: my $showoffload;
12866: foreach my $sparetype (@sparestypes) {
12867: $showoffload .= '<i>'.$typetitles{$sparetype}.'</i>: ';
12868: if (defined($offloadstr{$sparetype})) {
12869: $showoffload .= $offloadstr{$sparetype};
12870: } else {
12871: $showoffload .= &mt('None');
12872: }
12873: $showoffload .= (' 'x3);
12874: }
12875: $resulttext .= '<li>'.&mt('By default, Load Balancer: [_1] set to offload to - [_2]',$balancer,$showoffload).'</li>';
1.150 raeburn 12876: }
12877: }
12878: }
1.171 raeburn 12879: if (ref($changes{'curr'}{$balancer}{'rules'}) eq 'HASH') {
12880: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
12881: foreach my $type (@{$alltypes}) {
12882: if ($changes{'curr'}{$balancer}{'rules'}{$type}) {
12883: my $rule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
12884: my $balancetext;
12885: if ($rule eq '') {
12886: $balancetext = $ruletitles{'default'};
1.209 raeburn 12887: } elsif (($rule eq 'homeserver') || ($rule eq 'externalbalancer') ||
1.254 raeburn 12888: ($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
12889: if (($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
1.252 raeburn 12890: foreach my $sparetype (@sparestypes) {
12891: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
12892: map { $toupdate{$_} = 1; } (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
12893: }
12894: }
1.253 raeburn 12895: foreach my $item (@{$alltypes}) {
12896: next if ($item =~ /^_LC_ipchange/);
12897: my $hasrule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$item};
12898: if ($hasrule eq 'homeserver') {
12899: map { $toupdate{$_} = 1; } (keys(%libraryservers));
12900: } else {
12901: unless (($hasrule eq 'default') || ($hasrule eq 'none') || ($hasrule eq 'externalbalancer')) {
12902: if ($servers{$hasrule}) {
12903: $toupdate{$hasrule} = 1;
12904: }
12905: }
12906: }
12907: }
1.254 raeburn 12908: if (($rule eq 'balancer') || ($rule eq 'offloadedto')) {
12909: $balancetext = $ruletitles{$rule};
12910: } else {
12911: my $receiver = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
12912: $balancetext = $ruletitles{'particular'}.' '.$receiver;
12913: if ($receiver) {
12914: $toupdate{$receiver};
12915: }
12916: }
12917: } else {
12918: $balancetext = $ruletitles{$rule};
1.252 raeburn 12919: }
1.171 raeburn 12920: } else {
12921: $balancetext = &mt('offload to [_1]',$defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type});
12922: }
1.210 raeburn 12923: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- balancing for [_2] set to - "[_3]"',$balancer,$titles->{$type},$balancetext).'</li>';
1.150 raeburn 12924: }
12925: }
12926: }
12927: }
1.252 raeburn 12928: if (keys(%toupdate)) {
12929: my %thismachine;
12930: my $updatedhere;
12931: my $cachetime = 60*60*24;
12932: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
12933: foreach my $lonhost (keys(%toupdate)) {
12934: if ($thismachine{$lonhost}) {
12935: unless ($updatedhere) {
12936: &Apache::lonnet::do_cache_new('loadbalancing',$dom,
12937: $defaultshash{'loadbalancing'},
12938: $cachetime);
12939: $updatedhere = 1;
12940: }
12941: } else {
12942: my $cachekey = &escape('loadbalancing').':'.&escape($dom);
12943: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
12944: }
12945: }
12946: }
1.150 raeburn 12947: }
1.171 raeburn 12948: }
12949: if ($resulttext ne '') {
12950: $resulttext = &mt('Changes made:').'<ul>'.$resulttext.'</ul>';
1.150 raeburn 12951: } else {
12952: $resulttext = $nochgmsg;
12953: }
12954: } else {
1.171 raeburn 12955: $resulttext = $nochgmsg;
1.150 raeburn 12956: }
12957: } else {
1.171 raeburn 12958: $resulttext = '<span class="LC_error">'.
12959: &mt('An error occurred: [_1]',$putresult).'</span>';
1.150 raeburn 12960: }
12961: } else {
1.171 raeburn 12962: $resulttext = $nochgmsg;
1.150 raeburn 12963: }
12964: return $resulttext;
12965: }
12966:
1.48 raeburn 12967: sub recurse_check {
12968: my ($chkcats,$categories,$depth,$name) = @_;
12969: if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
12970: my $chg = 0;
12971: for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
12972: my $category = $chkcats->[$depth]{$name}[$j];
12973: my $item;
12974: if ($category eq '') {
12975: $chg ++;
12976: } else {
12977: my $deeper = $depth + 1;
12978: $item = &escape($category).':'.&escape($name).':'.$depth;
12979: if ($chg) {
12980: $categories->{$item} -= $chg;
12981: }
12982: &recurse_check($chkcats,$categories,$deeper,$category);
12983: $deeper --;
12984: }
12985: }
12986: }
12987: return;
12988: }
12989:
12990: sub recurse_cat_deletes {
12991: my ($item,$coursecategories,$deletions) = @_;
12992: my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
12993: my $subdepth = $depth + 1;
12994: if (ref($coursecategories) eq 'HASH') {
12995: foreach my $subitem (keys(%{$coursecategories})) {
12996: my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
12997: if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
12998: delete($coursecategories->{$subitem});
12999: $deletions->{$subitem} = 1;
13000: &recurse_cat_deletes($subitem,$coursecategories,$deletions);
1.168 raeburn 13001: }
1.48 raeburn 13002: }
13003: }
13004: return;
13005: }
13006:
1.125 raeburn 13007: sub get_active_dcs {
13008: my ($dom) = @_;
1.191 raeburn 13009: my $now = time;
13010: my %dompersonnel = &Apache::lonnet::get_domain_roles($dom,['dc'],$now,$now);
1.125 raeburn 13011: my %domcoords;
13012: my $numdcs = 0;
13013: foreach my $server (keys(%dompersonnel)) {
13014: foreach my $user (sort(keys(%{$dompersonnel{$server}}))) {
13015: my ($trole,$uname,$udom,$runame,$rudom,$rsec) = split(/:/,$user);
1.191 raeburn 13016: $domcoords{$uname.':'.$udom} = $dompersonnel{$server}{$user};
1.125 raeburn 13017: }
13018: }
13019: return %domcoords;
13020: }
13021:
13022: sub active_dc_picker {
1.191 raeburn 13023: my ($dom,$numinrow,$inputtype,$name,%currhash) = @_;
1.235 raeburn 13024: my %domcoords = &get_active_dcs($dom);
1.191 raeburn 13025: my @domcoord = keys(%domcoords);
13026: if (keys(%currhash)) {
13027: foreach my $dc (keys(%currhash)) {
13028: unless (exists($domcoords{$dc})) {
13029: push(@domcoord,$dc);
13030: }
13031: }
13032: }
13033: @domcoord = sort(@domcoord);
1.210 raeburn 13034: my $numdcs = scalar(@domcoord);
1.191 raeburn 13035: my $rows = 0;
13036: my $table;
1.125 raeburn 13037: if ($numdcs > 1) {
1.191 raeburn 13038: $table = '<table>';
13039: for (my $i=0; $i<@domcoord; $i++) {
1.125 raeburn 13040: my $rem = $i%($numinrow);
13041: if ($rem == 0) {
13042: if ($i > 0) {
1.191 raeburn 13043: $table .= '</tr>';
1.125 raeburn 13044: }
1.191 raeburn 13045: $table .= '<tr>';
13046: $rows ++;
1.125 raeburn 13047: }
1.191 raeburn 13048: my $check = '';
13049: if ($inputtype eq 'radio') {
13050: if (keys(%currhash) == 0) {
13051: if (!$i) {
13052: $check = ' checked="checked"';
13053: }
13054: } elsif (exists($currhash{$domcoord[$i]})) {
13055: $check = ' checked="checked"';
13056: }
13057: } else {
13058: if (exists($currhash{$domcoord[$i]})) {
13059: $check = ' checked="checked"';
1.125 raeburn 13060: }
13061: }
1.191 raeburn 13062: if ($i == @domcoord - 1) {
1.125 raeburn 13063: my $colsleft = $numinrow - $rem;
13064: if ($colsleft > 1) {
1.191 raeburn 13065: $table .= '<td class="LC_left_item" colspan="'.$colsleft.'">';
1.125 raeburn 13066: } else {
1.191 raeburn 13067: $table .= '<td class="LC_left_item">';
1.125 raeburn 13068: }
13069: } else {
1.191 raeburn 13070: $table .= '<td class="LC_left_item">';
13071: }
13072: my ($dcname,$dcdom) = split(':',$domcoord[$i]);
13073: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
13074: $table .= '<span class="LC_nobreak"><label>'.
13075: '<input type="'.$inputtype.'" name="'.$name.'"'.
13076: ' value="'.$domcoord[$i].'"'.$check.' />'.$user;
13077: if ($user ne $dcname.':'.$dcdom) {
1.219 raeburn 13078: $table .= ' ('.$dcname.':'.$dcdom.')';
1.191 raeburn 13079: }
1.219 raeburn 13080: $table .= '</label></span></td>';
1.191 raeburn 13081: }
13082: $table .= '</tr></table>';
13083: } elsif ($numdcs == 1) {
1.219 raeburn 13084: my ($dcname,$dcdom) = split(':',$domcoord[0]);
13085: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
1.191 raeburn 13086: if ($inputtype eq 'radio') {
1.247 raeburn 13087: $table = '<input type="hidden" name="'.$name.'" value="'.$domcoord[0].'" />'.$user;
1.219 raeburn 13088: if ($user ne $dcname.':'.$dcdom) {
13089: $table .= ' ('.$dcname.':'.$dcdom.')';
13090: }
1.191 raeburn 13091: } else {
13092: my $check;
13093: if (exists($currhash{$domcoord[0]})) {
13094: $check = ' checked="checked"';
1.125 raeburn 13095: }
1.247 raeburn 13096: $table = '<span class="LC_nobreak"><label>'.
13097: '<input type="checkbox" name="'.$name.'" '.
13098: 'value="'.$domcoord[0].'"'.$check.' />'.$user;
1.219 raeburn 13099: if ($user ne $dcname.':'.$dcdom) {
1.220 raeburn 13100: $table .= ' ('.$dcname.':'.$dcdom.')';
1.219 raeburn 13101: }
1.220 raeburn 13102: $table .= '</label></span>';
1.191 raeburn 13103: $rows ++;
1.125 raeburn 13104: }
13105: }
1.191 raeburn 13106: return ($numdcs,$table,$rows);
1.125 raeburn 13107: }
13108:
1.137 raeburn 13109: sub usersession_titles {
13110: return &Apache::lonlocal::texthash(
13111: hosted => 'Hosting of sessions for users from other domains on servers in this domain',
13112: remote => 'Hosting of sessions for users in this domain on servers in other domains',
1.145 raeburn 13113: spares => 'Servers offloaded to, when busy',
1.137 raeburn 13114: version => 'LON-CAPA version requirement',
1.138 raeburn 13115: excludedomain => 'Allow all, but exclude specific domains',
13116: includedomain => 'Deny all, but include specific domains',
1.145 raeburn 13117: primary => 'Primary (checked first)',
1.154 raeburn 13118: default => 'Default',
1.137 raeburn 13119: );
13120: }
13121:
1.152 raeburn 13122: sub id_for_thisdom {
13123: my (%servers) = @_;
13124: my %altids;
13125: foreach my $server (keys(%servers)) {
13126: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
13127: if ($serverhome ne $server) {
13128: $altids{$serverhome} = $server;
13129: }
13130: }
13131: return %altids;
13132: }
13133:
1.150 raeburn 13134: sub count_servers {
13135: my ($currbalancer,%servers) = @_;
13136: my (@spares,$numspares);
13137: foreach my $lonhost (sort(keys(%servers))) {
13138: next if ($currbalancer eq $lonhost);
13139: push(@spares,$lonhost);
13140: }
13141: if ($currbalancer) {
13142: $numspares = scalar(@spares);
13143: } else {
13144: $numspares = scalar(@spares) - 1;
13145: }
13146: return ($numspares,@spares);
13147: }
13148:
13149: sub lonbalance_targets_js {
1.171 raeburn 13150: my ($dom,$types,$servers,$settings) = @_;
1.150 raeburn 13151: my $select = &mt('Select');
13152: my ($alltargets,$allishome,$allinsttypes,@alltypes);
13153: if (ref($servers) eq 'HASH') {
13154: $alltargets = join("','",sort(keys(%{$servers})));
13155: my @homedoms;
13156: foreach my $server (sort(keys(%{$servers}))) {
13157: if (&Apache::lonnet::host_domain($server) eq $dom) {
13158: push(@homedoms,'1');
13159: } else {
13160: push(@homedoms,'0');
13161: }
13162: }
13163: $allishome = join("','",@homedoms);
13164: }
13165: if (ref($types) eq 'ARRAY') {
13166: if (@{$types} > 0) {
13167: @alltypes = @{$types};
13168: }
13169: }
13170: push(@alltypes,'default','_LC_adv','_LC_author','_LC_internetdom','_LC_external');
13171: $allinsttypes = join("','",@alltypes);
1.171 raeburn 13172: my (%currbalancer,%currtargets,%currrules,%existing);
13173: if (ref($settings) eq 'HASH') {
13174: %existing = %{$settings};
13175: }
13176: &get_loadbalancers_config($servers,\%existing,\%currbalancer,
13177: \%currtargets,\%currrules);
1.210 raeburn 13178: my $balancers = join("','",sort(keys(%currbalancer)));
1.150 raeburn 13179: return <<"END";
13180:
13181: <script type="text/javascript">
13182: // <![CDATA[
13183:
1.171 raeburn 13184: currBalancers = new Array('$balancers');
13185:
13186: function toggleTargets(balnum) {
13187: var lonhostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
13188: var prevhostitem = document.getElementById('loadbalancing_prevlonhost_'+balnum);
13189: var balancer = lonhostitem.options[lonhostitem.selectedIndex].value;
13190: var prevbalancer = prevhostitem.value;
13191: var baltotal = document.getElementById('loadbalancing_total').value;
13192: prevhostitem.value = balancer;
13193: if (prevbalancer != '') {
13194: var prevIdx = currBalancers.indexOf(prevbalancer);
13195: if (prevIdx != -1) {
13196: currBalancers.splice(prevIdx,1);
13197: }
13198: }
1.150 raeburn 13199: if (balancer == '') {
1.171 raeburn 13200: hideSpares(balnum);
1.150 raeburn 13201: } else {
1.171 raeburn 13202: var currIdx = currBalancers.indexOf(balancer);
13203: if (currIdx == -1) {
13204: currBalancers.push(balancer);
13205: }
1.150 raeburn 13206: var homedoms = new Array('$allishome');
1.171 raeburn 13207: var ishomedom = homedoms[lonhostitem.selectedIndex];
13208: showSpares(balancer,ishomedom,balnum);
1.150 raeburn 13209: }
1.171 raeburn 13210: balancerChange(balnum,baltotal,'change',prevbalancer,balancer);
1.150 raeburn 13211: return;
13212: }
13213:
1.171 raeburn 13214: function showSpares(balancer,ishomedom,balnum) {
1.150 raeburn 13215: var alltargets = new Array('$alltargets');
13216: var insttypes = new Array('$allinsttypes');
1.151 raeburn 13217: var offloadtypes = new Array('primary','default');
13218:
1.171 raeburn 13219: document.getElementById('loadbalancing_targets_'+balnum).style.display='block';
13220: document.getElementById('loadbalancing_disabled_'+balnum).style.display='none';
1.152 raeburn 13221:
1.151 raeburn 13222: for (var i=0; i<offloadtypes.length; i++) {
13223: var count = 0;
13224: for (var j=0; j<alltargets.length; j++) {
13225: if (alltargets[j] != balancer) {
1.171 raeburn 13226: var item = document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+count);
13227: item.value = alltargets[j];
13228: item.style.textAlign='left';
13229: item.style.textFace='normal';
13230: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+count).innerHTML = alltargets[j];
13231: if (currBalancers.indexOf(alltargets[j]) == -1) {
13232: item.disabled = '';
13233: } else {
13234: item.disabled = 'disabled';
13235: item.checked = false;
13236: }
1.151 raeburn 13237: count ++;
13238: }
1.150 raeburn 13239: }
13240: }
1.151 raeburn 13241: for (var k=0; k<insttypes.length; k++) {
13242: if ((insttypes[k] == '_LC_external') || (insttypes[k] == '_LC_internetdom')) {
1.150 raeburn 13243: if (ishomedom == 1) {
1.171 raeburn 13244: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
13245: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 13246: } else {
1.171 raeburn 13247: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
13248: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.150 raeburn 13249: }
13250: } else {
1.171 raeburn 13251: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
13252: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 13253: }
1.151 raeburn 13254: if ((insttypes[k] != '_LC_external') &&
13255: ((insttypes[k] != '_LC_internetdom') ||
13256: ((insttypes[k] == '_LC_internetdom') && (ishomedom == 1)))) {
1.171 raeburn 13257: var item = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]);
13258: item.options.length = 0;
13259: item.options[0] = new Option("","",true,true);
1.210 raeburn 13260: var idx = 0;
1.151 raeburn 13261: for (var m=0; m<alltargets.length; m++) {
1.171 raeburn 13262: if ((currBalancers.indexOf(alltargets[m]) == -1) && (alltargets[m] != balancer)) {
13263: idx ++;
13264: item.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
1.150 raeburn 13265: }
13266: }
13267: }
13268: }
13269: return;
13270: }
13271:
1.171 raeburn 13272: function hideSpares(balnum) {
1.150 raeburn 13273: var alltargets = new Array('$alltargets');
13274: var insttypes = new Array('$allinsttypes');
13275: var offloadtypes = new Array('primary','default');
13276:
1.171 raeburn 13277: document.getElementById('loadbalancing_targets_'+balnum).style.display='none';
13278: document.getElementById('loadbalancing_disabled_'+balnum).style.display='block';
1.150 raeburn 13279:
13280: var total = alltargets.length - 1;
13281: for (var i=0; i<offloadtypes; i++) {
13282: for (var j=0; j<total; j++) {
1.171 raeburn 13283: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).checked = false;
13284: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).value = '';
13285: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+j).innerHTML = '';
1.151 raeburn 13286: }
1.150 raeburn 13287: }
13288: for (var k=0; k<insttypes.length; k++) {
1.171 raeburn 13289: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
13290: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.151 raeburn 13291: if (insttypes[k] != '_LC_external') {
1.171 raeburn 13292: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).length = 0;
13293: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).options[0] = new Option("","",true,true);
1.150 raeburn 13294: }
13295: }
13296: return;
13297: }
13298:
1.171 raeburn 13299: function checkOffloads(item,balnum,type) {
1.150 raeburn 13300: var alltargets = new Array('$alltargets');
13301: var offloadtypes = new Array('primary','default');
13302: if (item.checked) {
13303: var total = alltargets.length - 1;
13304: var other;
13305: if (type == offloadtypes[0]) {
1.151 raeburn 13306: other = offloadtypes[1];
1.150 raeburn 13307: } else {
1.151 raeburn 13308: other = offloadtypes[0];
1.150 raeburn 13309: }
13310: for (var i=0; i<total; i++) {
1.171 raeburn 13311: var server = document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).value;
1.150 raeburn 13312: if (server == item.value) {
1.171 raeburn 13313: if (document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked) {
13314: document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked = false;
1.150 raeburn 13315: }
13316: }
13317: }
13318: }
13319: return;
13320: }
13321:
1.171 raeburn 13322: function singleServerToggle(balnum,type) {
13323: var offloadtoSelIdx = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex;
1.150 raeburn 13324: if (offloadtoSelIdx == 0) {
1.171 raeburn 13325: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_0').checked = true;
13326: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 13327:
13328: } else {
1.171 raeburn 13329: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_2').checked = true;
13330: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
1.150 raeburn 13331: }
13332: return;
13333: }
13334:
1.171 raeburn 13335: function balanceruleChange(formname,balnum,type) {
1.150 raeburn 13336: if (type == '_LC_external') {
1.171 raeburn 13337: return;
1.150 raeburn 13338: }
1.171 raeburn 13339: var typesRules = getIndicesByName(formname,'loadbalancing_rules_'+balnum+'_'+type);
1.150 raeburn 13340: for (var i=0; i<typesRules.length; i++) {
13341: if (formname.elements[typesRules[i]].checked) {
13342: if (formname.elements[typesRules[i]].value != 'specific') {
1.171 raeburn 13343: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex = 0;
13344: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 13345: } else {
1.171 raeburn 13346: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
13347: }
13348: }
13349: }
13350: return;
13351: }
13352:
13353: function balancerDeleteChange(balnum) {
13354: var hostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
13355: var baltotal = document.getElementById('loadbalancing_total').value;
13356: var addtarget;
13357: var removetarget;
13358: var action = 'delete';
13359: if (document.getElementById('loadbalancing_delete_'+balnum)) {
13360: var lonhost = hostitem.value;
13361: var currIdx = currBalancers.indexOf(lonhost);
13362: if (document.getElementById('loadbalancing_delete_'+balnum).checked) {
13363: if (currIdx != -1) {
13364: currBalancers.splice(currIdx,1);
13365: }
13366: addtarget = lonhost;
13367: } else {
13368: if (currIdx == -1) {
13369: currBalancers.push(lonhost);
13370: }
13371: removetarget = lonhost;
13372: action = 'undelete';
13373: }
13374: balancerChange(balnum,baltotal,action,addtarget,removetarget);
13375: }
13376: return;
13377: }
13378:
13379: function balancerChange(balnum,baltotal,action,addtarget,removetarget) {
13380: if (baltotal > 1) {
13381: var offloadtypes = new Array('primary','default');
13382: var alltargets = new Array('$alltargets');
13383: var insttypes = new Array('$allinsttypes');
13384: for (var i=0; i<baltotal; i++) {
13385: if (i != balnum) {
13386: for (var j=0; j<offloadtypes.length; j++) {
13387: var total = alltargets.length - 1;
13388: for (var k=0; k<total; k++) {
13389: var serveritem = document.getElementById('loadbalancing_target_'+i+'_'+offloadtypes[j]+'_'+k);
13390: var server = serveritem.value;
13391: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
13392: if (server == addtarget) {
13393: serveritem.disabled = '';
13394: }
13395: }
13396: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
13397: if (server == removetarget) {
13398: serveritem.disabled = 'disabled';
13399: serveritem.checked = false;
13400: }
13401: }
13402: }
13403: }
13404: for (var j=0; j<insttypes.length; j++) {
13405: if (insttypes[j] != '_LC_external') {
13406: if (document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j])) {
13407: var singleserver = document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j]);
13408: var currSel = singleserver.selectedIndex;
13409: var currVal = singleserver.options[currSel].value;
13410: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
13411: var numoptions = singleserver.options.length;
13412: var needsnew = 1;
13413: for (var k=0; k<numoptions; k++) {
13414: if (singleserver.options[k] == addtarget) {
13415: needsnew = 0;
13416: break;
13417: }
13418: }
13419: if (needsnew == 1) {
13420: singleserver.options[numoptions] = new Option(addtarget,addtarget,false,false);
13421: }
13422: }
13423: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
13424: singleserver.options.length = 0;
13425: if ((currVal) && (currVal != removetarget)) {
13426: singleserver.options[0] = new Option("","",false,false);
13427: } else {
13428: singleserver.options[0] = new Option("","",true,true);
13429: }
13430: var idx = 0;
13431: for (var m=0; m<alltargets.length; m++) {
13432: if (currBalancers.indexOf(alltargets[m]) == -1) {
13433: idx ++;
13434: if (currVal == alltargets[m]) {
13435: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],true,true);
13436: } else {
13437: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
13438: }
13439: }
13440: }
13441: }
13442: }
13443: }
13444: }
1.150 raeburn 13445: }
13446: }
13447: }
13448: return;
13449: }
13450:
1.152 raeburn 13451: // ]]>
13452: </script>
13453:
13454: END
13455: }
13456:
13457: sub new_spares_js {
13458: my @sparestypes = ('primary','default');
13459: my $types = join("','",@sparestypes);
13460: my $select = &mt('Select');
13461: return <<"END";
13462:
13463: <script type="text/javascript">
13464: // <![CDATA[
13465:
13466: function updateNewSpares(formname,lonhost) {
13467: var types = new Array('$types');
13468: var include = new Array();
13469: var exclude = new Array();
13470: for (var i=0; i<types.length; i++) {
13471: var spareboxes = getIndicesByName(formname,'spare_'+types[i]+'_'+lonhost);
13472: for (var j=0; j<spareboxes.length; j++) {
13473: if (formname.elements[spareboxes[j]].checked) {
13474: exclude.push(formname.elements[spareboxes[j]].value);
13475: } else {
13476: include.push(formname.elements[spareboxes[j]].value);
13477: }
13478: }
13479: }
13480: for (var i=0; i<types.length; i++) {
13481: var newSpare = document.getElementById('newspare_'+types[i]+'_'+lonhost);
13482: var selIdx = newSpare.selectedIndex;
13483: var currnew = newSpare.options[selIdx].value;
13484: var okSpares = new Array();
13485: for (var j=0; j<newSpare.options.length; j++) {
13486: var possible = newSpare.options[j].value;
13487: if (possible != '') {
13488: if (exclude.indexOf(possible) == -1) {
13489: okSpares.push(possible);
13490: } else {
13491: if (currnew == possible) {
13492: selIdx = 0;
13493: }
13494: }
13495: }
13496: }
13497: for (var k=0; k<include.length; k++) {
13498: if (okSpares.indexOf(include[k]) == -1) {
13499: okSpares.push(include[k]);
13500: }
13501: }
13502: okSpares.sort();
13503: newSpare.options.length = 0;
13504: if (selIdx == 0) {
13505: newSpare.options[0] = new Option("$select","",true,true);
13506: } else {
13507: newSpare.options[0] = new Option("$select","",false,false);
13508: }
13509: for (var m=0; m<okSpares.length; m++) {
13510: var idx = m+1;
13511: var selThis = 0;
13512: if (selIdx != 0) {
13513: if (okSpares[m] == currnew) {
13514: selThis = 1;
13515: }
13516: }
13517: if (selThis == 1) {
13518: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],true,true);
13519: } else {
13520: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],false,false);
13521: }
13522: }
13523: }
13524: return;
13525: }
13526:
13527: function checkNewSpares(lonhost,type) {
13528: var newSpare = document.getElementById('newspare_'+type+'_'+lonhost);
13529: var chosen = newSpare.options[newSpare.selectedIndex].value;
13530: if (chosen != '') {
13531: var othertype;
13532: var othernewSpare;
13533: if (type == 'primary') {
13534: othernewSpare = document.getElementById('newspare_default_'+lonhost);
13535: }
13536: if (type == 'default') {
13537: othernewSpare = document.getElementById('newspare_primary_'+lonhost);
13538: }
13539: if (othernewSpare.options[othernewSpare.selectedIndex].value == chosen) {
13540: othernewSpare.selectedIndex = 0;
13541: }
13542: }
13543: return;
13544: }
13545:
13546: // ]]>
13547: </script>
13548:
13549: END
13550:
13551: }
13552:
13553: sub common_domprefs_js {
13554: return <<"END";
13555:
13556: <script type="text/javascript">
13557: // <![CDATA[
13558:
1.150 raeburn 13559: function getIndicesByName(formname,item) {
1.152 raeburn 13560: var group = new Array();
1.150 raeburn 13561: for (var i=0;i<formname.elements.length;i++) {
13562: if (formname.elements[i].name == item) {
1.152 raeburn 13563: group.push(formname.elements[i].id);
1.150 raeburn 13564: }
13565: }
1.152 raeburn 13566: return group;
1.150 raeburn 13567: }
13568:
13569: // ]]>
13570: </script>
13571:
13572: END
1.152 raeburn 13573:
1.150 raeburn 13574: }
13575:
1.165 raeburn 13576: sub recaptcha_js {
13577: my %lt = &captcha_phrases();
13578: return <<"END";
13579:
13580: <script type="text/javascript">
13581: // <![CDATA[
13582:
13583: function updateCaptcha(caller,context) {
13584: var privitem;
13585: var pubitem;
13586: var privtext;
13587: var pubtext;
1.269 raeburn 13588: var versionitem;
13589: var versiontext;
1.165 raeburn 13590: if (document.getElementById(context+'_recaptchapub')) {
13591: pubitem = document.getElementById(context+'_recaptchapub');
13592: } else {
13593: return;
13594: }
13595: if (document.getElementById(context+'_recaptchapriv')) {
13596: privitem = document.getElementById(context+'_recaptchapriv');
13597: } else {
13598: return;
13599: }
13600: if (document.getElementById(context+'_recaptchapubtxt')) {
13601: pubtext = document.getElementById(context+'_recaptchapubtxt');
13602: } else {
13603: return;
13604: }
13605: if (document.getElementById(context+'_recaptchaprivtxt')) {
13606: privtext = document.getElementById(context+'_recaptchaprivtxt');
13607: } else {
13608: return;
13609: }
1.269 raeburn 13610: if (document.getElementById(context+'_recaptchaversion')) {
13611: versionitem = document.getElementById(context+'_recaptchaversion');
13612: } else {
13613: return;
13614: }
13615: if (document.getElementById(context+'_recaptchavertxt')) {
13616: versiontext = document.getElementById(context+'_recaptchavertxt');
13617: } else {
13618: return;
13619: }
1.165 raeburn 13620: if (caller.checked) {
13621: if (caller.value == 'recaptcha') {
13622: pubitem.type = 'text';
13623: privitem.type = 'text';
13624: pubitem.size = '40';
13625: privitem.size = '40';
13626: pubtext.innerHTML = "$lt{'pub'}";
13627: privtext.innerHTML = "$lt{'priv'}";
1.269 raeburn 13628: versionitem.type = 'text';
13629: versionitem.size = '3';
13630: versiontext.innerHTML = "$lt{'ver'}";
1.165 raeburn 13631: } else {
13632: pubitem.type = 'hidden';
13633: privitem.type = 'hidden';
1.269 raeburn 13634: versionitem.type = 'hidden';
1.165 raeburn 13635: pubtext.innerHTML = '';
13636: privtext.innerHTML = '';
1.269 raeburn 13637: versiontext.innerHTML = '';
1.165 raeburn 13638: }
13639: }
13640: return;
13641: }
13642:
13643: // ]]>
13644: </script>
13645:
13646: END
13647:
13648: }
13649:
1.236 raeburn 13650: sub toggle_display_js {
1.192 raeburn 13651: return <<"END";
13652:
13653: <script type="text/javascript">
13654: // <![CDATA[
13655:
1.236 raeburn 13656: function toggleDisplay(domForm,caller) {
13657: if (document.getElementById(caller)) {
13658: var divitem = document.getElementById(caller);
13659: var optionsElement = domForm.coursecredits;
1.264 raeburn 13660: var checkval = 1;
13661: var dispval = 'block';
1.236 raeburn 13662: if (caller == 'emailoptions') {
13663: optionsElement = domForm.cancreate_email;
13664: }
1.257 raeburn 13665: if (caller == 'studentsubmission') {
13666: optionsElement = domForm.postsubmit;
13667: }
1.264 raeburn 13668: if (caller == 'cloneinstcode') {
13669: optionsElement = domForm.canclone;
13670: checkval = 'instcode';
13671: }
1.236 raeburn 13672: if (optionsElement.length) {
1.192 raeburn 13673: var currval;
1.236 raeburn 13674: for (var i=0; i<optionsElement.length; i++) {
13675: if (optionsElement[i].checked) {
13676: currval = optionsElement[i].value;
1.192 raeburn 13677: }
13678: }
1.264 raeburn 13679: if (currval == checkval) {
13680: divitem.style.display = dispval;
1.192 raeburn 13681: } else {
1.236 raeburn 13682: divitem.style.display = 'none';
1.192 raeburn 13683: }
13684: }
13685: }
13686: return;
13687: }
13688:
13689: // ]]>
13690: </script>
13691:
13692: END
13693:
13694: }
13695:
1.165 raeburn 13696: sub captcha_phrases {
13697: return &Apache::lonlocal::texthash (
13698: priv => 'Private key',
13699: pub => 'Public key',
13700: original => 'original (CAPTCHA)',
13701: recaptcha => 'successor (ReCAPTCHA)',
13702: notused => 'unused',
1.269 raeburn 13703: ver => 'ReCAPTCHA version (1 or 2)',
1.165 raeburn 13704: );
13705: }
13706:
1.205 raeburn 13707: sub devalidate_remote_domconfs {
1.212 raeburn 13708: my ($dom,$cachekeys) = @_;
13709: return unless (ref($cachekeys) eq 'HASH');
1.205 raeburn 13710: my %servers = &Apache::lonnet::internet_dom_servers($dom);
13711: my %thismachine;
13712: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
1.267 raeburn 13713: my @posscached = ('domainconfig','domdefaults','ltitools');
1.260 raeburn 13714: if (keys(%servers)) {
1.205 raeburn 13715: foreach my $server (keys(%servers)) {
13716: next if ($thismachine{$server});
1.212 raeburn 13717: my @cached;
13718: foreach my $name (@posscached) {
13719: if ($cachekeys->{$name}) {
13720: push(@cached,&escape($name).':'.&escape($dom));
13721: }
13722: }
13723: if (@cached) {
13724: &Apache::lonnet::remote_devalidate_cache($server,\@cached);
13725: }
1.205 raeburn 13726: }
13727: }
13728: return;
13729: }
13730:
1.3 raeburn 13731: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>