Annotation of loncom/interface/domainprefs.pm, revision 1.230
1.1 raeburn 1: # The LearningOnline Network with CAPA
2: # Handler to set domain-wide configuration settings
3: #
1.230 ! raeburn 4: # $Id: domainprefs.pm,v 1.229 2014/03/17 02:36:56 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.216 raeburn 106: (official, unofficial, community, and textbook). In each case the radio buttons
107: 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.69 raeburn 167: use LONCAPA qw(:DEFAULT :match);
1.6 raeburn 168: use LONCAPA::Enrollment;
1.81 raeburn 169: use LONCAPA::lonauthcgi();
1.9 raeburn 170: use File::Copy;
1.43 raeburn 171: use Locale::Language;
1.62 raeburn 172: use DateTime::TimeZone;
1.68 raeburn 173: use DateTime::Locale;
1.1 raeburn 174:
1.155 raeburn 175: my $registered_cleanup;
176: my $modified_urls;
177:
1.1 raeburn 178: sub handler {
179: my $r=shift;
180: if ($r->header_only) {
181: &Apache::loncommon::content_type($r,'text/html');
182: $r->send_http_header;
183: return OK;
184: }
185:
1.91 raeburn 186: my $context = 'domain';
1.1 raeburn 187: my $dom = $env{'request.role.domain'};
1.5 albertel 188: my $domdesc = &Apache::lonnet::domain($dom,'description');
1.1 raeburn 189: if (&Apache::lonnet::allowed('mau',$dom)) {
190: &Apache::loncommon::content_type($r,'text/html');
191: $r->send_http_header;
192: } else {
193: $env{'user.error.msg'}=
194: "/adm/domainprefs:mau:0:0:Cannot modify domain settings";
195: return HTTP_NOT_ACCEPTABLE;
196: }
1.155 raeburn 197:
198: $registered_cleanup=0;
199: @{$modified_urls}=();
200:
1.1 raeburn 201: &Apache::lonhtmlcommon::clear_breadcrumbs();
202: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.58 raeburn 203: ['phase','actions']);
1.30 raeburn 204: my $phase = 'pickactions';
1.3 raeburn 205: if ( exists($env{'form.phase'}) ) {
206: $phase = $env{'form.phase'};
207: }
1.150 raeburn 208: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.3 raeburn 209: my %domconfig =
1.6 raeburn 210: &Apache::lonnet::get_dom('configuration',['login','rolecolors',
1.125 raeburn 211: 'quotas','autoenroll','autoupdate','autocreate',
212: 'directorysrch','usercreation','usermodification',
213: 'contacts','defaults','scantron','coursecategories',
214: 'serverstatuses','requestcourses','helpsettings',
1.163 raeburn 215: 'coursedefaults','usersessions','loadbalancing',
216: 'requestauthor'],$dom);
1.43 raeburn 217: my @prefs_order = ('rolecolors','login','defaults','quotas','autoenroll',
1.125 raeburn 218: 'autoupdate','autocreate','directorysrch','contacts',
1.224 raeburn 219: 'usercreation','selfcreation','usermodification','scantron',
1.163 raeburn 220: 'requestcourses','requestauthor','coursecategories',
221: 'serverstatuses','helpsettings',
1.137 raeburn 222: 'coursedefaults','usersessions');
1.171 raeburn 223: my %existing;
224: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
225: %existing = %{$domconfig{'loadbalancing'}};
226: }
227: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
1.150 raeburn 228: push(@prefs_order,'loadbalancing');
229: }
1.30 raeburn 230: my %prefs = (
231: 'rolecolors' =>
232: { text => 'Default color schemes',
1.67 raeburn 233: help => 'Domain_Configuration_Color_Schemes',
1.30 raeburn 234: header => [{col1 => 'Student Settings',
235: col2 => '',},
236: {col1 => 'Coordinator Settings',
237: col2 => '',},
238: {col1 => 'Author Settings',
239: col2 => '',},
240: {col1 => 'Administrator Settings',
241: col2 => '',}],
1.230 ! raeburn 242: print => \&print_rolecolors,
! 243: modify => \&modify_rolecolors,
1.30 raeburn 244: },
1.110 raeburn 245: 'login' =>
1.30 raeburn 246: { text => 'Log-in page options',
1.67 raeburn 247: help => 'Domain_Configuration_Login_Page',
1.168 raeburn 248: header => [{col1 => 'Log-in Page Items',
249: col2 => '',},
250: {col1 => 'Log-in Help',
251: col2 => 'Value'}],
1.230 ! raeburn 252: print => \&print_login,
! 253: modify => \&modify_login,
1.30 raeburn 254: },
1.43 raeburn 255: 'defaults' =>
1.141 raeburn 256: { text => 'Default authentication/language/timezone/portal',
1.67 raeburn 257: help => 'Domain_Configuration_LangTZAuth',
1.43 raeburn 258: header => [{col1 => 'Setting',
259: col2 => 'Value'}],
1.230 ! raeburn 260: print => \&print_defaults,
! 261: modify => \&modify_defaults,
1.43 raeburn 262: },
1.30 raeburn 263: 'quotas' =>
1.197 raeburn 264: { text => 'Blogs, personal web pages, webDAV/quotas, portfolios',
1.67 raeburn 265: help => 'Domain_Configuration_Quotas',
1.77 raeburn 266: header => [{col1 => 'User affiliation',
1.72 raeburn 267: col2 => 'Available tools',
1.213 raeburn 268: col3 => 'Quotas, MB; (Authoring requires role)',}],
1.230 ! raeburn 269: print => \&print_quotas,
! 270: modify => \&modify_quotas,
1.30 raeburn 271: },
272: 'autoenroll' =>
273: { text => 'Auto-enrollment settings',
1.67 raeburn 274: help => 'Domain_Configuration_Auto_Enrollment',
1.30 raeburn 275: header => [{col1 => 'Configuration setting',
276: col2 => 'Value(s)'}],
1.230 ! raeburn 277: print => \&print_autoenroll,
! 278: modify => \&modify_autoenroll,
1.30 raeburn 279: },
280: 'autoupdate' =>
281: { text => 'Auto-update settings',
1.67 raeburn 282: help => 'Domain_Configuration_Auto_Updates',
1.30 raeburn 283: header => [{col1 => 'Setting',
284: col2 => 'Value',},
1.131 raeburn 285: {col1 => 'Setting',
286: col2 => 'Affiliation'},
1.43 raeburn 287: {col1 => 'User population',
1.227 bisitz 288: col2 => 'Updatable user data'}],
1.230 ! raeburn 289: print => \&print_autoupdate,
! 290: modify => \&modify_autoupdate,
1.30 raeburn 291: },
1.125 raeburn 292: 'autocreate' =>
293: { text => 'Auto-course creation settings',
294: help => 'Domain_Configuration_Auto_Creation',
295: header => [{col1 => 'Configuration Setting',
296: col2 => 'Value',}],
1.230 ! raeburn 297: print => \&print_autocreate,
! 298: modify => \&modify_autocreate,
1.125 raeburn 299: },
1.30 raeburn 300: 'directorysrch' =>
301: { text => 'Institutional directory searches',
1.67 raeburn 302: help => 'Domain_Configuration_InstDirectory_Search',
1.30 raeburn 303: header => [{col1 => 'Setting',
304: col2 => 'Value',}],
1.230 ! raeburn 305: print => \&print_directorysrch,
! 306: modify => \&modify_directorysrch,
1.30 raeburn 307: },
308: 'contacts' =>
309: { text => 'Contact Information',
1.67 raeburn 310: help => 'Domain_Configuration_Contact_Info',
1.30 raeburn 311: header => [{col1 => 'Setting',
312: col2 => 'Value',}],
1.230 ! raeburn 313: print => \&print_contacts,
! 314: modify => \&modify_contacts,
1.30 raeburn 315: },
316: 'usercreation' =>
317: { text => 'User creation',
1.67 raeburn 318: help => 'Domain_Configuration_User_Creation',
1.43 raeburn 319: header => [{col1 => 'Format rule type',
320: col2 => 'Format rules in force'},
1.34 raeburn 321: {col1 => 'User account creation',
322: col2 => 'Usernames which may be created',},
1.30 raeburn 323: {col1 => 'Context',
1.43 raeburn 324: col2 => 'Assignable authentication types'}],
1.230 ! raeburn 325: print => \&print_usercreation,
! 326: modify => \&modify_usercreation,
1.30 raeburn 327: },
1.224 raeburn 328: 'selfcreation' =>
329: { text => 'Users self-creating accounts',
330: help => 'Domain_Configuration_Self_Creation',
331: header => [{col1 => 'Self-creation with institutional username',
332: col2 => 'Enabled?'},
333: {col1 => 'Institutional user type (login/SSO self-creation)',
334: col2 => 'Information user can enter'},
335: {col1 => 'Self-creation with e-mail as username',
336: col2 => 'Settings'}],
1.230 ! raeburn 337: print => \&print_selfcreation,
! 338: modify => \&modify_selfcreation,
1.224 raeburn 339: },
1.69 raeburn 340: 'usermodification' =>
1.33 raeburn 341: { text => 'User modification',
1.67 raeburn 342: help => 'Domain_Configuration_User_Modification',
1.33 raeburn 343: header => [{col1 => 'Target user has role',
1.227 bisitz 344: col2 => 'User information updatable in author context'},
1.33 raeburn 345: {col1 => 'Target user has role',
1.227 bisitz 346: col2 => 'User information updatable in course context'}],
1.230 ! raeburn 347: print => \&print_usermodification,
! 348: modify => \&modify_usermodification,
1.33 raeburn 349: },
1.69 raeburn 350: 'scantron' =>
1.95 www 351: { text => 'Bubblesheet format file',
1.67 raeburn 352: help => 'Domain_Configuration_Scantron_Format',
1.46 raeburn 353: header => [ {col1 => 'Item',
354: col2 => '',
355: }],
1.230 ! raeburn 356: print => \&print_scantron,
! 357: modify => \&modify_scantron,
1.46 raeburn 358: },
1.86 raeburn 359: 'requestcourses' =>
360: {text => 'Request creation of courses',
361: help => 'Domain_Configuration_Request_Courses',
362: header => [{col1 => 'User affiliation',
1.102 raeburn 363: col2 => 'Availability/Processing of requests',},
364: {col1 => 'Setting',
1.216 raeburn 365: col2 => 'Value'},
366: {col1 => 'Available textbooks',
367: col2 => ''}],
1.230 ! raeburn 368: print => \&print_quotas,
! 369: modify => \&modify_quotas,
1.86 raeburn 370: },
1.163 raeburn 371: 'requestauthor' =>
1.223 bisitz 372: {text => 'Request Authoring Space',
1.163 raeburn 373: help => 'Domain_Configuration_Request_Author',
374: header => [{col1 => 'User affiliation',
375: col2 => 'Availability/Processing of requests',},
376: {col1 => 'Setting',
377: col2 => 'Value'}],
1.230 ! raeburn 378: print => \&print_quotas,
! 379: modify => \&modify_quotas,
1.163 raeburn 380: },
1.69 raeburn 381: 'coursecategories' =>
1.120 raeburn 382: { text => 'Cataloging of courses/communities',
1.67 raeburn 383: help => 'Domain_Configuration_Cataloging_Courses',
1.69 raeburn 384: header => [{col1 => 'Category settings',
1.57 raeburn 385: col2 => '',},
386: {col1 => 'Categories',
387: col2 => '',
388: }],
1.230 ! raeburn 389: print => \&print_coursecategories,
! 390: modify => \&modify_coursecategories,
1.69 raeburn 391: },
392: 'serverstatuses' =>
1.77 raeburn 393: {text => 'Access to server status pages',
1.69 raeburn 394: help => 'Domain_Configuration_Server_Status',
395: header => [{col1 => 'Status Page',
396: col2 => 'Other named users',
397: col3 => 'Specific IPs',
398: }],
1.230 ! raeburn 399: print => \&print_serverstatuses,
! 400: modify => \&modify_serverstatuses,
1.69 raeburn 401: },
1.118 jms 402: 'helpsettings' =>
403: {text => 'Help page settings',
404: help => 'Domain_Configuration_Help_Settings',
1.166 raeburn 405: header => [{col1 => 'Help Settings (logged-in users)',
406: col2 => 'Value'}],
1.230 ! raeburn 407: print => \&print_helpsettings,
! 408: modify => \&modify_helpsettings,
1.118 jms 409: },
1.121 raeburn 410: 'coursedefaults' =>
411: {text => 'Course/Community defaults',
412: help => 'Domain_Configuration_Course_Defaults',
1.139 raeburn 413: header => [{col1 => 'Defaults which can be overridden in each course by a CC',
414: col2 => 'Value',},
415: {col1 => 'Defaults which can be overridden for each course by a DC',
416: col2 => 'Value',},],
1.230 ! raeburn 417: print => \&print_coursedefaults,
! 418: modify => \&modify_coursedefaults,
1.121 raeburn 419: },
1.120 raeburn 420: 'privacy' =>
421: {text => 'User Privacy',
422: help => 'Domain_Configuration_User_Privacy',
423: header => [{col1 => 'Setting',
424: col2 => 'Value',}],
1.230 ! raeburn 425: print => \&print_privacy,
! 426: modify => \&modify_privacy,
1.120 raeburn 427: },
1.141 raeburn 428: 'usersessions' =>
1.145 raeburn 429: {text => 'User session hosting/offloading',
1.137 raeburn 430: help => 'Domain_Configuration_User_Sessions',
1.145 raeburn 431: header => [{col1 => 'Domain server',
432: col2 => 'Servers to offload sessions to when busy'},
433: {col1 => 'Hosting of users from other domains',
1.137 raeburn 434: col2 => 'Rules'},
435: {col1 => "Hosting domain's own users elsewhere",
436: col2 => 'Rules'}],
1.230 ! raeburn 437: print => \&print_usersessions,
! 438: modify => \&modify_usersessions,
1.137 raeburn 439: },
1.150 raeburn 440: 'loadbalancing' =>
1.185 raeburn 441: {text => 'Dedicated Load Balancer(s)',
1.150 raeburn 442: help => 'Domain_Configuration_Load_Balancing',
1.171 raeburn 443: header => [{col1 => 'Balancers',
1.150 raeburn 444: col2 => 'Default destinations',
1.183 bisitz 445: col3 => 'User affiliation',
1.150 raeburn 446: col4 => 'Overrides'},
447: ],
1.230 ! raeburn 448: print => \&print_loadbalancing,
! 449: modify => \&modify_loadbalancing,
1.150 raeburn 450: },
1.3 raeburn 451: );
1.110 raeburn 452: if (keys(%servers) > 1) {
453: $prefs{'login'} = { text => 'Log-in page options',
454: help => 'Domain_Configuration_Login_Page',
455: header => [{col1 => 'Log-in Service',
456: col2 => 'Server Setting',},
457: {col1 => 'Log-in Page Items',
1.168 raeburn 458: col2 => ''},
459: {col1 => 'Log-in Help',
460: col2 => 'Value'}],
1.230 ! raeburn 461: print => \&print_login,
! 462: modify => \&modify_login,
1.110 raeburn 463: };
464: }
1.174 foxr 465:
1.6 raeburn 466: my @roles = ('student','coordinator','author','admin');
1.30 raeburn 467: my @actions = &Apache::loncommon::get_env_multiple('form.actions');
1.3 raeburn 468: &Apache::lonhtmlcommon::add_breadcrumb
1.30 raeburn 469: ({href=>"javascript:changePage(document.$phase,'pickactions')",
1.133 raeburn 470: text=>"Settings to display/modify"});
1.9 raeburn 471: my $confname = $dom.'-domainconfig';
1.174 foxr 472:
1.3 raeburn 473: if ($phase eq 'process') {
1.212 raeburn 474: my $result = &Apache::lonconfigsettings::make_changes($r,$dom,$phase,$context,\@prefs_order,
475: \%prefs,\%domconfig,$confname,\@roles);
1.224 raeburn 476: if ((ref($result) eq 'HASH') && (keys(%{$result}))) {
1.205 raeburn 477: $r->rflush();
1.212 raeburn 478: &devalidate_remote_domconfs($dom,$result);
1.205 raeburn 479: }
1.30 raeburn 480: } elsif ($phase eq 'display') {
1.192 raeburn 481: my $js = &recaptcha_js().
482: &credits_js();
1.171 raeburn 483: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
1.152 raeburn 484: my ($othertitle,$usertypes,$types) =
485: &Apache::loncommon::sorted_inst_types($dom);
1.171 raeburn 486: $js .= &lonbalance_targets_js($dom,$types,\%servers,
487: $domconfig{'loadbalancing'}).
1.170 raeburn 488: &new_spares_js().
489: &common_domprefs_js().
490: &Apache::loncommon::javascript_array_indexof();
1.152 raeburn 491: }
1.216 raeburn 492: if (grep(/^requestcourses$/,@actions)) {
493: my $javascript_validations;
494: my $coursebrowserjs=&Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'});
495: $js .= <<END;
496: <script type="text/javascript">
497: $javascript_validations
498: </script>
499: $coursebrowserjs
500: END
501: }
1.150 raeburn 502: &Apache::lonconfigsettings::display_settings($r,$dom,$phase,$context,\@prefs_order,\%prefs,\%domconfig,$confname,$js);
1.1 raeburn 503: } else {
1.180 raeburn 504: # check if domconfig user exists for the domain.
505: my $servadm = $r->dir_config('lonAdmEMail');
506: my ($configuserok,$author_ok,$switchserver) =
507: &config_check($dom,$confname,$servadm);
508: unless ($configuserok eq 'ok') {
1.181 raeburn 509: &Apache::lonconfigsettings::print_header($r,$phase,$context);
510: $r->print(&mt('The domain configuration user "[_1]" has yet to be created.',
1.210 raeburn 511: $confname).
1.181 raeburn 512: '<br />'
513: );
1.180 raeburn 514: if ($switchserver) {
1.181 raeburn 515: $r->print(&mt('Ordinarily, that domain configuration user is created when the ./UPDATE script is run to install LON-CAPA for the first time.').
516: '<br />'.
517: &mt('However, that does not apply when new domains are added to a multi-domain server, and ./UPDATE has not been run recently.').
518: '<br />'.
519: &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).
520: '<br />'.
521: &mt('To do that now, use the following link: [_1]',$switchserver)
522: );
523: } else {
524: $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.').
525: '<br />'.
526: &mt('Once that is done, you will be able to use the web-based "Set domain configuration" to configure the domain')
527: );
1.180 raeburn 528: }
529: $r->print(&Apache::loncommon::end_page());
530: return OK;
531: }
1.21 raeburn 532: if (keys(%domconfig) == 0) {
533: my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
1.29 raeburn 534: my @ids=&Apache::lonnet::current_machine_ids();
535: if (!grep(/^\Q$primarylibserv\E$/,@ids)) {
1.21 raeburn 536: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.41 raeburn 537: my @loginimages = ('img','logo','domlogo','login');
1.21 raeburn 538: my $custom_img_count = 0;
539: foreach my $img (@loginimages) {
540: if ($designhash{$dom.'.login.'.$img} ne '') {
541: $custom_img_count ++;
542: }
543: }
544: foreach my $role (@roles) {
545: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
546: $custom_img_count ++;
547: }
548: }
549: if ($custom_img_count > 0) {
1.94 raeburn 550: &Apache::lonconfigsettings::print_header($r,$phase,$context);
1.21 raeburn 551: my $switch_server = &check_switchserver($dom,$confname);
1.29 raeburn 552: $r->print(
553: &mt('Domain configuration settings have yet to be saved for this domain via the web-based domain preferences interface.').'<br />'.
554: &mt("While this remains so, you must switch to the domain's primary library server in order to update settings.").'<br /><br />'.
555: &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 />'.
556: &mt("However, you will still need to switch to the domain's primary library server to upload new images or logos.").'<br /><br />');
557: if ($switch_server) {
1.30 raeburn 558: $r->print($switch_server.' '.&mt('to primary library server for domain: [_1]',$dom));
1.29 raeburn 559: }
1.91 raeburn 560: $r->print(&Apache::loncommon::end_page());
1.21 raeburn 561: return OK;
562: }
563: }
564: }
1.91 raeburn 565: &Apache::lonconfigsettings::display_choices($r,$phase,$context,\@prefs_order,\%prefs);
1.3 raeburn 566: }
567: return OK;
568: }
569:
570: sub process_changes {
1.205 raeburn 571: my ($r,$dom,$confname,$action,$roles,$values,$lastactref) = @_;
1.92 raeburn 572: my %domconfig;
573: if (ref($values) eq 'HASH') {
574: %domconfig = %{$values};
575: }
1.3 raeburn 576: my $output;
577: if ($action eq 'login') {
1.205 raeburn 578: $output = &modify_login($r,$dom,$confname,$lastactref,%domconfig);
1.6 raeburn 579: } elsif ($action eq 'rolecolors') {
1.9 raeburn 580: $output = &modify_rolecolors($r,$dom,$confname,$roles,
1.205 raeburn 581: $lastactref,%domconfig);
1.3 raeburn 582: } elsif ($action eq 'quotas') {
1.216 raeburn 583: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.3 raeburn 584: } elsif ($action eq 'autoenroll') {
1.205 raeburn 585: $output = &modify_autoenroll($dom,$lastactref,%domconfig);
1.3 raeburn 586: } elsif ($action eq 'autoupdate') {
587: $output = &modify_autoupdate($dom,%domconfig);
1.125 raeburn 588: } elsif ($action eq 'autocreate') {
589: $output = &modify_autocreate($dom,%domconfig);
1.23 raeburn 590: } elsif ($action eq 'directorysrch') {
591: $output = &modify_directorysrch($dom,%domconfig);
1.27 raeburn 592: } elsif ($action eq 'usercreation') {
1.28 raeburn 593: $output = &modify_usercreation($dom,%domconfig);
1.224 raeburn 594: } elsif ($action eq 'selfcreation') {
595: $output = &modify_selfcreation($dom,%domconfig);
1.33 raeburn 596: } elsif ($action eq 'usermodification') {
597: $output = &modify_usermodification($dom,%domconfig);
1.28 raeburn 598: } elsif ($action eq 'contacts') {
1.205 raeburn 599: $output = &modify_contacts($dom,$lastactref,%domconfig);
1.43 raeburn 600: } elsif ($action eq 'defaults') {
1.212 raeburn 601: $output = &modify_defaults($dom,$lastactref,%domconfig);
1.46 raeburn 602: } elsif ($action eq 'scantron') {
1.205 raeburn 603: $output = &modify_scantron($r,$dom,$confname,$lastactref,%domconfig);
1.48 raeburn 604: } elsif ($action eq 'coursecategories') {
605: $output = &modify_coursecategories($dom,%domconfig);
1.69 raeburn 606: } elsif ($action eq 'serverstatuses') {
607: $output = &modify_serverstatuses($dom,%domconfig);
1.86 raeburn 608: } elsif ($action eq 'requestcourses') {
1.216 raeburn 609: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.163 raeburn 610: } elsif ($action eq 'requestauthor') {
1.216 raeburn 611: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.118 jms 612: } elsif ($action eq 'helpsettings') {
1.122 jms 613: $output = &modify_helpsettings($r,$dom,$confname,%domconfig);
1.121 raeburn 614: } elsif ($action eq 'coursedefaults') {
1.212 raeburn 615: $output = &modify_coursedefaults($dom,$lastactref,%domconfig);
1.137 raeburn 616: } elsif ($action eq 'usersessions') {
1.212 raeburn 617: $output = &modify_usersessions($dom,$lastactref,%domconfig);
1.150 raeburn 618: } elsif ($action eq 'loadbalancing') {
619: $output = &modify_loadbalancing($dom,%domconfig);
1.3 raeburn 620: }
621: return $output;
622: }
623:
624: sub print_config_box {
1.9 raeburn 625: my ($r,$dom,$confname,$phase,$action,$item,$settings) = @_;
1.30 raeburn 626: my $rowtotal = 0;
1.49 raeburn 627: my $output;
628: if ($action eq 'coursecategories') {
629: $output = &coursecategories_javascript($settings);
1.91 raeburn 630: }
1.49 raeburn 631: $output .=
1.30 raeburn 632: '<table class="LC_nested_outer">
1.3 raeburn 633: <tr>
1.66 raeburn 634: <th align="left" valign="middle"><span class="LC_nobreak">'.
635: &mt($item->{text}).' '.
636: &Apache::loncommon::help_open_topic($item->{'help'}).'</span></th>'."\n".
637: '</tr>';
1.30 raeburn 638: $rowtotal ++;
1.110 raeburn 639: my $numheaders = 1;
640: if (ref($item->{'header'}) eq 'ARRAY') {
641: $numheaders = scalar(@{$item->{'header'}});
642: }
643: if ($numheaders > 1) {
1.64 raeburn 644: my $colspan = '';
1.145 raeburn 645: my $rightcolspan = '';
1.210 raeburn 646: if (($action eq 'rolecolors') || ($action eq 'coursecategories') ||
1.168 raeburn 647: (($action eq 'login') && ($numheaders < 3))) {
1.64 raeburn 648: $colspan = ' colspan="2"';
649: }
1.145 raeburn 650: if ($action eq 'usersessions') {
651: $rightcolspan = ' colspan="3"';
652: }
1.30 raeburn 653: $output .= '
1.3 raeburn 654: <tr>
655: <td>
656: <table class="LC_nested">
657: <tr class="LC_info_row">
1.59 bisitz 658: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[0]->{'col1'}).'</td>
1.145 raeburn 659: <td class="LC_right_item"'.$rightcolspan.'>'.&mt($item->{'header'}->[0]->{'col2'}).'</td>
1.30 raeburn 660: </tr>';
1.69 raeburn 661: $rowtotal ++;
1.230 ! raeburn 662: if (($action eq 'autoupdate') || ($action eq 'usercreation') || ($action eq 'selfcreation') ||
! 663: ($action eq 'usermodification') || ($action eq 'coursedefaults') ||
! 664: ($action eq 'selfenrollment') || ($action eq 'usersessions')) {
! 665: $output .= $item->{'print'}->('top',$dom,$settings,\$rowtotal);
1.57 raeburn 666: } elsif ($action eq 'coursecategories') {
1.230 ! raeburn 667: $output .= $item->{'print'}->('top',$dom,$item,$settings,\$rowtotal);
1.110 raeburn 668: } elsif ($action eq 'login') {
1.168 raeburn 669: if ($numheaders == 3) {
670: $colspan = ' colspan="2"';
671: $output .= &print_login('service',$dom,$confname,$phase,$settings,\$rowtotal);
672: } else {
673: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal);
674: }
1.230 ! raeburn 675: } elsif (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.163 raeburn 676: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.122 jms 677: } elsif ($action eq 'rolecolors') {
1.30 raeburn 678: $output .= &print_rolecolors($phase,'student',$dom,$confname,$settings,\$rowtotal);
1.6 raeburn 679: }
1.30 raeburn 680: $output .= '
1.6 raeburn 681: </table>
682: </td>
683: </tr>
684: <tr>
685: <td>
686: <table class="LC_nested">
687: <tr class="LC_info_row">
1.230 ! raeburn 688: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col1'}).'</td>
1.59 bisitz 689: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col2'}).'</td>
1.30 raeburn 690: </tr>';
691: $rowtotal ++;
1.230 ! raeburn 692: if (($action eq 'autoupdate') || ($action eq 'usercreation') ||
! 693: ($action eq 'selfcreation') || ($action eq 'selfenrollment') ||
! 694: ($action eq 'usersessions')) {
! 695: $output .= $item->{'print'}->('middle',$dom,$settings,\$rowtotal).'
1.63 raeburn 696: </table>
697: </td>
698: </tr>
699: <tr>
700: <td>
701: <table class="LC_nested">
702: <tr class="LC_info_row">
703: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1.224 raeburn 704: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
1.230 ! raeburn 705: </tr>'."\n".
! 706: $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1.63 raeburn 707: $rowtotal ++;
1.230 ! raeburn 708: } elsif (($action eq 'usermodification') || ($action eq 'coursedefaults')) {
! 709: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1.57 raeburn 710: } elsif ($action eq 'coursecategories') {
711: $output .= &print_coursecategories('bottom',$dom,$item,$settings,\$rowtotal);
1.110 raeburn 712: } elsif ($action eq 'login') {
1.168 raeburn 713: if ($numheaders == 3) {
714: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal).'
715: </table>
716: </td>
717: </tr>
718: <tr>
719: <td>
720: <table class="LC_nested">
721: <tr class="LC_info_row">
722: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1.216 raeburn 723: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td></tr>'.
1.168 raeburn 724: &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
725: $rowtotal ++;
726: } else {
727: $output .= &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
728: }
1.102 raeburn 729: } elsif ($action eq 'requestcourses') {
1.216 raeburn 730: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal).
731: &print_studentcode($settings,\$rowtotal).'
732: </table>
733: </td>
734: </tr>
735: <tr>
736: <td>
737: <table class="LC_nested">
738: <tr class="LC_info_row">
739: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
740: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
741: &print_textbookcourses($dom,$settings,\$rowtotal);
1.163 raeburn 742: } elsif ($action eq 'requestauthor') {
743: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
1.122 jms 744: } elsif ($action eq 'rolecolors') {
1.30 raeburn 745: $output .= &print_rolecolors($phase,'coordinator',$dom,$confname,$settings,\$rowtotal).'
1.6 raeburn 746: </table>
747: </td>
748: </tr>
749: <tr>
750: <td>
751: <table class="LC_nested">
752: <tr class="LC_info_row">
1.69 raeburn 753: <td class="LC_left_item"'.$colspan.' valign="top">'.
754: &mt($item->{'header'}->[2]->{'col1'}).'</td>
755: <td class="LC_right_item" valign="top">'.
756: &mt($item->{'header'}->[2]->{'col2'}).'</td>
1.3 raeburn 757: </tr>'.
1.30 raeburn 758: &print_rolecolors($phase,'author',$dom,$confname,$settings,\$rowtotal).'
1.3 raeburn 759: </table>
760: </td>
761: </tr>
762: <tr>
763: <td>
764: <table class="LC_nested">
765: <tr class="LC_info_row">
1.59 bisitz 766: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
767: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
1.3 raeburn 768: </tr>'.
1.30 raeburn 769: &print_rolecolors($phase,'admin',$dom,$confname,$settings,\$rowtotal);
770: $rowtotal += 2;
1.6 raeburn 771: }
1.3 raeburn 772: } else {
1.30 raeburn 773: $output .= '
1.3 raeburn 774: <tr>
775: <td>
776: <table class="LC_nested">
1.30 raeburn 777: <tr class="LC_info_row">';
1.24 raeburn 778: if (($action eq 'login') || ($action eq 'directorysrch')) {
1.30 raeburn 779: $output .= '
1.59 bisitz 780: <td class="LC_left_item" colspan="2">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
1.69 raeburn 781: } elsif ($action eq 'serverstatuses') {
782: $output .= '
783: <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).
784: '<br />('.&mt('Automatic access for Dom. Coords.').')</td>';
785:
1.6 raeburn 786: } else {
1.30 raeburn 787: $output .= '
1.69 raeburn 788: <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
789: }
1.72 raeburn 790: if (defined($item->{'header'}->[0]->{'col3'})) {
791: $output .= '<td class="LC_left_item" valign="top">'.
792: &mt($item->{'header'}->[0]->{'col2'});
793: if ($action eq 'serverstatuses') {
794: $output .= '<br />(<tt>'.&mt('user1:domain1,user2:domain2 etc.').'</tt>)';
795: }
1.69 raeburn 796: } else {
797: $output .= '<td class="LC_right_item" valign="top">'.
798: &mt($item->{'header'}->[0]->{'col2'});
799: }
800: $output .= '</td>';
801: if ($item->{'header'}->[0]->{'col3'}) {
1.150 raeburn 802: if (defined($item->{'header'}->[0]->{'col4'})) {
803: $output .= '<td class="LC_left_item" valign="top">'.
804: &mt($item->{'header'}->[0]->{'col3'});
805: } else {
806: $output .= '<td class="LC_right_item" valign="top">'.
807: &mt($item->{'header'}->[0]->{'col3'});
808: }
1.69 raeburn 809: if ($action eq 'serverstatuses') {
810: $output .= '<br />(<tt>'.&mt('IP1,IP2 etc.').'</tt>)';
811: }
812: $output .= '</td>';
1.6 raeburn 813: }
1.150 raeburn 814: if ($item->{'header'}->[0]->{'col4'}) {
815: $output .= '<td class="LC_right_item" valign="top">'.
816: &mt($item->{'header'}->[0]->{'col4'});
817: }
1.69 raeburn 818: $output .= '</tr>';
1.48 raeburn 819: $rowtotal ++;
1.168 raeburn 820: if ($action eq 'quotas') {
1.86 raeburn 821: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.230 ! raeburn 822: } elsif (($action eq 'autoenroll') || ($action eq 'autocreate') || ($action eq 'directorysrch') ||
! 823: ($action eq 'contacts') || ($action eq 'defaults') || ($action eq 'serverstatuses') ||
! 824: ($action eq 'loadbalancing')) {
! 825: $output .= $item->{'print'}->($dom,$settings,\$rowtotal);
1.46 raeburn 826: } elsif ($action eq 'scantron') {
827: $output .= &print_scantronformat($r,$dom,$confname,$settings,\$rowtotal);
1.118 jms 828: } elsif ($action eq 'helpsettings') {
1.168 raeburn 829: $output .= &print_helpsettings($dom,$confname,$settings,\$rowtotal);
1.121 raeburn 830: }
1.3 raeburn 831: }
1.30 raeburn 832: $output .= '
1.3 raeburn 833: </table>
834: </td>
835: </tr>
1.30 raeburn 836: </table><br />';
837: return ($output,$rowtotal);
1.1 raeburn 838: }
839:
1.3 raeburn 840: sub print_login {
1.168 raeburn 841: my ($caller,$dom,$confname,$phase,$settings,$rowtotal) = @_;
1.110 raeburn 842: my ($css_class,$datatable);
1.6 raeburn 843: my %choices = &login_choices();
1.110 raeburn 844:
1.168 raeburn 845: if ($caller eq 'service') {
1.149 raeburn 846: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.110 raeburn 847: my $choice = $choices{'disallowlogin'};
848: $css_class = ' class="LC_odd_row"';
1.128 raeburn 849: $datatable .= '<tr'.$css_class.'><td>'.$choice.'</td>'.
1.110 raeburn 850: '<td align="right"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1.128 raeburn 851: '<th>'.$choices{'server'}.'</th>'.
852: '<th>'.$choices{'serverpath'}.'</th>'.
853: '<th>'.$choices{'custompath'}.'</th>'.
854: '<th><span class="LC_nobreak">'.$choices{'exempt'}.'</span></th></tr>'."\n";
1.110 raeburn 855: my %disallowed;
856: if (ref($settings) eq 'HASH') {
857: if (ref($settings->{'loginvia'}) eq 'HASH') {
858: %disallowed = %{$settings->{'loginvia'}};
859: }
860: }
861: foreach my $lonhost (sort(keys(%servers))) {
862: my $direct = 'selected="selected"';
1.128 raeburn 863: if (ref($disallowed{$lonhost}) eq 'HASH') {
864: if ($disallowed{$lonhost}{'server'} ne '') {
865: $direct = '';
866: }
1.110 raeburn 867: }
1.115 raeburn 868: $datatable .= '<tr><td>'.$servers{$lonhost}.'</td>'.
1.128 raeburn 869: '<td><select name="'.$lonhost.'_server">'.
1.110 raeburn 870: '<option value=""'.$direct.'>'.$choices{'directlogin'}.
871: '</option>';
1.184 raeburn 872: foreach my $hostid (sort(keys(%servers))) {
1.115 raeburn 873: next if ($servers{$hostid} eq $servers{$lonhost});
1.110 raeburn 874: my $selected = '';
1.128 raeburn 875: if (ref($disallowed{$lonhost}) eq 'HASH') {
876: if ($hostid eq $disallowed{$lonhost}{'server'}) {
877: $selected = 'selected="selected"';
878: }
1.110 raeburn 879: }
880: $datatable .= '<option value="'.$hostid.'"'.$selected.'>'.
881: $servers{$hostid}.'</option>';
882: }
1.128 raeburn 883: $datatable .= '</select></td>'.
884: '<td><select name="'.$lonhost.'_serverpath">';
885: foreach my $path ('','/','/adm/login','/adm/roles','custom') {
886: my $pathname = $path;
887: if ($path eq 'custom') {
888: $pathname = &mt('Custom Path').' ->';
889: }
890: my $selected = '';
891: if (ref($disallowed{$lonhost}) eq 'HASH') {
892: if ($path eq $disallowed{$lonhost}{'serverpath'}) {
893: $selected = 'selected="selected"';
894: }
895: } elsif ($path eq '') {
896: $selected = 'selected="selected"';
897: }
898: $datatable .= '<option value="'.$path.'"'.$selected.'>'.$pathname.'</option>';
899: }
900: $datatable .= '</select></td>';
901: my ($custom,$exempt);
902: if (ref($disallowed{$lonhost}) eq 'HASH') {
903: $custom = $disallowed{$lonhost}{'custompath'};
904: $exempt = $disallowed{$lonhost}{'exempt'};
905: }
906: $datatable .= '<td><input type="text" name="'.$lonhost.'_custompath" size="6" value="'.$custom.'" /></td>'.
907: '<td><input type="text" name="'.$lonhost.'_exempt" size="8" value="'.$exempt.'" /></td>'.
908: '</tr>';
1.110 raeburn 909: }
910: $datatable .= '</table></td></tr>';
911: return $datatable;
1.168 raeburn 912: } elsif ($caller eq 'page') {
913: my %defaultchecked = (
914: 'coursecatalog' => 'on',
1.188 raeburn 915: 'helpdesk' => 'on',
1.168 raeburn 916: 'adminmail' => 'off',
917: 'newuser' => 'off',
918: );
1.188 raeburn 919: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.168 raeburn 920: my (%checkedon,%checkedoff);
1.42 raeburn 921: foreach my $item (@toggles) {
1.168 raeburn 922: if ($defaultchecked{$item} eq 'on') {
923: $checkedon{$item} = ' checked="checked" ';
1.42 raeburn 924: $checkedoff{$item} = ' ';
1.168 raeburn 925: } elsif ($defaultchecked{$item} eq 'off') {
926: $checkedoff{$item} = ' checked="checked" ';
1.42 raeburn 927: $checkedon{$item} = ' ';
928: }
1.1 raeburn 929: }
1.168 raeburn 930: my @images = ('img','logo','domlogo','login');
931: my @logintext = ('textcol','bgcol');
932: my @bgs = ('pgbg','mainbg','sidebg');
933: my @links = ('link','alink','vlink');
934: my %designhash = &Apache::loncommon::get_domainconf($dom);
935: my %defaultdesign = %Apache::loncommon::defaultdesign;
936: my (%is_custom,%designs);
937: my %defaults = (
938: font => $defaultdesign{'login.font'},
939: );
1.6 raeburn 940: foreach my $item (@images) {
1.168 raeburn 941: $defaults{$item} = $defaultdesign{'login.'.$item};
942: $defaults{'showlogo'}{$item} = 1;
943: }
944: foreach my $item (@bgs) {
945: $defaults{'bgs'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 946: }
1.41 raeburn 947: foreach my $item (@logintext) {
1.168 raeburn 948: $defaults{'logintext'}{$item} = $defaultdesign{'login.'.$item};
1.41 raeburn 949: }
1.168 raeburn 950: foreach my $item (@links) {
951: $defaults{'links'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 952: }
1.168 raeburn 953: if (ref($settings) eq 'HASH') {
954: foreach my $item (@toggles) {
955: if ($settings->{$item} eq '1') {
956: $checkedon{$item} = ' checked="checked" ';
957: $checkedoff{$item} = ' ';
958: } elsif ($settings->{$item} eq '0') {
959: $checkedoff{$item} = ' checked="checked" ';
960: $checkedon{$item} = ' ';
961: }
962: }
963: foreach my $item (@images) {
964: if (defined($settings->{$item})) {
965: $designs{$item} = $settings->{$item};
966: $is_custom{$item} = 1;
967: }
968: if (defined($settings->{'showlogo'}{$item})) {
969: $designs{'showlogo'}{$item} = $settings->{'showlogo'}{$item};
970: }
971: }
972: foreach my $item (@logintext) {
973: if ($settings->{$item} ne '') {
974: $designs{'logintext'}{$item} = $settings->{$item};
975: $is_custom{$item} = 1;
976: }
977: }
978: if ($settings->{'font'} ne '') {
979: $designs{'font'} = $settings->{'font'};
980: $is_custom{'font'} = 1;
981: }
982: foreach my $item (@bgs) {
983: if ($settings->{$item} ne '') {
984: $designs{'bgs'}{$item} = $settings->{$item};
985: $is_custom{$item} = 1;
986: }
987: }
988: foreach my $item (@links) {
989: if ($settings->{$item} ne '') {
990: $designs{'links'}{$item} = $settings->{$item};
991: $is_custom{$item} = 1;
992: }
993: }
994: } else {
995: if ($designhash{$dom.'.login.font'} ne '') {
996: $designs{'font'} = $designhash{$dom.'.login.font'};
997: $is_custom{'font'} = 1;
998: }
999: foreach my $item (@images) {
1000: if ($designhash{$dom.'.login.'.$item} ne '') {
1001: $designs{$item} = $designhash{$dom.'.login.'.$item};
1002: $is_custom{$item} = 1;
1003: }
1004: }
1005: foreach my $item (@bgs) {
1006: if ($designhash{$dom.'.login.'.$item} ne '') {
1007: $designs{'bgs'}{$item} = $designhash{$dom.'.login.'.$item};
1008: $is_custom{$item} = 1;
1009: }
1.6 raeburn 1010: }
1.168 raeburn 1011: foreach my $item (@links) {
1012: if ($designhash{$dom.'.login.'.$item} ne '') {
1013: $designs{'links'}{$item} = $designhash{$dom.'.login.'.$item};
1014: $is_custom{$item} = 1;
1015: }
1.6 raeburn 1016: }
1017: }
1.168 raeburn 1018: my %alt_text = &Apache::lonlocal::texthash ( img => 'Log-in banner',
1019: logo => 'Institution Logo',
1020: domlogo => 'Domain Logo',
1021: login => 'Login box');
1022: my $itemcount = 1;
1023: foreach my $item (@toggles) {
1024: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1025: $datatable .=
1026: '<tr'.$css_class.'><td colspan="2">'.$choices{$item}.
1027: '</td><td>'.
1028: '<span class="LC_nobreak"><label><input type="radio" name="'.
1029: $item.'"'.$checkedon{$item}.' value="1" />'.&mt('Yes').
1030: '</label> <label><input type="radio" name="'.$item.'"'.
1031: $checkedoff{$item}.' value="0" />'.&mt('No').'</label></span></td>'.
1032: '</tr>';
1033: $itemcount ++;
1.6 raeburn 1034: }
1.168 raeburn 1035: $datatable .= &display_color_options($dom,$confname,$phase,'login',$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal,\@logintext);
1036: $datatable .= '</tr></table></td></tr>';
1037: } elsif ($caller eq 'help') {
1038: my ($defaulturl,$defaulttype,%url,%type,%lt,%langchoices);
1039: my $switchserver = &check_switchserver($dom,$confname);
1040: my $itemcount = 1;
1041: $defaulturl = '/adm/loginproblems.html';
1042: $defaulttype = 'default';
1043: %lt = &Apache::lonlocal::texthash (
1044: del => 'Delete?',
1045: rep => 'Replace:',
1046: upl => 'Upload:',
1047: default => 'Default',
1048: custom => 'Custom',
1049: );
1050: %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
1051: my @currlangs;
1052: if (ref($settings) eq 'HASH') {
1053: if (ref($settings->{'helpurl'}) eq 'HASH') {
1054: foreach my $key (sort(keys(%{$settings->{'helpurl'}}))) {
1055: next if ($settings->{'helpurl'}{$key} eq '');
1056: $url{$key} = $settings->{'helpurl'}{$key}.'?inhibitmenu=yes';
1057: $type{$key} = 'custom';
1058: unless ($key eq 'nolang') {
1059: push(@currlangs,$key);
1060: }
1061: }
1062: } elsif ($settings->{'helpurl'} ne '') {
1063: $type{'nolang'} = 'custom';
1064: $url{'nolang'} = $settings->{'helpurl'}.'?inhibitmenu=yes';
1.8 raeburn 1065: }
1066: }
1.168 raeburn 1067: foreach my $lang ('nolang',sort(@currlangs)) {
1068: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1069: $datatable .= '<tr'.$css_class.'>';
1070: if ($url{$lang} eq '') {
1071: $url{$lang} = $defaulturl;
1072: }
1073: if ($type{$lang} eq '') {
1074: $type{$lang} = $defaulttype;
1075: }
1076: $datatable .= '<td colspan="2"><span class="LC_nobreak">';
1077: if ($lang eq 'nolang') {
1078: $datatable .= &mt('Log-in help page if no specific language file: [_1]',
1079: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1080: } else {
1081: $datatable .= &mt('Log-in help page for language: [_1] is [_2]',
1082: $langchoices{$lang},
1083: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1084: }
1085: $datatable .= '</span></td>'."\n".
1086: '<td class="LC_left_item">';
1087: if ($type{$lang} eq 'custom') {
1088: $datatable .= '<span class="LC_nobreak"><label>'.
1089: '<input type="checkbox" name="loginhelpurl_del" value="'.$lang.'" />'.
1090: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1091: } else {
1092: $datatable .= $lt{'upl'};
1093: }
1094: $datatable .='<br />';
1095: if ($switchserver) {
1096: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1097: } else {
1098: $datatable .= '<input type="file" name="loginhelpurl_'.$lang.'" />';
1.6 raeburn 1099: }
1.168 raeburn 1100: $datatable .= '</td></tr>';
1101: $itemcount ++;
1.6 raeburn 1102: }
1.168 raeburn 1103: my @addlangs;
1104: foreach my $lang (sort(keys(%langchoices))) {
1105: next if ((grep(/^\Q$lang\E$/,@currlangs)) || ($lang eq 'x_chef'));
1106: push(@addlangs,$lang);
1107: }
1108: if (@addlangs > 0) {
1109: my %toadd;
1110: map { $toadd{$_} = $langchoices{$_} ; } @addlangs;
1111: $toadd{''} = &mt('Select');
1112: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1113: $datatable .= '<tr'.$css_class.'><td class="LC_left_item" colspan="2">'.
1114: &mt('Add log-in help page for a specific language:').' '.
1115: &Apache::loncommon::select_form('','loginhelpurl_add_lang',\%toadd).
1116: '</td><td class="LC_left_item">'.$lt{'upl'}.'<br />';
1117: if ($switchserver) {
1118: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1119: } else {
1120: $datatable .= '<input type="file" name="loginhelpurl_add_file" />';
1.6 raeburn 1121: }
1.168 raeburn 1122: $datatable .= '</td></tr>';
1.169 raeburn 1123: $itemcount ++;
1.6 raeburn 1124: }
1.169 raeburn 1125: $datatable .= &captcha_choice('login',$settings,$itemcount);
1.1 raeburn 1126: }
1.6 raeburn 1127: return $datatable;
1128: }
1129:
1130: sub login_choices {
1131: my %choices =
1132: &Apache::lonlocal::texthash (
1.116 bisitz 1133: coursecatalog => 'Display Course/Community Catalog link?',
1.110 raeburn 1134: adminmail => "Display Administrator's E-mail Address?",
1.188 raeburn 1135: helpdesk => 'Display "Contact Helpdesk" link',
1.110 raeburn 1136: disallowlogin => "Login page requests redirected",
1137: hostid => "Server",
1.128 raeburn 1138: server => "Redirect to:",
1139: serverpath => "Path",
1140: custompath => "Custom",
1141: exempt => "Exempt IP(s)",
1.110 raeburn 1142: directlogin => "No redirect",
1143: newuser => "Link to create a user account",
1144: img => "Header",
1145: logo => "Main Logo",
1146: domlogo => "Domain Logo",
1147: login => "Log-in Header",
1148: textcol => "Text color",
1149: bgcol => "Box color",
1150: bgs => "Background colors",
1151: links => "Link colors",
1152: font => "Font color",
1153: pgbg => "Header",
1154: mainbg => "Page",
1155: sidebg => "Login box",
1156: link => "Link",
1157: alink => "Active link",
1158: vlink => "Visited link",
1.6 raeburn 1159: );
1160: return %choices;
1161: }
1162:
1163: sub print_rolecolors {
1.30 raeburn 1164: my ($phase,$role,$dom,$confname,$settings,$rowtotal) = @_;
1.6 raeburn 1165: my %choices = &color_font_choices();
1166: my @bgs = ('pgbg','tabbg','sidebg');
1167: my @links = ('link','alink','vlink');
1168: my @images = ('img');
1169: my %alt_text = &Apache::lonlocal::texthash(img => "Banner for $role role");
1.7 albertel 1170: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.6 raeburn 1171: my %defaultdesign = %Apache::loncommon::defaultdesign;
1172: my (%is_custom,%designs);
1.200 raeburn 1173: my %defaults = &role_defaults($role,\@bgs,\@links,\@images);
1.6 raeburn 1174: if (ref($settings) eq 'HASH') {
1175: if (ref($settings->{$role}) eq 'HASH') {
1176: if ($settings->{$role}->{'img'} ne '') {
1177: $designs{'img'} = $settings->{$role}->{'img'};
1178: $is_custom{'img'} = 1;
1179: }
1180: if ($settings->{$role}->{'font'} ne '') {
1181: $designs{'font'} = $settings->{$role}->{'font'};
1182: $is_custom{'font'} = 1;
1183: }
1.97 tempelho 1184: if ($settings->{$role}->{'fontmenu'} ne '') {
1185: $designs{'fontmenu'} = $settings->{$role}->{'fontmenu'};
1186: $is_custom{'fontmenu'} = 1;
1187: }
1.6 raeburn 1188: foreach my $item (@bgs) {
1189: if ($settings->{$role}->{$item} ne '') {
1190: $designs{'bgs'}{$item} = $settings->{$role}->{$item};
1191: $is_custom{$item} = 1;
1192: }
1193: }
1194: foreach my $item (@links) {
1195: if ($settings->{$role}->{$item} ne '') {
1196: $designs{'links'}{$item} = $settings->{$role}->{$item};
1197: $is_custom{$item} = 1;
1198: }
1199: }
1200: }
1201: } else {
1202: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
1203: $designs{img} = $designhash{$dom.'.'.$role.'.img'};
1204: $is_custom{'img'} = 1;
1205: }
1.97 tempelho 1206: if ($designhash{$dom.'.'.$role.'.fontmenu'} ne '') {
1207: $designs{fontmenu} = $designhash{$dom.'.'.$role.'.fontmenu'};
1208: $is_custom{'fontmenu'} = 1;
1209: }
1.6 raeburn 1210: if ($designhash{$dom.'.'.$role.'.font'} ne '') {
1211: $designs{font} = $designhash{$dom.'.'.$role.'.font'};
1212: $is_custom{'font'} = 1;
1213: }
1214: foreach my $item (@bgs) {
1215: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1216: $designs{'bgs'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1217: $is_custom{$item} = 1;
1218:
1219: }
1220: }
1221: foreach my $item (@links) {
1222: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1223: $designs{'links'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1224: $is_custom{$item} = 1;
1225: }
1226: }
1227: }
1228: my $itemcount = 1;
1.30 raeburn 1229: my $datatable = &display_color_options($dom,$confname,$phase,$role,$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal);
1.6 raeburn 1230: $datatable .= '</tr></table></td></tr>';
1231: return $datatable;
1232: }
1233:
1.200 raeburn 1234: sub role_defaults {
1235: my ($role,$bgs,$links,$images,$logintext) = @_;
1.202 raeburn 1236: my %defaults;
1237: unless ((ref($bgs) eq 'ARRAY') && (ref($links) eq 'ARRAY') && (ref($images) eq 'ARRAY')) {
1.200 raeburn 1238: return %defaults;
1239: }
1240: my %defaultdesign = %Apache::loncommon::defaultdesign;
1241: if ($role eq 'login') {
1242: %defaults = (
1243: font => $defaultdesign{$role.'.font'},
1244: );
1245: if (ref($logintext) eq 'ARRAY') {
1246: foreach my $item (@{$logintext}) {
1247: $defaults{'logintext'}{$item} = $defaultdesign{$role.'.'.$item};
1248: }
1249: }
1250: foreach my $item (@{$images}) {
1251: $defaults{'showlogo'}{$item} = 1;
1252: }
1253: } else {
1254: %defaults = (
1255: img => $defaultdesign{$role.'.img'},
1256: font => $defaultdesign{$role.'.font'},
1257: fontmenu => $defaultdesign{$role.'.fontmenu'},
1258: );
1259: }
1260: foreach my $item (@{$bgs}) {
1261: $defaults{'bgs'}{$item} = $defaultdesign{$role.'.'.$item};
1262: }
1263: foreach my $item (@{$links}) {
1264: $defaults{'links'}{$item} = $defaultdesign{$role.'.'.$item};
1265: }
1266: foreach my $item (@{$images}) {
1267: $defaults{$item} = $defaultdesign{$role.'.'.$item};
1268: }
1269: return %defaults;
1270: }
1271:
1.6 raeburn 1272: sub display_color_options {
1.9 raeburn 1273: my ($dom,$confname,$phase,$role,$itemcount,$choices,$is_custom,$defaults,$designs,
1.135 bisitz 1274: $images,$bgs,$links,$alt_text,$rowtotal,$logintext) = @_;
1.159 raeburn 1275: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.6 raeburn 1276: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.176 raeburn 1277: my $datatable = '<tr'.$css_class.'>'.
1.6 raeburn 1278: '<td>'.$choices->{'font'}.'</td>';
1279: if (!$is_custom->{'font'}) {
1.30 raeburn 1280: $datatable .= '<td>'.&mt('Default in use:').' <span id="css_default_'.$role.'_font" style="color: '.$defaults->{'font'}.';">'.$defaults->{'font'}.'</span></td>';
1.6 raeburn 1281: } else {
1282: $datatable .= '<td> </td>';
1283: }
1.174 foxr 1284: my $current_color = $designs->{'font'} ? $designs->{'font'} : $defaults->{'font'};
1285:
1.8 raeburn 1286: $datatable .= '<td><span class="LC_nobreak">'.
1.174 foxr 1287: '<input type="text" class="colorchooser" size="10" name="'.$role.'_font"'.
1.202 raeburn 1288: ' value="'.$current_color.'" /> '.
1.174 foxr 1289: ' </td></tr>';
1.107 raeburn 1290: unless ($role eq 'login') {
1291: $datatable .= '<tr'.$css_class.'>'.
1292: '<td>'.$choices->{'fontmenu'}.'</td>';
1293: if (!$is_custom->{'fontmenu'}) {
1294: $datatable .= '<td>'.&mt('Default in use:').' <span id="css_default_'.$role.'_font" style="color: '.$defaults->{'fontmenu'}.';">'.$defaults->{'fontmenu'}.'</span></td>';
1295: } else {
1296: $datatable .= '<td> </td>';
1297: }
1.202 raeburn 1298: $current_color = $designs->{'fontmenu'} ?
1.174 foxr 1299: $designs->{'fontmenu'} : $defaults->{'fontmenu'};
1.107 raeburn 1300: $datatable .= '<td><span class="LC_nobreak">'.
1.174 foxr 1301: '<input class="colorchooser" type="text" size="10" name="'
1302: .$role.'_fontmenu"'.
1303: ' value="'.$current_color.'" /> '.
1304: ' </td></tr>';
1.97 tempelho 1305: }
1.9 raeburn 1306: my $switchserver = &check_switchserver($dom,$confname);
1.6 raeburn 1307: foreach my $img (@{$images}) {
1.18 albertel 1308: $itemcount ++;
1.6 raeburn 1309: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.8 raeburn 1310: $datatable .= '<tr'.$css_class.'>'.
1.70 raeburn 1311: '<td>'.$choices->{$img};
1.41 raeburn 1312: my ($imgfile,$img_import,$login_hdr_pick,$logincolors);
1.70 raeburn 1313: if ($role eq 'login') {
1314: if ($img eq 'login') {
1315: $login_hdr_pick =
1.135 bisitz 1316: &login_header_options($img,$role,$defaults,$is_custom,$choices);
1.70 raeburn 1317: $logincolors =
1318: &login_text_colors($img,$role,$logintext,$phase,$choices,
1.201 raeburn 1319: $designs,$defaults);
1.70 raeburn 1320: } elsif ($img ne 'domlogo') {
1321: $datatable.= &logo_display_options($img,$defaults,$designs);
1322: }
1323: }
1324: $datatable .= '</td>';
1.6 raeburn 1325: if ($designs->{$img} ne '') {
1326: $imgfile = $designs->{$img};
1.18 albertel 1327: $img_import = ($imgfile =~ m{^/adm/});
1.6 raeburn 1328: } else {
1329: $imgfile = $defaults->{$img};
1330: }
1331: if ($imgfile) {
1.9 raeburn 1332: my ($showfile,$fullsize);
1333: if ($imgfile =~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
1.6 raeburn 1334: my $urldir = $1;
1335: my $filename = $2;
1336: my @info = &Apache::lonnet::stat_file($designs->{$img});
1337: if (@info) {
1338: my $thumbfile = 'tn-'.$filename;
1339: my @thumb=&Apache::lonnet::stat_file($urldir.'/'.$thumbfile);
1340: if (@thumb) {
1341: $showfile = $urldir.'/'.$thumbfile;
1342: } else {
1343: $showfile = $imgfile;
1344: }
1345: } else {
1346: $showfile = '';
1347: }
1348: } elsif ($imgfile =~ m-^/(adm/[^/]+)/([^/]+)$-) {
1.16 raeburn 1349: $showfile = $imgfile;
1.6 raeburn 1350: my $imgdir = $1;
1351: my $filename = $2;
1.159 raeburn 1352: if (-e "$londocroot/$imgdir/tn-".$filename) {
1.6 raeburn 1353: $showfile = "/$imgdir/tn-".$filename;
1354: } else {
1.159 raeburn 1355: my $input = $londocroot.$imgfile;
1356: my $output = "$londocroot/$imgdir/tn-".$filename;
1.6 raeburn 1357: if (!-e $output) {
1.9 raeburn 1358: my ($width,$height) = &thumb_dimensions();
1.16 raeburn 1359: my ($fullwidth,$fullheight) = &check_dimensions($input);
1360: if ($fullwidth ne '' && $fullheight ne '') {
1361: if ($fullwidth > $width && $fullheight > $height) {
1362: my $size = $width.'x'.$height;
1363: system("convert -sample $size $input $output");
1.159 raeburn 1364: $showfile = "/$imgdir/tn-".$filename;
1.16 raeburn 1365: }
1366: }
1.6 raeburn 1367: }
1368: }
1.16 raeburn 1369: }
1.6 raeburn 1370: if ($showfile) {
1.40 raeburn 1371: if ($showfile =~ m{^/(adm|res)/}) {
1372: if ($showfile =~ m{^/res/}) {
1373: my $local_showfile =
1374: &Apache::lonnet::filelocation('',$showfile);
1375: &Apache::lonnet::repcopy($local_showfile);
1376: }
1377: $showfile = &Apache::loncommon::lonhttpdurl($showfile);
1378: }
1379: if ($imgfile) {
1380: if ($imgfile =~ m{^/(adm|res)/}) {
1381: if ($imgfile =~ m{^/res/}) {
1382: my $local_imgfile =
1383: &Apache::lonnet::filelocation('',$imgfile);
1384: &Apache::lonnet::repcopy($local_imgfile);
1385: }
1386: $fullsize = &Apache::loncommon::lonhttpdurl($imgfile);
1387: } else {
1388: $fullsize = $imgfile;
1389: }
1390: }
1.41 raeburn 1391: $datatable .= '<td>';
1392: if ($img eq 'login') {
1.135 bisitz 1393: $datatable .= $login_hdr_pick;
1394: }
1.41 raeburn 1395: $datatable .= &image_changes($is_custom->{$img},$alt_text->{$img},$img_import,
1396: $showfile,$fullsize,$role,$img,$imgfile,$logincolors);
1.6 raeburn 1397: } else {
1.201 raeburn 1398: $datatable .= '<td> </td><td class="LC_left_item">'.
1399: &mt('Upload:').'<br />';
1.6 raeburn 1400: }
1401: } else {
1.201 raeburn 1402: $datatable .= '<td> </td><td class="LC_left_item">'.
1403: &mt('Upload:').'<br />';
1.6 raeburn 1404: }
1.9 raeburn 1405: if ($switchserver) {
1406: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1407: } else {
1.135 bisitz 1408: if ($img ne 'login') { # suppress file selection for Log-in header
1409: $datatable .=' <input type="file" name="'.$role.'_'.$img.'" />';
1410: }
1.9 raeburn 1411: }
1412: $datatable .= '</td></tr>';
1.6 raeburn 1413: }
1414: $itemcount ++;
1415: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1416: $datatable .= '<tr'.$css_class.'>'.
1417: '<td>'.$choices->{'bgs'}.'</td>';
1418: my $bgs_def;
1419: foreach my $item (@{$bgs}) {
1420: if (!$is_custom->{$item}) {
1.70 raeburn 1421: $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 1422: }
1423: }
1424: if ($bgs_def) {
1.8 raeburn 1425: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$bgs_def.'</tr></table></td>';
1.6 raeburn 1426: } else {
1427: $datatable .= '<td> </td>';
1428: }
1429: $datatable .= '<td class="LC_right_item">'.
1430: '<table border="0"><tr>';
1.174 foxr 1431:
1.6 raeburn 1432: foreach my $item (@{$bgs}) {
1.201 raeburn 1433: $datatable .= '<td align="center">'.$choices->{$item};
1.174 foxr 1434: my $color = $designs->{'bgs'}{$item} ? $designs->{'bgs'}{$item} : $defaults->{'bgs'}{$item};
1.6 raeburn 1435: if ($designs->{'bgs'}{$item}) {
1.174 foxr 1436: $datatable .= ' ';
1.6 raeburn 1437: }
1.174 foxr 1438: $datatable .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1.41 raeburn 1439: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.6 raeburn 1440: }
1441: $datatable .= '</tr></table></td></tr>';
1442: $itemcount ++;
1443: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1444: $datatable .= '<tr'.$css_class.'>'.
1445: '<td>'.$choices->{'links'}.'</td>';
1446: my $links_def;
1447: foreach my $item (@{$links}) {
1448: if (!$is_custom->{$item}) {
1.30 raeburn 1449: $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 1450: }
1451: }
1452: if ($links_def) {
1.8 raeburn 1453: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$links_def.'</tr></table></td>';
1.6 raeburn 1454: } else {
1455: $datatable .= '<td> </td>';
1456: }
1457: $datatable .= '<td class="LC_right_item">'.
1458: '<table border="0"><tr>';
1459: foreach my $item (@{$links}) {
1.174 foxr 1460: my $color = $designs->{'link'}{$item} ? $designs->{'link'}{$item} : $defaults->{'links'}{$item};
1.201 raeburn 1461: $datatable .= '<td align="center">'.$choices->{$item}."\n";
1.6 raeburn 1462: if ($designs->{'links'}{$item}) {
1.174 foxr 1463: $datatable.=' ';
1.6 raeburn 1464: }
1.174 foxr 1465: $datatable .= '<br /><input type="text" size="8" class="colorchooser" name="'.$role.'_'.$item.'" value="'.$color.
1.6 raeburn 1466: '" /></td>';
1467: }
1.30 raeburn 1468: $$rowtotal += $itemcount;
1.3 raeburn 1469: return $datatable;
1470: }
1471:
1.70 raeburn 1472: sub logo_display_options {
1473: my ($img,$defaults,$designs) = @_;
1474: my $checkedon;
1475: if (ref($defaults) eq 'HASH') {
1476: if (ref($defaults->{'showlogo'}) eq 'HASH') {
1477: if ($defaults->{'showlogo'}{$img}) {
1478: $checkedon = 'checked="checked" ';
1479: }
1480: }
1481: }
1482: if (ref($designs) eq 'HASH') {
1483: if (ref($designs->{'showlogo'}) eq 'HASH') {
1484: if (defined($designs->{'showlogo'}{$img})) {
1485: if ($designs->{'showlogo'}{$img} == 0) {
1486: $checkedon = '';
1487: } elsif ($designs->{'showlogo'}{$img} == 1) {
1488: $checkedon = 'checked="checked" ';
1489: }
1490: }
1491: }
1492: }
1493: return '<br /><label> <input type="checkbox" name="'.
1494: 'login_showlogo_'.$img.'" value="1" '.$checkedon.'/>'.
1495: &mt('show').'</label>'."\n";
1496: }
1497:
1.41 raeburn 1498: sub login_header_options {
1.135 bisitz 1499: my ($img,$role,$defaults,$is_custom,$choices) = @_;
1500: my $output = '';
1.41 raeburn 1501: if ((!$is_custom->{'textcol'}) || (!$is_custom->{'bgcol'})) {
1.135 bisitz 1502: $output .= &mt('Text default(s):').'<br />';
1.41 raeburn 1503: if (!$is_custom->{'textcol'}) {
1504: $output .= $choices->{'textcol'}.': '.$defaults->{'logintext'}{'textcol'}.
1505: ' ';
1506: }
1507: if (!$is_custom->{'bgcol'}) {
1508: $output .= $choices->{'bgcol'}.': '.
1509: '<span id="css_'.$role.'_font" style="background-color: '.
1510: $defaults->{'logintext'}{'bgcol'}.';"> </span>';
1511: }
1512: $output .= '<br />';
1513: }
1514: $output .='<br />';
1515: return $output;
1516: }
1517:
1518: sub login_text_colors {
1.201 raeburn 1519: my ($img,$role,$logintext,$phase,$choices,$designs,$defaults) = @_;
1.41 raeburn 1520: my $color_menu = '<table border="0"><tr>';
1521: foreach my $item (@{$logintext}) {
1.201 raeburn 1522: $color_menu .= '<td align="center">'.$choices->{$item};
1523: my $color = $designs->{'logintext'}{$item} ? $designs->{'logintext'}{$item} : $defaults->{'logintext'}{$item};
1524: $color_menu .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1525: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.41 raeburn 1526: }
1527: $color_menu .= '</tr></table><br />';
1528: return $color_menu;
1529: }
1530:
1531: sub image_changes {
1532: my ($is_custom,$alt_text,$img_import,$showfile,$fullsize,$role,$img,$imgfile,$logincolors) = @_;
1533: my $output;
1.135 bisitz 1534: if ($img eq 'login') {
1535: # suppress image for Log-in header
1536: } elsif (!$is_custom) {
1.70 raeburn 1537: if ($img ne 'domlogo') {
1.41 raeburn 1538: $output .= &mt('Default image:').'<br />';
1539: } else {
1540: $output .= &mt('Default in use:').'<br />';
1541: }
1542: }
1.135 bisitz 1543: if ($img eq 'login') { # suppress image for Log-in header
1544: $output .= '<td>'.$logincolors;
1.41 raeburn 1545: } else {
1.135 bisitz 1546: if ($img_import) {
1547: $output .= '<input type="hidden" name="'.$role.'_import_'.$img.'" value="'.$imgfile.'" />';
1548: }
1549: $output .= '<a href="'.$fullsize.'" target="_blank"><img src="'.
1550: $showfile.'" alt="'.$alt_text.'" border="0" /></a></td>';
1551: if ($is_custom) {
1552: $output .= '<td>'.$logincolors.'<span class="LC_nobreak"><label>'.
1553: '<input type="checkbox" name="'.
1554: $role.'_del_'.$img.'" value="1" />'.&mt('Delete?').
1555: '</label> '.&mt('Replace:').'</span><br />';
1556: } else {
1.201 raeburn 1557: $output .= '<td valign="middle">'.$logincolors.&mt('Upload:').'<br />';
1.135 bisitz 1558: }
1.41 raeburn 1559: }
1560: return $output;
1561: }
1562:
1.3 raeburn 1563: sub print_quotas {
1.86 raeburn 1564: my ($dom,$settings,$rowtotal,$action) = @_;
1565: my $context;
1566: if ($action eq 'quotas') {
1567: $context = 'tools';
1568: } else {
1569: $context = $action;
1570: }
1.197 raeburn 1571: my ($datatable,$defaultquota,$authorquota,@usertools,@options,%validations);
1.44 raeburn 1572: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.3 raeburn 1573: my $typecount = 0;
1.101 raeburn 1574: my ($css_class,%titles);
1.86 raeburn 1575: if ($context eq 'requestcourses') {
1.216 raeburn 1576: @usertools = ('official','unofficial','community','textbook');
1.106 raeburn 1577: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 1578: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
1579: %titles = &courserequest_titles();
1.163 raeburn 1580: } elsif ($context eq 'requestauthor') {
1581: @usertools = ('author');
1582: @options = ('norequest','approval','automatic');
1.210 raeburn 1583: %titles = &authorrequest_titles();
1.86 raeburn 1584: } else {
1.162 raeburn 1585: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 1586: %titles = &tool_titles();
1.86 raeburn 1587: }
1.26 raeburn 1588: if (ref($types) eq 'ARRAY') {
1.23 raeburn 1589: foreach my $type (@{$types}) {
1.197 raeburn 1590: my ($currdefquota,$currauthorquota);
1.163 raeburn 1591: unless (($context eq 'requestcourses') ||
1592: ($context eq 'requestauthor')) {
1.86 raeburn 1593: if (ref($settings) eq 'HASH') {
1594: if (ref($settings->{defaultquota}) eq 'HASH') {
1.197 raeburn 1595: $currdefquota = $settings->{defaultquota}->{$type};
1.86 raeburn 1596: } else {
1597: $currdefquota = $settings->{$type};
1598: }
1.197 raeburn 1599: if (ref($settings->{authorquota}) eq 'HASH') {
1600: $currauthorquota = $settings->{authorquota}->{$type};
1601: }
1.78 raeburn 1602: }
1.72 raeburn 1603: }
1.3 raeburn 1604: if (defined($usertypes->{$type})) {
1605: $typecount ++;
1606: $css_class = $typecount%2?' class="LC_odd_row"':'';
1.72 raeburn 1607: $datatable .= '<tr'.$css_class.'>'.
1.3 raeburn 1608: '<td>'.$usertypes->{$type}.'</td>'.
1.72 raeburn 1609: '<td class="LC_left_item">';
1.101 raeburn 1610: if ($context eq 'requestcourses') {
1611: $datatable .= '<table><tr>';
1612: }
1613: my %cell;
1.72 raeburn 1614: foreach my $item (@usertools) {
1.101 raeburn 1615: if ($context eq 'requestcourses') {
1616: my ($curroption,$currlimit);
1617: if (ref($settings) eq 'HASH') {
1618: if (ref($settings->{$item}) eq 'HASH') {
1619: $curroption = $settings->{$item}->{$type};
1620: if ($curroption =~ /^autolimit=(\d*)$/) {
1621: $currlimit = $1;
1622: }
1623: }
1624: }
1625: if (!$curroption) {
1626: $curroption = 'norequest';
1627: }
1628: $datatable .= '<th>'.$titles{$item}.'</th>';
1629: foreach my $option (@options) {
1630: my $val = $option;
1631: if ($option eq 'norequest') {
1632: $val = 0;
1633: }
1634: if ($option eq 'validate') {
1635: my $canvalidate = 0;
1636: if (ref($validations{$item}) eq 'HASH') {
1637: if ($validations{$item}{$type}) {
1638: $canvalidate = 1;
1639: }
1640: }
1641: next if (!$canvalidate);
1642: }
1643: my $checked = '';
1644: if ($option eq $curroption) {
1645: $checked = ' checked="checked"';
1646: } elsif ($option eq 'autolimit') {
1647: if ($curroption =~ /^autolimit/) {
1648: $checked = ' checked="checked"';
1649: }
1650: }
1651: $cell{$item} .= '<span class="LC_nobreak"><label>'.
1652: '<input type="radio" name="crsreq_'.$item.
1653: '_'.$type.'" value="'.$val.'"'.$checked.' />'.
1.127 raeburn 1654: $titles{$option}.'</label>';
1.101 raeburn 1655: if ($option eq 'autolimit') {
1.127 raeburn 1656: $cell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 1657: $item.'_limit_'.$type.'" size="1" '.
1.103 raeburn 1658: 'value="'.$currlimit.'" />';
1.101 raeburn 1659: }
1.127 raeburn 1660: $cell{$item} .= '</span> ';
1.103 raeburn 1661: if ($option eq 'autolimit') {
1.127 raeburn 1662: $cell{$item} .= $titles{'unlimited'};
1.103 raeburn 1663: }
1.101 raeburn 1664: }
1.163 raeburn 1665: } elsif ($context eq 'requestauthor') {
1666: my $curroption;
1667: if (ref($settings) eq 'HASH') {
1668: $curroption = $settings->{$type};
1669: }
1670: if (!$curroption) {
1671: $curroption = 'norequest';
1672: }
1673: foreach my $option (@options) {
1674: my $val = $option;
1675: if ($option eq 'norequest') {
1676: $val = 0;
1677: }
1678: my $checked = '';
1679: if ($option eq $curroption) {
1680: $checked = ' checked="checked"';
1681: }
1682: $datatable .= '<span class="LC_nobreak"><label>'.
1683: '<input type="radio" name="authorreq_'.$type.
1684: '" value="'.$val.'"'.$checked.' />'.
1685: $titles{$option}.'</label></span> ';
1686: }
1.101 raeburn 1687: } else {
1688: my $checked = 'checked="checked" ';
1689: if (ref($settings) eq 'HASH') {
1690: if (ref($settings->{$item}) eq 'HASH') {
1691: if ($settings->{$item}->{$type} == 0) {
1692: $checked = '';
1693: } elsif ($settings->{$item}->{$type} == 1) {
1694: $checked = 'checked="checked" ';
1695: }
1.78 raeburn 1696: }
1.72 raeburn 1697: }
1.101 raeburn 1698: $datatable .= '<span class="LC_nobreak"><label>'.
1699: '<input type="checkbox" name="'.$context.'_'.$item.
1700: '" value="'.$type.'" '.$checked.'/>'.$titles{$item}.
1701: '</label></span> ';
1.72 raeburn 1702: }
1.101 raeburn 1703: }
1704: if ($context eq 'requestcourses') {
1705: $datatable .= '</tr><tr>';
1706: foreach my $item (@usertools) {
1.106 raeburn 1707: $datatable .= '<td style="vertical-align: top">'.$cell{$item}.'</td>';
1.101 raeburn 1708: }
1709: $datatable .= '</tr></table>';
1.72 raeburn 1710: }
1.86 raeburn 1711: $datatable .= '</td>';
1.163 raeburn 1712: unless (($context eq 'requestcourses') ||
1713: ($context eq 'requestauthor')) {
1.86 raeburn 1714: $datatable .=
1.197 raeburn 1715: '<td class="LC_right_item">'.
1716: '<span class="LC_nobreak">'.&mt('Portfolio').': '.
1.3 raeburn 1717: '<input type="text" name="quota_'.$type.
1.72 raeburn 1718: '" value="'.$currdefquota.
1.197 raeburn 1719: '" size="5" /></span>'.(' ' x 2).
1720: '<span class="LC_nobreak">'.&mt('Authoring').': '.
1721: '<input type="text" name="authorquota_'.$type.
1722: '" value="'.$currauthorquota.
1723: '" size="5" /></span></td>';
1.86 raeburn 1724: }
1725: $datatable .= '</tr>';
1.3 raeburn 1726: }
1727: }
1728: }
1.163 raeburn 1729: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 1730: $defaultquota = '20';
1.197 raeburn 1731: $authorquota = '500';
1.86 raeburn 1732: if (ref($settings) eq 'HASH') {
1733: if (ref($settings->{'defaultquota'}) eq 'HASH') {
1734: $defaultquota = $settings->{'defaultquota'}->{'default'};
1735: } elsif (defined($settings->{'default'})) {
1736: $defaultquota = $settings->{'default'};
1737: }
1.197 raeburn 1738: if (ref($settings->{'authorquota'}) eq 'HASH') {
1739: $authorquota = $settings->{'authorquota'}->{'default'};
1740: }
1.3 raeburn 1741: }
1742: }
1743: $typecount ++;
1744: $css_class = $typecount%2?' class="LC_odd_row"':'';
1745: $datatable .= '<tr'.$css_class.'>'.
1.26 raeburn 1746: '<td>'.$othertitle.'</td>'.
1.72 raeburn 1747: '<td class="LC_left_item">';
1.101 raeburn 1748: if ($context eq 'requestcourses') {
1749: $datatable .= '<table><tr>';
1750: }
1751: my %defcell;
1.72 raeburn 1752: foreach my $item (@usertools) {
1.101 raeburn 1753: if ($context eq 'requestcourses') {
1754: my ($curroption,$currlimit);
1755: if (ref($settings) eq 'HASH') {
1756: if (ref($settings->{$item}) eq 'HASH') {
1757: $curroption = $settings->{$item}->{'default'};
1758: if ($curroption =~ /^autolimit=(\d*)$/) {
1759: $currlimit = $1;
1760: }
1761: }
1762: }
1763: if (!$curroption) {
1764: $curroption = 'norequest';
1765: }
1766: $datatable .= '<th>'.$titles{$item}.'</th>';
1767: foreach my $option (@options) {
1768: my $val = $option;
1769: if ($option eq 'norequest') {
1770: $val = 0;
1771: }
1772: if ($option eq 'validate') {
1773: my $canvalidate = 0;
1774: if (ref($validations{$item}) eq 'HASH') {
1775: if ($validations{$item}{'default'}) {
1776: $canvalidate = 1;
1777: }
1778: }
1779: next if (!$canvalidate);
1780: }
1781: my $checked = '';
1782: if ($option eq $curroption) {
1783: $checked = ' checked="checked"';
1784: } elsif ($option eq 'autolimit') {
1785: if ($curroption =~ /^autolimit/) {
1786: $checked = ' checked="checked"';
1787: }
1788: }
1789: $defcell{$item} .= '<span class="LC_nobreak"><label>'.
1790: '<input type="radio" name="crsreq_'.$item.
1791: '_default" value="'.$val.'"'.$checked.' />'.
1792: $titles{$option}.'</label>';
1793: if ($option eq 'autolimit') {
1.127 raeburn 1794: $defcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 1795: $item.'_limit_default" size="1" '.
1796: 'value="'.$currlimit.'" />';
1797: }
1.127 raeburn 1798: $defcell{$item} .= '</span> ';
1.104 raeburn 1799: if ($option eq 'autolimit') {
1.127 raeburn 1800: $defcell{$item} .= $titles{'unlimited'};
1.104 raeburn 1801: }
1.101 raeburn 1802: }
1.163 raeburn 1803: } elsif ($context eq 'requestauthor') {
1804: my $curroption;
1805: if (ref($settings) eq 'HASH') {
1.172 raeburn 1806: $curroption = $settings->{'default'};
1.163 raeburn 1807: }
1808: if (!$curroption) {
1809: $curroption = 'norequest';
1810: }
1811: foreach my $option (@options) {
1812: my $val = $option;
1813: if ($option eq 'norequest') {
1814: $val = 0;
1815: }
1816: my $checked = '';
1817: if ($option eq $curroption) {
1818: $checked = ' checked="checked"';
1819: }
1820: $datatable .= '<span class="LC_nobreak"><label>'.
1821: '<input type="radio" name="authorreq_default"'.
1822: ' value="'.$val.'"'.$checked.' />'.
1823: $titles{$option}.'</label></span> ';
1824: }
1.101 raeburn 1825: } else {
1826: my $checked = 'checked="checked" ';
1827: if (ref($settings) eq 'HASH') {
1828: if (ref($settings->{$item}) eq 'HASH') {
1829: if ($settings->{$item}->{'default'} == 0) {
1830: $checked = '';
1831: } elsif ($settings->{$item}->{'default'} == 1) {
1832: $checked = 'checked="checked" ';
1833: }
1.78 raeburn 1834: }
1.72 raeburn 1835: }
1.101 raeburn 1836: $datatable .= '<span class="LC_nobreak"><label>'.
1837: '<input type="checkbox" name="'.$context.'_'.$item.
1838: '" value="default" '.$checked.'/>'.$titles{$item}.
1839: '</label></span> ';
1840: }
1841: }
1842: if ($context eq 'requestcourses') {
1843: $datatable .= '</tr><tr>';
1844: foreach my $item (@usertools) {
1.106 raeburn 1845: $datatable .= '<td style="vertical-align: top">'.$defcell{$item}.'</td>';
1.72 raeburn 1846: }
1.101 raeburn 1847: $datatable .= '</tr></table>';
1.72 raeburn 1848: }
1.86 raeburn 1849: $datatable .= '</td>';
1.163 raeburn 1850: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.197 raeburn 1851: $datatable .= '<td class="LC_right_item">'.
1852: '<span class="LC_nobreak">'.&mt('Portfolio').': '.
1.86 raeburn 1853: '<input type="text" name="defaultquota" value="'.
1.197 raeburn 1854: $defaultquota.'" size="5" /></span>'.(' ' x2).
1855: '<span class="LC_nobreak">'.&mt('Authoring').': '.
1856: '<input type="text" name="authorquota" value="'.
1857: $authorquota.'" size="5" /></span></td>';
1.86 raeburn 1858: }
1859: $datatable .= '</tr>';
1.72 raeburn 1860: $typecount ++;
1861: $css_class = $typecount%2?' class="LC_odd_row"':'';
1862: $datatable .= '<tr'.$css_class.'>'.
1.197 raeburn 1863: '<td>'.&mt('LON-CAPA Advanced Users').'<br />';
1.104 raeburn 1864: if ($context eq 'requestcourses') {
1.109 raeburn 1865: $datatable .= &mt('(overrides affiliation, if set)').
1866: '</td>'.
1867: '<td class="LC_left_item">'.
1868: '<table><tr>';
1.101 raeburn 1869: } else {
1.109 raeburn 1870: $datatable .= &mt('(overrides affiliation, if checked)').
1871: '</td>'.
1872: '<td class="LC_left_item" colspan="2">'.
1873: '<br />';
1.101 raeburn 1874: }
1875: my %advcell;
1.72 raeburn 1876: foreach my $item (@usertools) {
1.101 raeburn 1877: if ($context eq 'requestcourses') {
1878: my ($curroption,$currlimit);
1879: if (ref($settings) eq 'HASH') {
1880: if (ref($settings->{$item}) eq 'HASH') {
1881: $curroption = $settings->{$item}->{'_LC_adv'};
1882: if ($curroption =~ /^autolimit=(\d*)$/) {
1883: $currlimit = $1;
1884: }
1885: }
1886: }
1887: $datatable .= '<th>'.$titles{$item}.'</th>';
1.104 raeburn 1888: my $checked = '';
1889: if ($curroption eq '') {
1890: $checked = ' checked="checked"';
1891: }
1892: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
1893: '<input type="radio" name="crsreq_'.$item.
1894: '__LC_adv" value=""'.$checked.' />'.
1895: &mt('No override set').'</label></span> ';
1.101 raeburn 1896: foreach my $option (@options) {
1897: my $val = $option;
1898: if ($option eq 'norequest') {
1899: $val = 0;
1900: }
1901: if ($option eq 'validate') {
1902: my $canvalidate = 0;
1903: if (ref($validations{$item}) eq 'HASH') {
1904: if ($validations{$item}{'_LC_adv'}) {
1905: $canvalidate = 1;
1906: }
1907: }
1908: next if (!$canvalidate);
1909: }
1910: my $checked = '';
1.104 raeburn 1911: if ($val eq $curroption) {
1.101 raeburn 1912: $checked = ' checked="checked"';
1913: } elsif ($option eq 'autolimit') {
1914: if ($curroption =~ /^autolimit/) {
1915: $checked = ' checked="checked"';
1916: }
1917: }
1918: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
1919: '<input type="radio" name="crsreq_'.$item.
1920: '__LC_adv" value="'.$val.'"'.$checked.' />'.
1921: $titles{$option}.'</label>';
1922: if ($option eq 'autolimit') {
1.127 raeburn 1923: $advcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 1924: $item.'_limit__LC_adv" size="1" '.
1925: 'value="'.$currlimit.'" />';
1926: }
1.127 raeburn 1927: $advcell{$item} .= '</span> ';
1.104 raeburn 1928: if ($option eq 'autolimit') {
1.127 raeburn 1929: $advcell{$item} .= $titles{'unlimited'};
1.104 raeburn 1930: }
1.101 raeburn 1931: }
1.163 raeburn 1932: } elsif ($context eq 'requestauthor') {
1933: my $curroption;
1934: if (ref($settings) eq 'HASH') {
1935: $curroption = $settings->{'_LC_adv'};
1936: }
1937: my $checked = '';
1938: if ($curroption eq '') {
1939: $checked = ' checked="checked"';
1940: }
1941: $datatable .= '<span class="LC_nobreak"><label>'.
1942: '<input type="radio" name="authorreq__LC_adv"'.
1943: ' value=""'.$checked.' />'.
1944: &mt('No override set').'</label></span> ';
1945: foreach my $option (@options) {
1946: my $val = $option;
1947: if ($option eq 'norequest') {
1948: $val = 0;
1949: }
1950: my $checked = '';
1951: if ($val eq $curroption) {
1952: $checked = ' checked="checked"';
1953: }
1954: $datatable .= '<span class="LC_nobreak"><label>'.
1.173 raeburn 1955: '<input type="radio" name="authorreq__LC_adv"'.
1956: ' value="'.$val.'"'.$checked.' />'.
1.163 raeburn 1957: $titles{$option}.'</label></span> ';
1958: }
1.101 raeburn 1959: } else {
1960: my $checked = 'checked="checked" ';
1961: if (ref($settings) eq 'HASH') {
1962: if (ref($settings->{$item}) eq 'HASH') {
1963: if ($settings->{$item}->{'_LC_adv'} == 0) {
1964: $checked = '';
1965: } elsif ($settings->{$item}->{'_LC_adv'} == 1) {
1966: $checked = 'checked="checked" ';
1967: }
1.79 raeburn 1968: }
1.72 raeburn 1969: }
1.101 raeburn 1970: $datatable .= '<span class="LC_nobreak"><label>'.
1971: '<input type="checkbox" name="'.$context.'_'.$item.
1972: '" value="_LC_adv" '.$checked.'/>'.$titles{$item}.
1973: '</label></span> ';
1974: }
1975: }
1976: if ($context eq 'requestcourses') {
1977: $datatable .= '</tr><tr>';
1978: foreach my $item (@usertools) {
1.106 raeburn 1979: $datatable .= '<td style="vertical-align: top">'.$advcell{$item}.'</td>';
1.72 raeburn 1980: }
1.101 raeburn 1981: $datatable .= '</tr></table>';
1.72 raeburn 1982: }
1.98 raeburn 1983: $datatable .= '</td></tr>';
1.30 raeburn 1984: $$rowtotal += $typecount;
1.3 raeburn 1985: return $datatable;
1986: }
1987:
1.163 raeburn 1988: sub print_requestmail {
1989: my ($dom,$action,$settings,$rowtotal) = @_;
1.208 raeburn 1990: my ($now,$datatable,%currapp);
1.102 raeburn 1991: $now = time;
1992: if (ref($settings) eq 'HASH') {
1993: if (ref($settings->{'notify'}) eq 'HASH') {
1994: if ($settings->{'notify'}{'approval'} ne '') {
1.224 raeburn 1995: map {$currapp{$_}=1;} split(/,/,$settings->{'notify'}{'approval'});
1.102 raeburn 1996: }
1997: }
1998: }
1.191 raeburn 1999: my $numinrow = 2;
1.224 raeburn 2000: my $css_class;
2001: $css_class = ($$rowtotal%2? ' class="LC_odd_row"':'');
1.163 raeburn 2002: my $text;
2003: if ($action eq 'requestcourses') {
2004: $text = &mt('Receive notification of course requests requiring approval');
1.224 raeburn 2005: } elsif ($action eq 'requestauthor') {
2006: $text = &mt('Receive notification of Authoring Space requests requiring approval');
1.163 raeburn 2007: } else {
1.224 raeburn 2008: $text = &mt('Receive notification of queued requests for self-created user accounts requiring approval');
1.163 raeburn 2009: }
1.224 raeburn 2010: $datatable = '<tr'.$css_class.'>'.
1.163 raeburn 2011: ' <td>'.$text.'</td>'.
1.102 raeburn 2012: ' <td class="LC_left_item">';
1.191 raeburn 2013: my ($numdc,$table,$rows) = &active_dc_picker($dom,$numinrow,'checkbox',
1.224 raeburn 2014: $action.'notifyapproval',%currapp);
1.191 raeburn 2015: if ($numdc > 0) {
2016: $datatable .= $table;
1.102 raeburn 2017: } else {
2018: $datatable .= &mt('There are no active Domain Coordinators');
2019: }
2020: $datatable .='</td></tr>';
2021: $$rowtotal += $rows;
2022: return $datatable;
2023: }
2024:
1.216 raeburn 2025: sub print_studentcode {
2026: my ($settings,$rowtotal) = @_;
2027: my $rownum = 0;
1.218 raeburn 2028: my ($output,%current);
2029: my @crstypes = ('official','unofficial','community','textbook');
2030: if (ref($settings->{'uniquecode'}) eq 'HASH') {
2031: foreach my $type (@crstypes) {
2032: $current{$type} = $settings->{'uniquecode'}{$type};
2033: }
2034: }
2035: $output .= '<tr>'.
2036: '<td class="LC_left_item">'.&mt('Generate unique six character code as course identifier?').'</td>'.
2037: '<td class="LC_left_item">';
2038: foreach my $type (@crstypes) {
2039: my $check = ' ';
2040: if ($current{$type}) {
2041: $check = ' checked="checked" ';
2042: }
2043: $output .= '<span class="LC_nobreak"><label>'.
2044: '<input type="checkbox" name="uniquecode" value="'.$type.'"'.$check.'/>'.
2045: &mt($type).'</label></span>'.(' 'x2).' ';
2046: }
2047: $output .= '</td></tr>';
2048: $$rowtotal ++;
2049: return $output;
1.216 raeburn 2050: }
2051:
2052: sub print_textbookcourses {
2053: my ($dom,$settings,$rowtotal) = @_;
2054: my $rownum = 0;
2055: my $css_class;
2056: my $itemcount = 1;
2057: my $maxnum = 0;
2058: my $bookshash;
2059: if (ref($settings) eq 'HASH') {
2060: $bookshash = $settings->{'textbooks'};
2061: }
2062: my %ordered;
2063: if (ref($bookshash) eq 'HASH') {
2064: foreach my $item (keys(%{$bookshash})) {
2065: if (ref($bookshash->{$item}) eq 'HASH') {
2066: my $num = $bookshash->{$item}{'order'};
2067: $ordered{$num} = $item;
2068: }
2069: }
2070: }
2071: my $confname = $dom.'-domainconfig';
2072: my $switchserver = &check_switchserver($dom,$confname);
2073: my $maxnum = scalar(keys(%ordered));
1.217 raeburn 2074: my $datatable = &textbookcourses_javascript(\%ordered);
1.216 raeburn 2075: if (keys(%ordered)) {
2076: my @items = sort { $a <=> $b } keys(%ordered);
2077: for (my $i=0; $i<@items; $i++) {
2078: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2079: my $key = $ordered{$items[$i]};
2080: my %coursehash=&Apache::lonnet::coursedescription($key);
2081: my $coursetitle = $coursehash{'description'};
2082: my ($subject,$title,$author,$image,$imgsrc,$cdom,$cnum);
2083: if (ref($bookshash->{$key}) eq 'HASH') {
2084: $subject = $bookshash->{$key}->{'subject'};
2085: $title = $bookshash->{$key}->{'title'};
2086: $author = $bookshash->{$key}->{'author'};
2087: $image = $bookshash->{$key}->{'image'};
2088: if ($image ne '') {
2089: my ($path,$imagefile) = ($image =~ m{^(.+)/([^/]+)$});
2090: my $imagethumb = "$path/tn-".$imagefile;
2091: $imgsrc = '<img src="'.$imagethumb.'" alt="'.&mt('Textbook image').'" />';
2092: }
2093: }
1.217 raeburn 2094: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$key'".');"';
1.216 raeburn 2095: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
2096: .'<select name="'.$key.'"'.$chgstr.'>';
2097: for (my $k=0; $k<=$maxnum; $k++) {
2098: my $vpos = $k+1;
2099: my $selstr;
2100: if ($k == $i) {
2101: $selstr = ' selected="selected" ';
2102: }
2103: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2104: }
2105: $datatable .= '</select>'.(' 'x2).
2106: '<label><input type="checkbox" name="book_del" value="'.$key.'" />'.
2107: &mt('Delete?').'</label></span></td>'.
2108: '<td colspan="2">'.
2109: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="book_subject_'.$i.'" value="'.$subject.'" /></span> '.
2110: (' 'x2).
2111: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="book_title_'.$i.'" value="'.$title.'" /></span> '.
2112: (' 'x2).
2113: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="book_author_'.$i.'" value="'.$author.'" /></span> '.
2114: (' 'x2).
2115: '<span class="LC_nobreak">'.&mt('Thumbnail:');
2116: if ($image) {
2117: $datatable .= '<span class="LC_nobreak">'.
2118: $imgsrc.
2119: '<label><input type="checkbox" name="book_image_del"'.
2120: ' value="'.$key.'" />'.&mt('Delete?').'</label></span> '.
2121: '<span class="LC_nobreak"> '.&mt('Replace:').' ';
2122: }
2123: if ($switchserver) {
2124: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2125: } else {
2126: $datatable .= '<input type="file" name="book_image_'.$i.'" value="" />';
2127: }
2128: $datatable .= '<input type="hidden" name="book_id_'.$i.'" value="'.$key.'" /></span> '.
2129: '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
2130: $coursetitle.'</span></td></tr>'."\n";
2131: $itemcount ++;
2132: }
2133: }
2134: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.217 raeburn 2135: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'addbook_pos'".');"';
1.216 raeburn 2136: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
2137: '<input type="hidden" name="book_maxnum" value="'.$maxnum.'" />'."\n".
2138: '<select name="addbook_pos"'.$chgstr.'>';
2139: for (my $k=0; $k<$maxnum+1; $k++) {
2140: my $vpos = $k+1;
2141: my $selstr;
2142: if ($k == $maxnum) {
2143: $selstr = ' selected="selected" ';
2144: }
2145: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2146: }
2147: $datatable .= '</select> '."\n".
2148: '<input type="checkbox" name="addbook" value="1" />'.&mt('Add').'</td>'."\n".
2149: '<td colspan="2">'.
2150: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="addbook_subject" value="" /></span> '."\n".
2151: (' 'x2).
2152: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="addbook_title" value="" /></span> '."\n".
2153: (' 'x2).
2154: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="addbook_author" value="" /></span> '."\n".
2155: (' 'x2).
2156: '<span class="LC_nobreak">'.&mt('Image:').' ';
2157: if ($switchserver) {
2158: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2159: } else {
2160: $datatable .= '<input type="file" name="addbook_image" value="" />';
2161: }
2162: $datatable .= '</span>'."\n".
2163: '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
2164: &Apache::loncommon::select_dom_form($env{'request.role.domain'},'addbook_cdom').
2165: '<input type="text" size="25" name="addbook_cnum" value="" />'.
2166: &Apache::loncommon::selectcourse_link
2167: ('display','addbook_cnum','addbook_cdom',undef,undef,undef,'Course');
2168: '</span></td>'."\n".
2169: '</tr>'."\n";
2170: $itemcount ++;
2171: return $datatable;
2172: }
2173:
1.217 raeburn 2174: sub textbookcourses_javascript {
2175: my ($textbooks) = @_;
2176: return unless(ref($textbooks) eq 'HASH');
2177: my $num = scalar(keys(%{$textbooks}));
2178: my @jsarray;
2179: foreach my $item (sort {$a <=> $b } (keys(%{$textbooks}))) {
2180: push(@jsarray,$textbooks->{$item});
2181: }
2182: my $jstext = ' var textbooks = Array('."'".join("','",@jsarray)."'".');'."\n";
2183: return <<"ENDSCRIPT";
2184: <script type="text/javascript">
2185: // <![CDATA[
2186: function reorderBooks(form,item) {
2187: var changedVal;
2188: $jstext
2189: var newpos = 'addbook_pos';
2190: var current = new Array;
2191: var maxh = 1 + $num;
2192: var current = new Array;
2193: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
2194: if (item == newpos) {
2195: changedVal = newitemVal;
2196: } else {
2197: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
2198: current[newitemVal] = newpos;
2199: }
2200: for (var i=0; i<textbooks.length; i++) {
2201: var elementName = textbooks[i];
2202: if (elementName != item) {
2203: if (form.elements[elementName]) {
2204: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2205: current[currVal] = elementName;
2206: }
2207: }
2208: }
2209: var oldVal;
2210: for (var j=0; j<maxh; j++) {
2211: if (current[j] == undefined) {
2212: oldVal = j;
2213: }
2214: }
2215: if (oldVal < changedVal) {
2216: for (var k=oldVal+1; k<=changedVal ; k++) {
2217: var elementName = current[k];
2218: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
2219: }
2220: } else {
2221: for (var k=changedVal; k<oldVal; k++) {
2222: var elementName = current[k];
2223: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
2224: }
2225: }
2226: return;
2227: }
2228:
2229: // ]]>
2230: </script>
2231:
2232: ENDSCRIPT
2233: }
2234:
1.3 raeburn 2235: sub print_autoenroll {
1.30 raeburn 2236: my ($dom,$settings,$rowtotal) = @_;
1.3 raeburn 2237: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
1.129 raeburn 2238: my ($defdom,$runon,$runoff,$coownerson,$coownersoff);
1.3 raeburn 2239: if (ref($settings) eq 'HASH') {
2240: if (exists($settings->{'run'})) {
2241: if ($settings->{'run'} eq '0') {
2242: $runoff = ' checked="checked" ';
2243: $runon = ' ';
2244: } else {
2245: $runon = ' checked="checked" ';
2246: $runoff = ' ';
2247: }
2248: } else {
2249: if ($autorun) {
2250: $runon = ' checked="checked" ';
2251: $runoff = ' ';
2252: } else {
2253: $runoff = ' checked="checked" ';
2254: $runon = ' ';
2255: }
2256: }
1.129 raeburn 2257: if (exists($settings->{'co-owners'})) {
2258: if ($settings->{'co-owners'} eq '0') {
2259: $coownersoff = ' checked="checked" ';
2260: $coownerson = ' ';
2261: } else {
2262: $coownerson = ' checked="checked" ';
2263: $coownersoff = ' ';
2264: }
2265: } else {
2266: $coownersoff = ' checked="checked" ';
2267: $coownerson = ' ';
2268: }
1.3 raeburn 2269: if (exists($settings->{'sender_domain'})) {
2270: $defdom = $settings->{'sender_domain'};
2271: }
1.14 raeburn 2272: } else {
2273: if ($autorun) {
2274: $runon = ' checked="checked" ';
2275: $runoff = ' ';
2276: } else {
2277: $runoff = ' checked="checked" ';
2278: $runon = ' ';
2279: }
1.3 raeburn 2280: }
2281: my $domform = &Apache::loncommon::select_dom_form($defdom,'sender_domain',1);
1.39 raeburn 2282: my $notif_sender;
2283: if (ref($settings) eq 'HASH') {
2284: $notif_sender = $settings->{'sender_uname'};
2285: }
1.3 raeburn 2286: my $datatable='<tr class="LC_odd_row">'.
2287: '<td>'.&mt('Auto-enrollment active?').'</td>'.
1.8 raeburn 2288: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 2289: '<input type="radio" name="autoenroll_run"'.
1.8 raeburn 2290: $runon.' value="1" />'.&mt('Yes').'</label> '.
2291: '<label><input type="radio" name="autoenroll_run"'.
1.14 raeburn 2292: $runoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 2293: '</tr><tr>'.
2294: '<td>'.&mt('Notification messages - sender').
1.8 raeburn 2295: '</td><td class="LC_right_item"><span class="LC_nobreak">'.
1.3 raeburn 2296: &mt('username').': '.
2297: '<input type="text" name="sender_uname" value="'.
1.39 raeburn 2298: $notif_sender.'" size="10" /> '.&mt('domain').
1.129 raeburn 2299: ': '.$domform.'</span></td></tr>'.
2300: '<tr class="LC_odd_row">'.
2301: '<td>'.&mt('Automatically assign co-ownership').'</td>'.
2302: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2303: '<input type="radio" name="autoassign_coowners"'.
2304: $coownerson.' value="1" />'.&mt('Yes').'</label> '.
2305: '<label><input type="radio" name="autoassign_coowners"'.
2306: $coownersoff.' value="0" />'.&mt('No').'</label></span></td>'.
2307: '</tr>';
2308: $$rowtotal += 3;
1.3 raeburn 2309: return $datatable;
2310: }
2311:
2312: sub print_autoupdate {
1.30 raeburn 2313: my ($position,$dom,$settings,$rowtotal) = @_;
1.3 raeburn 2314: my $datatable;
2315: if ($position eq 'top') {
2316: my $updateon = ' ';
2317: my $updateoff = ' checked="checked" ';
2318: my $classlistson = ' ';
2319: my $classlistsoff = ' checked="checked" ';
2320: if (ref($settings) eq 'HASH') {
2321: if ($settings->{'run'} eq '1') {
2322: $updateon = $updateoff;
2323: $updateoff = ' ';
2324: }
2325: if ($settings->{'classlists'} eq '1') {
2326: $classlistson = $classlistsoff;
2327: $classlistsoff = ' ';
2328: }
2329: }
2330: my %title = (
2331: run => 'Auto-update active?',
2332: classlists => 'Update information in classlists?',
2333: );
2334: $datatable = '<tr class="LC_odd_row">'.
2335: '<td>'.&mt($title{'run'}).'</td>'.
1.8 raeburn 2336: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 2337: '<input type="radio" name="autoupdate_run"'.
1.8 raeburn 2338: $updateon.' value="1" />'.&mt('Yes').'</label> '.
2339: '<label><input type="radio" name="autoupdate_run"'.
2340: $updateoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 2341: '</tr><tr>'.
2342: '<td>'.&mt($title{'classlists'}).'</td>'.
1.8 raeburn 2343: '<td class="LC_right_item"><span class="LC_nobreak">'.
2344: '<label><input type="radio" name="classlists"'.
2345: $classlistson.' value="1" />'.&mt('Yes').'</label> '.
2346: '<label><input type="radio" name="classlists"'.
2347: $classlistsoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 2348: '</tr>';
1.30 raeburn 2349: $$rowtotal += 2;
1.131 raeburn 2350: } elsif ($position eq 'middle') {
2351: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
2352: my $numinrow = 3;
2353: my $locknamesettings;
2354: $datatable .= &insttypes_row($settings,$types,$usertypes,
2355: $dom,$numinrow,$othertitle,
2356: 'lockablenames');
2357: $$rowtotal ++;
1.3 raeburn 2358: } else {
1.44 raeburn 2359: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.132 raeburn 2360: my @fields = ('lastname','firstname','middlename','generation',
1.20 raeburn 2361: 'permanentemail','id');
1.33 raeburn 2362: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1.3 raeburn 2363: my $numrows = 0;
1.26 raeburn 2364: if (ref($types) eq 'ARRAY') {
2365: if (@{$types} > 0) {
2366: $datatable =
2367: &usertype_update_row($settings,$usertypes,\%fieldtitles,
2368: \@fields,$types,\$numrows);
1.30 raeburn 2369: $$rowtotal += @{$types};
1.26 raeburn 2370: }
1.3 raeburn 2371: }
2372: $datatable .=
2373: &usertype_update_row($settings,{'default' => $othertitle},
2374: \%fieldtitles,\@fields,['default'],
2375: \$numrows);
1.30 raeburn 2376: $$rowtotal ++;
1.3 raeburn 2377: }
2378: return $datatable;
2379: }
2380:
1.125 raeburn 2381: sub print_autocreate {
2382: my ($dom,$settings,$rowtotal) = @_;
1.191 raeburn 2383: my (%createon,%createoff,%currhash);
1.125 raeburn 2384: my @types = ('xml','req');
2385: if (ref($settings) eq 'HASH') {
2386: foreach my $item (@types) {
2387: $createoff{$item} = ' checked="checked" ';
2388: $createon{$item} = ' ';
2389: if (exists($settings->{$item})) {
2390: if ($settings->{$item}) {
2391: $createon{$item} = ' checked="checked" ';
2392: $createoff{$item} = ' ';
2393: }
2394: }
2395: }
1.210 raeburn 2396: if ($settings->{'xmldc'} ne '') {
1.191 raeburn 2397: $currhash{$settings->{'xmldc'}} = 1;
2398: }
1.125 raeburn 2399: } else {
2400: foreach my $item (@types) {
2401: $createoff{$item} = ' checked="checked" ';
2402: $createon{$item} = ' ';
2403: }
2404: }
2405: $$rowtotal += 2;
1.191 raeburn 2406: my $numinrow = 2;
1.125 raeburn 2407: my $datatable='<tr class="LC_odd_row">'.
2408: '<td>'.&mt('Create pending official courses from XML files').'</td>'.
2409: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2410: '<input type="radio" name="autocreate_xml"'.
2411: $createon{'xml'}.' value="1" />'.&mt('Yes').'</label> '.
2412: '<label><input type="radio" name="autocreate_xml"'.
1.143 raeburn 2413: $createoff{'xml'}.' value="0" />'.&mt('No').'</label></span>'.
2414: '</td></tr><tr>'.
2415: '<td>'.&mt('Create pending requests for official courses (if validated)').'</td>'.
2416: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2417: '<input type="radio" name="autocreate_req"'.
2418: $createon{'req'}.' value="1" />'.&mt('Yes').'</label> '.
2419: '<label><input type="radio" name="autocreate_req"'.
2420: $createoff{'req'}.' value="0" />'.&mt('No').'</label></span>';
1.191 raeburn 2421: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
2422: 'autocreate_xmldc',%currhash);
1.125 raeburn 2423: if ($numdc > 1) {
1.143 raeburn 2424: $datatable .= '</td></tr><tr class="LC_odd_row"><td>'.
2425: &mt('Course creation processed as: (choose Dom. Coord.)').
2426: '</td><td class="LC_left_item">'.$dctable.'</td></tr>';
1.125 raeburn 2427: } else {
1.143 raeburn 2428: $datatable .= $dctable.'</td></tr>';
1.125 raeburn 2429: }
1.191 raeburn 2430: $$rowtotal += $rows;
1.125 raeburn 2431: return $datatable;
2432: }
2433:
1.23 raeburn 2434: sub print_directorysrch {
1.30 raeburn 2435: my ($dom,$settings,$rowtotal) = @_;
1.23 raeburn 2436: my $srchon = ' ';
2437: my $srchoff = ' checked="checked" ';
1.25 raeburn 2438: my ($exacton,$containson,$beginson);
1.24 raeburn 2439: my $localon = ' ';
2440: my $localoff = ' checked="checked" ';
1.23 raeburn 2441: if (ref($settings) eq 'HASH') {
2442: if ($settings->{'available'} eq '1') {
2443: $srchon = $srchoff;
2444: $srchoff = ' ';
2445: }
1.24 raeburn 2446: if ($settings->{'localonly'} eq '1') {
2447: $localon = $localoff;
2448: $localoff = ' ';
2449: }
1.25 raeburn 2450: if (ref($settings->{'searchtypes'}) eq 'ARRAY') {
2451: foreach my $type (@{$settings->{'searchtypes'}}) {
2452: if ($type eq 'exact') {
2453: $exacton = ' checked="checked" ';
2454: } elsif ($type eq 'contains') {
2455: $containson = ' checked="checked" ';
2456: } elsif ($type eq 'begins') {
2457: $beginson = ' checked="checked" ';
2458: }
2459: }
2460: } else {
2461: if ($settings->{'searchtypes'} eq 'exact') {
2462: $exacton = ' checked="checked" ';
2463: } elsif ($settings->{'searchtypes'} eq 'contains') {
2464: $containson = ' checked="checked" ';
2465: } elsif ($settings->{'searchtypes'} eq 'specify') {
2466: $exacton = ' checked="checked" ';
2467: $containson = ' checked="checked" ';
2468: }
1.23 raeburn 2469: }
2470: }
2471: my ($searchtitles,$titleorder) = &sorted_searchtitles();
1.45 raeburn 2472: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.23 raeburn 2473:
2474: my $numinrow = 4;
1.26 raeburn 2475: my $cansrchrow = 0;
1.23 raeburn 2476: my $datatable='<tr class="LC_odd_row">'.
1.30 raeburn 2477: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Directory search available?').'</span></td>'.
1.23 raeburn 2478: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2479: '<input type="radio" name="dirsrch_available"'.
2480: $srchon.' value="1" />'.&mt('Yes').'</label> '.
2481: '<label><input type="radio" name="dirsrch_available"'.
2482: $srchoff.' value="0" />'.&mt('No').'</label></span></td>'.
2483: '</tr><tr>'.
1.30 raeburn 2484: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search?').'</span></td>'.
1.24 raeburn 2485: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2486: '<input type="radio" name="dirsrch_localonly"'.
2487: $localoff.' value="0" />'.&mt('Yes').'</label> '.
2488: '<label><input type="radio" name="dirsrch_localonly"'.
2489: $localon.' value="1" />'.&mt('No').'</label></span></td>'.
1.25 raeburn 2490: '</tr>';
1.30 raeburn 2491: $$rowtotal += 2;
1.26 raeburn 2492: if (ref($usertypes) eq 'HASH') {
2493: if (keys(%{$usertypes}) > 0) {
1.93 raeburn 2494: $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
2495: $numinrow,$othertitle,'cansearch');
1.26 raeburn 2496: $cansrchrow = 1;
2497: }
2498: }
2499: if ($cansrchrow) {
1.30 raeburn 2500: $$rowtotal ++;
1.26 raeburn 2501: $datatable .= '<tr>';
2502: } else {
2503: $datatable .= '<tr class="LC_odd_row">';
2504: }
1.30 raeburn 2505: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Supported search methods').
2506: '</span></td><td class="LC_left_item" colspan="2"><table><tr>';
1.25 raeburn 2507: foreach my $title (@{$titleorder}) {
2508: if (defined($searchtitles->{$title})) {
2509: my $check = ' ';
1.93 raeburn 2510: if (ref($settings) eq 'HASH') {
1.39 raeburn 2511: if (ref($settings->{'searchby'}) eq 'ARRAY') {
2512: if (grep(/^\Q$title\E$/,@{$settings->{'searchby'}})) {
2513: $check = ' checked="checked" ';
2514: }
1.25 raeburn 2515: }
2516: }
2517: $datatable .= '<td class="LC_left_item">'.
2518: '<span class="LC_nobreak"><label>'.
2519: '<input type="checkbox" name="searchby" '.
2520: 'value="'.$title.'"'.$check.'/>'.
2521: $searchtitles->{$title}.'</label></span></td>';
2522: }
2523: }
1.26 raeburn 2524: $datatable .= '</tr></table></td></tr>';
1.30 raeburn 2525: $$rowtotal ++;
1.26 raeburn 2526: if ($cansrchrow) {
2527: $datatable .= '<tr class="LC_odd_row">';
2528: } else {
2529: $datatable .= '<tr>';
2530: }
1.30 raeburn 2531: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Search latitude').'</span></td>'.
1.26 raeburn 2532: '<td class="LC_left_item" colspan="2">'.
1.25 raeburn 2533: '<span class="LC_nobreak"><label>'.
2534: '<input type="checkbox" name="searchtypes" '.
2535: $exacton.' value="exact" />'.&mt('Exact match').
2536: '</label> '.
2537: '<label><input type="checkbox" name="searchtypes" '.
2538: $beginson.' value="begins" />'.&mt('Begins with').
2539: '</label> '.
2540: '<label><input type="checkbox" name="searchtypes" '.
2541: $containson.' value="contains" />'.&mt('Contains').
2542: '</label></span></td></tr>';
1.30 raeburn 2543: $$rowtotal ++;
1.25 raeburn 2544: return $datatable;
2545: }
2546:
1.28 raeburn 2547: sub print_contacts {
1.30 raeburn 2548: my ($dom,$settings,$rowtotal) = @_;
1.28 raeburn 2549: my $datatable;
2550: my @contacts = ('adminemail','supportemail');
1.134 raeburn 2551: my (%checked,%to,%otheremails,%bccemails);
1.102 raeburn 2552: my @mailings = ('errormail','packagesmail','lonstatusmail','helpdeskmail',
1.203 raeburn 2553: 'requestsmail','updatesmail','idconflictsmail');
1.28 raeburn 2554: foreach my $type (@mailings) {
2555: $otheremails{$type} = '';
2556: }
1.134 raeburn 2557: $bccemails{'helpdeskmail'} = '';
1.28 raeburn 2558: if (ref($settings) eq 'HASH') {
2559: foreach my $item (@contacts) {
2560: if (exists($settings->{$item})) {
2561: $to{$item} = $settings->{$item};
2562: }
2563: }
2564: foreach my $type (@mailings) {
2565: if (exists($settings->{$type})) {
2566: if (ref($settings->{$type}) eq 'HASH') {
2567: foreach my $item (@contacts) {
2568: if ($settings->{$type}{$item}) {
2569: $checked{$type}{$item} = ' checked="checked" ';
2570: }
2571: }
2572: $otheremails{$type} = $settings->{$type}{'others'};
1.134 raeburn 2573: if ($type eq 'helpdeskmail') {
2574: $bccemails{$type} = $settings->{$type}{'bcc'};
2575: }
1.28 raeburn 2576: }
1.89 raeburn 2577: } elsif ($type eq 'lonstatusmail') {
2578: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
1.28 raeburn 2579: }
2580: }
2581: } else {
2582: $to{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
2583: $to{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
2584: $checked{'errormail'}{'adminemail'} = ' checked="checked" ';
2585: $checked{'packagesmail'}{'adminemail'} = ' checked="checked" ';
1.89 raeburn 2586: $checked{'helpdeskmail'}{'supportemail'} = ' checked="checked" ';
2587: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
1.102 raeburn 2588: $checked{'requestsmail'}{'adminemail'} = ' checked="checked" ';
1.190 raeburn 2589: $checked{'updatesmail'}{'adminemail'} = ' checked="checked" ';
1.203 raeburn 2590: $checked{'idconflictsmail'}{'adminemail'} = ' checked="checked" ';
1.28 raeburn 2591: }
2592: my ($titles,$short_titles) = &contact_titles();
2593: my $rownum = 0;
2594: my $css_class;
2595: foreach my $item (@contacts) {
1.69 raeburn 2596: $css_class = $rownum%2?' class="LC_odd_row"':'';
1.30 raeburn 2597: $datatable .= '<tr'.$css_class.'>'.
2598: '<td><span class="LC_nobreak">'.$titles->{$item}.
2599: '</span></td><td class="LC_right_item">'.
1.28 raeburn 2600: '<input type="text" name="'.$item.'" value="'.
2601: $to{$item}.'" /></td></tr>';
1.203 raeburn 2602: $rownum ++;
1.28 raeburn 2603: }
2604: foreach my $type (@mailings) {
1.69 raeburn 2605: $css_class = $rownum%2?' class="LC_odd_row"':'';
1.28 raeburn 2606: $datatable .= '<tr'.$css_class.'>'.
1.30 raeburn 2607: '<td><span class="LC_nobreak">'.
2608: $titles->{$type}.': </span></td>'.
1.28 raeburn 2609: '<td class="LC_left_item">'.
2610: '<span class="LC_nobreak">';
2611: foreach my $item (@contacts) {
2612: $datatable .= '<label>'.
2613: '<input type="checkbox" name="'.$type.'"'.
2614: $checked{$type}{$item}.
2615: ' value="'.$item.'" />'.$short_titles->{$item}.
2616: '</label> ';
2617: }
2618: $datatable .= '</span><br />'.&mt('Others').': '.
2619: '<input type="text" name="'.$type.'_others" '.
1.134 raeburn 2620: 'value="'.$otheremails{$type}.'" />';
2621: if ($type eq 'helpdeskmail') {
1.136 raeburn 2622: $datatable .= '<br />'.&mt('Bcc:').(' 'x6).
1.134 raeburn 2623: '<input type="text" name="'.$type.'_bcc" '.
2624: 'value="'.$bccemails{$type}.'" />';
2625: }
2626: $datatable .= '</td></tr>'."\n";
1.203 raeburn 2627: $rownum ++;
1.28 raeburn 2628: }
1.203 raeburn 2629: my %choices;
2630: $choices{'reporterrors'} = &mt('E-mail error reports to [_1]',
2631: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
2632: &mt('LON-CAPA core group - MSU'),600,500));
2633: $choices{'reportupdates'} = &mt('E-mail record of completed LON-CAPA updates to [_1]',
2634: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
2635: &mt('LON-CAPA core group - MSU'),600,500));
2636: my @toggles = ('reporterrors','reportupdates');
2637: my %defaultchecked = ('reporterrors' => 'on',
2638: 'reportupdates' => 'on');
2639: (my $reports,$rownum) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
2640: \%choices,$rownum);
2641: $datatable .= $reports;
1.30 raeburn 2642: $$rowtotal += $rownum;
1.28 raeburn 2643: return $datatable;
2644: }
2645:
1.118 jms 2646: sub print_helpsettings {
1.168 raeburn 2647: my ($dom,$confname,$settings,$rowtotal) = @_;
2648: my ($datatable,$itemcount);
1.166 raeburn 2649: $itemcount = 1;
1.168 raeburn 2650: my (%choices,%defaultchecked,@toggles);
2651: $choices{'submitbugs'} = &mt('Display link to: [_1]?',
2652: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
2653: &mt('LON-CAPA bug tracker'),600,500));
2654: %defaultchecked = ('submitbugs' => 'on');
2655: @toggles = ('submitbugs',);
1.166 raeburn 2656:
1.168 raeburn 2657: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
2658: \%choices,$itemcount);
1.166 raeburn 2659: return $datatable;
1.121 raeburn 2660: }
2661:
2662: sub radiobutton_prefs {
1.192 raeburn 2663: my ($settings,$toggles,$defaultchecked,$choices,$itemcount,$onclick,
2664: $additional) = @_;
1.121 raeburn 2665: return unless ((ref($toggles) eq 'ARRAY') && (ref($defaultchecked) eq 'HASH') &&
2666: (ref($choices) eq 'HASH'));
2667:
1.170 raeburn 2668: my (%checkedon,%checkedoff,$datatable,$css_class);
1.121 raeburn 2669:
2670: foreach my $item (@{$toggles}) {
2671: if ($defaultchecked->{$item} eq 'on') {
1.118 jms 2672: $checkedon{$item} = ' checked="checked" ';
2673: $checkedoff{$item} = ' ';
1.121 raeburn 2674: } elsif ($defaultchecked->{$item} eq 'off') {
1.118 jms 2675: $checkedoff{$item} = ' checked="checked" ';
2676: $checkedon{$item} = ' ';
2677: }
2678: }
2679: if (ref($settings) eq 'HASH') {
1.121 raeburn 2680: foreach my $item (@{$toggles}) {
1.118 jms 2681: if ($settings->{$item} eq '1') {
2682: $checkedon{$item} = ' checked="checked" ';
2683: $checkedoff{$item} = ' ';
2684: } elsif ($settings->{$item} eq '0') {
2685: $checkedoff{$item} = ' checked="checked" ';
2686: $checkedon{$item} = ' ';
2687: }
2688: }
1.121 raeburn 2689: }
1.192 raeburn 2690: if ($onclick) {
2691: $onclick = ' onclick="'.$onclick.'"';
2692: }
1.121 raeburn 2693: foreach my $item (@{$toggles}) {
1.118 jms 2694: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.121 raeburn 2695: $datatable .=
1.192 raeburn 2696: '<tr'.$css_class.'><td valign="top">'.
2697: '<span class="LC_nobreak">'.$choices->{$item}.
1.118 jms 2698: '</span></td>'.
2699: '<td class="LC_right_item"><span class="LC_nobreak">'.
2700: '<label><input type="radio" name="'.
1.192 raeburn 2701: $item.'" '.$checkedon{$item}.' value="1"'.$onclick.' />'.&mt('Yes').
1.118 jms 2702: '</label> <label><input type="radio" name="'.$item.'" '.
1.192 raeburn 2703: $checkedoff{$item}.' value="0"'.$onclick.' />'.&mt('No').'</label>'.
2704: '</span>'.$additional.
2705: '</td>'.
1.118 jms 2706: '</tr>';
2707: $itemcount ++;
1.121 raeburn 2708: }
2709: return ($datatable,$itemcount);
2710: }
2711:
2712: sub print_coursedefaults {
1.139 raeburn 2713: my ($position,$dom,$settings,$rowtotal) = @_;
1.192 raeburn 2714: my ($css_class,$datatable,%checkedon,%checkedoff,%defaultchecked,@toggles);
1.121 raeburn 2715: my $itemcount = 1;
1.192 raeburn 2716: my %choices = &Apache::lonlocal::texthash (
2717: canuse_pdfforms => 'Course/Community users can create/upload PDF forms',
1.198 raeburn 2718: uploadquota => 'Default quota for files uploaded directly to course/community using Course Editor (MB)',
1.192 raeburn 2719: anonsurvey_threshold => 'Responder count needed before showing submissions for anonymous surveys',
2720: coursecredits => 'Credits can be specified for courses',
2721: );
1.198 raeburn 2722: my %staticdefaults = (
2723: anonsurvey_threshold => 10,
2724: uploadquota => 500,
2725: );
1.139 raeburn 2726: if ($position eq 'top') {
2727: %defaultchecked = ('canuse_pdfforms' => 'off');
1.192 raeburn 2728: @toggles = ('canuse_pdfforms');
1.139 raeburn 2729: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
1.121 raeburn 2730: \%choices,$itemcount);
1.139 raeburn 2731: } else {
2732: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.216 raeburn 2733: my ($currdefresponder,$def_official_credits,$def_unofficial_credits,$def_textbook_credits,
2734: %curruploadquota);
1.192 raeburn 2735: my $currusecredits = 0;
1.216 raeburn 2736: my @types = ('official','unofficial','community','textbook');
1.139 raeburn 2737: if (ref($settings) eq 'HASH') {
2738: $currdefresponder = $settings->{'anonsurvey_threshold'};
1.198 raeburn 2739: if (ref($settings->{'uploadquota'}) eq 'HASH') {
2740: foreach my $type (keys(%{$settings->{'uploadquota'}})) {
2741: $curruploadquota{$type} = $settings->{'uploadquota'}{$type};
2742: }
2743: }
1.192 raeburn 2744: if (ref($settings->{'coursecredits'}) eq 'HASH') {
2745: $def_official_credits = $settings->{'coursecredits'}->{'official'};
2746: $def_unofficial_credits = $settings->{'coursecredits'}->{'unofficial'};
1.216 raeburn 2747: $def_textbook_credits = $settings->{'coursecredits'}->{'textbook'};
2748: if (($def_official_credits ne '') || ($def_unofficial_credits ne '') ||
2749: ($def_textbook_credits ne '')) {
1.192 raeburn 2750: $currusecredits = 1;
2751: }
2752: }
1.139 raeburn 2753: }
2754: if (!$currdefresponder) {
1.198 raeburn 2755: $currdefresponder = $staticdefaults{'anonsurvey_threshold'};
1.139 raeburn 2756: } elsif ($currdefresponder < 1) {
2757: $currdefresponder = 1;
2758: }
1.198 raeburn 2759: foreach my $type (@types) {
2760: if ($curruploadquota{$type} eq '') {
2761: $curruploadquota{$type} = $staticdefaults{'uploadquota'};
2762: }
2763: }
1.139 raeburn 2764: $datatable .=
1.192 raeburn 2765: '<tr'.$css_class.'><td><span class="LC_nobreak">'.
2766: $choices{'anonsurvey_threshold'}.
1.139 raeburn 2767: '</span></td>'.
2768: '<td class="LC_right_item"><span class="LC_nobreak">'.
2769: '<input type="text" name="anonsurvey_threshold"'.
2770: ' value="'.$currdefresponder.'" size="5" /></span>'.
1.230 ! raeburn 2771: '</td></tr>'."\n";
! 2772: $itemcount ++;
! 2773: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
! 2774: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
! 2775: $choices{'uploadquota'}.
! 2776: '</span></td>'.
! 2777: '<td align="right" class="LC_right_item">'.
! 2778: '<table><tr>';
1.198 raeburn 2779: foreach my $type (@types) {
2780: $datatable .= '<td align="center">'.&mt($type).'<br />'.
2781: '<input type="text" name="uploadquota_'.$type.'"'.
2782: ' value="'.$curruploadquota{$type}.'" size="5" /></td>';
2783: }
2784: $datatable .= '</tr></table></td></tr>'."\n";
1.230 ! raeburn 2785: $itemcount ++;
1.192 raeburn 2786: my $onclick = 'toggleCredits(this.form);';
1.210 raeburn 2787: my $display = 'none';
1.192 raeburn 2788: if ($currusecredits) {
2789: $display = 'block';
2790: }
2791: my $additional = '<div id="credits" style="display: '.$display.'">'.
2792: '<span class="LC_nobreak">'.
2793: &mt('Default credits for official courses [_1]',
2794: '<input type="text" name="official_credits" value="'.
2795: $def_official_credits.'" size="3" />').
2796: '</span><br />'.
2797: '<span class="LC_nobreak">'.
2798: &mt('Default credits for unofficial courses [_1]',
2799: '<input type="text" name="unofficial_credits" value="'.
2800: $def_unofficial_credits.'" size="3" />').
1.216 raeburn 2801: '</span><br />'.
2802: '<span class="LC_nobreak">'.
2803: &mt('Default credits for textbook courses [_1]',
2804: '<input type="text" name="textbook_credits" value="'.
2805: $def_textbook_credits.'" size="3" />').
1.192 raeburn 2806: '</span></div>'."\n";
2807: %defaultchecked = ('coursecredits' => 'off');
2808: @toggles = ('coursecredits');
2809: my $current = {
2810: 'coursecredits' => $currusecredits,
2811: };
2812: (my $table,$itemcount) =
2813: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
2814: \%choices,$itemcount,$onclick,$additional);
2815: $datatable .= $table;
1.230 ! raeburn 2816: $itemcount ++;
1.139 raeburn 2817: }
1.192 raeburn 2818: $$rowtotal += $itemcount;
1.121 raeburn 2819: return $datatable;
1.118 jms 2820: }
2821:
1.137 raeburn 2822: sub print_usersessions {
2823: my ($position,$dom,$settings,$rowtotal) = @_;
2824: my ($css_class,$datatable,%checked,%choices);
1.140 raeburn 2825: my (%by_ip,%by_location,@intdoms);
2826: &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
1.145 raeburn 2827:
2828: my @alldoms = &Apache::lonnet::all_domains();
1.152 raeburn 2829: my %serverhomes = %Apache::lonnet::serverhomeIDs;
1.149 raeburn 2830: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.152 raeburn 2831: my %altids = &id_for_thisdom(%servers);
1.145 raeburn 2832: my $itemcount = 1;
2833: if ($position eq 'top') {
1.152 raeburn 2834: if (keys(%serverhomes) > 1) {
1.145 raeburn 2835: my %spareid = ¤t_offloads_to($dom,$settings,\%servers);
1.152 raeburn 2836: $datatable .= &spares_row($dom,\%servers,\%spareid,\%serverhomes,\%altids,$rowtotal);
1.145 raeburn 2837: } else {
1.140 raeburn 2838: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.150 raeburn 2839: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one server.');
1.140 raeburn 2840: }
1.137 raeburn 2841: } else {
1.145 raeburn 2842: if (keys(%by_location) == 0) {
2843: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.150 raeburn 2844: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one institution.');
1.145 raeburn 2845: } else {
2846: my %lt = &usersession_titles();
2847: my $numinrow = 5;
2848: my $prefix;
2849: my @types;
2850: if ($position eq 'bottom') {
2851: $prefix = 'remote';
2852: @types = ('version','excludedomain','includedomain');
2853: } else {
2854: $prefix = 'hosted';
2855: @types = ('excludedomain','includedomain');
2856: }
2857: my (%current,%checkedon,%checkedoff);
2858: my @lcversions = &Apache::lonnet::all_loncaparevs();
2859: my @locations = sort(keys(%by_location));
2860: foreach my $type (@types) {
2861: $checkedon{$type} = '';
2862: $checkedoff{$type} = ' checked="checked"';
2863: }
2864: if (ref($settings) eq 'HASH') {
2865: if (ref($settings->{$prefix}) eq 'HASH') {
2866: foreach my $key (keys(%{$settings->{$prefix}})) {
2867: $current{$key} = $settings->{$prefix}{$key};
2868: if ($key eq 'version') {
2869: if ($current{$key} ne '') {
2870: $checkedon{$key} = ' checked="checked"';
2871: $checkedoff{$key} = '';
2872: }
2873: } elsif (ref($current{$key}) eq 'ARRAY') {
2874: $checkedon{$key} = ' checked="checked"';
2875: $checkedoff{$key} = '';
2876: }
1.137 raeburn 2877: }
2878: }
2879: }
1.145 raeburn 2880: foreach my $type (@types) {
2881: next if ($type ne 'version' && !@locations);
2882: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
2883: $datatable .= '<tr'.$css_class.'>
2884: <td><span class="LC_nobreak">'.$lt{$type}.'</span><br />
2885: <span class="LC_nobreak">
2886: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedoff{$type}.' value="0" />'.&mt('Not in use').'</label>
2887: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedon{$type}.' value="1" />'.&mt('In use').'</label></span></td><td>';
2888: if ($type eq 'version') {
2889: my $selector = '<select name="'.$prefix.'_version">';
2890: foreach my $version (@lcversions) {
2891: my $selected = '';
2892: if ($current{'version'} eq $version) {
2893: $selected = ' selected="selected"';
2894: }
2895: $selector .= ' <option value="'.$version.'"'.
2896: $selected.'>'.$version.'</option>';
2897: }
2898: $selector .= '</select> ';
2899: $datatable .= &mt('remote server must be version: [_1] or later',$selector);
2900: } else {
2901: $datatable.= '<div><input type="button" value="'.&mt('check all').'" '.
2902: 'onclick="javascript:checkAll(document.display.'.$prefix.'_'.$type.')"'.
2903: ' />'.(' 'x2).
2904: '<input type="button" value="'.&mt('uncheck all').'" '.
2905: 'onclick="javascript:uncheckAll(document.display.'.$prefix.'_'.$type.')" />'.
2906: "\n".
2907: '</div><div><table>';
2908: my $rem;
2909: for (my $i=0; $i<@locations; $i++) {
2910: my ($showloc,$value,$checkedtype);
2911: if (ref($by_location{$locations[$i]}) eq 'ARRAY') {
2912: my $ip = $by_location{$locations[$i]}->[0];
2913: if (ref($by_ip{$ip}) eq 'ARRAY') {
2914: $value = join(':',@{$by_ip{$ip}});
2915: $showloc = join(', ',@{$by_ip{$ip}});
2916: if (ref($current{$type}) eq 'ARRAY') {
2917: foreach my $loc (@{$by_ip{$ip}}) {
2918: if (grep(/^\Q$loc\E$/,@{$current{$type}})) {
2919: $checkedtype = ' checked="checked"';
2920: last;
2921: }
2922: }
1.138 raeburn 2923: }
2924: }
2925: }
1.145 raeburn 2926: $rem = $i%($numinrow);
2927: if ($rem == 0) {
2928: if ($i > 0) {
2929: $datatable .= '</tr>';
2930: }
2931: $datatable .= '<tr>';
2932: }
2933: $datatable .= '<td class="LC_left_item">'.
2934: '<span class="LC_nobreak"><label>'.
2935: '<input type="checkbox" name="'.$prefix.'_'.$type.
2936: '" value="'.$value.'"'.$checkedtype.' />'.$showloc.
2937: '</label></span></td>';
1.137 raeburn 2938: }
1.145 raeburn 2939: $rem = @locations%($numinrow);
2940: my $colsleft = $numinrow - $rem;
2941: if ($colsleft > 1 ) {
2942: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
2943: ' </td>';
2944: } elsif ($colsleft == 1) {
2945: $datatable .= '<td class="LC_left_item"> </td>';
1.137 raeburn 2946: }
1.145 raeburn 2947: $datatable .= '</tr></table>';
1.137 raeburn 2948: }
1.145 raeburn 2949: $datatable .= '</td></tr>';
2950: $itemcount ++;
1.137 raeburn 2951: }
2952: }
2953: }
2954: $$rowtotal += $itemcount;
2955: return $datatable;
2956: }
2957:
1.138 raeburn 2958: sub build_location_hashes {
2959: my ($intdoms,$by_ip,$by_location) = @_;
2960: return unless((ref($intdoms) eq 'ARRAY') && (ref($by_ip) eq 'HASH') &&
2961: (ref($by_location) eq 'HASH'));
2962: my %iphost = &Apache::lonnet::get_iphost();
2963: my $primary_id = &Apache::lonnet::domain($env{'request.role.domain'},'primary');
2964: my $primary_ip = &Apache::lonnet::get_host_ip($primary_id);
2965: if (ref($iphost{$primary_ip}) eq 'ARRAY') {
2966: foreach my $id (@{$iphost{$primary_ip}}) {
2967: my $intdom = &Apache::lonnet::internet_dom($id);
2968: unless(grep(/^\Q$intdom\E$/,@{$intdoms})) {
2969: push(@{$intdoms},$intdom);
2970: }
2971: }
2972: }
2973: foreach my $ip (keys(%iphost)) {
2974: if (ref($iphost{$ip}) eq 'ARRAY') {
2975: foreach my $id (@{$iphost{$ip}}) {
2976: my $location = &Apache::lonnet::internet_dom($id);
2977: if ($location) {
2978: next if (grep(/^\Q$location\E$/,@{$intdoms}));
2979: if (ref($by_ip->{$ip}) eq 'ARRAY') {
2980: unless(grep(/^\Q$location\E$/,@{$by_ip->{$ip}})) {
2981: push(@{$by_ip->{$ip}},$location);
2982: }
2983: } else {
2984: $by_ip->{$ip} = [$location];
2985: }
2986: }
2987: }
2988: }
2989: }
2990: foreach my $ip (sort(keys(%{$by_ip}))) {
2991: if (ref($by_ip->{$ip}) eq 'ARRAY') {
2992: @{$by_ip->{$ip}} = sort(@{$by_ip->{$ip}});
2993: my $first = $by_ip->{$ip}->[0];
2994: if (ref($by_location->{$first}) eq 'ARRAY') {
2995: unless (grep(/^\Q$ip\E$/,@{$by_location->{$first}})) {
2996: push(@{$by_location->{$first}},$ip);
2997: }
2998: } else {
2999: $by_location->{$first} = [$ip];
3000: }
3001: }
3002: }
3003: return;
3004: }
3005:
1.145 raeburn 3006: sub current_offloads_to {
3007: my ($dom,$settings,$servers) = @_;
3008: my (%spareid,%otherdomconfigs);
1.152 raeburn 3009: if (ref($servers) eq 'HASH') {
1.145 raeburn 3010: foreach my $lonhost (sort(keys(%{$servers}))) {
3011: my $gotspares;
1.152 raeburn 3012: if (ref($settings) eq 'HASH') {
3013: if (ref($settings->{'spares'}) eq 'HASH') {
3014: if (ref($settings->{'spares'}{$lonhost}) eq 'HASH') {
3015: $spareid{$lonhost}{'primary'} = $settings->{'spares'}{$lonhost}{'primary'};
3016: $spareid{$lonhost}{'default'} = $settings->{'spares'}{$lonhost}{'default'};
3017: $gotspares = 1;
3018: }
1.145 raeburn 3019: }
3020: }
3021: unless ($gotspares) {
3022: my $gotspares;
3023: my $serverhomeID =
3024: &Apache::lonnet::get_server_homeID($servers->{$lonhost});
3025: my $serverhomedom =
3026: &Apache::lonnet::host_domain($serverhomeID);
3027: if ($serverhomedom ne $dom) {
3028: if (ref($otherdomconfigs{$serverhomedom} eq 'HASH')) {
3029: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
3030: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
3031: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
3032: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
3033: $gotspares = 1;
3034: }
3035: }
3036: } else {
3037: $otherdomconfigs{$serverhomedom} =
3038: &Apache::lonnet::get_dom('configuration',['usersessions'],$serverhomedom);
3039: if (ref($otherdomconfigs{$serverhomedom}) eq 'HASH') {
3040: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
3041: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
3042: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{$lonhost}) eq 'HASH') {
3043: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
3044: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
3045: $gotspares = 1;
3046: }
3047: }
3048: }
3049: }
3050: }
3051: }
3052: }
3053: unless ($gotspares) {
3054: if ($lonhost eq $Apache::lonnet::perlvar{'lonHostID'}) {
3055: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
3056: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
3057: } else {
3058: my $server_hostname = &Apache::lonnet::hostname($lonhost);
3059: my $server_homeID = &Apache::lonnet::get_server_homeID($server_hostname);
3060: if ($server_homeID eq $Apache::lonnet::perlvar{'lonHostID'}) {
3061: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
3062: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
3063: } else {
1.150 raeburn 3064: my %what = (
3065: spareid => 1,
3066: );
3067: my ($result,$returnhash) =
3068: &Apache::lonnet::get_remote_globals($lonhost,\%what);
3069: if ($result eq 'ok') {
3070: if (ref($returnhash) eq 'HASH') {
3071: if (ref($returnhash->{'spareid'}) eq 'HASH') {
3072: $spareid{$lonhost}{'primary'} = $returnhash->{'spareid'}->{'primary'};
3073: $spareid{$lonhost}{'default'} = $returnhash->{'spareid'}->{'default'};
3074: }
3075: }
1.145 raeburn 3076: }
3077: }
3078: }
3079: }
3080: }
3081: }
3082: return %spareid;
3083: }
3084:
3085: sub spares_row {
1.152 raeburn 3086: my ($dom,$servers,$spareid,$serverhomes,$altids,$rowtotal) = @_;
1.145 raeburn 3087: my $css_class;
3088: my $numinrow = 4;
3089: my $itemcount = 1;
3090: my $datatable;
1.152 raeburn 3091: my %typetitles = &sparestype_titles();
3092: if ((ref($servers) eq 'HASH') && (ref($spareid) eq 'HASH') && (ref($altids) eq 'HASH')) {
1.145 raeburn 3093: foreach my $server (sort(keys(%{$servers}))) {
1.152 raeburn 3094: my $serverhome = &Apache::lonnet::get_server_homeID($servers->{$server});
3095: my ($othercontrol,$serverdom);
3096: if ($serverhome ne $server) {
3097: $serverdom = &Apache::lonnet::host_domain($serverhome);
3098: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
3099: } else {
3100: $serverdom = &Apache::lonnet::host_domain($server);
3101: if ($serverdom ne $dom) {
3102: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
3103: }
3104: }
3105: next unless (ref($spareid->{$server}) eq 'HASH');
1.145 raeburn 3106: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
3107: $datatable .= '<tr'.$css_class.'>
3108: <td rowspan="2">
1.183 bisitz 3109: <span class="LC_nobreak">'.
3110: &mt('[_1] when busy, offloads to:'
3111: ,'<b>'.$server.'</b>').
3112: "\n";
1.145 raeburn 3113: my (%current,%canselect);
1.152 raeburn 3114: my @choices =
3115: &possible_newspares($server,$spareid->{$server},$serverhomes,$altids);
3116: foreach my $type ('primary','default') {
3117: if (ref($spareid->{$server}) eq 'HASH') {
1.145 raeburn 3118: if (ref($spareid->{$server}{$type}) eq 'ARRAY') {
3119: my @spares = @{$spareid->{$server}{$type}};
3120: if (@spares > 0) {
1.152 raeburn 3121: if ($othercontrol) {
3122: $current{$type} = join(', ',@spares);
3123: } else {
3124: $current{$type} .= '<table>';
3125: my $numspares = scalar(@spares);
3126: for (my $i=0; $i<@spares; $i++) {
3127: my $rem = $i%($numinrow);
3128: if ($rem == 0) {
3129: if ($i > 0) {
3130: $current{$type} .= '</tr>';
3131: }
3132: $current{$type} .= '<tr>';
1.145 raeburn 3133: }
1.152 raeburn 3134: $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'".');" /> '.
3135: $spareid->{$server}{$type}[$i].
3136: '</label></td>'."\n";
3137: }
3138: my $rem = @spares%($numinrow);
3139: my $colsleft = $numinrow - $rem;
3140: if ($colsleft > 1 ) {
3141: $current{$type} .= '<td colspan="'.$colsleft.
3142: '" class="LC_left_item">'.
3143: ' </td>';
3144: } elsif ($colsleft == 1) {
3145: $current{$type} .= '<td class="LC_left_item"> </td>'."\n";
1.145 raeburn 3146: }
1.152 raeburn 3147: $current{$type} .= '</tr></table>';
1.150 raeburn 3148: }
1.145 raeburn 3149: }
3150: }
3151: if ($current{$type} eq '') {
3152: $current{$type} = &mt('None specified');
3153: }
1.152 raeburn 3154: if ($othercontrol) {
3155: if ($type eq 'primary') {
3156: $canselect{$type} = $othercontrol;
3157: }
3158: } else {
3159: $canselect{$type} =
3160: &mt('Add new [_1]'.$type.'[_2]:','<i>','</i>').' '.
3161: '<select name="newspare_'.$type.'_'.$server.'" '.
3162: 'id="newspare_'.$type.'_'.$server.'" onchange="checkNewSpares('."'$server','$type'".');">'."\n".
3163: '<option value="" selected ="selected">'.&mt('Select').'</option>'."\n";
3164: if (@choices > 0) {
3165: foreach my $lonhost (@choices) {
3166: $canselect{$type} .= '<option value="'.$lonhost.'">'.$lonhost.'</option>'."\n";
3167: }
3168: }
3169: $canselect{$type} .= '</select>'."\n";
3170: }
3171: } else {
3172: $current{$type} = &mt('Could not be determined');
3173: if ($type eq 'primary') {
3174: $canselect{$type} = $othercontrol;
3175: }
1.145 raeburn 3176: }
1.152 raeburn 3177: if ($type eq 'default') {
3178: $datatable .= '<tr'.$css_class.'>';
3179: }
3180: $datatable .= '<td><i>'.$typetitles{$type}.'</i></td>'."\n".
3181: '<td>'.$current{$type}.'</td>'."\n".
3182: '<td>'.$canselect{$type}.'</td></tr>'."\n";
1.145 raeburn 3183: }
3184: $itemcount ++;
3185: }
3186: }
3187: $$rowtotal += $itemcount;
3188: return $datatable;
3189: }
3190:
1.152 raeburn 3191: sub possible_newspares {
3192: my ($server,$currspares,$serverhomes,$altids) = @_;
3193: my $serverhostname = &Apache::lonnet::hostname($server);
3194: my %excluded;
3195: if ($serverhostname ne '') {
3196: %excluded = (
3197: $serverhostname => 1,
3198: );
3199: }
3200: if (ref($currspares) eq 'HASH') {
3201: foreach my $type (keys(%{$currspares})) {
3202: if (ref($currspares->{$type}) eq 'ARRAY') {
3203: if (@{$currspares->{$type}} > 0) {
3204: foreach my $curr (@{$currspares->{$type}}) {
3205: my $hostname = &Apache::lonnet::hostname($curr);
3206: $excluded{$hostname} = 1;
3207: }
3208: }
3209: }
3210: }
3211: }
3212: my @choices;
3213: if ((ref($serverhomes) eq 'HASH') && (ref($altids) eq 'HASH')) {
3214: if (keys(%{$serverhomes}) > 1) {
3215: foreach my $name (sort(keys(%{$serverhomes}))) {
3216: unless ($excluded{$name}) {
3217: if (exists($altids->{$serverhomes->{$name}})) {
3218: push(@choices,$altids->{$serverhomes->{$name}});
3219: } else {
3220: push(@choices,$serverhomes->{$name});
1.145 raeburn 3221: }
3222: }
3223: }
3224: }
3225: }
1.152 raeburn 3226: return sort(@choices);
1.145 raeburn 3227: }
3228:
1.150 raeburn 3229: sub print_loadbalancing {
3230: my ($dom,$settings,$rowtotal) = @_;
3231: my $primary_id = &Apache::lonnet::domain($dom,'primary');
3232: my $intdom = &Apache::lonnet::internet_dom($primary_id);
3233: my $numinrow = 1;
3234: my $datatable;
3235: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.171 raeburn 3236: my (%currbalancer,%currtargets,%currrules,%existing);
3237: if (ref($settings) eq 'HASH') {
3238: %existing = %{$settings};
3239: }
3240: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
3241: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
3242: \%currtargets,\%currrules);
1.150 raeburn 3243: } else {
3244: return;
3245: }
3246: my ($othertitle,$usertypes,$types) =
3247: &Apache::loncommon::sorted_inst_types($dom);
1.209 raeburn 3248: my $rownum = 8;
1.150 raeburn 3249: if (ref($types) eq 'ARRAY') {
3250: $rownum += scalar(@{$types});
3251: }
1.171 raeburn 3252: my @css_class = ('LC_odd_row','LC_even_row');
3253: my $balnum = 0;
3254: my $islast;
3255: my (@toshow,$disabledtext);
3256: if (keys(%currbalancer) > 0) {
3257: @toshow = sort(keys(%currbalancer));
3258: if (scalar(@toshow) < scalar(keys(%servers)) + 1) {
3259: push(@toshow,'');
3260: }
3261: } else {
3262: @toshow = ('');
3263: $disabledtext = &mt('No existing load balancer');
3264: }
3265: foreach my $lonhost (@toshow) {
3266: if ($balnum == scalar(@toshow)-1) {
3267: $islast = 1;
3268: } else {
3269: $islast = 0;
3270: }
3271: my $cssidx = $balnum%2;
3272: my $targets_div_style = 'display: none';
3273: my $disabled_div_style = 'display: block';
3274: my $homedom_div_style = 'display: none';
3275: $datatable .= '<tr class="'.$css_class[$cssidx].'">'.
3276: '<td rowspan="'.$rownum.'" valign="top">'.
3277: '<p>';
3278: if ($lonhost eq '') {
1.210 raeburn 3279: $datatable .= '<span class="LC_nobreak">';
1.171 raeburn 3280: if (keys(%currbalancer) > 0) {
3281: $datatable .= &mt('Add balancer:');
3282: } else {
3283: $datatable .= &mt('Enable balancer:');
3284: }
3285: $datatable .= ' '.
3286: '<select name="loadbalancing_lonhost_'.$balnum.'"'.
3287: ' id="loadbalancing_lonhost_'.$balnum.'"'.
3288: ' onchange="toggleTargets('."'$balnum'".');">'."\n".
3289: '<option value="" selected="selected">'.&mt('None').
3290: '</option>'."\n";
3291: foreach my $server (sort(keys(%servers))) {
3292: next if ($currbalancer{$server});
3293: $datatable .= '<option value="'.$server.'">'.$server.'</option>'."\n";
3294: }
1.210 raeburn 3295: $datatable .=
1.171 raeburn 3296: '</select>'."\n".
3297: '<input type="hidden" name="loadbalancing_prevlonhost_'.$balnum.'" id="loadbalancing_prevlonhost_'.$balnum.'" value="" /> </span>'."\n";
3298: } else {
3299: $datatable .= '<i>'.$lonhost.'</i><br /><span class="LC_nobreak">'.
3300: '<label><input type="checkbox" name="loadbalancing_delete" value="'.$balnum.'" id="loadbalancing_delete_'.$balnum.'" onclick="javascript:balancerDeleteChange('."'$balnum'".');" /> '.
3301: &mt('Stop balancing').'</label>'.
3302: '<input type="hidden" name="loadbalancing_lonhost_'.$balnum.'" value="'.$lonhost.'" id="loadbalancing_lonhost_'.$balnum.'" /></span>';
3303: $targets_div_style = 'display: block';
3304: $disabled_div_style = 'display: none';
3305: if ($dom eq &Apache::lonnet::host_domain($lonhost)) {
3306: $homedom_div_style = 'display: block';
3307: }
3308: }
3309: $datatable .= '</p></td><td rowspan="'.$rownum.'" valign="top">'.
3310: '<div id="loadbalancing_disabled_'.$balnum.'" style="'.
3311: $disabled_div_style.'">'.$disabledtext.'</div>'."\n".
3312: '<div id="loadbalancing_targets_'.$balnum.'" style="'.$targets_div_style.'">'.&mt('Offloads to:').'<br />';
3313: my ($numspares,@spares) = &count_servers($lonhost,%servers);
3314: my @sparestypes = ('primary','default');
3315: my %typetitles = &sparestype_titles();
3316: foreach my $sparetype (@sparestypes) {
3317: my $targettable;
3318: for (my $i=0; $i<$numspares; $i++) {
3319: my $checked;
3320: if (ref($currtargets{$lonhost}) eq 'HASH') {
3321: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
3322: if (grep(/^\Q$spares[$i]\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
3323: $checked = ' checked="checked"';
3324: }
3325: }
3326: }
3327: my ($chkboxval,$disabled);
3328: if (($lonhost ne '') && (exists($servers{$lonhost}))) {
3329: $chkboxval = $spares[$i];
3330: }
3331: if (exists($currbalancer{$spares[$i]})) {
3332: $disabled = ' disabled="disabled"';
3333: }
1.210 raeburn 3334: $targettable .=
1.171 raeburn 3335: '<td><label><input type="checkbox" name="loadbalancing_target_'.$balnum.'_'.$sparetype.'"'.
3336: $checked.$disabled.' value="'.$chkboxval.'" id="loadbalancing_target_'.$balnum.'_'.$sparetype.'_'.$i.'" onclick="checkOffloads('."this,'$balnum','$sparetype'".');" /><span id="loadbalancing_targettxt_'.$balnum.'_'.$sparetype.'_'.$i.'"> '.$chkboxval.
3337: '</span></label></td>';
3338: my $rem = $i%($numinrow);
3339: if ($rem == 0) {
3340: if (($i > 0) && ($i < $numspares-1)) {
3341: $targettable .= '</tr>';
3342: }
3343: if ($i < $numspares-1) {
3344: $targettable .= '<tr>';
1.150 raeburn 3345: }
3346: }
3347: }
1.171 raeburn 3348: if ($targettable ne '') {
3349: my $rem = $numspares%($numinrow);
3350: my $colsleft = $numinrow - $rem;
3351: if ($colsleft > 1 ) {
3352: $targettable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
3353: ' </td>';
3354: } elsif ($colsleft == 1) {
3355: $targettable .= '<td class="LC_left_item"> </td>';
3356: }
3357: $datatable .= '<i>'.$typetitles{$sparetype}.'</i><br />'.
3358: '<table><tr>'.$targettable.'</tr></table><br />';
3359: }
3360: }
3361: $datatable .= '</div></td></tr>'.
3362: &loadbalancing_rules($dom,$intdom,$currrules{$lonhost},
3363: $othertitle,$usertypes,$types,\%servers,
3364: \%currbalancer,$lonhost,
3365: $targets_div_style,$homedom_div_style,
3366: $css_class[$cssidx],$balnum,$islast);
3367: $$rowtotal += $rownum;
3368: $balnum ++;
3369: }
3370: $datatable .= '<input type="hidden" name="loadbalancing_total" id="loadbalancing_total" value="'.$balnum.'" />';
3371: return $datatable;
3372: }
3373:
3374: sub get_loadbalancers_config {
3375: my ($servers,$existing,$currbalancer,$currtargets,$currrules) = @_;
3376: return unless ((ref($servers) eq 'HASH') &&
3377: (ref($existing) eq 'HASH') && (ref($currbalancer) eq 'HASH') &&
3378: (ref($currtargets) eq 'HASH') && (ref($currrules) eq 'HASH'));
3379: if (keys(%{$existing}) > 0) {
3380: my $oldlonhost;
3381: foreach my $key (sort(keys(%{$existing}))) {
3382: if ($key eq 'lonhost') {
3383: $oldlonhost = $existing->{'lonhost'};
3384: $currbalancer->{$oldlonhost} = 1;
3385: } elsif ($key eq 'targets') {
3386: if ($oldlonhost) {
3387: $currtargets->{$oldlonhost} = $existing->{'targets'};
3388: }
3389: } elsif ($key eq 'rules') {
3390: if ($oldlonhost) {
3391: $currrules->{$oldlonhost} = $existing->{'rules'};
3392: }
3393: } elsif (ref($existing->{$key}) eq 'HASH') {
3394: $currbalancer->{$key} = 1;
3395: $currtargets->{$key} = $existing->{$key}{'targets'};
3396: $currrules->{$key} = $existing->{$key}{'rules'};
1.150 raeburn 3397: }
3398: }
1.171 raeburn 3399: } else {
3400: my ($balancerref,$targetsref) =
3401: &Apache::lonnet::get_lonbalancer_config($servers);
3402: if ((ref($balancerref) eq 'HASH') && (ref($targetsref) eq 'HASH')) {
3403: foreach my $server (sort(keys(%{$balancerref}))) {
3404: $currbalancer->{$server} = 1;
3405: $currtargets->{$server} = $targetsref->{$server};
1.150 raeburn 3406: }
3407: }
3408: }
1.171 raeburn 3409: return;
1.150 raeburn 3410: }
3411:
3412: sub loadbalancing_rules {
3413: my ($dom,$intdom,$currrules,$othertitle,$usertypes,$types,$servers,
1.171 raeburn 3414: $currbalancer,$lonhost,$targets_div_style,$homedom_div_style,
3415: $css_class,$balnum,$islast) = @_;
1.150 raeburn 3416: my $output;
1.171 raeburn 3417: my $num = 0;
1.210 raeburn 3418: my ($alltypes,$othertypes,$titles) =
1.150 raeburn 3419: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
3420: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
3421: foreach my $type (@{$alltypes}) {
1.171 raeburn 3422: $num ++;
1.150 raeburn 3423: my $current;
3424: if (ref($currrules) eq 'HASH') {
3425: $current = $currrules->{$type};
3426: }
1.209 raeburn 3427: if (($type eq '_LC_external') || ($type eq '_LC_internetdom') || ($type eq '_LC_ipchange')) {
1.171 raeburn 3428: if ($dom ne &Apache::lonnet::host_domain($lonhost)) {
1.150 raeburn 3429: $current = '';
3430: }
3431: }
3432: $output .= &loadbalance_rule_row($type,$titles->{$type},$current,
1.171 raeburn 3433: $servers,$currbalancer,$lonhost,$dom,
3434: $targets_div_style,$homedom_div_style,
3435: $css_class,$balnum,$num,$islast);
1.150 raeburn 3436: }
3437: }
3438: return $output;
3439: }
3440:
3441: sub loadbalancing_titles {
3442: my ($dom,$intdom,$usertypes,$types) = @_;
3443: my %othertypes = (
3444: '_LC_adv' => &mt('Advanced users from [_1]',$dom),
3445: '_LC_author' => &mt('Users from [_1] with author role',$dom),
3446: '_LC_internetdom' => &mt('Users not from [_1], but from [_2]',$dom,$intdom),
3447: '_LC_external' => &mt('Users not from [_1]',$intdom),
1.209 raeburn 3448: '_LC_ipchangesso' => &mt('SSO users from [_1], with IP mismatch',$dom),
3449: '_LC_ipchange' => &mt('Non-SSO users with IP mismatch'),
1.150 raeburn 3450: );
1.209 raeburn 3451: my @alltypes = ('_LC_adv','_LC_author','_LC_internetdom','_LC_external','_LC_ipchangesso','_LC_ipchange');
1.150 raeburn 3452: if (ref($types) eq 'ARRAY') {
3453: unshift(@alltypes,@{$types},'default');
3454: }
3455: my %titles;
3456: foreach my $type (@alltypes) {
3457: if ($type =~ /^_LC_/) {
3458: $titles{$type} = $othertypes{$type};
3459: } elsif ($type eq 'default') {
3460: $titles{$type} = &mt('All users from [_1]',$dom);
3461: if (ref($types) eq 'ARRAY') {
3462: if (@{$types} > 0) {
3463: $titles{$type} = &mt('Other users from [_1]',$dom);
3464: }
3465: }
3466: } elsif (ref($usertypes) eq 'HASH') {
3467: $titles{$type} = $usertypes->{$type};
3468: }
3469: }
3470: return (\@alltypes,\%othertypes,\%titles);
3471: }
3472:
3473: sub loadbalance_rule_row {
1.171 raeburn 3474: my ($type,$title,$current,$servers,$currbalancer,$lonhost,$dom,
3475: $targets_div_style,$homedom_div_style,$css_class,$balnum,$num,$islast) = @_;
1.209 raeburn 3476: my @rulenames;
1.150 raeburn 3477: my %ruletitles = &offloadtype_text();
1.209 raeburn 3478: if (($type eq '_LC_ipchangesso') || ($type eq '_LC_ipchange')) {
3479: @rulenames = ('balancer','offloadedto');
1.150 raeburn 3480: } else {
1.209 raeburn 3481: @rulenames = ('default','homeserver');
3482: if ($type eq '_LC_external') {
3483: push(@rulenames,'externalbalancer');
3484: } else {
3485: push(@rulenames,'specific');
3486: }
3487: push(@rulenames,'none');
1.150 raeburn 3488: }
3489: my $style = $targets_div_style;
1.209 raeburn 3490: if (($type eq '_LC_external') || ($type eq '_LC_internetdom') || ($type eq '_LC_ipchange')) {
1.150 raeburn 3491: $style = $homedom_div_style;
3492: }
1.171 raeburn 3493: my $space;
3494: if ($islast && $num == 1) {
3495: $space = '<div display="inline-block"> </div>';
3496: }
1.210 raeburn 3497: my $output =
1.171 raeburn 3498: '<tr class="'.$css_class.'" id="balanceruletr_'.$balnum.'_'.$num.'"><td valign="top">'.$space.
3499: '<div id="balanceruletitle_'.$balnum.'_'.$type.'" style="'.$style.'">'.$title.'</div></td>'."\n".
3500: '<td valaign="top">'.$space.
3501: '<div id="balancerule_'.$balnum.'_'.$type.'" style="'.$style.'">'."\n";
1.150 raeburn 3502: for (my $i=0; $i<@rulenames; $i++) {
3503: my $rule = $rulenames[$i];
3504: my ($checked,$extra);
3505: if ($rulenames[$i] eq 'default') {
3506: $rule = '';
3507: }
3508: if ($rulenames[$i] eq 'specific') {
3509: if (ref($servers) eq 'HASH') {
3510: my $default;
3511: if (($current ne '') && (exists($servers->{$current}))) {
3512: $checked = ' checked="checked"';
3513: }
3514: unless ($checked) {
3515: $default = ' selected="selected"';
3516: }
1.210 raeburn 3517: $extra =
1.171 raeburn 3518: ': <select name="loadbalancing_singleserver_'.$balnum.'_'.$type.
3519: '" id="loadbalancing_singleserver_'.$balnum.'_'.$type.
3520: '" onchange="singleServerToggle('."'$balnum','$type'".')">'."\n".
3521: '<option value=""'.$default.'></option>'."\n";
3522: foreach my $server (sort(keys(%{$servers}))) {
3523: if (ref($currbalancer) eq 'HASH') {
3524: next if (exists($currbalancer->{$server}));
3525: }
1.150 raeburn 3526: my $selected;
1.171 raeburn 3527: if ($server eq $current) {
1.150 raeburn 3528: $selected = ' selected="selected"';
3529: }
1.171 raeburn 3530: $extra .= '<option value="'.$server.'"'.$selected.'>'.$server.'</option>';
1.150 raeburn 3531: }
3532: $extra .= '</select>';
3533: }
3534: } elsif ($rule eq $current) {
3535: $checked = ' checked="checked"';
3536: }
3537: $output .= '<span class="LC_nobreak"><label>'.
1.171 raeburn 3538: '<input type="radio" name="loadbalancing_rules_'.$balnum.'_'.$type.
3539: '" id="loadbalancing_rules_'.$balnum.'_'.$type.'_'.$i.'" value="'.
3540: $rule.'" onclick="balanceruleChange('."this.form,'$balnum','$type'".
1.150 raeburn 3541: ')"'.$checked.' /> '.$ruletitles{$rulenames[$i]}.
3542: '</label>'.$extra.'</span><br />'."\n";
3543: }
3544: $output .= '</div></td></tr>'."\n";
3545: return $output;
3546: }
3547:
3548: sub offloadtype_text {
3549: my %ruletitles = &Apache::lonlocal::texthash (
3550: 'default' => 'Offloads to default destinations',
3551: 'homeserver' => "Offloads to user's home server",
3552: 'externalbalancer' => "Offloads to Load Balancer in user's domain",
3553: 'specific' => 'Offloads to specific server',
1.161 raeburn 3554: 'none' => 'No offload',
1.209 raeburn 3555: 'balancer' => 'Session hosted on Load Balancer, after re-authentication',
3556: 'offloadedto' => 'Session hosted on offload server, after re-authentication',
1.150 raeburn 3557: );
3558: return %ruletitles;
3559: }
3560:
3561: sub sparestype_titles {
3562: my %typestitles = &Apache::lonlocal::texthash (
3563: 'primary' => 'primary',
3564: 'default' => 'default',
3565: );
3566: return %typestitles;
3567: }
3568:
1.28 raeburn 3569: sub contact_titles {
3570: my %titles = &Apache::lonlocal::texthash (
3571: 'supportemail' => 'Support E-mail address',
1.69 raeburn 3572: 'adminemail' => 'Default Server Admin E-mail address',
1.28 raeburn 3573: 'errormail' => 'Error reports to be e-mailed to',
3574: 'packagesmail' => 'Package update alerts to be e-mailed to',
1.89 raeburn 3575: 'helpdeskmail' => 'Helpdesk requests to be e-mailed to',
3576: 'lonstatusmail' => 'E-mail from nightly status check (warnings/errors)',
1.102 raeburn 3577: 'requestsmail' => 'E-mail from course requests requiring approval',
1.190 raeburn 3578: 'updatesmail' => 'E-mail from nightly check of LON-CAPA module integrity/updates',
1.203 raeburn 3579: 'idconflictsmail' => 'E-mail from bi-nightly check for multiple users sharing same student/employee ID',
1.28 raeburn 3580: );
3581: my %short_titles = &Apache::lonlocal::texthash (
3582: adminemail => 'Admin E-mail address',
3583: supportemail => 'Support E-mail',
3584: );
3585: return (\%titles,\%short_titles);
3586: }
3587:
1.72 raeburn 3588: sub tool_titles {
3589: my %titles = &Apache::lonlocal::texthash (
1.162 raeburn 3590: aboutme => 'Personal web page',
1.86 raeburn 3591: blog => 'Blog',
1.162 raeburn 3592: webdav => 'WebDAV',
1.86 raeburn 3593: portfolio => 'Portfolio',
1.88 bisitz 3594: official => 'Official courses (with institutional codes)',
3595: unofficial => 'Unofficial courses',
1.98 raeburn 3596: community => 'Communities',
1.216 raeburn 3597: textbook => 'Textbook courses',
1.86 raeburn 3598: );
1.72 raeburn 3599: return %titles;
3600: }
3601:
1.101 raeburn 3602: sub courserequest_titles {
3603: my %titles = &Apache::lonlocal::texthash (
3604: official => 'Official',
3605: unofficial => 'Unofficial',
3606: community => 'Communities',
1.216 raeburn 3607: textbook => 'Textbook',
1.101 raeburn 3608: norequest => 'Not allowed',
1.104 raeburn 3609: approval => 'Approval by Dom. Coord.',
1.101 raeburn 3610: validate => 'With validation',
3611: autolimit => 'Numerical limit',
1.103 raeburn 3612: unlimited => '(blank for unlimited)',
1.101 raeburn 3613: );
3614: return %titles;
3615: }
3616:
1.163 raeburn 3617: sub authorrequest_titles {
3618: my %titles = &Apache::lonlocal::texthash (
3619: norequest => 'Not allowed',
3620: approval => 'Approval by Dom. Coord.',
3621: automatic => 'Automatic approval',
3622: );
3623: return %titles;
1.210 raeburn 3624: }
1.163 raeburn 3625:
1.101 raeburn 3626: sub courserequest_conditions {
3627: my %conditions = &Apache::lonlocal::texthash (
1.104 raeburn 3628: approval => '(Processing of request subject to approval by Domain Coordinator).',
1.193 bisitz 3629: validate => '(Processing of request subject to institutional validation).',
1.101 raeburn 3630: );
3631: return %conditions;
3632: }
3633:
3634:
1.27 raeburn 3635: sub print_usercreation {
1.30 raeburn 3636: my ($position,$dom,$settings,$rowtotal) = @_;
1.27 raeburn 3637: my $numinrow = 4;
1.28 raeburn 3638: my $datatable;
3639: if ($position eq 'top') {
1.30 raeburn 3640: $$rowtotal ++;
1.34 raeburn 3641: my $rowcount = 0;
1.32 raeburn 3642: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username');
1.28 raeburn 3643: if (ref($rules) eq 'HASH') {
3644: if (keys(%{$rules}) > 0) {
1.32 raeburn 3645: $datatable .= &user_formats_row('username',$settings,$rules,
3646: $ruleorder,$numinrow,$rowcount);
1.30 raeburn 3647: $$rowtotal ++;
1.32 raeburn 3648: $rowcount ++;
3649: }
3650: }
3651: my ($idrules,$idruleorder) = &Apache::lonnet::inst_userrules($dom,'id');
3652: if (ref($idrules) eq 'HASH') {
3653: if (keys(%{$idrules}) > 0) {
3654: $datatable .= &user_formats_row('id',$settings,$idrules,
3655: $idruleorder,$numinrow,$rowcount);
3656: $$rowtotal ++;
3657: $rowcount ++;
1.28 raeburn 3658: }
3659: }
1.39 raeburn 3660: if ($rowcount == 0) {
3661: $datatable .= '<tr><td colspan="2">'.&mt('No format rules have been defined for usernames or IDs in this domain.').'</td></tr>';
3662: $$rowtotal ++;
3663: $rowcount ++;
3664: }
1.34 raeburn 3665: } elsif ($position eq 'middle') {
1.224 raeburn 3666: my @creators = ('author','course','requestcrs');
1.37 raeburn 3667: my ($rules,$ruleorder) =
3668: &Apache::lonnet::inst_userrules($dom,'username');
1.34 raeburn 3669: my %lt = &usercreation_types();
3670: my %checked;
3671: if (ref($settings) eq 'HASH') {
3672: if (ref($settings->{'cancreate'}) eq 'HASH') {
3673: foreach my $item (@creators) {
3674: $checked{$item} = $settings->{'cancreate'}{$item};
3675: }
3676: } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {
3677: foreach my $item (@creators) {
3678: if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {
3679: $checked{$item} = 'none';
3680: }
3681: }
3682: }
3683: }
3684: my $rownum = 0;
3685: foreach my $item (@creators) {
3686: $rownum ++;
1.224 raeburn 3687: if ($checked{$item} eq '') {
3688: $checked{$item} = 'any';
1.34 raeburn 3689: }
3690: my $css_class;
3691: if ($rownum%2) {
3692: $css_class = '';
3693: } else {
3694: $css_class = ' class="LC_odd_row" ';
3695: }
3696: $datatable .= '<tr'.$css_class.'>'.
3697: '<td><span class="LC_nobreak">'.$lt{$item}.
3698: '</span></td><td align="right">';
1.224 raeburn 3699: my @options = ('any');
3700: if (ref($rules) eq 'HASH') {
3701: if (keys(%{$rules}) > 0) {
3702: push(@options,('official','unofficial'));
1.37 raeburn 3703: }
3704: }
1.224 raeburn 3705: push(@options,'none');
1.37 raeburn 3706: foreach my $option (@options) {
1.50 raeburn 3707: my $type = 'radio';
1.34 raeburn 3708: my $check = ' ';
1.224 raeburn 3709: if ($checked{$item} eq $option) {
3710: $check = ' checked="checked" ';
1.34 raeburn 3711: }
3712: $datatable .= '<span class="LC_nobreak"><label>'.
1.50 raeburn 3713: '<input type="'.$type.'" name="can_createuser_'.
1.34 raeburn 3714: $item.'" value="'.$option.'"'.$check.'/> '.
3715: $lt{$option}.'</label> </span>';
3716: }
3717: $datatable .= '</td></tr>';
3718: }
1.28 raeburn 3719: } else {
3720: my @contexts = ('author','course','domain');
3721: my @authtypes = ('int','krb4','krb5','loc');
3722: my %checked;
3723: if (ref($settings) eq 'HASH') {
3724: if (ref($settings->{'authtypes'}) eq 'HASH') {
3725: foreach my $item (@contexts) {
3726: if (ref($settings->{'authtypes'}{$item}) eq 'HASH') {
3727: foreach my $auth (@authtypes) {
3728: if ($settings->{'authtypes'}{$item}{$auth}) {
3729: $checked{$item}{$auth} = ' checked="checked" ';
3730: }
3731: }
3732: }
3733: }
1.27 raeburn 3734: }
1.35 raeburn 3735: } else {
3736: foreach my $item (@contexts) {
1.36 raeburn 3737: foreach my $auth (@authtypes) {
1.35 raeburn 3738: $checked{$item}{$auth} = ' checked="checked" ';
3739: }
3740: }
1.27 raeburn 3741: }
1.28 raeburn 3742: my %title = &context_names();
3743: my %authname = &authtype_names();
3744: my $rownum = 0;
3745: my $css_class;
3746: foreach my $item (@contexts) {
3747: if ($rownum%2) {
3748: $css_class = '';
3749: } else {
3750: $css_class = ' class="LC_odd_row" ';
3751: }
1.30 raeburn 3752: $datatable .= '<tr'.$css_class.'>'.
1.28 raeburn 3753: '<td>'.$title{$item}.
3754: '</td><td class="LC_left_item">'.
3755: '<span class="LC_nobreak">';
3756: foreach my $auth (@authtypes) {
3757: $datatable .= '<label>'.
3758: '<input type="checkbox" name="'.$item.'_auth" '.
3759: $checked{$item}{$auth}.' value="'.$auth.'" />'.
3760: $authname{$auth}.'</label> ';
3761: }
3762: $datatable .= '</span></td></tr>';
3763: $rownum ++;
1.27 raeburn 3764: }
1.30 raeburn 3765: $$rowtotal += $rownum;
1.27 raeburn 3766: }
3767: return $datatable;
3768: }
3769:
1.224 raeburn 3770: sub print_selfcreation {
3771: my ($position,$dom,$settings,$rowtotal) = @_;
3772: my (@selfcreate,$createsettings,$datatable);
3773: if (ref($settings) eq 'HASH') {
3774: if (ref($settings->{'cancreate'}) eq 'HASH') {
3775: $createsettings = $settings->{'cancreate'};
3776: if (ref($settings->{'cancreate'}{'selfcreate'}) eq 'ARRAY') {
3777: @selfcreate = @{$settings->{'cancreate'}{'selfcreate'}};
3778: } elsif ($settings->{'cancreate'}{'selfcreate'} ne '') {
3779: if ($settings->{'cancreate'}{'selfcreate'} eq 'any') {
3780: @selfcreate = ('email','login','sso');
3781: } elsif ($settings->{'cancreate'}{'selfcreate'} ne 'none') {
3782: @selfcreate = ($settings->{'cancreate'}{'selfcreate'});
3783: }
3784: }
3785: }
3786: }
3787: my %radiohash;
3788: my $numinrow = 4;
3789: map { $radiohash{'cancreate_'.$_} = 1; } @selfcreate;
3790: if ($position eq 'top') {
3791: my %choices = &Apache::lonlocal::texthash (
3792: cancreate_login => 'Institutional Login',
3793: cancreate_sso => 'Institutional Single Sign On',
3794: );
3795: my @toggles = sort(keys(%choices));
3796: my %defaultchecked = (
3797: 'cancreate_login' => 'off',
3798: 'cancreate_sso' => 'off',
3799: );
1.228 raeburn 3800: my ($onclick,$itemcount);
1.224 raeburn 3801: ($datatable,$itemcount) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
3802: \%choices,$itemcount,$onclick);
1.228 raeburn 3803: $$rowtotal += $itemcount;
3804:
1.224 raeburn 3805: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
3806:
3807: if (ref($usertypes) eq 'HASH') {
3808: if (keys(%{$usertypes}) > 0) {
3809: $datatable .= &insttypes_row($createsettings,$types,$usertypes,
3810: $dom,$numinrow,$othertitle,
1.228 raeburn 3811: 'statustocreate',$$rowtotal);
1.224 raeburn 3812: $$rowtotal ++;
3813: }
3814: }
3815: } elsif ($position eq 'middle') {
3816: my %domconf = &Apache::lonnet::get_dom('configuration',['usermodification'],$dom);
3817: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
3818: $usertypes->{'default'} = $othertitle;
3819: if (ref($types) eq 'ARRAY') {
3820: push(@{$types},'default');
3821: $usertypes->{'default'} = $othertitle;
3822: foreach my $status (@{$types}) {
3823: $datatable .= &modifiable_userdata_row('selfcreate',$status,$domconf{'usermodification'},
1.228 raeburn 3824: $numinrow,$$rowtotal,$usertypes);
1.224 raeburn 3825: $$rowtotal ++;
3826: }
3827: }
3828: } else {
1.228 raeburn 3829: my $css_class = $$rowtotal%2?' class="LC_odd_row"':'';
1.224 raeburn 3830: my %choices =
3831: &Apache::lonlocal::texthash(
3832: email => 'Approved automatically',
3833: emailapproval => 'Queued for approval by DC',
3834: off => 'Not enabled',
3835: );
3836: $datatable .= '<tr'.$css_class.'>'.
3837: '<td>'.&mt('E-mail address as username').
3838: '</td><td class="LC_left_item">'.
3839: '<span class="LC_nobreak">';
3840: foreach my $option ('email','emailapproval','off') {
3841: my $checked;
3842: if ($option eq 'email') {
3843: if ($radiohash{'cancreate_email'}) {
3844: $checked = 'checked="checked"';
3845: }
3846: } elsif ($option eq 'emailapproval') {
3847: if ($radiohash{'cancreate_emailapproval'}) {
3848: $checked = 'checked="checked"';
3849: }
3850: } else {
3851: if ((!$radiohash{'cancreate_email'}) && (!$radiohash{'cancreate_emailapproval'})) {
3852: $checked = 'checked="checked"';
3853: }
3854: }
3855: $datatable .= '<label>'.
3856: '<input type="radio" name="cancreate_email" '.
3857: $checked.' value="'.$option.'" />'.
3858: $choices{$option}.'</label> ';
3859: }
3860: $$rowtotal ++;
3861: $datatable .= '</span></td></tr>'.
3862: &print_requestmail($dom,'selfcreation',$createsettings,$rowtotal);
1.228 raeburn 3863: $$rowtotal ++;
1.224 raeburn 3864: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
1.228 raeburn 3865: $numinrow = 1;
3866: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
3867: $usertypes->{'default'} = $othertitle;
3868: if (ref($types) eq 'ARRAY') {
3869: push(@{$types},'default');
3870: $usertypes->{'default'} = $othertitle;
3871: foreach my $status (@{$types}) {
3872: $datatable .= &modifiable_userdata_row('cancreate','emailusername_'.$status,$settings,
3873: $numinrow,$$rowtotal,$usertypes,$infofields,$infotitles);
3874: $$rowtotal ++;
3875: }
3876: }
1.224 raeburn 3877: my ($emailrules,$emailruleorder) =
3878: &Apache::lonnet::inst_userrules($dom,'email');
3879: if (ref($emailrules) eq 'HASH') {
3880: if (keys(%{$emailrules}) > 0) {
3881: $datatable .= &user_formats_row('email',$settings,$emailrules,
1.228 raeburn 3882: $emailruleorder,$numinrow,$$rowtotal);
1.224 raeburn 3883: $$rowtotal ++;
3884: }
3885: }
1.228 raeburn 3886: $datatable .= &captcha_choice('cancreate',$createsettings,$$rowtotal);
1.224 raeburn 3887: }
3888: return $datatable;
3889: }
3890:
1.165 raeburn 3891: sub captcha_choice {
1.169 raeburn 3892: my ($context,$settings,$itemcount) = @_;
1.165 raeburn 3893: my ($keyentry,$currpub,$currpriv,%checked,$rowname,$pubtext,$privtext);
3894: my %lt = &captcha_phrases();
3895: $keyentry = 'hidden';
3896: if ($context eq 'cancreate') {
1.224 raeburn 3897: $rowname = &mt('CAPTCHA validation');
1.169 raeburn 3898: } elsif ($context eq 'login') {
3899: $rowname = &mt('"Contact helpdesk" CAPTCHA validation');
1.165 raeburn 3900: }
3901: if (ref($settings) eq 'HASH') {
3902: if ($settings->{'captcha'}) {
3903: $checked{$settings->{'captcha'}} = ' checked="checked"';
3904: } else {
3905: $checked{'original'} = ' checked="checked"';
3906: }
3907: if ($settings->{'captcha'} eq 'recaptcha') {
3908: $pubtext = $lt{'pub'};
3909: $privtext = $lt{'priv'};
3910: $keyentry = 'text';
3911: }
3912: if (ref($settings->{'recaptchakeys'}) eq 'HASH') {
3913: $currpub = $settings->{'recaptchakeys'}{'public'};
3914: $currpriv = $settings->{'recaptchakeys'}{'private'};
3915: }
3916: } else {
3917: $checked{'original'} = ' checked="checked"';
3918: }
1.169 raeburn 3919: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
3920: my $output = '<tr'.$css_class.'>'.
3921: '<td class="LC_left_item">'.$rowname.'</td><td class="LC_left_item" colspan="2">'."\n".
1.165 raeburn 3922: '<table><tr><td>'."\n";
3923: foreach my $option ('original','recaptcha','notused') {
3924: $output .= '<span class="LC_nobreak"><label><input type="radio" name="'.$context.'_captcha" value="'.
3925: $option.'" '.$checked{$option}.' onchange="javascript:updateCaptcha('."this,'$context'".');" />'.
3926: $lt{$option}.'</label></span>';
3927: unless ($option eq 'notused') {
3928: $output .= (' 'x2)."\n";
3929: }
3930: }
3931: #
3932: # Note: If reCAPTCHA is to be used for LON-CAPA servers in a domain, a domain coordinator should visit:
3933: # https://www.google.com/recaptcha and generate a Public and Private key. For domains with multiple
1.210 raeburn 3934: # servers a single key pair will be used for all servers, so the internet domain (e.g., yourcollege.edu)
1.165 raeburn 3935: # specified for use with the key should be broad enough to accommodate all servers in the LON-CAPA domain.
1.210 raeburn 3936: #
1.165 raeburn 3937: $output .= '</td></tr>'."\n".
3938: '<tr><td>'."\n".
3939: '<span class="LC_nobreak"><span id="'.$context.'_recaptchapubtxt">'.$pubtext.'</span> '."\n".
3940: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapub" name="'.$context.'_recaptchapub" value="'.
3941: $currpub.'" size="40" /></span><br />'."\n".
3942: '<span class="LC_nobreak"><span id="'.$context.'_recaptchaprivtxt">'.$privtext.'</span> '."\n".
3943: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapriv" name="'.$context.'_recaptchapriv" value="'.
3944: $currpriv.'" size="40" /></span></td></tr></table>'."\n".
3945: '</td></tr>';
3946: return $output;
3947: }
3948:
1.32 raeburn 3949: sub user_formats_row {
3950: my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount) = @_;
3951: my $output;
3952: my %text = (
3953: 'username' => 'new usernames',
3954: 'id' => 'IDs',
1.45 raeburn 3955: 'email' => 'self-created accounts (e-mail)',
1.32 raeburn 3956: );
3957: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
3958: $output = '<tr '.$css_class.'>'.
1.63 raeburn 3959: '<td><span class="LC_nobreak">';
3960: if ($type eq 'email') {
3961: $output .= &mt("Formats disallowed for $text{$type}: ");
3962: } else {
3963: $output .= &mt("Format rules to check for $text{$type}: ");
3964: }
3965: $output .= '</span></td>'.
3966: '<td class="LC_left_item" colspan="2"><table>';
1.27 raeburn 3967: my $rem;
3968: if (ref($ruleorder) eq 'ARRAY') {
3969: for (my $i=0; $i<@{$ruleorder}; $i++) {
3970: if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
3971: my $rem = $i%($numinrow);
3972: if ($rem == 0) {
3973: if ($i > 0) {
3974: $output .= '</tr>';
3975: }
3976: $output .= '<tr>';
3977: }
3978: my $check = ' ';
1.39 raeburn 3979: if (ref($settings) eq 'HASH') {
3980: if (ref($settings->{$type.'_rule'}) eq 'ARRAY') {
3981: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) {
3982: $check = ' checked="checked" ';
3983: }
1.27 raeburn 3984: }
3985: }
3986: $output .= '<td class="LC_left_item">'.
3987: '<span class="LC_nobreak"><label>'.
1.32 raeburn 3988: '<input type="checkbox" name="'.$type.'_rule" '.
1.27 raeburn 3989: 'value="'.$ruleorder->[$i].'"'.$check.'/>'.
3990: $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
3991: }
3992: }
3993: $rem = @{$ruleorder}%($numinrow);
3994: }
3995: my $colsleft = $numinrow - $rem;
3996: if ($colsleft > 1 ) {
3997: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
3998: ' </td>';
3999: } elsif ($colsleft == 1) {
4000: $output .= '<td class="LC_left_item"> </td>';
4001: }
4002: $output .= '</tr></table></td></tr>';
4003: return $output;
4004: }
4005:
1.34 raeburn 4006: sub usercreation_types {
4007: my %lt = &Apache::lonlocal::texthash (
4008: author => 'When adding a co-author',
4009: course => 'When adding a user to a course',
1.100 raeburn 4010: requestcrs => 'When requesting a course',
1.34 raeburn 4011: any => 'Any',
4012: official => 'Institutional only ',
4013: unofficial => 'Non-institutional only',
4014: none => 'None',
4015: );
4016: return %lt;
1.48 raeburn 4017: }
1.34 raeburn 4018:
1.224 raeburn 4019: sub selfcreation_types {
4020: my %lt = &Apache::lonlocal::texthash (
4021: selfcreate => 'User creates own account',
4022: any => 'Any',
4023: official => 'Institutional only ',
4024: unofficial => 'Non-institutional only',
4025: email => 'E-mail address',
4026: login => 'Institutional Login',
4027: sso => 'SSO',
4028: );
4029: }
4030:
1.28 raeburn 4031: sub authtype_names {
4032: my %lt = &Apache::lonlocal::texthash(
4033: int => 'Internal',
4034: krb4 => 'Kerberos 4',
4035: krb5 => 'Kerberos 5',
4036: loc => 'Local',
4037: );
4038: return %lt;
4039: }
4040:
4041: sub context_names {
4042: my %context_title = &Apache::lonlocal::texthash(
4043: author => 'Creating users when an Author',
4044: course => 'Creating users when in a course',
4045: domain => 'Creating users when a Domain Coordinator',
4046: );
4047: return %context_title;
4048: }
4049:
1.33 raeburn 4050: sub print_usermodification {
4051: my ($position,$dom,$settings,$rowtotal) = @_;
4052: my $numinrow = 4;
4053: my ($context,$datatable,$rowcount);
4054: if ($position eq 'top') {
4055: $rowcount = 0;
4056: $context = 'author';
4057: foreach my $role ('ca','aa') {
4058: $datatable .= &modifiable_userdata_row($context,$role,$settings,
4059: $numinrow,$rowcount);
4060: $$rowtotal ++;
4061: $rowcount ++;
4062: }
1.230 ! raeburn 4063: } elsif ($position eq 'bottom') {
1.33 raeburn 4064: $context = 'course';
4065: $rowcount = 0;
4066: foreach my $role ('st','ep','ta','in','cr') {
4067: $datatable .= &modifiable_userdata_row($context,$role,$settings,
4068: $numinrow,$rowcount);
4069: $$rowtotal ++;
4070: $rowcount ++;
4071: }
4072: }
4073: return $datatable;
4074: }
4075:
1.43 raeburn 4076: sub print_defaults {
1.212 raeburn 4077: my ($dom,$settings,$rowtotal) = @_;
1.68 raeburn 4078: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def',
1.141 raeburn 4079: 'datelocale_def','portal_def');
1.212 raeburn 4080: my %defaults;
4081: if (ref($settings) eq 'HASH') {
1.213 raeburn 4082: %defaults = %{$settings};
1.212 raeburn 4083: } else {
4084: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
4085: foreach my $item (@items) {
4086: $defaults{$item} = $domdefaults{$item};
4087: }
4088: }
1.141 raeburn 4089: my $titles = &defaults_titles($dom);
1.43 raeburn 4090: my $rownum = 0;
4091: my ($datatable,$css_class);
4092: foreach my $item (@items) {
4093: if ($rownum%2) {
4094: $css_class = '';
4095: } else {
4096: $css_class = ' class="LC_odd_row" ';
4097: }
4098: $datatable .= '<tr'.$css_class.'>'.
4099: '<td><span class="LC_nobreak">'.$titles->{$item}.
4100: '</span></td><td class="LC_right_item">';
4101: if ($item eq 'auth_def') {
4102: my @authtypes = ('internal','krb4','krb5','localauth');
4103: my %shortauth = (
4104: internal => 'int',
4105: krb4 => 'krb4',
4106: krb5 => 'krb5',
4107: localauth => 'loc'
4108: );
4109: my %authnames = &authtype_names();
4110: foreach my $auth (@authtypes) {
4111: my $checked = ' ';
1.212 raeburn 4112: if ($defaults{$item} eq $auth) {
1.43 raeburn 4113: $checked = ' checked="checked" ';
4114: }
4115: $datatable .= '<label><input type="radio" name="'.$item.
4116: '" value="'.$auth.'"'.$checked.'/>'.
4117: $authnames{$shortauth{$auth}}.'</label> ';
4118: }
1.54 raeburn 4119: } elsif ($item eq 'timezone_def') {
4120: my $includeempty = 1;
1.212 raeburn 4121: $datatable .= &Apache::loncommon::select_timezone($item,$defaults{$item},undef,$includeempty);
1.68 raeburn 4122: } elsif ($item eq 'datelocale_def') {
4123: my $includeempty = 1;
1.212 raeburn 4124: $datatable .= &Apache::loncommon::select_datelocale($item,$defaults{$item},undef,$includeempty);
1.167 raeburn 4125: } elsif ($item eq 'lang_def') {
1.168 raeburn 4126: my %langchoices = &get_languages_hash();
4127: $langchoices{''} = 'No language preference';
1.167 raeburn 4128: %langchoices = &Apache::lonlocal::texthash(%langchoices);
1.212 raeburn 4129: $datatable .= &Apache::loncommon::select_form($defaults{$item},$item,
1.167 raeburn 4130: \%langchoices);
1.43 raeburn 4131: } else {
1.141 raeburn 4132: my $size;
4133: if ($item eq 'portal_def') {
4134: $size = ' size="25"';
4135: }
1.43 raeburn 4136: $datatable .= '<input type="text" name="'.$item.'" value="'.
1.212 raeburn 4137: $defaults{$item}.'"'.$size.' />';
1.43 raeburn 4138: }
4139: $datatable .= '</td></tr>';
4140: $rownum ++;
4141: }
4142: $$rowtotal += $rownum;
4143: return $datatable;
4144: }
4145:
1.168 raeburn 4146: sub get_languages_hash {
4147: my %langchoices;
4148: foreach my $id (&Apache::loncommon::languageids()) {
4149: my $code = &Apache::loncommon::supportedlanguagecode($id);
4150: if ($code ne '') {
4151: $langchoices{$code} = &Apache::loncommon::plainlanguagedescription($id);
4152: }
4153: }
4154: return %langchoices;
4155: }
4156:
1.43 raeburn 4157: sub defaults_titles {
1.141 raeburn 4158: my ($dom) = @_;
1.43 raeburn 4159: my %titles = &Apache::lonlocal::texthash (
4160: 'auth_def' => 'Default authentication type',
4161: 'auth_arg_def' => 'Default authentication argument',
4162: 'lang_def' => 'Default language',
1.54 raeburn 4163: 'timezone_def' => 'Default timezone',
1.68 raeburn 4164: 'datelocale_def' => 'Default locale for dates',
1.141 raeburn 4165: 'portal_def' => 'Portal/Default URL',
1.43 raeburn 4166: );
1.141 raeburn 4167: if ($dom) {
4168: my $uprimary_id = &Apache::lonnet::domain($dom,'primary');
4169: my $uint_dom = &Apache::lonnet::internet_dom($uprimary_id);
4170: my $protocol = $Apache::lonnet::protocol{$uprimary_id};
4171: $protocol = 'http' if ($protocol ne 'https');
4172: if ($uint_dom) {
4173: $titles{'portal_def'} .= ' '.&mt('(for example: [_1])',$protocol.'://loncapa.'.
4174: $uint_dom);
4175: }
4176: }
1.43 raeburn 4177: return (\%titles);
4178: }
4179:
1.46 raeburn 4180: sub print_scantronformat {
4181: my ($r,$dom,$confname,$settings,$rowtotal) = @_;
4182: my $itemcount = 1;
1.60 raeburn 4183: my ($datatable,$css_class,$scantronurl,$is_custom,%error,%scantronurls,
4184: %confhash);
1.46 raeburn 4185: my $switchserver = &check_switchserver($dom,$confname);
4186: my %lt = &Apache::lonlocal::texthash (
1.95 www 4187: default => 'Default bubblesheet format file error',
4188: custom => 'Custom bubblesheet format file error',
1.46 raeburn 4189: );
4190: my %scantronfiles = (
4191: default => 'default.tab',
4192: custom => 'custom.tab',
4193: );
4194: foreach my $key (keys(%scantronfiles)) {
4195: $scantronurls{$key} = '/res/'.$dom.'/'.$confname.'/scantron/'
4196: .$scantronfiles{$key};
4197: }
4198: my @defaultinfo = &Apache::lonnet::stat_file($scantronurls{'default'});
4199: if ((!@defaultinfo) || ($defaultinfo[0] eq 'no_such_dir')) {
4200: if (!$switchserver) {
4201: my $servadm = $r->dir_config('lonAdmEMail');
4202: my ($configuserok,$author_ok) = &config_check($dom,$confname,$servadm);
4203: if ($configuserok eq 'ok') {
4204: if ($author_ok eq 'ok') {
4205: my %legacyfile = (
4206: default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab',
4207: custom => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab',
4208: );
4209: my %md5chk;
4210: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 4211: ($md5chk{$type}) = split(/ /,`md5sum $legacyfile{$type}`);
4212: chomp($md5chk{$type});
1.46 raeburn 4213: }
4214: if ($md5chk{'default'} ne $md5chk{'custom'}) {
4215: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 4216: ($scantronurls{$type},my $error) =
1.46 raeburn 4217: &legacy_scantronformat($r,$dom,$confname,
4218: $type,$legacyfile{$type},
4219: $scantronurls{$type},
4220: $scantronfiles{$type});
1.60 raeburn 4221: if ($error ne '') {
4222: $error{$type} = $error;
4223: }
4224: }
4225: if (keys(%error) == 0) {
4226: $is_custom = 1;
4227: $confhash{'scantron'}{'scantronformat'} =
4228: $scantronurls{'custom'};
4229: my $putresult =
4230: &Apache::lonnet::put_dom('configuration',
4231: \%confhash,$dom);
4232: if ($putresult ne 'ok') {
4233: $error{'custom'} =
4234: '<span class="LC_error">'.
4235: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
4236: }
1.46 raeburn 4237: }
4238: } else {
1.60 raeburn 4239: ($scantronurls{'default'},my $error) =
1.46 raeburn 4240: &legacy_scantronformat($r,$dom,$confname,
4241: 'default',$legacyfile{'default'},
4242: $scantronurls{'default'},
4243: $scantronfiles{'default'});
1.60 raeburn 4244: if ($error eq '') {
4245: $confhash{'scantron'}{'scantronformat'} = '';
4246: my $putresult =
4247: &Apache::lonnet::put_dom('configuration',
4248: \%confhash,$dom);
4249: if ($putresult ne 'ok') {
4250: $error{'default'} =
4251: '<span class="LC_error">'.
4252: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
4253: }
4254: } else {
4255: $error{'default'} = $error;
4256: }
1.46 raeburn 4257: }
4258: }
4259: }
4260: } else {
1.95 www 4261: $error{'default'} = &mt("Unable to copy default bubblesheet formatfile to domain's RES space: [_1]",$switchserver);
1.46 raeburn 4262: }
4263: }
4264: if (ref($settings) eq 'HASH') {
4265: if ($settings->{'scantronformat'} eq "/res/$dom/$confname/scantron/custom.tab") {
4266: my @info = &Apache::lonnet::stat_file($settings->{'scantronformat'});
4267: if ((!@info) || ($info[0] eq 'no_such_dir')) {
4268: $scantronurl = '';
4269: } else {
4270: $scantronurl = $settings->{'scantronformat'};
4271: }
4272: $is_custom = 1;
4273: } else {
4274: $scantronurl = $scantronurls{'default'};
4275: }
4276: } else {
1.60 raeburn 4277: if ($is_custom) {
4278: $scantronurl = $scantronurls{'custom'};
4279: } else {
4280: $scantronurl = $scantronurls{'default'};
4281: }
1.46 raeburn 4282: }
4283: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4284: $datatable .= '<tr'.$css_class.'>';
4285: if (!$is_custom) {
1.65 raeburn 4286: $datatable .= '<td>'.&mt('Default in use:').'<br />'.
4287: '<span class="LC_nobreak">';
1.46 raeburn 4288: if ($scantronurl) {
1.199 raeburn 4289: $datatable .= &Apache::loncommon::modal_link($scantronurl,&mt('Default bubblesheet format file'),600,500,
4290: undef,undef,undef,undef,'background-color:#ffffff');
1.46 raeburn 4291: } else {
4292: $datatable = &mt('File unavailable for display');
4293: }
1.65 raeburn 4294: $datatable .= '</span></td>';
1.60 raeburn 4295: if (keys(%error) == 0) {
4296: $datatable .= '<td valign="bottom">';
4297: if (!$switchserver) {
4298: $datatable .= &mt('Upload:').'<br />';
4299: }
4300: } else {
4301: my $errorstr;
4302: foreach my $key (sort(keys(%error))) {
4303: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
4304: }
4305: $datatable .= '<td>'.$errorstr;
4306: }
1.46 raeburn 4307: } else {
4308: if (keys(%error) > 0) {
4309: my $errorstr;
4310: foreach my $key (sort(keys(%error))) {
4311: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
4312: }
1.60 raeburn 4313: $datatable .= '<td>'.$errorstr.'</td><td> ';
1.46 raeburn 4314: } elsif ($scantronurl) {
1.199 raeburn 4315: my $link = &Apache::loncommon::modal_link($scantronurl,&mt('Custom bubblesheet format file'),600,500,
4316: undef,undef,undef,undef,'background-color:#ffffff');
1.65 raeburn 4317: $datatable .= '<td><span class="LC_nobreak">'.
1.199 raeburn 4318: $link.
4319: '<label><input type="checkbox" name="scantronformat_del"'.
4320: ' value="1" />'.&mt('Delete?').'</label></span></td>'.
1.65 raeburn 4321: '<td><span class="LC_nobreak"> '.
4322: &mt('Replace:').'</span><br />';
1.46 raeburn 4323: }
4324: }
4325: if (keys(%error) == 0) {
4326: if ($switchserver) {
4327: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
4328: } else {
1.65 raeburn 4329: $datatable .='<span class="LC_nobreak"> '.
4330: '<input type="file" name="scantronformat" /></span>';
1.46 raeburn 4331: }
4332: }
4333: $datatable .= '</td></tr>';
4334: $$rowtotal ++;
4335: return $datatable;
4336: }
4337:
4338: sub legacy_scantronformat {
4339: my ($r,$dom,$confname,$file,$legacyfile,$newurl,$newfile) = @_;
4340: my ($url,$error);
4341: my @statinfo = &Apache::lonnet::stat_file($newurl);
4342: if ((!@statinfo) || ($statinfo[0] eq 'no_such_dir')) {
4343: (my $result,$url) =
4344: &publishlogo($r,'copy',$legacyfile,$dom,$confname,'scantron',
4345: '','',$newfile);
4346: if ($result ne 'ok') {
1.130 raeburn 4347: $error = &mt("An error occurred publishing the [_1] bubblesheet format file in RES space. Error was: [_2].",$newfile,$result);
1.46 raeburn 4348: }
4349: }
4350: return ($url,$error);
4351: }
1.43 raeburn 4352:
1.49 raeburn 4353: sub print_coursecategories {
1.57 raeburn 4354: my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;
4355: my $datatable;
4356: if ($position eq 'top') {
4357: my $toggle_cats_crs = ' ';
4358: my $toggle_cats_dom = ' checked="checked" ';
4359: my $can_cat_crs = ' ';
4360: my $can_cat_dom = ' checked="checked" ';
1.120 raeburn 4361: my $toggle_catscomm_comm = ' ';
4362: my $toggle_catscomm_dom = ' checked="checked" ';
4363: my $can_catcomm_comm = ' ';
4364: my $can_catcomm_dom = ' checked="checked" ';
4365:
1.57 raeburn 4366: if (ref($settings) eq 'HASH') {
4367: if ($settings->{'togglecats'} eq 'crs') {
4368: $toggle_cats_crs = $toggle_cats_dom;
4369: $toggle_cats_dom = ' ';
4370: }
4371: if ($settings->{'categorize'} eq 'crs') {
4372: $can_cat_crs = $can_cat_dom;
4373: $can_cat_dom = ' ';
4374: }
1.120 raeburn 4375: if ($settings->{'togglecatscomm'} eq 'comm') {
4376: $toggle_catscomm_comm = $toggle_catscomm_dom;
4377: $toggle_catscomm_dom = ' ';
4378: }
4379: if ($settings->{'categorizecomm'} eq 'comm') {
4380: $can_catcomm_comm = $can_catcomm_dom;
4381: $can_catcomm_dom = ' ';
4382: }
1.57 raeburn 4383: }
4384: my %title = &Apache::lonlocal::texthash (
1.120 raeburn 4385: togglecats => 'Show/Hide a course in catalog',
4386: togglecatscomm => 'Show/Hide a community in catalog',
4387: categorize => 'Assign a category to a course',
4388: categorizecomm => 'Assign a category to a community',
1.57 raeburn 4389: );
4390: my %level = &Apache::lonlocal::texthash (
1.120 raeburn 4391: dom => 'Set in Domain',
4392: crs => 'Set in Course',
4393: comm => 'Set in Community',
1.57 raeburn 4394: );
4395: $datatable = '<tr class="LC_odd_row">'.
4396: '<td>'.$title{'togglecats'}.'</td>'.
4397: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4398: '<input type="radio" name="togglecats"'.
4399: $toggle_cats_dom.' value="dom" />'.$level{'dom'}.'</label> '.
4400: '<label><input type="radio" name="togglecats"'.
4401: $toggle_cats_crs.' value="crs" />'.$level{'crs'}.'</label></span></td>'.
4402: '</tr><tr>'.
4403: '<td>'.$title{'categorize'}.'</td>'.
4404: '<td class="LC_right_item"><span class="LC_nobreak">'.
4405: '<label><input type="radio" name="categorize"'.
4406: $can_cat_dom.' value="dom" />'.$level{'dom'}.'</label> '.
4407: '<label><input type="radio" name="categorize"'.
4408: $can_cat_crs.'value="crs" />'.$level{'crs'}.'</label></span></td>'.
1.120 raeburn 4409: '</tr><tr class="LC_odd_row">'.
4410: '<td>'.$title{'togglecatscomm'}.'</td>'.
4411: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4412: '<input type="radio" name="togglecatscomm"'.
4413: $toggle_catscomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
4414: '<label><input type="radio" name="togglecatscomm"'.
4415: $toggle_catscomm_comm.' value="comm" />'.$level{'comm'}.'</label></span></td>'.
4416: '</tr><tr>'.
4417: '<td>'.$title{'categorizecomm'}.'</td>'.
4418: '<td class="LC_right_item"><span class="LC_nobreak">'.
4419: '<label><input type="radio" name="categorizecomm"'.
4420: $can_catcomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
4421: '<label><input type="radio" name="categorizecomm"'.
4422: $can_catcomm_comm.'value="comm" />'.$level{'comm'}.'</label></span></td>'.
1.57 raeburn 4423: '</tr>';
1.120 raeburn 4424: $$rowtotal += 4;
1.57 raeburn 4425: } else {
4426: my $css_class;
4427: my $itemcount = 1;
4428: my $cathash;
4429: if (ref($settings) eq 'HASH') {
4430: $cathash = $settings->{'cats'};
4431: }
4432: if (ref($cathash) eq 'HASH') {
4433: my (@cats,@trails,%allitems,%idx,@jsarray);
4434: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
4435: \%allitems,\%idx,\@jsarray);
4436: my $maxdepth = scalar(@cats);
4437: my $colattrib = '';
4438: if ($maxdepth > 2) {
4439: $colattrib = ' colspan="2" ';
4440: }
4441: my @path;
4442: if (@cats > 0) {
4443: if (ref($cats[0]) eq 'ARRAY') {
4444: my $numtop = @{$cats[0]};
4445: my $maxnum = $numtop;
1.120 raeburn 4446: my %default_names = (
4447: instcode => &mt('Official courses'),
4448: communities => &mt('Communities'),
4449: );
4450:
4451: if ((!grep(/^instcode$/,@{$cats[0]})) ||
4452: ($cathash->{'instcode::0'} eq '') ||
4453: (!grep(/^communities$/,@{$cats[0]})) ||
4454: ($cathash->{'communities::0'} eq '')) {
1.57 raeburn 4455: $maxnum ++;
4456: }
4457: my $lastidx;
4458: for (my $i=0; $i<$numtop; $i++) {
4459: my $parent = $cats[0][$i];
4460: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4461: my $item = &escape($parent).'::0';
4462: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$item','$idx{$item}'".');"';
4463: $lastidx = $idx{$item};
4464: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
4465: .'<select name="'.$item.'"'.$chgstr.'>';
4466: for (my $k=0; $k<=$maxnum; $k++) {
4467: my $vpos = $k+1;
4468: my $selstr;
4469: if ($k == $i) {
4470: $selstr = ' selected="selected" ';
4471: }
4472: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4473: }
1.214 raeburn 4474: $datatable .= '</select></span></td><td>';
1.120 raeburn 4475: if ($parent eq 'instcode' || $parent eq 'communities') {
4476: $datatable .= '<span class="LC_nobreak">'
4477: .$default_names{$parent}.'</span>';
4478: if ($parent eq 'instcode') {
4479: $datatable .= '<br /><span class="LC_nobreak">('
4480: .&mt('with institutional codes')
4481: .')</span></td><td'.$colattrib.'>';
4482: } else {
4483: $datatable .= '<table><tr><td>';
4484: }
4485: $datatable .= '<span class="LC_nobreak">'
4486: .'<label><input type="radio" name="'
4487: .$parent.'" value="1" checked="checked" />'
4488: .&mt('Display').'</label>';
4489: if ($parent eq 'instcode') {
4490: $datatable .= ' ';
4491: } else {
4492: $datatable .= '</span></td></tr><tr><td>'
4493: .'<span class="LC_nobreak">';
4494: }
4495: $datatable .= '<label><input type="radio" name="'
4496: .$parent.'" value="0" />'
4497: .&mt('Do not display').'</label></span>';
4498: if ($parent eq 'communities') {
4499: $datatable .= '</td></tr></table>';
4500: }
4501: $datatable .= '</td>';
1.57 raeburn 4502: } else {
4503: $datatable .= $parent
1.214 raeburn 4504: .' <span class="LC_nobreak"><label>'
4505: .'<input type="checkbox" name="deletecategory" '
1.57 raeburn 4506: .'value="'.$item.'" />'.&mt('Delete').'</label></span></td>';
4507: }
4508: my $depth = 1;
4509: push(@path,$parent);
4510: $datatable .= &build_category_rows($itemcount,\@cats,$depth,$parent,\@path,\%idx);
4511: pop(@path);
4512: $datatable .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
4513: $itemcount ++;
4514: }
1.48 raeburn 4515: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.57 raeburn 4516: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','$lastidx'".');"';
4517: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="addcategory_pos"'.$chgstr.'>';
1.48 raeburn 4518: for (my $k=0; $k<=$maxnum; $k++) {
4519: my $vpos = $k+1;
4520: my $selstr;
1.57 raeburn 4521: if ($k == $numtop) {
1.48 raeburn 4522: $selstr = ' selected="selected" ';
4523: }
4524: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4525: }
1.59 bisitz 4526: $datatable .= '</select></span></td><td colspan="2">'.&mt('Add category:').' '
1.57 raeburn 4527: .'<input type="text" size="20" name="addcategory_name" value="" /></td>'
4528: .'</tr>'."\n";
1.48 raeburn 4529: $itemcount ++;
1.120 raeburn 4530: foreach my $default ('instcode','communities') {
4531: if ((!grep(/^\Q$default\E$/,@{$cats[0]})) || ($cathash->{$default.'::0'} eq '')) {
4532: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4533: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','$lastidx'".');"';
4534: $datatable .= '<tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr><tr '.$css_class.'><td>'.
4535: '<span class="LC_nobreak"><select name="'.$default.'_pos"'.$chgstr.'>';
4536: for (my $k=0; $k<=$maxnum; $k++) {
4537: my $vpos = $k+1;
4538: my $selstr;
4539: if ($k == $maxnum) {
4540: $selstr = ' selected="selected" ';
4541: }
4542: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.57 raeburn 4543: }
1.120 raeburn 4544: $datatable .= '</select></span></td>'.
4545: '<td><span class="LC_nobreak">'.
4546: $default_names{$default}.'</span>';
4547: if ($default eq 'instcode') {
4548: $datatable .= '<br /><span class="LC_nobreak">('
4549: .&mt('with institutional codes').')</span>';
4550: }
4551: $datatable .= '</td>'
4552: .'<td><span class="LC_nobreak"><label><input type="radio" name="'.$default.'" value="1" />'
4553: .&mt('Display').'</label> '
4554: .'<label><input type="radio" name="'.$default.'" value="0" checked="checked"/>'
4555: .&mt('Do not display').'</label></span></td></tr>';
1.48 raeburn 4556: }
4557: }
4558: }
1.57 raeburn 4559: } else {
4560: $datatable .= &initialize_categories($itemcount);
1.48 raeburn 4561: }
4562: } else {
1.57 raeburn 4563: $datatable .= '<td class="LC_right_item">'.$hdritem->{'header'}->[0]->{'col2'}.'</td>'
4564: .&initialize_categories($itemcount);
1.48 raeburn 4565: }
1.57 raeburn 4566: $$rowtotal += $itemcount;
1.48 raeburn 4567: }
4568: return $datatable;
4569: }
4570:
1.69 raeburn 4571: sub print_serverstatuses {
4572: my ($dom,$settings,$rowtotal) = @_;
4573: my $datatable;
4574: my @pages = &serverstatus_pages();
4575: my (%namedaccess,%machineaccess);
4576: foreach my $type (@pages) {
4577: $namedaccess{$type} = '';
4578: $machineaccess{$type}= '';
4579: }
4580: if (ref($settings) eq 'HASH') {
4581: foreach my $type (@pages) {
4582: if (exists($settings->{$type})) {
4583: if (ref($settings->{$type}) eq 'HASH') {
4584: foreach my $key (keys(%{$settings->{$type}})) {
4585: if ($key eq 'namedusers') {
4586: $namedaccess{$type} = $settings->{$type}->{$key};
4587: } elsif ($key eq 'machines') {
4588: $machineaccess{$type} = $settings->{$type}->{$key};
4589: }
4590: }
4591: }
4592: }
4593: }
4594: }
1.81 raeburn 4595: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 4596: my $rownum = 0;
4597: my $css_class;
4598: foreach my $type (@pages) {
4599: $rownum ++;
4600: $css_class = $rownum%2?' class="LC_odd_row"':'';
4601: $datatable .= '<tr'.$css_class.'>'.
4602: '<td><span class="LC_nobreak">'.
4603: $titles->{$type}.'</span></td>'.
4604: '<td class="LC_left_item">'.
4605: '<input type="text" name="'.$type.'_namedusers" '.
4606: 'value="'.$namedaccess{$type}.'" size="30" /></td>'.
4607: '<td class="LC_right_item">'.
4608: '<span class="LC_nobreak">'.
4609: '<input type="text" name="'.$type.'_machines" '.
4610: 'value="'.$machineaccess{$type}.'" size="10" />'.
4611: '</td></tr>'."\n";
4612: }
4613: $$rowtotal += $rownum;
4614: return $datatable;
4615: }
4616:
4617: sub serverstatus_pages {
4618: return ('userstatus','lonstatus','loncron','server-status','codeversions',
1.189 raeburn 4619: 'checksums','clusterstatus','metadata_keywords','metadata_harvest',
1.221 raeburn 4620: 'takeoffline','takeonline','showenv','toggledebug','ping','domconf',
1.229 raeburn 4621: 'uniquecodes','diskusage');
1.69 raeburn 4622: }
4623:
1.49 raeburn 4624: sub coursecategories_javascript {
4625: my ($settings) = @_;
1.57 raeburn 4626: my ($output,$jstext,$cathash);
1.49 raeburn 4627: if (ref($settings) eq 'HASH') {
1.57 raeburn 4628: $cathash = $settings->{'cats'};
4629: }
4630: if (ref($cathash) eq 'HASH') {
1.49 raeburn 4631: my (@cats,@jsarray,%idx);
1.57 raeburn 4632: &Apache::loncommon::gather_categories($cathash,\@cats,\%idx,\@jsarray);
1.49 raeburn 4633: if (@jsarray > 0) {
4634: $jstext = ' var categories = Array('.scalar(@jsarray).');'."\n";
4635: for (my $i=0; $i<@jsarray; $i++) {
4636: if (ref($jsarray[$i]) eq 'ARRAY') {
4637: my $catstr = join('","',@{$jsarray[$i]});
4638: $jstext .= ' categories['.$i.'] = Array("'.$catstr.'");'."\n";
4639: }
4640: }
4641: }
4642: } else {
4643: $jstext = ' var categories = Array(1);'."\n".
4644: ' categories[0] = Array("instcode_pos");'."\n";
4645: }
1.120 raeburn 4646: my $instcode_reserved = &mt('The name: "instcode" is a reserved category');
4647: my $communities_reserved = &mt('The name: "communities" is a reserved category');
4648: my $choose_again = '\\n'.&mt('Please use a different name for the new top level category');
1.49 raeburn 4649: $output = <<"ENDSCRIPT";
4650: <script type="text/javascript">
1.109 raeburn 4651: // <![CDATA[
1.49 raeburn 4652: function reorderCats(form,parent,item,idx) {
4653: var changedVal;
4654: $jstext
4655: var newpos = 'addcategory_pos';
4656: var current = new Array;
4657: if (parent == '') {
4658: var has_instcode = 0;
4659: var maxtop = categories[idx].length;
4660: for (var j=0; j<maxtop; j++) {
4661: if (categories[idx][j] == 'instcode::0') {
4662: has_instcode == 1;
4663: }
4664: }
4665: if (has_instcode == 0) {
4666: categories[idx][maxtop] = 'instcode_pos';
4667: }
4668: } else {
4669: newpos += '_'+parent;
4670: }
4671: var maxh = 1 + categories[idx].length;
4672: var current = new Array;
4673: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
4674: if (item == newpos) {
4675: changedVal = newitemVal;
4676: } else {
4677: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
4678: current[newitemVal] = newpos;
4679: }
4680: for (var i=0; i<categories[idx].length; i++) {
4681: var elementName = categories[idx][i];
4682: if (elementName != item) {
4683: if (form.elements[elementName]) {
4684: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
4685: current[currVal] = elementName;
4686: }
4687: }
4688: }
4689: var oldVal;
4690: for (var j=0; j<maxh; j++) {
4691: if (current[j] == undefined) {
4692: oldVal = j;
4693: }
4694: }
4695: if (oldVal < changedVal) {
4696: for (var k=oldVal+1; k<=changedVal ; k++) {
4697: var elementName = current[k];
4698: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
4699: }
4700: } else {
4701: for (var k=changedVal; k<oldVal; k++) {
4702: var elementName = current[k];
4703: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
4704: }
4705: }
4706: return;
4707: }
1.120 raeburn 4708:
4709: function categoryCheck(form) {
4710: if (form.elements['addcategory_name'].value == 'instcode') {
4711: alert('$instcode_reserved\\n$choose_again');
4712: return false;
4713: }
4714: if (form.elements['addcategory_name'].value == 'communities') {
4715: alert('$communities_reserved\\n$choose_again');
4716: return false;
4717: }
4718: return true;
4719: }
4720:
1.109 raeburn 4721: // ]]>
1.49 raeburn 4722: </script>
4723:
4724: ENDSCRIPT
4725: return $output;
4726: }
4727:
1.48 raeburn 4728: sub initialize_categories {
4729: my ($itemcount) = @_;
1.120 raeburn 4730: my ($datatable,$css_class,$chgstr);
4731: my %default_names = (
4732: instcode => 'Official courses (with institutional codes)',
4733: communities => 'Communities',
4734: );
4735: my $select0 = ' selected="selected"';
4736: my $select1 = '';
4737: foreach my $default ('instcode','communities') {
4738: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4739: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'',$default"."_pos','0'".');"';
4740: if ($default eq 'communities') {
4741: $select1 = $select0;
4742: $select0 = '';
4743: }
4744: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
4745: .'<select name="'.$default.'_pos">'
4746: .'<option value="0"'.$select0.'>1</option>'
4747: .'<option value="1"'.$select1.'>2</option>'
4748: .'<option value="2">3</option></select> '
4749: .$default_names{$default}
4750: .'</span></td><td><span class="LC_nobreak">'
4751: .'<label><input type="radio" name="'.$default.'" value="1" checked="checked" />'
4752: .&mt('Display').'</label> <label>'
4753: .'<input type="radio" name="'.$default.'" value="0" />'.&mt('Do not display')
1.48 raeburn 4754: .'</label></span></td></tr>';
1.120 raeburn 4755: $itemcount ++;
4756: }
1.48 raeburn 4757: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.49 raeburn 4758: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','0'".');"';
1.48 raeburn 4759: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.120 raeburn 4760: .'<select name="addcategory_pos"'.$chgstr.'>'
4761: .'<option value="0">1</option>'
4762: .'<option value="1">2</option>'
4763: .'<option value="2" selected="selected">3</option></select> '
1.48 raeburn 4764: .&mt('Add category').'</td><td>'.&mt('Name:')
4765: .' <input type="text" size="20" name="addcategory_name" value="" /></td></tr>';
4766: return $datatable;
4767: }
4768:
4769: sub build_category_rows {
1.49 raeburn 4770: my ($itemcount,$cats,$depth,$parent,$path,$idx) = @_;
4771: my ($text,$name,$item,$chgstr);
1.48 raeburn 4772: if (ref($cats) eq 'ARRAY') {
4773: my $maxdepth = scalar(@{$cats});
4774: if (ref($cats->[$depth]) eq 'HASH') {
4775: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
4776: my $numchildren = @{$cats->[$depth]{$parent}};
4777: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.204 raeburn 4778: $text .= '<td><table class="LC_data_table">';
1.49 raeburn 4779: my ($idxnum,$parent_name,$parent_item);
4780: my $higher = $depth - 1;
4781: if ($higher == 0) {
4782: $parent_name = &escape($parent).'::'.$higher;
4783: } else {
4784: if (ref($path) eq 'ARRAY') {
4785: $parent_name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
4786: }
4787: }
4788: $parent_item = 'addcategory_pos_'.$parent_name;
1.48 raeburn 4789: for (my $j=0; $j<=$numchildren; $j++) {
1.49 raeburn 4790: if ($j < $numchildren) {
1.48 raeburn 4791: $name = $cats->[$depth]{$parent}[$j];
4792: $item = &escape($name).':'.&escape($parent).':'.$depth;
1.49 raeburn 4793: $idxnum = $idx->{$item};
4794: } else {
4795: $name = $parent_name;
4796: $item = $parent_item;
1.48 raeburn 4797: }
1.49 raeburn 4798: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'$parent_name','$item','$idxnum'".');"';
4799: $text .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="'.$item.'"'.$chgstr.'>';
1.48 raeburn 4800: for (my $i=0; $i<=$numchildren; $i++) {
4801: my $vpos = $i+1;
4802: my $selstr;
4803: if ($j == $i) {
4804: $selstr = ' selected="selected" ';
4805: }
4806: $text .= '<option value="'.$i.'"'.$selstr.'>'.$vpos.'</option>';
4807: }
4808: $text .= '</select> ';
4809: if ($j < $numchildren) {
4810: my $deeper = $depth+1;
4811: $text .= $name.' '
4812: .'<label><input type="checkbox" name="deletecategory" value="'
4813: .$item.'" />'.&mt('Delete').'</label></span></td><td>';
4814: if(ref($path) eq 'ARRAY') {
4815: push(@{$path},$name);
1.49 raeburn 4816: $text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path,$idx);
1.48 raeburn 4817: pop(@{$path});
4818: }
4819: } else {
1.59 bisitz 4820: $text .= &mt('Add subcategory:').' </span><input type="textbox" size="20" name="addcategory_name_';
1.48 raeburn 4821: if ($j == $numchildren) {
4822: $text .= $name;
4823: } else {
4824: $text .= $item;
4825: }
4826: $text .= '" value="" />';
4827: }
4828: $text .= '</td></tr>';
4829: }
4830: $text .= '</table></td>';
4831: } else {
4832: my $higher = $depth-1;
4833: if ($higher == 0) {
4834: $name = &escape($parent).'::'.$higher;
4835: } else {
4836: if (ref($path) eq 'ARRAY') {
4837: $name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
4838: }
4839: }
4840: my $colspan;
4841: if ($parent ne 'instcode') {
4842: $colspan = $maxdepth - $depth - 1;
4843: $text .= '<td colspan="'.$colspan.'">'.&mt('Add subcategory:').'<input type="textbox" size="20" name="subcat_'.$name.'" value="" /></td>';
4844: }
4845: }
4846: }
4847: }
4848: return $text;
4849: }
4850:
1.33 raeburn 4851: sub modifiable_userdata_row {
1.228 raeburn 4852: my ($context,$item,$settings,$numinrow,$rowcount,$usertypes,$fieldsref,$titlesref) = @_;
4853: my ($role,$rolename,$statustype);
4854: $role = $item;
1.224 raeburn 4855: if ($context eq 'cancreate') {
1.228 raeburn 4856: if ($item =~ /^emailusername_(.+)$/) {
4857: $statustype = $1;
4858: $role = 'emailusername';
4859: if (ref($usertypes) eq 'HASH') {
4860: if ($usertypes->{$statustype}) {
4861: $rolename = &mt('Data provided by [_1]',$usertypes->{$statustype});
4862: } else {
4863: $rolename = &mt('Data provided by user');
4864: }
4865: }
1.224 raeburn 4866: }
4867: } elsif ($context eq 'selfcreate') {
1.63 raeburn 4868: if (ref($usertypes) eq 'HASH') {
4869: $rolename = $usertypes->{$role};
4870: } else {
4871: $rolename = $role;
4872: }
1.33 raeburn 4873: } else {
1.63 raeburn 4874: if ($role eq 'cr') {
4875: $rolename = &mt('Custom role');
4876: } else {
4877: $rolename = &Apache::lonnet::plaintext($role);
4878: }
1.33 raeburn 4879: }
1.224 raeburn 4880: my (@fields,%fieldtitles);
4881: if (ref($fieldsref) eq 'ARRAY') {
4882: @fields = @{$fieldsref};
4883: } else {
4884: @fields = ('lastname','firstname','middlename','generation',
4885: 'permanentemail','id');
4886: }
4887: if ((ref($titlesref) eq 'HASH')) {
4888: %fieldtitles = %{$titlesref};
4889: } else {
4890: %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
4891: }
1.33 raeburn 4892: my $output;
4893: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
4894: $output = '<tr '.$css_class.'>'.
4895: '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
4896: '<td class="LC_left_item" colspan="2"><table>';
4897: my $rem;
4898: my %checks;
4899: if (ref($settings) eq 'HASH') {
4900: if (ref($settings->{$context}) eq 'HASH') {
4901: if (ref($settings->{$context}->{$role}) eq 'HASH') {
1.228 raeburn 4902: my $hashref = $settings->{$context}->{$role};
4903: if ($role eq 'emailusername') {
4904: if ($statustype) {
4905: if (ref($settings->{$context}->{$role}->{$statustype}) eq 'HASH') {
4906: $hashref = $settings->{$context}->{$role}->{$statustype};
4907: if (ref($hashref) eq 'HASH') {
4908: foreach my $field (@fields) {
4909: if ($hashref->{$field}) {
4910: $checks{$field} = $hashref->{$field};
4911: }
4912: }
4913: }
4914: }
4915: }
4916: } else {
4917: if (ref($hashref) eq 'HASH') {
4918: foreach my $field (@fields) {
4919: if ($hashref->{$field}) {
4920: $checks{$field} = ' checked="checked" ';
4921: }
4922: }
1.33 raeburn 4923: }
4924: }
4925: }
4926: }
4927: }
1.228 raeburn 4928:
1.33 raeburn 4929: for (my $i=0; $i<@fields; $i++) {
4930: my $rem = $i%($numinrow);
4931: if ($rem == 0) {
4932: if ($i > 0) {
4933: $output .= '</tr>';
4934: }
4935: $output .= '<tr>';
4936: }
4937: my $check = ' ';
1.228 raeburn 4938: unless ($role eq 'emailusername') {
4939: if (exists($checks{$fields[$i]})) {
4940: $check = $checks{$fields[$i]}
4941: } else {
4942: if ($role eq 'st') {
4943: if (ref($settings) ne 'HASH') {
4944: $check = ' checked="checked" ';
4945: }
1.33 raeburn 4946: }
4947: }
4948: }
4949: $output .= '<td class="LC_left_item">'.
1.228 raeburn 4950: '<span class="LC_nobreak">';
4951: if ($role eq 'emailusername') {
4952: unless ($checks{$fields[$i]} =~ /^(required|optional)$/) {
4953: $checks{$fields[$i]} = 'omit';
4954: }
4955: foreach my $option ('required','optional','omit') {
4956: my $checked='';
4957: if ($checks{$fields[$i]} eq $option) {
4958: $checked='checked="checked" ';
4959: }
4960: $output .= '<label>'.
4961: '<input type="radio" name="canmodify_'.$item.'_'.$fields[$i].'" value="'.$option.'" '.$checked.'/>'.
4962: &mt($option).'</label>'.(' ' x2);
4963: }
4964: $output .= '<i>'.$fieldtitles{$fields[$i]}.'</i>';
4965: } else {
4966: $output .= '<label>'.
4967: '<input type="checkbox" name="canmodify_'.$role.'" '.
4968: 'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
4969: '</label>';
4970: }
4971: $output .= '</span></td>';
1.33 raeburn 4972: $rem = @fields%($numinrow);
4973: }
4974: my $colsleft = $numinrow - $rem;
4975: if ($colsleft > 1 ) {
4976: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
4977: ' </td>';
4978: } elsif ($colsleft == 1) {
4979: $output .= '<td class="LC_left_item"> </td>';
4980: }
4981: $output .= '</tr></table></td></tr>';
4982: return $output;
4983: }
1.28 raeburn 4984:
1.93 raeburn 4985: sub insttypes_row {
1.224 raeburn 4986: my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle,$context,$rownum) = @_;
1.93 raeburn 4987: my %lt = &Apache::lonlocal::texthash (
4988: cansearch => 'Users allowed to search',
4989: statustocreate => 'Institutional affiliation(s) able to create own account (login/SSO)',
1.131 raeburn 4990: lockablenames => 'User preference to lock name',
1.93 raeburn 4991: );
4992: my $showdom;
4993: if ($context eq 'cansearch') {
4994: $showdom = ' ('.$dom.')';
4995: }
1.165 raeburn 4996: my $class = 'LC_left_item';
4997: if ($context eq 'statustocreate') {
4998: $class = 'LC_right_item';
4999: }
1.224 raeburn 5000: my $css_class = ' class="LC_odd_row"';
5001: if ($rownum ne '') {
5002: $css_class = ($rownum%2? ' class="LC_odd_row"':'');
5003: }
5004: my $output = '<tr'.$css_class.'>'.
5005: '<td>'.$lt{$context}.$showdom.
5006: '</td><td class="'.$class.'" colspan="2"><table>';
1.26 raeburn 5007: my $rem;
5008: if (ref($types) eq 'ARRAY') {
5009: for (my $i=0; $i<@{$types}; $i++) {
5010: if (defined($usertypes->{$types->[$i]})) {
5011: my $rem = $i%($numinrow);
5012: if ($rem == 0) {
5013: if ($i > 0) {
5014: $output .= '</tr>';
5015: }
5016: $output .= '<tr>';
1.23 raeburn 5017: }
1.26 raeburn 5018: my $check = ' ';
1.99 raeburn 5019: if (ref($settings) eq 'HASH') {
5020: if (ref($settings->{$context}) eq 'ARRAY') {
5021: if (grep(/^\Q$types->[$i]\E$/,@{$settings->{$context}})) {
5022: $check = ' checked="checked" ';
5023: }
5024: } elsif ($context eq 'statustocreate') {
1.26 raeburn 5025: $check = ' checked="checked" ';
5026: }
1.23 raeburn 5027: }
1.26 raeburn 5028: $output .= '<td class="LC_left_item">'.
5029: '<span class="LC_nobreak"><label>'.
1.93 raeburn 5030: '<input type="checkbox" name="'.$context.'" '.
1.26 raeburn 5031: 'value="'.$types->[$i].'"'.$check.'/>'.
5032: $usertypes->{$types->[$i]}.'</label></span></td>';
1.23 raeburn 5033: }
5034: }
1.26 raeburn 5035: $rem = @{$types}%($numinrow);
1.23 raeburn 5036: }
5037: my $colsleft = $numinrow - $rem;
1.131 raeburn 5038: if (($rem == 0) && (@{$types} > 0)) {
5039: $output .= '<tr>';
5040: }
1.23 raeburn 5041: if ($colsleft > 1) {
1.25 raeburn 5042: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
1.23 raeburn 5043: } else {
1.25 raeburn 5044: $output .= '<td class="LC_left_item">';
1.23 raeburn 5045: }
5046: my $defcheck = ' ';
1.99 raeburn 5047: if (ref($settings) eq 'HASH') {
5048: if (ref($settings->{$context}) eq 'ARRAY') {
5049: if (grep(/^default$/,@{$settings->{$context}})) {
5050: $defcheck = ' checked="checked" ';
5051: }
5052: } elsif ($context eq 'statustocreate') {
1.26 raeburn 5053: $defcheck = ' checked="checked" ';
5054: }
1.23 raeburn 5055: }
1.25 raeburn 5056: $output .= '<span class="LC_nobreak"><label>'.
1.93 raeburn 5057: '<input type="checkbox" name="'.$context.'" '.
1.25 raeburn 5058: 'value="default"'.$defcheck.'/>'.
5059: $othertitle.'</label></span></td>'.
5060: '</tr></table></td></tr>';
5061: return $output;
1.23 raeburn 5062: }
5063:
5064: sub sorted_searchtitles {
5065: my %searchtitles = &Apache::lonlocal::texthash(
5066: 'uname' => 'username',
5067: 'lastname' => 'last name',
5068: 'lastfirst' => 'last name, first name',
5069: );
5070: my @titleorder = ('uname','lastname','lastfirst');
5071: return (\%searchtitles,\@titleorder);
5072: }
5073:
1.25 raeburn 5074: sub sorted_searchtypes {
5075: my %srchtypes_desc = (
5076: exact => 'is exact match',
5077: contains => 'contains ..',
5078: begins => 'begins with ..',
5079: );
5080: my @srchtypeorder = ('exact','begins','contains');
5081: return (\%srchtypes_desc,\@srchtypeorder);
5082: }
5083:
1.3 raeburn 5084: sub usertype_update_row {
5085: my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
5086: my $datatable;
5087: my $numinrow = 4;
5088: foreach my $type (@{$types}) {
5089: if (defined($usertypes->{$type})) {
5090: $$rownums ++;
5091: my $css_class = $$rownums%2?' class="LC_odd_row"':'';
5092: $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
5093: '</td><td class="LC_left_item"><table>';
5094: for (my $i=0; $i<@{$fields}; $i++) {
5095: my $rem = $i%($numinrow);
5096: if ($rem == 0) {
5097: if ($i > 0) {
5098: $datatable .= '</tr>';
5099: }
5100: $datatable .= '<tr>';
5101: }
5102: my $check = ' ';
1.39 raeburn 5103: if (ref($settings) eq 'HASH') {
5104: if (ref($settings->{'fields'}) eq 'HASH') {
5105: if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
5106: if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
5107: $check = ' checked="checked" ';
5108: }
1.3 raeburn 5109: }
5110: }
5111: }
5112:
5113: if ($i == @{$fields}-1) {
5114: my $colsleft = $numinrow - $rem;
5115: if ($colsleft > 1) {
5116: $datatable .= '<td colspan="'.$colsleft.'">';
5117: } else {
5118: $datatable .= '<td>';
5119: }
5120: } else {
5121: $datatable .= '<td>';
5122: }
1.8 raeburn 5123: $datatable .= '<span class="LC_nobreak"><label>'.
5124: '<input type="checkbox" name="updateable_'.$type.
5125: '_'.$fields->[$i].'" value="1"'.$check.'/>'.
5126: $fieldtitles->{$fields->[$i]}.'</label></span></td>';
1.3 raeburn 5127: }
5128: $datatable .= '</tr></table></td></tr>';
5129: }
5130: }
5131: return $datatable;
1.1 raeburn 5132: }
5133:
5134: sub modify_login {
1.205 raeburn 5135: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.168 raeburn 5136: my ($resulttext,$errors,$colchgtext,%changes,%colchanges,%newfile,%newurl,
5137: %curr_loginvia,%loginhash,@currlangs,@newlangs,$addedfile,%title,@offon);
5138: %title = ( coursecatalog => 'Display course catalog',
5139: adminmail => 'Display administrator E-mail address',
1.188 raeburn 5140: helpdesk => 'Display "Contact Helpdesk" link',
1.168 raeburn 5141: newuser => 'Link for visitors to create a user account',
5142: loginheader => 'Log-in box header');
5143: @offon = ('off','on');
1.112 raeburn 5144: if (ref($domconfig{login}) eq 'HASH') {
5145: if (ref($domconfig{login}{loginvia}) eq 'HASH') {
5146: foreach my $lonhost (keys(%{$domconfig{login}{loginvia}})) {
5147: $curr_loginvia{$lonhost} = $domconfig{login}{loginvia}{$lonhost};
5148: }
5149: }
5150: }
1.9 raeburn 5151: ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
5152: \%domconfig,\%loginhash);
1.188 raeburn 5153: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 5154: foreach my $item (@toggles) {
5155: $loginhash{login}{$item} = $env{'form.'.$item};
5156: }
1.41 raeburn 5157: $loginhash{login}{loginheader} = $env{'form.loginheader'};
1.6 raeburn 5158: if (ref($colchanges{'login'}) eq 'HASH') {
5159: $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
5160: \%loginhash);
5161: }
1.110 raeburn 5162:
1.149 raeburn 5163: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.128 raeburn 5164: my @loginvia_attribs = ('serverpath','custompath','exempt');
1.110 raeburn 5165: if (keys(%servers) > 1) {
5166: foreach my $lonhost (keys(%servers)) {
1.128 raeburn 5167: next if ($env{'form.'.$lonhost.'_server'} eq $lonhost);
5168: if (ref($curr_loginvia{$lonhost}) eq 'HASH') {
5169: if ($env{'form.'.$lonhost.'_server'} eq $curr_loginvia{$lonhost}{'server'}) {
5170: $loginhash{login}{loginvia}{$lonhost}{'server'} = $curr_loginvia{$lonhost}{'server'};
5171: } elsif ($curr_loginvia{$lonhost}{'server'} ne '') {
5172: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
5173: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
5174: $changes{'loginvia'}{$lonhost} = 1;
5175: } else {
5176: $loginhash{login}{loginvia}{$lonhost}{'server'} = '';
5177: $changes{'loginvia'}{$lonhost} = 1;
5178: }
5179: } else {
5180: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
5181: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
5182: $changes{'loginvia'}{$lonhost} = 1;
5183: }
5184: }
5185: if ($loginhash{login}{loginvia}{$lonhost}{'server'} eq '') {
5186: foreach my $item (@loginvia_attribs) {
5187: $loginhash{login}{loginvia}{$lonhost}{$item} = '';
5188: }
5189: } else {
5190: foreach my $item (@loginvia_attribs) {
5191: my $new = $env{'form.'.$lonhost.'_'.$item};
5192: if (($item eq 'serverpath') && ($new eq 'custom')) {
5193: $env{'form.'.$lonhost.'_custompath'} =~ s/\s+//g;
5194: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
5195: $new = '/';
5196: }
5197: }
5198: if (($item eq 'custompath') &&
5199: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
5200: $new = '';
5201: }
5202: if ($new ne $curr_loginvia{$lonhost}{$item}) {
5203: $changes{'loginvia'}{$lonhost} = 1;
5204: }
5205: if ($item eq 'exempt') {
5206: $new =~ s/^\s+//;
5207: $new =~ s/\s+$//;
5208: my @poss_ips = split(/\s*[,:]\s*/,$new);
5209: my @okips;
5210: foreach my $ip (@poss_ips) {
5211: if ($ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
5212: if (($1 <= 255) && ($2 <= 255) && ($3 <= 255) && ($4 <= 255)) {
5213: push(@okips,$ip);
5214: }
5215: }
5216: }
5217: if (@okips > 0) {
5218: $new = join(',',@okips);
5219: } else {
5220: $new = '';
5221: }
5222: }
5223: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
5224: }
5225: }
1.112 raeburn 5226: } else {
1.128 raeburn 5227: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
5228: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
1.112 raeburn 5229: $changes{'loginvia'}{$lonhost} = 1;
1.128 raeburn 5230: foreach my $item (@loginvia_attribs) {
5231: my $new = $env{'form.'.$lonhost.'_'.$item};
5232: if (($item eq 'serverpath') && ($new eq 'custom')) {
5233: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
5234: $new = '/';
5235: }
5236: }
5237: if (($item eq 'custompath') &&
5238: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
5239: $new = '';
5240: }
5241: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
5242: }
1.110 raeburn 5243: }
5244: }
5245: }
5246: }
1.119 raeburn 5247:
1.168 raeburn 5248: my $servadm = $r->dir_config('lonAdmEMail');
5249: my %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
5250: if (ref($domconfig{'login'}) eq 'HASH') {
5251: if (ref($domconfig{'login'}{'helpurl'}) eq 'HASH') {
5252: foreach my $lang (sort(keys(%{$domconfig{'login'}{'helpurl'}}))) {
5253: if ($lang eq 'nolang') {
5254: push(@currlangs,$lang);
5255: } elsif (defined($langchoices{$lang})) {
5256: push(@currlangs,$lang);
5257: } else {
5258: next;
5259: }
5260: }
5261: }
5262: }
5263: my @delurls = &Apache::loncommon::get_env_multiple('form.loginhelpurl_del');
5264: if (@currlangs > 0) {
5265: foreach my $lang (@currlangs) {
5266: if (grep(/^\Q$lang\E$/,@delurls)) {
5267: $changes{'helpurl'}{$lang} = 1;
5268: } elsif ($env{'form.loginhelpurl_'.$lang.'.filename'}) {
5269: $changes{'helpurl'}{$lang} = 1;
5270: $newfile{$lang} = $env{'form.loginhelpurl_'.$lang.'.filename'};
5271: push(@newlangs,$lang);
5272: } else {
5273: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
5274: }
5275: }
5276: }
5277: unless (grep(/^nolang$/,@currlangs)) {
5278: if ($env{'form.loginhelpurl_nolang.filename'}) {
5279: $changes{'helpurl'}{'nolang'} = 1;
5280: $newfile{'nolang'} = $env{'form.loginhelpurl_nolang.filename'};
5281: push(@newlangs,'nolang');
5282: }
5283: }
5284: if ($env{'form.loginhelpurl_add_lang'}) {
5285: if ((defined($langchoices{$env{'form.loginhelpurl_add_lang'}})) &&
5286: ($env{'form.loginhelpurl_add_file.filename'})) {
5287: $newfile{$env{'form.loginhelpurl_add_lang'}} = $env{'form.loginhelpurl_add_file.filename'};
5288: $addedfile = $env{'form.loginhelpurl_add_lang'};
5289: }
5290: }
5291: if ((@newlangs > 0) || ($addedfile)) {
5292: my $error;
5293: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
5294: if ($configuserok eq 'ok') {
5295: if ($switchserver) {
5296: $error = &mt("Upload of custom help file is not permitted to this server: [_1]",$switchserver);
5297: } elsif ($author_ok eq 'ok') {
5298: my @allnew = @newlangs;
5299: if ($addedfile ne '') {
5300: push(@allnew,$addedfile);
5301: }
5302: foreach my $lang (@allnew) {
5303: my $formelem = 'loginhelpurl_'.$lang;
5304: if ($lang eq $env{'form.loginhelpurl_add_lang'}) {
5305: $formelem = 'loginhelpurl_add_file';
5306: }
5307: (my $result,$newurl{$lang}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
5308: "help/$lang",'','',$newfile{$lang});
5309: if ($result eq 'ok') {
5310: $loginhash{'login'}{'helpurl'}{$lang} = $newurl{$lang};
5311: $changes{'helpurl'}{$lang} = 1;
5312: } else {
5313: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$newfile{$lang},$result);
5314: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
1.210 raeburn 5315: if ((grep(/^\Q$lang\E$/,@currlangs)) &&
1.168 raeburn 5316: (!grep(/^\Q$lang\E$/,@delurls))) {
5317:
5318: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
5319: }
5320: }
5321: }
5322: } else {
5323: $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);
5324: }
5325: } else {
5326: $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);
5327: }
5328: if ($error) {
5329: &Apache::lonnet::logthis($error);
5330: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
5331: }
5332: }
1.169 raeburn 5333: &process_captcha('login',\%changes,$loginhash{'login'},$domconfig{'login'});
1.168 raeburn 5334:
5335: my $defaulthelpfile = '/adm/loginproblems.html';
5336: my $defaulttext = &mt('Default in use');
5337:
1.1 raeburn 5338: my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
5339: $dom);
5340: if ($putresult eq 'ok') {
1.188 raeburn 5341: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 5342: my %defaultchecked = (
5343: 'coursecatalog' => 'on',
1.188 raeburn 5344: 'helpdesk' => 'on',
1.42 raeburn 5345: 'adminmail' => 'off',
1.43 raeburn 5346: 'newuser' => 'off',
1.42 raeburn 5347: );
1.55 raeburn 5348: if (ref($domconfig{'login'}) eq 'HASH') {
5349: foreach my $item (@toggles) {
5350: if ($defaultchecked{$item} eq 'on') {
5351: if (($domconfig{'login'}{$item} eq '0') &&
5352: ($env{'form.'.$item} eq '1')) {
5353: $changes{$item} = 1;
5354: } elsif (($domconfig{'login'}{$item} eq '' ||
5355: $domconfig{'login'}{$item} eq '1') &&
5356: ($env{'form.'.$item} eq '0')) {
5357: $changes{$item} = 1;
5358: }
5359: } elsif ($defaultchecked{$item} eq 'off') {
5360: if (($domconfig{'login'}{$item} eq '1') &&
5361: ($env{'form.'.$item} eq '0')) {
5362: $changes{$item} = 1;
5363: } elsif (($domconfig{'login'}{$item} eq '' ||
5364: $domconfig{'login'}{$item} eq '0') &&
5365: ($env{'form.'.$item} eq '1')) {
5366: $changes{$item} = 1;
5367: }
1.42 raeburn 5368: }
5369: }
1.41 raeburn 5370: }
1.6 raeburn 5371: if (keys(%changes) > 0 || $colchgtext) {
1.41 raeburn 5372: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 5373: if (ref($lastactref) eq 'HASH') {
5374: $lastactref->{'domainconfig'} = 1;
5375: }
1.1 raeburn 5376: $resulttext = &mt('Changes made:').'<ul>';
5377: foreach my $item (sort(keys(%changes))) {
1.135 bisitz 5378: if ($item eq 'loginvia') {
1.112 raeburn 5379: if (ref($changes{$item}) eq 'HASH') {
5380: $resulttext .= '<li>'.&mt('Log-in page availability:').'<ul>';
5381: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
1.128 raeburn 5382: if (defined($servers{$loginhash{login}{loginvia}{$lonhost}{'server'}})) {
5383: if (ref($loginhash{login}{loginvia}{$lonhost}) eq 'HASH') {
5384: my $protocol = $Apache::lonnet::protocol{$env{'form.'.$lonhost.'_server'}};
5385: $protocol = 'http' if ($protocol ne 'https');
5386: my $target = $protocol.'://'.$servers{$env{'form.'.$lonhost.'_server'}};
5387:
5388: if ($loginhash{login}{loginvia}{$lonhost}{'serverpath'} eq 'custom') {
5389: $target .= $loginhash{login}{loginvia}{$lonhost}{'custompath'};
5390: } else {
5391: $target .= $loginhash{login}{loginvia}{$lonhost}{'serverpath'};
5392: }
5393: $resulttext .= '<li>'.&mt('Server: [_1] log-in page redirects to [_2].',$servers{$lonhost},'<a href="'.$target.'">'.$target.'</a>');
5394: if ($loginhash{login}{loginvia}{$lonhost}{'exempt'} ne '') {
5395: $resulttext .= ' '.&mt('No redirection for clients from following IPs:').' '.$loginhash{login}{loginvia}{$lonhost}{'exempt'};
5396: }
5397: $resulttext .= '</li>';
5398: } else {
5399: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$lonhost).'</li>';
5400: }
1.112 raeburn 5401: } else {
1.128 raeburn 5402: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$servers{$lonhost}).'</li>';
1.112 raeburn 5403: }
5404: }
1.128 raeburn 5405: $resulttext .= '</ul></li>';
1.112 raeburn 5406: }
1.168 raeburn 5407: } elsif ($item eq 'helpurl') {
5408: if (ref($changes{$item}) eq 'HASH') {
5409: foreach my $lang (sort(keys(%{$changes{$item}}))) {
5410: if (grep(/^\Q$lang\E$/,@delurls)) {
5411: my ($chg,$link);
5412: $link = &Apache::loncommon::modal_link($defaulthelpfile,$defaulttext,600,500);
5413: if ($lang eq 'nolang') {
5414: $chg = &mt('custom log-in help file removed for no preferred language; [_1]',$link);
5415: } else {
5416: $chg = &mt('custom log-in help file removed for specific language: [_1]; [_2]',$langchoices{$lang},$link);
5417: }
5418: $resulttext .= '<li>'.$chg.'</li>';
5419: } else {
5420: my $chg;
5421: if ($lang eq 'nolang') {
5422: $chg = &mt('custom log-in help file for no preferred language');
5423: } else {
5424: $chg = &mt('custom log-in help file for specific language: [_1]',$langchoices{$lang});
5425: }
5426: $resulttext .= '<li>'.&Apache::loncommon::modal_link(
5427: $loginhash{'login'}{'helpurl'}{$lang}.
5428: '?inhibitmenu=yes',$chg,600,500).
5429: '</li>';
5430: }
5431: }
5432: }
1.169 raeburn 5433: } elsif ($item eq 'captcha') {
5434: if (ref($loginhash{'login'}) eq 'HASH') {
1.210 raeburn 5435: my $chgtxt;
1.169 raeburn 5436: if ($loginhash{'login'}{$item} eq 'notused') {
5437: $chgtxt .= &mt('No CAPTCHA validation in use for helpdesk form.');
5438: } else {
5439: my %captchas = &captcha_phrases();
5440: if ($captchas{$loginhash{'login'}{$item}}) {
5441: $chgtxt .= &mt("Validation for helpdesk form set to $captchas{$loginhash{'login'}{$item}}.");
5442: } else {
5443: $chgtxt .= &mt('Validation for helpdesk form set to unknown type.');
5444: }
5445: }
5446: $resulttext .= '<li>'.$chgtxt.'</li>';
5447: }
5448: } elsif ($item eq 'recaptchakeys') {
5449: if (ref($loginhash{'login'}) eq 'HASH') {
5450: my ($privkey,$pubkey);
5451: if (ref($loginhash{'login'}{$item}) eq 'HASH') {
5452: $pubkey = $loginhash{'login'}{$item}{'public'};
5453: $privkey = $loginhash{'login'}{$item}{'private'};
5454: }
5455: my $chgtxt .= &mt('ReCAPTCHA keys changes').'<ul>';
5456: if (!$pubkey) {
5457: $chgtxt .= '<li>'.&mt('Public key deleted').'</li>';
5458: } else {
5459: $chgtxt .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
5460: }
5461: if (!$privkey) {
5462: $chgtxt .= '<li>'.&mt('Private key deleted').'</li>';
5463: } else {
5464: $chgtxt .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
5465: }
5466: $chgtxt .= '</ul>';
5467: $resulttext .= '<li>'.$chgtxt.'</li>';
5468: }
1.41 raeburn 5469: } else {
5470: $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
5471: }
1.1 raeburn 5472: }
1.6 raeburn 5473: $resulttext .= $colchgtext.'</ul>';
1.1 raeburn 5474: } else {
5475: $resulttext = &mt('No changes made to log-in page settings');
5476: }
5477: } else {
1.11 albertel 5478: $resulttext = '<span class="LC_error">'.
5479: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 5480: }
1.6 raeburn 5481: if ($errors) {
1.9 raeburn 5482: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.6 raeburn 5483: $errors.'</ul>';
5484: }
5485: return $resulttext;
5486: }
5487:
5488: sub color_font_choices {
5489: my %choices =
5490: &Apache::lonlocal::texthash (
5491: img => "Header",
5492: bgs => "Background colors",
5493: links => "Link colors",
1.55 raeburn 5494: images => "Images",
1.6 raeburn 5495: font => "Font color",
1.201 raeburn 5496: fontmenu => "Font menu",
1.76 raeburn 5497: pgbg => "Page",
1.6 raeburn 5498: tabbg => "Header",
5499: sidebg => "Border",
5500: link => "Link",
5501: alink => "Active link",
5502: vlink => "Visited link",
5503: );
5504: return %choices;
5505: }
5506:
5507: sub modify_rolecolors {
1.205 raeburn 5508: my ($r,$dom,$confname,$roles,$lastactref,%domconfig) = @_;
1.6 raeburn 5509: my ($resulttext,%rolehash);
5510: $rolehash{'rolecolors'} = {};
1.55 raeburn 5511: if (ref($domconfig{'rolecolors'}) ne 'HASH') {
5512: if ($domconfig{'rolecolors'} eq '') {
5513: $domconfig{'rolecolors'} = {};
5514: }
5515: }
1.9 raeburn 5516: my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
1.6 raeburn 5517: $domconfig{'rolecolors'},$rolehash{'rolecolors'});
5518: my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
5519: $dom);
5520: if ($putresult eq 'ok') {
5521: if (keys(%changes) > 0) {
1.41 raeburn 5522: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 5523: if (ref($lastactref) eq 'HASH') {
5524: $lastactref->{'domainconfig'} = 1;
5525: }
1.6 raeburn 5526: $resulttext = &display_colorchgs($dom,\%changes,$roles,
5527: $rolehash{'rolecolors'});
5528: } else {
5529: $resulttext = &mt('No changes made to default color schemes');
5530: }
5531: } else {
1.11 albertel 5532: $resulttext = '<span class="LC_error">'.
5533: &mt('An error occurred: [_1]',$putresult).'</span>';
1.6 raeburn 5534: }
5535: if ($errors) {
5536: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
5537: $errors.'</ul>';
5538: }
5539: return $resulttext;
5540: }
5541:
5542: sub modify_colors {
1.9 raeburn 5543: my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
1.12 raeburn 5544: my (%changes,%choices);
1.51 raeburn 5545: my @bgs;
1.6 raeburn 5546: my @links = ('link','alink','vlink');
1.41 raeburn 5547: my @logintext;
1.6 raeburn 5548: my @images;
5549: my $servadm = $r->dir_config('lonAdmEMail');
5550: my $errors;
1.200 raeburn 5551: my %defaults;
1.6 raeburn 5552: foreach my $role (@{$roles}) {
5553: if ($role eq 'login') {
1.12 raeburn 5554: %choices = &login_choices();
1.41 raeburn 5555: @logintext = ('textcol','bgcol');
1.12 raeburn 5556: } else {
5557: %choices = &color_font_choices();
5558: }
5559: if ($role eq 'login') {
1.41 raeburn 5560: @images = ('img','logo','domlogo','login');
1.51 raeburn 5561: @bgs = ('pgbg','mainbg','sidebg');
1.6 raeburn 5562: } else {
5563: @images = ('img');
1.200 raeburn 5564: @bgs = ('pgbg','tabbg','sidebg');
5565: }
5566: my %defaults = &role_defaults($role,\@bgs,\@links,\@images,\@logintext);
5567: unless ($env{'form.'.$role.'_font'} eq $defaults{'font'}) {
5568: $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
5569: }
5570: if ($role eq 'login') {
5571: foreach my $item (@logintext) {
5572: unless ($env{'form.'.$role.'_'.$item} eq $defaults{'logintext'}{$item}) {
5573: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
5574: }
5575: }
5576: } else {
5577: unless($env{'form.'.$role.'_fontmenu'} eq $defaults{'fontmenu'}) {
5578: $confhash->{$role}{'fontmenu'} = $env{'form.'.$role.'_fontmenu'};
5579: }
1.6 raeburn 5580: }
1.200 raeburn 5581: foreach my $item (@bgs) {
5582: unless ($env{'form.'.$role.'_'.$item} eq $defaults{'bgs'}{$item} ) {
5583: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
5584: }
5585: }
5586: foreach my $item (@links) {
5587: unless ($env{'form.'.$role.'_'.$item} eq $defaults{'links'}{$item}) {
5588: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
5589: }
1.6 raeburn 5590: }
1.46 raeburn 5591: my ($configuserok,$author_ok,$switchserver) =
5592: &config_check($dom,$confname,$servadm);
1.9 raeburn 5593: my ($width,$height) = &thumb_dimensions();
1.40 raeburn 5594: if (ref($domconfig->{$role}) ne 'HASH') {
5595: $domconfig->{$role} = {};
5596: }
1.8 raeburn 5597: foreach my $img (@images) {
1.70 raeburn 5598: if (($role eq 'login') && (($img eq 'img') || ($img eq 'logo'))) {
5599: if (defined($env{'form.login_showlogo_'.$img})) {
5600: $confhash->{$role}{'showlogo'}{$img} = 1;
5601: } else {
5602: $confhash->{$role}{'showlogo'}{$img} = 0;
5603: }
5604: }
1.18 albertel 5605: if ( ! $env{'form.'.$role.'_'.$img.'.filename'}
5606: && !defined($domconfig->{$role}{$img})
5607: && !$env{'form.'.$role.'_del_'.$img}
5608: && $env{'form.'.$role.'_import_'.$img}) {
5609: # import the old configured image from the .tab setting
5610: # if they haven't provided a new one
5611: $domconfig->{$role}{$img} =
5612: $env{'form.'.$role.'_import_'.$img};
5613: }
1.6 raeburn 5614: if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
1.9 raeburn 5615: my $error;
1.6 raeburn 5616: if ($configuserok eq 'ok') {
1.9 raeburn 5617: if ($switchserver) {
1.12 raeburn 5618: $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
1.9 raeburn 5619: } else {
5620: if ($author_ok eq 'ok') {
5621: my ($result,$logourl) =
5622: &publishlogo($r,'upload',$role.'_'.$img,
5623: $dom,$confname,$img,$width,$height);
5624: if ($result eq 'ok') {
5625: $confhash->{$role}{$img} = $logourl;
1.12 raeburn 5626: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 5627: } else {
1.12 raeburn 5628: $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 5629: }
5630: } else {
1.46 raeburn 5631: $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 5632: }
5633: }
5634: } else {
1.46 raeburn 5635: $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 5636: }
5637: if ($error) {
1.8 raeburn 5638: &Apache::lonnet::logthis($error);
1.11 albertel 5639: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
1.8 raeburn 5640: }
5641: } elsif ($domconfig->{$role}{$img} ne '') {
1.9 raeburn 5642: if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
5643: my $error;
5644: if ($configuserok eq 'ok') {
5645: # is confname an author?
5646: if ($switchserver eq '') {
5647: if ($author_ok eq 'ok') {
5648: my ($result,$logourl) =
5649: &publishlogo($r,'copy',$domconfig->{$role}{$img},
5650: $dom,$confname,$img,$width,$height);
5651: if ($result eq 'ok') {
5652: $confhash->{$role}{$img} = $logourl;
1.18 albertel 5653: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 5654: }
5655: }
5656: }
5657: }
1.6 raeburn 5658: }
5659: }
5660: }
5661: if (ref($domconfig) eq 'HASH') {
5662: if (ref($domconfig->{$role}) eq 'HASH') {
5663: foreach my $img (@images) {
5664: if ($domconfig->{$role}{$img} ne '') {
5665: if ($env{'form.'.$role.'_del_'.$img}) {
5666: $confhash->{$role}{$img} = '';
1.12 raeburn 5667: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 5668: } else {
1.9 raeburn 5669: if ($confhash->{$role}{$img} eq '') {
5670: $confhash->{$role}{$img} = $domconfig->{$role}{$img};
5671: }
1.6 raeburn 5672: }
5673: } else {
5674: if ($env{'form.'.$role.'_del_'.$img}) {
5675: $confhash->{$role}{$img} = '';
1.12 raeburn 5676: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 5677: }
5678: }
1.70 raeburn 5679: if (($role eq 'login') && (($img eq 'logo') || ($img eq 'img'))) {
5680: if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') {
5681: if ($confhash->{$role}{'showlogo'}{$img} ne
5682: $domconfig->{$role}{'showlogo'}{$img}) {
5683: $changes{$role}{'showlogo'}{$img} = 1;
5684: }
5685: } else {
5686: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
5687: $changes{$role}{'showlogo'}{$img} = 1;
5688: }
5689: }
5690: }
5691: }
1.6 raeburn 5692: if ($domconfig->{$role}{'font'} ne '') {
5693: if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
5694: $changes{$role}{'font'} = 1;
5695: }
5696: } else {
5697: if ($confhash->{$role}{'font'}) {
5698: $changes{$role}{'font'} = 1;
5699: }
5700: }
1.107 raeburn 5701: if ($role ne 'login') {
5702: if ($domconfig->{$role}{'fontmenu'} ne '') {
5703: if ($confhash->{$role}{'fontmenu'} ne $domconfig->{$role}{'fontmenu'}) {
5704: $changes{$role}{'fontmenu'} = 1;
5705: }
5706: } else {
5707: if ($confhash->{$role}{'fontmenu'}) {
5708: $changes{$role}{'fontmenu'} = 1;
5709: }
1.97 tempelho 5710: }
5711: }
1.6 raeburn 5712: foreach my $item (@bgs) {
5713: if ($domconfig->{$role}{$item} ne '') {
5714: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
5715: $changes{$role}{'bgs'}{$item} = 1;
5716: }
5717: } else {
5718: if ($confhash->{$role}{$item}) {
5719: $changes{$role}{'bgs'}{$item} = 1;
5720: }
5721: }
5722: }
5723: foreach my $item (@links) {
5724: if ($domconfig->{$role}{$item} ne '') {
5725: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
5726: $changes{$role}{'links'}{$item} = 1;
5727: }
5728: } else {
5729: if ($confhash->{$role}{$item}) {
5730: $changes{$role}{'links'}{$item} = 1;
5731: }
5732: }
5733: }
1.41 raeburn 5734: foreach my $item (@logintext) {
5735: if ($domconfig->{$role}{$item} ne '') {
5736: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
5737: $changes{$role}{'logintext'}{$item} = 1;
5738: }
5739: } else {
5740: if ($confhash->{$role}{$item}) {
5741: $changes{$role}{'logintext'}{$item} = 1;
5742: }
5743: }
5744: }
1.6 raeburn 5745: } else {
5746: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 5747: \@logintext,$confhash,\%changes);
1.6 raeburn 5748: }
5749: } else {
5750: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 5751: \@logintext,$confhash,\%changes);
1.6 raeburn 5752: }
5753: }
5754: return ($errors,%changes);
5755: }
5756:
1.46 raeburn 5757: sub config_check {
5758: my ($dom,$confname,$servadm) = @_;
5759: my ($configuserok,$author_ok,$switchserver,%currroles);
5760: my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
5761: ($configuserok,%currroles) = &check_configuser($uhome,$dom,
5762: $confname,$servadm);
5763: if ($configuserok eq 'ok') {
5764: $switchserver = &check_switchserver($dom,$confname);
5765: if ($switchserver eq '') {
5766: $author_ok = &check_authorstatus($dom,$confname,%currroles);
5767: }
5768: }
5769: return ($configuserok,$author_ok,$switchserver);
5770: }
5771:
1.6 raeburn 5772: sub default_change_checker {
1.41 raeburn 5773: my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
1.6 raeburn 5774: foreach my $item (@{$links}) {
5775: if ($confhash->{$role}{$item}) {
5776: $changes->{$role}{'links'}{$item} = 1;
5777: }
5778: }
5779: foreach my $item (@{$bgs}) {
5780: if ($confhash->{$role}{$item}) {
5781: $changes->{$role}{'bgs'}{$item} = 1;
5782: }
5783: }
1.41 raeburn 5784: foreach my $item (@{$logintext}) {
5785: if ($confhash->{$role}{$item}) {
5786: $changes->{$role}{'logintext'}{$item} = 1;
5787: }
5788: }
1.6 raeburn 5789: foreach my $img (@{$images}) {
5790: if ($env{'form.'.$role.'_del_'.$img}) {
5791: $confhash->{$role}{$img} = '';
1.12 raeburn 5792: $changes->{$role}{'images'}{$img} = 1;
1.6 raeburn 5793: }
1.70 raeburn 5794: if ($role eq 'login') {
5795: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
5796: $changes->{$role}{'showlogo'}{$img} = 1;
5797: }
5798: }
1.6 raeburn 5799: }
5800: if ($confhash->{$role}{'font'}) {
5801: $changes->{$role}{'font'} = 1;
5802: }
1.48 raeburn 5803: }
1.6 raeburn 5804:
5805: sub display_colorchgs {
5806: my ($dom,$changes,$roles,$confhash) = @_;
5807: my (%choices,$resulttext);
5808: if (!grep(/^login$/,@{$roles})) {
5809: $resulttext = &mt('Changes made:').'<br />';
5810: }
5811: foreach my $role (@{$roles}) {
5812: if ($role eq 'login') {
5813: %choices = &login_choices();
5814: } else {
5815: %choices = &color_font_choices();
5816: }
5817: if (ref($changes->{$role}) eq 'HASH') {
5818: if ($role ne 'login') {
5819: $resulttext .= '<h4>'.&mt($role).'</h4>';
5820: }
5821: foreach my $key (sort(keys(%{$changes->{$role}}))) {
5822: if ($role ne 'login') {
5823: $resulttext .= '<ul>';
5824: }
5825: if (ref($changes->{$role}{$key}) eq 'HASH') {
5826: if ($role ne 'login') {
5827: $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
5828: }
5829: foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
1.70 raeburn 5830: if (($role eq 'login') && ($key eq 'showlogo')) {
5831: if ($confhash->{$role}{$key}{$item}) {
5832: $resulttext .= '<li>'.&mt("$choices{$item} set to be displayed").'</li>';
5833: } else {
5834: $resulttext .= '<li>'.&mt("$choices{$item} set to not be displayed").'</li>';
5835: }
5836: } elsif ($confhash->{$role}{$item} eq '') {
1.6 raeburn 5837: $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
5838: } else {
1.12 raeburn 5839: my $newitem = $confhash->{$role}{$item};
5840: if ($key eq 'images') {
5841: $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" valign="bottom" />';
5842: }
5843: $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
1.6 raeburn 5844: }
5845: }
5846: if ($role ne 'login') {
5847: $resulttext .= '</ul></li>';
5848: }
5849: } else {
5850: if ($confhash->{$role}{$key} eq '') {
5851: $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
5852: } else {
5853: $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
5854: }
5855: }
5856: if ($role ne 'login') {
5857: $resulttext .= '</ul>';
5858: }
5859: }
5860: }
5861: }
1.3 raeburn 5862: return $resulttext;
1.1 raeburn 5863: }
5864:
1.9 raeburn 5865: sub thumb_dimensions {
5866: return ('200','50');
5867: }
5868:
1.16 raeburn 5869: sub check_dimensions {
5870: my ($inputfile) = @_;
5871: my ($fullwidth,$fullheight);
5872: if ($inputfile =~ m|^[/\w.\-]+$|) {
5873: if (open(PIPE,"identify $inputfile 2>&1 |")) {
5874: my $imageinfo = <PIPE>;
5875: if (!close(PIPE)) {
5876: &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
5877: }
5878: chomp($imageinfo);
5879: my ($fullsize) =
1.21 raeburn 5880: ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
1.16 raeburn 5881: if ($fullsize) {
5882: ($fullwidth,$fullheight) = split(/x/,$fullsize);
5883: }
5884: }
5885: }
5886: return ($fullwidth,$fullheight);
5887: }
5888:
1.9 raeburn 5889: sub check_configuser {
5890: my ($uhome,$dom,$confname,$servadm) = @_;
5891: my ($configuserok,%currroles);
5892: if ($uhome eq 'no_host') {
5893: srand( time() ^ ($$ + ($$ << 15)) ); # Seed rand.
5894: my $configpass = &LONCAPA::Enrollment::create_password();
5895: $configuserok =
5896: &Apache::lonnet::modifyuser($dom,$confname,'','internal',
5897: $configpass,'','','','','',undef,$servadm);
5898: } else {
5899: $configuserok = 'ok';
5900: %currroles =
5901: &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
5902: }
5903: return ($configuserok,%currroles);
5904: }
5905:
5906: sub check_authorstatus {
5907: my ($dom,$confname,%currroles) = @_;
5908: my $author_ok;
1.40 raeburn 5909: if (!$currroles{':'.$dom.':au'}) {
1.9 raeburn 5910: my $start = time;
5911: my $end = 0;
5912: $author_ok =
5913: &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
1.47 raeburn 5914: 'au',$end,$start,'','','domconfig');
1.9 raeburn 5915: } else {
5916: $author_ok = 'ok';
5917: }
5918: return $author_ok;
5919: }
5920:
5921: sub publishlogo {
1.46 raeburn 5922: my ($r,$action,$formname,$dom,$confname,$subdir,$thumbwidth,$thumbheight,$savefileas) = @_;
1.9 raeburn 5923: my ($output,$fname,$logourl);
5924: if ($action eq 'upload') {
5925: $fname=$env{'form.'.$formname.'.filename'};
5926: chop($env{'form.'.$formname});
5927: } else {
5928: ($fname) = ($formname =~ /([^\/]+)$/);
5929: }
1.46 raeburn 5930: if ($savefileas ne '') {
5931: $fname = $savefileas;
5932: }
1.9 raeburn 5933: $fname=&Apache::lonnet::clean_filename($fname);
5934: # See if there is anything left
5935: unless ($fname) { return ('error: no uploaded file'); }
5936: $fname="$subdir/$fname";
1.210 raeburn 5937: my $docroot=$r->dir_config('lonDocRoot');
1.164 raeburn 5938: my $filepath="$docroot/priv";
5939: my $relpath = "$dom/$confname";
1.9 raeburn 5940: my ($fnamepath,$file,$fetchthumb);
5941: $file=$fname;
5942: if ($fname=~m|/|) {
5943: ($fnamepath,$file) = ($fname =~ m|^(.*)/([^/]+)$|);
5944: }
1.164 raeburn 5945: my @parts=split(/\//,"$filepath/$relpath/$fnamepath");
1.9 raeburn 5946: my $count;
1.164 raeburn 5947: for ($count=5;$count<=$#parts;$count++) {
1.9 raeburn 5948: $filepath.="/$parts[$count]";
5949: if ((-e $filepath)!=1) {
5950: mkdir($filepath,02770);
5951: }
5952: }
5953: # Check for bad extension and disallow upload
5954: if ($file=~/\.(\w+)$/ &&
5955: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
5956: $output =
1.207 bisitz 5957: &mt('Invalid file extension ([_1]) - reserved for internal use.',$1);
1.9 raeburn 5958: } elsif ($file=~/\.(\w+)$/ &&
5959: !defined(&Apache::loncommon::fileembstyle($1))) {
5960: $output = &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
5961: } elsif ($file=~/\.(\d+)\.(\w+)$/) {
1.195 bisitz 5962: $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 5963: } elsif (-d "$filepath/$file") {
1.195 bisitz 5964: $output = &mt('Filename is a directory name - rename the file and re-upload');
1.9 raeburn 5965: } else {
5966: my $source = $filepath.'/'.$file;
5967: my $logfile;
5968: if (!open($logfile,">>$source".'.log')) {
1.196 raeburn 5969: return (&mt('No write permission to Authoring Space'));
1.9 raeburn 5970: }
5971: print $logfile
5972: "\n================= Publish ".localtime()." ================\n".
5973: $env{'user.name'}.':'.$env{'user.domain'}."\n";
5974: # Save the file
5975: if (!open(FH,'>'.$source)) {
5976: &Apache::lonnet::logthis('Failed to create '.$source);
5977: return (&mt('Failed to create file'));
5978: }
5979: if ($action eq 'upload') {
5980: if (!print FH ($env{'form.'.$formname})) {
5981: &Apache::lonnet::logthis('Failed to write to '.$source);
5982: return (&mt('Failed to write file'));
5983: }
5984: } else {
5985: my $original = &Apache::lonnet::filelocation('',$formname);
5986: if(!copy($original,$source)) {
5987: &Apache::lonnet::logthis('Failed to copy '.$original.' to '.$source);
5988: return (&mt('Failed to write file'));
5989: }
5990: }
5991: close(FH);
5992: chmod(0660, $source); # Permissions to rw-rw---.
5993:
5994: my $targetdir=$docroot.'/res/'.$dom.'/'.$confname .'/'.$fnamepath;
5995: my $copyfile=$targetdir.'/'.$file;
5996:
5997: my @parts=split(/\//,$targetdir);
5998: my $path="/$parts[1]/$parts[2]/$parts[3]/$parts[4]";
5999: for (my $count=5;$count<=$#parts;$count++) {
6000: $path.="/$parts[$count]";
6001: if (!-e $path) {
6002: print $logfile "\nCreating directory ".$path;
6003: mkdir($path,02770);
6004: }
6005: }
6006: my $versionresult;
6007: if (-e $copyfile) {
6008: $versionresult = &logo_versioning($targetdir,$file,$logfile);
6009: } else {
6010: $versionresult = 'ok';
6011: }
6012: if ($versionresult eq 'ok') {
6013: if (copy($source,$copyfile)) {
6014: print $logfile "\nCopied original source to ".$copyfile."\n";
6015: $output = 'ok';
6016: $logourl = '/res/'.$dom.'/'.$confname.'/'.$fname;
1.155 raeburn 6017: push(@{$modified_urls},[$copyfile,$source]);
6018: my $metaoutput =
6019: &write_metadata($dom,$confname,$formname,$targetdir,$file,$logfile);
6020: unless ($registered_cleanup) {
6021: my $handlers = $r->get_handlers('PerlCleanupHandler');
6022: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
6023: $registered_cleanup=1;
6024: }
1.9 raeburn 6025: } else {
6026: print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";
6027: $output = &mt('Failed to copy file to RES space').", $!";
6028: }
6029: if (($thumbwidth =~ /^\d+$/) && ($thumbheight =~ /^\d+$/)) {
6030: my $inputfile = $filepath.'/'.$file;
6031: my $outfile = $filepath.'/'.'tn-'.$file;
1.16 raeburn 6032: my ($fullwidth,$fullheight) = &check_dimensions($inputfile);
6033: if ($fullwidth ne '' && $fullheight ne '') {
6034: if ($fullwidth > $thumbwidth && $fullheight > $thumbheight) {
6035: my $thumbsize = $thumbwidth.'x'.$thumbheight;
6036: system("convert -sample $thumbsize $inputfile $outfile");
6037: chmod(0660, $filepath.'/tn-'.$file);
6038: if (-e $outfile) {
6039: my $copyfile=$targetdir.'/tn-'.$file;
6040: if (copy($outfile,$copyfile)) {
6041: print $logfile "\nCopied source to ".$copyfile."\n";
1.155 raeburn 6042: my $thumb_metaoutput =
6043: &write_metadata($dom,$confname,$formname,
6044: $targetdir,'tn-'.$file,$logfile);
6045: push(@{$modified_urls},[$copyfile,$outfile]);
6046: unless ($registered_cleanup) {
6047: my $handlers = $r->get_handlers('PerlCleanupHandler');
6048: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
6049: $registered_cleanup=1;
6050: }
1.16 raeburn 6051: } else {
6052: print $logfile "\nUnable to write ".$copyfile.
6053: ':'.$!."\n";
6054: }
6055: }
1.9 raeburn 6056: }
6057: }
6058: }
6059: } else {
6060: $output = $versionresult;
6061: }
6062: }
6063: return ($output,$logourl);
6064: }
6065:
6066: sub logo_versioning {
6067: my ($targetdir,$file,$logfile) = @_;
6068: my $target = $targetdir.'/'.$file;
6069: my ($maxversion,$fn,$extn,$output);
6070: $maxversion = 0;
6071: if ($file =~ /^(.+)\.(\w+)$/) {
6072: $fn=$1;
6073: $extn=$2;
6074: }
6075: opendir(DIR,$targetdir);
6076: while (my $filename=readdir(DIR)) {
6077: if ($filename=~/\Q$fn\E\.(\d+)\.\Q$extn\E$/) {
6078: $maxversion=($1>$maxversion)?$1:$maxversion;
6079: }
6080: }
6081: $maxversion++;
6082: print $logfile "\nCreating old version ".$maxversion."\n";
6083: my $copyfile=$targetdir.'/'.$fn.'.'.$maxversion.'.'.$extn;
6084: if (copy($target,$copyfile)) {
6085: print $logfile "Copied old target to ".$copyfile."\n";
6086: $copyfile=$copyfile.'.meta';
6087: if (copy($target.'.meta',$copyfile)) {
6088: print $logfile "Copied old target metadata to ".$copyfile."\n";
6089: $output = 'ok';
6090: } else {
6091: print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";
6092: $output = &mt('Failed to copy old meta').", $!, ";
6093: }
6094: } else {
6095: print $logfile "Unable to write ".$copyfile.':'.$!."\n";
6096: $output = &mt('Failed to copy old target').", $!, ";
6097: }
6098: return $output;
6099: }
6100:
6101: sub write_metadata {
6102: my ($dom,$confname,$formname,$targetdir,$file,$logfile) = @_;
6103: my (%metadatafields,%metadatakeys,$output);
6104: $metadatafields{'title'}=$formname;
6105: $metadatafields{'creationdate'}=time;
6106: $metadatafields{'lastrevisiondate'}=time;
6107: $metadatafields{'copyright'}='public';
6108: $metadatafields{'modifyinguser'}=$env{'user.name'}.':'.
6109: $env{'user.domain'};
6110: $metadatafields{'authorspace'}=$confname.':'.$dom;
6111: $metadatafields{'domain'}=$dom;
6112: {
6113: print $logfile "\nWrite metadata file for ".$targetdir.'/'.$file;
6114: my $mfh;
1.155 raeburn 6115: if (open($mfh,'>'.$targetdir.'/'.$file.'.meta')) {
1.184 raeburn 6116: foreach (sort(keys(%metadatafields))) {
1.155 raeburn 6117: unless ($_=~/\./) {
6118: my $unikey=$_;
6119: $unikey=~/^([A-Za-z]+)/;
6120: my $tag=$1;
6121: $tag=~tr/A-Z/a-z/;
6122: print $mfh "\n\<$tag";
6123: foreach (split(/\,/,$metadatakeys{$unikey})) {
6124: my $value=$metadatafields{$unikey.'.'.$_};
6125: $value=~s/\"/\'\'/g;
6126: print $mfh ' '.$_.'="'.$value.'"';
6127: }
6128: print $mfh '>'.
6129: &HTML::Entities::encode($metadatafields{$unikey},'<>&"')
6130: .'</'.$tag.'>';
6131: }
6132: }
6133: $output = 'ok';
6134: print $logfile "\nWrote metadata";
6135: close($mfh);
6136: } else {
6137: print $logfile "\nFailed to open metadata file";
1.9 raeburn 6138: $output = &mt('Could not write metadata');
6139: }
6140: }
1.155 raeburn 6141: return $output;
6142: }
6143:
6144: sub notifysubscribed {
6145: foreach my $targetsource (@{$modified_urls}){
6146: next unless (ref($targetsource) eq 'ARRAY');
6147: my ($target,$source)=@{$targetsource};
6148: if ($source ne '') {
6149: if (open(my $logfh,'>>'.$source.'.log')) {
6150: print $logfh "\nCleanup phase: Notifications\n";
6151: my @subscribed=&subscribed_hosts($target);
6152: foreach my $subhost (@subscribed) {
6153: print $logfh "\nNotifying host ".$subhost.':';
6154: my $reply=&Apache::lonnet::critical('update:'.$target,$subhost);
6155: print $logfh $reply;
6156: }
6157: my @subscribedmeta=&subscribed_hosts("$target.meta");
6158: foreach my $subhost (@subscribedmeta) {
6159: print $logfh "\nNotifying host for metadata only ".$subhost.':';
6160: my $reply=&Apache::lonnet::critical('update:'.$target.'.meta',
6161: $subhost);
6162: print $logfh $reply;
6163: }
6164: print $logfh "\n============ Done ============\n";
1.160 raeburn 6165: close($logfh);
1.155 raeburn 6166: }
6167: }
6168: }
6169: return OK;
6170: }
6171:
6172: sub subscribed_hosts {
6173: my ($target) = @_;
6174: my @subscribed;
6175: if (open(my $fh,"<$target.subscription")) {
6176: while (my $subline=<$fh>) {
6177: if ($subline =~ /^($match_lonid):/) {
6178: my $host = $1;
6179: if ($host ne $Apache::lonnet::perlvar{'lonHostID'}) {
6180: unless (grep(/^\Q$host\E$/,@subscribed)) {
6181: push(@subscribed,$host);
6182: }
6183: }
6184: }
6185: }
6186: }
6187: return @subscribed;
1.9 raeburn 6188: }
6189:
6190: sub check_switchserver {
6191: my ($dom,$confname) = @_;
6192: my ($allowed,$switchserver);
6193: my $home = &Apache::lonnet::homeserver($confname,$dom);
6194: if ($home eq 'no_host') {
6195: $home = &Apache::lonnet::domain($dom,'primary');
6196: }
6197: my @ids=&Apache::lonnet::current_machine_ids();
1.10 albertel 6198: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
6199: if (!$allowed) {
1.180 raeburn 6200: $switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role=dc./'.$dom.'/&destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
1.9 raeburn 6201: }
6202: return $switchserver;
6203: }
6204:
1.1 raeburn 6205: sub modify_quotas {
1.216 raeburn 6206: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
1.101 raeburn 6207: my ($context,@usertools,@options,%validations,%titles,%confhash,%toolshash,
1.216 raeburn 6208: %limithash,$toolregexp,%conditions,$resulttext,%changes,$confname,$configuserok,
6209: $author_ok,$switchserver,$errors);
1.86 raeburn 6210: if ($action eq 'quotas') {
6211: $context = 'tools';
1.163 raeburn 6212: } else {
1.86 raeburn 6213: $context = $action;
6214: }
6215: if ($context eq 'requestcourses') {
1.216 raeburn 6216: @usertools = ('official','unofficial','community','textbook');
1.106 raeburn 6217: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 6218: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
6219: %titles = &courserequest_titles();
6220: $toolregexp = join('|',@usertools);
6221: %conditions = &courserequest_conditions();
1.216 raeburn 6222: $confname = $dom.'-domainconfig';
6223: my $servadm = $r->dir_config('lonAdmEMail');
6224: ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
1.163 raeburn 6225: } elsif ($context eq 'requestauthor') {
6226: @usertools = ('author');
6227: %titles = &authorrequest_titles();
1.86 raeburn 6228: } else {
1.162 raeburn 6229: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 6230: %titles = &tool_titles();
1.86 raeburn 6231: }
1.212 raeburn 6232: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.44 raeburn 6233: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 6234: foreach my $key (keys(%env)) {
1.101 raeburn 6235: if ($context eq 'requestcourses') {
6236: if ($key =~ /^form\.crsreq_($toolregexp)_(.+)$/) {
6237: my $item = $1;
6238: my $type = $2;
6239: if ($type =~ /^limit_(.+)/) {
6240: $limithash{$item}{$1} = $env{$key};
6241: } else {
6242: $confhash{$item}{$type} = $env{$key};
6243: }
6244: }
1.163 raeburn 6245: } elsif ($context eq 'requestauthor') {
6246: if ($key =~ /^\Qform.authorreq_\E(.+)$/) {
6247: $confhash{$1} = $env{$key};
6248: }
1.101 raeburn 6249: } else {
1.86 raeburn 6250: if ($key =~ /^form\.quota_(.+)$/) {
6251: $confhash{'defaultquota'}{$1} = $env{$key};
1.197 raeburn 6252: } elsif ($key =~ /^form\.authorquota_(.+)$/) {
6253: $confhash{'authorquota'}{$1} = $env{$key};
6254: } elsif ($key =~ /^form\.\Q$context\E_(.+)$/) {
1.101 raeburn 6255: @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key);
6256: }
1.72 raeburn 6257: }
6258: }
1.163 raeburn 6259: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.224 raeburn 6260: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.'.$context.'notifyapproval');
1.102 raeburn 6261: @approvalnotify = sort(@approvalnotify);
6262: $confhash{'notify'}{'approval'} = join(',',@approvalnotify);
1.218 raeburn 6263: my @crstypes = ('official','unofficial','community','textbook');
6264: my @hasuniquecode = &Apache::loncommon::get_env_multiple('form.uniquecode');
6265: foreach my $type (@hasuniquecode) {
6266: if (grep(/^\Q$type\E$/,@crstypes)) {
6267: $confhash{'uniquecode'}{$type} = 1;
6268: }
1.216 raeburn 6269: }
6270: my ($newbook,@allpos);
6271: if ($context eq 'requestcourses') {
6272: if ($env{'form.addbook'}) {
6273: if (($env{'form.addbook_cnum'} =~ /^$match_courseid$/) &&
6274: ($env{'form.addbook_cdom'} =~ /^$match_domain$/)) {
6275: if (&Apache::lonnet::homeserver($env{'form.addbook_cnum'},
6276: $env{'form.addbook_cdom'}) eq 'no_host') {
6277: $errors .= '<li><span class="LC_error">'.&mt('Invalid LON-CAPA course for textbook').
6278: '</span></li>';
6279: } else {
6280: $newbook = $env{'form.addbook_cdom'}.'_'.$env{'form.addbook_cnum'};
6281: my $position = $env{'form.addbook_pos'};
6282: $position =~ s/\D+//g;
6283: if ($position ne '') {
6284: $allpos[$position] = $newbook;
6285: }
6286: }
6287: } else {
6288: $errors .= '<li><span class="LC_error">'.&mt('Invalid LON-CAPA course for textbook').
6289: '</span></li>';
6290: }
6291: }
6292: }
1.102 raeburn 6293: if (ref($domconfig{$action}) eq 'HASH') {
6294: if (ref($domconfig{$action}{'notify'}) eq 'HASH') {
6295: if ($domconfig{$action}{'notify'}{'approval'} ne $confhash{'notify'}{'approval'}) {
6296: $changes{'notify'}{'approval'} = 1;
6297: }
6298: } else {
1.144 raeburn 6299: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 6300: $changes{'notify'}{'approval'} = 1;
6301: }
6302: }
1.218 raeburn 6303: if (ref($domconfig{$action}{'uniquecode'}) eq 'HASH') {
6304: if (ref($confhash{'uniquecode'}) eq 'HASH') {
6305: foreach my $crstype (keys(%{$domconfig{$action}{'uniquecode'}})) {
6306: unless ($confhash{'uniquecode'}{$crstype}) {
6307: $changes{'uniquecode'} = 1;
6308: }
6309: }
6310: unless ($changes{'uniquecode'}) {
6311: foreach my $crstype (keys(%{$confhash{'uniquecode'}})) {
6312: unless ($domconfig{$action}{'uniquecode'}{$crstype}) {
6313: $changes{'uniquecode'} = 1;
6314: }
6315: }
6316: }
6317: } else {
6318: $changes{'uniquecode'} = 1;
6319: }
6320: } elsif (ref($confhash{'uniquecode'}) eq 'HASH') {
6321: $changes{'uniquecode'} = 1;
1.216 raeburn 6322: }
6323: if ($context eq 'requestcourses') {
6324: if (ref($domconfig{$action}{'textbooks'}) eq 'HASH') {
6325: my %deletions;
6326: my @todelete = &Apache::loncommon::get_env_multiple('form.book_del');
6327: if (@todelete) {
6328: map { $deletions{$_} = 1; } @todelete;
6329: }
6330: my %imgdeletions;
6331: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.book_image_del');
6332: if (@todeleteimages) {
6333: map { $imgdeletions{$_} = 1; } @todeleteimages;
6334: }
6335: my $maxnum = $env{'form.book_maxnum'};
6336: for (my $i=0; $i<=$maxnum; $i++) {
6337: my $key = $env{'form.book_id_'.$i};
6338: if (ref($domconfig{$action}{'textbooks'}{$key}) eq 'HASH') {
6339: if ($deletions{$key}) {
6340: if ($domconfig{$action}{'textbooks'}{$key}{'image'}) {
6341: #FIXME need to obsolete item in RES space
6342: }
6343: next;
6344: } else {
6345: my $newpos = $env{'form.'.$key};
6346: $newpos =~ s/\D+//g;
6347: foreach my $item ('subject','title','author') {
6348: $confhash{'textbooks'}{$key}{$item} = $env{'form.book_'.$item.'_'.$i};
6349: if ($domconfig{$action}{'textbooks'}{$key}{$item} ne $confhash{'textbooks'}{$key}{$item}) {
6350: $changes{'textbooks'}{$key} = 1;
6351: }
6352: }
6353: $allpos[$newpos] = $key;
6354: }
6355: if ($imgdeletions{$key}) {
6356: $changes{'textbooks'}{$key} = 1;
6357: #FIXME need to obsolete item in RES space
6358: } elsif ($env{'form.book_image_'.$i.'.filename'}) {
6359: my ($cdom,$cnum) = split(/_/,$key);
6360: my ($imgurl,$error) = &process_textbook_image($r,$dom,$confname,'book_image_'.$i,
6361: $cdom,$cnum,$configuserok,
6362: $switchserver,$author_ok);
6363: if ($imgurl) {
6364: $confhash{'textbooks'}{$key}{'image'} = $imgurl;
6365: $changes{'textbooks'}{$key} = 1;
6366: }
6367: if ($error) {
6368: &Apache::lonnet::logthis($error);
6369: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
6370: }
6371: } elsif ($domconfig{$action}{'textbooks'}{$key}{'image'}) {
6372: $confhash{'textbooks'}{$key}{'image'} =
6373: $domconfig{$action}{'textbooks'}{$key}{'image'};
6374: }
6375: }
6376: }
6377: }
6378: }
1.102 raeburn 6379: } else {
1.144 raeburn 6380: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 6381: $changes{'notify'}{'approval'} = 1;
6382: }
1.218 raeburn 6383: if (ref($confhash{'uniquecode'} eq 'HASH')) {
1.216 raeburn 6384: $changes{'uniquecode'} = 1;
6385: }
6386: }
6387: if ($context eq 'requestcourses') {
6388: if ($newbook) {
6389: $changes{'textbooks'}{$newbook} = 1;
6390: foreach my $item ('subject','title','author') {
6391: $env{'form.addbook_'.$item} =~ s/(`)/'/g;
6392: if ($env{'form.addbook_'.$item}) {
6393: $confhash{'textbooks'}{$newbook}{$item} = $env{'form.addbook_'.$item};
6394: }
6395: }
6396: if ($env{'form.addbook_image.filename'} ne '') {
6397: my ($cdom,$cnum) = split(/_/,$newbook);
6398: my ($imageurl,$error) =
6399: &process_textbook_image($r,$dom,$confname,'addbook_image',$cdom,$cnum,$configuserok,
6400: $switchserver,$author_ok);
6401: if ($imageurl) {
6402: $confhash{'textbooks'}{$newbook}{'image'} = $imageurl;
6403: }
6404: if ($error) {
6405: &Apache::lonnet::logthis($error);
6406: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
6407: }
6408: }
6409: }
6410: if (@allpos > 0) {
6411: my $idx = 0;
6412: foreach my $item (@allpos) {
6413: if ($item ne '') {
6414: $confhash{'textbooks'}{$item}{'order'} = $idx;
6415: if (ref($domconfig{$action}) eq 'HASH') {
6416: if (ref($domconfig{$action}{'textbooks'}) eq 'HASH') {
6417: if (ref($domconfig{$action}{'textbooks'}{$item}) eq 'HASH') {
6418: if ($domconfig{$action}{'textbooks'}{$item}{'order'} ne $idx) {
6419: $changes{'textbooks'}{$item} = 1;
6420: }
6421: }
6422: }
6423: }
6424: $idx ++;
6425: }
6426: }
6427: }
1.102 raeburn 6428: }
6429: } else {
1.86 raeburn 6430: $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
1.197 raeburn 6431: $confhash{'authorquota'}{'default'} = $env{'form.authorquota'};
1.86 raeburn 6432: }
1.72 raeburn 6433: foreach my $item (@usertools) {
6434: foreach my $type (@{$types},'default','_LC_adv') {
1.104 raeburn 6435: my $unset;
1.101 raeburn 6436: if ($context eq 'requestcourses') {
1.104 raeburn 6437: $unset = '0';
6438: if ($type eq '_LC_adv') {
6439: $unset = '';
6440: }
1.101 raeburn 6441: if ($confhash{$item}{$type} eq 'autolimit') {
6442: $confhash{$item}{$type} .= '=';
6443: unless ($limithash{$item}{$type} =~ /\D/) {
6444: $confhash{$item}{$type} .= $limithash{$item}{$type};
6445: }
6446: }
1.163 raeburn 6447: } elsif ($context eq 'requestauthor') {
6448: $unset = '0';
6449: if ($type eq '_LC_adv') {
6450: $unset = '';
6451: }
1.72 raeburn 6452: } else {
1.101 raeburn 6453: if (grep(/^\Q$type\E$/,@{$toolshash{$item}})) {
6454: $confhash{$item}{$type} = 1;
6455: } else {
6456: $confhash{$item}{$type} = 0;
6457: }
1.72 raeburn 6458: }
1.86 raeburn 6459: if (ref($domconfig{$action}) eq 'HASH') {
1.163 raeburn 6460: if ($action eq 'requestauthor') {
6461: if ($domconfig{$action}{$type} ne $confhash{$type}) {
6462: $changes{$type} = 1;
6463: }
6464: } elsif (ref($domconfig{$action}{$item}) eq 'HASH') {
1.86 raeburn 6465: if ($domconfig{$action}{$item}{$type} ne $confhash{$item}{$type}) {
6466: $changes{$item}{$type} = 1;
6467: }
6468: } else {
6469: if ($context eq 'requestcourses') {
1.104 raeburn 6470: if ($confhash{$item}{$type} ne $unset) {
1.86 raeburn 6471: $changes{$item}{$type} = 1;
6472: }
6473: } else {
6474: if (!$confhash{$item}{$type}) {
6475: $changes{$item}{$type} = 1;
6476: }
6477: }
6478: }
6479: } else {
6480: if ($context eq 'requestcourses') {
1.104 raeburn 6481: if ($confhash{$item}{$type} ne $unset) {
1.72 raeburn 6482: $changes{$item}{$type} = 1;
6483: }
1.163 raeburn 6484: } elsif ($context eq 'requestauthor') {
6485: if ($confhash{$type} ne $unset) {
6486: $changes{$type} = 1;
6487: }
1.72 raeburn 6488: } else {
6489: if (!$confhash{$item}{$type}) {
6490: $changes{$item}{$type} = 1;
6491: }
6492: }
6493: }
1.1 raeburn 6494: }
6495: }
1.163 raeburn 6496: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 6497: if (ref($domconfig{'quotas'}) eq 'HASH') {
6498: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
6499: foreach my $key (keys(%{$domconfig{'quotas'}{'defaultquota'}})) {
6500: if (exists($confhash{'defaultquota'}{$key})) {
6501: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{'defaultquota'}{$key}) {
6502: $changes{'defaultquota'}{$key} = 1;
6503: }
6504: } else {
6505: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{'defaultquota'}{$key};
1.72 raeburn 6506: }
6507: }
1.86 raeburn 6508: } else {
6509: foreach my $key (keys(%{$domconfig{'quotas'}})) {
6510: if (exists($confhash{'defaultquota'}{$key})) {
6511: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{$key}) {
6512: $changes{'defaultquota'}{$key} = 1;
6513: }
6514: } else {
6515: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{$key};
1.72 raeburn 6516: }
1.1 raeburn 6517: }
6518: }
1.197 raeburn 6519: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
6520: foreach my $key (keys(%{$domconfig{'quotas'}{'authorquota'}})) {
6521: if (exists($confhash{'authorquota'}{$key})) {
6522: if ($confhash{'authorquota'}{$key} ne $domconfig{'quotas'}{'authorquota'}{$key}) {
6523: $changes{'authorquota'}{$key} = 1;
6524: }
6525: } else {
6526: $confhash{'authorquota'}{$key} = $domconfig{'quotas'}{'authorquota'}{$key};
6527: }
6528: }
6529: }
1.1 raeburn 6530: }
1.86 raeburn 6531: if (ref($confhash{'defaultquota'}) eq 'HASH') {
6532: foreach my $key (keys(%{$confhash{'defaultquota'}})) {
6533: if (ref($domconfig{'quotas'}) eq 'HASH') {
6534: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
6535: if (!exists($domconfig{'quotas'}{'defaultquota'}{$key})) {
6536: $changes{'defaultquota'}{$key} = 1;
6537: }
6538: } else {
6539: if (!exists($domconfig{'quotas'}{$key})) {
6540: $changes{'defaultquota'}{$key} = 1;
6541: }
1.72 raeburn 6542: }
6543: } else {
1.86 raeburn 6544: $changes{'defaultquota'}{$key} = 1;
1.55 raeburn 6545: }
1.1 raeburn 6546: }
6547: }
1.197 raeburn 6548: if (ref($confhash{'authorquota'}) eq 'HASH') {
6549: foreach my $key (keys(%{$confhash{'authorquota'}})) {
6550: if (ref($domconfig{'quotas'}) eq 'HASH') {
6551: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
6552: if (!exists($domconfig{'quotas'}{'authorquota'}{$key})) {
6553: $changes{'authorquota'}{$key} = 1;
6554: }
6555: } else {
6556: $changes{'authorquota'}{$key} = 1;
6557: }
6558: } else {
6559: $changes{'authorquota'}{$key} = 1;
6560: }
6561: }
6562: }
1.1 raeburn 6563: }
1.72 raeburn 6564:
1.163 raeburn 6565: if ($context eq 'requestauthor') {
6566: $domdefaults{'requestauthor'} = \%confhash;
6567: } else {
6568: foreach my $key (keys(%confhash)) {
1.216 raeburn 6569: unless (($context eq 'requestcourses') && ($key eq 'textbooks')) {
6570: $domdefaults{$key} = $confhash{$key};
6571: }
1.163 raeburn 6572: }
1.72 raeburn 6573: }
1.163 raeburn 6574:
1.1 raeburn 6575: my %quotahash = (
1.86 raeburn 6576: $action => { %confhash }
1.1 raeburn 6577: );
6578: my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
6579: $dom);
6580: if ($putresult eq 'ok') {
6581: if (keys(%changes) > 0) {
1.72 raeburn 6582: my $cachetime = 24*60*60;
6583: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 6584: if (ref($lastactref) eq 'HASH') {
6585: $lastactref->{'domdefaults'} = 1;
6586: }
1.1 raeburn 6587: $resulttext = &mt('Changes made:').'<ul>';
1.210 raeburn 6588: unless (($context eq 'requestcourses') ||
1.163 raeburn 6589: ($context eq 'requestauthor')) {
1.86 raeburn 6590: if (ref($changes{'defaultquota'}) eq 'HASH') {
6591: $resulttext .= '<li>'.&mt('Portfolio default quotas').'<ul>';
6592: foreach my $type (@{$types},'default') {
6593: if (defined($changes{'defaultquota'}{$type})) {
6594: my $typetitle = $usertypes->{$type};
6595: if ($type eq 'default') {
6596: $typetitle = $othertitle;
6597: }
1.213 raeburn 6598: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'defaultquota'}{$type}).'</li>';
1.72 raeburn 6599: }
6600: }
1.86 raeburn 6601: $resulttext .= '</ul></li>';
1.72 raeburn 6602: }
1.197 raeburn 6603: if (ref($changes{'authorquota'}) eq 'HASH') {
1.223 bisitz 6604: $resulttext .= '<li>'.&mt('Authoring Space default quotas').'<ul>';
1.197 raeburn 6605: foreach my $type (@{$types},'default') {
6606: if (defined($changes{'authorquota'}{$type})) {
6607: my $typetitle = $usertypes->{$type};
6608: if ($type eq 'default') {
6609: $typetitle = $othertitle;
6610: }
1.213 raeburn 6611: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'authorquota'}{$type}).'</li>';
1.197 raeburn 6612: }
6613: }
6614: $resulttext .= '</ul></li>';
6615: }
1.72 raeburn 6616: }
1.80 raeburn 6617: my %newenv;
1.72 raeburn 6618: foreach my $item (@usertools) {
1.163 raeburn 6619: my (%haschgs,%inconf);
6620: if ($context eq 'requestauthor') {
6621: %haschgs = %changes;
1.210 raeburn 6622: %inconf = %confhash;
1.163 raeburn 6623: } else {
6624: if (ref($changes{$item}) eq 'HASH') {
6625: %haschgs = %{$changes{$item}};
6626: }
6627: if (ref($confhash{$item}) eq 'HASH') {
6628: %inconf = %{$confhash{$item}};
6629: }
6630: }
6631: if (keys(%haschgs) > 0) {
1.80 raeburn 6632: my $newacc =
6633: &Apache::lonnet::usertools_access($env{'user.name'},
6634: $env{'user.domain'},
1.86 raeburn 6635: $item,'reload',$context);
1.210 raeburn 6636: if (($context eq 'requestcourses') ||
1.163 raeburn 6637: ($context eq 'requestauthor')) {
1.108 raeburn 6638: if ($env{'environment.canrequest.'.$item} ne $newacc) {
6639: $newenv{'environment.canrequest.'.$item} = $newacc;
1.86 raeburn 6640: }
6641: } else {
6642: if ($env{'environment.availabletools.'.$item} ne $newacc) {
6643: $newenv{'environment.availabletools.'.$item} = $newacc;
6644: }
1.80 raeburn 6645: }
1.163 raeburn 6646: unless ($context eq 'requestauthor') {
6647: $resulttext .= '<li>'.$titles{$item}.'<ul>';
6648: }
1.72 raeburn 6649: foreach my $type (@{$types},'default','_LC_adv') {
1.163 raeburn 6650: if ($haschgs{$type}) {
1.72 raeburn 6651: my $typetitle = $usertypes->{$type};
6652: if ($type eq 'default') {
6653: $typetitle = $othertitle;
6654: } elsif ($type eq '_LC_adv') {
6655: $typetitle = 'LON-CAPA Advanced Users';
6656: }
1.163 raeburn 6657: if ($inconf{$type}) {
1.101 raeburn 6658: if ($context eq 'requestcourses') {
6659: my $cond;
1.163 raeburn 6660: if ($inconf{$type} =~ /^autolimit=(\d*)$/) {
1.101 raeburn 6661: if ($1 eq '') {
6662: $cond = &mt('(Automatic processing of any request).');
6663: } else {
6664: $cond = &mt('(Automatic processing of requests up to limit of [quant,_1,request] per user).',$1);
6665: }
6666: } else {
1.163 raeburn 6667: $cond = $conditions{$inconf{$type}};
1.101 raeburn 6668: }
6669: $resulttext .= '<li>'.&mt('Set to be available to [_1].',$typetitle).' '.$cond.'</li>';
1.172 raeburn 6670: } elsif ($context eq 'requestauthor') {
6671: $resulttext .= '<li>'.&mt('Set to "[_1]" for "[_2]".',
6672: $titles{$inconf{$type}},$typetitle);
6673:
1.101 raeburn 6674: } else {
6675: $resulttext .= '<li>'.&mt('Set to be available to [_1]',$typetitle).'</li>';
6676: }
1.72 raeburn 6677: } else {
1.104 raeburn 6678: if ($type eq '_LC_adv') {
1.163 raeburn 6679: if ($inconf{$type} eq '0') {
1.104 raeburn 6680: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
6681: } else {
6682: $resulttext .= '<li>'.&mt('No override set for [_1]',$typetitle).'</li>';
6683: }
6684: } else {
6685: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
6686: }
1.72 raeburn 6687: }
6688: }
1.26 raeburn 6689: }
1.163 raeburn 6690: unless ($context eq 'requestauthor') {
6691: $resulttext .= '</ul></li>';
6692: }
1.26 raeburn 6693: }
1.1 raeburn 6694: }
1.163 raeburn 6695: if (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.102 raeburn 6696: if (ref($changes{'notify'}) eq 'HASH') {
6697: if ($changes{'notify'}{'approval'}) {
6698: if (ref($confhash{'notify'}) eq 'HASH') {
6699: if ($confhash{'notify'}{'approval'}) {
6700: $resulttext .= '<li>'.&mt('Notification of requests requiring approval will be sent to: ').$confhash{'notify'}{'approval'}.'</li>';
6701: } else {
1.163 raeburn 6702: $resulttext .= '<li>'.&mt('No Domain Coordinators will receive notification of requests requiring approval.').'</li>';
1.102 raeburn 6703: }
6704: }
6705: }
6706: }
6707: }
1.216 raeburn 6708: if ($action eq 'requestcourses') {
6709: my @offon = ('off','on');
6710: if ($changes{'uniquecode'}) {
1.218 raeburn 6711: if (ref($confhash{'uniquecode'}) eq 'HASH') {
6712: my $codestr = join(' ',map{ &mt($_); } sort(keys(%{$confhash{'uniquecode'}})));
6713: $resulttext .= '<li>'.
6714: &mt('Generation of six character code as course identifier for distribution to students set to on for: [_1].','<b>'.$codestr.'</b>').
6715: '</li>';
6716: } else {
6717: $resulttext .= '<li>'.&mt('Generation of six character code as course identifier for distribution to students set to off.').
6718: '</li>';
6719: }
1.216 raeburn 6720: }
6721: if (ref($changes{'textbooks'}) eq 'HASH') {
6722: $resulttext .= '<li>'.&mt('Available textbooks updated').'<ul>';
6723: foreach my $key (sort(keys(%{$changes{'textbooks'}}))) {
6724: my %coursehash = &Apache::lonnet::coursedescription($key);
6725: my $coursetitle = $coursehash{'description'};
6726: my $position = $confhash{'textbooks'}{$key}{'order'} + 1;
6727: $resulttext .= '<li>';
6728: foreach my $item ('subject','title','author') {
6729: my $name = $item.':';
6730: $name =~ s/^(\w)/\U$1/;
6731: $resulttext .= &mt($name).' '.$confhash{'textbooks'}{$key}{$item}.'<br />';
6732: }
6733: $resulttext .= ' '.&mt('Order: [_1]',$position).'<br />';
6734: if ($confhash{'textbooks'}{$key}{'image'}) {
6735: $resulttext .= ' '.&mt('Image: [_1]',
6736: '<img src="'.$confhash{'textbooks'}{$key}{'image'}.'"'.
6737: ' alt="Textbook cover" />').'<br />';
6738: }
6739: $resulttext .= ' '.&mt('LON-CAPA Course: [_1]',$coursetitle).'</li>';
6740: }
6741: $resulttext .= '</ul></li>';
6742: }
6743: }
1.1 raeburn 6744: $resulttext .= '</ul>';
1.80 raeburn 6745: if (keys(%newenv)) {
6746: &Apache::lonnet::appenv(\%newenv);
6747: }
1.1 raeburn 6748: } else {
1.86 raeburn 6749: if ($context eq 'requestcourses') {
6750: $resulttext = &mt('No changes made to rights to request creation of courses.');
1.163 raeburn 6751: } elsif ($context eq 'requestauthor') {
6752: $resulttext = &mt('No changes made to rights to request author space.');
1.86 raeburn 6753: } else {
1.90 weissno 6754: $resulttext = &mt('No changes made to availability of personal information pages, blogs, portfolios or default quotas');
1.86 raeburn 6755: }
1.1 raeburn 6756: }
6757: } else {
1.11 albertel 6758: $resulttext = '<span class="LC_error">'.
6759: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 6760: }
1.216 raeburn 6761: if ($errors) {
6762: $resulttext .= '<p>'.&mt('The following errors occurred when modifying Textbook settings.').
6763: '<ul>'.$errors.'</ul></p>';
6764: }
1.3 raeburn 6765: return $resulttext;
1.1 raeburn 6766: }
6767:
1.216 raeburn 6768: sub process_textbook_image {
6769: my ($r,$dom,$confname,$caller,$cdom,$cnum,$configuserok,$switchserver,$author_ok) = @_;
6770: my $filename = $env{'form.'.$caller.'.filename'};
6771: my ($error,$url);
6772: my ($width,$height) = (50,50);
6773: if ($configuserok eq 'ok') {
6774: if ($switchserver) {
6775: $error = &mt('Upload of textbook image is not permitted to this server: [_1]',
6776: $switchserver);
6777: } elsif ($author_ok eq 'ok') {
6778: my ($result,$imageurl) =
6779: &publishlogo($r,'upload',$caller,$dom,$confname,
6780: "textbooks/$dom/$cnum/cover",$width,$height);
6781: if ($result eq 'ok') {
6782: $url = $imageurl;
6783: } else {
6784: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
6785: }
6786: } else {
6787: $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);
6788: }
6789: } else {
6790: $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);
6791: }
6792: return ($url,$error);
6793: }
6794:
1.3 raeburn 6795: sub modify_autoenroll {
1.205 raeburn 6796: my ($dom,$lastactref,%domconfig) = @_;
1.1 raeburn 6797: my ($resulttext,%changes);
6798: my %currautoenroll;
6799: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
6800: foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
6801: $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
6802: }
6803: }
6804: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
6805: my %title = ( run => 'Auto-enrollment active',
1.129 raeburn 6806: sender => 'Sender for notification messages',
6807: coowners => 'Automatic assignment of co-ownership to instructors of record (institutional data)');
1.1 raeburn 6808: my @offon = ('off','on');
1.17 raeburn 6809: my $sender_uname = $env{'form.sender_uname'};
6810: my $sender_domain = $env{'form.sender_domain'};
6811: if ($sender_domain eq '') {
6812: $sender_uname = '';
6813: } elsif ($sender_uname eq '') {
6814: $sender_domain = '';
6815: }
1.129 raeburn 6816: my $coowners = $env{'form.autoassign_coowners'};
1.1 raeburn 6817: my %autoenrollhash = (
1.129 raeburn 6818: autoenroll => { 'run' => $env{'form.autoenroll_run'},
6819: 'sender_uname' => $sender_uname,
6820: 'sender_domain' => $sender_domain,
6821: 'co-owners' => $coowners,
1.1 raeburn 6822: }
6823: );
1.4 raeburn 6824: my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
6825: $dom);
1.1 raeburn 6826: if ($putresult eq 'ok') {
6827: if (exists($currautoenroll{'run'})) {
6828: if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
6829: $changes{'run'} = 1;
6830: }
6831: } elsif ($autorun) {
6832: if ($env{'form.autoenroll_run'} ne '1') {
1.23 raeburn 6833: $changes{'run'} = 1;
1.1 raeburn 6834: }
6835: }
1.17 raeburn 6836: if ($currautoenroll{'sender_uname'} ne $sender_uname) {
1.1 raeburn 6837: $changes{'sender'} = 1;
6838: }
1.17 raeburn 6839: if ($currautoenroll{'sender_domain'} ne $sender_domain) {
1.1 raeburn 6840: $changes{'sender'} = 1;
6841: }
1.129 raeburn 6842: if ($currautoenroll{'co-owners'} ne '') {
6843: if ($currautoenroll{'co-owners'} ne $coowners) {
6844: $changes{'coowners'} = 1;
6845: }
6846: } elsif ($coowners) {
6847: $changes{'coowners'} = 1;
6848: }
1.1 raeburn 6849: if (keys(%changes) > 0) {
6850: $resulttext = &mt('Changes made:').'<ul>';
1.3 raeburn 6851: if ($changes{'run'}) {
1.1 raeburn 6852: $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
6853: }
6854: if ($changes{'sender'}) {
1.17 raeburn 6855: if ($sender_uname eq '' || $sender_domain eq '') {
6856: $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
6857: } else {
6858: $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
6859: }
1.1 raeburn 6860: }
1.129 raeburn 6861: if ($changes{'coowners'}) {
6862: $resulttext .= '<li>'.&mt("$title{'coowners'} set to $offon[$env{'form.autoassign_coowners'}]").'</li>';
6863: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 6864: if (ref($lastactref) eq 'HASH') {
6865: $lastactref->{'domainconfig'} = 1;
6866: }
1.129 raeburn 6867: }
1.1 raeburn 6868: $resulttext .= '</ul>';
6869: } else {
6870: $resulttext = &mt('No changes made to auto-enrollment settings');
6871: }
6872: } else {
1.11 albertel 6873: $resulttext = '<span class="LC_error">'.
6874: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 6875: }
1.3 raeburn 6876: return $resulttext;
1.1 raeburn 6877: }
6878:
6879: sub modify_autoupdate {
1.3 raeburn 6880: my ($dom,%domconfig) = @_;
1.1 raeburn 6881: my ($resulttext,%currautoupdate,%fields,%changes);
6882: if (ref($domconfig{'autoupdate'}) eq 'HASH') {
6883: foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
6884: $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
6885: }
6886: }
6887: my @offon = ('off','on');
6888: my %title = &Apache::lonlocal::texthash (
6889: run => 'Auto-update:',
6890: classlists => 'Updates to user information in classlists?'
6891: );
1.44 raeburn 6892: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 6893: my %fieldtitles = &Apache::lonlocal::texthash (
6894: id => 'Student/Employee ID',
1.20 raeburn 6895: permanentemail => 'E-mail address',
1.1 raeburn 6896: lastname => 'Last Name',
6897: firstname => 'First Name',
6898: middlename => 'Middle Name',
1.132 raeburn 6899: generation => 'Generation',
1.1 raeburn 6900: );
1.142 raeburn 6901: $othertitle = &mt('All users');
1.1 raeburn 6902: if (keys(%{$usertypes}) > 0) {
1.26 raeburn 6903: $othertitle = &mt('Other users');
1.1 raeburn 6904: }
6905: foreach my $key (keys(%env)) {
6906: if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
1.132 raeburn 6907: my ($usertype,$item) = ($1,$2);
6908: if (grep(/^\Q$item\E$/,keys(%fieldtitles))) {
6909: if ($usertype eq 'default') {
6910: push(@{$fields{$1}},$2);
6911: } elsif (ref($types) eq 'ARRAY') {
6912: if (grep(/^\Q$usertype\E$/,@{$types})) {
6913: push(@{$fields{$1}},$2);
6914: }
6915: }
6916: }
1.1 raeburn 6917: }
6918: }
1.131 raeburn 6919: my @lockablenames = &Apache::loncommon::get_env_multiple('form.lockablenames');
6920: @lockablenames = sort(@lockablenames);
6921: if (ref($currautoupdate{'lockablenames'}) eq 'ARRAY') {
6922: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
6923: if (@changed) {
6924: $changes{'lockablenames'} = 1;
6925: }
6926: } else {
6927: if (@lockablenames) {
6928: $changes{'lockablenames'} = 1;
6929: }
6930: }
1.1 raeburn 6931: my %updatehash = (
6932: autoupdate => { run => $env{'form.autoupdate_run'},
6933: classlists => $env{'form.classlists'},
6934: fields => {%fields},
1.131 raeburn 6935: lockablenames => \@lockablenames,
1.1 raeburn 6936: }
6937: );
6938: foreach my $key (keys(%currautoupdate)) {
6939: if (($key eq 'run') || ($key eq 'classlists')) {
6940: if (exists($updatehash{autoupdate}{$key})) {
6941: if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
6942: $changes{$key} = 1;
6943: }
6944: }
6945: } elsif ($key eq 'fields') {
6946: if (ref($currautoupdate{$key}) eq 'HASH') {
1.26 raeburn 6947: foreach my $item (@{$types},'default') {
1.1 raeburn 6948: if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
6949: my $change = 0;
6950: foreach my $type (@{$currautoupdate{$key}{$item}}) {
6951: if (!exists($fields{$item})) {
6952: $change = 1;
1.132 raeburn 6953: last;
1.1 raeburn 6954: } elsif (ref($fields{$item}) eq 'ARRAY') {
1.26 raeburn 6955: if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
1.1 raeburn 6956: $change = 1;
1.132 raeburn 6957: last;
1.1 raeburn 6958: }
6959: }
6960: }
6961: if ($change) {
6962: push(@{$changes{$key}},$item);
6963: }
1.26 raeburn 6964: }
1.1 raeburn 6965: }
6966: }
1.131 raeburn 6967: } elsif ($key eq 'lockablenames') {
6968: if (ref($currautoupdate{$key}) eq 'ARRAY') {
6969: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
6970: if (@changed) {
6971: $changes{'lockablenames'} = 1;
6972: }
6973: } else {
6974: if (@lockablenames) {
6975: $changes{'lockablenames'} = 1;
6976: }
6977: }
6978: }
6979: }
6980: unless (grep(/^\Qlockablenames\E$/,keys(%currautoupdate))) {
6981: if (@lockablenames) {
6982: $changes{'lockablenames'} = 1;
1.1 raeburn 6983: }
6984: }
1.26 raeburn 6985: foreach my $item (@{$types},'default') {
6986: if (defined($fields{$item})) {
6987: if (ref($currautoupdate{'fields'}) eq 'HASH') {
1.132 raeburn 6988: if (ref($currautoupdate{'fields'}{$item}) eq 'ARRAY') {
6989: my $change = 0;
6990: if (ref($fields{$item}) eq 'ARRAY') {
6991: foreach my $type (@{$fields{$item}}) {
6992: if (!grep(/^\Q$type\E$/,@{$currautoupdate{'fields'}{$item}})) {
6993: $change = 1;
6994: last;
6995: }
6996: }
6997: }
6998: if ($change) {
6999: push(@{$changes{'fields'}},$item);
7000: }
7001: } else {
1.26 raeburn 7002: push(@{$changes{'fields'}},$item);
7003: }
7004: } else {
7005: push(@{$changes{'fields'}},$item);
1.1 raeburn 7006: }
7007: }
7008: }
7009: my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
7010: $dom);
7011: if ($putresult eq 'ok') {
7012: if (keys(%changes) > 0) {
7013: $resulttext = &mt('Changes made:').'<ul>';
7014: foreach my $key (sort(keys(%changes))) {
1.131 raeburn 7015: if ($key eq 'lockablenames') {
7016: $resulttext .= '<li>';
7017: if (@lockablenames) {
7018: $usertypes->{'default'} = $othertitle;
7019: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update), available for the following affiliations:").' '.
7020: join(', ', map { $usertypes->{$_}; } @lockablenames).'</li>';
7021: } else {
7022: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update) is unavailable.");
7023: }
7024: $resulttext .= '</li>';
7025: } elsif (ref($changes{$key}) eq 'ARRAY') {
1.1 raeburn 7026: foreach my $item (@{$changes{$key}}) {
7027: my @newvalues;
7028: foreach my $type (@{$fields{$item}}) {
7029: push(@newvalues,$fieldtitles{$type});
7030: }
1.3 raeburn 7031: my $newvaluestr;
7032: if (@newvalues > 0) {
7033: $newvaluestr = join(', ',@newvalues);
7034: } else {
7035: $newvaluestr = &mt('none');
1.6 raeburn 7036: }
1.1 raeburn 7037: if ($item eq 'default') {
1.26 raeburn 7038: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
1.1 raeburn 7039: } else {
1.26 raeburn 7040: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
1.1 raeburn 7041: }
7042: }
7043: } else {
7044: my $newvalue;
7045: if ($key eq 'run') {
7046: $newvalue = $offon[$env{'form.autoupdate_run'}];
7047: } else {
7048: $newvalue = $offon[$env{'form.'.$key}];
1.3 raeburn 7049: }
1.1 raeburn 7050: $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
7051: }
7052: }
7053: $resulttext .= '</ul>';
7054: } else {
1.3 raeburn 7055: $resulttext = &mt('No changes made to autoupdates');
1.1 raeburn 7056: }
7057: } else {
1.11 albertel 7058: $resulttext = '<span class="LC_error">'.
7059: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 7060: }
1.3 raeburn 7061: return $resulttext;
1.1 raeburn 7062: }
7063:
1.125 raeburn 7064: sub modify_autocreate {
7065: my ($dom,%domconfig) = @_;
7066: my ($resulttext,%changes,%currautocreate,%newvals,%autocreatehash);
7067: if (ref($domconfig{'autocreate'}) eq 'HASH') {
7068: foreach my $key (keys(%{$domconfig{'autocreate'}})) {
7069: $currautocreate{$key} = $domconfig{'autocreate'}{$key};
7070: }
7071: }
7072: my %title= ( xml => 'Auto-creation of courses in XML course description files',
7073: req => 'Auto-creation of validated requests for official courses',
7074: xmldc => 'Identity of course creator of courses from XML files',
7075: );
7076: my @types = ('xml','req');
7077: foreach my $item (@types) {
7078: $newvals{$item} = $env{'form.autocreate_'.$item};
7079: $newvals{$item} =~ s/\D//g;
7080: $newvals{$item} = 0 if ($newvals{$item} eq '');
7081: }
7082: $newvals{'xmldc'} = $env{'form.autocreate_xmldc'};
7083: my %domcoords = &get_active_dcs($dom);
7084: unless (exists($domcoords{$newvals{'xmldc'}})) {
7085: $newvals{'xmldc'} = '';
7086: }
7087: %autocreatehash = (
7088: autocreate => { xml => $newvals{'xml'},
7089: req => $newvals{'req'},
7090: }
7091: );
7092: if ($newvals{'xmldc'} ne '') {
7093: $autocreatehash{'autocreate'}{'xmldc'} = $newvals{'xmldc'};
7094: }
7095: my $putresult = &Apache::lonnet::put_dom('configuration',\%autocreatehash,
7096: $dom);
7097: if ($putresult eq 'ok') {
7098: my @items = @types;
7099: if ($newvals{'xml'}) {
7100: push(@items,'xmldc');
7101: }
7102: foreach my $item (@items) {
7103: if (exists($currautocreate{$item})) {
7104: if ($currautocreate{$item} ne $newvals{$item}) {
7105: $changes{$item} = 1;
7106: }
7107: } elsif ($newvals{$item}) {
7108: $changes{$item} = 1;
7109: }
7110: }
7111: if (keys(%changes) > 0) {
7112: my @offon = ('off','on');
7113: $resulttext = &mt('Changes made:').'<ul>';
7114: foreach my $item (@types) {
7115: if ($changes{$item}) {
7116: my $newtxt = $offon[$newvals{$item}];
1.178 raeburn 7117: $resulttext .= '<li>'.
7118: &mt("$title{$item} set to [_1]$newtxt [_2]",
7119: '<b>','</b>').
7120: '</li>';
1.125 raeburn 7121: }
7122: }
7123: if ($changes{'xmldc'}) {
7124: my ($dcname,$dcdom) = split(':',$newvals{'xmldc'});
7125: my $newtxt = &Apache::loncommon::plainname($dcname,$dcdom);
1.178 raeburn 7126: $resulttext .= '<li>'.&mt("$title{'xmldc'} set to [_1]",'<b>'.$newtxt.'</b>').'</li>';
1.125 raeburn 7127: }
7128: $resulttext .= '</ul>';
7129: } else {
7130: $resulttext = &mt('No changes made to auto-creation settings');
7131: }
7132: } else {
7133: $resulttext = '<span class="LC_error">'.
7134: &mt('An error occurred: [_1]',$putresult).'</span>';
7135: }
7136: return $resulttext;
7137: }
7138:
1.23 raeburn 7139: sub modify_directorysrch {
7140: my ($dom,%domconfig) = @_;
7141: my ($resulttext,%changes);
7142: my %currdirsrch;
7143: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
7144: foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
7145: $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
7146: }
7147: }
7148: my %title = ( available => 'Directory search available',
1.24 raeburn 7149: localonly => 'Other domains can search',
1.23 raeburn 7150: searchby => 'Search types',
7151: searchtypes => 'Search latitude');
7152: my @offon = ('off','on');
1.24 raeburn 7153: my @otherdoms = ('Yes','No');
1.23 raeburn 7154:
1.25 raeburn 7155: my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');
1.23 raeburn 7156: my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
7157: my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
7158:
1.44 raeburn 7159: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.26 raeburn 7160: if (keys(%{$usertypes}) == 0) {
7161: @cansearch = ('default');
7162: } else {
7163: if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
7164: foreach my $type (@{$currdirsrch{'cansearch'}}) {
7165: if (!grep(/^\Q$type\E$/,@cansearch)) {
7166: push(@{$changes{'cansearch'}},$type);
7167: }
1.23 raeburn 7168: }
1.26 raeburn 7169: foreach my $type (@cansearch) {
7170: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
7171: push(@{$changes{'cansearch'}},$type);
7172: }
1.23 raeburn 7173: }
1.26 raeburn 7174: } else {
7175: push(@{$changes{'cansearch'}},@cansearch);
1.23 raeburn 7176: }
7177: }
7178:
7179: if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
7180: foreach my $by (@{$currdirsrch{'searchby'}}) {
7181: if (!grep(/^\Q$by\E$/,@searchby)) {
7182: push(@{$changes{'searchby'}},$by);
7183: }
7184: }
7185: foreach my $by (@searchby) {
7186: if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
7187: push(@{$changes{'searchby'}},$by);
7188: }
7189: }
7190: } else {
7191: push(@{$changes{'searchby'}},@searchby);
7192: }
1.25 raeburn 7193:
7194: if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
7195: foreach my $type (@{$currdirsrch{'searchtypes'}}) {
7196: if (!grep(/^\Q$type\E$/,@searchtypes)) {
7197: push(@{$changes{'searchtypes'}},$type);
7198: }
7199: }
7200: foreach my $type (@searchtypes) {
7201: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
7202: push(@{$changes{'searchtypes'}},$type);
7203: }
7204: }
7205: } else {
7206: if (exists($currdirsrch{'searchtypes'})) {
7207: foreach my $type (@searchtypes) {
7208: if ($type ne $currdirsrch{'searchtypes'}) {
7209: push(@{$changes{'searchtypes'}},$type);
7210: }
7211: }
7212: if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
7213: push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
7214: }
7215: } else {
7216: push(@{$changes{'searchtypes'}},@searchtypes);
7217: }
7218: }
7219:
1.23 raeburn 7220: my %dirsrch_hash = (
7221: directorysrch => { available => $env{'form.dirsrch_available'},
7222: cansearch => \@cansearch,
1.24 raeburn 7223: localonly => $env{'form.dirsrch_localonly'},
1.23 raeburn 7224: searchby => \@searchby,
1.25 raeburn 7225: searchtypes => \@searchtypes,
1.23 raeburn 7226: }
7227: );
7228: my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
7229: $dom);
7230: if ($putresult eq 'ok') {
7231: if (exists($currdirsrch{'available'})) {
7232: if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
7233: $changes{'available'} = 1;
7234: }
7235: } else {
7236: if ($env{'form.dirsrch_available'} eq '1') {
7237: $changes{'available'} = 1;
7238: }
7239: }
1.24 raeburn 7240: if (exists($currdirsrch{'localonly'})) {
7241: if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_localonly'}) {
7242: $changes{'localonly'} = 1;
7243: }
7244: } else {
7245: if ($env{'form.dirsrch_localonly'} eq '1') {
7246: $changes{'localonly'} = 1;
7247: }
7248: }
1.23 raeburn 7249: if (keys(%changes) > 0) {
7250: $resulttext = &mt('Changes made:').'<ul>';
7251: if ($changes{'available'}) {
7252: $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
7253: }
1.24 raeburn 7254: if ($changes{'localonly'}) {
7255: $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_localonly'}]").'</li>';
7256: }
7257:
1.23 raeburn 7258: if (ref($changes{'cansearch'}) eq 'ARRAY') {
7259: my $chgtext;
1.26 raeburn 7260: if (ref($usertypes) eq 'HASH') {
7261: if (keys(%{$usertypes}) > 0) {
7262: foreach my $type (@{$types}) {
7263: if (grep(/^\Q$type\E$/,@cansearch)) {
7264: $chgtext .= $usertypes->{$type}.'; ';
7265: }
7266: }
7267: if (grep(/^default$/,@cansearch)) {
7268: $chgtext .= $othertitle;
7269: } else {
7270: $chgtext =~ s/\; $//;
7271: }
1.210 raeburn 7272: $resulttext .=
1.178 raeburn 7273: '<li>'.
7274: &mt("Users from domain '[_1]' permitted to search the institutional directory set to: [_2]",
7275: '<span class="LC_cusr_emph">'.$dom.'</span>',$chgtext).
7276: '</li>';
1.23 raeburn 7277: }
7278: }
7279: }
7280: if (ref($changes{'searchby'}) eq 'ARRAY') {
7281: my ($searchtitles,$titleorder) = &sorted_searchtitles();
7282: my $chgtext;
7283: foreach my $type (@{$titleorder}) {
7284: if (grep(/^\Q$type\E$/,@searchby)) {
7285: if (defined($searchtitles->{$type})) {
7286: $chgtext .= $searchtitles->{$type}.'; ';
7287: }
7288: }
7289: }
7290: $chgtext =~ s/\; $//;
7291: $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
7292: }
1.25 raeburn 7293: if (ref($changes{'searchtypes'}) eq 'ARRAY') {
7294: my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes();
7295: my $chgtext;
7296: foreach my $type (@{$srchtypeorder}) {
7297: if (grep(/^\Q$type\E$/,@searchtypes)) {
7298: if (defined($srchtypes_desc->{$type})) {
7299: $chgtext .= $srchtypes_desc->{$type}.'; ';
7300: }
7301: }
7302: }
7303: $chgtext =~ s/\; $//;
1.178 raeburn 7304: $resulttext .= '<li>'.&mt($title{'searchtypes'}.' set to: "[_1]"',$chgtext).'</li>';
1.23 raeburn 7305: }
7306: $resulttext .= '</ul>';
7307: } else {
7308: $resulttext = &mt('No changes made to institution directory search settings');
7309: }
7310: } else {
7311: $resulttext = '<span class="LC_error">'.
1.27 raeburn 7312: &mt('An error occurred: [_1]',$putresult).'</span>';
7313: }
7314: return $resulttext;
7315: }
7316:
1.28 raeburn 7317: sub modify_contacts {
1.205 raeburn 7318: my ($dom,$lastactref,%domconfig) = @_;
1.28 raeburn 7319: my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
7320: if (ref($domconfig{'contacts'}) eq 'HASH') {
7321: foreach my $key (keys(%{$domconfig{'contacts'}})) {
7322: $currsetting{$key} = $domconfig{'contacts'}{$key};
7323: }
7324: }
1.134 raeburn 7325: my (%others,%to,%bcc);
1.28 raeburn 7326: my @contacts = ('supportemail','adminemail');
1.102 raeburn 7327: my @mailings = ('errormail','packagesmail','helpdeskmail','lonstatusmail',
1.203 raeburn 7328: 'requestsmail','updatesmail','idconflictsmail');
7329: my @toggles = ('reporterrors','reportupdates');
1.28 raeburn 7330: foreach my $type (@mailings) {
7331: @{$newsetting{$type}} =
7332: &Apache::loncommon::get_env_multiple('form.'.$type);
7333: foreach my $item (@contacts) {
7334: if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
7335: $contacts_hash{contacts}{$type}{$item} = 1;
7336: } else {
7337: $contacts_hash{contacts}{$type}{$item} = 0;
7338: }
7339: }
7340: $others{$type} = $env{'form.'.$type.'_others'};
7341: $contacts_hash{contacts}{$type}{'others'} = $others{$type};
1.134 raeburn 7342: if ($type eq 'helpdeskmail') {
7343: $bcc{$type} = $env{'form.'.$type.'_bcc'};
7344: $contacts_hash{contacts}{$type}{'bcc'} = $bcc{$type};
7345: }
1.28 raeburn 7346: }
7347: foreach my $item (@contacts) {
7348: $to{$item} = $env{'form.'.$item};
7349: $contacts_hash{'contacts'}{$item} = $to{$item};
7350: }
1.203 raeburn 7351: foreach my $item (@toggles) {
7352: if ($env{'form.'.$item} =~ /^(0|1)$/) {
7353: $contacts_hash{'contacts'}{$item} = $env{'form.'.$item};
7354: }
7355: }
1.28 raeburn 7356: if (keys(%currsetting) > 0) {
7357: foreach my $item (@contacts) {
7358: if ($to{$item} ne $currsetting{$item}) {
7359: $changes{$item} = 1;
7360: }
7361: }
7362: foreach my $type (@mailings) {
7363: foreach my $item (@contacts) {
7364: if (ref($currsetting{$type}) eq 'HASH') {
7365: if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
7366: push(@{$changes{$type}},$item);
7367: }
7368: } else {
7369: push(@{$changes{$type}},@{$newsetting{$type}});
7370: }
7371: }
7372: if ($others{$type} ne $currsetting{$type}{'others'}) {
7373: push(@{$changes{$type}},'others');
7374: }
1.134 raeburn 7375: if ($type eq 'helpdeskmail') {
7376: if ($bcc{$type} ne $currsetting{$type}{'bcc'}) {
7377: push(@{$changes{$type}},'bcc');
7378: }
7379: }
1.28 raeburn 7380: }
7381: } else {
7382: my %default;
7383: $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
7384: $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
7385: $default{'errormail'} = 'adminemail';
7386: $default{'packagesmail'} = 'adminemail';
7387: $default{'helpdeskmail'} = 'supportemail';
1.89 raeburn 7388: $default{'lonstatusmail'} = 'adminemail';
1.102 raeburn 7389: $default{'requestsmail'} = 'adminemail';
1.190 raeburn 7390: $default{'updatesmail'} = 'adminemail';
1.28 raeburn 7391: foreach my $item (@contacts) {
7392: if ($to{$item} ne $default{$item}) {
7393: $changes{$item} = 1;
1.203 raeburn 7394: }
1.28 raeburn 7395: }
7396: foreach my $type (@mailings) {
7397: if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
7398:
7399: push(@{$changes{$type}},@{$newsetting{$type}});
7400: }
7401: if ($others{$type} ne '') {
7402: push(@{$changes{$type}},'others');
1.134 raeburn 7403: }
7404: if ($type eq 'helpdeskmail') {
7405: if ($bcc{$type} ne '') {
7406: push(@{$changes{$type}},'bcc');
7407: }
7408: }
1.28 raeburn 7409: }
7410: }
1.203 raeburn 7411: foreach my $item (@toggles) {
7412: if (($env{'form.'.$item} == 1) && ($currsetting{$item} == 0)) {
7413: $changes{$item} = 1;
7414: } elsif ((!$env{'form.'.$item}) &&
7415: (($currsetting{$item} eq '') || ($currsetting{$item} == 1))) {
7416: $changes{$item} = 1;
7417: }
7418: }
1.28 raeburn 7419: my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
7420: $dom);
7421: if ($putresult eq 'ok') {
7422: if (keys(%changes) > 0) {
1.205 raeburn 7423: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 7424: if (ref($lastactref) eq 'HASH') {
7425: $lastactref->{'domainconfig'} = 1;
7426: }
1.28 raeburn 7427: my ($titles,$short_titles) = &contact_titles();
7428: $resulttext = &mt('Changes made:').'<ul>';
7429: foreach my $item (@contacts) {
7430: if ($changes{$item}) {
7431: $resulttext .= '<li>'.$titles->{$item}.
7432: &mt(' set to: ').
7433: '<span class="LC_cusr_emph">'.
7434: $to{$item}.'</span></li>';
7435: }
7436: }
7437: foreach my $type (@mailings) {
7438: if (ref($changes{$type}) eq 'ARRAY') {
7439: $resulttext .= '<li>'.$titles->{$type}.': ';
7440: my @text;
7441: foreach my $item (@{$newsetting{$type}}) {
7442: push(@text,$short_titles->{$item});
7443: }
7444: if ($others{$type} ne '') {
7445: push(@text,$others{$type});
7446: }
7447: $resulttext .= '<span class="LC_cusr_emph">'.
1.134 raeburn 7448: join(', ',@text).'</span>';
7449: if ($type eq 'helpdeskmail') {
7450: if ($bcc{$type} ne '') {
7451: $resulttext .= ' '.&mt('with Bcc to').': <span class="LC_cusr_emph">'.$bcc{$type}.'</span>';
7452: }
7453: }
7454: $resulttext .= '</li>';
1.28 raeburn 7455: }
7456: }
1.203 raeburn 7457: my @offon = ('off','on');
7458: if ($changes{'reporterrors'}) {
7459: $resulttext .= '<li>'.
7460: &mt('E-mail error reports to [_1] set to "'.
7461: $offon[$env{'form.reporterrors'}].'".',
7462: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
7463: &mt('LON-CAPA core group - MSU'),600,500)).
7464: '</li>';
7465: }
7466: if ($changes{'reportupdates'}) {
7467: $resulttext .= '<li>'.
7468: &mt('E-mail record of completed LON-CAPA updates to [_1] set to "'.
7469: $offon[$env{'form.reportupdates'}].'".',
7470: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
7471: &mt('LON-CAPA core group - MSU'),600,500)).
7472: '</li>';
7473: }
1.28 raeburn 7474: $resulttext .= '</ul>';
7475: } else {
1.34 raeburn 7476: $resulttext = &mt('No changes made to contact information');
1.28 raeburn 7477: }
7478: } else {
7479: $resulttext = '<span class="LC_error">'.
7480: &mt('An error occurred: [_1].',$putresult).'</span>';
7481: }
7482: return $resulttext;
7483: }
7484:
7485: sub modify_usercreation {
1.27 raeburn 7486: my ($dom,%domconfig) = @_;
1.224 raeburn 7487: my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate,%save_usercreate);
1.43 raeburn 7488: my $warningmsg;
1.27 raeburn 7489: if (ref($domconfig{'usercreation'}) eq 'HASH') {
7490: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
1.224 raeburn 7491: if ($key eq 'cancreate') {
7492: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
7493: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
7494: if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
7495: ($item eq 'captcha') || ($item eq 'recaptchakeys')) {
7496: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
7497: } else {
7498: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
7499: }
7500: }
7501: }
7502: } elsif ($key eq 'email_rule') {
7503: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
7504: } else {
7505: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
7506: }
1.27 raeburn 7507: }
7508: }
7509: my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
1.32 raeburn 7510: my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
1.224 raeburn 7511: my @contexts = ('author','course','requestcrs');
1.34 raeburn 7512: foreach my $item(@contexts) {
1.224 raeburn 7513: $cancreate{$item} = $env{'form.can_createuser_'.$item};
1.93 raeburn 7514: }
1.34 raeburn 7515: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
7516: foreach my $item (@contexts) {
1.224 raeburn 7517: if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
7518: push(@{$changes{'cancreate'}},$item);
1.50 raeburn 7519: }
1.27 raeburn 7520: }
1.34 raeburn 7521: } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
7522: foreach my $item (@contexts) {
1.43 raeburn 7523: if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
1.34 raeburn 7524: if ($cancreate{$item} ne 'any') {
7525: push(@{$changes{'cancreate'}},$item);
7526: }
7527: } else {
7528: if ($cancreate{$item} ne 'none') {
7529: push(@{$changes{'cancreate'}},$item);
7530: }
1.27 raeburn 7531: }
7532: }
7533: } else {
1.43 raeburn 7534: foreach my $item (@contexts) {
1.34 raeburn 7535: push(@{$changes{'cancreate'}},$item);
7536: }
1.27 raeburn 7537: }
1.34 raeburn 7538:
1.27 raeburn 7539: if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
7540: foreach my $type (@{$curr_usercreation{'username_rule'}}) {
7541: if (!grep(/^\Q$type\E$/,@username_rule)) {
7542: push(@{$changes{'username_rule'}},$type);
7543: }
7544: }
7545: foreach my $type (@username_rule) {
7546: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
7547: push(@{$changes{'username_rule'}},$type);
7548: }
7549: }
7550: } else {
7551: push(@{$changes{'username_rule'}},@username_rule);
7552: }
7553:
1.32 raeburn 7554: if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
7555: foreach my $type (@{$curr_usercreation{'id_rule'}}) {
7556: if (!grep(/^\Q$type\E$/,@id_rule)) {
7557: push(@{$changes{'id_rule'}},$type);
7558: }
7559: }
7560: foreach my $type (@id_rule) {
7561: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
7562: push(@{$changes{'id_rule'}},$type);
7563: }
7564: }
7565: } else {
7566: push(@{$changes{'id_rule'}},@id_rule);
7567: }
7568:
1.43 raeburn 7569: my @authen_contexts = ('author','course','domain');
1.28 raeburn 7570: my @authtypes = ('int','krb4','krb5','loc');
7571: my %authhash;
1.43 raeburn 7572: foreach my $item (@authen_contexts) {
1.28 raeburn 7573: my @authallowed = &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
7574: foreach my $auth (@authtypes) {
7575: if (grep(/^\Q$auth\E$/,@authallowed)) {
7576: $authhash{$item}{$auth} = 1;
7577: } else {
7578: $authhash{$item}{$auth} = 0;
7579: }
7580: }
7581: }
7582: if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
1.43 raeburn 7583: foreach my $item (@authen_contexts) {
1.28 raeburn 7584: if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
7585: foreach my $auth (@authtypes) {
7586: if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
7587: push(@{$changes{'authtypes'}},$item);
7588: last;
7589: }
7590: }
7591: }
7592: }
7593: } else {
1.43 raeburn 7594: foreach my $item (@authen_contexts) {
1.28 raeburn 7595: push(@{$changes{'authtypes'}},$item);
7596: }
7597: }
7598:
1.224 raeburn 7599: $save_usercreate{'cancreate'}{'course'} = $cancreate{'course'};
7600: $save_usercreate{'cancreate'}{'author'} = $cancreate{'author'};
7601: $save_usercreate{'cancreate'}{'requestcrs'} = $cancreate{'requestcrs'};
7602: $save_usercreate{'id_rule'} = \@id_rule;
7603: $save_usercreate{'username_rule'} = \@username_rule,
7604: $save_usercreate{'authtypes'} = \%authhash;
7605:
1.27 raeburn 7606: my %usercreation_hash = (
1.224 raeburn 7607: usercreation => \%save_usercreate,
7608: );
1.27 raeburn 7609:
7610: my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
7611: $dom);
1.50 raeburn 7612:
1.224 raeburn 7613: if ($putresult eq 'ok') {
7614: if (keys(%changes) > 0) {
7615: $resulttext = &mt('Changes made:').'<ul>';
7616: if (ref($changes{'cancreate'}) eq 'ARRAY') {
7617: my %lt = &usercreation_types();
7618: foreach my $type (@{$changes{'cancreate'}}) {
7619: my $chgtext = $lt{$type}.', ';
7620: if ($cancreate{$type} eq 'none') {
7621: $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
7622: } elsif ($cancreate{$type} eq 'any') {
7623: $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
7624: } elsif ($cancreate{$type} eq 'official') {
7625: $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
7626: } elsif ($cancreate{$type} eq 'unofficial') {
7627: $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
7628: }
7629: $resulttext .= '<li>'.$chgtext.'</li>';
7630: }
7631: }
7632: if (ref($changes{'username_rule'}) eq 'ARRAY') {
7633: my ($rules,$ruleorder) =
7634: &Apache::lonnet::inst_userrules($dom,'username');
7635: my $chgtext = '<ul>';
7636: foreach my $type (@username_rule) {
7637: if (ref($rules->{$type}) eq 'HASH') {
7638: $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
7639: }
7640: }
7641: $chgtext .= '</ul>';
7642: if (@username_rule > 0) {
7643: $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
7644: } else {
7645: $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>';
7646: }
7647: }
7648: if (ref($changes{'id_rule'}) eq 'ARRAY') {
7649: my ($idrules,$idruleorder) =
7650: &Apache::lonnet::inst_userrules($dom,'id');
7651: my $chgtext = '<ul>';
7652: foreach my $type (@id_rule) {
7653: if (ref($idrules->{$type}) eq 'HASH') {
7654: $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
7655: }
7656: }
7657: $chgtext .= '</ul>';
7658: if (@id_rule > 0) {
7659: $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
7660: } else {
7661: $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
7662: }
7663: }
7664: my %authname = &authtype_names();
7665: my %context_title = &context_names();
7666: if (ref($changes{'authtypes'}) eq 'ARRAY') {
7667: my $chgtext = '<ul>';
7668: foreach my $type (@{$changes{'authtypes'}}) {
7669: my @allowed;
7670: $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
7671: foreach my $auth (@authtypes) {
7672: if ($authhash{$type}{$auth}) {
7673: push(@allowed,$authname{$auth});
7674: }
7675: }
7676: if (@allowed > 0) {
7677: $chgtext .= join(', ',@allowed).'</li>';
7678: } else {
7679: $chgtext .= &mt('none').'</li>';
7680: }
7681: }
7682: $chgtext .= '</ul>';
7683: $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
7684: $resulttext .= '</li>';
7685: }
7686: $resulttext .= '</ul>';
7687: } else {
7688: $resulttext = &mt('No changes made to user creation settings');
7689: }
7690: } else {
7691: $resulttext = '<span class="LC_error">'.
7692: &mt('An error occurred: [_1]',$putresult).'</span>';
7693: }
7694: if ($warningmsg ne '') {
7695: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
7696: }
7697: return $resulttext;
7698: }
7699:
7700: sub modify_selfcreation {
7701: my ($dom,%domconfig) = @_;
7702: my ($resulttext,$warningmsg,%curr_usercreation,%curr_usermodify,%changes,%cancreate);
7703: my (%save_usercreate,%save_usermodify);
1.228 raeburn 7704: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
7705: if (ref($types) eq 'ARRAY') {
7706: $usertypes->{'default'} = $othertitle;
7707: push(@{$types},'default');
7708: }
1.224 raeburn 7709: #
7710: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usercreation'}.
7711: #
7712: if (ref($domconfig{'usercreation'}) eq 'HASH') {
7713: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
7714: if ($key eq 'cancreate') {
7715: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
7716: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
7717: if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
7718: ($item eq 'captcha') || ($item eq 'recaptchakeys') ||
7719: ($item eq 'emailusername') || ($item eq 'notify')) {
7720: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
7721: } else {
7722: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
7723: }
7724: }
7725: }
7726: } elsif ($key eq 'email_rule') {
7727: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
7728: } else {
7729: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
7730: }
7731: }
7732: }
7733: #
7734: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usermodification'}.
7735: #
7736: if (ref($domconfig{'usermodification'}) eq 'HASH') {
7737: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
7738: if ($key eq 'selfcreate') {
7739: $curr_usermodify{$key} = $domconfig{'usermodification'}{$key};
7740: } else {
7741: $save_usermodify{$key} = $domconfig{'usermodification'}{$key};
7742: }
7743: }
7744: }
7745:
7746: my @contexts = ('selfcreate');
7747: @{$cancreate{'selfcreate'}} = ();
7748: %{$cancreate{'emailusername'}} = ();
7749: @{$cancreate{'statustocreate'}} = ();
1.50 raeburn 7750: my %selfcreatetypes = (
7751: sso => 'users authenticated by institutional single sign on',
7752: login => 'users authenticated by institutional log-in',
1.224 raeburn 7753: email => 'users who provide a valid e-mail address for use as username (automatic creation)',
7754: emailapproval => 'users who provide a valid e-mail address for use as username (queued for Domain Coordinator review)',
1.50 raeburn 7755: );
1.224 raeburn 7756: #
7757: # Populate $cancreate{'selfcreate'} array reference with types of user, for which self-creation of user accounts
7758: # is permitted.
7759: #
1.228 raeburn 7760: foreach my $item ('login','sso','email') {
1.224 raeburn 7761: if ($item eq 'email') {
7762: if ($env{'form.cancreate_email'} eq 'email') {
7763: push(@{$cancreate{'selfcreate'}},'email');
7764: } elsif ($env{'form.cancreate_email'} eq 'emailapproval') {
7765: push(@{$cancreate{'selfcreate'}},'emailapproval');
7766: }
7767: } else {
7768: if ($env{'form.cancreate_'.$item}) {
7769: push(@{$cancreate{'selfcreate'}},$item);
7770: }
7771: }
7772: }
7773: my (@email_rule,%userinfo,%savecaptcha);
7774: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
7775: #
1.228 raeburn 7776: # Populate $cancreate{'emailusername'}{$type} hash ref with information fields (if new user will provide data
7777: # value set to one), if self-creation with e-mail address permitted, where $type is user type: faculty, staff, student etc.
1.224 raeburn 7778: #
7779: if (($env{'form.cancreate_email'} eq 'email') || ($env{'form.cancreate_email'} eq 'emailapproval')) {
1.228 raeburn 7780: push(@contexts,'emailusername');
7781: if (ref($types) eq 'ARRAY') {
7782: foreach my $type (@{$types}) {
7783: if (ref($infofields) eq 'ARRAY') {
7784: foreach my $field (@{$infofields}) {
7785: if ($env{'form.canmodify_emailusername_'.$type.'_'.$field} =~ /^(required|optional)$/) {
7786: $cancreate{'emailusername'}{$type}{$field} = $1;
7787: }
7788: }
1.224 raeburn 7789: }
7790: }
7791: }
7792: #
7793: # Populate $cancreate{'notify'} hash ref with names of Domain Coordinators who are to be notified of
7794: # queued requests for self-creation of account using e-mail address as username
7795: #
7796:
7797: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.selfcreationnotifyapproval');
7798: @approvalnotify = sort(@approvalnotify);
7799: $cancreate{'notify'}{'approval'} = join(',',@approvalnotify);
7800: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
7801: if (ref($curr_usercreation{'cancreate'}{'notify'}) eq 'HASH') {
7802: if ($curr_usercreation{'cancreate'}{'notify'}{'approval'} ne $cancreate{'notify'}{'approval'}) {
7803: push(@{$changes{'cancreate'}},'notify');
7804: }
7805: } else {
7806: if ($cancreate{'notify'}{'approval'}) {
7807: push(@{$changes{'cancreate'}},'notify');
7808: }
7809: }
7810: } elsif ($cancreate{'notify'}{'approval'}) {
7811: push(@{$changes{'cancreate'}},'notify');
7812: }
7813:
7814: #
7815: # Retrieve rules (if any) governing types of e-mail address which may be used as a username
7816: #
7817: @email_rule = &Apache::loncommon::get_env_multiple('form.email_rule');
7818: &process_captcha('cancreate',\%changes,\%savecaptcha,$curr_usercreation{'cancreate'});
7819: if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
7820: if (@{$curr_usercreation{'email_rule'}} > 0) {
7821: foreach my $type (@{$curr_usercreation{'email_rule'}}) {
7822: if (!grep(/^\Q$type\E$/,@email_rule)) {
7823: push(@{$changes{'email_rule'}},$type);
7824: }
7825: }
7826: }
7827: if (@email_rule > 0) {
7828: foreach my $type (@email_rule) {
7829: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'email_rule'}})) {
7830: push(@{$changes{'email_rule'}},$type);
7831: }
7832: }
7833: }
7834: } elsif (@email_rule > 0) {
7835: push(@{$changes{'email_rule'}},@email_rule);
7836: }
7837: }
7838: #
7839: # Check if domain default is set appropriately, if selef-creation of accounts is to be available for
7840: # institutional log-in.
7841: #
7842: if (grep(/^login$/,@{$cancreate{'selfcreate'}})) {
7843: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
7844: if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) ||
7845: ($domdefaults{'auth_def'} eq 'localauth'))) {
7846: $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.').' '.
7847: &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.');
7848: }
7849: }
7850: my @fields = ('lastname','firstname','middlename','generation',
7851: 'permanentemail','id');
7852: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
7853: #
7854: # Where usernames may created for institutional log-in and/or institutional single sign on:
7855: # (a) populate $cancreate{'statustocreate'} array reference with institutional status types who
7856: # may self-create accounts
7857: # (b) populate $save_usermodify{'selfcreate'} hash reference with status types, and information fields
7858: # which the user may supply, if institutional data is unavailable.
7859: #
7860: if (($env{'form.cancreate_login'}) || ($env{'form.cancreate_sso'})) {
7861: if (ref($types) eq 'ARRAY') {
1.228 raeburn 7862: if (@{$types} > 1) {
1.224 raeburn 7863: @{$cancreate{'statustocreate'}} = &Apache::loncommon::get_env_multiple('form.statustocreate');
7864: push(@contexts,'statustocreate');
7865: } else {
7866: undef($cancreate{'statustocreate'});
7867: }
7868: foreach my $type (@{$types}) {
7869: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$type);
7870: foreach my $field (@fields) {
7871: if (grep(/^\Q$field\E$/,@modifiable)) {
7872: $save_usermodify{'selfcreate'}{$type}{$field} = 1;
7873: } else {
7874: $save_usermodify{'selfcreate'}{$type}{$field} = 0;
7875: }
7876: }
7877: }
7878: if (ref($curr_usermodify{'selfcreate'}) eq 'HASH') {
7879: foreach my $type (@{$types}) {
7880: if (ref($curr_usermodify{'selfcreate'}{$type}) eq 'HASH') {
7881: foreach my $field (@fields) {
7882: if ($save_usermodify{'selfcreate'}{$type}{$field} ne
7883: $curr_usermodify{'selfcreate'}{$type}{$field}) {
7884: push(@{$changes{'selfcreate'}},$type);
7885: last;
7886: }
7887: }
7888: }
7889: }
7890: } else {
7891: foreach my $type (@{$types}) {
7892: push(@{$changes{'selfcreate'}},$type);
7893: }
7894: }
7895: }
7896: }
7897: foreach my $item (@contexts) {
7898: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
7899: foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
7900: if (ref($cancreate{$item}) eq 'ARRAY') {
7901: if (!grep(/^$curr$/,@{$cancreate{$item}})) {
7902: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
7903: push(@{$changes{'cancreate'}},$item);
7904: }
7905: }
7906: }
7907: }
7908: if (ref($cancreate{$item}) eq 'ARRAY') {
7909: foreach my $type (@{$cancreate{$item}}) {
7910: if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
7911: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
7912: push(@{$changes{'cancreate'}},$item);
7913: }
7914: }
7915: }
7916: }
7917: } elsif (ref($curr_usercreation{'cancreate'}{$item}) eq 'HASH') {
7918: if (ref($cancreate{$item}) eq 'HASH') {
7919: foreach my $curr (keys(%{$curr_usercreation{'cancreate'}{$item}})) {
1.228 raeburn 7920: if (ref($curr_usercreation{'cancreate'}{$item}{$curr}) eq 'HASH') {
7921: foreach my $field (keys(%{$curr_usercreation{'cancreate'}{$item}{$curr}})) {
7922: unless ($curr_usercreation{'cancreate'}{$item}{$curr}{$field} eq $cancreate{$item}{$curr}{$field}) {
7923: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
7924: push(@{$changes{'cancreate'}},$item);
7925: }
7926: }
7927: }
7928: } else {
7929: if (!$cancreate{$item}{$curr}) {
7930: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
7931: push(@{$changes{'cancreate'}},$item);
7932: }
1.224 raeburn 7933: }
7934: }
7935: }
7936: foreach my $field (keys(%{$cancreate{$item}})) {
1.228 raeburn 7937: if (ref($cancreate{$item}{$field}) eq 'HASH') {
7938: foreach my $inner (keys(%{$cancreate{$item}{$field}})) {
7939: if (ref($curr_usercreation{'cancreate'}{$item}{$field}) eq 'HASH') {
7940: unless ($curr_usercreation{'cancreate'}{$item}{$field}{$inner} eq $cancreate{$item}{$field}{$inner}) {
7941: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
7942: push(@{$changes{'cancreate'}},$item);
7943: }
7944: }
7945: } else {
7946: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
7947: push(@{$changes{'cancreate'}},$item);
7948: }
7949: }
7950: }
7951: } else {
7952: if (!$curr_usercreation{'cancreate'}{$item}{$field}) {
7953: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
7954: push(@{$changes{'cancreate'}},$item);
7955: }
1.224 raeburn 7956: }
7957: }
7958: }
7959: }
7960: } elsif ($curr_usercreation{'cancreate'}{$item}) {
7961: if (ref($cancreate{$item}) eq 'ARRAY') {
7962: if (!grep(/^\Q$curr_usercreation{'cancreate'}{$item}\E$/,@{$cancreate{$item}})) {
7963: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
7964: push(@{$changes{'cancreate'}},$item);
7965: }
7966: }
7967: } elsif (ref($cancreate{$item}) eq 'HASH') {
7968: if (!$cancreate{$item}{$curr_usercreation{'cancreate'}{$item}}) {
7969: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
7970: push(@{$changes{'cancreate'}},$item);
7971: }
7972: }
7973: }
7974: } elsif ($item eq 'emailusername') {
1.228 raeburn 7975: if (ref($cancreate{$item}) eq 'HASH') {
7976: foreach my $type (keys(%{$cancreate{$item}})) {
7977: if (ref($cancreate{$item}{$type}) eq 'HASH') {
7978: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
7979: if ($cancreate{$item}{$type}{$field}) {
7980: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
7981: push(@{$changes{'cancreate'}},$item);
7982: }
7983: last;
7984: }
7985: }
7986: }
7987: }
1.224 raeburn 7988: }
7989: }
7990: }
7991: #
7992: # Populate %save_usercreate hash with updates to self-creation configuration.
7993: #
7994: $save_usercreate{'cancreate'}{'captcha'} = $savecaptcha{'captcha'};
7995: $save_usercreate{'cancreate'}{'recaptchakeys'} = $savecaptcha{'recaptchakeys'};
7996: $save_usercreate{'cancreate'}{'selfcreate'} = $cancreate{'selfcreate'};
7997: if (ref($cancreate{'notify'}) eq 'HASH') {
7998: $save_usercreate{'cancreate'}{'notify'} = $cancreate{'notify'};
7999: }
8000: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
8001: $save_usercreate{'cancreate'}{'statustocreate'} = $cancreate{'statustocreate'};
8002: }
8003: $save_usercreate{'cancreate'}{'emailusername'} = $cancreate{'emailusername'};
8004: $save_usercreate{'emailrule'} = \@email_rule;
8005:
8006: my %userconfig_hash = (
8007: usercreation => \%save_usercreate,
8008: usermodification => \%save_usermodify,
8009: );
8010: my $putresult = &Apache::lonnet::put_dom('configuration',\%userconfig_hash,
8011: $dom);
8012: #
8013: # Accumulate details of changes to domain cofiguration for self-creation of usernames in $resulttext
8014: #
1.27 raeburn 8015: if ($putresult eq 'ok') {
8016: if (keys(%changes) > 0) {
8017: $resulttext = &mt('Changes made:').'<ul>';
8018: if (ref($changes{'cancreate'}) eq 'ARRAY') {
1.224 raeburn 8019: my %lt = &selfcreation_types();
1.34 raeburn 8020: foreach my $type (@{$changes{'cancreate'}}) {
1.100 raeburn 8021: my $chgtext;
1.45 raeburn 8022: if ($type eq 'selfcreate') {
1.50 raeburn 8023: if (@{$cancreate{$type}} == 0) {
1.224 raeburn 8024: $chgtext .= &mt('Self creation of a new user account is not permitted.');
1.50 raeburn 8025: } else {
1.224 raeburn 8026: $chgtext .= &mt('Self-creation of a new account is permitted for:').
8027: '<ul>';
1.50 raeburn 8028: foreach my $case (@{$cancreate{$type}}) {
8029: $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
8030: }
8031: $chgtext .= '</ul>';
1.100 raeburn 8032: if (ref($cancreate{$type}) eq 'ARRAY') {
8033: if (grep(/^(login|sso)$/,@{$cancreate{$type}})) {
8034: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
8035: if (@{$cancreate{'statustocreate'}} == 0) {
1.224 raeburn 8036: $chgtext .= '<br />'.
8037: '<span class="LC_warning">'.
8038: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
8039: '</span>';
1.100 raeburn 8040: }
8041: }
8042: }
8043: }
1.43 raeburn 8044: }
1.93 raeburn 8045: } elsif ($type eq 'statustocreate') {
1.96 raeburn 8046: if ((ref($cancreate{'selfcreate'}) eq 'ARRAY') &&
8047: (ref($cancreate{'statustocreate'}) eq 'ARRAY')) {
8048: if (@{$cancreate{'selfcreate'}} > 0) {
8049: if (@{$cancreate{'statustocreate'}} == 0) {
1.100 raeburn 8050: $chgtext .= &mt("Institutional affiliations permitted to create accounts set to 'None'.");
1.96 raeburn 8051: if (!grep(/^email$/,@{$cancreate{'selfcreate'}})) {
1.224 raeburn 8052: $chgtext .= '<br />'.
8053: '<span class="LC_warning">'.
8054: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
8055: '</span>';
8056: }
1.96 raeburn 8057: } elsif (ref($usertypes) eq 'HASH') {
8058: if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.100 raeburn 8059: $chgtext .= &mt('Creation of a new account for an institutional user is restricted to the following institutional affiliation(s):');
8060: } else {
8061: $chgtext .= &mt('Institutional affiliations permitted to create accounts with institutional authentication were set as follows:');
8062: }
8063: $chgtext .= '<ul>';
8064: foreach my $case (@{$cancreate{$type}}) {
8065: if ($case eq 'default') {
8066: $chgtext .= '<li>'.$othertitle.'</li>';
8067: } else {
8068: $chgtext .= '<li>'.$usertypes->{$case}.'</li>';
1.93 raeburn 8069: }
8070: }
1.100 raeburn 8071: $chgtext .= '</ul>';
8072: if (!grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.224 raeburn 8073: $chgtext .= '<br /><span class="LC_warning">'.
8074: &mt('However, users authenticated by institutional login/single sign on are not currently permitted to create accounts.').
8075: '</span>';
1.100 raeburn 8076: }
8077: }
8078: } else {
8079: if (@{$cancreate{$type}} == 0) {
8080: $chgtext .= &mt("Institutional affiliations permitted to create accounts were set to 'none'.");
8081: } else {
8082: $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 8083: }
8084: }
8085: }
1.165 raeburn 8086: } elsif ($type eq 'captcha') {
1.224 raeburn 8087: if ($savecaptcha{$type} eq 'notused') {
1.165 raeburn 8088: $chgtext .= &mt('No CAPTCHA validation in use for self-creation screen.');
8089: } else {
8090: my %captchas = &captcha_phrases();
1.224 raeburn 8091: if ($captchas{$savecaptcha{$type}}) {
8092: $chgtext .= &mt("Validation for self-creation screen set to $captchas{$savecaptcha{$type}}.");
1.165 raeburn 8093: } else {
1.210 raeburn 8094: $chgtext .= &mt('Validation for self-creation screen set to unknown type.');
1.165 raeburn 8095: }
8096: }
8097: } elsif ($type eq 'recaptchakeys') {
8098: my ($privkey,$pubkey);
1.224 raeburn 8099: if (ref($savecaptcha{$type}) eq 'HASH') {
8100: $pubkey = $savecaptcha{$type}{'public'};
8101: $privkey = $savecaptcha{$type}{'private'};
1.165 raeburn 8102: }
8103: $chgtext .= &mt('ReCAPTCHA keys changes').'<ul>';
8104: if (!$pubkey) {
8105: $chgtext .= '<li>'.&mt('Public key deleted').'</li>';
8106: } else {
8107: $chgtext .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
8108: }
8109: if (!$privkey) {
8110: $chgtext .= '<li>'.&mt('Private key deleted').'</li>';
8111: } else {
8112: $chgtext .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
8113: }
8114: $chgtext .= '</ul>';
1.224 raeburn 8115: } elsif ($type eq 'emailusername') {
8116: if (ref($cancreate{'emailusername'}) eq 'HASH') {
1.228 raeburn 8117: if (ref($types) eq 'ARRAY') {
8118: foreach my $type (@{$types}) {
8119: if (ref($cancreate{'emailusername'}{$type}) eq 'HASH') {
8120: if (keys(%{$cancreate{'emailusername'}{$type}}) > 0) {
8121: $chgtext .= &mt('When self-creating account with e-mail as username, the following information will be provided by [_1]:',$usertypes->{$type}).
8122: '<ul>';
8123: foreach my $field (@{$infofields}) {
8124: if ($cancreate{'emailusername'}{$type}{$field}) {
8125: $chgtext .= '<li>'.$infotitles->{$field}.'</li>';
8126: }
8127: }
8128: }
8129: $chgtext .= '</ul>';
8130: } else {
8131: $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 8132: }
8133: }
8134: }
8135: }
8136: } elsif ($type eq 'notify') {
8137: $chgtext = &mt('No Domain Coordinators will receive notification of username requests requiring approval.');
8138: if (ref($changes{'cancreate'}) eq 'ARRAY') {
8139: if ((grep(/^notify$/,@{$changes{'cancreate'}})) && (ref($cancreate{'notify'}) eq 'HASH')) {
8140: if ($cancreate{'notify'}{'approval'}) {
8141: $chgtext = &mt('Notification of username requests requiring approval will be sent to: ').$cancreate{'notify'}{'approval'};
8142: }
8143: }
1.43 raeburn 8144: }
1.34 raeburn 8145: }
1.224 raeburn 8146: if ($chgtext) {
8147: $resulttext .= '<li>'.$chgtext.'</li>';
1.32 raeburn 8148: }
8149: }
8150: }
1.43 raeburn 8151: if (ref($changes{'email_rule'}) eq 'ARRAY') {
8152: my ($emailrules,$emailruleorder) =
8153: &Apache::lonnet::inst_userrules($dom,'email');
8154: my $chgtext = '<ul>';
8155: foreach my $type (@email_rule) {
8156: if (ref($emailrules->{$type}) eq 'HASH') {
8157: $chgtext .= '<li>'.$emailrules->{$type}{'name'}.'</li>';
8158: }
8159: }
8160: $chgtext .= '</ul>';
8161: if (@email_rule > 0) {
1.224 raeburn 8162: $resulttext .= '<li>'.
8163: &mt('Accounts may not be created by users self-enrolling with e-mail addresses of the following types: ').
8164: $chgtext.
8165: '</li>';
1.43 raeburn 8166: } else {
1.224 raeburn 8167: $resulttext .= '<li>'.
8168: &mt('There are now no restrictions on e-mail addresses which may be used as a username when self-enrolling.').
8169: '</li>';
1.43 raeburn 8170: }
8171: }
1.224 raeburn 8172: if (ref($changes{'selfcreate'}) eq 'ARRAY') {
8173: $resulttext .= '<li>'.&mt('When self-creating institutional account:').'<ul>';
8174: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
8175: foreach my $type (@{$changes{'selfcreate'}}) {
8176: my $typename = $type;
8177: if (ref($usertypes) eq 'HASH') {
8178: if ($usertypes->{$type} ne '') {
8179: $typename = $usertypes->{$type};
8180: }
8181: }
8182: my @modifiable;
8183: $resulttext .= '<li>'.
8184: &mt('Self-creation of account by users with status: [_1]',
8185: '<span class="LC_cusr_emph">'.$typename.'</span>').
8186: ' - '.&mt('modifiable fields (if institutional data blank): ');
8187: foreach my $field (@fields) {
8188: if ($save_usermodify{'selfcreate'}{$type}{$field}) {
8189: push(@modifiable,'<b>'.$fieldtitles{$field}.'</b>');
1.28 raeburn 8190: }
8191: }
1.224 raeburn 8192: if (@modifiable > 0) {
8193: $resulttext .= join(', ',@modifiable);
1.43 raeburn 8194: } else {
1.224 raeburn 8195: $resulttext .= &mt('none');
1.43 raeburn 8196: }
1.224 raeburn 8197: $resulttext .= '</li>';
1.28 raeburn 8198: }
1.224 raeburn 8199: $resulttext .= '</ul></li>';
1.28 raeburn 8200: }
1.27 raeburn 8201: $resulttext .= '</ul>';
8202: } else {
1.224 raeburn 8203: $resulttext = &mt('No changes made to self-creation settings');
1.27 raeburn 8204: }
8205: } else {
8206: $resulttext = '<span class="LC_error">'.
1.23 raeburn 8207: &mt('An error occurred: [_1]',$putresult).'</span>';
8208: }
1.43 raeburn 8209: if ($warningmsg ne '') {
8210: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
8211: }
1.23 raeburn 8212: return $resulttext;
8213: }
8214:
1.165 raeburn 8215: sub process_captcha {
8216: my ($container,$changes,$newsettings,$current) = @_;
8217: return unless ((ref($changes) eq 'HASH') && (ref($newsettings) eq 'HASH') || (ref($current) eq 'HASH'));
8218: $newsettings->{'captcha'} = $env{'form.'.$container.'_captcha'};
8219: unless ($newsettings->{'captcha'} eq 'recaptcha' || $newsettings->{'captcha'} eq 'notused') {
8220: $newsettings->{'captcha'} = 'original';
8221: }
8222: if ($current->{'captcha'} ne $newsettings->{'captcha'}) {
1.210 raeburn 8223: if ($container eq 'cancreate') {
1.169 raeburn 8224: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
8225: push(@{$changes->{'cancreate'}},'captcha');
8226: } elsif (!defined($changes->{'cancreate'})) {
8227: $changes->{'cancreate'} = ['captcha'];
8228: }
8229: } else {
8230: $changes->{'captcha'} = 1;
1.165 raeburn 8231: }
8232: }
8233: my ($newpub,$newpriv,$currpub,$currpriv);
8234: if ($newsettings->{'captcha'} eq 'recaptcha') {
8235: $newpub = $env{'form.'.$container.'_recaptchapub'};
8236: $newpriv = $env{'form.'.$container.'_recaptchapriv'};
1.169 raeburn 8237: $newpub =~ s/\W//g;
8238: $newpriv =~ s/\W//g;
8239: $newsettings->{'recaptchakeys'} = {
8240: public => $newpub,
8241: private => $newpriv,
8242: };
1.165 raeburn 8243: }
8244: if (ref($current->{'recaptchakeys'}) eq 'HASH') {
8245: $currpub = $current->{'recaptchakeys'}{'public'};
8246: $currpriv = $current->{'recaptchakeys'}{'private'};
1.179 raeburn 8247: unless ($newsettings->{'captcha'} eq 'recaptcha') {
8248: $newsettings->{'recaptchakeys'} = {
8249: public => '',
8250: private => '',
8251: }
8252: }
1.165 raeburn 8253: }
8254: if (($newpub ne $currpub) || ($newpriv ne $currpriv)) {
1.169 raeburn 8255: if ($container eq 'cancreate') {
8256: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
8257: push(@{$changes->{'cancreate'}},'recaptchakeys');
8258: } elsif (!defined($changes->{'cancreate'})) {
8259: $changes->{'cancreate'} = ['recaptchakeys'];
8260: }
8261: } else {
1.210 raeburn 8262: $changes->{'recaptchakeys'} = 1;
1.165 raeburn 8263: }
8264: }
8265: return;
8266: }
8267:
1.33 raeburn 8268: sub modify_usermodification {
8269: my ($dom,%domconfig) = @_;
1.224 raeburn 8270: my ($resulttext,%curr_usermodification,%changes,%modifyhash);
1.33 raeburn 8271: if (ref($domconfig{'usermodification'}) eq 'HASH') {
8272: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
1.224 raeburn 8273: if ($key eq 'selfcreate') {
8274: $modifyhash{$key} = $domconfig{'usermodification'}{$key};
8275: } else {
8276: $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
8277: }
1.33 raeburn 8278: }
8279: }
1.224 raeburn 8280: my @contexts = ('author','course');
1.33 raeburn 8281: my %context_title = (
8282: author => 'In author context',
8283: course => 'In course context',
8284: );
8285: my @fields = ('lastname','firstname','middlename','generation',
8286: 'permanentemail','id');
8287: my %roles = (
8288: author => ['ca','aa'],
8289: course => ['st','ep','ta','in','cr'],
8290: );
8291: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
8292: foreach my $context (@contexts) {
8293: foreach my $role (@{$roles{$context}}) {
8294: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$role);
8295: foreach my $item (@fields) {
8296: if (grep(/^\Q$item\E$/,@modifiable)) {
8297: $modifyhash{$context}{$role}{$item} = 1;
8298: } else {
8299: $modifyhash{$context}{$role}{$item} = 0;
8300: }
8301: }
8302: }
8303: if (ref($curr_usermodification{$context}) eq 'HASH') {
8304: foreach my $role (@{$roles{$context}}) {
8305: if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
8306: foreach my $field (@fields) {
8307: if ($modifyhash{$context}{$role}{$field} ne
8308: $curr_usermodification{$context}{$role}{$field}) {
8309: push(@{$changes{$context}},$role);
8310: last;
8311: }
8312: }
8313: }
8314: }
8315: } else {
8316: foreach my $context (@contexts) {
8317: foreach my $role (@{$roles{$context}}) {
8318: push(@{$changes{$context}},$role);
8319: }
8320: }
8321: }
8322: }
8323: my %usermodification_hash = (
8324: usermodification => \%modifyhash,
8325: );
8326: my $putresult = &Apache::lonnet::put_dom('configuration',
8327: \%usermodification_hash,$dom);
8328: if ($putresult eq 'ok') {
8329: if (keys(%changes) > 0) {
8330: $resulttext = &mt('Changes made: ').'<ul>';
8331: foreach my $context (@contexts) {
8332: if (ref($changes{$context}) eq 'ARRAY') {
8333: $resulttext .= '<li>'.$context_title{$context}.':<ul>';
8334: if (ref($changes{$context}) eq 'ARRAY') {
8335: foreach my $role (@{$changes{$context}}) {
8336: my $rolename;
1.224 raeburn 8337: if ($role eq 'cr') {
8338: $rolename = &mt('Custom');
1.33 raeburn 8339: } else {
1.224 raeburn 8340: $rolename = &Apache::lonnet::plaintext($role);
1.33 raeburn 8341: }
8342: my @modifiable;
1.224 raeburn 8343: $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
1.33 raeburn 8344: foreach my $field (@fields) {
8345: if ($modifyhash{$context}{$role}{$field}) {
8346: push(@modifiable,$fieldtitles{$field});
8347: }
8348: }
8349: if (@modifiable > 0) {
8350: $resulttext .= join(', ',@modifiable);
8351: } else {
8352: $resulttext .= &mt('none');
8353: }
8354: $resulttext .= '</li>';
8355: }
8356: $resulttext .= '</ul></li>';
8357: }
8358: }
8359: }
8360: $resulttext .= '</ul>';
8361: } else {
8362: $resulttext = &mt('No changes made to user modification settings');
8363: }
8364: } else {
8365: $resulttext = '<span class="LC_error">'.
8366: &mt('An error occurred: [_1]',$putresult).'</span>';
8367: }
8368: return $resulttext;
8369: }
8370:
1.43 raeburn 8371: sub modify_defaults {
1.212 raeburn 8372: my ($dom,$lastactref,%domconfig) = @_;
1.43 raeburn 8373: my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
1.212 raeburn 8374: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.141 raeburn 8375: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def','portal_def');
1.43 raeburn 8376: my @authtypes = ('internal','krb4','krb5','localauth');
8377: foreach my $item (@items) {
8378: $newvalues{$item} = $env{'form.'.$item};
8379: if ($item eq 'auth_def') {
8380: if ($newvalues{$item} ne '') {
8381: if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
8382: push(@errors,$item);
8383: }
8384: }
8385: } elsif ($item eq 'lang_def') {
8386: if ($newvalues{$item} ne '') {
8387: if ($newvalues{$item} =~ /^(\w+)/) {
8388: my $langcode = $1;
1.103 raeburn 8389: if ($langcode ne 'x_chef') {
8390: if (code2language($langcode) eq '') {
8391: push(@errors,$item);
8392: }
1.43 raeburn 8393: }
8394: } else {
8395: push(@errors,$item);
8396: }
8397: }
1.54 raeburn 8398: } elsif ($item eq 'timezone_def') {
8399: if ($newvalues{$item} ne '') {
1.62 raeburn 8400: if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
1.54 raeburn 8401: push(@errors,$item);
8402: }
8403: }
1.68 raeburn 8404: } elsif ($item eq 'datelocale_def') {
8405: if ($newvalues{$item} ne '') {
8406: my @datelocale_ids = DateTime::Locale->ids();
8407: if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
8408: push(@errors,$item);
8409: }
8410: }
1.141 raeburn 8411: } elsif ($item eq 'portal_def') {
8412: if ($newvalues{$item} ne '') {
8413: 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])\/?$/) {
8414: push(@errors,$item);
8415: }
8416: }
1.43 raeburn 8417: }
8418: if (grep(/^\Q$item\E$/,@errors)) {
8419: $newvalues{$item} = $domdefaults{$item};
8420: } elsif ($domdefaults{$item} ne $newvalues{$item}) {
8421: $changes{$item} = 1;
8422: }
1.72 raeburn 8423: $domdefaults{$item} = $newvalues{$item};
1.43 raeburn 8424: }
8425: my %defaults_hash = (
1.72 raeburn 8426: defaults => \%newvalues,
8427: );
1.43 raeburn 8428: my $title = &defaults_titles();
8429: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
8430: $dom);
8431: if ($putresult eq 'ok') {
8432: if (keys(%changes) > 0) {
8433: $resulttext = &mt('Changes made:').'<ul>';
1.212 raeburn 8434: my $version = &Apache::lonnet::get_server_loncaparev($dom);
1.43 raeburn 8435: 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";
8436: foreach my $item (sort(keys(%changes))) {
8437: my $value = $env{'form.'.$item};
8438: if ($value eq '') {
8439: $value = &mt('none');
8440: } elsif ($item eq 'auth_def') {
8441: my %authnames = &authtype_names();
8442: my %shortauth = (
8443: internal => 'int',
8444: krb4 => 'krb4',
8445: krb5 => 'krb5',
8446: localauth => 'loc',
8447: );
8448: $value = $authnames{$shortauth{$value}};
8449: }
8450: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
8451: $mailmsgtext .= "$title->{$item} set to $value\n";
8452: }
8453: $resulttext .= '</ul>';
8454: $mailmsgtext .= "\n";
8455: my $cachetime = 24*60*60;
1.72 raeburn 8456: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 8457: if (ref($lastactref) eq 'HASH') {
8458: $lastactref->{'domdefaults'} = 1;
8459: }
1.68 raeburn 8460: if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
1.203 raeburn 8461: my $notify = 1;
8462: if (ref($domconfig{'contacts'}) eq 'HASH') {
8463: if ($domconfig{'contacts'}{'reportupdates'} == 0) {
8464: $notify = 0;
8465: }
8466: }
8467: if ($notify) {
8468: &Apache::lonmsg::sendemail('installrecord@loncapa.org',
8469: "LON-CAPA Domain Settings Change - $dom",
8470: $mailmsgtext);
8471: }
1.54 raeburn 8472: }
1.43 raeburn 8473: } else {
1.54 raeburn 8474: $resulttext = &mt('No changes made to default authentication/language/timezone settings');
1.43 raeburn 8475: }
8476: } else {
8477: $resulttext = '<span class="LC_error">'.
8478: &mt('An error occurred: [_1]',$putresult).'</span>';
8479: }
8480: if (@errors > 0) {
8481: $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
8482: foreach my $item (@errors) {
8483: $resulttext .= ' "'.$title->{$item}.'",';
8484: }
8485: $resulttext =~ s/,$//;
8486: }
8487: return $resulttext;
8488: }
8489:
1.46 raeburn 8490: sub modify_scantron {
1.205 raeburn 8491: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.46 raeburn 8492: my ($resulttext,%confhash,%changes,$errors);
8493: my $custom = 'custom.tab';
8494: my $default = 'default.tab';
8495: my $servadm = $r->dir_config('lonAdmEMail');
8496: my ($configuserok,$author_ok,$switchserver) =
8497: &config_check($dom,$confname,$servadm);
8498: if ($env{'form.scantronformat.filename'} ne '') {
8499: my $error;
8500: if ($configuserok eq 'ok') {
8501: if ($switchserver) {
1.130 raeburn 8502: $error = &mt("Upload of bubblesheet format file is not permitted to this server: [_1]",$switchserver);
1.46 raeburn 8503: } else {
8504: if ($author_ok eq 'ok') {
8505: my ($result,$scantronurl) =
8506: &publishlogo($r,'upload','scantronformat',$dom,
8507: $confname,'scantron','','',$custom);
8508: if ($result eq 'ok') {
8509: $confhash{'scantron'}{'scantronformat'} = $scantronurl;
1.48 raeburn 8510: $changes{'scantronformat'} = 1;
1.46 raeburn 8511: } else {
8512: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
8513: }
8514: } else {
8515: $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);
8516: }
8517: }
8518: } else {
8519: $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);
8520: }
8521: if ($error) {
8522: &Apache::lonnet::logthis($error);
8523: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
8524: }
8525: }
1.48 raeburn 8526: if (ref($domconfig{'scantron'}) eq 'HASH') {
8527: if ($domconfig{'scantron'}{'scantronformat'} ne '') {
8528: if ($env{'form.scantronformat_del'}) {
8529: $confhash{'scantron'}{'scantronformat'} = '';
8530: $changes{'scantronformat'} = 1;
1.46 raeburn 8531: }
8532: }
8533: }
8534: if (keys(%confhash) > 0) {
8535: my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
8536: $dom);
8537: if ($putresult eq 'ok') {
8538: if (keys(%changes) > 0) {
1.48 raeburn 8539: if (ref($confhash{'scantron'}) eq 'HASH') {
8540: $resulttext = &mt('Changes made:').'<ul>';
8541: if ($confhash{'scantron'}{'scantronformat'} eq '') {
1.130 raeburn 8542: $resulttext .= '<li>'.&mt('[_1] bubblesheet format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
1.48 raeburn 8543: } else {
1.130 raeburn 8544: $resulttext .= '<li>'.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
1.46 raeburn 8545: }
1.48 raeburn 8546: $resulttext .= '</ul>';
8547: } else {
1.130 raeburn 8548: $resulttext = &mt('Changes made to bubblesheet format file.');
1.46 raeburn 8549: }
8550: $resulttext .= '</ul>';
8551: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 8552: if (ref($lastactref) eq 'HASH') {
8553: $lastactref->{'domainconfig'} = 1;
8554: }
1.46 raeburn 8555: } else {
1.130 raeburn 8556: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 8557: }
8558: } else {
8559: $resulttext = '<span class="LC_error">'.
8560: &mt('An error occurred: [_1]',$putresult).'</span>';
8561: }
8562: } else {
1.130 raeburn 8563: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 8564: }
8565: if ($errors) {
8566: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
8567: $errors.'</ul>';
8568: }
8569: return $resulttext;
8570: }
8571:
1.48 raeburn 8572: sub modify_coursecategories {
8573: my ($dom,%domconfig) = @_;
1.57 raeburn 8574: my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
8575: $cathash);
1.48 raeburn 8576: my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
1.55 raeburn 8577: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
1.57 raeburn 8578: $cathash = $domconfig{'coursecategories'}{'cats'};
8579: if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
8580: $changes{'togglecats'} = 1;
8581: $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
8582: }
8583: if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
8584: $changes{'categorize'} = 1;
8585: $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
8586: }
1.120 raeburn 8587: if ($domconfig{'coursecategories'}{'togglecatscomm'} ne $env{'form.togglecatscomm'}) {
8588: $changes{'togglecatscomm'} = 1;
8589: $domconfig{'coursecategories'}{'togglecatscomm'} = $env{'form.togglecatscomm'};
8590: }
8591: if ($domconfig{'coursecategories'}{'categorizecomm'} ne $env{'form.categorizecomm'}) {
8592: $changes{'categorizecomm'} = 1;
8593: $domconfig{'coursecategories'}{'categorizecomm'} = $env{'form.categorizecomm'};
8594: }
1.57 raeburn 8595: } else {
8596: $changes{'togglecats'} = 1;
8597: $changes{'categorize'} = 1;
1.124 raeburn 8598: $changes{'togglecatscomm'} = 1;
8599: $changes{'categorizecomm'} = 1;
1.87 raeburn 8600: $domconfig{'coursecategories'} = {
8601: togglecats => $env{'form.togglecats'},
8602: categorize => $env{'form.categorize'},
1.124 raeburn 8603: togglecatscomm => $env{'form.togglecatscomm'},
8604: categorizecomm => $env{'form.categorizecomm'},
1.120 raeburn 8605: };
1.57 raeburn 8606: }
8607: if (ref($cathash) eq 'HASH') {
8608: if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '') && ($env{'form.instcode'} == 0)) {
1.55 raeburn 8609: push (@deletecategory,'instcode::0');
8610: }
1.120 raeburn 8611: if (($domconfig{'coursecategories'}{'cats'}{'communities::0'} ne '') && ($env{'form.communities'} == 0)) {
8612: push(@deletecategory,'communities::0');
8613: }
1.48 raeburn 8614: }
1.57 raeburn 8615: my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
8616: if (ref($cathash) eq 'HASH') {
1.48 raeburn 8617: if (@deletecategory > 0) {
8618: #FIXME Need to remove category from all courses using a deleted category
1.57 raeburn 8619: &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
1.48 raeburn 8620: foreach my $item (@deletecategory) {
1.57 raeburn 8621: if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
8622: delete($domconfig{'coursecategories'}{'cats'}{$item});
1.48 raeburn 8623: $deletions{$item} = 1;
1.57 raeburn 8624: &recurse_cat_deletes($item,$cathash,\%deletions);
1.48 raeburn 8625: }
8626: }
8627: }
1.57 raeburn 8628: foreach my $item (keys(%{$cathash})) {
1.48 raeburn 8629: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
1.57 raeburn 8630: if ($cathash->{$item} ne $env{'form.'.$item}) {
1.48 raeburn 8631: $reorderings{$item} = 1;
1.57 raeburn 8632: $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
1.48 raeburn 8633: }
8634: if ($env{'form.addcategory_name_'.$item} ne '') {
8635: my $newcat = $env{'form.addcategory_name_'.$item};
8636: my $newdepth = $depth+1;
8637: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 8638: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
1.48 raeburn 8639: $adds{$newitem} = 1;
8640: }
8641: if ($env{'form.subcat_'.$item} ne '') {
8642: my $newcat = $env{'form.subcat_'.$item};
8643: my $newdepth = $depth+1;
8644: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 8645: $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
1.48 raeburn 8646: $adds{$newitem} = 1;
8647: }
8648: }
8649: }
8650: if ($env{'form.instcode'} eq '1') {
1.57 raeburn 8651: if (ref($cathash) eq 'HASH') {
1.48 raeburn 8652: my $newitem = 'instcode::0';
1.57 raeburn 8653: if ($cathash->{$newitem} eq '') {
8654: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 8655: $adds{$newitem} = 1;
8656: }
8657: } else {
8658: my $newitem = 'instcode::0';
1.57 raeburn 8659: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 8660: $adds{$newitem} = 1;
8661: }
8662: }
1.120 raeburn 8663: if ($env{'form.communities'} eq '1') {
8664: if (ref($cathash) eq 'HASH') {
8665: my $newitem = 'communities::0';
8666: if ($cathash->{$newitem} eq '') {
8667: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
8668: $adds{$newitem} = 1;
8669: }
8670: } else {
8671: my $newitem = 'communities::0';
8672: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
8673: $adds{$newitem} = 1;
8674: }
8675: }
1.48 raeburn 8676: if ($env{'form.addcategory_name'} ne '') {
1.120 raeburn 8677: if (($env{'form.addcategory_name'} ne 'instcode') &&
8678: ($env{'form.addcategory_name'} ne 'communities')) {
8679: my $newitem = &escape($env{'form.addcategory_name'}).'::0';
8680: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
8681: $adds{$newitem} = 1;
8682: }
1.48 raeburn 8683: }
1.57 raeburn 8684: my $putresult;
1.48 raeburn 8685: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
8686: if (keys(%deletions) > 0) {
8687: foreach my $key (keys(%deletions)) {
8688: if ($predelallitems{$key} ne '') {
8689: $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
8690: }
8691: }
8692: }
8693: my (@chkcats,@chktrails,%chkallitems);
1.57 raeburn 8694: &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
1.48 raeburn 8695: if (ref($chkcats[0]) eq 'ARRAY') {
8696: my $depth = 0;
8697: my $chg = 0;
8698: for (my $i=0; $i<@{$chkcats[0]}; $i++) {
8699: my $name = $chkcats[0][$i];
8700: my $item;
8701: if ($name eq '') {
8702: $chg ++;
8703: } else {
8704: $item = &escape($name).'::0';
8705: if ($chg) {
1.57 raeburn 8706: $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
1.48 raeburn 8707: }
8708: $depth ++;
1.57 raeburn 8709: &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
1.48 raeburn 8710: $depth --;
8711: }
8712: }
8713: }
1.57 raeburn 8714: }
8715: if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
8716: $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
1.48 raeburn 8717: if ($putresult eq 'ok') {
1.57 raeburn 8718: my %title = (
1.120 raeburn 8719: togglecats => 'Show/Hide a course in catalog',
8720: categorize => 'Assign a category to a course',
8721: togglecatscomm => 'Show/Hide a community in catalog',
8722: categorizecomm => 'Assign a category to a community',
1.57 raeburn 8723: );
8724: my %level = (
1.120 raeburn 8725: dom => 'set in Domain ("Modify Course/Community")',
8726: crs => 'set in Course ("Course Configuration")',
8727: comm => 'set in Community ("Community Configuration")',
1.57 raeburn 8728: );
1.48 raeburn 8729: $resulttext = &mt('Changes made:').'<ul>';
1.57 raeburn 8730: if ($changes{'togglecats'}) {
8731: $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>';
8732: }
8733: if ($changes{'categorize'}) {
8734: $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
1.48 raeburn 8735: }
1.120 raeburn 8736: if ($changes{'togglecatscomm'}) {
8737: $resulttext .= '<li>'.&mt("$title{'togglecatscomm'} $level{$env{'form.togglecatscomm'}}").'</li>';
8738: }
8739: if ($changes{'categorizecomm'}) {
8740: $resulttext .= '<li>'.&mt("$title{'categorizecomm'} $level{$env{'form.categorizecomm'}}").'</li>';
8741: }
1.57 raeburn 8742: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
8743: my $cathash;
8744: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
8745: $cathash = $domconfig{'coursecategories'}{'cats'};
8746: } else {
8747: $cathash = {};
8748: }
8749: my (@cats,@trails,%allitems);
8750: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
8751: if (keys(%deletions) > 0) {
8752: $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
8753: foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) {
8754: $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
8755: }
8756: $resulttext .= '</ul></li>';
8757: }
8758: if (keys(%reorderings) > 0) {
8759: my %sort_by_trail;
8760: $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
8761: foreach my $key (keys(%reorderings)) {
8762: if ($allitems{$key} ne '') {
8763: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
8764: }
1.48 raeburn 8765: }
1.57 raeburn 8766: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
8767: $resulttext .= '<li>'.$trails[$trail].'</li>';
8768: }
8769: $resulttext .= '</ul></li>';
1.48 raeburn 8770: }
1.57 raeburn 8771: if (keys(%adds) > 0) {
8772: my %sort_by_trail;
8773: $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
8774: foreach my $key (keys(%adds)) {
8775: if ($allitems{$key} ne '') {
8776: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
8777: }
8778: }
8779: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
8780: $resulttext .= '<li>'.$trails[$trail].'</li>';
1.48 raeburn 8781: }
1.57 raeburn 8782: $resulttext .= '</ul></li>';
1.48 raeburn 8783: }
8784: }
8785: $resulttext .= '</ul>';
8786: } else {
8787: $resulttext = '<span class="LC_error">'.
1.57 raeburn 8788: &mt('An error occurred: [_1]',$putresult).'</span>';
1.48 raeburn 8789: }
8790: } else {
1.120 raeburn 8791: $resulttext = &mt('No changes made to course and community categories');
1.48 raeburn 8792: }
8793: return $resulttext;
8794: }
8795:
1.69 raeburn 8796: sub modify_serverstatuses {
8797: my ($dom,%domconfig) = @_;
8798: my ($resulttext,%changes,%currserverstatus,%newserverstatus);
8799: if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
8800: %currserverstatus = %{$domconfig{'serverstatuses'}};
8801: }
8802: my @pages = &serverstatus_pages();
8803: foreach my $type (@pages) {
8804: $newserverstatus{$type}{'namedusers'} = '';
8805: $newserverstatus{$type}{'machines'} = '';
8806: if (defined($env{'form.'.$type.'_namedusers'})) {
8807: my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
8808: my @okusers;
8809: foreach my $user (@users) {
8810: my ($uname,$udom) = split(/:/,$user);
8811: if (($udom =~ /^$match_domain$/) &&
8812: (&Apache::lonnet::domain($udom)) &&
8813: ($uname =~ /^$match_username$/)) {
8814: if (!grep(/^\Q$user\E/,@okusers)) {
8815: push(@okusers,$user);
8816: }
8817: }
8818: }
8819: if (@okusers > 0) {
8820: @okusers = sort(@okusers);
8821: $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
8822: }
8823: }
8824: if (defined($env{'form.'.$type.'_machines'})) {
8825: my @machines = split(/,/,$env{'form.'.$type.'_machines'});
8826: my @okmachines;
8827: foreach my $ip (@machines) {
8828: my @parts = split(/\./,$ip);
8829: next if (@parts < 4);
8830: my $badip = 0;
8831: for (my $i=0; $i<4; $i++) {
8832: if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
8833: $badip = 1;
8834: last;
8835: }
8836: }
8837: if (!$badip) {
8838: push(@okmachines,$ip);
8839: }
8840: }
8841: @okmachines = sort(@okmachines);
8842: $newserverstatus{$type}{'machines'} = join(',',@okmachines);
8843: }
8844: }
8845: my %serverstatushash = (
8846: serverstatuses => \%newserverstatus,
8847: );
8848: foreach my $type (@pages) {
1.83 raeburn 8849: foreach my $setting ('namedusers','machines') {
1.84 raeburn 8850: my (@current,@new);
1.83 raeburn 8851: if (ref($currserverstatus{$type}) eq 'HASH') {
1.84 raeburn 8852: if ($currserverstatus{$type}{$setting} ne '') {
8853: @current = split(/,/,$currserverstatus{$type}{$setting});
8854: }
8855: }
8856: if ($newserverstatus{$type}{$setting} ne '') {
8857: @new = split(/,/,$newserverstatus{$type}{$setting});
1.83 raeburn 8858: }
8859: if (@current > 0) {
8860: if (@new > 0) {
8861: foreach my $item (@current) {
8862: if (!grep(/^\Q$item\E$/,@new)) {
8863: $changes{$type}{$setting} = 1;
1.82 raeburn 8864: last;
8865: }
8866: }
1.84 raeburn 8867: foreach my $item (@new) {
8868: if (!grep(/^\Q$item\E$/,@current)) {
8869: $changes{$type}{$setting} = 1;
8870: last;
1.82 raeburn 8871: }
8872: }
8873: } else {
1.83 raeburn 8874: $changes{$type}{$setting} = 1;
1.69 raeburn 8875: }
1.83 raeburn 8876: } elsif (@new > 0) {
8877: $changes{$type}{$setting} = 1;
1.69 raeburn 8878: }
8879: }
8880: }
8881: if (keys(%changes) > 0) {
1.81 raeburn 8882: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 8883: my $putresult = &Apache::lonnet::put_dom('configuration',
8884: \%serverstatushash,$dom);
8885: if ($putresult eq 'ok') {
8886: $resulttext .= &mt('Changes made:').'<ul>';
8887: foreach my $type (@pages) {
1.84 raeburn 8888: if (ref($changes{$type}) eq 'HASH') {
1.69 raeburn 8889: $resulttext .= '<li>'.$titles->{$type}.'<ul>';
1.84 raeburn 8890: if ($changes{$type}{'namedusers'}) {
1.69 raeburn 8891: if ($newserverstatus{$type}{'namedusers'} eq '') {
8892: $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n";
8893: } else {
8894: $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n";
8895: }
1.84 raeburn 8896: }
8897: if ($changes{$type}{'machines'}) {
1.69 raeburn 8898: if ($newserverstatus{$type}{'machines'} eq '') {
8899: $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n";
8900: } else {
8901: $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n";
8902: }
8903:
8904: }
8905: $resulttext .= '</ul></li>';
8906: }
8907: }
8908: $resulttext .= '</ul>';
8909: } else {
8910: $resulttext = '<span class="LC_error">'.
8911: &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>';
8912:
8913: }
8914: } else {
8915: $resulttext = &mt('No changes made to access to server status pages');
8916: }
8917: return $resulttext;
8918: }
8919:
1.118 jms 8920: sub modify_helpsettings {
1.122 jms 8921: my ($r,$dom,$confname,%domconfig) = @_;
1.166 raeburn 8922: my ($resulttext,$errors,%changes,%helphash);
8923: my %defaultchecked = ('submitbugs' => 'on');
8924: my @offon = ('off','on');
1.118 jms 8925: my @toggles = ('submitbugs');
8926: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
8927: foreach my $item (@toggles) {
1.166 raeburn 8928: if ($defaultchecked{$item} eq 'on') {
8929: if ($domconfig{'helpsettings'}{$item} eq '') {
8930: if ($env{'form.'.$item} eq '0') {
8931: $changes{$item} = 1;
8932: }
8933: } elsif ($domconfig{'helpsettings'}{$item} ne $env{'form.'.$item}) {
8934: $changes{$item} = 1;
8935: }
8936: } elsif ($defaultchecked{$item} eq 'off') {
8937: if ($domconfig{'helpsettings'}{$item} eq '') {
8938: if ($env{'form.'.$item} eq '1') {
8939: $changes{$item} = 1;
8940: }
8941: } elsif ($domconfig{'helpsettings'}{$item} ne $env{'form.'.$item}) {
8942: $changes{$item} = 1;
8943: }
8944: }
1.210 raeburn 8945: if (($env{'form.'.$item} eq '0') || ($env{'form.'.$item} eq '1')) {
1.166 raeburn 8946: $helphash{'helpsettings'}{$item} = $env{'form.'.$item};
8947: }
8948: }
1.118 jms 8949: }
1.123 jms 8950: my $putresult;
8951: if (keys(%changes) > 0) {
1.166 raeburn 8952: $putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom);
1.168 raeburn 8953: if ($putresult eq 'ok') {
1.166 raeburn 8954: $resulttext = &mt('Changes made:').'<ul>';
8955: foreach my $item (sort(keys(%changes))) {
8956: if ($item eq 'submitbugs') {
8957: $resulttext .= '<li>'.&mt('Display link to: [_1] set to "'.$offon[$env{'form.'.$item}].'".',
8958: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
8959: &mt('LON-CAPA bug tracker'),600,500)).'</li>';
8960: }
8961: }
8962: $resulttext .= '</ul>';
8963: } else {
8964: $resulttext = &mt('No changes made to help settings');
1.168 raeburn 8965: $errors .= '<li><span class="LC_error">'.
8966: &mt('An error occurred storing the settings: [_1]',
8967: $putresult).'</span></li>';
1.166 raeburn 8968: }
1.118 jms 8969: }
8970: if ($errors) {
1.168 raeburn 8971: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.118 jms 8972: $errors.'</ul>';
8973: }
8974: return $resulttext;
8975: }
8976:
1.121 raeburn 8977: sub modify_coursedefaults {
1.212 raeburn 8978: my ($dom,$lastactref,%domconfig) = @_;
1.121 raeburn 8979: my ($resulttext,$errors,%changes,%defaultshash);
8980: my %defaultchecked = ('canuse_pdfforms' => 'off');
8981: my @toggles = ('canuse_pdfforms');
1.198 raeburn 8982: my @numbers = ('anonsurvey_threshold','uploadquota_official','uploadquota_unofficial',
1.216 raeburn 8983: 'uploadquota_community','uploadquota_textbook');
8984: my @types = ('official','unofficial','community','textbook');
1.198 raeburn 8985: my %staticdefaults = (
8986: anonsurvey_threshold => 10,
8987: uploadquota => 500,
8988: );
1.121 raeburn 8989:
8990: $defaultshash{'coursedefaults'} = {};
8991:
8992: if (ref($domconfig{'coursedefaults'}) ne 'HASH') {
8993: if ($domconfig{'coursedefaults'} eq '') {
8994: $domconfig{'coursedefaults'} = {};
8995: }
8996: }
8997:
8998: if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
8999: foreach my $item (@toggles) {
9000: if ($defaultchecked{$item} eq 'on') {
9001: if (($domconfig{'coursedefaults'}{$item} eq '') &&
9002: ($env{'form.'.$item} eq '0')) {
9003: $changes{$item} = 1;
1.192 raeburn 9004: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
1.121 raeburn 9005: $changes{$item} = 1;
9006: }
9007: } elsif ($defaultchecked{$item} eq 'off') {
9008: if (($domconfig{'coursedefaults'}{$item} eq '') &&
9009: ($env{'form.'.$item} eq '1')) {
9010: $changes{$item} = 1;
9011: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
9012: $changes{$item} = 1;
9013: }
9014: }
9015: $defaultshash{'coursedefaults'}{$item} = $env{'form.'.$item};
9016: }
1.198 raeburn 9017: foreach my $item (@numbers) {
9018: my ($currdef,$newdef);
1.208 raeburn 9019: $newdef = $env{'form.'.$item};
1.198 raeburn 9020: if ($item eq 'anonsurvey_threshold') {
9021: $currdef = $domconfig{'coursedefaults'}{$item};
9022: $newdef =~ s/\D//g;
9023: if ($newdef eq '' || $newdef < 1) {
9024: $newdef = 1;
9025: }
9026: $defaultshash{'coursedefaults'}{$item} = $newdef;
9027: } else {
9028: my ($type) = ($item =~ /^\Quploadquota_\E(\w+)$/);
9029: if (ref($domconfig{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
9030: $currdef = $domconfig{'coursedefaults'}{'uploadquota'}{$type};
9031: }
9032: $newdef =~ s/[^\w.\-]//g;
9033: $defaultshash{'coursedefaults'}{'uploadquota'}{$type} = $newdef;
9034: }
9035: if ($currdef ne $newdef) {
9036: my $staticdef;
9037: if ($item eq 'anonsurvey_threshold') {
9038: unless (($currdef eq '') && ($newdef == $staticdefaults{$item})) {
9039: $changes{$item} = 1;
9040: }
9041: } else {
9042: unless (($currdef eq '') && ($newdef == $staticdefaults{'uploadquota'})) {
9043: $changes{'uploadquota'} = 1;
9044: }
9045: }
1.139 raeburn 9046: }
9047: }
1.192 raeburn 9048: my $officialcreds = $env{'form.official_credits'};
1.216 raeburn 9049: $officialcreds =~ s/[^\d.]+//g;
1.192 raeburn 9050: my $unofficialcreds = $env{'form.unofficial_credits'};
1.216 raeburn 9051: $unofficialcreds =~ s/[^\d.]+//g;
9052: my $textbookcreds = $env{'form.textbook_credits'};
9053: $textbookcreds =~ s/[^\d.]+//g;
1.192 raeburn 9054: if (ref($domconfig{'coursedefaults'}{'coursecredits'} ne 'HASH') &&
9055: ($env{'form.coursecredits'} eq '1')) {
9056: $changes{'coursecredits'} = 1;
9057: } else {
9058: if (($domconfig{'coursedefaults'}{'coursecredits'}{'official'} ne $officialcreds) ||
1.216 raeburn 9059: ($domconfig{'coursedefaults'}{'coursecredits'}{'unofficial'} ne $unofficialcreds) ||
9060: ($domconfig{'coursedefaults'}{'coursecredits'}{'textbook'} ne $textbookcreds)) {
1.192 raeburn 9061: $changes{'coursecredits'} = 1;
9062: }
9063: }
9064: $defaultshash{'coursedefaults'}{'coursecredits'} = {
9065: official => $officialcreds,
9066: unofficial => $unofficialcreds,
1.216 raeburn 9067: textbook => $textbookcreds,
1.192 raeburn 9068: }
1.121 raeburn 9069: }
9070: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
9071: $dom);
9072: if ($putresult eq 'ok') {
9073: if (keys(%changes) > 0) {
1.213 raeburn 9074: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.230 ! raeburn 9075: if (($changes{'canuse_pdfforms'}) || ($changes{'coursecredits'}) ||
! 9076: ($changes{'uploadquota'})) {
1.192 raeburn 9077: if ($changes{'canuse_pdfforms'}) {
9078: $domdefaults{'canuse_pdfforms'}=$defaultshash{'coursedefaults'}{'canuse_pdfforms'};
9079: }
9080: if ($changes{'coursecredits'}) {
9081: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
9082: $domdefaults{'officialcredits'} =
9083: $defaultshash{'coursedefaults'}{'coursecredits'}{'official'};
9084: $domdefaults{'unofficialcredits'} =
9085: $defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'};
1.216 raeburn 9086: $domdefaults{'textbookcredits'} =
9087: $domdefaults{'coursedefaults'}{'coursecredits'}{'textbook'};
1.192 raeburn 9088: }
9089: }
1.198 raeburn 9090: if ($changes{'uploadquota'}) {
9091: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
9092: foreach my $type (@types) {
9093: $domdefaults{$type.'quota'}=$defaultshash{'coursedefaults'}{'uploadquota'}{$type};
9094: }
9095: }
9096: }
1.121 raeburn 9097: my $cachetime = 24*60*60;
9098: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 9099: if (ref($lastactref) eq 'HASH') {
9100: $lastactref->{'domdefaults'} = 1;
9101: }
1.121 raeburn 9102: }
9103: $resulttext = &mt('Changes made:').'<ul>';
9104: foreach my $item (sort(keys(%changes))) {
9105: if ($item eq 'canuse_pdfforms') {
9106: if ($env{'form.'.$item} eq '1') {
9107: $resulttext .= '<li>'.&mt("Course/Community users can create/upload PDF forms set to 'on'").'</li>';
9108: } else {
9109: $resulttext .= '<li>'.&mt('Course/Community users can create/upload PDF forms set to "off"').'</li>';
9110: }
1.139 raeburn 9111: } elsif ($item eq 'anonsurvey_threshold') {
1.192 raeburn 9112: $resulttext .= '<li>'.&mt('Responder count required for display of anonymous survey submissions set to [_1].',$defaultshash{'coursedefaults'}{'anonsurvey_threshold'}).'</li>';
1.198 raeburn 9113: } elsif ($item eq 'uploadquota') {
9114: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
9115: $resulttext .= '<li>'.&mt('Default quota for content uploaded to a course/community via Course Editor set as follows:').'<ul>'.
9116: '<li>'.&mt('Official courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'official'}.'</b>').'</li>'.
9117: '<li>'.&mt('Unofficial courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'unofficial'}.'</b>').'</li>'.
1.216 raeburn 9118: '<li>'.&mt('Textbook courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'textbook'}.'</b>').'</li>'.
9119:
1.198 raeburn 9120: '<li>'.&mt('Communities: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'community'}.'</b>').'</li>'.
9121: '</ul>'.
9122: '</li>';
9123: } else {
9124: $resulttext .= '<li>'.&mt('Default quota for content uploaded via Course Editor remains default: [_1] MB',$staticdefaults{'uploadquota'}).'</li>';
9125: }
1.192 raeburn 9126: } elsif ($item eq 'coursecredits') {
9127: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
9128: if (($domdefaults{'officialcredits'} eq '') &&
1.216 raeburn 9129: ($domdefaults{'unofficialcredits'} eq '') &&
9130: ($domdefaults{'textbookcredits'} eq '')) {
1.192 raeburn 9131: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
9132: } else {
9133: $resulttext .= '<li>'.&mt('Student credits can be set per course by a Domain Coordinator, with the following defaults applying:').'<ul>'.
9134: '<li>'.&mt('Official courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'official'}).'</li>'.
9135: '<li>'.&mt('Unofficial courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'}).'</li>'.
1.216 raeburn 9136: '<li>'.&mt('Textbook courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'textbook'}).'</li>'.
1.192 raeburn 9137: '</ul>'.
9138: '</li>';
9139: }
9140: } else {
9141: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
9142: }
1.140 raeburn 9143: }
1.121 raeburn 9144: }
9145: $resulttext .= '</ul>';
9146: } else {
9147: $resulttext = &mt('No changes made to course defaults');
9148: }
9149: } else {
9150: $resulttext = '<span class="LC_error">'.
9151: &mt('An error occurred: [_1]',$putresult).'</span>';
9152: }
9153: return $resulttext;
9154: }
9155:
1.137 raeburn 9156: sub modify_usersessions {
1.212 raeburn 9157: my ($dom,$lastactref,%domconfig) = @_;
1.145 raeburn 9158: my @hostingtypes = ('version','excludedomain','includedomain');
9159: my @offloadtypes = ('primary','default');
9160: my %types = (
9161: remote => \@hostingtypes,
9162: hosted => \@hostingtypes,
9163: spares => \@offloadtypes,
9164: );
9165: my @prefixes = ('remote','hosted','spares');
1.137 raeburn 9166: my @lcversions = &Apache::lonnet::all_loncaparevs();
1.138 raeburn 9167: my (%by_ip,%by_location,@intdoms);
9168: &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
9169: my @locations = sort(keys(%by_location));
1.137 raeburn 9170: my (%defaultshash,%changes);
9171: foreach my $prefix (@prefixes) {
9172: $defaultshash{'usersessions'}{$prefix} = {};
9173: }
1.212 raeburn 9174: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.137 raeburn 9175: my $resulttext;
1.138 raeburn 9176: my %iphost = &Apache::lonnet::get_iphost();
1.137 raeburn 9177: foreach my $prefix (@prefixes) {
1.145 raeburn 9178: next if ($prefix eq 'spares');
9179: foreach my $type (@{$types{$prefix}}) {
1.137 raeburn 9180: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
9181: if ($type eq 'version') {
9182: my $value = $env{'form.'.$prefix.'_'.$type};
9183: my $okvalue;
9184: if ($value ne '') {
9185: if (grep(/^\Q$value\E$/,@lcversions)) {
9186: $okvalue = $value;
9187: }
9188: }
9189: if (ref($domconfig{'usersessions'}) eq 'HASH') {
9190: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
9191: if ($domconfig{'usersessions'}{$prefix}{$type} ne '') {
9192: if ($inuse == 0) {
9193: $changes{$prefix}{$type} = 1;
9194: } else {
9195: if ($okvalue ne $domconfig{'usersessions'}{$prefix}{$type}) {
9196: $changes{$prefix}{$type} = 1;
9197: }
9198: if ($okvalue ne '') {
9199: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
9200: }
9201: }
9202: } else {
9203: if (($inuse == 1) && ($okvalue ne '')) {
9204: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
9205: $changes{$prefix}{$type} = 1;
9206: }
9207: }
9208: } else {
9209: if (($inuse == 1) && ($okvalue ne '')) {
9210: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
9211: $changes{$prefix}{$type} = 1;
9212: }
9213: }
9214: } else {
9215: if (($inuse == 1) && ($okvalue ne '')) {
9216: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
9217: $changes{$prefix}{$type} = 1;
9218: }
9219: }
9220: } else {
9221: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
9222: my @okvals;
9223: foreach my $val (@vals) {
1.138 raeburn 9224: if ($val =~ /:/) {
9225: my @items = split(/:/,$val);
9226: foreach my $item (@items) {
9227: if (ref($by_location{$item}) eq 'ARRAY') {
9228: push(@okvals,$item);
9229: }
9230: }
9231: } else {
9232: if (ref($by_location{$val}) eq 'ARRAY') {
9233: push(@okvals,$val);
9234: }
1.137 raeburn 9235: }
9236: }
9237: @okvals = sort(@okvals);
9238: if (ref($domconfig{'usersessions'}) eq 'HASH') {
9239: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
9240: if (ref($domconfig{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
9241: if ($inuse == 0) {
9242: $changes{$prefix}{$type} = 1;
9243: } else {
9244: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
9245: my @changed = &Apache::loncommon::compare_arrays($domconfig{'usersessions'}{$prefix}{$type},$defaultshash{'usersessions'}{$prefix}{$type});
9246: if (@changed > 0) {
9247: $changes{$prefix}{$type} = 1;
9248: }
9249: }
9250: } else {
9251: if ($inuse == 1) {
9252: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
9253: $changes{$prefix}{$type} = 1;
9254: }
9255: }
9256: } else {
9257: if ($inuse == 1) {
9258: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
9259: $changes{$prefix}{$type} = 1;
9260: }
9261: }
9262: } else {
9263: if ($inuse == 1) {
9264: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
9265: $changes{$prefix}{$type} = 1;
9266: }
9267: }
9268: }
9269: }
9270: }
1.145 raeburn 9271:
9272: my @alldoms = &Apache::lonnet::all_domains();
1.149 raeburn 9273: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.145 raeburn 9274: my %spareid = ¤t_offloads_to($dom,$domconfig{'usersessions'},\%servers);
9275: my $savespares;
9276:
9277: foreach my $lonhost (sort(keys(%servers))) {
9278: my $serverhomeID =
9279: &Apache::lonnet::get_server_homeID($servers{$lonhost});
1.152 raeburn 9280: my $serverhostname = &Apache::lonnet::hostname($lonhost);
1.145 raeburn 9281: $defaultshash{'usersessions'}{'spares'}{$lonhost} = {};
9282: my %spareschg;
9283: foreach my $type (@{$types{'spares'}}) {
9284: my @okspares;
9285: my @checked = &Apache::loncommon::get_env_multiple('form.spare_'.$type.'_'.$lonhost);
9286: foreach my $server (@checked) {
1.152 raeburn 9287: if (&Apache::lonnet::hostname($server) ne '') {
9288: unless (&Apache::lonnet::hostname($server) eq $serverhostname) {
9289: unless (grep(/^\Q$server\E$/,@okspares)) {
9290: push(@okspares,$server);
9291: }
1.145 raeburn 9292: }
9293: }
9294: }
9295: my $new = $env{'form.newspare_'.$type.'_'.$lonhost};
9296: my $newspare;
1.152 raeburn 9297: if (($new ne '') && (&Apache::lonnet::hostname($new))) {
9298: unless (&Apache::lonnet::hostname($new) eq $serverhostname) {
1.145 raeburn 9299: $newspare = $new;
9300: }
9301: }
1.152 raeburn 9302: my @spares;
9303: if (($newspare ne '') && (!grep(/^\Q$newspare\E$/,@okspares))) {
9304: @spares = sort(@okspares,$newspare);
9305: } else {
9306: @spares = sort(@okspares);
9307: }
9308: $defaultshash{'usersessions'}{'spares'}{$lonhost}{$type} = \@spares;
1.145 raeburn 9309: if (ref($spareid{$lonhost}) eq 'HASH') {
9310: if (ref($spareid{$lonhost}{$type}) eq 'ARRAY') {
1.152 raeburn 9311: my @diffs = &Apache::loncommon::compare_arrays($spareid{$lonhost}{$type},\@spares);
1.145 raeburn 9312: if (@diffs > 0) {
9313: $spareschg{$type} = 1;
9314: }
9315: }
9316: }
9317: }
9318: if (keys(%spareschg) > 0) {
9319: $changes{'spares'}{$lonhost} = \%spareschg;
9320: }
9321: }
9322:
9323: if (ref($domconfig{'usersessions'}) eq 'HASH') {
9324: if (ref($domconfig{'usersessions'}{'spares'}) eq 'HASH') {
9325: if (ref($changes{'spares'}) eq 'HASH') {
9326: if (keys(%{$changes{'spares'}}) > 0) {
9327: $savespares = 1;
9328: }
9329: }
9330: } else {
9331: $savespares = 1;
9332: }
9333: }
9334:
1.147 raeburn 9335: my $nochgmsg = &mt('No changes made to settings for user session hosting/offloading.');
9336: if ((keys(%changes) > 0) || ($savespares)) {
1.137 raeburn 9337: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
9338: $dom);
9339: if ($putresult eq 'ok') {
9340: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
9341: if (ref($defaultshash{'usersessions'}{'remote'}) eq 'HASH') {
9342: $domdefaults{'remotesessions'} = $defaultshash{'usersessions'}{'remote'};
9343: }
9344: if (ref($defaultshash{'usersessions'}{'hosted'}) eq 'HASH') {
9345: $domdefaults{'hostedsessions'} = $defaultshash{'usersessions'}{'hosted'};
9346: }
9347: }
9348: my $cachetime = 24*60*60;
9349: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 9350: if (ref($lastactref) eq 'HASH') {
9351: $lastactref->{'domdefaults'} = 1;
9352: }
1.147 raeburn 9353: if (keys(%changes) > 0) {
9354: my %lt = &usersession_titles();
9355: $resulttext = &mt('Changes made:').'<ul>';
9356: foreach my $prefix (@prefixes) {
9357: if (ref($changes{$prefix}) eq 'HASH') {
9358: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
9359: if ($prefix eq 'spares') {
9360: if (ref($changes{$prefix}) eq 'HASH') {
9361: foreach my $lonhost (sort(keys(%{$changes{$prefix}}))) {
9362: $resulttext .= '<li><b>'.$lonhost.'</b> ';
1.148 raeburn 9363: my $lonhostdom = &Apache::lonnet::host_domain($lonhost);
1.211 raeburn 9364: my $cachekey = &escape('spares').':'.&escape($lonhostdom);
9365: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
1.147 raeburn 9366: if (ref($changes{$prefix}{$lonhost}) eq 'HASH') {
9367: foreach my $type (@{$types{$prefix}}) {
9368: if ($changes{$prefix}{$lonhost}{$type}) {
9369: my $offloadto = &mt('None');
9370: if (ref($defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}) eq 'ARRAY') {
9371: if (@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}} > 0) {
9372: $offloadto = join(', ',@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}});
9373: }
1.145 raeburn 9374: }
1.147 raeburn 9375: $resulttext .= &mt('[_1] set to: [_2].','<i>'.$lt{$type}.'</i>',$offloadto).(' 'x3);
1.145 raeburn 9376: }
1.137 raeburn 9377: }
9378: }
1.147 raeburn 9379: $resulttext .= '</li>';
1.137 raeburn 9380: }
9381: }
1.147 raeburn 9382: } else {
9383: foreach my $type (@{$types{$prefix}}) {
9384: if (defined($changes{$prefix}{$type})) {
9385: my $newvalue;
9386: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
9387: if (ref($defaultshash{'usersessions'}{$prefix})) {
9388: if ($type eq 'version') {
9389: $newvalue = $defaultshash{'usersessions'}{$prefix}{$type};
9390: } elsif (ref($defaultshash{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
9391: if (@{$defaultshash{'usersessions'}{$prefix}{$type}} > 0) {
9392: $newvalue = join(', ',@{$defaultshash{'usersessions'}{$prefix}{$type}});
9393: }
1.145 raeburn 9394: }
9395: }
9396: }
1.147 raeburn 9397: if ($newvalue eq '') {
9398: if ($type eq 'version') {
9399: $resulttext .= '<li>'.&mt('[_1] set to: off',$lt{$type}).'</li>';
9400: } else {
9401: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
9402: }
1.145 raeburn 9403: } else {
1.147 raeburn 9404: if ($type eq 'version') {
9405: $newvalue .= ' '.&mt('(or later)');
9406: }
9407: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
1.145 raeburn 9408: }
1.137 raeburn 9409: }
9410: }
9411: }
1.147 raeburn 9412: $resulttext .= '</ul>';
1.137 raeburn 9413: }
9414: }
1.147 raeburn 9415: $resulttext .= '</ul>';
9416: } else {
9417: $resulttext = $nochgmsg;
1.137 raeburn 9418: }
9419: } else {
9420: $resulttext = '<span class="LC_error">'.
9421: &mt('An error occurred: [_1]',$putresult).'</span>';
9422: }
9423: } else {
1.147 raeburn 9424: $resulttext = $nochgmsg;
1.137 raeburn 9425: }
9426: return $resulttext;
9427: }
9428:
1.150 raeburn 9429: sub modify_loadbalancing {
9430: my ($dom,%domconfig) = @_;
9431: my $primary_id = &Apache::lonnet::domain($dom,'primary');
9432: my $intdom = &Apache::lonnet::internet_dom($primary_id);
9433: my ($othertitle,$usertypes,$types) =
9434: &Apache::loncommon::sorted_inst_types($dom);
9435: my %servers = &Apache::lonnet::internet_dom_servers($dom);
9436: my @sparestypes = ('primary','default');
9437: my %typetitles = &sparestype_titles();
9438: my $resulttext;
1.171 raeburn 9439: my (%currbalancer,%currtargets,%currrules,%existing);
9440: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
9441: %existing = %{$domconfig{'loadbalancing'}};
9442: }
9443: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
9444: \%currtargets,\%currrules);
9445: my ($saveloadbalancing,%defaultshash,%changes);
9446: my ($alltypes,$othertypes,$titles) =
9447: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
9448: my %ruletitles = &offloadtype_text();
9449: my @deletions = &Apache::loncommon::get_env_multiple('form.loadbalancing_delete');
9450: for (my $i=0; $i<$env{'form.loadbalancing_total'}; $i++) {
9451: my $balancer = $env{'form.loadbalancing_lonhost_'.$i};
9452: if ($balancer eq '') {
9453: next;
9454: }
1.210 raeburn 9455: if (!exists($servers{$balancer})) {
1.171 raeburn 9456: if (exists($currbalancer{$balancer})) {
9457: push(@{$changes{'delete'}},$balancer);
1.150 raeburn 9458: }
1.171 raeburn 9459: next;
9460: }
9461: if ((@deletions > 0) && (grep(/^\Q$i\E$/,@deletions))) {
9462: push(@{$changes{'delete'}},$balancer);
9463: next;
9464: }
9465: if (!exists($currbalancer{$balancer})) {
9466: push(@{$changes{'add'}},$balancer);
9467: }
9468: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'} = [];
9469: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'default'} = [];
9470: $defaultshash{'loadbalancing'}{$balancer}{'rules'} = {};
9471: unless (ref($domconfig{'loadbalancing'}) eq 'HASH') {
9472: $saveloadbalancing = 1;
9473: }
9474: foreach my $sparetype (@sparestypes) {
9475: my @targets = &Apache::loncommon::get_env_multiple('form.loadbalancing_target_'.$i.'_'.$sparetype);
9476: my @offloadto;
9477: foreach my $target (@targets) {
9478: if (($servers{$target}) && ($target ne $balancer)) {
9479: if ($sparetype eq 'default') {
9480: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}) eq 'ARRAY') {
9481: next if (grep(/^\Q$target\E$/,@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}}));
1.150 raeburn 9482: }
9483: }
1.171 raeburn 9484: unless(grep(/^\Q$target\E$/,@offloadto)) {
9485: push(@offloadto,$target);
9486: }
1.150 raeburn 9487: }
1.171 raeburn 9488: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype} = \@offloadto;
1.150 raeburn 9489: }
9490: }
1.171 raeburn 9491: if (ref($currtargets{$balancer}) eq 'HASH') {
1.150 raeburn 9492: foreach my $sparetype (@sparestypes) {
1.171 raeburn 9493: if (ref($currtargets{$balancer}{$sparetype}) eq 'ARRAY') {
9494: my @targetdiffs = &Apache::loncommon::compare_arrays($currtargets{$balancer}{$sparetype},$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype});
1.150 raeburn 9495: if (@targetdiffs > 0) {
1.171 raeburn 9496: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 9497: }
1.171 raeburn 9498: } elsif (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
9499: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
9500: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 9501: }
9502: }
9503: }
9504: } else {
1.171 raeburn 9505: if (ref($defaultshash{'loadbalancing'}{$balancer}) eq 'HASH') {
1.210 raeburn 9506: foreach my $sparetype (@sparestypes) {
1.171 raeburn 9507: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
9508: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
9509: $changes{'curr'}{$balancer}{'targets'} = 1;
9510: }
1.150 raeburn 9511: }
9512: }
1.210 raeburn 9513: }
1.150 raeburn 9514: }
9515: my $ishomedom;
1.171 raeburn 9516: if (&Apache::lonnet::host_domain($balancer) eq $dom) {
9517: $ishomedom = 1;
1.150 raeburn 9518: }
9519: if (ref($alltypes) eq 'ARRAY') {
9520: foreach my $type (@{$alltypes}) {
9521: my $rule;
1.210 raeburn 9522: unless ((($type eq '_LC_external') || ($type eq '_LC_internetdom')) &&
1.150 raeburn 9523: (!$ishomedom)) {
1.171 raeburn 9524: $rule = $env{'form.loadbalancing_rules_'.$i.'_'.$type};
9525: }
9526: if ($rule eq 'specific') {
9527: $rule = $env{'form.loadbalancing_singleserver_'.$i.'_'.$type};
1.150 raeburn 9528: }
1.171 raeburn 9529: $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type} = $rule;
9530: if (ref($currrules{$balancer}) eq 'HASH') {
9531: if ($rule ne $currrules{$balancer}{$type}) {
9532: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 9533: }
9534: } elsif ($rule ne '') {
1.171 raeburn 9535: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 9536: }
9537: }
9538: }
1.171 raeburn 9539: }
9540: my $nochgmsg = &mt('No changes made to Load Balancer settings.');
9541: if ((keys(%changes) > 0) || ($saveloadbalancing)) {
9542: unless (ref($defaultshash{'loadbalancing'}) eq 'HASH') {
9543: $defaultshash{'loadbalancing'} = {};
9544: }
9545: my $putresult = &Apache::lonnet::put_dom('configuration',
9546: \%defaultshash,$dom);
9547: if ($putresult eq 'ok') {
9548: if (keys(%changes) > 0) {
9549: if (ref($changes{'delete'}) eq 'ARRAY') {
9550: foreach my $balancer (sort(@{$changes{'delete'}})) {
9551: $resulttext .= '<li>'.&mt('Load Balancing discontinued for: [_1]',$balancer).'</li>';
1.211 raeburn 9552: my $cachekey = &escape('loadbalancing').':'.&escape($dom);
9553: &Apache::lonnet::remote_devalidate_cache($balancer,[$cachekey]);
1.150 raeburn 9554: }
1.171 raeburn 9555: }
9556: if (ref($changes{'add'}) eq 'ARRAY') {
1.210 raeburn 9557: foreach my $balancer (sort(@{$changes{'add'}})) {
1.171 raeburn 9558: $resulttext .= '<li>'.&mt('Load Balancing enabled for: [_1]',$balancer);
9559: }
9560: }
9561: if (ref($changes{'curr'}) eq 'HASH') {
9562: foreach my $balancer (sort(keys(%{$changes{'curr'}}))) {
9563: if (ref($changes{'curr'}{$balancer}) eq 'HASH') {
9564: if ($changes{'curr'}{$balancer}{'targets'}) {
9565: my %offloadstr;
9566: foreach my $sparetype (@sparestypes) {
9567: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
9568: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
9569: $offloadstr{$sparetype} = join(', ',@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
9570: }
9571: }
1.150 raeburn 9572: }
1.171 raeburn 9573: if (keys(%offloadstr) == 0) {
9574: $resulttext .= '<li>'.&mt("Servers to which Load Balance server offloads set to 'None', by default").'</li>';
1.150 raeburn 9575: } else {
1.171 raeburn 9576: my $showoffload;
9577: foreach my $sparetype (@sparestypes) {
9578: $showoffload .= '<i>'.$typetitles{$sparetype}.'</i>: ';
9579: if (defined($offloadstr{$sparetype})) {
9580: $showoffload .= $offloadstr{$sparetype};
9581: } else {
9582: $showoffload .= &mt('None');
9583: }
9584: $showoffload .= (' 'x3);
9585: }
9586: $resulttext .= '<li>'.&mt('By default, Load Balancer: [_1] set to offload to - [_2]',$balancer,$showoffload).'</li>';
1.150 raeburn 9587: }
9588: }
9589: }
1.171 raeburn 9590: if (ref($changes{'curr'}{$balancer}{'rules'}) eq 'HASH') {
9591: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
9592: foreach my $type (@{$alltypes}) {
9593: if ($changes{'curr'}{$balancer}{'rules'}{$type}) {
9594: my $rule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
9595: my $balancetext;
9596: if ($rule eq '') {
9597: $balancetext = $ruletitles{'default'};
1.209 raeburn 9598: } elsif (($rule eq 'homeserver') || ($rule eq 'externalbalancer') ||
9599: ($rule eq 'balancer') || ($rule eq 'offloadedto')) {
1.171 raeburn 9600: $balancetext = $ruletitles{$rule};
9601: } else {
9602: $balancetext = &mt('offload to [_1]',$defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type});
9603: }
1.210 raeburn 9604: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- balancing for [_2] set to - "[_3]"',$balancer,$titles->{$type},$balancetext).'</li>';
1.150 raeburn 9605: }
9606: }
9607: }
9608: }
1.215 raeburn 9609: my $cachekey = &escape('loadbalancing').':'.&escape($dom);
1.211 raeburn 9610: &Apache::lonnet::remote_devalidate_cache($balancer,[$cachekey]);
1.150 raeburn 9611: }
1.171 raeburn 9612: }
9613: if ($resulttext ne '') {
9614: $resulttext = &mt('Changes made:').'<ul>'.$resulttext.'</ul>';
1.150 raeburn 9615: } else {
9616: $resulttext = $nochgmsg;
9617: }
9618: } else {
1.171 raeburn 9619: $resulttext = $nochgmsg;
1.150 raeburn 9620: }
9621: } else {
1.171 raeburn 9622: $resulttext = '<span class="LC_error">'.
9623: &mt('An error occurred: [_1]',$putresult).'</span>';
1.150 raeburn 9624: }
9625: } else {
1.171 raeburn 9626: $resulttext = $nochgmsg;
1.150 raeburn 9627: }
9628: return $resulttext;
9629: }
9630:
1.48 raeburn 9631: sub recurse_check {
9632: my ($chkcats,$categories,$depth,$name) = @_;
9633: if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
9634: my $chg = 0;
9635: for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
9636: my $category = $chkcats->[$depth]{$name}[$j];
9637: my $item;
9638: if ($category eq '') {
9639: $chg ++;
9640: } else {
9641: my $deeper = $depth + 1;
9642: $item = &escape($category).':'.&escape($name).':'.$depth;
9643: if ($chg) {
9644: $categories->{$item} -= $chg;
9645: }
9646: &recurse_check($chkcats,$categories,$deeper,$category);
9647: $deeper --;
9648: }
9649: }
9650: }
9651: return;
9652: }
9653:
9654: sub recurse_cat_deletes {
9655: my ($item,$coursecategories,$deletions) = @_;
9656: my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
9657: my $subdepth = $depth + 1;
9658: if (ref($coursecategories) eq 'HASH') {
9659: foreach my $subitem (keys(%{$coursecategories})) {
9660: my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
9661: if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
9662: delete($coursecategories->{$subitem});
9663: $deletions->{$subitem} = 1;
9664: &recurse_cat_deletes($subitem,$coursecategories,$deletions);
1.168 raeburn 9665: }
1.48 raeburn 9666: }
9667: }
9668: return;
9669: }
9670:
1.125 raeburn 9671: sub get_active_dcs {
9672: my ($dom) = @_;
1.191 raeburn 9673: my $now = time;
9674: my %dompersonnel = &Apache::lonnet::get_domain_roles($dom,['dc'],$now,$now);
1.125 raeburn 9675: my %domcoords;
9676: my $numdcs = 0;
9677: foreach my $server (keys(%dompersonnel)) {
9678: foreach my $user (sort(keys(%{$dompersonnel{$server}}))) {
9679: my ($trole,$uname,$udom,$runame,$rudom,$rsec) = split(/:/,$user);
1.191 raeburn 9680: $domcoords{$uname.':'.$udom} = $dompersonnel{$server}{$user};
1.125 raeburn 9681: }
9682: }
9683: return %domcoords;
9684: }
9685:
9686: sub active_dc_picker {
1.191 raeburn 9687: my ($dom,$numinrow,$inputtype,$name,%currhash) = @_;
1.125 raeburn 9688: my %domcoords = &get_active_dcs($dom);
1.191 raeburn 9689: my @domcoord = keys(%domcoords);
9690: if (keys(%currhash)) {
9691: foreach my $dc (keys(%currhash)) {
9692: unless (exists($domcoords{$dc})) {
9693: push(@domcoord,$dc);
9694: }
9695: }
9696: }
9697: @domcoord = sort(@domcoord);
1.210 raeburn 9698: my $numdcs = scalar(@domcoord);
1.191 raeburn 9699: my $rows = 0;
9700: my $table;
1.125 raeburn 9701: if ($numdcs > 1) {
1.191 raeburn 9702: $table = '<table>';
9703: for (my $i=0; $i<@domcoord; $i++) {
1.125 raeburn 9704: my $rem = $i%($numinrow);
9705: if ($rem == 0) {
9706: if ($i > 0) {
1.191 raeburn 9707: $table .= '</tr>';
1.125 raeburn 9708: }
1.191 raeburn 9709: $table .= '<tr>';
9710: $rows ++;
1.125 raeburn 9711: }
1.191 raeburn 9712: my $check = '';
9713: if ($inputtype eq 'radio') {
9714: if (keys(%currhash) == 0) {
9715: if (!$i) {
9716: $check = ' checked="checked"';
9717: }
9718: } elsif (exists($currhash{$domcoord[$i]})) {
9719: $check = ' checked="checked"';
9720: }
9721: } else {
9722: if (exists($currhash{$domcoord[$i]})) {
9723: $check = ' checked="checked"';
1.125 raeburn 9724: }
9725: }
1.191 raeburn 9726: if ($i == @domcoord - 1) {
1.125 raeburn 9727: my $colsleft = $numinrow - $rem;
9728: if ($colsleft > 1) {
1.191 raeburn 9729: $table .= '<td class="LC_left_item" colspan="'.$colsleft.'">';
1.125 raeburn 9730: } else {
1.191 raeburn 9731: $table .= '<td class="LC_left_item">';
1.125 raeburn 9732: }
9733: } else {
1.191 raeburn 9734: $table .= '<td class="LC_left_item">';
9735: }
9736: my ($dcname,$dcdom) = split(':',$domcoord[$i]);
9737: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
9738: $table .= '<span class="LC_nobreak"><label>'.
9739: '<input type="'.$inputtype.'" name="'.$name.'"'.
9740: ' value="'.$domcoord[$i].'"'.$check.' />'.$user;
9741: if ($user ne $dcname.':'.$dcdom) {
1.219 raeburn 9742: $table .= ' ('.$dcname.':'.$dcdom.')';
1.191 raeburn 9743: }
1.219 raeburn 9744: $table .= '</label></span></td>';
1.191 raeburn 9745: }
9746: $table .= '</tr></table>';
9747: } elsif ($numdcs == 1) {
1.219 raeburn 9748: my ($dcname,$dcdom) = split(':',$domcoord[0]);
9749: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
1.191 raeburn 9750: if ($inputtype eq 'radio') {
1.219 raeburn 9751: $table .= '<input type="hidden" name="'.$name.'" value="'.$domcoord[0].'" />'.$user;
9752: if ($user ne $dcname.':'.$dcdom) {
9753: $table .= ' ('.$dcname.':'.$dcdom.')';
9754: }
1.191 raeburn 9755: } else {
9756: my $check;
9757: if (exists($currhash{$domcoord[0]})) {
9758: $check = ' checked="checked"';
1.125 raeburn 9759: }
1.219 raeburn 9760: $table .= '<span class="LC_nobreak"><label>'.
9761: '<input type="checkbox" name="'.$name.'" '.
9762: 'value="'.$domcoord[0].'"'.$check.' />'.$user;
9763: if ($user ne $dcname.':'.$dcdom) {
1.220 raeburn 9764: $table .= ' ('.$dcname.':'.$dcdom.')';
1.219 raeburn 9765: }
1.220 raeburn 9766: $table .= '</label></span>';
1.191 raeburn 9767: $rows ++;
1.125 raeburn 9768: }
9769: }
1.191 raeburn 9770: return ($numdcs,$table,$rows);
1.125 raeburn 9771: }
9772:
1.137 raeburn 9773: sub usersession_titles {
9774: return &Apache::lonlocal::texthash(
9775: hosted => 'Hosting of sessions for users from other domains on servers in this domain',
9776: remote => 'Hosting of sessions for users in this domain on servers in other domains',
1.145 raeburn 9777: spares => 'Servers offloaded to, when busy',
1.137 raeburn 9778: version => 'LON-CAPA version requirement',
1.138 raeburn 9779: excludedomain => 'Allow all, but exclude specific domains',
9780: includedomain => 'Deny all, but include specific domains',
1.145 raeburn 9781: primary => 'Primary (checked first)',
1.154 raeburn 9782: default => 'Default',
1.137 raeburn 9783: );
9784: }
9785:
1.152 raeburn 9786: sub id_for_thisdom {
9787: my (%servers) = @_;
9788: my %altids;
9789: foreach my $server (keys(%servers)) {
9790: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
9791: if ($serverhome ne $server) {
9792: $altids{$serverhome} = $server;
9793: }
9794: }
9795: return %altids;
9796: }
9797:
1.150 raeburn 9798: sub count_servers {
9799: my ($currbalancer,%servers) = @_;
9800: my (@spares,$numspares);
9801: foreach my $lonhost (sort(keys(%servers))) {
9802: next if ($currbalancer eq $lonhost);
9803: push(@spares,$lonhost);
9804: }
9805: if ($currbalancer) {
9806: $numspares = scalar(@spares);
9807: } else {
9808: $numspares = scalar(@spares) - 1;
9809: }
9810: return ($numspares,@spares);
9811: }
9812:
9813: sub lonbalance_targets_js {
1.171 raeburn 9814: my ($dom,$types,$servers,$settings) = @_;
1.150 raeburn 9815: my $select = &mt('Select');
9816: my ($alltargets,$allishome,$allinsttypes,@alltypes);
9817: if (ref($servers) eq 'HASH') {
9818: $alltargets = join("','",sort(keys(%{$servers})));
9819: my @homedoms;
9820: foreach my $server (sort(keys(%{$servers}))) {
9821: if (&Apache::lonnet::host_domain($server) eq $dom) {
9822: push(@homedoms,'1');
9823: } else {
9824: push(@homedoms,'0');
9825: }
9826: }
9827: $allishome = join("','",@homedoms);
9828: }
9829: if (ref($types) eq 'ARRAY') {
9830: if (@{$types} > 0) {
9831: @alltypes = @{$types};
9832: }
9833: }
9834: push(@alltypes,'default','_LC_adv','_LC_author','_LC_internetdom','_LC_external');
9835: $allinsttypes = join("','",@alltypes);
1.171 raeburn 9836: my (%currbalancer,%currtargets,%currrules,%existing);
9837: if (ref($settings) eq 'HASH') {
9838: %existing = %{$settings};
9839: }
9840: &get_loadbalancers_config($servers,\%existing,\%currbalancer,
9841: \%currtargets,\%currrules);
1.210 raeburn 9842: my $balancers = join("','",sort(keys(%currbalancer)));
1.150 raeburn 9843: return <<"END";
9844:
9845: <script type="text/javascript">
9846: // <![CDATA[
9847:
1.171 raeburn 9848: currBalancers = new Array('$balancers');
9849:
9850: function toggleTargets(balnum) {
9851: var lonhostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
9852: var prevhostitem = document.getElementById('loadbalancing_prevlonhost_'+balnum);
9853: var balancer = lonhostitem.options[lonhostitem.selectedIndex].value;
9854: var prevbalancer = prevhostitem.value;
9855: var baltotal = document.getElementById('loadbalancing_total').value;
9856: prevhostitem.value = balancer;
9857: if (prevbalancer != '') {
9858: var prevIdx = currBalancers.indexOf(prevbalancer);
9859: if (prevIdx != -1) {
9860: currBalancers.splice(prevIdx,1);
9861: }
9862: }
1.150 raeburn 9863: if (balancer == '') {
1.171 raeburn 9864: hideSpares(balnum);
1.150 raeburn 9865: } else {
1.171 raeburn 9866: var currIdx = currBalancers.indexOf(balancer);
9867: if (currIdx == -1) {
9868: currBalancers.push(balancer);
9869: }
1.150 raeburn 9870: var homedoms = new Array('$allishome');
1.171 raeburn 9871: var ishomedom = homedoms[lonhostitem.selectedIndex];
9872: showSpares(balancer,ishomedom,balnum);
1.150 raeburn 9873: }
1.171 raeburn 9874: balancerChange(balnum,baltotal,'change',prevbalancer,balancer);
1.150 raeburn 9875: return;
9876: }
9877:
1.171 raeburn 9878: function showSpares(balancer,ishomedom,balnum) {
1.150 raeburn 9879: var alltargets = new Array('$alltargets');
9880: var insttypes = new Array('$allinsttypes');
1.151 raeburn 9881: var offloadtypes = new Array('primary','default');
9882:
1.171 raeburn 9883: document.getElementById('loadbalancing_targets_'+balnum).style.display='block';
9884: document.getElementById('loadbalancing_disabled_'+balnum).style.display='none';
1.152 raeburn 9885:
1.151 raeburn 9886: for (var i=0; i<offloadtypes.length; i++) {
9887: var count = 0;
9888: for (var j=0; j<alltargets.length; j++) {
9889: if (alltargets[j] != balancer) {
1.171 raeburn 9890: var item = document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+count);
9891: item.value = alltargets[j];
9892: item.style.textAlign='left';
9893: item.style.textFace='normal';
9894: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+count).innerHTML = alltargets[j];
9895: if (currBalancers.indexOf(alltargets[j]) == -1) {
9896: item.disabled = '';
9897: } else {
9898: item.disabled = 'disabled';
9899: item.checked = false;
9900: }
1.151 raeburn 9901: count ++;
9902: }
1.150 raeburn 9903: }
9904: }
1.151 raeburn 9905: for (var k=0; k<insttypes.length; k++) {
9906: if ((insttypes[k] == '_LC_external') || (insttypes[k] == '_LC_internetdom')) {
1.150 raeburn 9907: if (ishomedom == 1) {
1.171 raeburn 9908: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
9909: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 9910: } else {
1.171 raeburn 9911: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
9912: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.150 raeburn 9913: }
9914: } else {
1.171 raeburn 9915: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
9916: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 9917: }
1.151 raeburn 9918: if ((insttypes[k] != '_LC_external') &&
9919: ((insttypes[k] != '_LC_internetdom') ||
9920: ((insttypes[k] == '_LC_internetdom') && (ishomedom == 1)))) {
1.171 raeburn 9921: var item = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]);
9922: item.options.length = 0;
9923: item.options[0] = new Option("","",true,true);
1.210 raeburn 9924: var idx = 0;
1.151 raeburn 9925: for (var m=0; m<alltargets.length; m++) {
1.171 raeburn 9926: if ((currBalancers.indexOf(alltargets[m]) == -1) && (alltargets[m] != balancer)) {
9927: idx ++;
9928: item.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
1.150 raeburn 9929: }
9930: }
9931: }
9932: }
9933: return;
9934: }
9935:
1.171 raeburn 9936: function hideSpares(balnum) {
1.150 raeburn 9937: var alltargets = new Array('$alltargets');
9938: var insttypes = new Array('$allinsttypes');
9939: var offloadtypes = new Array('primary','default');
9940:
1.171 raeburn 9941: document.getElementById('loadbalancing_targets_'+balnum).style.display='none';
9942: document.getElementById('loadbalancing_disabled_'+balnum).style.display='block';
1.150 raeburn 9943:
9944: var total = alltargets.length - 1;
9945: for (var i=0; i<offloadtypes; i++) {
9946: for (var j=0; j<total; j++) {
1.171 raeburn 9947: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).checked = false;
9948: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).value = '';
9949: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+j).innerHTML = '';
1.151 raeburn 9950: }
1.150 raeburn 9951: }
9952: for (var k=0; k<insttypes.length; k++) {
1.171 raeburn 9953: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
9954: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.151 raeburn 9955: if (insttypes[k] != '_LC_external') {
1.171 raeburn 9956: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).length = 0;
9957: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).options[0] = new Option("","",true,true);
1.150 raeburn 9958: }
9959: }
9960: return;
9961: }
9962:
1.171 raeburn 9963: function checkOffloads(item,balnum,type) {
1.150 raeburn 9964: var alltargets = new Array('$alltargets');
9965: var offloadtypes = new Array('primary','default');
9966: if (item.checked) {
9967: var total = alltargets.length - 1;
9968: var other;
9969: if (type == offloadtypes[0]) {
1.151 raeburn 9970: other = offloadtypes[1];
1.150 raeburn 9971: } else {
1.151 raeburn 9972: other = offloadtypes[0];
1.150 raeburn 9973: }
9974: for (var i=0; i<total; i++) {
1.171 raeburn 9975: var server = document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).value;
1.150 raeburn 9976: if (server == item.value) {
1.171 raeburn 9977: if (document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked) {
9978: document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked = false;
1.150 raeburn 9979: }
9980: }
9981: }
9982: }
9983: return;
9984: }
9985:
1.171 raeburn 9986: function singleServerToggle(balnum,type) {
9987: var offloadtoSelIdx = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex;
1.150 raeburn 9988: if (offloadtoSelIdx == 0) {
1.171 raeburn 9989: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_0').checked = true;
9990: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 9991:
9992: } else {
1.171 raeburn 9993: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_2').checked = true;
9994: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
1.150 raeburn 9995: }
9996: return;
9997: }
9998:
1.171 raeburn 9999: function balanceruleChange(formname,balnum,type) {
1.150 raeburn 10000: if (type == '_LC_external') {
1.171 raeburn 10001: return;
1.150 raeburn 10002: }
1.171 raeburn 10003: var typesRules = getIndicesByName(formname,'loadbalancing_rules_'+balnum+'_'+type);
1.150 raeburn 10004: for (var i=0; i<typesRules.length; i++) {
10005: if (formname.elements[typesRules[i]].checked) {
10006: if (formname.elements[typesRules[i]].value != 'specific') {
1.171 raeburn 10007: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex = 0;
10008: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 10009: } else {
1.171 raeburn 10010: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
10011: }
10012: }
10013: }
10014: return;
10015: }
10016:
10017: function balancerDeleteChange(balnum) {
10018: var hostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
10019: var baltotal = document.getElementById('loadbalancing_total').value;
10020: var addtarget;
10021: var removetarget;
10022: var action = 'delete';
10023: if (document.getElementById('loadbalancing_delete_'+balnum)) {
10024: var lonhost = hostitem.value;
10025: var currIdx = currBalancers.indexOf(lonhost);
10026: if (document.getElementById('loadbalancing_delete_'+balnum).checked) {
10027: if (currIdx != -1) {
10028: currBalancers.splice(currIdx,1);
10029: }
10030: addtarget = lonhost;
10031: } else {
10032: if (currIdx == -1) {
10033: currBalancers.push(lonhost);
10034: }
10035: removetarget = lonhost;
10036: action = 'undelete';
10037: }
10038: balancerChange(balnum,baltotal,action,addtarget,removetarget);
10039: }
10040: return;
10041: }
10042:
10043: function balancerChange(balnum,baltotal,action,addtarget,removetarget) {
10044: if (baltotal > 1) {
10045: var offloadtypes = new Array('primary','default');
10046: var alltargets = new Array('$alltargets');
10047: var insttypes = new Array('$allinsttypes');
10048: for (var i=0; i<baltotal; i++) {
10049: if (i != balnum) {
10050: for (var j=0; j<offloadtypes.length; j++) {
10051: var total = alltargets.length - 1;
10052: for (var k=0; k<total; k++) {
10053: var serveritem = document.getElementById('loadbalancing_target_'+i+'_'+offloadtypes[j]+'_'+k);
10054: var server = serveritem.value;
10055: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
10056: if (server == addtarget) {
10057: serveritem.disabled = '';
10058: }
10059: }
10060: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
10061: if (server == removetarget) {
10062: serveritem.disabled = 'disabled';
10063: serveritem.checked = false;
10064: }
10065: }
10066: }
10067: }
10068: for (var j=0; j<insttypes.length; j++) {
10069: if (insttypes[j] != '_LC_external') {
10070: if (document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j])) {
10071: var singleserver = document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j]);
10072: var currSel = singleserver.selectedIndex;
10073: var currVal = singleserver.options[currSel].value;
10074: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
10075: var numoptions = singleserver.options.length;
10076: var needsnew = 1;
10077: for (var k=0; k<numoptions; k++) {
10078: if (singleserver.options[k] == addtarget) {
10079: needsnew = 0;
10080: break;
10081: }
10082: }
10083: if (needsnew == 1) {
10084: singleserver.options[numoptions] = new Option(addtarget,addtarget,false,false);
10085: }
10086: }
10087: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
10088: singleserver.options.length = 0;
10089: if ((currVal) && (currVal != removetarget)) {
10090: singleserver.options[0] = new Option("","",false,false);
10091: } else {
10092: singleserver.options[0] = new Option("","",true,true);
10093: }
10094: var idx = 0;
10095: for (var m=0; m<alltargets.length; m++) {
10096: if (currBalancers.indexOf(alltargets[m]) == -1) {
10097: idx ++;
10098: if (currVal == alltargets[m]) {
10099: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],true,true);
10100: } else {
10101: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
10102: }
10103: }
10104: }
10105: }
10106: }
10107: }
10108: }
1.150 raeburn 10109: }
10110: }
10111: }
10112: return;
10113: }
10114:
1.152 raeburn 10115: // ]]>
10116: </script>
10117:
10118: END
10119: }
10120:
10121: sub new_spares_js {
10122: my @sparestypes = ('primary','default');
10123: my $types = join("','",@sparestypes);
10124: my $select = &mt('Select');
10125: return <<"END";
10126:
10127: <script type="text/javascript">
10128: // <![CDATA[
10129:
10130: function updateNewSpares(formname,lonhost) {
10131: var types = new Array('$types');
10132: var include = new Array();
10133: var exclude = new Array();
10134: for (var i=0; i<types.length; i++) {
10135: var spareboxes = getIndicesByName(formname,'spare_'+types[i]+'_'+lonhost);
10136: for (var j=0; j<spareboxes.length; j++) {
10137: if (formname.elements[spareboxes[j]].checked) {
10138: exclude.push(formname.elements[spareboxes[j]].value);
10139: } else {
10140: include.push(formname.elements[spareboxes[j]].value);
10141: }
10142: }
10143: }
10144: for (var i=0; i<types.length; i++) {
10145: var newSpare = document.getElementById('newspare_'+types[i]+'_'+lonhost);
10146: var selIdx = newSpare.selectedIndex;
10147: var currnew = newSpare.options[selIdx].value;
10148: var okSpares = new Array();
10149: for (var j=0; j<newSpare.options.length; j++) {
10150: var possible = newSpare.options[j].value;
10151: if (possible != '') {
10152: if (exclude.indexOf(possible) == -1) {
10153: okSpares.push(possible);
10154: } else {
10155: if (currnew == possible) {
10156: selIdx = 0;
10157: }
10158: }
10159: }
10160: }
10161: for (var k=0; k<include.length; k++) {
10162: if (okSpares.indexOf(include[k]) == -1) {
10163: okSpares.push(include[k]);
10164: }
10165: }
10166: okSpares.sort();
10167: newSpare.options.length = 0;
10168: if (selIdx == 0) {
10169: newSpare.options[0] = new Option("$select","",true,true);
10170: } else {
10171: newSpare.options[0] = new Option("$select","",false,false);
10172: }
10173: for (var m=0; m<okSpares.length; m++) {
10174: var idx = m+1;
10175: var selThis = 0;
10176: if (selIdx != 0) {
10177: if (okSpares[m] == currnew) {
10178: selThis = 1;
10179: }
10180: }
10181: if (selThis == 1) {
10182: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],true,true);
10183: } else {
10184: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],false,false);
10185: }
10186: }
10187: }
10188: return;
10189: }
10190:
10191: function checkNewSpares(lonhost,type) {
10192: var newSpare = document.getElementById('newspare_'+type+'_'+lonhost);
10193: var chosen = newSpare.options[newSpare.selectedIndex].value;
10194: if (chosen != '') {
10195: var othertype;
10196: var othernewSpare;
10197: if (type == 'primary') {
10198: othernewSpare = document.getElementById('newspare_default_'+lonhost);
10199: }
10200: if (type == 'default') {
10201: othernewSpare = document.getElementById('newspare_primary_'+lonhost);
10202: }
10203: if (othernewSpare.options[othernewSpare.selectedIndex].value == chosen) {
10204: othernewSpare.selectedIndex = 0;
10205: }
10206: }
10207: return;
10208: }
10209:
10210: // ]]>
10211: </script>
10212:
10213: END
10214:
10215: }
10216:
10217: sub common_domprefs_js {
10218: return <<"END";
10219:
10220: <script type="text/javascript">
10221: // <![CDATA[
10222:
1.150 raeburn 10223: function getIndicesByName(formname,item) {
1.152 raeburn 10224: var group = new Array();
1.150 raeburn 10225: for (var i=0;i<formname.elements.length;i++) {
10226: if (formname.elements[i].name == item) {
1.152 raeburn 10227: group.push(formname.elements[i].id);
1.150 raeburn 10228: }
10229: }
1.152 raeburn 10230: return group;
1.150 raeburn 10231: }
10232:
10233: // ]]>
10234: </script>
10235:
10236: END
1.152 raeburn 10237:
1.150 raeburn 10238: }
10239:
1.165 raeburn 10240: sub recaptcha_js {
10241: my %lt = &captcha_phrases();
10242: return <<"END";
10243:
10244: <script type="text/javascript">
10245: // <![CDATA[
10246:
10247: function updateCaptcha(caller,context) {
10248: var privitem;
10249: var pubitem;
10250: var privtext;
10251: var pubtext;
10252: if (document.getElementById(context+'_recaptchapub')) {
10253: pubitem = document.getElementById(context+'_recaptchapub');
10254: } else {
10255: return;
10256: }
10257: if (document.getElementById(context+'_recaptchapriv')) {
10258: privitem = document.getElementById(context+'_recaptchapriv');
10259: } else {
10260: return;
10261: }
10262: if (document.getElementById(context+'_recaptchapubtxt')) {
10263: pubtext = document.getElementById(context+'_recaptchapubtxt');
10264: } else {
10265: return;
10266: }
10267: if (document.getElementById(context+'_recaptchaprivtxt')) {
10268: privtext = document.getElementById(context+'_recaptchaprivtxt');
10269: } else {
10270: return;
10271: }
10272: if (caller.checked) {
10273: if (caller.value == 'recaptcha') {
10274: pubitem.type = 'text';
10275: privitem.type = 'text';
10276: pubitem.size = '40';
10277: privitem.size = '40';
10278: pubtext.innerHTML = "$lt{'pub'}";
10279: privtext.innerHTML = "$lt{'priv'}";
10280: } else {
10281: pubitem.type = 'hidden';
10282: privitem.type = 'hidden';
10283: pubtext.innerHTML = '';
10284: privtext.innerHTML = '';
10285: }
10286: }
10287: return;
10288: }
10289:
10290: // ]]>
10291: </script>
10292:
10293: END
10294:
10295: }
10296:
1.192 raeburn 10297: sub credits_js {
10298: return <<"END";
10299:
10300: <script type="text/javascript">
10301: // <![CDATA[
10302:
10303: function toggleCredits(domForm) {
10304: if (document.getElementById('credits')) {
10305: creditsitem = document.getElementById('credits');
10306: var creditsLength = domForm.coursecredits.length;
10307: if (creditsLength) {
10308: var currval;
10309: for (var i=0; i<creditsLength; i++) {
10310: if (domForm.coursecredits[i].checked) {
10311: currval = domForm.coursecredits[i].value;
10312: }
10313: }
10314: if (currval == 1) {
10315: creditsitem.style.display = 'block';
10316: } else {
10317: creditsitem.style.display = 'none';
10318: }
10319: }
10320: }
10321: return;
10322: }
10323:
10324: // ]]>
10325: </script>
10326:
10327: END
10328:
10329: }
10330:
1.165 raeburn 10331: sub captcha_phrases {
10332: return &Apache::lonlocal::texthash (
10333: priv => 'Private key',
10334: pub => 'Public key',
10335: original => 'original (CAPTCHA)',
10336: recaptcha => 'successor (ReCAPTCHA)',
10337: notused => 'unused',
10338: );
10339: }
10340:
1.205 raeburn 10341: sub devalidate_remote_domconfs {
1.212 raeburn 10342: my ($dom,$cachekeys) = @_;
10343: return unless (ref($cachekeys) eq 'HASH');
1.205 raeburn 10344: my %servers = &Apache::lonnet::internet_dom_servers($dom);
10345: my %thismachine;
10346: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
1.212 raeburn 10347: my @posscached = ('domainconfig','domdefaults');
1.205 raeburn 10348: if (keys(%servers) > 1) {
10349: foreach my $server (keys(%servers)) {
10350: next if ($thismachine{$server});
1.212 raeburn 10351: my @cached;
10352: foreach my $name (@posscached) {
10353: if ($cachekeys->{$name}) {
10354: push(@cached,&escape($name).':'.&escape($dom));
10355: }
10356: }
10357: if (@cached) {
10358: &Apache::lonnet::remote_devalidate_cache($server,\@cached);
10359: }
1.205 raeburn 10360: }
10361: }
10362: return;
10363: }
10364:
1.3 raeburn 10365: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>