Annotation of loncom/interface/domainprefs.pm, revision 1.228
1.1 raeburn 1: # The LearningOnline Network with CAPA
2: # Handler to set domain-wide configuration settings
3: #
1.228 ! raeburn 4: # $Id: domainprefs.pm,v 1.227 2014/02/28 19:20:05 bisitz 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 => '',}],
242: },
1.110 raeburn 243: 'login' =>
1.30 raeburn 244: { text => 'Log-in page options',
1.67 raeburn 245: help => 'Domain_Configuration_Login_Page',
1.168 raeburn 246: header => [{col1 => 'Log-in Page Items',
247: col2 => '',},
248: {col1 => 'Log-in Help',
249: col2 => 'Value'}],
1.30 raeburn 250: },
1.43 raeburn 251: 'defaults' =>
1.141 raeburn 252: { text => 'Default authentication/language/timezone/portal',
1.67 raeburn 253: help => 'Domain_Configuration_LangTZAuth',
1.43 raeburn 254: header => [{col1 => 'Setting',
255: col2 => 'Value'}],
256: },
1.30 raeburn 257: 'quotas' =>
1.197 raeburn 258: { text => 'Blogs, personal web pages, webDAV/quotas, portfolios',
1.67 raeburn 259: help => 'Domain_Configuration_Quotas',
1.77 raeburn 260: header => [{col1 => 'User affiliation',
1.72 raeburn 261: col2 => 'Available tools',
1.213 raeburn 262: col3 => 'Quotas, MB; (Authoring requires role)',}],
1.30 raeburn 263: },
264: 'autoenroll' =>
265: { text => 'Auto-enrollment settings',
1.67 raeburn 266: help => 'Domain_Configuration_Auto_Enrollment',
1.30 raeburn 267: header => [{col1 => 'Configuration setting',
268: col2 => 'Value(s)'}],
269: },
270: 'autoupdate' =>
271: { text => 'Auto-update settings',
1.67 raeburn 272: help => 'Domain_Configuration_Auto_Updates',
1.30 raeburn 273: header => [{col1 => 'Setting',
274: col2 => 'Value',},
1.131 raeburn 275: {col1 => 'Setting',
276: col2 => 'Affiliation'},
1.43 raeburn 277: {col1 => 'User population',
1.227 bisitz 278: col2 => 'Updatable user data'}],
1.30 raeburn 279: },
1.125 raeburn 280: 'autocreate' =>
281: { text => 'Auto-course creation settings',
282: help => 'Domain_Configuration_Auto_Creation',
283: header => [{col1 => 'Configuration Setting',
284: col2 => 'Value',}],
285: },
1.30 raeburn 286: 'directorysrch' =>
287: { text => 'Institutional directory searches',
1.67 raeburn 288: help => 'Domain_Configuration_InstDirectory_Search',
1.30 raeburn 289: header => [{col1 => 'Setting',
290: col2 => 'Value',}],
291: },
292: 'contacts' =>
293: { text => 'Contact Information',
1.67 raeburn 294: help => 'Domain_Configuration_Contact_Info',
1.30 raeburn 295: header => [{col1 => 'Setting',
296: col2 => 'Value',}],
297: },
298: 'usercreation' =>
299: { text => 'User creation',
1.67 raeburn 300: help => 'Domain_Configuration_User_Creation',
1.43 raeburn 301: header => [{col1 => 'Format rule type',
302: col2 => 'Format rules in force'},
1.34 raeburn 303: {col1 => 'User account creation',
304: col2 => 'Usernames which may be created',},
1.30 raeburn 305: {col1 => 'Context',
1.43 raeburn 306: col2 => 'Assignable authentication types'}],
1.30 raeburn 307: },
1.224 raeburn 308: 'selfcreation' =>
309: { text => 'Users self-creating accounts',
310: help => 'Domain_Configuration_Self_Creation',
311: header => [{col1 => 'Self-creation with institutional username',
312: col2 => 'Enabled?'},
313: {col1 => 'Institutional user type (login/SSO self-creation)',
314: col2 => 'Information user can enter'},
315: {col1 => 'Self-creation with e-mail as username',
316: col2 => 'Settings'}],
317: },
1.69 raeburn 318: 'usermodification' =>
1.33 raeburn 319: { text => 'User modification',
1.67 raeburn 320: help => 'Domain_Configuration_User_Modification',
1.33 raeburn 321: header => [{col1 => 'Target user has role',
1.227 bisitz 322: col2 => 'User information updatable in author context'},
1.33 raeburn 323: {col1 => 'Target user has role',
1.227 bisitz 324: col2 => 'User information updatable in course context'}],
1.33 raeburn 325: },
1.69 raeburn 326: 'scantron' =>
1.95 www 327: { text => 'Bubblesheet format file',
1.67 raeburn 328: help => 'Domain_Configuration_Scantron_Format',
1.46 raeburn 329: header => [ {col1 => 'Item',
330: col2 => '',
331: }],
332: },
1.86 raeburn 333: 'requestcourses' =>
334: {text => 'Request creation of courses',
335: help => 'Domain_Configuration_Request_Courses',
336: header => [{col1 => 'User affiliation',
1.102 raeburn 337: col2 => 'Availability/Processing of requests',},
338: {col1 => 'Setting',
1.216 raeburn 339: col2 => 'Value'},
340: {col1 => 'Available textbooks',
341: col2 => ''}],
1.86 raeburn 342: },
1.163 raeburn 343: 'requestauthor' =>
1.223 bisitz 344: {text => 'Request Authoring Space',
1.163 raeburn 345: help => 'Domain_Configuration_Request_Author',
346: header => [{col1 => 'User affiliation',
347: col2 => 'Availability/Processing of requests',},
348: {col1 => 'Setting',
349: col2 => 'Value'}],
350: },
1.69 raeburn 351: 'coursecategories' =>
1.120 raeburn 352: { text => 'Cataloging of courses/communities',
1.67 raeburn 353: help => 'Domain_Configuration_Cataloging_Courses',
1.69 raeburn 354: header => [{col1 => 'Category settings',
1.57 raeburn 355: col2 => '',},
356: {col1 => 'Categories',
357: col2 => '',
358: }],
1.69 raeburn 359: },
360: 'serverstatuses' =>
1.77 raeburn 361: {text => 'Access to server status pages',
1.69 raeburn 362: help => 'Domain_Configuration_Server_Status',
363: header => [{col1 => 'Status Page',
364: col2 => 'Other named users',
365: col3 => 'Specific IPs',
366: }],
367: },
1.118 jms 368: 'helpsettings' =>
369: {text => 'Help page settings',
370: help => 'Domain_Configuration_Help_Settings',
1.166 raeburn 371: header => [{col1 => 'Help Settings (logged-in users)',
372: col2 => 'Value'}],
1.118 jms 373: },
1.121 raeburn 374: 'coursedefaults' =>
375: {text => 'Course/Community defaults',
376: help => 'Domain_Configuration_Course_Defaults',
1.139 raeburn 377: header => [{col1 => 'Defaults which can be overridden in each course by a CC',
378: col2 => 'Value',},
379: {col1 => 'Defaults which can be overridden for each course by a DC',
380: col2 => 'Value',},],
1.121 raeburn 381: },
1.120 raeburn 382: 'privacy' =>
383: {text => 'User Privacy',
384: help => 'Domain_Configuration_User_Privacy',
385: header => [{col1 => 'Setting',
386: col2 => 'Value',}],
387: },
1.141 raeburn 388: 'usersessions' =>
1.145 raeburn 389: {text => 'User session hosting/offloading',
1.137 raeburn 390: help => 'Domain_Configuration_User_Sessions',
1.145 raeburn 391: header => [{col1 => 'Domain server',
392: col2 => 'Servers to offload sessions to when busy'},
393: {col1 => 'Hosting of users from other domains',
1.137 raeburn 394: col2 => 'Rules'},
395: {col1 => "Hosting domain's own users elsewhere",
396: col2 => 'Rules'}],
397: },
1.150 raeburn 398: 'loadbalancing' =>
1.185 raeburn 399: {text => 'Dedicated Load Balancer(s)',
1.150 raeburn 400: help => 'Domain_Configuration_Load_Balancing',
1.171 raeburn 401: header => [{col1 => 'Balancers',
1.150 raeburn 402: col2 => 'Default destinations',
1.183 bisitz 403: col3 => 'User affiliation',
1.150 raeburn 404: col4 => 'Overrides'},
405: ],
406: },
1.3 raeburn 407: );
1.110 raeburn 408: if (keys(%servers) > 1) {
409: $prefs{'login'} = { text => 'Log-in page options',
410: help => 'Domain_Configuration_Login_Page',
411: header => [{col1 => 'Log-in Service',
412: col2 => 'Server Setting',},
413: {col1 => 'Log-in Page Items',
1.168 raeburn 414: col2 => ''},
415: {col1 => 'Log-in Help',
416: col2 => 'Value'}],
1.110 raeburn 417: };
418: }
1.174 foxr 419:
1.6 raeburn 420: my @roles = ('student','coordinator','author','admin');
1.30 raeburn 421: my @actions = &Apache::loncommon::get_env_multiple('form.actions');
1.3 raeburn 422: &Apache::lonhtmlcommon::add_breadcrumb
1.30 raeburn 423: ({href=>"javascript:changePage(document.$phase,'pickactions')",
1.133 raeburn 424: text=>"Settings to display/modify"});
1.9 raeburn 425: my $confname = $dom.'-domainconfig';
1.174 foxr 426:
1.3 raeburn 427: if ($phase eq 'process') {
1.212 raeburn 428: my $result = &Apache::lonconfigsettings::make_changes($r,$dom,$phase,$context,\@prefs_order,
429: \%prefs,\%domconfig,$confname,\@roles);
1.224 raeburn 430: if ((ref($result) eq 'HASH') && (keys(%{$result}))) {
1.205 raeburn 431: $r->rflush();
1.212 raeburn 432: &devalidate_remote_domconfs($dom,$result);
1.205 raeburn 433: }
1.30 raeburn 434: } elsif ($phase eq 'display') {
1.192 raeburn 435: my $js = &recaptcha_js().
436: &credits_js();
1.171 raeburn 437: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
1.152 raeburn 438: my ($othertitle,$usertypes,$types) =
439: &Apache::loncommon::sorted_inst_types($dom);
1.171 raeburn 440: $js .= &lonbalance_targets_js($dom,$types,\%servers,
441: $domconfig{'loadbalancing'}).
1.170 raeburn 442: &new_spares_js().
443: &common_domprefs_js().
444: &Apache::loncommon::javascript_array_indexof();
1.152 raeburn 445: }
1.216 raeburn 446: if (grep(/^requestcourses$/,@actions)) {
447: my $javascript_validations;
448: my $coursebrowserjs=&Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'});
449: $js .= <<END;
450: <script type="text/javascript">
451: $javascript_validations
452: </script>
453: $coursebrowserjs
454: END
455: }
1.150 raeburn 456: &Apache::lonconfigsettings::display_settings($r,$dom,$phase,$context,\@prefs_order,\%prefs,\%domconfig,$confname,$js);
1.1 raeburn 457: } else {
1.180 raeburn 458: # check if domconfig user exists for the domain.
459: my $servadm = $r->dir_config('lonAdmEMail');
460: my ($configuserok,$author_ok,$switchserver) =
461: &config_check($dom,$confname,$servadm);
462: unless ($configuserok eq 'ok') {
1.181 raeburn 463: &Apache::lonconfigsettings::print_header($r,$phase,$context);
464: $r->print(&mt('The domain configuration user "[_1]" has yet to be created.',
1.210 raeburn 465: $confname).
1.181 raeburn 466: '<br />'
467: );
1.180 raeburn 468: if ($switchserver) {
1.181 raeburn 469: $r->print(&mt('Ordinarily, that domain configuration user is created when the ./UPDATE script is run to install LON-CAPA for the first time.').
470: '<br />'.
471: &mt('However, that does not apply when new domains are added to a multi-domain server, and ./UPDATE has not been run recently.').
472: '<br />'.
473: &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).
474: '<br />'.
475: &mt('To do that now, use the following link: [_1]',$switchserver)
476: );
477: } else {
478: $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.').
479: '<br />'.
480: &mt('Once that is done, you will be able to use the web-based "Set domain configuration" to configure the domain')
481: );
1.180 raeburn 482: }
483: $r->print(&Apache::loncommon::end_page());
484: return OK;
485: }
1.21 raeburn 486: if (keys(%domconfig) == 0) {
487: my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
1.29 raeburn 488: my @ids=&Apache::lonnet::current_machine_ids();
489: if (!grep(/^\Q$primarylibserv\E$/,@ids)) {
1.21 raeburn 490: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.41 raeburn 491: my @loginimages = ('img','logo','domlogo','login');
1.21 raeburn 492: my $custom_img_count = 0;
493: foreach my $img (@loginimages) {
494: if ($designhash{$dom.'.login.'.$img} ne '') {
495: $custom_img_count ++;
496: }
497: }
498: foreach my $role (@roles) {
499: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
500: $custom_img_count ++;
501: }
502: }
503: if ($custom_img_count > 0) {
1.94 raeburn 504: &Apache::lonconfigsettings::print_header($r,$phase,$context);
1.21 raeburn 505: my $switch_server = &check_switchserver($dom,$confname);
1.29 raeburn 506: $r->print(
507: &mt('Domain configuration settings have yet to be saved for this domain via the web-based domain preferences interface.').'<br />'.
508: &mt("While this remains so, you must switch to the domain's primary library server in order to update settings.").'<br /><br />'.
509: &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 />'.
510: &mt("However, you will still need to switch to the domain's primary library server to upload new images or logos.").'<br /><br />');
511: if ($switch_server) {
1.30 raeburn 512: $r->print($switch_server.' '.&mt('to primary library server for domain: [_1]',$dom));
1.29 raeburn 513: }
1.91 raeburn 514: $r->print(&Apache::loncommon::end_page());
1.21 raeburn 515: return OK;
516: }
517: }
518: }
1.91 raeburn 519: &Apache::lonconfigsettings::display_choices($r,$phase,$context,\@prefs_order,\%prefs);
1.3 raeburn 520: }
521: return OK;
522: }
523:
524: sub process_changes {
1.205 raeburn 525: my ($r,$dom,$confname,$action,$roles,$values,$lastactref) = @_;
1.92 raeburn 526: my %domconfig;
527: if (ref($values) eq 'HASH') {
528: %domconfig = %{$values};
529: }
1.3 raeburn 530: my $output;
531: if ($action eq 'login') {
1.205 raeburn 532: $output = &modify_login($r,$dom,$confname,$lastactref,%domconfig);
1.6 raeburn 533: } elsif ($action eq 'rolecolors') {
1.9 raeburn 534: $output = &modify_rolecolors($r,$dom,$confname,$roles,
1.205 raeburn 535: $lastactref,%domconfig);
1.3 raeburn 536: } elsif ($action eq 'quotas') {
1.216 raeburn 537: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.3 raeburn 538: } elsif ($action eq 'autoenroll') {
1.205 raeburn 539: $output = &modify_autoenroll($dom,$lastactref,%domconfig);
1.3 raeburn 540: } elsif ($action eq 'autoupdate') {
541: $output = &modify_autoupdate($dom,%domconfig);
1.125 raeburn 542: } elsif ($action eq 'autocreate') {
543: $output = &modify_autocreate($dom,%domconfig);
1.23 raeburn 544: } elsif ($action eq 'directorysrch') {
545: $output = &modify_directorysrch($dom,%domconfig);
1.27 raeburn 546: } elsif ($action eq 'usercreation') {
1.28 raeburn 547: $output = &modify_usercreation($dom,%domconfig);
1.224 raeburn 548: } elsif ($action eq 'selfcreation') {
549: $output = &modify_selfcreation($dom,%domconfig);
1.33 raeburn 550: } elsif ($action eq 'usermodification') {
551: $output = &modify_usermodification($dom,%domconfig);
1.28 raeburn 552: } elsif ($action eq 'contacts') {
1.205 raeburn 553: $output = &modify_contacts($dom,$lastactref,%domconfig);
1.43 raeburn 554: } elsif ($action eq 'defaults') {
1.212 raeburn 555: $output = &modify_defaults($dom,$lastactref,%domconfig);
1.46 raeburn 556: } elsif ($action eq 'scantron') {
1.205 raeburn 557: $output = &modify_scantron($r,$dom,$confname,$lastactref,%domconfig);
1.48 raeburn 558: } elsif ($action eq 'coursecategories') {
559: $output = &modify_coursecategories($dom,%domconfig);
1.69 raeburn 560: } elsif ($action eq 'serverstatuses') {
561: $output = &modify_serverstatuses($dom,%domconfig);
1.86 raeburn 562: } elsif ($action eq 'requestcourses') {
1.216 raeburn 563: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.163 raeburn 564: } elsif ($action eq 'requestauthor') {
1.216 raeburn 565: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.118 jms 566: } elsif ($action eq 'helpsettings') {
1.122 jms 567: $output = &modify_helpsettings($r,$dom,$confname,%domconfig);
1.121 raeburn 568: } elsif ($action eq 'coursedefaults') {
1.212 raeburn 569: $output = &modify_coursedefaults($dom,$lastactref,%domconfig);
1.137 raeburn 570: } elsif ($action eq 'usersessions') {
1.212 raeburn 571: $output = &modify_usersessions($dom,$lastactref,%domconfig);
1.150 raeburn 572: } elsif ($action eq 'loadbalancing') {
573: $output = &modify_loadbalancing($dom,%domconfig);
1.3 raeburn 574: }
575: return $output;
576: }
577:
578: sub print_config_box {
1.9 raeburn 579: my ($r,$dom,$confname,$phase,$action,$item,$settings) = @_;
1.30 raeburn 580: my $rowtotal = 0;
1.49 raeburn 581: my $output;
582: if ($action eq 'coursecategories') {
583: $output = &coursecategories_javascript($settings);
1.91 raeburn 584: }
1.49 raeburn 585: $output .=
1.30 raeburn 586: '<table class="LC_nested_outer">
1.3 raeburn 587: <tr>
1.66 raeburn 588: <th align="left" valign="middle"><span class="LC_nobreak">'.
589: &mt($item->{text}).' '.
590: &Apache::loncommon::help_open_topic($item->{'help'}).'</span></th>'."\n".
591: '</tr>';
1.30 raeburn 592: $rowtotal ++;
1.110 raeburn 593: my $numheaders = 1;
594: if (ref($item->{'header'}) eq 'ARRAY') {
595: $numheaders = scalar(@{$item->{'header'}});
596: }
597: if ($numheaders > 1) {
1.64 raeburn 598: my $colspan = '';
1.145 raeburn 599: my $rightcolspan = '';
1.210 raeburn 600: if (($action eq 'rolecolors') || ($action eq 'coursecategories') ||
1.168 raeburn 601: (($action eq 'login') && ($numheaders < 3))) {
1.64 raeburn 602: $colspan = ' colspan="2"';
603: }
1.145 raeburn 604: if ($action eq 'usersessions') {
605: $rightcolspan = ' colspan="3"';
606: }
1.30 raeburn 607: $output .= '
1.3 raeburn 608: <tr>
609: <td>
610: <table class="LC_nested">
611: <tr class="LC_info_row">
1.59 bisitz 612: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[0]->{'col1'}).'</td>
1.145 raeburn 613: <td class="LC_right_item"'.$rightcolspan.'>'.&mt($item->{'header'}->[0]->{'col2'}).'</td>
1.30 raeburn 614: </tr>';
1.69 raeburn 615: $rowtotal ++;
1.6 raeburn 616: if ($action eq 'autoupdate') {
1.30 raeburn 617: $output .= &print_autoupdate('top',$dom,$settings,\$rowtotal);
1.28 raeburn 618: } elsif ($action eq 'usercreation') {
1.33 raeburn 619: $output .= &print_usercreation('top',$dom,$settings,\$rowtotal);
1.224 raeburn 620: } elsif ($action eq 'selfcreation') {
621: $output .= &print_selfcreation('top',$dom,$settings,\$rowtotal);
1.33 raeburn 622: } elsif ($action eq 'usermodification') {
623: $output .= &print_usermodification('top',$dom,$settings,\$rowtotal);
1.57 raeburn 624: } elsif ($action eq 'coursecategories') {
625: $output .= &print_coursecategories('top',$dom,$item,$settings,\$rowtotal);
1.110 raeburn 626: } elsif ($action eq 'login') {
1.168 raeburn 627: if ($numheaders == 3) {
628: $colspan = ' colspan="2"';
629: $output .= &print_login('service',$dom,$confname,$phase,$settings,\$rowtotal);
630: } else {
631: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal);
632: }
1.102 raeburn 633: } elsif ($action eq 'requestcourses') {
634: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.163 raeburn 635: } elsif ($action eq 'requestauthor') {
636: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.137 raeburn 637: } elsif ($action eq 'usersessions') {
638: $output .= &print_usersessions('top',$dom,$settings,\$rowtotal);
1.122 jms 639: } elsif ($action eq 'rolecolors') {
1.30 raeburn 640: $output .= &print_rolecolors($phase,'student',$dom,$confname,$settings,\$rowtotal);
1.139 raeburn 641: } elsif ($action eq 'coursedefaults') {
642: $output .= &print_coursedefaults('top',$dom,$settings,\$rowtotal);
1.6 raeburn 643: }
1.30 raeburn 644: $output .= '
1.6 raeburn 645: </table>
646: </td>
647: </tr>
648: <tr>
649: <td>
650: <table class="LC_nested">
651: <tr class="LC_info_row">
1.59 bisitz 652: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col1'}).'</td>';
1.57 raeburn 653: $output .= '
1.59 bisitz 654: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col2'}).'</td>
1.30 raeburn 655: </tr>';
656: $rowtotal ++;
1.6 raeburn 657: if ($action eq 'autoupdate') {
1.131 raeburn 658: $output .= &print_autoupdate('middle',$dom,$settings,\$rowtotal).'
659: </table>
660: </td>
661: </tr>
662: <tr>
663: <td>
664: <table class="LC_nested">
665: <tr class="LC_info_row">
666: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
667: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
668: &print_autoupdate('bottom',$dom,$settings,\$rowtotal);
669: $rowtotal ++;
1.28 raeburn 670: } elsif ($action eq 'usercreation') {
1.34 raeburn 671: $output .= &print_usercreation('middle',$dom,$settings,\$rowtotal).'
672: </table>
673: </td>
674: </tr>
675: <tr>
676: <td>
677: <table class="LC_nested">
678: <tr class="LC_info_row">
1.59 bisitz 679: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
680: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
1.34 raeburn 681: &print_usercreation('bottom',$dom,$settings,\$rowtotal);
682: $rowtotal ++;
1.224 raeburn 683: } elsif ($action eq 'selfcreation') {
684: $output .= &print_selfcreation('middle',$dom,$settings,\$rowtotal).'
1.63 raeburn 685: </table>
686: </td>
687: </tr>
688: <tr>
689: <td>
690: <table class="LC_nested">
691: <tr class="LC_info_row">
692: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1.224 raeburn 693: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
694: </tr>'.
695: &print_selfcreation('bottom',$dom,$settings,\$rowtotal);
1.63 raeburn 696: $rowtotal ++;
1.224 raeburn 697: } elsif ($action eq 'usermodification') {
698: $output .= &print_usermodification('middle',$dom,$settings,\$rowtotal);
1.57 raeburn 699: } elsif ($action eq 'coursecategories') {
700: $output .= &print_coursecategories('bottom',$dom,$item,$settings,\$rowtotal);
1.110 raeburn 701: } elsif ($action eq 'login') {
1.168 raeburn 702: if ($numheaders == 3) {
703: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal).'
704: </table>
705: </td>
706: </tr>
707: <tr>
708: <td>
709: <table class="LC_nested">
710: <tr class="LC_info_row">
711: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1.216 raeburn 712: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td></tr>'.
1.168 raeburn 713: &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
714: $rowtotal ++;
715: } else {
716: $output .= &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
717: }
1.102 raeburn 718: } elsif ($action eq 'requestcourses') {
1.216 raeburn 719: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal).
720: &print_studentcode($settings,\$rowtotal).'
721: </table>
722: </td>
723: </tr>
724: <tr>
725: <td>
726: <table class="LC_nested">
727: <tr class="LC_info_row">
728: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
729: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
730: &print_textbookcourses($dom,$settings,\$rowtotal);
1.163 raeburn 731: } elsif ($action eq 'requestauthor') {
732: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
1.137 raeburn 733: } elsif ($action eq 'usersessions') {
1.145 raeburn 734: $output .= &print_usersessions('middle',$dom,$settings,\$rowtotal).'
735: </table>
736: </td>
737: </tr>
738: <tr>
739: <td>
740: <table class="LC_nested">
741: <tr class="LC_info_row">
742: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
743: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
744: &print_usersessions('bottom',$dom,$settings,\$rowtotal);
745: $rowtotal ++;
1.139 raeburn 746: } elsif ($action eq 'coursedefaults') {
747: $output .= &print_coursedefaults('bottom',$dom,$settings,\$rowtotal);
1.122 jms 748: } elsif ($action eq 'rolecolors') {
1.30 raeburn 749: $output .= &print_rolecolors($phase,'coordinator',$dom,$confname,$settings,\$rowtotal).'
1.6 raeburn 750: </table>
751: </td>
752: </tr>
753: <tr>
754: <td>
755: <table class="LC_nested">
756: <tr class="LC_info_row">
1.69 raeburn 757: <td class="LC_left_item"'.$colspan.' valign="top">'.
758: &mt($item->{'header'}->[2]->{'col1'}).'</td>
759: <td class="LC_right_item" valign="top">'.
760: &mt($item->{'header'}->[2]->{'col2'}).'</td>
1.3 raeburn 761: </tr>'.
1.30 raeburn 762: &print_rolecolors($phase,'author',$dom,$confname,$settings,\$rowtotal).'
1.3 raeburn 763: </table>
764: </td>
765: </tr>
766: <tr>
767: <td>
768: <table class="LC_nested">
769: <tr class="LC_info_row">
1.59 bisitz 770: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
771: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
1.3 raeburn 772: </tr>'.
1.30 raeburn 773: &print_rolecolors($phase,'admin',$dom,$confname,$settings,\$rowtotal);
774: $rowtotal += 2;
1.6 raeburn 775: }
1.3 raeburn 776: } else {
1.30 raeburn 777: $output .= '
1.3 raeburn 778: <tr>
779: <td>
780: <table class="LC_nested">
1.30 raeburn 781: <tr class="LC_info_row">';
1.24 raeburn 782: if (($action eq 'login') || ($action eq 'directorysrch')) {
1.30 raeburn 783: $output .= '
1.59 bisitz 784: <td class="LC_left_item" colspan="2">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
1.69 raeburn 785: } elsif ($action eq 'serverstatuses') {
786: $output .= '
787: <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).
788: '<br />('.&mt('Automatic access for Dom. Coords.').')</td>';
789:
1.6 raeburn 790: } else {
1.30 raeburn 791: $output .= '
1.69 raeburn 792: <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
793: }
1.72 raeburn 794: if (defined($item->{'header'}->[0]->{'col3'})) {
795: $output .= '<td class="LC_left_item" valign="top">'.
796: &mt($item->{'header'}->[0]->{'col2'});
797: if ($action eq 'serverstatuses') {
798: $output .= '<br />(<tt>'.&mt('user1:domain1,user2:domain2 etc.').'</tt>)';
799: }
1.69 raeburn 800: } else {
801: $output .= '<td class="LC_right_item" valign="top">'.
802: &mt($item->{'header'}->[0]->{'col2'});
803: }
804: $output .= '</td>';
805: if ($item->{'header'}->[0]->{'col3'}) {
1.150 raeburn 806: if (defined($item->{'header'}->[0]->{'col4'})) {
807: $output .= '<td class="LC_left_item" valign="top">'.
808: &mt($item->{'header'}->[0]->{'col3'});
809: } else {
810: $output .= '<td class="LC_right_item" valign="top">'.
811: &mt($item->{'header'}->[0]->{'col3'});
812: }
1.69 raeburn 813: if ($action eq 'serverstatuses') {
814: $output .= '<br />(<tt>'.&mt('IP1,IP2 etc.').'</tt>)';
815: }
816: $output .= '</td>';
1.6 raeburn 817: }
1.150 raeburn 818: if ($item->{'header'}->[0]->{'col4'}) {
819: $output .= '<td class="LC_right_item" valign="top">'.
820: &mt($item->{'header'}->[0]->{'col4'});
821: }
1.69 raeburn 822: $output .= '</tr>';
1.48 raeburn 823: $rowtotal ++;
1.168 raeburn 824: if ($action eq 'quotas') {
1.86 raeburn 825: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.3 raeburn 826: } elsif ($action eq 'autoenroll') {
1.30 raeburn 827: $output .= &print_autoenroll($dom,$settings,\$rowtotal);
1.125 raeburn 828: } elsif ($action eq 'autocreate') {
829: $output .= &print_autocreate($dom,$settings,\$rowtotal);
1.23 raeburn 830: } elsif ($action eq 'directorysrch') {
1.30 raeburn 831: $output .= &print_directorysrch($dom,$settings,\$rowtotal);
1.28 raeburn 832: } elsif ($action eq 'contacts') {
1.30 raeburn 833: $output .= &print_contacts($dom,$settings,\$rowtotal);
1.43 raeburn 834: } elsif ($action eq 'defaults') {
1.212 raeburn 835: $output .= &print_defaults($dom,$settings,\$rowtotal);
1.46 raeburn 836: } elsif ($action eq 'scantron') {
837: $output .= &print_scantronformat($r,$dom,$confname,$settings,\$rowtotal);
1.69 raeburn 838: } elsif ($action eq 'serverstatuses') {
839: $output .= &print_serverstatuses($dom,$settings,\$rowtotal);
1.118 jms 840: } elsif ($action eq 'helpsettings') {
1.168 raeburn 841: $output .= &print_helpsettings($dom,$confname,$settings,\$rowtotal);
1.150 raeburn 842: } elsif ($action eq 'loadbalancing') {
843: $output .= &print_loadbalancing($dom,$settings,\$rowtotal);
1.121 raeburn 844: }
1.3 raeburn 845: }
1.30 raeburn 846: $output .= '
1.3 raeburn 847: </table>
848: </td>
849: </tr>
1.30 raeburn 850: </table><br />';
851: return ($output,$rowtotal);
1.1 raeburn 852: }
853:
1.3 raeburn 854: sub print_login {
1.168 raeburn 855: my ($caller,$dom,$confname,$phase,$settings,$rowtotal) = @_;
1.110 raeburn 856: my ($css_class,$datatable);
1.6 raeburn 857: my %choices = &login_choices();
1.110 raeburn 858:
1.168 raeburn 859: if ($caller eq 'service') {
1.149 raeburn 860: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.110 raeburn 861: my $choice = $choices{'disallowlogin'};
862: $css_class = ' class="LC_odd_row"';
1.128 raeburn 863: $datatable .= '<tr'.$css_class.'><td>'.$choice.'</td>'.
1.110 raeburn 864: '<td align="right"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1.128 raeburn 865: '<th>'.$choices{'server'}.'</th>'.
866: '<th>'.$choices{'serverpath'}.'</th>'.
867: '<th>'.$choices{'custompath'}.'</th>'.
868: '<th><span class="LC_nobreak">'.$choices{'exempt'}.'</span></th></tr>'."\n";
1.110 raeburn 869: my %disallowed;
870: if (ref($settings) eq 'HASH') {
871: if (ref($settings->{'loginvia'}) eq 'HASH') {
872: %disallowed = %{$settings->{'loginvia'}};
873: }
874: }
875: foreach my $lonhost (sort(keys(%servers))) {
876: my $direct = 'selected="selected"';
1.128 raeburn 877: if (ref($disallowed{$lonhost}) eq 'HASH') {
878: if ($disallowed{$lonhost}{'server'} ne '') {
879: $direct = '';
880: }
1.110 raeburn 881: }
1.115 raeburn 882: $datatable .= '<tr><td>'.$servers{$lonhost}.'</td>'.
1.128 raeburn 883: '<td><select name="'.$lonhost.'_server">'.
1.110 raeburn 884: '<option value=""'.$direct.'>'.$choices{'directlogin'}.
885: '</option>';
1.184 raeburn 886: foreach my $hostid (sort(keys(%servers))) {
1.115 raeburn 887: next if ($servers{$hostid} eq $servers{$lonhost});
1.110 raeburn 888: my $selected = '';
1.128 raeburn 889: if (ref($disallowed{$lonhost}) eq 'HASH') {
890: if ($hostid eq $disallowed{$lonhost}{'server'}) {
891: $selected = 'selected="selected"';
892: }
1.110 raeburn 893: }
894: $datatable .= '<option value="'.$hostid.'"'.$selected.'>'.
895: $servers{$hostid}.'</option>';
896: }
1.128 raeburn 897: $datatable .= '</select></td>'.
898: '<td><select name="'.$lonhost.'_serverpath">';
899: foreach my $path ('','/','/adm/login','/adm/roles','custom') {
900: my $pathname = $path;
901: if ($path eq 'custom') {
902: $pathname = &mt('Custom Path').' ->';
903: }
904: my $selected = '';
905: if (ref($disallowed{$lonhost}) eq 'HASH') {
906: if ($path eq $disallowed{$lonhost}{'serverpath'}) {
907: $selected = 'selected="selected"';
908: }
909: } elsif ($path eq '') {
910: $selected = 'selected="selected"';
911: }
912: $datatable .= '<option value="'.$path.'"'.$selected.'>'.$pathname.'</option>';
913: }
914: $datatable .= '</select></td>';
915: my ($custom,$exempt);
916: if (ref($disallowed{$lonhost}) eq 'HASH') {
917: $custom = $disallowed{$lonhost}{'custompath'};
918: $exempt = $disallowed{$lonhost}{'exempt'};
919: }
920: $datatable .= '<td><input type="text" name="'.$lonhost.'_custompath" size="6" value="'.$custom.'" /></td>'.
921: '<td><input type="text" name="'.$lonhost.'_exempt" size="8" value="'.$exempt.'" /></td>'.
922: '</tr>';
1.110 raeburn 923: }
924: $datatable .= '</table></td></tr>';
925: return $datatable;
1.168 raeburn 926: } elsif ($caller eq 'page') {
927: my %defaultchecked = (
928: 'coursecatalog' => 'on',
1.188 raeburn 929: 'helpdesk' => 'on',
1.168 raeburn 930: 'adminmail' => 'off',
931: 'newuser' => 'off',
932: );
1.188 raeburn 933: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.168 raeburn 934: my (%checkedon,%checkedoff);
1.42 raeburn 935: foreach my $item (@toggles) {
1.168 raeburn 936: if ($defaultchecked{$item} eq 'on') {
937: $checkedon{$item} = ' checked="checked" ';
1.42 raeburn 938: $checkedoff{$item} = ' ';
1.168 raeburn 939: } elsif ($defaultchecked{$item} eq 'off') {
940: $checkedoff{$item} = ' checked="checked" ';
1.42 raeburn 941: $checkedon{$item} = ' ';
942: }
1.1 raeburn 943: }
1.168 raeburn 944: my @images = ('img','logo','domlogo','login');
945: my @logintext = ('textcol','bgcol');
946: my @bgs = ('pgbg','mainbg','sidebg');
947: my @links = ('link','alink','vlink');
948: my %designhash = &Apache::loncommon::get_domainconf($dom);
949: my %defaultdesign = %Apache::loncommon::defaultdesign;
950: my (%is_custom,%designs);
951: my %defaults = (
952: font => $defaultdesign{'login.font'},
953: );
1.6 raeburn 954: foreach my $item (@images) {
1.168 raeburn 955: $defaults{$item} = $defaultdesign{'login.'.$item};
956: $defaults{'showlogo'}{$item} = 1;
957: }
958: foreach my $item (@bgs) {
959: $defaults{'bgs'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 960: }
1.41 raeburn 961: foreach my $item (@logintext) {
1.168 raeburn 962: $defaults{'logintext'}{$item} = $defaultdesign{'login.'.$item};
1.41 raeburn 963: }
1.168 raeburn 964: foreach my $item (@links) {
965: $defaults{'links'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 966: }
1.168 raeburn 967: if (ref($settings) eq 'HASH') {
968: foreach my $item (@toggles) {
969: if ($settings->{$item} eq '1') {
970: $checkedon{$item} = ' checked="checked" ';
971: $checkedoff{$item} = ' ';
972: } elsif ($settings->{$item} eq '0') {
973: $checkedoff{$item} = ' checked="checked" ';
974: $checkedon{$item} = ' ';
975: }
976: }
977: foreach my $item (@images) {
978: if (defined($settings->{$item})) {
979: $designs{$item} = $settings->{$item};
980: $is_custom{$item} = 1;
981: }
982: if (defined($settings->{'showlogo'}{$item})) {
983: $designs{'showlogo'}{$item} = $settings->{'showlogo'}{$item};
984: }
985: }
986: foreach my $item (@logintext) {
987: if ($settings->{$item} ne '') {
988: $designs{'logintext'}{$item} = $settings->{$item};
989: $is_custom{$item} = 1;
990: }
991: }
992: if ($settings->{'font'} ne '') {
993: $designs{'font'} = $settings->{'font'};
994: $is_custom{'font'} = 1;
995: }
996: foreach my $item (@bgs) {
997: if ($settings->{$item} ne '') {
998: $designs{'bgs'}{$item} = $settings->{$item};
999: $is_custom{$item} = 1;
1000: }
1001: }
1002: foreach my $item (@links) {
1003: if ($settings->{$item} ne '') {
1004: $designs{'links'}{$item} = $settings->{$item};
1005: $is_custom{$item} = 1;
1006: }
1007: }
1008: } else {
1009: if ($designhash{$dom.'.login.font'} ne '') {
1010: $designs{'font'} = $designhash{$dom.'.login.font'};
1011: $is_custom{'font'} = 1;
1012: }
1013: foreach my $item (@images) {
1014: if ($designhash{$dom.'.login.'.$item} ne '') {
1015: $designs{$item} = $designhash{$dom.'.login.'.$item};
1016: $is_custom{$item} = 1;
1017: }
1018: }
1019: foreach my $item (@bgs) {
1020: if ($designhash{$dom.'.login.'.$item} ne '') {
1021: $designs{'bgs'}{$item} = $designhash{$dom.'.login.'.$item};
1022: $is_custom{$item} = 1;
1023: }
1.6 raeburn 1024: }
1.168 raeburn 1025: foreach my $item (@links) {
1026: if ($designhash{$dom.'.login.'.$item} ne '') {
1027: $designs{'links'}{$item} = $designhash{$dom.'.login.'.$item};
1028: $is_custom{$item} = 1;
1029: }
1.6 raeburn 1030: }
1031: }
1.168 raeburn 1032: my %alt_text = &Apache::lonlocal::texthash ( img => 'Log-in banner',
1033: logo => 'Institution Logo',
1034: domlogo => 'Domain Logo',
1035: login => 'Login box');
1036: my $itemcount = 1;
1037: foreach my $item (@toggles) {
1038: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1039: $datatable .=
1040: '<tr'.$css_class.'><td colspan="2">'.$choices{$item}.
1041: '</td><td>'.
1042: '<span class="LC_nobreak"><label><input type="radio" name="'.
1043: $item.'"'.$checkedon{$item}.' value="1" />'.&mt('Yes').
1044: '</label> <label><input type="radio" name="'.$item.'"'.
1045: $checkedoff{$item}.' value="0" />'.&mt('No').'</label></span></td>'.
1046: '</tr>';
1047: $itemcount ++;
1.6 raeburn 1048: }
1.168 raeburn 1049: $datatable .= &display_color_options($dom,$confname,$phase,'login',$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal,\@logintext);
1050: $datatable .= '</tr></table></td></tr>';
1051: } elsif ($caller eq 'help') {
1052: my ($defaulturl,$defaulttype,%url,%type,%lt,%langchoices);
1053: my $switchserver = &check_switchserver($dom,$confname);
1054: my $itemcount = 1;
1055: $defaulturl = '/adm/loginproblems.html';
1056: $defaulttype = 'default';
1057: %lt = &Apache::lonlocal::texthash (
1058: del => 'Delete?',
1059: rep => 'Replace:',
1060: upl => 'Upload:',
1061: default => 'Default',
1062: custom => 'Custom',
1063: );
1064: %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
1065: my @currlangs;
1066: if (ref($settings) eq 'HASH') {
1067: if (ref($settings->{'helpurl'}) eq 'HASH') {
1068: foreach my $key (sort(keys(%{$settings->{'helpurl'}}))) {
1069: next if ($settings->{'helpurl'}{$key} eq '');
1070: $url{$key} = $settings->{'helpurl'}{$key}.'?inhibitmenu=yes';
1071: $type{$key} = 'custom';
1072: unless ($key eq 'nolang') {
1073: push(@currlangs,$key);
1074: }
1075: }
1076: } elsif ($settings->{'helpurl'} ne '') {
1077: $type{'nolang'} = 'custom';
1078: $url{'nolang'} = $settings->{'helpurl'}.'?inhibitmenu=yes';
1.8 raeburn 1079: }
1080: }
1.168 raeburn 1081: foreach my $lang ('nolang',sort(@currlangs)) {
1082: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1083: $datatable .= '<tr'.$css_class.'>';
1084: if ($url{$lang} eq '') {
1085: $url{$lang} = $defaulturl;
1086: }
1087: if ($type{$lang} eq '') {
1088: $type{$lang} = $defaulttype;
1089: }
1090: $datatable .= '<td colspan="2"><span class="LC_nobreak">';
1091: if ($lang eq 'nolang') {
1092: $datatable .= &mt('Log-in help page if no specific language file: [_1]',
1093: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1094: } else {
1095: $datatable .= &mt('Log-in help page for language: [_1] is [_2]',
1096: $langchoices{$lang},
1097: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1098: }
1099: $datatable .= '</span></td>'."\n".
1100: '<td class="LC_left_item">';
1101: if ($type{$lang} eq 'custom') {
1102: $datatable .= '<span class="LC_nobreak"><label>'.
1103: '<input type="checkbox" name="loginhelpurl_del" value="'.$lang.'" />'.
1104: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1105: } else {
1106: $datatable .= $lt{'upl'};
1107: }
1108: $datatable .='<br />';
1109: if ($switchserver) {
1110: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1111: } else {
1112: $datatable .= '<input type="file" name="loginhelpurl_'.$lang.'" />';
1.6 raeburn 1113: }
1.168 raeburn 1114: $datatable .= '</td></tr>';
1115: $itemcount ++;
1.6 raeburn 1116: }
1.168 raeburn 1117: my @addlangs;
1118: foreach my $lang (sort(keys(%langchoices))) {
1119: next if ((grep(/^\Q$lang\E$/,@currlangs)) || ($lang eq 'x_chef'));
1120: push(@addlangs,$lang);
1121: }
1122: if (@addlangs > 0) {
1123: my %toadd;
1124: map { $toadd{$_} = $langchoices{$_} ; } @addlangs;
1125: $toadd{''} = &mt('Select');
1126: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1127: $datatable .= '<tr'.$css_class.'><td class="LC_left_item" colspan="2">'.
1128: &mt('Add log-in help page for a specific language:').' '.
1129: &Apache::loncommon::select_form('','loginhelpurl_add_lang',\%toadd).
1130: '</td><td class="LC_left_item">'.$lt{'upl'}.'<br />';
1131: if ($switchserver) {
1132: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1133: } else {
1134: $datatable .= '<input type="file" name="loginhelpurl_add_file" />';
1.6 raeburn 1135: }
1.168 raeburn 1136: $datatable .= '</td></tr>';
1.169 raeburn 1137: $itemcount ++;
1.6 raeburn 1138: }
1.169 raeburn 1139: $datatable .= &captcha_choice('login',$settings,$itemcount);
1.1 raeburn 1140: }
1.6 raeburn 1141: return $datatable;
1142: }
1143:
1144: sub login_choices {
1145: my %choices =
1146: &Apache::lonlocal::texthash (
1.116 bisitz 1147: coursecatalog => 'Display Course/Community Catalog link?',
1.110 raeburn 1148: adminmail => "Display Administrator's E-mail Address?",
1.188 raeburn 1149: helpdesk => 'Display "Contact Helpdesk" link',
1.110 raeburn 1150: disallowlogin => "Login page requests redirected",
1151: hostid => "Server",
1.128 raeburn 1152: server => "Redirect to:",
1153: serverpath => "Path",
1154: custompath => "Custom",
1155: exempt => "Exempt IP(s)",
1.110 raeburn 1156: directlogin => "No redirect",
1157: newuser => "Link to create a user account",
1158: img => "Header",
1159: logo => "Main Logo",
1160: domlogo => "Domain Logo",
1161: login => "Log-in Header",
1162: textcol => "Text color",
1163: bgcol => "Box color",
1164: bgs => "Background colors",
1165: links => "Link colors",
1166: font => "Font color",
1167: pgbg => "Header",
1168: mainbg => "Page",
1169: sidebg => "Login box",
1170: link => "Link",
1171: alink => "Active link",
1172: vlink => "Visited link",
1.6 raeburn 1173: );
1174: return %choices;
1175: }
1176:
1177: sub print_rolecolors {
1.30 raeburn 1178: my ($phase,$role,$dom,$confname,$settings,$rowtotal) = @_;
1.6 raeburn 1179: my %choices = &color_font_choices();
1180: my @bgs = ('pgbg','tabbg','sidebg');
1181: my @links = ('link','alink','vlink');
1182: my @images = ('img');
1183: my %alt_text = &Apache::lonlocal::texthash(img => "Banner for $role role");
1.7 albertel 1184: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.6 raeburn 1185: my %defaultdesign = %Apache::loncommon::defaultdesign;
1186: my (%is_custom,%designs);
1.200 raeburn 1187: my %defaults = &role_defaults($role,\@bgs,\@links,\@images);
1.6 raeburn 1188: if (ref($settings) eq 'HASH') {
1189: if (ref($settings->{$role}) eq 'HASH') {
1190: if ($settings->{$role}->{'img'} ne '') {
1191: $designs{'img'} = $settings->{$role}->{'img'};
1192: $is_custom{'img'} = 1;
1193: }
1194: if ($settings->{$role}->{'font'} ne '') {
1195: $designs{'font'} = $settings->{$role}->{'font'};
1196: $is_custom{'font'} = 1;
1197: }
1.97 tempelho 1198: if ($settings->{$role}->{'fontmenu'} ne '') {
1199: $designs{'fontmenu'} = $settings->{$role}->{'fontmenu'};
1200: $is_custom{'fontmenu'} = 1;
1201: }
1.6 raeburn 1202: foreach my $item (@bgs) {
1203: if ($settings->{$role}->{$item} ne '') {
1204: $designs{'bgs'}{$item} = $settings->{$role}->{$item};
1205: $is_custom{$item} = 1;
1206: }
1207: }
1208: foreach my $item (@links) {
1209: if ($settings->{$role}->{$item} ne '') {
1210: $designs{'links'}{$item} = $settings->{$role}->{$item};
1211: $is_custom{$item} = 1;
1212: }
1213: }
1214: }
1215: } else {
1216: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
1217: $designs{img} = $designhash{$dom.'.'.$role.'.img'};
1218: $is_custom{'img'} = 1;
1219: }
1.97 tempelho 1220: if ($designhash{$dom.'.'.$role.'.fontmenu'} ne '') {
1221: $designs{fontmenu} = $designhash{$dom.'.'.$role.'.fontmenu'};
1222: $is_custom{'fontmenu'} = 1;
1223: }
1.6 raeburn 1224: if ($designhash{$dom.'.'.$role.'.font'} ne '') {
1225: $designs{font} = $designhash{$dom.'.'.$role.'.font'};
1226: $is_custom{'font'} = 1;
1227: }
1228: foreach my $item (@bgs) {
1229: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1230: $designs{'bgs'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1231: $is_custom{$item} = 1;
1232:
1233: }
1234: }
1235: foreach my $item (@links) {
1236: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1237: $designs{'links'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1238: $is_custom{$item} = 1;
1239: }
1240: }
1241: }
1242: my $itemcount = 1;
1.30 raeburn 1243: my $datatable = &display_color_options($dom,$confname,$phase,$role,$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal);
1.6 raeburn 1244: $datatable .= '</tr></table></td></tr>';
1245: return $datatable;
1246: }
1247:
1.200 raeburn 1248: sub role_defaults {
1249: my ($role,$bgs,$links,$images,$logintext) = @_;
1.202 raeburn 1250: my %defaults;
1251: unless ((ref($bgs) eq 'ARRAY') && (ref($links) eq 'ARRAY') && (ref($images) eq 'ARRAY')) {
1.200 raeburn 1252: return %defaults;
1253: }
1254: my %defaultdesign = %Apache::loncommon::defaultdesign;
1255: if ($role eq 'login') {
1256: %defaults = (
1257: font => $defaultdesign{$role.'.font'},
1258: );
1259: if (ref($logintext) eq 'ARRAY') {
1260: foreach my $item (@{$logintext}) {
1261: $defaults{'logintext'}{$item} = $defaultdesign{$role.'.'.$item};
1262: }
1263: }
1264: foreach my $item (@{$images}) {
1265: $defaults{'showlogo'}{$item} = 1;
1266: }
1267: } else {
1268: %defaults = (
1269: img => $defaultdesign{$role.'.img'},
1270: font => $defaultdesign{$role.'.font'},
1271: fontmenu => $defaultdesign{$role.'.fontmenu'},
1272: );
1273: }
1274: foreach my $item (@{$bgs}) {
1275: $defaults{'bgs'}{$item} = $defaultdesign{$role.'.'.$item};
1276: }
1277: foreach my $item (@{$links}) {
1278: $defaults{'links'}{$item} = $defaultdesign{$role.'.'.$item};
1279: }
1280: foreach my $item (@{$images}) {
1281: $defaults{$item} = $defaultdesign{$role.'.'.$item};
1282: }
1283: return %defaults;
1284: }
1285:
1.6 raeburn 1286: sub display_color_options {
1.9 raeburn 1287: my ($dom,$confname,$phase,$role,$itemcount,$choices,$is_custom,$defaults,$designs,
1.135 bisitz 1288: $images,$bgs,$links,$alt_text,$rowtotal,$logintext) = @_;
1.159 raeburn 1289: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.6 raeburn 1290: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.176 raeburn 1291: my $datatable = '<tr'.$css_class.'>'.
1.6 raeburn 1292: '<td>'.$choices->{'font'}.'</td>';
1293: if (!$is_custom->{'font'}) {
1.30 raeburn 1294: $datatable .= '<td>'.&mt('Default in use:').' <span id="css_default_'.$role.'_font" style="color: '.$defaults->{'font'}.';">'.$defaults->{'font'}.'</span></td>';
1.6 raeburn 1295: } else {
1296: $datatable .= '<td> </td>';
1297: }
1.174 foxr 1298: my $current_color = $designs->{'font'} ? $designs->{'font'} : $defaults->{'font'};
1299:
1.8 raeburn 1300: $datatable .= '<td><span class="LC_nobreak">'.
1.174 foxr 1301: '<input type="text" class="colorchooser" size="10" name="'.$role.'_font"'.
1.202 raeburn 1302: ' value="'.$current_color.'" /> '.
1.174 foxr 1303: ' </td></tr>';
1.107 raeburn 1304: unless ($role eq 'login') {
1305: $datatable .= '<tr'.$css_class.'>'.
1306: '<td>'.$choices->{'fontmenu'}.'</td>';
1307: if (!$is_custom->{'fontmenu'}) {
1308: $datatable .= '<td>'.&mt('Default in use:').' <span id="css_default_'.$role.'_font" style="color: '.$defaults->{'fontmenu'}.';">'.$defaults->{'fontmenu'}.'</span></td>';
1309: } else {
1310: $datatable .= '<td> </td>';
1311: }
1.202 raeburn 1312: $current_color = $designs->{'fontmenu'} ?
1.174 foxr 1313: $designs->{'fontmenu'} : $defaults->{'fontmenu'};
1.107 raeburn 1314: $datatable .= '<td><span class="LC_nobreak">'.
1.174 foxr 1315: '<input class="colorchooser" type="text" size="10" name="'
1316: .$role.'_fontmenu"'.
1317: ' value="'.$current_color.'" /> '.
1318: ' </td></tr>';
1.97 tempelho 1319: }
1.9 raeburn 1320: my $switchserver = &check_switchserver($dom,$confname);
1.6 raeburn 1321: foreach my $img (@{$images}) {
1.18 albertel 1322: $itemcount ++;
1.6 raeburn 1323: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.8 raeburn 1324: $datatable .= '<tr'.$css_class.'>'.
1.70 raeburn 1325: '<td>'.$choices->{$img};
1.41 raeburn 1326: my ($imgfile,$img_import,$login_hdr_pick,$logincolors);
1.70 raeburn 1327: if ($role eq 'login') {
1328: if ($img eq 'login') {
1329: $login_hdr_pick =
1.135 bisitz 1330: &login_header_options($img,$role,$defaults,$is_custom,$choices);
1.70 raeburn 1331: $logincolors =
1332: &login_text_colors($img,$role,$logintext,$phase,$choices,
1.201 raeburn 1333: $designs,$defaults);
1.70 raeburn 1334: } elsif ($img ne 'domlogo') {
1335: $datatable.= &logo_display_options($img,$defaults,$designs);
1336: }
1337: }
1338: $datatable .= '</td>';
1.6 raeburn 1339: if ($designs->{$img} ne '') {
1340: $imgfile = $designs->{$img};
1.18 albertel 1341: $img_import = ($imgfile =~ m{^/adm/});
1.6 raeburn 1342: } else {
1343: $imgfile = $defaults->{$img};
1344: }
1345: if ($imgfile) {
1.9 raeburn 1346: my ($showfile,$fullsize);
1347: if ($imgfile =~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
1.6 raeburn 1348: my $urldir = $1;
1349: my $filename = $2;
1350: my @info = &Apache::lonnet::stat_file($designs->{$img});
1351: if (@info) {
1352: my $thumbfile = 'tn-'.$filename;
1353: my @thumb=&Apache::lonnet::stat_file($urldir.'/'.$thumbfile);
1354: if (@thumb) {
1355: $showfile = $urldir.'/'.$thumbfile;
1356: } else {
1357: $showfile = $imgfile;
1358: }
1359: } else {
1360: $showfile = '';
1361: }
1362: } elsif ($imgfile =~ m-^/(adm/[^/]+)/([^/]+)$-) {
1.16 raeburn 1363: $showfile = $imgfile;
1.6 raeburn 1364: my $imgdir = $1;
1365: my $filename = $2;
1.159 raeburn 1366: if (-e "$londocroot/$imgdir/tn-".$filename) {
1.6 raeburn 1367: $showfile = "/$imgdir/tn-".$filename;
1368: } else {
1.159 raeburn 1369: my $input = $londocroot.$imgfile;
1370: my $output = "$londocroot/$imgdir/tn-".$filename;
1.6 raeburn 1371: if (!-e $output) {
1.9 raeburn 1372: my ($width,$height) = &thumb_dimensions();
1.16 raeburn 1373: my ($fullwidth,$fullheight) = &check_dimensions($input);
1374: if ($fullwidth ne '' && $fullheight ne '') {
1375: if ($fullwidth > $width && $fullheight > $height) {
1376: my $size = $width.'x'.$height;
1377: system("convert -sample $size $input $output");
1.159 raeburn 1378: $showfile = "/$imgdir/tn-".$filename;
1.16 raeburn 1379: }
1380: }
1.6 raeburn 1381: }
1382: }
1.16 raeburn 1383: }
1.6 raeburn 1384: if ($showfile) {
1.40 raeburn 1385: if ($showfile =~ m{^/(adm|res)/}) {
1386: if ($showfile =~ m{^/res/}) {
1387: my $local_showfile =
1388: &Apache::lonnet::filelocation('',$showfile);
1389: &Apache::lonnet::repcopy($local_showfile);
1390: }
1391: $showfile = &Apache::loncommon::lonhttpdurl($showfile);
1392: }
1393: if ($imgfile) {
1394: if ($imgfile =~ m{^/(adm|res)/}) {
1395: if ($imgfile =~ m{^/res/}) {
1396: my $local_imgfile =
1397: &Apache::lonnet::filelocation('',$imgfile);
1398: &Apache::lonnet::repcopy($local_imgfile);
1399: }
1400: $fullsize = &Apache::loncommon::lonhttpdurl($imgfile);
1401: } else {
1402: $fullsize = $imgfile;
1403: }
1404: }
1.41 raeburn 1405: $datatable .= '<td>';
1406: if ($img eq 'login') {
1.135 bisitz 1407: $datatable .= $login_hdr_pick;
1408: }
1.41 raeburn 1409: $datatable .= &image_changes($is_custom->{$img},$alt_text->{$img},$img_import,
1410: $showfile,$fullsize,$role,$img,$imgfile,$logincolors);
1.6 raeburn 1411: } else {
1.201 raeburn 1412: $datatable .= '<td> </td><td class="LC_left_item">'.
1413: &mt('Upload:').'<br />';
1.6 raeburn 1414: }
1415: } else {
1.201 raeburn 1416: $datatable .= '<td> </td><td class="LC_left_item">'.
1417: &mt('Upload:').'<br />';
1.6 raeburn 1418: }
1.9 raeburn 1419: if ($switchserver) {
1420: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1421: } else {
1.135 bisitz 1422: if ($img ne 'login') { # suppress file selection for Log-in header
1423: $datatable .=' <input type="file" name="'.$role.'_'.$img.'" />';
1424: }
1.9 raeburn 1425: }
1426: $datatable .= '</td></tr>';
1.6 raeburn 1427: }
1428: $itemcount ++;
1429: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1430: $datatable .= '<tr'.$css_class.'>'.
1431: '<td>'.$choices->{'bgs'}.'</td>';
1432: my $bgs_def;
1433: foreach my $item (@{$bgs}) {
1434: if (!$is_custom->{$item}) {
1.70 raeburn 1435: $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 1436: }
1437: }
1438: if ($bgs_def) {
1.8 raeburn 1439: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$bgs_def.'</tr></table></td>';
1.6 raeburn 1440: } else {
1441: $datatable .= '<td> </td>';
1442: }
1443: $datatable .= '<td class="LC_right_item">'.
1444: '<table border="0"><tr>';
1.174 foxr 1445:
1.6 raeburn 1446: foreach my $item (@{$bgs}) {
1.201 raeburn 1447: $datatable .= '<td align="center">'.$choices->{$item};
1.174 foxr 1448: my $color = $designs->{'bgs'}{$item} ? $designs->{'bgs'}{$item} : $defaults->{'bgs'}{$item};
1.6 raeburn 1449: if ($designs->{'bgs'}{$item}) {
1.174 foxr 1450: $datatable .= ' ';
1.6 raeburn 1451: }
1.174 foxr 1452: $datatable .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1.41 raeburn 1453: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.6 raeburn 1454: }
1455: $datatable .= '</tr></table></td></tr>';
1456: $itemcount ++;
1457: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1458: $datatable .= '<tr'.$css_class.'>'.
1459: '<td>'.$choices->{'links'}.'</td>';
1460: my $links_def;
1461: foreach my $item (@{$links}) {
1462: if (!$is_custom->{$item}) {
1.30 raeburn 1463: $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 1464: }
1465: }
1466: if ($links_def) {
1.8 raeburn 1467: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$links_def.'</tr></table></td>';
1.6 raeburn 1468: } else {
1469: $datatable .= '<td> </td>';
1470: }
1471: $datatable .= '<td class="LC_right_item">'.
1472: '<table border="0"><tr>';
1473: foreach my $item (@{$links}) {
1.174 foxr 1474: my $color = $designs->{'link'}{$item} ? $designs->{'link'}{$item} : $defaults->{'links'}{$item};
1.201 raeburn 1475: $datatable .= '<td align="center">'.$choices->{$item}."\n";
1.6 raeburn 1476: if ($designs->{'links'}{$item}) {
1.174 foxr 1477: $datatable.=' ';
1.6 raeburn 1478: }
1.174 foxr 1479: $datatable .= '<br /><input type="text" size="8" class="colorchooser" name="'.$role.'_'.$item.'" value="'.$color.
1.6 raeburn 1480: '" /></td>';
1481: }
1.30 raeburn 1482: $$rowtotal += $itemcount;
1.3 raeburn 1483: return $datatable;
1484: }
1485:
1.70 raeburn 1486: sub logo_display_options {
1487: my ($img,$defaults,$designs) = @_;
1488: my $checkedon;
1489: if (ref($defaults) eq 'HASH') {
1490: if (ref($defaults->{'showlogo'}) eq 'HASH') {
1491: if ($defaults->{'showlogo'}{$img}) {
1492: $checkedon = 'checked="checked" ';
1493: }
1494: }
1495: }
1496: if (ref($designs) eq 'HASH') {
1497: if (ref($designs->{'showlogo'}) eq 'HASH') {
1498: if (defined($designs->{'showlogo'}{$img})) {
1499: if ($designs->{'showlogo'}{$img} == 0) {
1500: $checkedon = '';
1501: } elsif ($designs->{'showlogo'}{$img} == 1) {
1502: $checkedon = 'checked="checked" ';
1503: }
1504: }
1505: }
1506: }
1507: return '<br /><label> <input type="checkbox" name="'.
1508: 'login_showlogo_'.$img.'" value="1" '.$checkedon.'/>'.
1509: &mt('show').'</label>'."\n";
1510: }
1511:
1.41 raeburn 1512: sub login_header_options {
1.135 bisitz 1513: my ($img,$role,$defaults,$is_custom,$choices) = @_;
1514: my $output = '';
1.41 raeburn 1515: if ((!$is_custom->{'textcol'}) || (!$is_custom->{'bgcol'})) {
1.135 bisitz 1516: $output .= &mt('Text default(s):').'<br />';
1.41 raeburn 1517: if (!$is_custom->{'textcol'}) {
1518: $output .= $choices->{'textcol'}.': '.$defaults->{'logintext'}{'textcol'}.
1519: ' ';
1520: }
1521: if (!$is_custom->{'bgcol'}) {
1522: $output .= $choices->{'bgcol'}.': '.
1523: '<span id="css_'.$role.'_font" style="background-color: '.
1524: $defaults->{'logintext'}{'bgcol'}.';"> </span>';
1525: }
1526: $output .= '<br />';
1527: }
1528: $output .='<br />';
1529: return $output;
1530: }
1531:
1532: sub login_text_colors {
1.201 raeburn 1533: my ($img,$role,$logintext,$phase,$choices,$designs,$defaults) = @_;
1.41 raeburn 1534: my $color_menu = '<table border="0"><tr>';
1535: foreach my $item (@{$logintext}) {
1.201 raeburn 1536: $color_menu .= '<td align="center">'.$choices->{$item};
1537: my $color = $designs->{'logintext'}{$item} ? $designs->{'logintext'}{$item} : $defaults->{'logintext'}{$item};
1538: $color_menu .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1539: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.41 raeburn 1540: }
1541: $color_menu .= '</tr></table><br />';
1542: return $color_menu;
1543: }
1544:
1545: sub image_changes {
1546: my ($is_custom,$alt_text,$img_import,$showfile,$fullsize,$role,$img,$imgfile,$logincolors) = @_;
1547: my $output;
1.135 bisitz 1548: if ($img eq 'login') {
1549: # suppress image for Log-in header
1550: } elsif (!$is_custom) {
1.70 raeburn 1551: if ($img ne 'domlogo') {
1.41 raeburn 1552: $output .= &mt('Default image:').'<br />';
1553: } else {
1554: $output .= &mt('Default in use:').'<br />';
1555: }
1556: }
1.135 bisitz 1557: if ($img eq 'login') { # suppress image for Log-in header
1558: $output .= '<td>'.$logincolors;
1.41 raeburn 1559: } else {
1.135 bisitz 1560: if ($img_import) {
1561: $output .= '<input type="hidden" name="'.$role.'_import_'.$img.'" value="'.$imgfile.'" />';
1562: }
1563: $output .= '<a href="'.$fullsize.'" target="_blank"><img src="'.
1564: $showfile.'" alt="'.$alt_text.'" border="0" /></a></td>';
1565: if ($is_custom) {
1566: $output .= '<td>'.$logincolors.'<span class="LC_nobreak"><label>'.
1567: '<input type="checkbox" name="'.
1568: $role.'_del_'.$img.'" value="1" />'.&mt('Delete?').
1569: '</label> '.&mt('Replace:').'</span><br />';
1570: } else {
1.201 raeburn 1571: $output .= '<td valign="middle">'.$logincolors.&mt('Upload:').'<br />';
1.135 bisitz 1572: }
1.41 raeburn 1573: }
1574: return $output;
1575: }
1576:
1.3 raeburn 1577: sub print_quotas {
1.86 raeburn 1578: my ($dom,$settings,$rowtotal,$action) = @_;
1579: my $context;
1580: if ($action eq 'quotas') {
1581: $context = 'tools';
1582: } else {
1583: $context = $action;
1584: }
1.197 raeburn 1585: my ($datatable,$defaultquota,$authorquota,@usertools,@options,%validations);
1.44 raeburn 1586: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.3 raeburn 1587: my $typecount = 0;
1.101 raeburn 1588: my ($css_class,%titles);
1.86 raeburn 1589: if ($context eq 'requestcourses') {
1.216 raeburn 1590: @usertools = ('official','unofficial','community','textbook');
1.106 raeburn 1591: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 1592: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
1593: %titles = &courserequest_titles();
1.163 raeburn 1594: } elsif ($context eq 'requestauthor') {
1595: @usertools = ('author');
1596: @options = ('norequest','approval','automatic');
1.210 raeburn 1597: %titles = &authorrequest_titles();
1.86 raeburn 1598: } else {
1.162 raeburn 1599: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 1600: %titles = &tool_titles();
1.86 raeburn 1601: }
1.26 raeburn 1602: if (ref($types) eq 'ARRAY') {
1.23 raeburn 1603: foreach my $type (@{$types}) {
1.197 raeburn 1604: my ($currdefquota,$currauthorquota);
1.163 raeburn 1605: unless (($context eq 'requestcourses') ||
1606: ($context eq 'requestauthor')) {
1.86 raeburn 1607: if (ref($settings) eq 'HASH') {
1608: if (ref($settings->{defaultquota}) eq 'HASH') {
1.197 raeburn 1609: $currdefquota = $settings->{defaultquota}->{$type};
1.86 raeburn 1610: } else {
1611: $currdefquota = $settings->{$type};
1612: }
1.197 raeburn 1613: if (ref($settings->{authorquota}) eq 'HASH') {
1614: $currauthorquota = $settings->{authorquota}->{$type};
1615: }
1.78 raeburn 1616: }
1.72 raeburn 1617: }
1.3 raeburn 1618: if (defined($usertypes->{$type})) {
1619: $typecount ++;
1620: $css_class = $typecount%2?' class="LC_odd_row"':'';
1.72 raeburn 1621: $datatable .= '<tr'.$css_class.'>'.
1.3 raeburn 1622: '<td>'.$usertypes->{$type}.'</td>'.
1.72 raeburn 1623: '<td class="LC_left_item">';
1.101 raeburn 1624: if ($context eq 'requestcourses') {
1625: $datatable .= '<table><tr>';
1626: }
1627: my %cell;
1.72 raeburn 1628: foreach my $item (@usertools) {
1.101 raeburn 1629: if ($context eq 'requestcourses') {
1630: my ($curroption,$currlimit);
1631: if (ref($settings) eq 'HASH') {
1632: if (ref($settings->{$item}) eq 'HASH') {
1633: $curroption = $settings->{$item}->{$type};
1634: if ($curroption =~ /^autolimit=(\d*)$/) {
1635: $currlimit = $1;
1636: }
1637: }
1638: }
1639: if (!$curroption) {
1640: $curroption = 'norequest';
1641: }
1642: $datatable .= '<th>'.$titles{$item}.'</th>';
1643: foreach my $option (@options) {
1644: my $val = $option;
1645: if ($option eq 'norequest') {
1646: $val = 0;
1647: }
1648: if ($option eq 'validate') {
1649: my $canvalidate = 0;
1650: if (ref($validations{$item}) eq 'HASH') {
1651: if ($validations{$item}{$type}) {
1652: $canvalidate = 1;
1653: }
1654: }
1655: next if (!$canvalidate);
1656: }
1657: my $checked = '';
1658: if ($option eq $curroption) {
1659: $checked = ' checked="checked"';
1660: } elsif ($option eq 'autolimit') {
1661: if ($curroption =~ /^autolimit/) {
1662: $checked = ' checked="checked"';
1663: }
1664: }
1665: $cell{$item} .= '<span class="LC_nobreak"><label>'.
1666: '<input type="radio" name="crsreq_'.$item.
1667: '_'.$type.'" value="'.$val.'"'.$checked.' />'.
1.127 raeburn 1668: $titles{$option}.'</label>';
1.101 raeburn 1669: if ($option eq 'autolimit') {
1.127 raeburn 1670: $cell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 1671: $item.'_limit_'.$type.'" size="1" '.
1.103 raeburn 1672: 'value="'.$currlimit.'" />';
1.101 raeburn 1673: }
1.127 raeburn 1674: $cell{$item} .= '</span> ';
1.103 raeburn 1675: if ($option eq 'autolimit') {
1.127 raeburn 1676: $cell{$item} .= $titles{'unlimited'};
1.103 raeburn 1677: }
1.101 raeburn 1678: }
1.163 raeburn 1679: } elsif ($context eq 'requestauthor') {
1680: my $curroption;
1681: if (ref($settings) eq 'HASH') {
1682: $curroption = $settings->{$type};
1683: }
1684: if (!$curroption) {
1685: $curroption = 'norequest';
1686: }
1687: foreach my $option (@options) {
1688: my $val = $option;
1689: if ($option eq 'norequest') {
1690: $val = 0;
1691: }
1692: my $checked = '';
1693: if ($option eq $curroption) {
1694: $checked = ' checked="checked"';
1695: }
1696: $datatable .= '<span class="LC_nobreak"><label>'.
1697: '<input type="radio" name="authorreq_'.$type.
1698: '" value="'.$val.'"'.$checked.' />'.
1699: $titles{$option}.'</label></span> ';
1700: }
1.101 raeburn 1701: } else {
1702: my $checked = 'checked="checked" ';
1703: if (ref($settings) eq 'HASH') {
1704: if (ref($settings->{$item}) eq 'HASH') {
1705: if ($settings->{$item}->{$type} == 0) {
1706: $checked = '';
1707: } elsif ($settings->{$item}->{$type} == 1) {
1708: $checked = 'checked="checked" ';
1709: }
1.78 raeburn 1710: }
1.72 raeburn 1711: }
1.101 raeburn 1712: $datatable .= '<span class="LC_nobreak"><label>'.
1713: '<input type="checkbox" name="'.$context.'_'.$item.
1714: '" value="'.$type.'" '.$checked.'/>'.$titles{$item}.
1715: '</label></span> ';
1.72 raeburn 1716: }
1.101 raeburn 1717: }
1718: if ($context eq 'requestcourses') {
1719: $datatable .= '</tr><tr>';
1720: foreach my $item (@usertools) {
1.106 raeburn 1721: $datatable .= '<td style="vertical-align: top">'.$cell{$item}.'</td>';
1.101 raeburn 1722: }
1723: $datatable .= '</tr></table>';
1.72 raeburn 1724: }
1.86 raeburn 1725: $datatable .= '</td>';
1.163 raeburn 1726: unless (($context eq 'requestcourses') ||
1727: ($context eq 'requestauthor')) {
1.86 raeburn 1728: $datatable .=
1.197 raeburn 1729: '<td class="LC_right_item">'.
1730: '<span class="LC_nobreak">'.&mt('Portfolio').': '.
1.3 raeburn 1731: '<input type="text" name="quota_'.$type.
1.72 raeburn 1732: '" value="'.$currdefquota.
1.197 raeburn 1733: '" size="5" /></span>'.(' ' x 2).
1734: '<span class="LC_nobreak">'.&mt('Authoring').': '.
1735: '<input type="text" name="authorquota_'.$type.
1736: '" value="'.$currauthorquota.
1737: '" size="5" /></span></td>';
1.86 raeburn 1738: }
1739: $datatable .= '</tr>';
1.3 raeburn 1740: }
1741: }
1742: }
1.163 raeburn 1743: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 1744: $defaultquota = '20';
1.197 raeburn 1745: $authorquota = '500';
1.86 raeburn 1746: if (ref($settings) eq 'HASH') {
1747: if (ref($settings->{'defaultquota'}) eq 'HASH') {
1748: $defaultquota = $settings->{'defaultquota'}->{'default'};
1749: } elsif (defined($settings->{'default'})) {
1750: $defaultquota = $settings->{'default'};
1751: }
1.197 raeburn 1752: if (ref($settings->{'authorquota'}) eq 'HASH') {
1753: $authorquota = $settings->{'authorquota'}->{'default'};
1754: }
1.3 raeburn 1755: }
1756: }
1757: $typecount ++;
1758: $css_class = $typecount%2?' class="LC_odd_row"':'';
1759: $datatable .= '<tr'.$css_class.'>'.
1.26 raeburn 1760: '<td>'.$othertitle.'</td>'.
1.72 raeburn 1761: '<td class="LC_left_item">';
1.101 raeburn 1762: if ($context eq 'requestcourses') {
1763: $datatable .= '<table><tr>';
1764: }
1765: my %defcell;
1.72 raeburn 1766: foreach my $item (@usertools) {
1.101 raeburn 1767: if ($context eq 'requestcourses') {
1768: my ($curroption,$currlimit);
1769: if (ref($settings) eq 'HASH') {
1770: if (ref($settings->{$item}) eq 'HASH') {
1771: $curroption = $settings->{$item}->{'default'};
1772: if ($curroption =~ /^autolimit=(\d*)$/) {
1773: $currlimit = $1;
1774: }
1775: }
1776: }
1777: if (!$curroption) {
1778: $curroption = 'norequest';
1779: }
1780: $datatable .= '<th>'.$titles{$item}.'</th>';
1781: foreach my $option (@options) {
1782: my $val = $option;
1783: if ($option eq 'norequest') {
1784: $val = 0;
1785: }
1786: if ($option eq 'validate') {
1787: my $canvalidate = 0;
1788: if (ref($validations{$item}) eq 'HASH') {
1789: if ($validations{$item}{'default'}) {
1790: $canvalidate = 1;
1791: }
1792: }
1793: next if (!$canvalidate);
1794: }
1795: my $checked = '';
1796: if ($option eq $curroption) {
1797: $checked = ' checked="checked"';
1798: } elsif ($option eq 'autolimit') {
1799: if ($curroption =~ /^autolimit/) {
1800: $checked = ' checked="checked"';
1801: }
1802: }
1803: $defcell{$item} .= '<span class="LC_nobreak"><label>'.
1804: '<input type="radio" name="crsreq_'.$item.
1805: '_default" value="'.$val.'"'.$checked.' />'.
1806: $titles{$option}.'</label>';
1807: if ($option eq 'autolimit') {
1.127 raeburn 1808: $defcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 1809: $item.'_limit_default" size="1" '.
1810: 'value="'.$currlimit.'" />';
1811: }
1.127 raeburn 1812: $defcell{$item} .= '</span> ';
1.104 raeburn 1813: if ($option eq 'autolimit') {
1.127 raeburn 1814: $defcell{$item} .= $titles{'unlimited'};
1.104 raeburn 1815: }
1.101 raeburn 1816: }
1.163 raeburn 1817: } elsif ($context eq 'requestauthor') {
1818: my $curroption;
1819: if (ref($settings) eq 'HASH') {
1.172 raeburn 1820: $curroption = $settings->{'default'};
1.163 raeburn 1821: }
1822: if (!$curroption) {
1823: $curroption = 'norequest';
1824: }
1825: foreach my $option (@options) {
1826: my $val = $option;
1827: if ($option eq 'norequest') {
1828: $val = 0;
1829: }
1830: my $checked = '';
1831: if ($option eq $curroption) {
1832: $checked = ' checked="checked"';
1833: }
1834: $datatable .= '<span class="LC_nobreak"><label>'.
1835: '<input type="radio" name="authorreq_default"'.
1836: ' value="'.$val.'"'.$checked.' />'.
1837: $titles{$option}.'</label></span> ';
1838: }
1.101 raeburn 1839: } else {
1840: my $checked = 'checked="checked" ';
1841: if (ref($settings) eq 'HASH') {
1842: if (ref($settings->{$item}) eq 'HASH') {
1843: if ($settings->{$item}->{'default'} == 0) {
1844: $checked = '';
1845: } elsif ($settings->{$item}->{'default'} == 1) {
1846: $checked = 'checked="checked" ';
1847: }
1.78 raeburn 1848: }
1.72 raeburn 1849: }
1.101 raeburn 1850: $datatable .= '<span class="LC_nobreak"><label>'.
1851: '<input type="checkbox" name="'.$context.'_'.$item.
1852: '" value="default" '.$checked.'/>'.$titles{$item}.
1853: '</label></span> ';
1854: }
1855: }
1856: if ($context eq 'requestcourses') {
1857: $datatable .= '</tr><tr>';
1858: foreach my $item (@usertools) {
1.106 raeburn 1859: $datatable .= '<td style="vertical-align: top">'.$defcell{$item}.'</td>';
1.72 raeburn 1860: }
1.101 raeburn 1861: $datatable .= '</tr></table>';
1.72 raeburn 1862: }
1.86 raeburn 1863: $datatable .= '</td>';
1.163 raeburn 1864: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.197 raeburn 1865: $datatable .= '<td class="LC_right_item">'.
1866: '<span class="LC_nobreak">'.&mt('Portfolio').': '.
1.86 raeburn 1867: '<input type="text" name="defaultquota" value="'.
1.197 raeburn 1868: $defaultquota.'" size="5" /></span>'.(' ' x2).
1869: '<span class="LC_nobreak">'.&mt('Authoring').': '.
1870: '<input type="text" name="authorquota" value="'.
1871: $authorquota.'" size="5" /></span></td>';
1.86 raeburn 1872: }
1873: $datatable .= '</tr>';
1.72 raeburn 1874: $typecount ++;
1875: $css_class = $typecount%2?' class="LC_odd_row"':'';
1876: $datatable .= '<tr'.$css_class.'>'.
1.197 raeburn 1877: '<td>'.&mt('LON-CAPA Advanced Users').'<br />';
1.104 raeburn 1878: if ($context eq 'requestcourses') {
1.109 raeburn 1879: $datatable .= &mt('(overrides affiliation, if set)').
1880: '</td>'.
1881: '<td class="LC_left_item">'.
1882: '<table><tr>';
1.101 raeburn 1883: } else {
1.109 raeburn 1884: $datatable .= &mt('(overrides affiliation, if checked)').
1885: '</td>'.
1886: '<td class="LC_left_item" colspan="2">'.
1887: '<br />';
1.101 raeburn 1888: }
1889: my %advcell;
1.72 raeburn 1890: foreach my $item (@usertools) {
1.101 raeburn 1891: if ($context eq 'requestcourses') {
1892: my ($curroption,$currlimit);
1893: if (ref($settings) eq 'HASH') {
1894: if (ref($settings->{$item}) eq 'HASH') {
1895: $curroption = $settings->{$item}->{'_LC_adv'};
1896: if ($curroption =~ /^autolimit=(\d*)$/) {
1897: $currlimit = $1;
1898: }
1899: }
1900: }
1901: $datatable .= '<th>'.$titles{$item}.'</th>';
1.104 raeburn 1902: my $checked = '';
1903: if ($curroption eq '') {
1904: $checked = ' checked="checked"';
1905: }
1906: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
1907: '<input type="radio" name="crsreq_'.$item.
1908: '__LC_adv" value=""'.$checked.' />'.
1909: &mt('No override set').'</label></span> ';
1.101 raeburn 1910: foreach my $option (@options) {
1911: my $val = $option;
1912: if ($option eq 'norequest') {
1913: $val = 0;
1914: }
1915: if ($option eq 'validate') {
1916: my $canvalidate = 0;
1917: if (ref($validations{$item}) eq 'HASH') {
1918: if ($validations{$item}{'_LC_adv'}) {
1919: $canvalidate = 1;
1920: }
1921: }
1922: next if (!$canvalidate);
1923: }
1924: my $checked = '';
1.104 raeburn 1925: if ($val eq $curroption) {
1.101 raeburn 1926: $checked = ' checked="checked"';
1927: } elsif ($option eq 'autolimit') {
1928: if ($curroption =~ /^autolimit/) {
1929: $checked = ' checked="checked"';
1930: }
1931: }
1932: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
1933: '<input type="radio" name="crsreq_'.$item.
1934: '__LC_adv" value="'.$val.'"'.$checked.' />'.
1935: $titles{$option}.'</label>';
1936: if ($option eq 'autolimit') {
1.127 raeburn 1937: $advcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 1938: $item.'_limit__LC_adv" size="1" '.
1939: 'value="'.$currlimit.'" />';
1940: }
1.127 raeburn 1941: $advcell{$item} .= '</span> ';
1.104 raeburn 1942: if ($option eq 'autolimit') {
1.127 raeburn 1943: $advcell{$item} .= $titles{'unlimited'};
1.104 raeburn 1944: }
1.101 raeburn 1945: }
1.163 raeburn 1946: } elsif ($context eq 'requestauthor') {
1947: my $curroption;
1948: if (ref($settings) eq 'HASH') {
1949: $curroption = $settings->{'_LC_adv'};
1950: }
1951: my $checked = '';
1952: if ($curroption eq '') {
1953: $checked = ' checked="checked"';
1954: }
1955: $datatable .= '<span class="LC_nobreak"><label>'.
1956: '<input type="radio" name="authorreq__LC_adv"'.
1957: ' value=""'.$checked.' />'.
1958: &mt('No override set').'</label></span> ';
1959: foreach my $option (@options) {
1960: my $val = $option;
1961: if ($option eq 'norequest') {
1962: $val = 0;
1963: }
1964: my $checked = '';
1965: if ($val eq $curroption) {
1966: $checked = ' checked="checked"';
1967: }
1968: $datatable .= '<span class="LC_nobreak"><label>'.
1.173 raeburn 1969: '<input type="radio" name="authorreq__LC_adv"'.
1970: ' value="'.$val.'"'.$checked.' />'.
1.163 raeburn 1971: $titles{$option}.'</label></span> ';
1972: }
1.101 raeburn 1973: } else {
1974: my $checked = 'checked="checked" ';
1975: if (ref($settings) eq 'HASH') {
1976: if (ref($settings->{$item}) eq 'HASH') {
1977: if ($settings->{$item}->{'_LC_adv'} == 0) {
1978: $checked = '';
1979: } elsif ($settings->{$item}->{'_LC_adv'} == 1) {
1980: $checked = 'checked="checked" ';
1981: }
1.79 raeburn 1982: }
1.72 raeburn 1983: }
1.101 raeburn 1984: $datatable .= '<span class="LC_nobreak"><label>'.
1985: '<input type="checkbox" name="'.$context.'_'.$item.
1986: '" value="_LC_adv" '.$checked.'/>'.$titles{$item}.
1987: '</label></span> ';
1988: }
1989: }
1990: if ($context eq 'requestcourses') {
1991: $datatable .= '</tr><tr>';
1992: foreach my $item (@usertools) {
1.106 raeburn 1993: $datatable .= '<td style="vertical-align: top">'.$advcell{$item}.'</td>';
1.72 raeburn 1994: }
1.101 raeburn 1995: $datatable .= '</tr></table>';
1.72 raeburn 1996: }
1.98 raeburn 1997: $datatable .= '</td></tr>';
1.30 raeburn 1998: $$rowtotal += $typecount;
1.3 raeburn 1999: return $datatable;
2000: }
2001:
1.163 raeburn 2002: sub print_requestmail {
2003: my ($dom,$action,$settings,$rowtotal) = @_;
1.208 raeburn 2004: my ($now,$datatable,%currapp);
1.102 raeburn 2005: $now = time;
2006: if (ref($settings) eq 'HASH') {
2007: if (ref($settings->{'notify'}) eq 'HASH') {
2008: if ($settings->{'notify'}{'approval'} ne '') {
1.224 raeburn 2009: map {$currapp{$_}=1;} split(/,/,$settings->{'notify'}{'approval'});
1.102 raeburn 2010: }
2011: }
2012: }
1.191 raeburn 2013: my $numinrow = 2;
1.224 raeburn 2014: my $css_class;
2015: $css_class = ($$rowtotal%2? ' class="LC_odd_row"':'');
1.163 raeburn 2016: my $text;
2017: if ($action eq 'requestcourses') {
2018: $text = &mt('Receive notification of course requests requiring approval');
1.224 raeburn 2019: } elsif ($action eq 'requestauthor') {
2020: $text = &mt('Receive notification of Authoring Space requests requiring approval');
1.163 raeburn 2021: } else {
1.224 raeburn 2022: $text = &mt('Receive notification of queued requests for self-created user accounts requiring approval');
1.163 raeburn 2023: }
1.224 raeburn 2024: $datatable = '<tr'.$css_class.'>'.
1.163 raeburn 2025: ' <td>'.$text.'</td>'.
1.102 raeburn 2026: ' <td class="LC_left_item">';
1.191 raeburn 2027: my ($numdc,$table,$rows) = &active_dc_picker($dom,$numinrow,'checkbox',
1.224 raeburn 2028: $action.'notifyapproval',%currapp);
1.191 raeburn 2029: if ($numdc > 0) {
2030: $datatable .= $table;
1.102 raeburn 2031: } else {
2032: $datatable .= &mt('There are no active Domain Coordinators');
2033: }
2034: $datatable .='</td></tr>';
2035: $$rowtotal += $rows;
2036: return $datatable;
2037: }
2038:
1.216 raeburn 2039: sub print_studentcode {
2040: my ($settings,$rowtotal) = @_;
2041: my $rownum = 0;
1.218 raeburn 2042: my ($output,%current);
2043: my @crstypes = ('official','unofficial','community','textbook');
2044: if (ref($settings->{'uniquecode'}) eq 'HASH') {
2045: foreach my $type (@crstypes) {
2046: $current{$type} = $settings->{'uniquecode'}{$type};
2047: }
2048: }
2049: $output .= '<tr>'.
2050: '<td class="LC_left_item">'.&mt('Generate unique six character code as course identifier?').'</td>'.
2051: '<td class="LC_left_item">';
2052: foreach my $type (@crstypes) {
2053: my $check = ' ';
2054: if ($current{$type}) {
2055: $check = ' checked="checked" ';
2056: }
2057: $output .= '<span class="LC_nobreak"><label>'.
2058: '<input type="checkbox" name="uniquecode" value="'.$type.'"'.$check.'/>'.
2059: &mt($type).'</label></span>'.(' 'x2).' ';
2060: }
2061: $output .= '</td></tr>';
2062: $$rowtotal ++;
2063: return $output;
1.216 raeburn 2064: }
2065:
2066: sub print_textbookcourses {
2067: my ($dom,$settings,$rowtotal) = @_;
2068: my $rownum = 0;
2069: my $css_class;
2070: my $itemcount = 1;
2071: my $maxnum = 0;
2072: my $bookshash;
2073: if (ref($settings) eq 'HASH') {
2074: $bookshash = $settings->{'textbooks'};
2075: }
2076: my %ordered;
2077: if (ref($bookshash) eq 'HASH') {
2078: foreach my $item (keys(%{$bookshash})) {
2079: if (ref($bookshash->{$item}) eq 'HASH') {
2080: my $num = $bookshash->{$item}{'order'};
2081: $ordered{$num} = $item;
2082: }
2083: }
2084: }
2085: my $confname = $dom.'-domainconfig';
2086: my $switchserver = &check_switchserver($dom,$confname);
2087: my $maxnum = scalar(keys(%ordered));
1.217 raeburn 2088: my $datatable = &textbookcourses_javascript(\%ordered);
1.216 raeburn 2089: if (keys(%ordered)) {
2090: my @items = sort { $a <=> $b } keys(%ordered);
2091: for (my $i=0; $i<@items; $i++) {
2092: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2093: my $key = $ordered{$items[$i]};
2094: my %coursehash=&Apache::lonnet::coursedescription($key);
2095: my $coursetitle = $coursehash{'description'};
2096: my ($subject,$title,$author,$image,$imgsrc,$cdom,$cnum);
2097: if (ref($bookshash->{$key}) eq 'HASH') {
2098: $subject = $bookshash->{$key}->{'subject'};
2099: $title = $bookshash->{$key}->{'title'};
2100: $author = $bookshash->{$key}->{'author'};
2101: $image = $bookshash->{$key}->{'image'};
2102: if ($image ne '') {
2103: my ($path,$imagefile) = ($image =~ m{^(.+)/([^/]+)$});
2104: my $imagethumb = "$path/tn-".$imagefile;
2105: $imgsrc = '<img src="'.$imagethumb.'" alt="'.&mt('Textbook image').'" />';
2106: }
2107: }
1.217 raeburn 2108: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$key'".');"';
1.216 raeburn 2109: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
2110: .'<select name="'.$key.'"'.$chgstr.'>';
2111: for (my $k=0; $k<=$maxnum; $k++) {
2112: my $vpos = $k+1;
2113: my $selstr;
2114: if ($k == $i) {
2115: $selstr = ' selected="selected" ';
2116: }
2117: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2118: }
2119: $datatable .= '</select>'.(' 'x2).
2120: '<label><input type="checkbox" name="book_del" value="'.$key.'" />'.
2121: &mt('Delete?').'</label></span></td>'.
2122: '<td colspan="2">'.
2123: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="book_subject_'.$i.'" value="'.$subject.'" /></span> '.
2124: (' 'x2).
2125: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="book_title_'.$i.'" value="'.$title.'" /></span> '.
2126: (' 'x2).
2127: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="book_author_'.$i.'" value="'.$author.'" /></span> '.
2128: (' 'x2).
2129: '<span class="LC_nobreak">'.&mt('Thumbnail:');
2130: if ($image) {
2131: $datatable .= '<span class="LC_nobreak">'.
2132: $imgsrc.
2133: '<label><input type="checkbox" name="book_image_del"'.
2134: ' value="'.$key.'" />'.&mt('Delete?').'</label></span> '.
2135: '<span class="LC_nobreak"> '.&mt('Replace:').' ';
2136: }
2137: if ($switchserver) {
2138: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2139: } else {
2140: $datatable .= '<input type="file" name="book_image_'.$i.'" value="" />';
2141: }
2142: $datatable .= '<input type="hidden" name="book_id_'.$i.'" value="'.$key.'" /></span> '.
2143: '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
2144: $coursetitle.'</span></td></tr>'."\n";
2145: $itemcount ++;
2146: }
2147: }
2148: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.217 raeburn 2149: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'addbook_pos'".');"';
1.216 raeburn 2150: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
2151: '<input type="hidden" name="book_maxnum" value="'.$maxnum.'" />'."\n".
2152: '<select name="addbook_pos"'.$chgstr.'>';
2153: for (my $k=0; $k<$maxnum+1; $k++) {
2154: my $vpos = $k+1;
2155: my $selstr;
2156: if ($k == $maxnum) {
2157: $selstr = ' selected="selected" ';
2158: }
2159: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2160: }
2161: $datatable .= '</select> '."\n".
2162: '<input type="checkbox" name="addbook" value="1" />'.&mt('Add').'</td>'."\n".
2163: '<td colspan="2">'.
2164: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="addbook_subject" value="" /></span> '."\n".
2165: (' 'x2).
2166: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="addbook_title" value="" /></span> '."\n".
2167: (' 'x2).
2168: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="addbook_author" value="" /></span> '."\n".
2169: (' 'x2).
2170: '<span class="LC_nobreak">'.&mt('Image:').' ';
2171: if ($switchserver) {
2172: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2173: } else {
2174: $datatable .= '<input type="file" name="addbook_image" value="" />';
2175: }
2176: $datatable .= '</span>'."\n".
2177: '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
2178: &Apache::loncommon::select_dom_form($env{'request.role.domain'},'addbook_cdom').
2179: '<input type="text" size="25" name="addbook_cnum" value="" />'.
2180: &Apache::loncommon::selectcourse_link
2181: ('display','addbook_cnum','addbook_cdom',undef,undef,undef,'Course');
2182: '</span></td>'."\n".
2183: '</tr>'."\n";
2184: $itemcount ++;
2185: return $datatable;
2186: }
2187:
1.217 raeburn 2188: sub textbookcourses_javascript {
2189: my ($textbooks) = @_;
2190: return unless(ref($textbooks) eq 'HASH');
2191: my $num = scalar(keys(%{$textbooks}));
2192: my @jsarray;
2193: foreach my $item (sort {$a <=> $b } (keys(%{$textbooks}))) {
2194: push(@jsarray,$textbooks->{$item});
2195: }
2196: my $jstext = ' var textbooks = Array('."'".join("','",@jsarray)."'".');'."\n";
2197: return <<"ENDSCRIPT";
2198: <script type="text/javascript">
2199: // <![CDATA[
2200: function reorderBooks(form,item) {
2201: var changedVal;
2202: $jstext
2203: var newpos = 'addbook_pos';
2204: var current = new Array;
2205: var maxh = 1 + $num;
2206: var current = new Array;
2207: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
2208: if (item == newpos) {
2209: changedVal = newitemVal;
2210: } else {
2211: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
2212: current[newitemVal] = newpos;
2213: }
2214: for (var i=0; i<textbooks.length; i++) {
2215: var elementName = textbooks[i];
2216: if (elementName != item) {
2217: if (form.elements[elementName]) {
2218: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2219: current[currVal] = elementName;
2220: }
2221: }
2222: }
2223: var oldVal;
2224: for (var j=0; j<maxh; j++) {
2225: if (current[j] == undefined) {
2226: oldVal = j;
2227: }
2228: }
2229: if (oldVal < changedVal) {
2230: for (var k=oldVal+1; k<=changedVal ; k++) {
2231: var elementName = current[k];
2232: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
2233: }
2234: } else {
2235: for (var k=changedVal; k<oldVal; k++) {
2236: var elementName = current[k];
2237: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
2238: }
2239: }
2240: return;
2241: }
2242:
2243: // ]]>
2244: </script>
2245:
2246: ENDSCRIPT
2247: }
2248:
1.3 raeburn 2249: sub print_autoenroll {
1.30 raeburn 2250: my ($dom,$settings,$rowtotal) = @_;
1.3 raeburn 2251: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
1.129 raeburn 2252: my ($defdom,$runon,$runoff,$coownerson,$coownersoff);
1.3 raeburn 2253: if (ref($settings) eq 'HASH') {
2254: if (exists($settings->{'run'})) {
2255: if ($settings->{'run'} eq '0') {
2256: $runoff = ' checked="checked" ';
2257: $runon = ' ';
2258: } else {
2259: $runon = ' checked="checked" ';
2260: $runoff = ' ';
2261: }
2262: } else {
2263: if ($autorun) {
2264: $runon = ' checked="checked" ';
2265: $runoff = ' ';
2266: } else {
2267: $runoff = ' checked="checked" ';
2268: $runon = ' ';
2269: }
2270: }
1.129 raeburn 2271: if (exists($settings->{'co-owners'})) {
2272: if ($settings->{'co-owners'} eq '0') {
2273: $coownersoff = ' checked="checked" ';
2274: $coownerson = ' ';
2275: } else {
2276: $coownerson = ' checked="checked" ';
2277: $coownersoff = ' ';
2278: }
2279: } else {
2280: $coownersoff = ' checked="checked" ';
2281: $coownerson = ' ';
2282: }
1.3 raeburn 2283: if (exists($settings->{'sender_domain'})) {
2284: $defdom = $settings->{'sender_domain'};
2285: }
1.14 raeburn 2286: } else {
2287: if ($autorun) {
2288: $runon = ' checked="checked" ';
2289: $runoff = ' ';
2290: } else {
2291: $runoff = ' checked="checked" ';
2292: $runon = ' ';
2293: }
1.3 raeburn 2294: }
2295: my $domform = &Apache::loncommon::select_dom_form($defdom,'sender_domain',1);
1.39 raeburn 2296: my $notif_sender;
2297: if (ref($settings) eq 'HASH') {
2298: $notif_sender = $settings->{'sender_uname'};
2299: }
1.3 raeburn 2300: my $datatable='<tr class="LC_odd_row">'.
2301: '<td>'.&mt('Auto-enrollment active?').'</td>'.
1.8 raeburn 2302: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 2303: '<input type="radio" name="autoenroll_run"'.
1.8 raeburn 2304: $runon.' value="1" />'.&mt('Yes').'</label> '.
2305: '<label><input type="radio" name="autoenroll_run"'.
1.14 raeburn 2306: $runoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 2307: '</tr><tr>'.
2308: '<td>'.&mt('Notification messages - sender').
1.8 raeburn 2309: '</td><td class="LC_right_item"><span class="LC_nobreak">'.
1.3 raeburn 2310: &mt('username').': '.
2311: '<input type="text" name="sender_uname" value="'.
1.39 raeburn 2312: $notif_sender.'" size="10" /> '.&mt('domain').
1.129 raeburn 2313: ': '.$domform.'</span></td></tr>'.
2314: '<tr class="LC_odd_row">'.
2315: '<td>'.&mt('Automatically assign co-ownership').'</td>'.
2316: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2317: '<input type="radio" name="autoassign_coowners"'.
2318: $coownerson.' value="1" />'.&mt('Yes').'</label> '.
2319: '<label><input type="radio" name="autoassign_coowners"'.
2320: $coownersoff.' value="0" />'.&mt('No').'</label></span></td>'.
2321: '</tr>';
2322: $$rowtotal += 3;
1.3 raeburn 2323: return $datatable;
2324: }
2325:
2326: sub print_autoupdate {
1.30 raeburn 2327: my ($position,$dom,$settings,$rowtotal) = @_;
1.3 raeburn 2328: my $datatable;
2329: if ($position eq 'top') {
2330: my $updateon = ' ';
2331: my $updateoff = ' checked="checked" ';
2332: my $classlistson = ' ';
2333: my $classlistsoff = ' checked="checked" ';
2334: if (ref($settings) eq 'HASH') {
2335: if ($settings->{'run'} eq '1') {
2336: $updateon = $updateoff;
2337: $updateoff = ' ';
2338: }
2339: if ($settings->{'classlists'} eq '1') {
2340: $classlistson = $classlistsoff;
2341: $classlistsoff = ' ';
2342: }
2343: }
2344: my %title = (
2345: run => 'Auto-update active?',
2346: classlists => 'Update information in classlists?',
2347: );
2348: $datatable = '<tr class="LC_odd_row">'.
2349: '<td>'.&mt($title{'run'}).'</td>'.
1.8 raeburn 2350: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 2351: '<input type="radio" name="autoupdate_run"'.
1.8 raeburn 2352: $updateon.' value="1" />'.&mt('Yes').'</label> '.
2353: '<label><input type="radio" name="autoupdate_run"'.
2354: $updateoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 2355: '</tr><tr>'.
2356: '<td>'.&mt($title{'classlists'}).'</td>'.
1.8 raeburn 2357: '<td class="LC_right_item"><span class="LC_nobreak">'.
2358: '<label><input type="radio" name="classlists"'.
2359: $classlistson.' value="1" />'.&mt('Yes').'</label> '.
2360: '<label><input type="radio" name="classlists"'.
2361: $classlistsoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 2362: '</tr>';
1.30 raeburn 2363: $$rowtotal += 2;
1.131 raeburn 2364: } elsif ($position eq 'middle') {
2365: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
2366: my $numinrow = 3;
2367: my $locknamesettings;
2368: $datatable .= &insttypes_row($settings,$types,$usertypes,
2369: $dom,$numinrow,$othertitle,
2370: 'lockablenames');
2371: $$rowtotal ++;
1.3 raeburn 2372: } else {
1.44 raeburn 2373: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.132 raeburn 2374: my @fields = ('lastname','firstname','middlename','generation',
1.20 raeburn 2375: 'permanentemail','id');
1.33 raeburn 2376: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1.3 raeburn 2377: my $numrows = 0;
1.26 raeburn 2378: if (ref($types) eq 'ARRAY') {
2379: if (@{$types} > 0) {
2380: $datatable =
2381: &usertype_update_row($settings,$usertypes,\%fieldtitles,
2382: \@fields,$types,\$numrows);
1.30 raeburn 2383: $$rowtotal += @{$types};
1.26 raeburn 2384: }
1.3 raeburn 2385: }
2386: $datatable .=
2387: &usertype_update_row($settings,{'default' => $othertitle},
2388: \%fieldtitles,\@fields,['default'],
2389: \$numrows);
1.30 raeburn 2390: $$rowtotal ++;
1.3 raeburn 2391: }
2392: return $datatable;
2393: }
2394:
1.125 raeburn 2395: sub print_autocreate {
2396: my ($dom,$settings,$rowtotal) = @_;
1.191 raeburn 2397: my (%createon,%createoff,%currhash);
1.125 raeburn 2398: my @types = ('xml','req');
2399: if (ref($settings) eq 'HASH') {
2400: foreach my $item (@types) {
2401: $createoff{$item} = ' checked="checked" ';
2402: $createon{$item} = ' ';
2403: if (exists($settings->{$item})) {
2404: if ($settings->{$item}) {
2405: $createon{$item} = ' checked="checked" ';
2406: $createoff{$item} = ' ';
2407: }
2408: }
2409: }
1.210 raeburn 2410: if ($settings->{'xmldc'} ne '') {
1.191 raeburn 2411: $currhash{$settings->{'xmldc'}} = 1;
2412: }
1.125 raeburn 2413: } else {
2414: foreach my $item (@types) {
2415: $createoff{$item} = ' checked="checked" ';
2416: $createon{$item} = ' ';
2417: }
2418: }
2419: $$rowtotal += 2;
1.191 raeburn 2420: my $numinrow = 2;
1.125 raeburn 2421: my $datatable='<tr class="LC_odd_row">'.
2422: '<td>'.&mt('Create pending official courses from XML files').'</td>'.
2423: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2424: '<input type="radio" name="autocreate_xml"'.
2425: $createon{'xml'}.' value="1" />'.&mt('Yes').'</label> '.
2426: '<label><input type="radio" name="autocreate_xml"'.
1.143 raeburn 2427: $createoff{'xml'}.' value="0" />'.&mt('No').'</label></span>'.
2428: '</td></tr><tr>'.
2429: '<td>'.&mt('Create pending requests for official courses (if validated)').'</td>'.
2430: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2431: '<input type="radio" name="autocreate_req"'.
2432: $createon{'req'}.' value="1" />'.&mt('Yes').'</label> '.
2433: '<label><input type="radio" name="autocreate_req"'.
2434: $createoff{'req'}.' value="0" />'.&mt('No').'</label></span>';
1.191 raeburn 2435: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
2436: 'autocreate_xmldc',%currhash);
1.125 raeburn 2437: if ($numdc > 1) {
1.143 raeburn 2438: $datatable .= '</td></tr><tr class="LC_odd_row"><td>'.
2439: &mt('Course creation processed as: (choose Dom. Coord.)').
2440: '</td><td class="LC_left_item">'.$dctable.'</td></tr>';
1.125 raeburn 2441: } else {
1.143 raeburn 2442: $datatable .= $dctable.'</td></tr>';
1.125 raeburn 2443: }
1.191 raeburn 2444: $$rowtotal += $rows;
1.125 raeburn 2445: return $datatable;
2446: }
2447:
1.23 raeburn 2448: sub print_directorysrch {
1.30 raeburn 2449: my ($dom,$settings,$rowtotal) = @_;
1.23 raeburn 2450: my $srchon = ' ';
2451: my $srchoff = ' checked="checked" ';
1.25 raeburn 2452: my ($exacton,$containson,$beginson);
1.24 raeburn 2453: my $localon = ' ';
2454: my $localoff = ' checked="checked" ';
1.23 raeburn 2455: if (ref($settings) eq 'HASH') {
2456: if ($settings->{'available'} eq '1') {
2457: $srchon = $srchoff;
2458: $srchoff = ' ';
2459: }
1.24 raeburn 2460: if ($settings->{'localonly'} eq '1') {
2461: $localon = $localoff;
2462: $localoff = ' ';
2463: }
1.25 raeburn 2464: if (ref($settings->{'searchtypes'}) eq 'ARRAY') {
2465: foreach my $type (@{$settings->{'searchtypes'}}) {
2466: if ($type eq 'exact') {
2467: $exacton = ' checked="checked" ';
2468: } elsif ($type eq 'contains') {
2469: $containson = ' checked="checked" ';
2470: } elsif ($type eq 'begins') {
2471: $beginson = ' checked="checked" ';
2472: }
2473: }
2474: } else {
2475: if ($settings->{'searchtypes'} eq 'exact') {
2476: $exacton = ' checked="checked" ';
2477: } elsif ($settings->{'searchtypes'} eq 'contains') {
2478: $containson = ' checked="checked" ';
2479: } elsif ($settings->{'searchtypes'} eq 'specify') {
2480: $exacton = ' checked="checked" ';
2481: $containson = ' checked="checked" ';
2482: }
1.23 raeburn 2483: }
2484: }
2485: my ($searchtitles,$titleorder) = &sorted_searchtitles();
1.45 raeburn 2486: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.23 raeburn 2487:
2488: my $numinrow = 4;
1.26 raeburn 2489: my $cansrchrow = 0;
1.23 raeburn 2490: my $datatable='<tr class="LC_odd_row">'.
1.30 raeburn 2491: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Directory search available?').'</span></td>'.
1.23 raeburn 2492: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2493: '<input type="radio" name="dirsrch_available"'.
2494: $srchon.' value="1" />'.&mt('Yes').'</label> '.
2495: '<label><input type="radio" name="dirsrch_available"'.
2496: $srchoff.' value="0" />'.&mt('No').'</label></span></td>'.
2497: '</tr><tr>'.
1.30 raeburn 2498: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search?').'</span></td>'.
1.24 raeburn 2499: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2500: '<input type="radio" name="dirsrch_localonly"'.
2501: $localoff.' value="0" />'.&mt('Yes').'</label> '.
2502: '<label><input type="radio" name="dirsrch_localonly"'.
2503: $localon.' value="1" />'.&mt('No').'</label></span></td>'.
1.25 raeburn 2504: '</tr>';
1.30 raeburn 2505: $$rowtotal += 2;
1.26 raeburn 2506: if (ref($usertypes) eq 'HASH') {
2507: if (keys(%{$usertypes}) > 0) {
1.93 raeburn 2508: $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
2509: $numinrow,$othertitle,'cansearch');
1.26 raeburn 2510: $cansrchrow = 1;
2511: }
2512: }
2513: if ($cansrchrow) {
1.30 raeburn 2514: $$rowtotal ++;
1.26 raeburn 2515: $datatable .= '<tr>';
2516: } else {
2517: $datatable .= '<tr class="LC_odd_row">';
2518: }
1.30 raeburn 2519: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Supported search methods').
2520: '</span></td><td class="LC_left_item" colspan="2"><table><tr>';
1.25 raeburn 2521: foreach my $title (@{$titleorder}) {
2522: if (defined($searchtitles->{$title})) {
2523: my $check = ' ';
1.93 raeburn 2524: if (ref($settings) eq 'HASH') {
1.39 raeburn 2525: if (ref($settings->{'searchby'}) eq 'ARRAY') {
2526: if (grep(/^\Q$title\E$/,@{$settings->{'searchby'}})) {
2527: $check = ' checked="checked" ';
2528: }
1.25 raeburn 2529: }
2530: }
2531: $datatable .= '<td class="LC_left_item">'.
2532: '<span class="LC_nobreak"><label>'.
2533: '<input type="checkbox" name="searchby" '.
2534: 'value="'.$title.'"'.$check.'/>'.
2535: $searchtitles->{$title}.'</label></span></td>';
2536: }
2537: }
1.26 raeburn 2538: $datatable .= '</tr></table></td></tr>';
1.30 raeburn 2539: $$rowtotal ++;
1.26 raeburn 2540: if ($cansrchrow) {
2541: $datatable .= '<tr class="LC_odd_row">';
2542: } else {
2543: $datatable .= '<tr>';
2544: }
1.30 raeburn 2545: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Search latitude').'</span></td>'.
1.26 raeburn 2546: '<td class="LC_left_item" colspan="2">'.
1.25 raeburn 2547: '<span class="LC_nobreak"><label>'.
2548: '<input type="checkbox" name="searchtypes" '.
2549: $exacton.' value="exact" />'.&mt('Exact match').
2550: '</label> '.
2551: '<label><input type="checkbox" name="searchtypes" '.
2552: $beginson.' value="begins" />'.&mt('Begins with').
2553: '</label> '.
2554: '<label><input type="checkbox" name="searchtypes" '.
2555: $containson.' value="contains" />'.&mt('Contains').
2556: '</label></span></td></tr>';
1.30 raeburn 2557: $$rowtotal ++;
1.25 raeburn 2558: return $datatable;
2559: }
2560:
1.28 raeburn 2561: sub print_contacts {
1.30 raeburn 2562: my ($dom,$settings,$rowtotal) = @_;
1.28 raeburn 2563: my $datatable;
2564: my @contacts = ('adminemail','supportemail');
1.134 raeburn 2565: my (%checked,%to,%otheremails,%bccemails);
1.102 raeburn 2566: my @mailings = ('errormail','packagesmail','lonstatusmail','helpdeskmail',
1.203 raeburn 2567: 'requestsmail','updatesmail','idconflictsmail');
1.28 raeburn 2568: foreach my $type (@mailings) {
2569: $otheremails{$type} = '';
2570: }
1.134 raeburn 2571: $bccemails{'helpdeskmail'} = '';
1.28 raeburn 2572: if (ref($settings) eq 'HASH') {
2573: foreach my $item (@contacts) {
2574: if (exists($settings->{$item})) {
2575: $to{$item} = $settings->{$item};
2576: }
2577: }
2578: foreach my $type (@mailings) {
2579: if (exists($settings->{$type})) {
2580: if (ref($settings->{$type}) eq 'HASH') {
2581: foreach my $item (@contacts) {
2582: if ($settings->{$type}{$item}) {
2583: $checked{$type}{$item} = ' checked="checked" ';
2584: }
2585: }
2586: $otheremails{$type} = $settings->{$type}{'others'};
1.134 raeburn 2587: if ($type eq 'helpdeskmail') {
2588: $bccemails{$type} = $settings->{$type}{'bcc'};
2589: }
1.28 raeburn 2590: }
1.89 raeburn 2591: } elsif ($type eq 'lonstatusmail') {
2592: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
1.28 raeburn 2593: }
2594: }
2595: } else {
2596: $to{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
2597: $to{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
2598: $checked{'errormail'}{'adminemail'} = ' checked="checked" ';
2599: $checked{'packagesmail'}{'adminemail'} = ' checked="checked" ';
1.89 raeburn 2600: $checked{'helpdeskmail'}{'supportemail'} = ' checked="checked" ';
2601: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
1.102 raeburn 2602: $checked{'requestsmail'}{'adminemail'} = ' checked="checked" ';
1.190 raeburn 2603: $checked{'updatesmail'}{'adminemail'} = ' checked="checked" ';
1.203 raeburn 2604: $checked{'idconflictsmail'}{'adminemail'} = ' checked="checked" ';
1.28 raeburn 2605: }
2606: my ($titles,$short_titles) = &contact_titles();
2607: my $rownum = 0;
2608: my $css_class;
2609: foreach my $item (@contacts) {
1.69 raeburn 2610: $css_class = $rownum%2?' class="LC_odd_row"':'';
1.30 raeburn 2611: $datatable .= '<tr'.$css_class.'>'.
2612: '<td><span class="LC_nobreak">'.$titles->{$item}.
2613: '</span></td><td class="LC_right_item">'.
1.28 raeburn 2614: '<input type="text" name="'.$item.'" value="'.
2615: $to{$item}.'" /></td></tr>';
1.203 raeburn 2616: $rownum ++;
1.28 raeburn 2617: }
2618: foreach my $type (@mailings) {
1.69 raeburn 2619: $css_class = $rownum%2?' class="LC_odd_row"':'';
1.28 raeburn 2620: $datatable .= '<tr'.$css_class.'>'.
1.30 raeburn 2621: '<td><span class="LC_nobreak">'.
2622: $titles->{$type}.': </span></td>'.
1.28 raeburn 2623: '<td class="LC_left_item">'.
2624: '<span class="LC_nobreak">';
2625: foreach my $item (@contacts) {
2626: $datatable .= '<label>'.
2627: '<input type="checkbox" name="'.$type.'"'.
2628: $checked{$type}{$item}.
2629: ' value="'.$item.'" />'.$short_titles->{$item}.
2630: '</label> ';
2631: }
2632: $datatable .= '</span><br />'.&mt('Others').': '.
2633: '<input type="text" name="'.$type.'_others" '.
1.134 raeburn 2634: 'value="'.$otheremails{$type}.'" />';
2635: if ($type eq 'helpdeskmail') {
1.136 raeburn 2636: $datatable .= '<br />'.&mt('Bcc:').(' 'x6).
1.134 raeburn 2637: '<input type="text" name="'.$type.'_bcc" '.
2638: 'value="'.$bccemails{$type}.'" />';
2639: }
2640: $datatable .= '</td></tr>'."\n";
1.203 raeburn 2641: $rownum ++;
1.28 raeburn 2642: }
1.203 raeburn 2643: my %choices;
2644: $choices{'reporterrors'} = &mt('E-mail error reports to [_1]',
2645: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
2646: &mt('LON-CAPA core group - MSU'),600,500));
2647: $choices{'reportupdates'} = &mt('E-mail record of completed LON-CAPA updates to [_1]',
2648: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
2649: &mt('LON-CAPA core group - MSU'),600,500));
2650: my @toggles = ('reporterrors','reportupdates');
2651: my %defaultchecked = ('reporterrors' => 'on',
2652: 'reportupdates' => 'on');
2653: (my $reports,$rownum) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
2654: \%choices,$rownum);
2655: $datatable .= $reports;
1.30 raeburn 2656: $$rowtotal += $rownum;
1.28 raeburn 2657: return $datatable;
2658: }
2659:
1.118 jms 2660: sub print_helpsettings {
1.168 raeburn 2661: my ($dom,$confname,$settings,$rowtotal) = @_;
2662: my ($datatable,$itemcount);
1.166 raeburn 2663: $itemcount = 1;
1.168 raeburn 2664: my (%choices,%defaultchecked,@toggles);
2665: $choices{'submitbugs'} = &mt('Display link to: [_1]?',
2666: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
2667: &mt('LON-CAPA bug tracker'),600,500));
2668: %defaultchecked = ('submitbugs' => 'on');
2669: @toggles = ('submitbugs',);
1.166 raeburn 2670:
1.168 raeburn 2671: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
2672: \%choices,$itemcount);
1.166 raeburn 2673: return $datatable;
1.121 raeburn 2674: }
2675:
2676: sub radiobutton_prefs {
1.192 raeburn 2677: my ($settings,$toggles,$defaultchecked,$choices,$itemcount,$onclick,
2678: $additional) = @_;
1.121 raeburn 2679: return unless ((ref($toggles) eq 'ARRAY') && (ref($defaultchecked) eq 'HASH') &&
2680: (ref($choices) eq 'HASH'));
2681:
1.170 raeburn 2682: my (%checkedon,%checkedoff,$datatable,$css_class);
1.121 raeburn 2683:
2684: foreach my $item (@{$toggles}) {
2685: if ($defaultchecked->{$item} eq 'on') {
1.118 jms 2686: $checkedon{$item} = ' checked="checked" ';
2687: $checkedoff{$item} = ' ';
1.121 raeburn 2688: } elsif ($defaultchecked->{$item} eq 'off') {
1.118 jms 2689: $checkedoff{$item} = ' checked="checked" ';
2690: $checkedon{$item} = ' ';
2691: }
2692: }
2693: if (ref($settings) eq 'HASH') {
1.121 raeburn 2694: foreach my $item (@{$toggles}) {
1.118 jms 2695: if ($settings->{$item} eq '1') {
2696: $checkedon{$item} = ' checked="checked" ';
2697: $checkedoff{$item} = ' ';
2698: } elsif ($settings->{$item} eq '0') {
2699: $checkedoff{$item} = ' checked="checked" ';
2700: $checkedon{$item} = ' ';
2701: }
2702: }
1.121 raeburn 2703: }
1.192 raeburn 2704: if ($onclick) {
2705: $onclick = ' onclick="'.$onclick.'"';
2706: }
1.121 raeburn 2707: foreach my $item (@{$toggles}) {
1.118 jms 2708: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.121 raeburn 2709: $datatable .=
1.192 raeburn 2710: '<tr'.$css_class.'><td valign="top">'.
2711: '<span class="LC_nobreak">'.$choices->{$item}.
1.118 jms 2712: '</span></td>'.
2713: '<td class="LC_right_item"><span class="LC_nobreak">'.
2714: '<label><input type="radio" name="'.
1.192 raeburn 2715: $item.'" '.$checkedon{$item}.' value="1"'.$onclick.' />'.&mt('Yes').
1.118 jms 2716: '</label> <label><input type="radio" name="'.$item.'" '.
1.192 raeburn 2717: $checkedoff{$item}.' value="0"'.$onclick.' />'.&mt('No').'</label>'.
2718: '</span>'.$additional.
2719: '</td>'.
1.118 jms 2720: '</tr>';
2721: $itemcount ++;
1.121 raeburn 2722: }
2723: return ($datatable,$itemcount);
2724: }
2725:
2726: sub print_coursedefaults {
1.139 raeburn 2727: my ($position,$dom,$settings,$rowtotal) = @_;
1.192 raeburn 2728: my ($css_class,$datatable,%checkedon,%checkedoff,%defaultchecked,@toggles);
1.121 raeburn 2729: my $itemcount = 1;
1.192 raeburn 2730: my %choices = &Apache::lonlocal::texthash (
2731: canuse_pdfforms => 'Course/Community users can create/upload PDF forms',
1.198 raeburn 2732: uploadquota => 'Default quota for files uploaded directly to course/community using Course Editor (MB)',
1.192 raeburn 2733: anonsurvey_threshold => 'Responder count needed before showing submissions for anonymous surveys',
2734: coursecredits => 'Credits can be specified for courses',
2735: );
1.198 raeburn 2736: my %staticdefaults = (
2737: anonsurvey_threshold => 10,
2738: uploadquota => 500,
2739: );
1.139 raeburn 2740: if ($position eq 'top') {
2741: %defaultchecked = ('canuse_pdfforms' => 'off');
1.192 raeburn 2742: @toggles = ('canuse_pdfforms');
1.139 raeburn 2743: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
1.121 raeburn 2744: \%choices,$itemcount);
1.139 raeburn 2745: } else {
2746: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.216 raeburn 2747: my ($currdefresponder,$def_official_credits,$def_unofficial_credits,$def_textbook_credits,
2748: %curruploadquota);
1.192 raeburn 2749: my $currusecredits = 0;
1.216 raeburn 2750: my @types = ('official','unofficial','community','textbook');
1.139 raeburn 2751: if (ref($settings) eq 'HASH') {
2752: $currdefresponder = $settings->{'anonsurvey_threshold'};
1.198 raeburn 2753: if (ref($settings->{'uploadquota'}) eq 'HASH') {
2754: foreach my $type (keys(%{$settings->{'uploadquota'}})) {
2755: $curruploadquota{$type} = $settings->{'uploadquota'}{$type};
2756: }
2757: }
1.192 raeburn 2758: if (ref($settings->{'coursecredits'}) eq 'HASH') {
2759: $def_official_credits = $settings->{'coursecredits'}->{'official'};
2760: $def_unofficial_credits = $settings->{'coursecredits'}->{'unofficial'};
1.216 raeburn 2761: $def_textbook_credits = $settings->{'coursecredits'}->{'textbook'};
2762: if (($def_official_credits ne '') || ($def_unofficial_credits ne '') ||
2763: ($def_textbook_credits ne '')) {
1.192 raeburn 2764: $currusecredits = 1;
2765: }
2766: }
1.139 raeburn 2767: }
2768: if (!$currdefresponder) {
1.198 raeburn 2769: $currdefresponder = $staticdefaults{'anonsurvey_threshold'};
1.139 raeburn 2770: } elsif ($currdefresponder < 1) {
2771: $currdefresponder = 1;
2772: }
1.198 raeburn 2773: foreach my $type (@types) {
2774: if ($curruploadquota{$type} eq '') {
2775: $curruploadquota{$type} = $staticdefaults{'uploadquota'};
2776: }
2777: }
1.139 raeburn 2778: $datatable .=
1.192 raeburn 2779: '<tr'.$css_class.'><td><span class="LC_nobreak">'.
2780: $choices{'anonsurvey_threshold'}.
1.139 raeburn 2781: '</span></td>'.
2782: '<td class="LC_right_item"><span class="LC_nobreak">'.
2783: '<input type="text" name="anonsurvey_threshold"'.
2784: ' value="'.$currdefresponder.'" size="5" /></span>'.
1.198 raeburn 2785: '</td></tr>'."\n".
2786: '<tr><td><span class="LC_nobreak">'.
2787: $choices{'uploadquota'}.
2788: '</span></td>'.
2789: '<td align="right" class="LC_right_item">'.
2790: '<table><tr>';
2791: foreach my $type (@types) {
2792: $datatable .= '<td align="center">'.&mt($type).'<br />'.
2793: '<input type="text" name="uploadquota_'.$type.'"'.
2794: ' value="'.$curruploadquota{$type}.'" size="5" /></td>';
2795: }
2796: $datatable .= '</tr></table></td></tr>'."\n";
2797: $itemcount += 2;
1.192 raeburn 2798: my $onclick = 'toggleCredits(this.form);';
1.210 raeburn 2799: my $display = 'none';
1.192 raeburn 2800: if ($currusecredits) {
2801: $display = 'block';
2802: }
2803: my $additional = '<div id="credits" style="display: '.$display.'">'.
2804: '<span class="LC_nobreak">'.
2805: &mt('Default credits for official courses [_1]',
2806: '<input type="text" name="official_credits" value="'.
2807: $def_official_credits.'" size="3" />').
2808: '</span><br />'.
2809: '<span class="LC_nobreak">'.
2810: &mt('Default credits for unofficial courses [_1]',
2811: '<input type="text" name="unofficial_credits" value="'.
2812: $def_unofficial_credits.'" size="3" />').
1.216 raeburn 2813: '</span><br />'.
2814: '<span class="LC_nobreak">'.
2815: &mt('Default credits for textbook courses [_1]',
2816: '<input type="text" name="textbook_credits" value="'.
2817: $def_textbook_credits.'" size="3" />').
1.192 raeburn 2818: '</span></div>'."\n";
2819: %defaultchecked = ('coursecredits' => 'off');
2820: @toggles = ('coursecredits');
2821: my $current = {
2822: 'coursecredits' => $currusecredits,
2823: };
2824: (my $table,$itemcount) =
2825: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
2826: \%choices,$itemcount,$onclick,$additional);
2827: $datatable .= $table;
1.139 raeburn 2828: }
1.192 raeburn 2829: $$rowtotal += $itemcount;
1.121 raeburn 2830: return $datatable;
1.118 jms 2831: }
2832:
1.137 raeburn 2833: sub print_usersessions {
2834: my ($position,$dom,$settings,$rowtotal) = @_;
2835: my ($css_class,$datatable,%checked,%choices);
1.140 raeburn 2836: my (%by_ip,%by_location,@intdoms);
2837: &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
1.145 raeburn 2838:
2839: my @alldoms = &Apache::lonnet::all_domains();
1.152 raeburn 2840: my %serverhomes = %Apache::lonnet::serverhomeIDs;
1.149 raeburn 2841: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.152 raeburn 2842: my %altids = &id_for_thisdom(%servers);
1.145 raeburn 2843: my $itemcount = 1;
2844: if ($position eq 'top') {
1.152 raeburn 2845: if (keys(%serverhomes) > 1) {
1.145 raeburn 2846: my %spareid = ¤t_offloads_to($dom,$settings,\%servers);
1.152 raeburn 2847: $datatable .= &spares_row($dom,\%servers,\%spareid,\%serverhomes,\%altids,$rowtotal);
1.145 raeburn 2848: } else {
1.140 raeburn 2849: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.150 raeburn 2850: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one server.');
1.140 raeburn 2851: }
1.137 raeburn 2852: } else {
1.145 raeburn 2853: if (keys(%by_location) == 0) {
2854: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.150 raeburn 2855: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one institution.');
1.145 raeburn 2856: } else {
2857: my %lt = &usersession_titles();
2858: my $numinrow = 5;
2859: my $prefix;
2860: my @types;
2861: if ($position eq 'bottom') {
2862: $prefix = 'remote';
2863: @types = ('version','excludedomain','includedomain');
2864: } else {
2865: $prefix = 'hosted';
2866: @types = ('excludedomain','includedomain');
2867: }
2868: my (%current,%checkedon,%checkedoff);
2869: my @lcversions = &Apache::lonnet::all_loncaparevs();
2870: my @locations = sort(keys(%by_location));
2871: foreach my $type (@types) {
2872: $checkedon{$type} = '';
2873: $checkedoff{$type} = ' checked="checked"';
2874: }
2875: if (ref($settings) eq 'HASH') {
2876: if (ref($settings->{$prefix}) eq 'HASH') {
2877: foreach my $key (keys(%{$settings->{$prefix}})) {
2878: $current{$key} = $settings->{$prefix}{$key};
2879: if ($key eq 'version') {
2880: if ($current{$key} ne '') {
2881: $checkedon{$key} = ' checked="checked"';
2882: $checkedoff{$key} = '';
2883: }
2884: } elsif (ref($current{$key}) eq 'ARRAY') {
2885: $checkedon{$key} = ' checked="checked"';
2886: $checkedoff{$key} = '';
2887: }
1.137 raeburn 2888: }
2889: }
2890: }
1.145 raeburn 2891: foreach my $type (@types) {
2892: next if ($type ne 'version' && !@locations);
2893: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
2894: $datatable .= '<tr'.$css_class.'>
2895: <td><span class="LC_nobreak">'.$lt{$type}.'</span><br />
2896: <span class="LC_nobreak">
2897: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedoff{$type}.' value="0" />'.&mt('Not in use').'</label>
2898: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedon{$type}.' value="1" />'.&mt('In use').'</label></span></td><td>';
2899: if ($type eq 'version') {
2900: my $selector = '<select name="'.$prefix.'_version">';
2901: foreach my $version (@lcversions) {
2902: my $selected = '';
2903: if ($current{'version'} eq $version) {
2904: $selected = ' selected="selected"';
2905: }
2906: $selector .= ' <option value="'.$version.'"'.
2907: $selected.'>'.$version.'</option>';
2908: }
2909: $selector .= '</select> ';
2910: $datatable .= &mt('remote server must be version: [_1] or later',$selector);
2911: } else {
2912: $datatable.= '<div><input type="button" value="'.&mt('check all').'" '.
2913: 'onclick="javascript:checkAll(document.display.'.$prefix.'_'.$type.')"'.
2914: ' />'.(' 'x2).
2915: '<input type="button" value="'.&mt('uncheck all').'" '.
2916: 'onclick="javascript:uncheckAll(document.display.'.$prefix.'_'.$type.')" />'.
2917: "\n".
2918: '</div><div><table>';
2919: my $rem;
2920: for (my $i=0; $i<@locations; $i++) {
2921: my ($showloc,$value,$checkedtype);
2922: if (ref($by_location{$locations[$i]}) eq 'ARRAY') {
2923: my $ip = $by_location{$locations[$i]}->[0];
2924: if (ref($by_ip{$ip}) eq 'ARRAY') {
2925: $value = join(':',@{$by_ip{$ip}});
2926: $showloc = join(', ',@{$by_ip{$ip}});
2927: if (ref($current{$type}) eq 'ARRAY') {
2928: foreach my $loc (@{$by_ip{$ip}}) {
2929: if (grep(/^\Q$loc\E$/,@{$current{$type}})) {
2930: $checkedtype = ' checked="checked"';
2931: last;
2932: }
2933: }
1.138 raeburn 2934: }
2935: }
2936: }
1.145 raeburn 2937: $rem = $i%($numinrow);
2938: if ($rem == 0) {
2939: if ($i > 0) {
2940: $datatable .= '</tr>';
2941: }
2942: $datatable .= '<tr>';
2943: }
2944: $datatable .= '<td class="LC_left_item">'.
2945: '<span class="LC_nobreak"><label>'.
2946: '<input type="checkbox" name="'.$prefix.'_'.$type.
2947: '" value="'.$value.'"'.$checkedtype.' />'.$showloc.
2948: '</label></span></td>';
1.137 raeburn 2949: }
1.145 raeburn 2950: $rem = @locations%($numinrow);
2951: my $colsleft = $numinrow - $rem;
2952: if ($colsleft > 1 ) {
2953: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
2954: ' </td>';
2955: } elsif ($colsleft == 1) {
2956: $datatable .= '<td class="LC_left_item"> </td>';
1.137 raeburn 2957: }
1.145 raeburn 2958: $datatable .= '</tr></table>';
1.137 raeburn 2959: }
1.145 raeburn 2960: $datatable .= '</td></tr>';
2961: $itemcount ++;
1.137 raeburn 2962: }
2963: }
2964: }
2965: $$rowtotal += $itemcount;
2966: return $datatable;
2967: }
2968:
1.138 raeburn 2969: sub build_location_hashes {
2970: my ($intdoms,$by_ip,$by_location) = @_;
2971: return unless((ref($intdoms) eq 'ARRAY') && (ref($by_ip) eq 'HASH') &&
2972: (ref($by_location) eq 'HASH'));
2973: my %iphost = &Apache::lonnet::get_iphost();
2974: my $primary_id = &Apache::lonnet::domain($env{'request.role.domain'},'primary');
2975: my $primary_ip = &Apache::lonnet::get_host_ip($primary_id);
2976: if (ref($iphost{$primary_ip}) eq 'ARRAY') {
2977: foreach my $id (@{$iphost{$primary_ip}}) {
2978: my $intdom = &Apache::lonnet::internet_dom($id);
2979: unless(grep(/^\Q$intdom\E$/,@{$intdoms})) {
2980: push(@{$intdoms},$intdom);
2981: }
2982: }
2983: }
2984: foreach my $ip (keys(%iphost)) {
2985: if (ref($iphost{$ip}) eq 'ARRAY') {
2986: foreach my $id (@{$iphost{$ip}}) {
2987: my $location = &Apache::lonnet::internet_dom($id);
2988: if ($location) {
2989: next if (grep(/^\Q$location\E$/,@{$intdoms}));
2990: if (ref($by_ip->{$ip}) eq 'ARRAY') {
2991: unless(grep(/^\Q$location\E$/,@{$by_ip->{$ip}})) {
2992: push(@{$by_ip->{$ip}},$location);
2993: }
2994: } else {
2995: $by_ip->{$ip} = [$location];
2996: }
2997: }
2998: }
2999: }
3000: }
3001: foreach my $ip (sort(keys(%{$by_ip}))) {
3002: if (ref($by_ip->{$ip}) eq 'ARRAY') {
3003: @{$by_ip->{$ip}} = sort(@{$by_ip->{$ip}});
3004: my $first = $by_ip->{$ip}->[0];
3005: if (ref($by_location->{$first}) eq 'ARRAY') {
3006: unless (grep(/^\Q$ip\E$/,@{$by_location->{$first}})) {
3007: push(@{$by_location->{$first}},$ip);
3008: }
3009: } else {
3010: $by_location->{$first} = [$ip];
3011: }
3012: }
3013: }
3014: return;
3015: }
3016:
1.145 raeburn 3017: sub current_offloads_to {
3018: my ($dom,$settings,$servers) = @_;
3019: my (%spareid,%otherdomconfigs);
1.152 raeburn 3020: if (ref($servers) eq 'HASH') {
1.145 raeburn 3021: foreach my $lonhost (sort(keys(%{$servers}))) {
3022: my $gotspares;
1.152 raeburn 3023: if (ref($settings) eq 'HASH') {
3024: if (ref($settings->{'spares'}) eq 'HASH') {
3025: if (ref($settings->{'spares'}{$lonhost}) eq 'HASH') {
3026: $spareid{$lonhost}{'primary'} = $settings->{'spares'}{$lonhost}{'primary'};
3027: $spareid{$lonhost}{'default'} = $settings->{'spares'}{$lonhost}{'default'};
3028: $gotspares = 1;
3029: }
1.145 raeburn 3030: }
3031: }
3032: unless ($gotspares) {
3033: my $gotspares;
3034: my $serverhomeID =
3035: &Apache::lonnet::get_server_homeID($servers->{$lonhost});
3036: my $serverhomedom =
3037: &Apache::lonnet::host_domain($serverhomeID);
3038: if ($serverhomedom ne $dom) {
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: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
3043: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
3044: $gotspares = 1;
3045: }
3046: }
3047: } else {
3048: $otherdomconfigs{$serverhomedom} =
3049: &Apache::lonnet::get_dom('configuration',['usersessions'],$serverhomedom);
3050: if (ref($otherdomconfigs{$serverhomedom}) eq 'HASH') {
3051: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
3052: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
3053: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{$lonhost}) eq 'HASH') {
3054: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
3055: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
3056: $gotspares = 1;
3057: }
3058: }
3059: }
3060: }
3061: }
3062: }
3063: }
3064: unless ($gotspares) {
3065: if ($lonhost eq $Apache::lonnet::perlvar{'lonHostID'}) {
3066: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
3067: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
3068: } else {
3069: my $server_hostname = &Apache::lonnet::hostname($lonhost);
3070: my $server_homeID = &Apache::lonnet::get_server_homeID($server_hostname);
3071: if ($server_homeID eq $Apache::lonnet::perlvar{'lonHostID'}) {
3072: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
3073: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
3074: } else {
1.150 raeburn 3075: my %what = (
3076: spareid => 1,
3077: );
3078: my ($result,$returnhash) =
3079: &Apache::lonnet::get_remote_globals($lonhost,\%what);
3080: if ($result eq 'ok') {
3081: if (ref($returnhash) eq 'HASH') {
3082: if (ref($returnhash->{'spareid'}) eq 'HASH') {
3083: $spareid{$lonhost}{'primary'} = $returnhash->{'spareid'}->{'primary'};
3084: $spareid{$lonhost}{'default'} = $returnhash->{'spareid'}->{'default'};
3085: }
3086: }
1.145 raeburn 3087: }
3088: }
3089: }
3090: }
3091: }
3092: }
3093: return %spareid;
3094: }
3095:
3096: sub spares_row {
1.152 raeburn 3097: my ($dom,$servers,$spareid,$serverhomes,$altids,$rowtotal) = @_;
1.145 raeburn 3098: my $css_class;
3099: my $numinrow = 4;
3100: my $itemcount = 1;
3101: my $datatable;
1.152 raeburn 3102: my %typetitles = &sparestype_titles();
3103: if ((ref($servers) eq 'HASH') && (ref($spareid) eq 'HASH') && (ref($altids) eq 'HASH')) {
1.145 raeburn 3104: foreach my $server (sort(keys(%{$servers}))) {
1.152 raeburn 3105: my $serverhome = &Apache::lonnet::get_server_homeID($servers->{$server});
3106: my ($othercontrol,$serverdom);
3107: if ($serverhome ne $server) {
3108: $serverdom = &Apache::lonnet::host_domain($serverhome);
3109: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
3110: } else {
3111: $serverdom = &Apache::lonnet::host_domain($server);
3112: if ($serverdom ne $dom) {
3113: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
3114: }
3115: }
3116: next unless (ref($spareid->{$server}) eq 'HASH');
1.145 raeburn 3117: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
3118: $datatable .= '<tr'.$css_class.'>
3119: <td rowspan="2">
1.183 bisitz 3120: <span class="LC_nobreak">'.
3121: &mt('[_1] when busy, offloads to:'
3122: ,'<b>'.$server.'</b>').
3123: "\n";
1.145 raeburn 3124: my (%current,%canselect);
1.152 raeburn 3125: my @choices =
3126: &possible_newspares($server,$spareid->{$server},$serverhomes,$altids);
3127: foreach my $type ('primary','default') {
3128: if (ref($spareid->{$server}) eq 'HASH') {
1.145 raeburn 3129: if (ref($spareid->{$server}{$type}) eq 'ARRAY') {
3130: my @spares = @{$spareid->{$server}{$type}};
3131: if (@spares > 0) {
1.152 raeburn 3132: if ($othercontrol) {
3133: $current{$type} = join(', ',@spares);
3134: } else {
3135: $current{$type} .= '<table>';
3136: my $numspares = scalar(@spares);
3137: for (my $i=0; $i<@spares; $i++) {
3138: my $rem = $i%($numinrow);
3139: if ($rem == 0) {
3140: if ($i > 0) {
3141: $current{$type} .= '</tr>';
3142: }
3143: $current{$type} .= '<tr>';
1.145 raeburn 3144: }
1.152 raeburn 3145: $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'".');" /> '.
3146: $spareid->{$server}{$type}[$i].
3147: '</label></td>'."\n";
3148: }
3149: my $rem = @spares%($numinrow);
3150: my $colsleft = $numinrow - $rem;
3151: if ($colsleft > 1 ) {
3152: $current{$type} .= '<td colspan="'.$colsleft.
3153: '" class="LC_left_item">'.
3154: ' </td>';
3155: } elsif ($colsleft == 1) {
3156: $current{$type} .= '<td class="LC_left_item"> </td>'."\n";
1.145 raeburn 3157: }
1.152 raeburn 3158: $current{$type} .= '</tr></table>';
1.150 raeburn 3159: }
1.145 raeburn 3160: }
3161: }
3162: if ($current{$type} eq '') {
3163: $current{$type} = &mt('None specified');
3164: }
1.152 raeburn 3165: if ($othercontrol) {
3166: if ($type eq 'primary') {
3167: $canselect{$type} = $othercontrol;
3168: }
3169: } else {
3170: $canselect{$type} =
3171: &mt('Add new [_1]'.$type.'[_2]:','<i>','</i>').' '.
3172: '<select name="newspare_'.$type.'_'.$server.'" '.
3173: 'id="newspare_'.$type.'_'.$server.'" onchange="checkNewSpares('."'$server','$type'".');">'."\n".
3174: '<option value="" selected ="selected">'.&mt('Select').'</option>'."\n";
3175: if (@choices > 0) {
3176: foreach my $lonhost (@choices) {
3177: $canselect{$type} .= '<option value="'.$lonhost.'">'.$lonhost.'</option>'."\n";
3178: }
3179: }
3180: $canselect{$type} .= '</select>'."\n";
3181: }
3182: } else {
3183: $current{$type} = &mt('Could not be determined');
3184: if ($type eq 'primary') {
3185: $canselect{$type} = $othercontrol;
3186: }
1.145 raeburn 3187: }
1.152 raeburn 3188: if ($type eq 'default') {
3189: $datatable .= '<tr'.$css_class.'>';
3190: }
3191: $datatable .= '<td><i>'.$typetitles{$type}.'</i></td>'."\n".
3192: '<td>'.$current{$type}.'</td>'."\n".
3193: '<td>'.$canselect{$type}.'</td></tr>'."\n";
1.145 raeburn 3194: }
3195: $itemcount ++;
3196: }
3197: }
3198: $$rowtotal += $itemcount;
3199: return $datatable;
3200: }
3201:
1.152 raeburn 3202: sub possible_newspares {
3203: my ($server,$currspares,$serverhomes,$altids) = @_;
3204: my $serverhostname = &Apache::lonnet::hostname($server);
3205: my %excluded;
3206: if ($serverhostname ne '') {
3207: %excluded = (
3208: $serverhostname => 1,
3209: );
3210: }
3211: if (ref($currspares) eq 'HASH') {
3212: foreach my $type (keys(%{$currspares})) {
3213: if (ref($currspares->{$type}) eq 'ARRAY') {
3214: if (@{$currspares->{$type}} > 0) {
3215: foreach my $curr (@{$currspares->{$type}}) {
3216: my $hostname = &Apache::lonnet::hostname($curr);
3217: $excluded{$hostname} = 1;
3218: }
3219: }
3220: }
3221: }
3222: }
3223: my @choices;
3224: if ((ref($serverhomes) eq 'HASH') && (ref($altids) eq 'HASH')) {
3225: if (keys(%{$serverhomes}) > 1) {
3226: foreach my $name (sort(keys(%{$serverhomes}))) {
3227: unless ($excluded{$name}) {
3228: if (exists($altids->{$serverhomes->{$name}})) {
3229: push(@choices,$altids->{$serverhomes->{$name}});
3230: } else {
3231: push(@choices,$serverhomes->{$name});
1.145 raeburn 3232: }
3233: }
3234: }
3235: }
3236: }
1.152 raeburn 3237: return sort(@choices);
1.145 raeburn 3238: }
3239:
1.150 raeburn 3240: sub print_loadbalancing {
3241: my ($dom,$settings,$rowtotal) = @_;
3242: my $primary_id = &Apache::lonnet::domain($dom,'primary');
3243: my $intdom = &Apache::lonnet::internet_dom($primary_id);
3244: my $numinrow = 1;
3245: my $datatable;
3246: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.171 raeburn 3247: my (%currbalancer,%currtargets,%currrules,%existing);
3248: if (ref($settings) eq 'HASH') {
3249: %existing = %{$settings};
3250: }
3251: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
3252: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
3253: \%currtargets,\%currrules);
1.150 raeburn 3254: } else {
3255: return;
3256: }
3257: my ($othertitle,$usertypes,$types) =
3258: &Apache::loncommon::sorted_inst_types($dom);
1.209 raeburn 3259: my $rownum = 8;
1.150 raeburn 3260: if (ref($types) eq 'ARRAY') {
3261: $rownum += scalar(@{$types});
3262: }
1.171 raeburn 3263: my @css_class = ('LC_odd_row','LC_even_row');
3264: my $balnum = 0;
3265: my $islast;
3266: my (@toshow,$disabledtext);
3267: if (keys(%currbalancer) > 0) {
3268: @toshow = sort(keys(%currbalancer));
3269: if (scalar(@toshow) < scalar(keys(%servers)) + 1) {
3270: push(@toshow,'');
3271: }
3272: } else {
3273: @toshow = ('');
3274: $disabledtext = &mt('No existing load balancer');
3275: }
3276: foreach my $lonhost (@toshow) {
3277: if ($balnum == scalar(@toshow)-1) {
3278: $islast = 1;
3279: } else {
3280: $islast = 0;
3281: }
3282: my $cssidx = $balnum%2;
3283: my $targets_div_style = 'display: none';
3284: my $disabled_div_style = 'display: block';
3285: my $homedom_div_style = 'display: none';
3286: $datatable .= '<tr class="'.$css_class[$cssidx].'">'.
3287: '<td rowspan="'.$rownum.'" valign="top">'.
3288: '<p>';
3289: if ($lonhost eq '') {
1.210 raeburn 3290: $datatable .= '<span class="LC_nobreak">';
1.171 raeburn 3291: if (keys(%currbalancer) > 0) {
3292: $datatable .= &mt('Add balancer:');
3293: } else {
3294: $datatable .= &mt('Enable balancer:');
3295: }
3296: $datatable .= ' '.
3297: '<select name="loadbalancing_lonhost_'.$balnum.'"'.
3298: ' id="loadbalancing_lonhost_'.$balnum.'"'.
3299: ' onchange="toggleTargets('."'$balnum'".');">'."\n".
3300: '<option value="" selected="selected">'.&mt('None').
3301: '</option>'."\n";
3302: foreach my $server (sort(keys(%servers))) {
3303: next if ($currbalancer{$server});
3304: $datatable .= '<option value="'.$server.'">'.$server.'</option>'."\n";
3305: }
1.210 raeburn 3306: $datatable .=
1.171 raeburn 3307: '</select>'."\n".
3308: '<input type="hidden" name="loadbalancing_prevlonhost_'.$balnum.'" id="loadbalancing_prevlonhost_'.$balnum.'" value="" /> </span>'."\n";
3309: } else {
3310: $datatable .= '<i>'.$lonhost.'</i><br /><span class="LC_nobreak">'.
3311: '<label><input type="checkbox" name="loadbalancing_delete" value="'.$balnum.'" id="loadbalancing_delete_'.$balnum.'" onclick="javascript:balancerDeleteChange('."'$balnum'".');" /> '.
3312: &mt('Stop balancing').'</label>'.
3313: '<input type="hidden" name="loadbalancing_lonhost_'.$balnum.'" value="'.$lonhost.'" id="loadbalancing_lonhost_'.$balnum.'" /></span>';
3314: $targets_div_style = 'display: block';
3315: $disabled_div_style = 'display: none';
3316: if ($dom eq &Apache::lonnet::host_domain($lonhost)) {
3317: $homedom_div_style = 'display: block';
3318: }
3319: }
3320: $datatable .= '</p></td><td rowspan="'.$rownum.'" valign="top">'.
3321: '<div id="loadbalancing_disabled_'.$balnum.'" style="'.
3322: $disabled_div_style.'">'.$disabledtext.'</div>'."\n".
3323: '<div id="loadbalancing_targets_'.$balnum.'" style="'.$targets_div_style.'">'.&mt('Offloads to:').'<br />';
3324: my ($numspares,@spares) = &count_servers($lonhost,%servers);
3325: my @sparestypes = ('primary','default');
3326: my %typetitles = &sparestype_titles();
3327: foreach my $sparetype (@sparestypes) {
3328: my $targettable;
3329: for (my $i=0; $i<$numspares; $i++) {
3330: my $checked;
3331: if (ref($currtargets{$lonhost}) eq 'HASH') {
3332: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
3333: if (grep(/^\Q$spares[$i]\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
3334: $checked = ' checked="checked"';
3335: }
3336: }
3337: }
3338: my ($chkboxval,$disabled);
3339: if (($lonhost ne '') && (exists($servers{$lonhost}))) {
3340: $chkboxval = $spares[$i];
3341: }
3342: if (exists($currbalancer{$spares[$i]})) {
3343: $disabled = ' disabled="disabled"';
3344: }
1.210 raeburn 3345: $targettable .=
1.171 raeburn 3346: '<td><label><input type="checkbox" name="loadbalancing_target_'.$balnum.'_'.$sparetype.'"'.
3347: $checked.$disabled.' value="'.$chkboxval.'" id="loadbalancing_target_'.$balnum.'_'.$sparetype.'_'.$i.'" onclick="checkOffloads('."this,'$balnum','$sparetype'".');" /><span id="loadbalancing_targettxt_'.$balnum.'_'.$sparetype.'_'.$i.'"> '.$chkboxval.
3348: '</span></label></td>';
3349: my $rem = $i%($numinrow);
3350: if ($rem == 0) {
3351: if (($i > 0) && ($i < $numspares-1)) {
3352: $targettable .= '</tr>';
3353: }
3354: if ($i < $numspares-1) {
3355: $targettable .= '<tr>';
1.150 raeburn 3356: }
3357: }
3358: }
1.171 raeburn 3359: if ($targettable ne '') {
3360: my $rem = $numspares%($numinrow);
3361: my $colsleft = $numinrow - $rem;
3362: if ($colsleft > 1 ) {
3363: $targettable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
3364: ' </td>';
3365: } elsif ($colsleft == 1) {
3366: $targettable .= '<td class="LC_left_item"> </td>';
3367: }
3368: $datatable .= '<i>'.$typetitles{$sparetype}.'</i><br />'.
3369: '<table><tr>'.$targettable.'</tr></table><br />';
3370: }
3371: }
3372: $datatable .= '</div></td></tr>'.
3373: &loadbalancing_rules($dom,$intdom,$currrules{$lonhost},
3374: $othertitle,$usertypes,$types,\%servers,
3375: \%currbalancer,$lonhost,
3376: $targets_div_style,$homedom_div_style,
3377: $css_class[$cssidx],$balnum,$islast);
3378: $$rowtotal += $rownum;
3379: $balnum ++;
3380: }
3381: $datatable .= '<input type="hidden" name="loadbalancing_total" id="loadbalancing_total" value="'.$balnum.'" />';
3382: return $datatable;
3383: }
3384:
3385: sub get_loadbalancers_config {
3386: my ($servers,$existing,$currbalancer,$currtargets,$currrules) = @_;
3387: return unless ((ref($servers) eq 'HASH') &&
3388: (ref($existing) eq 'HASH') && (ref($currbalancer) eq 'HASH') &&
3389: (ref($currtargets) eq 'HASH') && (ref($currrules) eq 'HASH'));
3390: if (keys(%{$existing}) > 0) {
3391: my $oldlonhost;
3392: foreach my $key (sort(keys(%{$existing}))) {
3393: if ($key eq 'lonhost') {
3394: $oldlonhost = $existing->{'lonhost'};
3395: $currbalancer->{$oldlonhost} = 1;
3396: } elsif ($key eq 'targets') {
3397: if ($oldlonhost) {
3398: $currtargets->{$oldlonhost} = $existing->{'targets'};
3399: }
3400: } elsif ($key eq 'rules') {
3401: if ($oldlonhost) {
3402: $currrules->{$oldlonhost} = $existing->{'rules'};
3403: }
3404: } elsif (ref($existing->{$key}) eq 'HASH') {
3405: $currbalancer->{$key} = 1;
3406: $currtargets->{$key} = $existing->{$key}{'targets'};
3407: $currrules->{$key} = $existing->{$key}{'rules'};
1.150 raeburn 3408: }
3409: }
1.171 raeburn 3410: } else {
3411: my ($balancerref,$targetsref) =
3412: &Apache::lonnet::get_lonbalancer_config($servers);
3413: if ((ref($balancerref) eq 'HASH') && (ref($targetsref) eq 'HASH')) {
3414: foreach my $server (sort(keys(%{$balancerref}))) {
3415: $currbalancer->{$server} = 1;
3416: $currtargets->{$server} = $targetsref->{$server};
1.150 raeburn 3417: }
3418: }
3419: }
1.171 raeburn 3420: return;
1.150 raeburn 3421: }
3422:
3423: sub loadbalancing_rules {
3424: my ($dom,$intdom,$currrules,$othertitle,$usertypes,$types,$servers,
1.171 raeburn 3425: $currbalancer,$lonhost,$targets_div_style,$homedom_div_style,
3426: $css_class,$balnum,$islast) = @_;
1.150 raeburn 3427: my $output;
1.171 raeburn 3428: my $num = 0;
1.210 raeburn 3429: my ($alltypes,$othertypes,$titles) =
1.150 raeburn 3430: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
3431: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
3432: foreach my $type (@{$alltypes}) {
1.171 raeburn 3433: $num ++;
1.150 raeburn 3434: my $current;
3435: if (ref($currrules) eq 'HASH') {
3436: $current = $currrules->{$type};
3437: }
1.209 raeburn 3438: if (($type eq '_LC_external') || ($type eq '_LC_internetdom') || ($type eq '_LC_ipchange')) {
1.171 raeburn 3439: if ($dom ne &Apache::lonnet::host_domain($lonhost)) {
1.150 raeburn 3440: $current = '';
3441: }
3442: }
3443: $output .= &loadbalance_rule_row($type,$titles->{$type},$current,
1.171 raeburn 3444: $servers,$currbalancer,$lonhost,$dom,
3445: $targets_div_style,$homedom_div_style,
3446: $css_class,$balnum,$num,$islast);
1.150 raeburn 3447: }
3448: }
3449: return $output;
3450: }
3451:
3452: sub loadbalancing_titles {
3453: my ($dom,$intdom,$usertypes,$types) = @_;
3454: my %othertypes = (
3455: '_LC_adv' => &mt('Advanced users from [_1]',$dom),
3456: '_LC_author' => &mt('Users from [_1] with author role',$dom),
3457: '_LC_internetdom' => &mt('Users not from [_1], but from [_2]',$dom,$intdom),
3458: '_LC_external' => &mt('Users not from [_1]',$intdom),
1.209 raeburn 3459: '_LC_ipchangesso' => &mt('SSO users from [_1], with IP mismatch',$dom),
3460: '_LC_ipchange' => &mt('Non-SSO users with IP mismatch'),
1.150 raeburn 3461: );
1.209 raeburn 3462: my @alltypes = ('_LC_adv','_LC_author','_LC_internetdom','_LC_external','_LC_ipchangesso','_LC_ipchange');
1.150 raeburn 3463: if (ref($types) eq 'ARRAY') {
3464: unshift(@alltypes,@{$types},'default');
3465: }
3466: my %titles;
3467: foreach my $type (@alltypes) {
3468: if ($type =~ /^_LC_/) {
3469: $titles{$type} = $othertypes{$type};
3470: } elsif ($type eq 'default') {
3471: $titles{$type} = &mt('All users from [_1]',$dom);
3472: if (ref($types) eq 'ARRAY') {
3473: if (@{$types} > 0) {
3474: $titles{$type} = &mt('Other users from [_1]',$dom);
3475: }
3476: }
3477: } elsif (ref($usertypes) eq 'HASH') {
3478: $titles{$type} = $usertypes->{$type};
3479: }
3480: }
3481: return (\@alltypes,\%othertypes,\%titles);
3482: }
3483:
3484: sub loadbalance_rule_row {
1.171 raeburn 3485: my ($type,$title,$current,$servers,$currbalancer,$lonhost,$dom,
3486: $targets_div_style,$homedom_div_style,$css_class,$balnum,$num,$islast) = @_;
1.209 raeburn 3487: my @rulenames;
1.150 raeburn 3488: my %ruletitles = &offloadtype_text();
1.209 raeburn 3489: if (($type eq '_LC_ipchangesso') || ($type eq '_LC_ipchange')) {
3490: @rulenames = ('balancer','offloadedto');
1.150 raeburn 3491: } else {
1.209 raeburn 3492: @rulenames = ('default','homeserver');
3493: if ($type eq '_LC_external') {
3494: push(@rulenames,'externalbalancer');
3495: } else {
3496: push(@rulenames,'specific');
3497: }
3498: push(@rulenames,'none');
1.150 raeburn 3499: }
3500: my $style = $targets_div_style;
1.209 raeburn 3501: if (($type eq '_LC_external') || ($type eq '_LC_internetdom') || ($type eq '_LC_ipchange')) {
1.150 raeburn 3502: $style = $homedom_div_style;
3503: }
1.171 raeburn 3504: my $space;
3505: if ($islast && $num == 1) {
3506: $space = '<div display="inline-block"> </div>';
3507: }
1.210 raeburn 3508: my $output =
1.171 raeburn 3509: '<tr class="'.$css_class.'" id="balanceruletr_'.$balnum.'_'.$num.'"><td valign="top">'.$space.
3510: '<div id="balanceruletitle_'.$balnum.'_'.$type.'" style="'.$style.'">'.$title.'</div></td>'."\n".
3511: '<td valaign="top">'.$space.
3512: '<div id="balancerule_'.$balnum.'_'.$type.'" style="'.$style.'">'."\n";
1.150 raeburn 3513: for (my $i=0; $i<@rulenames; $i++) {
3514: my $rule = $rulenames[$i];
3515: my ($checked,$extra);
3516: if ($rulenames[$i] eq 'default') {
3517: $rule = '';
3518: }
3519: if ($rulenames[$i] eq 'specific') {
3520: if (ref($servers) eq 'HASH') {
3521: my $default;
3522: if (($current ne '') && (exists($servers->{$current}))) {
3523: $checked = ' checked="checked"';
3524: }
3525: unless ($checked) {
3526: $default = ' selected="selected"';
3527: }
1.210 raeburn 3528: $extra =
1.171 raeburn 3529: ': <select name="loadbalancing_singleserver_'.$balnum.'_'.$type.
3530: '" id="loadbalancing_singleserver_'.$balnum.'_'.$type.
3531: '" onchange="singleServerToggle('."'$balnum','$type'".')">'."\n".
3532: '<option value=""'.$default.'></option>'."\n";
3533: foreach my $server (sort(keys(%{$servers}))) {
3534: if (ref($currbalancer) eq 'HASH') {
3535: next if (exists($currbalancer->{$server}));
3536: }
1.150 raeburn 3537: my $selected;
1.171 raeburn 3538: if ($server eq $current) {
1.150 raeburn 3539: $selected = ' selected="selected"';
3540: }
1.171 raeburn 3541: $extra .= '<option value="'.$server.'"'.$selected.'>'.$server.'</option>';
1.150 raeburn 3542: }
3543: $extra .= '</select>';
3544: }
3545: } elsif ($rule eq $current) {
3546: $checked = ' checked="checked"';
3547: }
3548: $output .= '<span class="LC_nobreak"><label>'.
1.171 raeburn 3549: '<input type="radio" name="loadbalancing_rules_'.$balnum.'_'.$type.
3550: '" id="loadbalancing_rules_'.$balnum.'_'.$type.'_'.$i.'" value="'.
3551: $rule.'" onclick="balanceruleChange('."this.form,'$balnum','$type'".
1.150 raeburn 3552: ')"'.$checked.' /> '.$ruletitles{$rulenames[$i]}.
3553: '</label>'.$extra.'</span><br />'."\n";
3554: }
3555: $output .= '</div></td></tr>'."\n";
3556: return $output;
3557: }
3558:
3559: sub offloadtype_text {
3560: my %ruletitles = &Apache::lonlocal::texthash (
3561: 'default' => 'Offloads to default destinations',
3562: 'homeserver' => "Offloads to user's home server",
3563: 'externalbalancer' => "Offloads to Load Balancer in user's domain",
3564: 'specific' => 'Offloads to specific server',
1.161 raeburn 3565: 'none' => 'No offload',
1.209 raeburn 3566: 'balancer' => 'Session hosted on Load Balancer, after re-authentication',
3567: 'offloadedto' => 'Session hosted on offload server, after re-authentication',
1.150 raeburn 3568: );
3569: return %ruletitles;
3570: }
3571:
3572: sub sparestype_titles {
3573: my %typestitles = &Apache::lonlocal::texthash (
3574: 'primary' => 'primary',
3575: 'default' => 'default',
3576: );
3577: return %typestitles;
3578: }
3579:
1.28 raeburn 3580: sub contact_titles {
3581: my %titles = &Apache::lonlocal::texthash (
3582: 'supportemail' => 'Support E-mail address',
1.69 raeburn 3583: 'adminemail' => 'Default Server Admin E-mail address',
1.28 raeburn 3584: 'errormail' => 'Error reports to be e-mailed to',
3585: 'packagesmail' => 'Package update alerts to be e-mailed to',
1.89 raeburn 3586: 'helpdeskmail' => 'Helpdesk requests to be e-mailed to',
3587: 'lonstatusmail' => 'E-mail from nightly status check (warnings/errors)',
1.102 raeburn 3588: 'requestsmail' => 'E-mail from course requests requiring approval',
1.190 raeburn 3589: 'updatesmail' => 'E-mail from nightly check of LON-CAPA module integrity/updates',
1.203 raeburn 3590: 'idconflictsmail' => 'E-mail from bi-nightly check for multiple users sharing same student/employee ID',
1.28 raeburn 3591: );
3592: my %short_titles = &Apache::lonlocal::texthash (
3593: adminemail => 'Admin E-mail address',
3594: supportemail => 'Support E-mail',
3595: );
3596: return (\%titles,\%short_titles);
3597: }
3598:
1.72 raeburn 3599: sub tool_titles {
3600: my %titles = &Apache::lonlocal::texthash (
1.162 raeburn 3601: aboutme => 'Personal web page',
1.86 raeburn 3602: blog => 'Blog',
1.162 raeburn 3603: webdav => 'WebDAV',
1.86 raeburn 3604: portfolio => 'Portfolio',
1.88 bisitz 3605: official => 'Official courses (with institutional codes)',
3606: unofficial => 'Unofficial courses',
1.98 raeburn 3607: community => 'Communities',
1.216 raeburn 3608: textbook => 'Textbook courses',
1.86 raeburn 3609: );
1.72 raeburn 3610: return %titles;
3611: }
3612:
1.101 raeburn 3613: sub courserequest_titles {
3614: my %titles = &Apache::lonlocal::texthash (
3615: official => 'Official',
3616: unofficial => 'Unofficial',
3617: community => 'Communities',
1.216 raeburn 3618: textbook => 'Textbook',
1.101 raeburn 3619: norequest => 'Not allowed',
1.104 raeburn 3620: approval => 'Approval by Dom. Coord.',
1.101 raeburn 3621: validate => 'With validation',
3622: autolimit => 'Numerical limit',
1.103 raeburn 3623: unlimited => '(blank for unlimited)',
1.101 raeburn 3624: );
3625: return %titles;
3626: }
3627:
1.163 raeburn 3628: sub authorrequest_titles {
3629: my %titles = &Apache::lonlocal::texthash (
3630: norequest => 'Not allowed',
3631: approval => 'Approval by Dom. Coord.',
3632: automatic => 'Automatic approval',
3633: );
3634: return %titles;
1.210 raeburn 3635: }
1.163 raeburn 3636:
1.101 raeburn 3637: sub courserequest_conditions {
3638: my %conditions = &Apache::lonlocal::texthash (
1.104 raeburn 3639: approval => '(Processing of request subject to approval by Domain Coordinator).',
1.193 bisitz 3640: validate => '(Processing of request subject to institutional validation).',
1.101 raeburn 3641: );
3642: return %conditions;
3643: }
3644:
3645:
1.27 raeburn 3646: sub print_usercreation {
1.30 raeburn 3647: my ($position,$dom,$settings,$rowtotal) = @_;
1.27 raeburn 3648: my $numinrow = 4;
1.28 raeburn 3649: my $datatable;
3650: if ($position eq 'top') {
1.30 raeburn 3651: $$rowtotal ++;
1.34 raeburn 3652: my $rowcount = 0;
1.32 raeburn 3653: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username');
1.28 raeburn 3654: if (ref($rules) eq 'HASH') {
3655: if (keys(%{$rules}) > 0) {
1.32 raeburn 3656: $datatable .= &user_formats_row('username',$settings,$rules,
3657: $ruleorder,$numinrow,$rowcount);
1.30 raeburn 3658: $$rowtotal ++;
1.32 raeburn 3659: $rowcount ++;
3660: }
3661: }
3662: my ($idrules,$idruleorder) = &Apache::lonnet::inst_userrules($dom,'id');
3663: if (ref($idrules) eq 'HASH') {
3664: if (keys(%{$idrules}) > 0) {
3665: $datatable .= &user_formats_row('id',$settings,$idrules,
3666: $idruleorder,$numinrow,$rowcount);
3667: $$rowtotal ++;
3668: $rowcount ++;
1.28 raeburn 3669: }
3670: }
1.39 raeburn 3671: if ($rowcount == 0) {
3672: $datatable .= '<tr><td colspan="2">'.&mt('No format rules have been defined for usernames or IDs in this domain.').'</td></tr>';
3673: $$rowtotal ++;
3674: $rowcount ++;
3675: }
1.34 raeburn 3676: } elsif ($position eq 'middle') {
1.224 raeburn 3677: my @creators = ('author','course','requestcrs');
1.37 raeburn 3678: my ($rules,$ruleorder) =
3679: &Apache::lonnet::inst_userrules($dom,'username');
1.34 raeburn 3680: my %lt = &usercreation_types();
3681: my %checked;
3682: if (ref($settings) eq 'HASH') {
3683: if (ref($settings->{'cancreate'}) eq 'HASH') {
3684: foreach my $item (@creators) {
3685: $checked{$item} = $settings->{'cancreate'}{$item};
3686: }
3687: } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {
3688: foreach my $item (@creators) {
3689: if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {
3690: $checked{$item} = 'none';
3691: }
3692: }
3693: }
3694: }
3695: my $rownum = 0;
3696: foreach my $item (@creators) {
3697: $rownum ++;
1.224 raeburn 3698: if ($checked{$item} eq '') {
3699: $checked{$item} = 'any';
1.34 raeburn 3700: }
3701: my $css_class;
3702: if ($rownum%2) {
3703: $css_class = '';
3704: } else {
3705: $css_class = ' class="LC_odd_row" ';
3706: }
3707: $datatable .= '<tr'.$css_class.'>'.
3708: '<td><span class="LC_nobreak">'.$lt{$item}.
3709: '</span></td><td align="right">';
1.224 raeburn 3710: my @options = ('any');
3711: if (ref($rules) eq 'HASH') {
3712: if (keys(%{$rules}) > 0) {
3713: push(@options,('official','unofficial'));
1.37 raeburn 3714: }
3715: }
1.224 raeburn 3716: push(@options,'none');
1.37 raeburn 3717: foreach my $option (@options) {
1.50 raeburn 3718: my $type = 'radio';
1.34 raeburn 3719: my $check = ' ';
1.224 raeburn 3720: if ($checked{$item} eq $option) {
3721: $check = ' checked="checked" ';
1.34 raeburn 3722: }
3723: $datatable .= '<span class="LC_nobreak"><label>'.
1.50 raeburn 3724: '<input type="'.$type.'" name="can_createuser_'.
1.34 raeburn 3725: $item.'" value="'.$option.'"'.$check.'/> '.
3726: $lt{$option}.'</label> </span>';
3727: }
3728: $datatable .= '</td></tr>';
3729: }
1.28 raeburn 3730: } else {
3731: my @contexts = ('author','course','domain');
3732: my @authtypes = ('int','krb4','krb5','loc');
3733: my %checked;
3734: if (ref($settings) eq 'HASH') {
3735: if (ref($settings->{'authtypes'}) eq 'HASH') {
3736: foreach my $item (@contexts) {
3737: if (ref($settings->{'authtypes'}{$item}) eq 'HASH') {
3738: foreach my $auth (@authtypes) {
3739: if ($settings->{'authtypes'}{$item}{$auth}) {
3740: $checked{$item}{$auth} = ' checked="checked" ';
3741: }
3742: }
3743: }
3744: }
1.27 raeburn 3745: }
1.35 raeburn 3746: } else {
3747: foreach my $item (@contexts) {
1.36 raeburn 3748: foreach my $auth (@authtypes) {
1.35 raeburn 3749: $checked{$item}{$auth} = ' checked="checked" ';
3750: }
3751: }
1.27 raeburn 3752: }
1.28 raeburn 3753: my %title = &context_names();
3754: my %authname = &authtype_names();
3755: my $rownum = 0;
3756: my $css_class;
3757: foreach my $item (@contexts) {
3758: if ($rownum%2) {
3759: $css_class = '';
3760: } else {
3761: $css_class = ' class="LC_odd_row" ';
3762: }
1.30 raeburn 3763: $datatable .= '<tr'.$css_class.'>'.
1.28 raeburn 3764: '<td>'.$title{$item}.
3765: '</td><td class="LC_left_item">'.
3766: '<span class="LC_nobreak">';
3767: foreach my $auth (@authtypes) {
3768: $datatable .= '<label>'.
3769: '<input type="checkbox" name="'.$item.'_auth" '.
3770: $checked{$item}{$auth}.' value="'.$auth.'" />'.
3771: $authname{$auth}.'</label> ';
3772: }
3773: $datatable .= '</span></td></tr>';
3774: $rownum ++;
1.27 raeburn 3775: }
1.30 raeburn 3776: $$rowtotal += $rownum;
1.27 raeburn 3777: }
3778: return $datatable;
3779: }
3780:
1.224 raeburn 3781: sub print_selfcreation {
3782: my ($position,$dom,$settings,$rowtotal) = @_;
3783: my (@selfcreate,$createsettings,$datatable);
3784: if (ref($settings) eq 'HASH') {
3785: if (ref($settings->{'cancreate'}) eq 'HASH') {
3786: $createsettings = $settings->{'cancreate'};
3787: if (ref($settings->{'cancreate'}{'selfcreate'}) eq 'ARRAY') {
3788: @selfcreate = @{$settings->{'cancreate'}{'selfcreate'}};
3789: } elsif ($settings->{'cancreate'}{'selfcreate'} ne '') {
3790: if ($settings->{'cancreate'}{'selfcreate'} eq 'any') {
3791: @selfcreate = ('email','login','sso');
3792: } elsif ($settings->{'cancreate'}{'selfcreate'} ne 'none') {
3793: @selfcreate = ($settings->{'cancreate'}{'selfcreate'});
3794: }
3795: }
3796: }
3797: }
3798: my %radiohash;
3799: my $numinrow = 4;
3800: map { $radiohash{'cancreate_'.$_} = 1; } @selfcreate;
3801: if ($position eq 'top') {
3802: my %choices = &Apache::lonlocal::texthash (
3803: cancreate_login => 'Institutional Login',
3804: cancreate_sso => 'Institutional Single Sign On',
3805: );
3806: my @toggles = sort(keys(%choices));
3807: my %defaultchecked = (
3808: 'cancreate_login' => 'off',
3809: 'cancreate_sso' => 'off',
3810: );
1.228 ! raeburn 3811: my ($onclick,$itemcount);
1.224 raeburn 3812: ($datatable,$itemcount) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
3813: \%choices,$itemcount,$onclick);
1.228 ! raeburn 3814: $$rowtotal += $itemcount;
! 3815:
1.224 raeburn 3816: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
3817:
3818: if (ref($usertypes) eq 'HASH') {
3819: if (keys(%{$usertypes}) > 0) {
3820: $datatable .= &insttypes_row($createsettings,$types,$usertypes,
3821: $dom,$numinrow,$othertitle,
1.228 ! raeburn 3822: 'statustocreate',$$rowtotal);
1.224 raeburn 3823: $$rowtotal ++;
3824: }
3825: }
3826: } elsif ($position eq 'middle') {
3827: my %domconf = &Apache::lonnet::get_dom('configuration',['usermodification'],$dom);
3828: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
3829: $usertypes->{'default'} = $othertitle;
3830: if (ref($types) eq 'ARRAY') {
3831: push(@{$types},'default');
3832: $usertypes->{'default'} = $othertitle;
3833: foreach my $status (@{$types}) {
3834: $datatable .= &modifiable_userdata_row('selfcreate',$status,$domconf{'usermodification'},
1.228 ! raeburn 3835: $numinrow,$$rowtotal,$usertypes);
1.224 raeburn 3836: $$rowtotal ++;
3837: }
3838: }
3839: } else {
1.228 ! raeburn 3840: my $css_class = $$rowtotal%2?' class="LC_odd_row"':'';
1.224 raeburn 3841: my %choices =
3842: &Apache::lonlocal::texthash(
3843: email => 'Approved automatically',
3844: emailapproval => 'Queued for approval by DC',
3845: off => 'Not enabled',
3846: );
3847: $datatable .= '<tr'.$css_class.'>'.
3848: '<td>'.&mt('E-mail address as username').
3849: '</td><td class="LC_left_item">'.
3850: '<span class="LC_nobreak">';
3851: foreach my $option ('email','emailapproval','off') {
3852: my $checked;
3853: if ($option eq 'email') {
3854: if ($radiohash{'cancreate_email'}) {
3855: $checked = 'checked="checked"';
3856: }
3857: } elsif ($option eq 'emailapproval') {
3858: if ($radiohash{'cancreate_emailapproval'}) {
3859: $checked = 'checked="checked"';
3860: }
3861: } else {
3862: if ((!$radiohash{'cancreate_email'}) && (!$radiohash{'cancreate_emailapproval'})) {
3863: $checked = 'checked="checked"';
3864: }
3865: }
3866: $datatable .= '<label>'.
3867: '<input type="radio" name="cancreate_email" '.
3868: $checked.' value="'.$option.'" />'.
3869: $choices{$option}.'</label> ';
3870: }
3871: $$rowtotal ++;
3872: $datatable .= '</span></td></tr>'.
3873: &print_requestmail($dom,'selfcreation',$createsettings,$rowtotal);
1.228 ! raeburn 3874: $$rowtotal ++;
1.224 raeburn 3875: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
1.228 ! raeburn 3876: $numinrow = 1;
! 3877: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
! 3878: $usertypes->{'default'} = $othertitle;
! 3879: if (ref($types) eq 'ARRAY') {
! 3880: push(@{$types},'default');
! 3881: $usertypes->{'default'} = $othertitle;
! 3882: foreach my $status (@{$types}) {
! 3883: $datatable .= &modifiable_userdata_row('cancreate','emailusername_'.$status,$settings,
! 3884: $numinrow,$$rowtotal,$usertypes,$infofields,$infotitles);
! 3885: $$rowtotal ++;
! 3886: }
! 3887: }
1.224 raeburn 3888: my ($emailrules,$emailruleorder) =
3889: &Apache::lonnet::inst_userrules($dom,'email');
3890: if (ref($emailrules) eq 'HASH') {
3891: if (keys(%{$emailrules}) > 0) {
3892: $datatable .= &user_formats_row('email',$settings,$emailrules,
1.228 ! raeburn 3893: $emailruleorder,$numinrow,$$rowtotal);
1.224 raeburn 3894: $$rowtotal ++;
3895: }
3896: }
1.228 ! raeburn 3897: $datatable .= &captcha_choice('cancreate',$createsettings,$$rowtotal);
1.224 raeburn 3898: }
3899: return $datatable;
3900: }
3901:
1.165 raeburn 3902: sub captcha_choice {
1.169 raeburn 3903: my ($context,$settings,$itemcount) = @_;
1.165 raeburn 3904: my ($keyentry,$currpub,$currpriv,%checked,$rowname,$pubtext,$privtext);
3905: my %lt = &captcha_phrases();
3906: $keyentry = 'hidden';
3907: if ($context eq 'cancreate') {
1.224 raeburn 3908: $rowname = &mt('CAPTCHA validation');
1.169 raeburn 3909: } elsif ($context eq 'login') {
3910: $rowname = &mt('"Contact helpdesk" CAPTCHA validation');
1.165 raeburn 3911: }
3912: if (ref($settings) eq 'HASH') {
3913: if ($settings->{'captcha'}) {
3914: $checked{$settings->{'captcha'}} = ' checked="checked"';
3915: } else {
3916: $checked{'original'} = ' checked="checked"';
3917: }
3918: if ($settings->{'captcha'} eq 'recaptcha') {
3919: $pubtext = $lt{'pub'};
3920: $privtext = $lt{'priv'};
3921: $keyentry = 'text';
3922: }
3923: if (ref($settings->{'recaptchakeys'}) eq 'HASH') {
3924: $currpub = $settings->{'recaptchakeys'}{'public'};
3925: $currpriv = $settings->{'recaptchakeys'}{'private'};
3926: }
3927: } else {
3928: $checked{'original'} = ' checked="checked"';
3929: }
1.169 raeburn 3930: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
3931: my $output = '<tr'.$css_class.'>'.
3932: '<td class="LC_left_item">'.$rowname.'</td><td class="LC_left_item" colspan="2">'."\n".
1.165 raeburn 3933: '<table><tr><td>'."\n";
3934: foreach my $option ('original','recaptcha','notused') {
3935: $output .= '<span class="LC_nobreak"><label><input type="radio" name="'.$context.'_captcha" value="'.
3936: $option.'" '.$checked{$option}.' onchange="javascript:updateCaptcha('."this,'$context'".');" />'.
3937: $lt{$option}.'</label></span>';
3938: unless ($option eq 'notused') {
3939: $output .= (' 'x2)."\n";
3940: }
3941: }
3942: #
3943: # Note: If reCAPTCHA is to be used for LON-CAPA servers in a domain, a domain coordinator should visit:
3944: # https://www.google.com/recaptcha and generate a Public and Private key. For domains with multiple
1.210 raeburn 3945: # servers a single key pair will be used for all servers, so the internet domain (e.g., yourcollege.edu)
1.165 raeburn 3946: # specified for use with the key should be broad enough to accommodate all servers in the LON-CAPA domain.
1.210 raeburn 3947: #
1.165 raeburn 3948: $output .= '</td></tr>'."\n".
3949: '<tr><td>'."\n".
3950: '<span class="LC_nobreak"><span id="'.$context.'_recaptchapubtxt">'.$pubtext.'</span> '."\n".
3951: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapub" name="'.$context.'_recaptchapub" value="'.
3952: $currpub.'" size="40" /></span><br />'."\n".
3953: '<span class="LC_nobreak"><span id="'.$context.'_recaptchaprivtxt">'.$privtext.'</span> '."\n".
3954: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapriv" name="'.$context.'_recaptchapriv" value="'.
3955: $currpriv.'" size="40" /></span></td></tr></table>'."\n".
3956: '</td></tr>';
3957: return $output;
3958: }
3959:
1.32 raeburn 3960: sub user_formats_row {
3961: my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount) = @_;
3962: my $output;
3963: my %text = (
3964: 'username' => 'new usernames',
3965: 'id' => 'IDs',
1.45 raeburn 3966: 'email' => 'self-created accounts (e-mail)',
1.32 raeburn 3967: );
3968: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
3969: $output = '<tr '.$css_class.'>'.
1.63 raeburn 3970: '<td><span class="LC_nobreak">';
3971: if ($type eq 'email') {
3972: $output .= &mt("Formats disallowed for $text{$type}: ");
3973: } else {
3974: $output .= &mt("Format rules to check for $text{$type}: ");
3975: }
3976: $output .= '</span></td>'.
3977: '<td class="LC_left_item" colspan="2"><table>';
1.27 raeburn 3978: my $rem;
3979: if (ref($ruleorder) eq 'ARRAY') {
3980: for (my $i=0; $i<@{$ruleorder}; $i++) {
3981: if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
3982: my $rem = $i%($numinrow);
3983: if ($rem == 0) {
3984: if ($i > 0) {
3985: $output .= '</tr>';
3986: }
3987: $output .= '<tr>';
3988: }
3989: my $check = ' ';
1.39 raeburn 3990: if (ref($settings) eq 'HASH') {
3991: if (ref($settings->{$type.'_rule'}) eq 'ARRAY') {
3992: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) {
3993: $check = ' checked="checked" ';
3994: }
1.27 raeburn 3995: }
3996: }
3997: $output .= '<td class="LC_left_item">'.
3998: '<span class="LC_nobreak"><label>'.
1.32 raeburn 3999: '<input type="checkbox" name="'.$type.'_rule" '.
1.27 raeburn 4000: 'value="'.$ruleorder->[$i].'"'.$check.'/>'.
4001: $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
4002: }
4003: }
4004: $rem = @{$ruleorder}%($numinrow);
4005: }
4006: my $colsleft = $numinrow - $rem;
4007: if ($colsleft > 1 ) {
4008: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
4009: ' </td>';
4010: } elsif ($colsleft == 1) {
4011: $output .= '<td class="LC_left_item"> </td>';
4012: }
4013: $output .= '</tr></table></td></tr>';
4014: return $output;
4015: }
4016:
1.34 raeburn 4017: sub usercreation_types {
4018: my %lt = &Apache::lonlocal::texthash (
4019: author => 'When adding a co-author',
4020: course => 'When adding a user to a course',
1.100 raeburn 4021: requestcrs => 'When requesting a course',
1.34 raeburn 4022: any => 'Any',
4023: official => 'Institutional only ',
4024: unofficial => 'Non-institutional only',
4025: none => 'None',
4026: );
4027: return %lt;
1.48 raeburn 4028: }
1.34 raeburn 4029:
1.224 raeburn 4030: sub selfcreation_types {
4031: my %lt = &Apache::lonlocal::texthash (
4032: selfcreate => 'User creates own account',
4033: any => 'Any',
4034: official => 'Institutional only ',
4035: unofficial => 'Non-institutional only',
4036: email => 'E-mail address',
4037: login => 'Institutional Login',
4038: sso => 'SSO',
4039: );
4040: }
4041:
1.28 raeburn 4042: sub authtype_names {
4043: my %lt = &Apache::lonlocal::texthash(
4044: int => 'Internal',
4045: krb4 => 'Kerberos 4',
4046: krb5 => 'Kerberos 5',
4047: loc => 'Local',
4048: );
4049: return %lt;
4050: }
4051:
4052: sub context_names {
4053: my %context_title = &Apache::lonlocal::texthash(
4054: author => 'Creating users when an Author',
4055: course => 'Creating users when in a course',
4056: domain => 'Creating users when a Domain Coordinator',
4057: );
4058: return %context_title;
4059: }
4060:
1.33 raeburn 4061: sub print_usermodification {
4062: my ($position,$dom,$settings,$rowtotal) = @_;
4063: my $numinrow = 4;
4064: my ($context,$datatable,$rowcount);
4065: if ($position eq 'top') {
4066: $rowcount = 0;
4067: $context = 'author';
4068: foreach my $role ('ca','aa') {
4069: $datatable .= &modifiable_userdata_row($context,$role,$settings,
4070: $numinrow,$rowcount);
4071: $$rowtotal ++;
4072: $rowcount ++;
4073: }
1.63 raeburn 4074: } elsif ($position eq 'middle') {
1.33 raeburn 4075: $context = 'course';
4076: $rowcount = 0;
4077: foreach my $role ('st','ep','ta','in','cr') {
4078: $datatable .= &modifiable_userdata_row($context,$role,$settings,
4079: $numinrow,$rowcount);
4080: $$rowtotal ++;
4081: $rowcount ++;
4082: }
4083: }
4084: return $datatable;
4085: }
4086:
1.43 raeburn 4087: sub print_defaults {
1.212 raeburn 4088: my ($dom,$settings,$rowtotal) = @_;
1.68 raeburn 4089: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def',
1.141 raeburn 4090: 'datelocale_def','portal_def');
1.212 raeburn 4091: my %defaults;
4092: if (ref($settings) eq 'HASH') {
1.213 raeburn 4093: %defaults = %{$settings};
1.212 raeburn 4094: } else {
4095: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
4096: foreach my $item (@items) {
4097: $defaults{$item} = $domdefaults{$item};
4098: }
4099: }
1.141 raeburn 4100: my $titles = &defaults_titles($dom);
1.43 raeburn 4101: my $rownum = 0;
4102: my ($datatable,$css_class);
4103: foreach my $item (@items) {
4104: if ($rownum%2) {
4105: $css_class = '';
4106: } else {
4107: $css_class = ' class="LC_odd_row" ';
4108: }
4109: $datatable .= '<tr'.$css_class.'>'.
4110: '<td><span class="LC_nobreak">'.$titles->{$item}.
4111: '</span></td><td class="LC_right_item">';
4112: if ($item eq 'auth_def') {
4113: my @authtypes = ('internal','krb4','krb5','localauth');
4114: my %shortauth = (
4115: internal => 'int',
4116: krb4 => 'krb4',
4117: krb5 => 'krb5',
4118: localauth => 'loc'
4119: );
4120: my %authnames = &authtype_names();
4121: foreach my $auth (@authtypes) {
4122: my $checked = ' ';
1.212 raeburn 4123: if ($defaults{$item} eq $auth) {
1.43 raeburn 4124: $checked = ' checked="checked" ';
4125: }
4126: $datatable .= '<label><input type="radio" name="'.$item.
4127: '" value="'.$auth.'"'.$checked.'/>'.
4128: $authnames{$shortauth{$auth}}.'</label> ';
4129: }
1.54 raeburn 4130: } elsif ($item eq 'timezone_def') {
4131: my $includeempty = 1;
1.212 raeburn 4132: $datatable .= &Apache::loncommon::select_timezone($item,$defaults{$item},undef,$includeempty);
1.68 raeburn 4133: } elsif ($item eq 'datelocale_def') {
4134: my $includeempty = 1;
1.212 raeburn 4135: $datatable .= &Apache::loncommon::select_datelocale($item,$defaults{$item},undef,$includeempty);
1.167 raeburn 4136: } elsif ($item eq 'lang_def') {
1.168 raeburn 4137: my %langchoices = &get_languages_hash();
4138: $langchoices{''} = 'No language preference';
1.167 raeburn 4139: %langchoices = &Apache::lonlocal::texthash(%langchoices);
1.212 raeburn 4140: $datatable .= &Apache::loncommon::select_form($defaults{$item},$item,
1.167 raeburn 4141: \%langchoices);
1.43 raeburn 4142: } else {
1.141 raeburn 4143: my $size;
4144: if ($item eq 'portal_def') {
4145: $size = ' size="25"';
4146: }
1.43 raeburn 4147: $datatable .= '<input type="text" name="'.$item.'" value="'.
1.212 raeburn 4148: $defaults{$item}.'"'.$size.' />';
1.43 raeburn 4149: }
4150: $datatable .= '</td></tr>';
4151: $rownum ++;
4152: }
4153: $$rowtotal += $rownum;
4154: return $datatable;
4155: }
4156:
1.168 raeburn 4157: sub get_languages_hash {
4158: my %langchoices;
4159: foreach my $id (&Apache::loncommon::languageids()) {
4160: my $code = &Apache::loncommon::supportedlanguagecode($id);
4161: if ($code ne '') {
4162: $langchoices{$code} = &Apache::loncommon::plainlanguagedescription($id);
4163: }
4164: }
4165: return %langchoices;
4166: }
4167:
1.43 raeburn 4168: sub defaults_titles {
1.141 raeburn 4169: my ($dom) = @_;
1.43 raeburn 4170: my %titles = &Apache::lonlocal::texthash (
4171: 'auth_def' => 'Default authentication type',
4172: 'auth_arg_def' => 'Default authentication argument',
4173: 'lang_def' => 'Default language',
1.54 raeburn 4174: 'timezone_def' => 'Default timezone',
1.68 raeburn 4175: 'datelocale_def' => 'Default locale for dates',
1.141 raeburn 4176: 'portal_def' => 'Portal/Default URL',
1.43 raeburn 4177: );
1.141 raeburn 4178: if ($dom) {
4179: my $uprimary_id = &Apache::lonnet::domain($dom,'primary');
4180: my $uint_dom = &Apache::lonnet::internet_dom($uprimary_id);
4181: my $protocol = $Apache::lonnet::protocol{$uprimary_id};
4182: $protocol = 'http' if ($protocol ne 'https');
4183: if ($uint_dom) {
4184: $titles{'portal_def'} .= ' '.&mt('(for example: [_1])',$protocol.'://loncapa.'.
4185: $uint_dom);
4186: }
4187: }
1.43 raeburn 4188: return (\%titles);
4189: }
4190:
1.46 raeburn 4191: sub print_scantronformat {
4192: my ($r,$dom,$confname,$settings,$rowtotal) = @_;
4193: my $itemcount = 1;
1.60 raeburn 4194: my ($datatable,$css_class,$scantronurl,$is_custom,%error,%scantronurls,
4195: %confhash);
1.46 raeburn 4196: my $switchserver = &check_switchserver($dom,$confname);
4197: my %lt = &Apache::lonlocal::texthash (
1.95 www 4198: default => 'Default bubblesheet format file error',
4199: custom => 'Custom bubblesheet format file error',
1.46 raeburn 4200: );
4201: my %scantronfiles = (
4202: default => 'default.tab',
4203: custom => 'custom.tab',
4204: );
4205: foreach my $key (keys(%scantronfiles)) {
4206: $scantronurls{$key} = '/res/'.$dom.'/'.$confname.'/scantron/'
4207: .$scantronfiles{$key};
4208: }
4209: my @defaultinfo = &Apache::lonnet::stat_file($scantronurls{'default'});
4210: if ((!@defaultinfo) || ($defaultinfo[0] eq 'no_such_dir')) {
4211: if (!$switchserver) {
4212: my $servadm = $r->dir_config('lonAdmEMail');
4213: my ($configuserok,$author_ok) = &config_check($dom,$confname,$servadm);
4214: if ($configuserok eq 'ok') {
4215: if ($author_ok eq 'ok') {
4216: my %legacyfile = (
4217: default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab',
4218: custom => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab',
4219: );
4220: my %md5chk;
4221: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 4222: ($md5chk{$type}) = split(/ /,`md5sum $legacyfile{$type}`);
4223: chomp($md5chk{$type});
1.46 raeburn 4224: }
4225: if ($md5chk{'default'} ne $md5chk{'custom'}) {
4226: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 4227: ($scantronurls{$type},my $error) =
1.46 raeburn 4228: &legacy_scantronformat($r,$dom,$confname,
4229: $type,$legacyfile{$type},
4230: $scantronurls{$type},
4231: $scantronfiles{$type});
1.60 raeburn 4232: if ($error ne '') {
4233: $error{$type} = $error;
4234: }
4235: }
4236: if (keys(%error) == 0) {
4237: $is_custom = 1;
4238: $confhash{'scantron'}{'scantronformat'} =
4239: $scantronurls{'custom'};
4240: my $putresult =
4241: &Apache::lonnet::put_dom('configuration',
4242: \%confhash,$dom);
4243: if ($putresult ne 'ok') {
4244: $error{'custom'} =
4245: '<span class="LC_error">'.
4246: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
4247: }
1.46 raeburn 4248: }
4249: } else {
1.60 raeburn 4250: ($scantronurls{'default'},my $error) =
1.46 raeburn 4251: &legacy_scantronformat($r,$dom,$confname,
4252: 'default',$legacyfile{'default'},
4253: $scantronurls{'default'},
4254: $scantronfiles{'default'});
1.60 raeburn 4255: if ($error eq '') {
4256: $confhash{'scantron'}{'scantronformat'} = '';
4257: my $putresult =
4258: &Apache::lonnet::put_dom('configuration',
4259: \%confhash,$dom);
4260: if ($putresult ne 'ok') {
4261: $error{'default'} =
4262: '<span class="LC_error">'.
4263: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
4264: }
4265: } else {
4266: $error{'default'} = $error;
4267: }
1.46 raeburn 4268: }
4269: }
4270: }
4271: } else {
1.95 www 4272: $error{'default'} = &mt("Unable to copy default bubblesheet formatfile to domain's RES space: [_1]",$switchserver);
1.46 raeburn 4273: }
4274: }
4275: if (ref($settings) eq 'HASH') {
4276: if ($settings->{'scantronformat'} eq "/res/$dom/$confname/scantron/custom.tab") {
4277: my @info = &Apache::lonnet::stat_file($settings->{'scantronformat'});
4278: if ((!@info) || ($info[0] eq 'no_such_dir')) {
4279: $scantronurl = '';
4280: } else {
4281: $scantronurl = $settings->{'scantronformat'};
4282: }
4283: $is_custom = 1;
4284: } else {
4285: $scantronurl = $scantronurls{'default'};
4286: }
4287: } else {
1.60 raeburn 4288: if ($is_custom) {
4289: $scantronurl = $scantronurls{'custom'};
4290: } else {
4291: $scantronurl = $scantronurls{'default'};
4292: }
1.46 raeburn 4293: }
4294: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4295: $datatable .= '<tr'.$css_class.'>';
4296: if (!$is_custom) {
1.65 raeburn 4297: $datatable .= '<td>'.&mt('Default in use:').'<br />'.
4298: '<span class="LC_nobreak">';
1.46 raeburn 4299: if ($scantronurl) {
1.199 raeburn 4300: $datatable .= &Apache::loncommon::modal_link($scantronurl,&mt('Default bubblesheet format file'),600,500,
4301: undef,undef,undef,undef,'background-color:#ffffff');
1.46 raeburn 4302: } else {
4303: $datatable = &mt('File unavailable for display');
4304: }
1.65 raeburn 4305: $datatable .= '</span></td>';
1.60 raeburn 4306: if (keys(%error) == 0) {
4307: $datatable .= '<td valign="bottom">';
4308: if (!$switchserver) {
4309: $datatable .= &mt('Upload:').'<br />';
4310: }
4311: } else {
4312: my $errorstr;
4313: foreach my $key (sort(keys(%error))) {
4314: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
4315: }
4316: $datatable .= '<td>'.$errorstr;
4317: }
1.46 raeburn 4318: } else {
4319: if (keys(%error) > 0) {
4320: my $errorstr;
4321: foreach my $key (sort(keys(%error))) {
4322: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
4323: }
1.60 raeburn 4324: $datatable .= '<td>'.$errorstr.'</td><td> ';
1.46 raeburn 4325: } elsif ($scantronurl) {
1.199 raeburn 4326: my $link = &Apache::loncommon::modal_link($scantronurl,&mt('Custom bubblesheet format file'),600,500,
4327: undef,undef,undef,undef,'background-color:#ffffff');
1.65 raeburn 4328: $datatable .= '<td><span class="LC_nobreak">'.
1.199 raeburn 4329: $link.
4330: '<label><input type="checkbox" name="scantronformat_del"'.
4331: ' value="1" />'.&mt('Delete?').'</label></span></td>'.
1.65 raeburn 4332: '<td><span class="LC_nobreak"> '.
4333: &mt('Replace:').'</span><br />';
1.46 raeburn 4334: }
4335: }
4336: if (keys(%error) == 0) {
4337: if ($switchserver) {
4338: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
4339: } else {
1.65 raeburn 4340: $datatable .='<span class="LC_nobreak"> '.
4341: '<input type="file" name="scantronformat" /></span>';
1.46 raeburn 4342: }
4343: }
4344: $datatable .= '</td></tr>';
4345: $$rowtotal ++;
4346: return $datatable;
4347: }
4348:
4349: sub legacy_scantronformat {
4350: my ($r,$dom,$confname,$file,$legacyfile,$newurl,$newfile) = @_;
4351: my ($url,$error);
4352: my @statinfo = &Apache::lonnet::stat_file($newurl);
4353: if ((!@statinfo) || ($statinfo[0] eq 'no_such_dir')) {
4354: (my $result,$url) =
4355: &publishlogo($r,'copy',$legacyfile,$dom,$confname,'scantron',
4356: '','',$newfile);
4357: if ($result ne 'ok') {
1.130 raeburn 4358: $error = &mt("An error occurred publishing the [_1] bubblesheet format file in RES space. Error was: [_2].",$newfile,$result);
1.46 raeburn 4359: }
4360: }
4361: return ($url,$error);
4362: }
1.43 raeburn 4363:
1.49 raeburn 4364: sub print_coursecategories {
1.57 raeburn 4365: my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;
4366: my $datatable;
4367: if ($position eq 'top') {
4368: my $toggle_cats_crs = ' ';
4369: my $toggle_cats_dom = ' checked="checked" ';
4370: my $can_cat_crs = ' ';
4371: my $can_cat_dom = ' checked="checked" ';
1.120 raeburn 4372: my $toggle_catscomm_comm = ' ';
4373: my $toggle_catscomm_dom = ' checked="checked" ';
4374: my $can_catcomm_comm = ' ';
4375: my $can_catcomm_dom = ' checked="checked" ';
4376:
1.57 raeburn 4377: if (ref($settings) eq 'HASH') {
4378: if ($settings->{'togglecats'} eq 'crs') {
4379: $toggle_cats_crs = $toggle_cats_dom;
4380: $toggle_cats_dom = ' ';
4381: }
4382: if ($settings->{'categorize'} eq 'crs') {
4383: $can_cat_crs = $can_cat_dom;
4384: $can_cat_dom = ' ';
4385: }
1.120 raeburn 4386: if ($settings->{'togglecatscomm'} eq 'comm') {
4387: $toggle_catscomm_comm = $toggle_catscomm_dom;
4388: $toggle_catscomm_dom = ' ';
4389: }
4390: if ($settings->{'categorizecomm'} eq 'comm') {
4391: $can_catcomm_comm = $can_catcomm_dom;
4392: $can_catcomm_dom = ' ';
4393: }
1.57 raeburn 4394: }
4395: my %title = &Apache::lonlocal::texthash (
1.120 raeburn 4396: togglecats => 'Show/Hide a course in catalog',
4397: togglecatscomm => 'Show/Hide a community in catalog',
4398: categorize => 'Assign a category to a course',
4399: categorizecomm => 'Assign a category to a community',
1.57 raeburn 4400: );
4401: my %level = &Apache::lonlocal::texthash (
1.120 raeburn 4402: dom => 'Set in Domain',
4403: crs => 'Set in Course',
4404: comm => 'Set in Community',
1.57 raeburn 4405: );
4406: $datatable = '<tr class="LC_odd_row">'.
4407: '<td>'.$title{'togglecats'}.'</td>'.
4408: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4409: '<input type="radio" name="togglecats"'.
4410: $toggle_cats_dom.' value="dom" />'.$level{'dom'}.'</label> '.
4411: '<label><input type="radio" name="togglecats"'.
4412: $toggle_cats_crs.' value="crs" />'.$level{'crs'}.'</label></span></td>'.
4413: '</tr><tr>'.
4414: '<td>'.$title{'categorize'}.'</td>'.
4415: '<td class="LC_right_item"><span class="LC_nobreak">'.
4416: '<label><input type="radio" name="categorize"'.
4417: $can_cat_dom.' value="dom" />'.$level{'dom'}.'</label> '.
4418: '<label><input type="radio" name="categorize"'.
4419: $can_cat_crs.'value="crs" />'.$level{'crs'}.'</label></span></td>'.
1.120 raeburn 4420: '</tr><tr class="LC_odd_row">'.
4421: '<td>'.$title{'togglecatscomm'}.'</td>'.
4422: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4423: '<input type="radio" name="togglecatscomm"'.
4424: $toggle_catscomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
4425: '<label><input type="radio" name="togglecatscomm"'.
4426: $toggle_catscomm_comm.' value="comm" />'.$level{'comm'}.'</label></span></td>'.
4427: '</tr><tr>'.
4428: '<td>'.$title{'categorizecomm'}.'</td>'.
4429: '<td class="LC_right_item"><span class="LC_nobreak">'.
4430: '<label><input type="radio" name="categorizecomm"'.
4431: $can_catcomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
4432: '<label><input type="radio" name="categorizecomm"'.
4433: $can_catcomm_comm.'value="comm" />'.$level{'comm'}.'</label></span></td>'.
1.57 raeburn 4434: '</tr>';
1.120 raeburn 4435: $$rowtotal += 4;
1.57 raeburn 4436: } else {
4437: my $css_class;
4438: my $itemcount = 1;
4439: my $cathash;
4440: if (ref($settings) eq 'HASH') {
4441: $cathash = $settings->{'cats'};
4442: }
4443: if (ref($cathash) eq 'HASH') {
4444: my (@cats,@trails,%allitems,%idx,@jsarray);
4445: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
4446: \%allitems,\%idx,\@jsarray);
4447: my $maxdepth = scalar(@cats);
4448: my $colattrib = '';
4449: if ($maxdepth > 2) {
4450: $colattrib = ' colspan="2" ';
4451: }
4452: my @path;
4453: if (@cats > 0) {
4454: if (ref($cats[0]) eq 'ARRAY') {
4455: my $numtop = @{$cats[0]};
4456: my $maxnum = $numtop;
1.120 raeburn 4457: my %default_names = (
4458: instcode => &mt('Official courses'),
4459: communities => &mt('Communities'),
4460: );
4461:
4462: if ((!grep(/^instcode$/,@{$cats[0]})) ||
4463: ($cathash->{'instcode::0'} eq '') ||
4464: (!grep(/^communities$/,@{$cats[0]})) ||
4465: ($cathash->{'communities::0'} eq '')) {
1.57 raeburn 4466: $maxnum ++;
4467: }
4468: my $lastidx;
4469: for (my $i=0; $i<$numtop; $i++) {
4470: my $parent = $cats[0][$i];
4471: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4472: my $item = &escape($parent).'::0';
4473: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$item','$idx{$item}'".');"';
4474: $lastidx = $idx{$item};
4475: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
4476: .'<select name="'.$item.'"'.$chgstr.'>';
4477: for (my $k=0; $k<=$maxnum; $k++) {
4478: my $vpos = $k+1;
4479: my $selstr;
4480: if ($k == $i) {
4481: $selstr = ' selected="selected" ';
4482: }
4483: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4484: }
1.214 raeburn 4485: $datatable .= '</select></span></td><td>';
1.120 raeburn 4486: if ($parent eq 'instcode' || $parent eq 'communities') {
4487: $datatable .= '<span class="LC_nobreak">'
4488: .$default_names{$parent}.'</span>';
4489: if ($parent eq 'instcode') {
4490: $datatable .= '<br /><span class="LC_nobreak">('
4491: .&mt('with institutional codes')
4492: .')</span></td><td'.$colattrib.'>';
4493: } else {
4494: $datatable .= '<table><tr><td>';
4495: }
4496: $datatable .= '<span class="LC_nobreak">'
4497: .'<label><input type="radio" name="'
4498: .$parent.'" value="1" checked="checked" />'
4499: .&mt('Display').'</label>';
4500: if ($parent eq 'instcode') {
4501: $datatable .= ' ';
4502: } else {
4503: $datatable .= '</span></td></tr><tr><td>'
4504: .'<span class="LC_nobreak">';
4505: }
4506: $datatable .= '<label><input type="radio" name="'
4507: .$parent.'" value="0" />'
4508: .&mt('Do not display').'</label></span>';
4509: if ($parent eq 'communities') {
4510: $datatable .= '</td></tr></table>';
4511: }
4512: $datatable .= '</td>';
1.57 raeburn 4513: } else {
4514: $datatable .= $parent
1.214 raeburn 4515: .' <span class="LC_nobreak"><label>'
4516: .'<input type="checkbox" name="deletecategory" '
1.57 raeburn 4517: .'value="'.$item.'" />'.&mt('Delete').'</label></span></td>';
4518: }
4519: my $depth = 1;
4520: push(@path,$parent);
4521: $datatable .= &build_category_rows($itemcount,\@cats,$depth,$parent,\@path,\%idx);
4522: pop(@path);
4523: $datatable .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
4524: $itemcount ++;
4525: }
1.48 raeburn 4526: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.57 raeburn 4527: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','$lastidx'".');"';
4528: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="addcategory_pos"'.$chgstr.'>';
1.48 raeburn 4529: for (my $k=0; $k<=$maxnum; $k++) {
4530: my $vpos = $k+1;
4531: my $selstr;
1.57 raeburn 4532: if ($k == $numtop) {
1.48 raeburn 4533: $selstr = ' selected="selected" ';
4534: }
4535: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4536: }
1.59 bisitz 4537: $datatable .= '</select></span></td><td colspan="2">'.&mt('Add category:').' '
1.57 raeburn 4538: .'<input type="text" size="20" name="addcategory_name" value="" /></td>'
4539: .'</tr>'."\n";
1.48 raeburn 4540: $itemcount ++;
1.120 raeburn 4541: foreach my $default ('instcode','communities') {
4542: if ((!grep(/^\Q$default\E$/,@{$cats[0]})) || ($cathash->{$default.'::0'} eq '')) {
4543: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4544: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','$lastidx'".');"';
4545: $datatable .= '<tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr><tr '.$css_class.'><td>'.
4546: '<span class="LC_nobreak"><select name="'.$default.'_pos"'.$chgstr.'>';
4547: for (my $k=0; $k<=$maxnum; $k++) {
4548: my $vpos = $k+1;
4549: my $selstr;
4550: if ($k == $maxnum) {
4551: $selstr = ' selected="selected" ';
4552: }
4553: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.57 raeburn 4554: }
1.120 raeburn 4555: $datatable .= '</select></span></td>'.
4556: '<td><span class="LC_nobreak">'.
4557: $default_names{$default}.'</span>';
4558: if ($default eq 'instcode') {
4559: $datatable .= '<br /><span class="LC_nobreak">('
4560: .&mt('with institutional codes').')</span>';
4561: }
4562: $datatable .= '</td>'
4563: .'<td><span class="LC_nobreak"><label><input type="radio" name="'.$default.'" value="1" />'
4564: .&mt('Display').'</label> '
4565: .'<label><input type="radio" name="'.$default.'" value="0" checked="checked"/>'
4566: .&mt('Do not display').'</label></span></td></tr>';
1.48 raeburn 4567: }
4568: }
4569: }
1.57 raeburn 4570: } else {
4571: $datatable .= &initialize_categories($itemcount);
1.48 raeburn 4572: }
4573: } else {
1.57 raeburn 4574: $datatable .= '<td class="LC_right_item">'.$hdritem->{'header'}->[0]->{'col2'}.'</td>'
4575: .&initialize_categories($itemcount);
1.48 raeburn 4576: }
1.57 raeburn 4577: $$rowtotal += $itemcount;
1.48 raeburn 4578: }
4579: return $datatable;
4580: }
4581:
1.69 raeburn 4582: sub print_serverstatuses {
4583: my ($dom,$settings,$rowtotal) = @_;
4584: my $datatable;
4585: my @pages = &serverstatus_pages();
4586: my (%namedaccess,%machineaccess);
4587: foreach my $type (@pages) {
4588: $namedaccess{$type} = '';
4589: $machineaccess{$type}= '';
4590: }
4591: if (ref($settings) eq 'HASH') {
4592: foreach my $type (@pages) {
4593: if (exists($settings->{$type})) {
4594: if (ref($settings->{$type}) eq 'HASH') {
4595: foreach my $key (keys(%{$settings->{$type}})) {
4596: if ($key eq 'namedusers') {
4597: $namedaccess{$type} = $settings->{$type}->{$key};
4598: } elsif ($key eq 'machines') {
4599: $machineaccess{$type} = $settings->{$type}->{$key};
4600: }
4601: }
4602: }
4603: }
4604: }
4605: }
1.81 raeburn 4606: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 4607: my $rownum = 0;
4608: my $css_class;
4609: foreach my $type (@pages) {
4610: $rownum ++;
4611: $css_class = $rownum%2?' class="LC_odd_row"':'';
4612: $datatable .= '<tr'.$css_class.'>'.
4613: '<td><span class="LC_nobreak">'.
4614: $titles->{$type}.'</span></td>'.
4615: '<td class="LC_left_item">'.
4616: '<input type="text" name="'.$type.'_namedusers" '.
4617: 'value="'.$namedaccess{$type}.'" size="30" /></td>'.
4618: '<td class="LC_right_item">'.
4619: '<span class="LC_nobreak">'.
4620: '<input type="text" name="'.$type.'_machines" '.
4621: 'value="'.$machineaccess{$type}.'" size="10" />'.
4622: '</td></tr>'."\n";
4623: }
4624: $$rowtotal += $rownum;
4625: return $datatable;
4626: }
4627:
4628: sub serverstatus_pages {
4629: return ('userstatus','lonstatus','loncron','server-status','codeversions',
1.189 raeburn 4630: 'checksums','clusterstatus','metadata_keywords','metadata_harvest',
1.221 raeburn 4631: 'takeoffline','takeonline','showenv','toggledebug','ping','domconf',
4632: 'uniquecodes');
1.69 raeburn 4633: }
4634:
1.49 raeburn 4635: sub coursecategories_javascript {
4636: my ($settings) = @_;
1.57 raeburn 4637: my ($output,$jstext,$cathash);
1.49 raeburn 4638: if (ref($settings) eq 'HASH') {
1.57 raeburn 4639: $cathash = $settings->{'cats'};
4640: }
4641: if (ref($cathash) eq 'HASH') {
1.49 raeburn 4642: my (@cats,@jsarray,%idx);
1.57 raeburn 4643: &Apache::loncommon::gather_categories($cathash,\@cats,\%idx,\@jsarray);
1.49 raeburn 4644: if (@jsarray > 0) {
4645: $jstext = ' var categories = Array('.scalar(@jsarray).');'."\n";
4646: for (my $i=0; $i<@jsarray; $i++) {
4647: if (ref($jsarray[$i]) eq 'ARRAY') {
4648: my $catstr = join('","',@{$jsarray[$i]});
4649: $jstext .= ' categories['.$i.'] = Array("'.$catstr.'");'."\n";
4650: }
4651: }
4652: }
4653: } else {
4654: $jstext = ' var categories = Array(1);'."\n".
4655: ' categories[0] = Array("instcode_pos");'."\n";
4656: }
1.120 raeburn 4657: my $instcode_reserved = &mt('The name: "instcode" is a reserved category');
4658: my $communities_reserved = &mt('The name: "communities" is a reserved category');
4659: my $choose_again = '\\n'.&mt('Please use a different name for the new top level category');
1.49 raeburn 4660: $output = <<"ENDSCRIPT";
4661: <script type="text/javascript">
1.109 raeburn 4662: // <![CDATA[
1.49 raeburn 4663: function reorderCats(form,parent,item,idx) {
4664: var changedVal;
4665: $jstext
4666: var newpos = 'addcategory_pos';
4667: var current = new Array;
4668: if (parent == '') {
4669: var has_instcode = 0;
4670: var maxtop = categories[idx].length;
4671: for (var j=0; j<maxtop; j++) {
4672: if (categories[idx][j] == 'instcode::0') {
4673: has_instcode == 1;
4674: }
4675: }
4676: if (has_instcode == 0) {
4677: categories[idx][maxtop] = 'instcode_pos';
4678: }
4679: } else {
4680: newpos += '_'+parent;
4681: }
4682: var maxh = 1 + categories[idx].length;
4683: var current = new Array;
4684: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
4685: if (item == newpos) {
4686: changedVal = newitemVal;
4687: } else {
4688: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
4689: current[newitemVal] = newpos;
4690: }
4691: for (var i=0; i<categories[idx].length; i++) {
4692: var elementName = categories[idx][i];
4693: if (elementName != item) {
4694: if (form.elements[elementName]) {
4695: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
4696: current[currVal] = elementName;
4697: }
4698: }
4699: }
4700: var oldVal;
4701: for (var j=0; j<maxh; j++) {
4702: if (current[j] == undefined) {
4703: oldVal = j;
4704: }
4705: }
4706: if (oldVal < changedVal) {
4707: for (var k=oldVal+1; k<=changedVal ; k++) {
4708: var elementName = current[k];
4709: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
4710: }
4711: } else {
4712: for (var k=changedVal; k<oldVal; k++) {
4713: var elementName = current[k];
4714: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
4715: }
4716: }
4717: return;
4718: }
1.120 raeburn 4719:
4720: function categoryCheck(form) {
4721: if (form.elements['addcategory_name'].value == 'instcode') {
4722: alert('$instcode_reserved\\n$choose_again');
4723: return false;
4724: }
4725: if (form.elements['addcategory_name'].value == 'communities') {
4726: alert('$communities_reserved\\n$choose_again');
4727: return false;
4728: }
4729: return true;
4730: }
4731:
1.109 raeburn 4732: // ]]>
1.49 raeburn 4733: </script>
4734:
4735: ENDSCRIPT
4736: return $output;
4737: }
4738:
1.48 raeburn 4739: sub initialize_categories {
4740: my ($itemcount) = @_;
1.120 raeburn 4741: my ($datatable,$css_class,$chgstr);
4742: my %default_names = (
4743: instcode => 'Official courses (with institutional codes)',
4744: communities => 'Communities',
4745: );
4746: my $select0 = ' selected="selected"';
4747: my $select1 = '';
4748: foreach my $default ('instcode','communities') {
4749: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4750: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'',$default"."_pos','0'".');"';
4751: if ($default eq 'communities') {
4752: $select1 = $select0;
4753: $select0 = '';
4754: }
4755: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
4756: .'<select name="'.$default.'_pos">'
4757: .'<option value="0"'.$select0.'>1</option>'
4758: .'<option value="1"'.$select1.'>2</option>'
4759: .'<option value="2">3</option></select> '
4760: .$default_names{$default}
4761: .'</span></td><td><span class="LC_nobreak">'
4762: .'<label><input type="radio" name="'.$default.'" value="1" checked="checked" />'
4763: .&mt('Display').'</label> <label>'
4764: .'<input type="radio" name="'.$default.'" value="0" />'.&mt('Do not display')
1.48 raeburn 4765: .'</label></span></td></tr>';
1.120 raeburn 4766: $itemcount ++;
4767: }
1.48 raeburn 4768: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.49 raeburn 4769: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','0'".');"';
1.48 raeburn 4770: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.120 raeburn 4771: .'<select name="addcategory_pos"'.$chgstr.'>'
4772: .'<option value="0">1</option>'
4773: .'<option value="1">2</option>'
4774: .'<option value="2" selected="selected">3</option></select> '
1.48 raeburn 4775: .&mt('Add category').'</td><td>'.&mt('Name:')
4776: .' <input type="text" size="20" name="addcategory_name" value="" /></td></tr>';
4777: return $datatable;
4778: }
4779:
4780: sub build_category_rows {
1.49 raeburn 4781: my ($itemcount,$cats,$depth,$parent,$path,$idx) = @_;
4782: my ($text,$name,$item,$chgstr);
1.48 raeburn 4783: if (ref($cats) eq 'ARRAY') {
4784: my $maxdepth = scalar(@{$cats});
4785: if (ref($cats->[$depth]) eq 'HASH') {
4786: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
4787: my $numchildren = @{$cats->[$depth]{$parent}};
4788: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.204 raeburn 4789: $text .= '<td><table class="LC_data_table">';
1.49 raeburn 4790: my ($idxnum,$parent_name,$parent_item);
4791: my $higher = $depth - 1;
4792: if ($higher == 0) {
4793: $parent_name = &escape($parent).'::'.$higher;
4794: } else {
4795: if (ref($path) eq 'ARRAY') {
4796: $parent_name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
4797: }
4798: }
4799: $parent_item = 'addcategory_pos_'.$parent_name;
1.48 raeburn 4800: for (my $j=0; $j<=$numchildren; $j++) {
1.49 raeburn 4801: if ($j < $numchildren) {
1.48 raeburn 4802: $name = $cats->[$depth]{$parent}[$j];
4803: $item = &escape($name).':'.&escape($parent).':'.$depth;
1.49 raeburn 4804: $idxnum = $idx->{$item};
4805: } else {
4806: $name = $parent_name;
4807: $item = $parent_item;
1.48 raeburn 4808: }
1.49 raeburn 4809: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'$parent_name','$item','$idxnum'".');"';
4810: $text .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="'.$item.'"'.$chgstr.'>';
1.48 raeburn 4811: for (my $i=0; $i<=$numchildren; $i++) {
4812: my $vpos = $i+1;
4813: my $selstr;
4814: if ($j == $i) {
4815: $selstr = ' selected="selected" ';
4816: }
4817: $text .= '<option value="'.$i.'"'.$selstr.'>'.$vpos.'</option>';
4818: }
4819: $text .= '</select> ';
4820: if ($j < $numchildren) {
4821: my $deeper = $depth+1;
4822: $text .= $name.' '
4823: .'<label><input type="checkbox" name="deletecategory" value="'
4824: .$item.'" />'.&mt('Delete').'</label></span></td><td>';
4825: if(ref($path) eq 'ARRAY') {
4826: push(@{$path},$name);
1.49 raeburn 4827: $text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path,$idx);
1.48 raeburn 4828: pop(@{$path});
4829: }
4830: } else {
1.59 bisitz 4831: $text .= &mt('Add subcategory:').' </span><input type="textbox" size="20" name="addcategory_name_';
1.48 raeburn 4832: if ($j == $numchildren) {
4833: $text .= $name;
4834: } else {
4835: $text .= $item;
4836: }
4837: $text .= '" value="" />';
4838: }
4839: $text .= '</td></tr>';
4840: }
4841: $text .= '</table></td>';
4842: } else {
4843: my $higher = $depth-1;
4844: if ($higher == 0) {
4845: $name = &escape($parent).'::'.$higher;
4846: } else {
4847: if (ref($path) eq 'ARRAY') {
4848: $name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
4849: }
4850: }
4851: my $colspan;
4852: if ($parent ne 'instcode') {
4853: $colspan = $maxdepth - $depth - 1;
4854: $text .= '<td colspan="'.$colspan.'">'.&mt('Add subcategory:').'<input type="textbox" size="20" name="subcat_'.$name.'" value="" /></td>';
4855: }
4856: }
4857: }
4858: }
4859: return $text;
4860: }
4861:
1.33 raeburn 4862: sub modifiable_userdata_row {
1.228 ! raeburn 4863: my ($context,$item,$settings,$numinrow,$rowcount,$usertypes,$fieldsref,$titlesref) = @_;
! 4864: my ($role,$rolename,$statustype);
! 4865: $role = $item;
1.224 raeburn 4866: if ($context eq 'cancreate') {
1.228 ! raeburn 4867: if ($item =~ /^emailusername_(.+)$/) {
! 4868: $statustype = $1;
! 4869: $role = 'emailusername';
! 4870: if (ref($usertypes) eq 'HASH') {
! 4871: if ($usertypes->{$statustype}) {
! 4872: $rolename = &mt('Data provided by [_1]',$usertypes->{$statustype});
! 4873: } else {
! 4874: $rolename = &mt('Data provided by user');
! 4875: }
! 4876: }
1.224 raeburn 4877: }
4878: } elsif ($context eq 'selfcreate') {
1.63 raeburn 4879: if (ref($usertypes) eq 'HASH') {
4880: $rolename = $usertypes->{$role};
4881: } else {
4882: $rolename = $role;
4883: }
1.33 raeburn 4884: } else {
1.63 raeburn 4885: if ($role eq 'cr') {
4886: $rolename = &mt('Custom role');
4887: } else {
4888: $rolename = &Apache::lonnet::plaintext($role);
4889: }
1.33 raeburn 4890: }
1.224 raeburn 4891: my (@fields,%fieldtitles);
4892: if (ref($fieldsref) eq 'ARRAY') {
4893: @fields = @{$fieldsref};
4894: } else {
4895: @fields = ('lastname','firstname','middlename','generation',
4896: 'permanentemail','id');
4897: }
4898: if ((ref($titlesref) eq 'HASH')) {
4899: %fieldtitles = %{$titlesref};
4900: } else {
4901: %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
4902: }
1.33 raeburn 4903: my $output;
4904: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
4905: $output = '<tr '.$css_class.'>'.
4906: '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
4907: '<td class="LC_left_item" colspan="2"><table>';
4908: my $rem;
4909: my %checks;
4910: if (ref($settings) eq 'HASH') {
4911: if (ref($settings->{$context}) eq 'HASH') {
4912: if (ref($settings->{$context}->{$role}) eq 'HASH') {
1.228 ! raeburn 4913: my $hashref = $settings->{$context}->{$role};
! 4914: if ($role eq 'emailusername') {
! 4915: if ($statustype) {
! 4916: if (ref($settings->{$context}->{$role}->{$statustype}) eq 'HASH') {
! 4917: $hashref = $settings->{$context}->{$role}->{$statustype};
! 4918: if (ref($hashref) eq 'HASH') {
! 4919: foreach my $field (@fields) {
! 4920: if ($hashref->{$field}) {
! 4921: $checks{$field} = $hashref->{$field};
! 4922: }
! 4923: }
! 4924: }
! 4925: }
! 4926: }
! 4927: } else {
! 4928: if (ref($hashref) eq 'HASH') {
! 4929: foreach my $field (@fields) {
! 4930: if ($hashref->{$field}) {
! 4931: $checks{$field} = ' checked="checked" ';
! 4932: }
! 4933: }
1.33 raeburn 4934: }
4935: }
4936: }
4937: }
4938: }
1.228 ! raeburn 4939:
1.33 raeburn 4940: for (my $i=0; $i<@fields; $i++) {
4941: my $rem = $i%($numinrow);
4942: if ($rem == 0) {
4943: if ($i > 0) {
4944: $output .= '</tr>';
4945: }
4946: $output .= '<tr>';
4947: }
4948: my $check = ' ';
1.228 ! raeburn 4949: unless ($role eq 'emailusername') {
! 4950: if (exists($checks{$fields[$i]})) {
! 4951: $check = $checks{$fields[$i]}
! 4952: } else {
! 4953: if ($role eq 'st') {
! 4954: if (ref($settings) ne 'HASH') {
! 4955: $check = ' checked="checked" ';
! 4956: }
1.33 raeburn 4957: }
4958: }
4959: }
4960: $output .= '<td class="LC_left_item">'.
1.228 ! raeburn 4961: '<span class="LC_nobreak">';
! 4962: if ($role eq 'emailusername') {
! 4963: unless ($checks{$fields[$i]} =~ /^(required|optional)$/) {
! 4964: $checks{$fields[$i]} = 'omit';
! 4965: }
! 4966: foreach my $option ('required','optional','omit') {
! 4967: my $checked='';
! 4968: if ($checks{$fields[$i]} eq $option) {
! 4969: $checked='checked="checked" ';
! 4970: }
! 4971: $output .= '<label>'.
! 4972: '<input type="radio" name="canmodify_'.$item.'_'.$fields[$i].'" value="'.$option.'" '.$checked.'/>'.
! 4973: &mt($option).'</label>'.(' ' x2);
! 4974: }
! 4975: $output .= '<i>'.$fieldtitles{$fields[$i]}.'</i>';
! 4976: } else {
! 4977: $output .= '<label>'.
! 4978: '<input type="checkbox" name="canmodify_'.$role.'" '.
! 4979: 'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
! 4980: '</label>';
! 4981: }
! 4982: $output .= '</span></td>';
1.33 raeburn 4983: $rem = @fields%($numinrow);
4984: }
4985: my $colsleft = $numinrow - $rem;
4986: if ($colsleft > 1 ) {
4987: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
4988: ' </td>';
4989: } elsif ($colsleft == 1) {
4990: $output .= '<td class="LC_left_item"> </td>';
4991: }
4992: $output .= '</tr></table></td></tr>';
4993: return $output;
4994: }
1.28 raeburn 4995:
1.93 raeburn 4996: sub insttypes_row {
1.224 raeburn 4997: my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle,$context,$rownum) = @_;
1.93 raeburn 4998: my %lt = &Apache::lonlocal::texthash (
4999: cansearch => 'Users allowed to search',
5000: statustocreate => 'Institutional affiliation(s) able to create own account (login/SSO)',
1.131 raeburn 5001: lockablenames => 'User preference to lock name',
1.93 raeburn 5002: );
5003: my $showdom;
5004: if ($context eq 'cansearch') {
5005: $showdom = ' ('.$dom.')';
5006: }
1.165 raeburn 5007: my $class = 'LC_left_item';
5008: if ($context eq 'statustocreate') {
5009: $class = 'LC_right_item';
5010: }
1.224 raeburn 5011: my $css_class = ' class="LC_odd_row"';
5012: if ($rownum ne '') {
5013: $css_class = ($rownum%2? ' class="LC_odd_row"':'');
5014: }
5015: my $output = '<tr'.$css_class.'>'.
5016: '<td>'.$lt{$context}.$showdom.
5017: '</td><td class="'.$class.'" colspan="2"><table>';
1.26 raeburn 5018: my $rem;
5019: if (ref($types) eq 'ARRAY') {
5020: for (my $i=0; $i<@{$types}; $i++) {
5021: if (defined($usertypes->{$types->[$i]})) {
5022: my $rem = $i%($numinrow);
5023: if ($rem == 0) {
5024: if ($i > 0) {
5025: $output .= '</tr>';
5026: }
5027: $output .= '<tr>';
1.23 raeburn 5028: }
1.26 raeburn 5029: my $check = ' ';
1.99 raeburn 5030: if (ref($settings) eq 'HASH') {
5031: if (ref($settings->{$context}) eq 'ARRAY') {
5032: if (grep(/^\Q$types->[$i]\E$/,@{$settings->{$context}})) {
5033: $check = ' checked="checked" ';
5034: }
5035: } elsif ($context eq 'statustocreate') {
1.26 raeburn 5036: $check = ' checked="checked" ';
5037: }
1.23 raeburn 5038: }
1.26 raeburn 5039: $output .= '<td class="LC_left_item">'.
5040: '<span class="LC_nobreak"><label>'.
1.93 raeburn 5041: '<input type="checkbox" name="'.$context.'" '.
1.26 raeburn 5042: 'value="'.$types->[$i].'"'.$check.'/>'.
5043: $usertypes->{$types->[$i]}.'</label></span></td>';
1.23 raeburn 5044: }
5045: }
1.26 raeburn 5046: $rem = @{$types}%($numinrow);
1.23 raeburn 5047: }
5048: my $colsleft = $numinrow - $rem;
1.131 raeburn 5049: if (($rem == 0) && (@{$types} > 0)) {
5050: $output .= '<tr>';
5051: }
1.23 raeburn 5052: if ($colsleft > 1) {
1.25 raeburn 5053: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
1.23 raeburn 5054: } else {
1.25 raeburn 5055: $output .= '<td class="LC_left_item">';
1.23 raeburn 5056: }
5057: my $defcheck = ' ';
1.99 raeburn 5058: if (ref($settings) eq 'HASH') {
5059: if (ref($settings->{$context}) eq 'ARRAY') {
5060: if (grep(/^default$/,@{$settings->{$context}})) {
5061: $defcheck = ' checked="checked" ';
5062: }
5063: } elsif ($context eq 'statustocreate') {
1.26 raeburn 5064: $defcheck = ' checked="checked" ';
5065: }
1.23 raeburn 5066: }
1.25 raeburn 5067: $output .= '<span class="LC_nobreak"><label>'.
1.93 raeburn 5068: '<input type="checkbox" name="'.$context.'" '.
1.25 raeburn 5069: 'value="default"'.$defcheck.'/>'.
5070: $othertitle.'</label></span></td>'.
5071: '</tr></table></td></tr>';
5072: return $output;
1.23 raeburn 5073: }
5074:
5075: sub sorted_searchtitles {
5076: my %searchtitles = &Apache::lonlocal::texthash(
5077: 'uname' => 'username',
5078: 'lastname' => 'last name',
5079: 'lastfirst' => 'last name, first name',
5080: );
5081: my @titleorder = ('uname','lastname','lastfirst');
5082: return (\%searchtitles,\@titleorder);
5083: }
5084:
1.25 raeburn 5085: sub sorted_searchtypes {
5086: my %srchtypes_desc = (
5087: exact => 'is exact match',
5088: contains => 'contains ..',
5089: begins => 'begins with ..',
5090: );
5091: my @srchtypeorder = ('exact','begins','contains');
5092: return (\%srchtypes_desc,\@srchtypeorder);
5093: }
5094:
1.3 raeburn 5095: sub usertype_update_row {
5096: my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
5097: my $datatable;
5098: my $numinrow = 4;
5099: foreach my $type (@{$types}) {
5100: if (defined($usertypes->{$type})) {
5101: $$rownums ++;
5102: my $css_class = $$rownums%2?' class="LC_odd_row"':'';
5103: $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
5104: '</td><td class="LC_left_item"><table>';
5105: for (my $i=0; $i<@{$fields}; $i++) {
5106: my $rem = $i%($numinrow);
5107: if ($rem == 0) {
5108: if ($i > 0) {
5109: $datatable .= '</tr>';
5110: }
5111: $datatable .= '<tr>';
5112: }
5113: my $check = ' ';
1.39 raeburn 5114: if (ref($settings) eq 'HASH') {
5115: if (ref($settings->{'fields'}) eq 'HASH') {
5116: if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
5117: if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
5118: $check = ' checked="checked" ';
5119: }
1.3 raeburn 5120: }
5121: }
5122: }
5123:
5124: if ($i == @{$fields}-1) {
5125: my $colsleft = $numinrow - $rem;
5126: if ($colsleft > 1) {
5127: $datatable .= '<td colspan="'.$colsleft.'">';
5128: } else {
5129: $datatable .= '<td>';
5130: }
5131: } else {
5132: $datatable .= '<td>';
5133: }
1.8 raeburn 5134: $datatable .= '<span class="LC_nobreak"><label>'.
5135: '<input type="checkbox" name="updateable_'.$type.
5136: '_'.$fields->[$i].'" value="1"'.$check.'/>'.
5137: $fieldtitles->{$fields->[$i]}.'</label></span></td>';
1.3 raeburn 5138: }
5139: $datatable .= '</tr></table></td></tr>';
5140: }
5141: }
5142: return $datatable;
1.1 raeburn 5143: }
5144:
5145: sub modify_login {
1.205 raeburn 5146: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.168 raeburn 5147: my ($resulttext,$errors,$colchgtext,%changes,%colchanges,%newfile,%newurl,
5148: %curr_loginvia,%loginhash,@currlangs,@newlangs,$addedfile,%title,@offon);
5149: %title = ( coursecatalog => 'Display course catalog',
5150: adminmail => 'Display administrator E-mail address',
1.188 raeburn 5151: helpdesk => 'Display "Contact Helpdesk" link',
1.168 raeburn 5152: newuser => 'Link for visitors to create a user account',
5153: loginheader => 'Log-in box header');
5154: @offon = ('off','on');
1.112 raeburn 5155: if (ref($domconfig{login}) eq 'HASH') {
5156: if (ref($domconfig{login}{loginvia}) eq 'HASH') {
5157: foreach my $lonhost (keys(%{$domconfig{login}{loginvia}})) {
5158: $curr_loginvia{$lonhost} = $domconfig{login}{loginvia}{$lonhost};
5159: }
5160: }
5161: }
1.9 raeburn 5162: ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
5163: \%domconfig,\%loginhash);
1.188 raeburn 5164: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 5165: foreach my $item (@toggles) {
5166: $loginhash{login}{$item} = $env{'form.'.$item};
5167: }
1.41 raeburn 5168: $loginhash{login}{loginheader} = $env{'form.loginheader'};
1.6 raeburn 5169: if (ref($colchanges{'login'}) eq 'HASH') {
5170: $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
5171: \%loginhash);
5172: }
1.110 raeburn 5173:
1.149 raeburn 5174: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.128 raeburn 5175: my @loginvia_attribs = ('serverpath','custompath','exempt');
1.110 raeburn 5176: if (keys(%servers) > 1) {
5177: foreach my $lonhost (keys(%servers)) {
1.128 raeburn 5178: next if ($env{'form.'.$lonhost.'_server'} eq $lonhost);
5179: if (ref($curr_loginvia{$lonhost}) eq 'HASH') {
5180: if ($env{'form.'.$lonhost.'_server'} eq $curr_loginvia{$lonhost}{'server'}) {
5181: $loginhash{login}{loginvia}{$lonhost}{'server'} = $curr_loginvia{$lonhost}{'server'};
5182: } elsif ($curr_loginvia{$lonhost}{'server'} ne '') {
5183: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
5184: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
5185: $changes{'loginvia'}{$lonhost} = 1;
5186: } else {
5187: $loginhash{login}{loginvia}{$lonhost}{'server'} = '';
5188: $changes{'loginvia'}{$lonhost} = 1;
5189: }
5190: } else {
5191: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
5192: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
5193: $changes{'loginvia'}{$lonhost} = 1;
5194: }
5195: }
5196: if ($loginhash{login}{loginvia}{$lonhost}{'server'} eq '') {
5197: foreach my $item (@loginvia_attribs) {
5198: $loginhash{login}{loginvia}{$lonhost}{$item} = '';
5199: }
5200: } else {
5201: foreach my $item (@loginvia_attribs) {
5202: my $new = $env{'form.'.$lonhost.'_'.$item};
5203: if (($item eq 'serverpath') && ($new eq 'custom')) {
5204: $env{'form.'.$lonhost.'_custompath'} =~ s/\s+//g;
5205: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
5206: $new = '/';
5207: }
5208: }
5209: if (($item eq 'custompath') &&
5210: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
5211: $new = '';
5212: }
5213: if ($new ne $curr_loginvia{$lonhost}{$item}) {
5214: $changes{'loginvia'}{$lonhost} = 1;
5215: }
5216: if ($item eq 'exempt') {
5217: $new =~ s/^\s+//;
5218: $new =~ s/\s+$//;
5219: my @poss_ips = split(/\s*[,:]\s*/,$new);
5220: my @okips;
5221: foreach my $ip (@poss_ips) {
5222: if ($ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
5223: if (($1 <= 255) && ($2 <= 255) && ($3 <= 255) && ($4 <= 255)) {
5224: push(@okips,$ip);
5225: }
5226: }
5227: }
5228: if (@okips > 0) {
5229: $new = join(',',@okips);
5230: } else {
5231: $new = '';
5232: }
5233: }
5234: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
5235: }
5236: }
1.112 raeburn 5237: } else {
1.128 raeburn 5238: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
5239: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
1.112 raeburn 5240: $changes{'loginvia'}{$lonhost} = 1;
1.128 raeburn 5241: foreach my $item (@loginvia_attribs) {
5242: my $new = $env{'form.'.$lonhost.'_'.$item};
5243: if (($item eq 'serverpath') && ($new eq 'custom')) {
5244: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
5245: $new = '/';
5246: }
5247: }
5248: if (($item eq 'custompath') &&
5249: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
5250: $new = '';
5251: }
5252: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
5253: }
1.110 raeburn 5254: }
5255: }
5256: }
5257: }
1.119 raeburn 5258:
1.168 raeburn 5259: my $servadm = $r->dir_config('lonAdmEMail');
5260: my %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
5261: if (ref($domconfig{'login'}) eq 'HASH') {
5262: if (ref($domconfig{'login'}{'helpurl'}) eq 'HASH') {
5263: foreach my $lang (sort(keys(%{$domconfig{'login'}{'helpurl'}}))) {
5264: if ($lang eq 'nolang') {
5265: push(@currlangs,$lang);
5266: } elsif (defined($langchoices{$lang})) {
5267: push(@currlangs,$lang);
5268: } else {
5269: next;
5270: }
5271: }
5272: }
5273: }
5274: my @delurls = &Apache::loncommon::get_env_multiple('form.loginhelpurl_del');
5275: if (@currlangs > 0) {
5276: foreach my $lang (@currlangs) {
5277: if (grep(/^\Q$lang\E$/,@delurls)) {
5278: $changes{'helpurl'}{$lang} = 1;
5279: } elsif ($env{'form.loginhelpurl_'.$lang.'.filename'}) {
5280: $changes{'helpurl'}{$lang} = 1;
5281: $newfile{$lang} = $env{'form.loginhelpurl_'.$lang.'.filename'};
5282: push(@newlangs,$lang);
5283: } else {
5284: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
5285: }
5286: }
5287: }
5288: unless (grep(/^nolang$/,@currlangs)) {
5289: if ($env{'form.loginhelpurl_nolang.filename'}) {
5290: $changes{'helpurl'}{'nolang'} = 1;
5291: $newfile{'nolang'} = $env{'form.loginhelpurl_nolang.filename'};
5292: push(@newlangs,'nolang');
5293: }
5294: }
5295: if ($env{'form.loginhelpurl_add_lang'}) {
5296: if ((defined($langchoices{$env{'form.loginhelpurl_add_lang'}})) &&
5297: ($env{'form.loginhelpurl_add_file.filename'})) {
5298: $newfile{$env{'form.loginhelpurl_add_lang'}} = $env{'form.loginhelpurl_add_file.filename'};
5299: $addedfile = $env{'form.loginhelpurl_add_lang'};
5300: }
5301: }
5302: if ((@newlangs > 0) || ($addedfile)) {
5303: my $error;
5304: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
5305: if ($configuserok eq 'ok') {
5306: if ($switchserver) {
5307: $error = &mt("Upload of custom help file is not permitted to this server: [_1]",$switchserver);
5308: } elsif ($author_ok eq 'ok') {
5309: my @allnew = @newlangs;
5310: if ($addedfile ne '') {
5311: push(@allnew,$addedfile);
5312: }
5313: foreach my $lang (@allnew) {
5314: my $formelem = 'loginhelpurl_'.$lang;
5315: if ($lang eq $env{'form.loginhelpurl_add_lang'}) {
5316: $formelem = 'loginhelpurl_add_file';
5317: }
5318: (my $result,$newurl{$lang}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
5319: "help/$lang",'','',$newfile{$lang});
5320: if ($result eq 'ok') {
5321: $loginhash{'login'}{'helpurl'}{$lang} = $newurl{$lang};
5322: $changes{'helpurl'}{$lang} = 1;
5323: } else {
5324: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$newfile{$lang},$result);
5325: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
1.210 raeburn 5326: if ((grep(/^\Q$lang\E$/,@currlangs)) &&
1.168 raeburn 5327: (!grep(/^\Q$lang\E$/,@delurls))) {
5328:
5329: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
5330: }
5331: }
5332: }
5333: } else {
5334: $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);
5335: }
5336: } else {
5337: $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);
5338: }
5339: if ($error) {
5340: &Apache::lonnet::logthis($error);
5341: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
5342: }
5343: }
1.169 raeburn 5344: &process_captcha('login',\%changes,$loginhash{'login'},$domconfig{'login'});
1.168 raeburn 5345:
5346: my $defaulthelpfile = '/adm/loginproblems.html';
5347: my $defaulttext = &mt('Default in use');
5348:
1.1 raeburn 5349: my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
5350: $dom);
5351: if ($putresult eq 'ok') {
1.188 raeburn 5352: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 5353: my %defaultchecked = (
5354: 'coursecatalog' => 'on',
1.188 raeburn 5355: 'helpdesk' => 'on',
1.42 raeburn 5356: 'adminmail' => 'off',
1.43 raeburn 5357: 'newuser' => 'off',
1.42 raeburn 5358: );
1.55 raeburn 5359: if (ref($domconfig{'login'}) eq 'HASH') {
5360: foreach my $item (@toggles) {
5361: if ($defaultchecked{$item} eq 'on') {
5362: if (($domconfig{'login'}{$item} eq '0') &&
5363: ($env{'form.'.$item} eq '1')) {
5364: $changes{$item} = 1;
5365: } elsif (($domconfig{'login'}{$item} eq '' ||
5366: $domconfig{'login'}{$item} eq '1') &&
5367: ($env{'form.'.$item} eq '0')) {
5368: $changes{$item} = 1;
5369: }
5370: } elsif ($defaultchecked{$item} eq 'off') {
5371: if (($domconfig{'login'}{$item} eq '1') &&
5372: ($env{'form.'.$item} eq '0')) {
5373: $changes{$item} = 1;
5374: } elsif (($domconfig{'login'}{$item} eq '' ||
5375: $domconfig{'login'}{$item} eq '0') &&
5376: ($env{'form.'.$item} eq '1')) {
5377: $changes{$item} = 1;
5378: }
1.42 raeburn 5379: }
5380: }
1.41 raeburn 5381: }
1.6 raeburn 5382: if (keys(%changes) > 0 || $colchgtext) {
1.41 raeburn 5383: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 5384: if (ref($lastactref) eq 'HASH') {
5385: $lastactref->{'domainconfig'} = 1;
5386: }
1.1 raeburn 5387: $resulttext = &mt('Changes made:').'<ul>';
5388: foreach my $item (sort(keys(%changes))) {
1.135 bisitz 5389: if ($item eq 'loginvia') {
1.112 raeburn 5390: if (ref($changes{$item}) eq 'HASH') {
5391: $resulttext .= '<li>'.&mt('Log-in page availability:').'<ul>';
5392: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
1.128 raeburn 5393: if (defined($servers{$loginhash{login}{loginvia}{$lonhost}{'server'}})) {
5394: if (ref($loginhash{login}{loginvia}{$lonhost}) eq 'HASH') {
5395: my $protocol = $Apache::lonnet::protocol{$env{'form.'.$lonhost.'_server'}};
5396: $protocol = 'http' if ($protocol ne 'https');
5397: my $target = $protocol.'://'.$servers{$env{'form.'.$lonhost.'_server'}};
5398:
5399: if ($loginhash{login}{loginvia}{$lonhost}{'serverpath'} eq 'custom') {
5400: $target .= $loginhash{login}{loginvia}{$lonhost}{'custompath'};
5401: } else {
5402: $target .= $loginhash{login}{loginvia}{$lonhost}{'serverpath'};
5403: }
5404: $resulttext .= '<li>'.&mt('Server: [_1] log-in page redirects to [_2].',$servers{$lonhost},'<a href="'.$target.'">'.$target.'</a>');
5405: if ($loginhash{login}{loginvia}{$lonhost}{'exempt'} ne '') {
5406: $resulttext .= ' '.&mt('No redirection for clients from following IPs:').' '.$loginhash{login}{loginvia}{$lonhost}{'exempt'};
5407: }
5408: $resulttext .= '</li>';
5409: } else {
5410: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$lonhost).'</li>';
5411: }
1.112 raeburn 5412: } else {
1.128 raeburn 5413: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$servers{$lonhost}).'</li>';
1.112 raeburn 5414: }
5415: }
1.128 raeburn 5416: $resulttext .= '</ul></li>';
1.112 raeburn 5417: }
1.168 raeburn 5418: } elsif ($item eq 'helpurl') {
5419: if (ref($changes{$item}) eq 'HASH') {
5420: foreach my $lang (sort(keys(%{$changes{$item}}))) {
5421: if (grep(/^\Q$lang\E$/,@delurls)) {
5422: my ($chg,$link);
5423: $link = &Apache::loncommon::modal_link($defaulthelpfile,$defaulttext,600,500);
5424: if ($lang eq 'nolang') {
5425: $chg = &mt('custom log-in help file removed for no preferred language; [_1]',$link);
5426: } else {
5427: $chg = &mt('custom log-in help file removed for specific language: [_1]; [_2]',$langchoices{$lang},$link);
5428: }
5429: $resulttext .= '<li>'.$chg.'</li>';
5430: } else {
5431: my $chg;
5432: if ($lang eq 'nolang') {
5433: $chg = &mt('custom log-in help file for no preferred language');
5434: } else {
5435: $chg = &mt('custom log-in help file for specific language: [_1]',$langchoices{$lang});
5436: }
5437: $resulttext .= '<li>'.&Apache::loncommon::modal_link(
5438: $loginhash{'login'}{'helpurl'}{$lang}.
5439: '?inhibitmenu=yes',$chg,600,500).
5440: '</li>';
5441: }
5442: }
5443: }
1.169 raeburn 5444: } elsif ($item eq 'captcha') {
5445: if (ref($loginhash{'login'}) eq 'HASH') {
1.210 raeburn 5446: my $chgtxt;
1.169 raeburn 5447: if ($loginhash{'login'}{$item} eq 'notused') {
5448: $chgtxt .= &mt('No CAPTCHA validation in use for helpdesk form.');
5449: } else {
5450: my %captchas = &captcha_phrases();
5451: if ($captchas{$loginhash{'login'}{$item}}) {
5452: $chgtxt .= &mt("Validation for helpdesk form set to $captchas{$loginhash{'login'}{$item}}.");
5453: } else {
5454: $chgtxt .= &mt('Validation for helpdesk form set to unknown type.');
5455: }
5456: }
5457: $resulttext .= '<li>'.$chgtxt.'</li>';
5458: }
5459: } elsif ($item eq 'recaptchakeys') {
5460: if (ref($loginhash{'login'}) eq 'HASH') {
5461: my ($privkey,$pubkey);
5462: if (ref($loginhash{'login'}{$item}) eq 'HASH') {
5463: $pubkey = $loginhash{'login'}{$item}{'public'};
5464: $privkey = $loginhash{'login'}{$item}{'private'};
5465: }
5466: my $chgtxt .= &mt('ReCAPTCHA keys changes').'<ul>';
5467: if (!$pubkey) {
5468: $chgtxt .= '<li>'.&mt('Public key deleted').'</li>';
5469: } else {
5470: $chgtxt .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
5471: }
5472: if (!$privkey) {
5473: $chgtxt .= '<li>'.&mt('Private key deleted').'</li>';
5474: } else {
5475: $chgtxt .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
5476: }
5477: $chgtxt .= '</ul>';
5478: $resulttext .= '<li>'.$chgtxt.'</li>';
5479: }
1.41 raeburn 5480: } else {
5481: $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
5482: }
1.1 raeburn 5483: }
1.6 raeburn 5484: $resulttext .= $colchgtext.'</ul>';
1.1 raeburn 5485: } else {
5486: $resulttext = &mt('No changes made to log-in page settings');
5487: }
5488: } else {
1.11 albertel 5489: $resulttext = '<span class="LC_error">'.
5490: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 5491: }
1.6 raeburn 5492: if ($errors) {
1.9 raeburn 5493: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.6 raeburn 5494: $errors.'</ul>';
5495: }
5496: return $resulttext;
5497: }
5498:
5499: sub color_font_choices {
5500: my %choices =
5501: &Apache::lonlocal::texthash (
5502: img => "Header",
5503: bgs => "Background colors",
5504: links => "Link colors",
1.55 raeburn 5505: images => "Images",
1.6 raeburn 5506: font => "Font color",
1.201 raeburn 5507: fontmenu => "Font menu",
1.76 raeburn 5508: pgbg => "Page",
1.6 raeburn 5509: tabbg => "Header",
5510: sidebg => "Border",
5511: link => "Link",
5512: alink => "Active link",
5513: vlink => "Visited link",
5514: );
5515: return %choices;
5516: }
5517:
5518: sub modify_rolecolors {
1.205 raeburn 5519: my ($r,$dom,$confname,$roles,$lastactref,%domconfig) = @_;
1.6 raeburn 5520: my ($resulttext,%rolehash);
5521: $rolehash{'rolecolors'} = {};
1.55 raeburn 5522: if (ref($domconfig{'rolecolors'}) ne 'HASH') {
5523: if ($domconfig{'rolecolors'} eq '') {
5524: $domconfig{'rolecolors'} = {};
5525: }
5526: }
1.9 raeburn 5527: my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
1.6 raeburn 5528: $domconfig{'rolecolors'},$rolehash{'rolecolors'});
5529: my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
5530: $dom);
5531: if ($putresult eq 'ok') {
5532: if (keys(%changes) > 0) {
1.41 raeburn 5533: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 5534: if (ref($lastactref) eq 'HASH') {
5535: $lastactref->{'domainconfig'} = 1;
5536: }
1.6 raeburn 5537: $resulttext = &display_colorchgs($dom,\%changes,$roles,
5538: $rolehash{'rolecolors'});
5539: } else {
5540: $resulttext = &mt('No changes made to default color schemes');
5541: }
5542: } else {
1.11 albertel 5543: $resulttext = '<span class="LC_error">'.
5544: &mt('An error occurred: [_1]',$putresult).'</span>';
1.6 raeburn 5545: }
5546: if ($errors) {
5547: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
5548: $errors.'</ul>';
5549: }
5550: return $resulttext;
5551: }
5552:
5553: sub modify_colors {
1.9 raeburn 5554: my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
1.12 raeburn 5555: my (%changes,%choices);
1.51 raeburn 5556: my @bgs;
1.6 raeburn 5557: my @links = ('link','alink','vlink');
1.41 raeburn 5558: my @logintext;
1.6 raeburn 5559: my @images;
5560: my $servadm = $r->dir_config('lonAdmEMail');
5561: my $errors;
1.200 raeburn 5562: my %defaults;
1.6 raeburn 5563: foreach my $role (@{$roles}) {
5564: if ($role eq 'login') {
1.12 raeburn 5565: %choices = &login_choices();
1.41 raeburn 5566: @logintext = ('textcol','bgcol');
1.12 raeburn 5567: } else {
5568: %choices = &color_font_choices();
5569: }
5570: if ($role eq 'login') {
1.41 raeburn 5571: @images = ('img','logo','domlogo','login');
1.51 raeburn 5572: @bgs = ('pgbg','mainbg','sidebg');
1.6 raeburn 5573: } else {
5574: @images = ('img');
1.200 raeburn 5575: @bgs = ('pgbg','tabbg','sidebg');
5576: }
5577: my %defaults = &role_defaults($role,\@bgs,\@links,\@images,\@logintext);
5578: unless ($env{'form.'.$role.'_font'} eq $defaults{'font'}) {
5579: $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
5580: }
5581: if ($role eq 'login') {
5582: foreach my $item (@logintext) {
5583: unless ($env{'form.'.$role.'_'.$item} eq $defaults{'logintext'}{$item}) {
5584: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
5585: }
5586: }
5587: } else {
5588: unless($env{'form.'.$role.'_fontmenu'} eq $defaults{'fontmenu'}) {
5589: $confhash->{$role}{'fontmenu'} = $env{'form.'.$role.'_fontmenu'};
5590: }
1.6 raeburn 5591: }
1.200 raeburn 5592: foreach my $item (@bgs) {
5593: unless ($env{'form.'.$role.'_'.$item} eq $defaults{'bgs'}{$item} ) {
5594: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
5595: }
5596: }
5597: foreach my $item (@links) {
5598: unless ($env{'form.'.$role.'_'.$item} eq $defaults{'links'}{$item}) {
5599: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
5600: }
1.6 raeburn 5601: }
1.46 raeburn 5602: my ($configuserok,$author_ok,$switchserver) =
5603: &config_check($dom,$confname,$servadm);
1.9 raeburn 5604: my ($width,$height) = &thumb_dimensions();
1.40 raeburn 5605: if (ref($domconfig->{$role}) ne 'HASH') {
5606: $domconfig->{$role} = {};
5607: }
1.8 raeburn 5608: foreach my $img (@images) {
1.70 raeburn 5609: if (($role eq 'login') && (($img eq 'img') || ($img eq 'logo'))) {
5610: if (defined($env{'form.login_showlogo_'.$img})) {
5611: $confhash->{$role}{'showlogo'}{$img} = 1;
5612: } else {
5613: $confhash->{$role}{'showlogo'}{$img} = 0;
5614: }
5615: }
1.18 albertel 5616: if ( ! $env{'form.'.$role.'_'.$img.'.filename'}
5617: && !defined($domconfig->{$role}{$img})
5618: && !$env{'form.'.$role.'_del_'.$img}
5619: && $env{'form.'.$role.'_import_'.$img}) {
5620: # import the old configured image from the .tab setting
5621: # if they haven't provided a new one
5622: $domconfig->{$role}{$img} =
5623: $env{'form.'.$role.'_import_'.$img};
5624: }
1.6 raeburn 5625: if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
1.9 raeburn 5626: my $error;
1.6 raeburn 5627: if ($configuserok eq 'ok') {
1.9 raeburn 5628: if ($switchserver) {
1.12 raeburn 5629: $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
1.9 raeburn 5630: } else {
5631: if ($author_ok eq 'ok') {
5632: my ($result,$logourl) =
5633: &publishlogo($r,'upload',$role.'_'.$img,
5634: $dom,$confname,$img,$width,$height);
5635: if ($result eq 'ok') {
5636: $confhash->{$role}{$img} = $logourl;
1.12 raeburn 5637: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 5638: } else {
1.12 raeburn 5639: $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 5640: }
5641: } else {
1.46 raeburn 5642: $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 5643: }
5644: }
5645: } else {
1.46 raeburn 5646: $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 5647: }
5648: if ($error) {
1.8 raeburn 5649: &Apache::lonnet::logthis($error);
1.11 albertel 5650: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
1.8 raeburn 5651: }
5652: } elsif ($domconfig->{$role}{$img} ne '') {
1.9 raeburn 5653: if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
5654: my $error;
5655: if ($configuserok eq 'ok') {
5656: # is confname an author?
5657: if ($switchserver eq '') {
5658: if ($author_ok eq 'ok') {
5659: my ($result,$logourl) =
5660: &publishlogo($r,'copy',$domconfig->{$role}{$img},
5661: $dom,$confname,$img,$width,$height);
5662: if ($result eq 'ok') {
5663: $confhash->{$role}{$img} = $logourl;
1.18 albertel 5664: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 5665: }
5666: }
5667: }
5668: }
1.6 raeburn 5669: }
5670: }
5671: }
5672: if (ref($domconfig) eq 'HASH') {
5673: if (ref($domconfig->{$role}) eq 'HASH') {
5674: foreach my $img (@images) {
5675: if ($domconfig->{$role}{$img} ne '') {
5676: if ($env{'form.'.$role.'_del_'.$img}) {
5677: $confhash->{$role}{$img} = '';
1.12 raeburn 5678: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 5679: } else {
1.9 raeburn 5680: if ($confhash->{$role}{$img} eq '') {
5681: $confhash->{$role}{$img} = $domconfig->{$role}{$img};
5682: }
1.6 raeburn 5683: }
5684: } else {
5685: if ($env{'form.'.$role.'_del_'.$img}) {
5686: $confhash->{$role}{$img} = '';
1.12 raeburn 5687: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 5688: }
5689: }
1.70 raeburn 5690: if (($role eq 'login') && (($img eq 'logo') || ($img eq 'img'))) {
5691: if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') {
5692: if ($confhash->{$role}{'showlogo'}{$img} ne
5693: $domconfig->{$role}{'showlogo'}{$img}) {
5694: $changes{$role}{'showlogo'}{$img} = 1;
5695: }
5696: } else {
5697: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
5698: $changes{$role}{'showlogo'}{$img} = 1;
5699: }
5700: }
5701: }
5702: }
1.6 raeburn 5703: if ($domconfig->{$role}{'font'} ne '') {
5704: if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
5705: $changes{$role}{'font'} = 1;
5706: }
5707: } else {
5708: if ($confhash->{$role}{'font'}) {
5709: $changes{$role}{'font'} = 1;
5710: }
5711: }
1.107 raeburn 5712: if ($role ne 'login') {
5713: if ($domconfig->{$role}{'fontmenu'} ne '') {
5714: if ($confhash->{$role}{'fontmenu'} ne $domconfig->{$role}{'fontmenu'}) {
5715: $changes{$role}{'fontmenu'} = 1;
5716: }
5717: } else {
5718: if ($confhash->{$role}{'fontmenu'}) {
5719: $changes{$role}{'fontmenu'} = 1;
5720: }
1.97 tempelho 5721: }
5722: }
1.6 raeburn 5723: foreach my $item (@bgs) {
5724: if ($domconfig->{$role}{$item} ne '') {
5725: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
5726: $changes{$role}{'bgs'}{$item} = 1;
5727: }
5728: } else {
5729: if ($confhash->{$role}{$item}) {
5730: $changes{$role}{'bgs'}{$item} = 1;
5731: }
5732: }
5733: }
5734: foreach my $item (@links) {
5735: if ($domconfig->{$role}{$item} ne '') {
5736: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
5737: $changes{$role}{'links'}{$item} = 1;
5738: }
5739: } else {
5740: if ($confhash->{$role}{$item}) {
5741: $changes{$role}{'links'}{$item} = 1;
5742: }
5743: }
5744: }
1.41 raeburn 5745: foreach my $item (@logintext) {
5746: if ($domconfig->{$role}{$item} ne '') {
5747: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
5748: $changes{$role}{'logintext'}{$item} = 1;
5749: }
5750: } else {
5751: if ($confhash->{$role}{$item}) {
5752: $changes{$role}{'logintext'}{$item} = 1;
5753: }
5754: }
5755: }
1.6 raeburn 5756: } else {
5757: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 5758: \@logintext,$confhash,\%changes);
1.6 raeburn 5759: }
5760: } else {
5761: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 5762: \@logintext,$confhash,\%changes);
1.6 raeburn 5763: }
5764: }
5765: return ($errors,%changes);
5766: }
5767:
1.46 raeburn 5768: sub config_check {
5769: my ($dom,$confname,$servadm) = @_;
5770: my ($configuserok,$author_ok,$switchserver,%currroles);
5771: my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
5772: ($configuserok,%currroles) = &check_configuser($uhome,$dom,
5773: $confname,$servadm);
5774: if ($configuserok eq 'ok') {
5775: $switchserver = &check_switchserver($dom,$confname);
5776: if ($switchserver eq '') {
5777: $author_ok = &check_authorstatus($dom,$confname,%currroles);
5778: }
5779: }
5780: return ($configuserok,$author_ok,$switchserver);
5781: }
5782:
1.6 raeburn 5783: sub default_change_checker {
1.41 raeburn 5784: my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
1.6 raeburn 5785: foreach my $item (@{$links}) {
5786: if ($confhash->{$role}{$item}) {
5787: $changes->{$role}{'links'}{$item} = 1;
5788: }
5789: }
5790: foreach my $item (@{$bgs}) {
5791: if ($confhash->{$role}{$item}) {
5792: $changes->{$role}{'bgs'}{$item} = 1;
5793: }
5794: }
1.41 raeburn 5795: foreach my $item (@{$logintext}) {
5796: if ($confhash->{$role}{$item}) {
5797: $changes->{$role}{'logintext'}{$item} = 1;
5798: }
5799: }
1.6 raeburn 5800: foreach my $img (@{$images}) {
5801: if ($env{'form.'.$role.'_del_'.$img}) {
5802: $confhash->{$role}{$img} = '';
1.12 raeburn 5803: $changes->{$role}{'images'}{$img} = 1;
1.6 raeburn 5804: }
1.70 raeburn 5805: if ($role eq 'login') {
5806: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
5807: $changes->{$role}{'showlogo'}{$img} = 1;
5808: }
5809: }
1.6 raeburn 5810: }
5811: if ($confhash->{$role}{'font'}) {
5812: $changes->{$role}{'font'} = 1;
5813: }
1.48 raeburn 5814: }
1.6 raeburn 5815:
5816: sub display_colorchgs {
5817: my ($dom,$changes,$roles,$confhash) = @_;
5818: my (%choices,$resulttext);
5819: if (!grep(/^login$/,@{$roles})) {
5820: $resulttext = &mt('Changes made:').'<br />';
5821: }
5822: foreach my $role (@{$roles}) {
5823: if ($role eq 'login') {
5824: %choices = &login_choices();
5825: } else {
5826: %choices = &color_font_choices();
5827: }
5828: if (ref($changes->{$role}) eq 'HASH') {
5829: if ($role ne 'login') {
5830: $resulttext .= '<h4>'.&mt($role).'</h4>';
5831: }
5832: foreach my $key (sort(keys(%{$changes->{$role}}))) {
5833: if ($role ne 'login') {
5834: $resulttext .= '<ul>';
5835: }
5836: if (ref($changes->{$role}{$key}) eq 'HASH') {
5837: if ($role ne 'login') {
5838: $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
5839: }
5840: foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
1.70 raeburn 5841: if (($role eq 'login') && ($key eq 'showlogo')) {
5842: if ($confhash->{$role}{$key}{$item}) {
5843: $resulttext .= '<li>'.&mt("$choices{$item} set to be displayed").'</li>';
5844: } else {
5845: $resulttext .= '<li>'.&mt("$choices{$item} set to not be displayed").'</li>';
5846: }
5847: } elsif ($confhash->{$role}{$item} eq '') {
1.6 raeburn 5848: $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
5849: } else {
1.12 raeburn 5850: my $newitem = $confhash->{$role}{$item};
5851: if ($key eq 'images') {
5852: $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" valign="bottom" />';
5853: }
5854: $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
1.6 raeburn 5855: }
5856: }
5857: if ($role ne 'login') {
5858: $resulttext .= '</ul></li>';
5859: }
5860: } else {
5861: if ($confhash->{$role}{$key} eq '') {
5862: $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
5863: } else {
5864: $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
5865: }
5866: }
5867: if ($role ne 'login') {
5868: $resulttext .= '</ul>';
5869: }
5870: }
5871: }
5872: }
1.3 raeburn 5873: return $resulttext;
1.1 raeburn 5874: }
5875:
1.9 raeburn 5876: sub thumb_dimensions {
5877: return ('200','50');
5878: }
5879:
1.16 raeburn 5880: sub check_dimensions {
5881: my ($inputfile) = @_;
5882: my ($fullwidth,$fullheight);
5883: if ($inputfile =~ m|^[/\w.\-]+$|) {
5884: if (open(PIPE,"identify $inputfile 2>&1 |")) {
5885: my $imageinfo = <PIPE>;
5886: if (!close(PIPE)) {
5887: &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
5888: }
5889: chomp($imageinfo);
5890: my ($fullsize) =
1.21 raeburn 5891: ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
1.16 raeburn 5892: if ($fullsize) {
5893: ($fullwidth,$fullheight) = split(/x/,$fullsize);
5894: }
5895: }
5896: }
5897: return ($fullwidth,$fullheight);
5898: }
5899:
1.9 raeburn 5900: sub check_configuser {
5901: my ($uhome,$dom,$confname,$servadm) = @_;
5902: my ($configuserok,%currroles);
5903: if ($uhome eq 'no_host') {
5904: srand( time() ^ ($$ + ($$ << 15)) ); # Seed rand.
5905: my $configpass = &LONCAPA::Enrollment::create_password();
5906: $configuserok =
5907: &Apache::lonnet::modifyuser($dom,$confname,'','internal',
5908: $configpass,'','','','','',undef,$servadm);
5909: } else {
5910: $configuserok = 'ok';
5911: %currroles =
5912: &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
5913: }
5914: return ($configuserok,%currroles);
5915: }
5916:
5917: sub check_authorstatus {
5918: my ($dom,$confname,%currroles) = @_;
5919: my $author_ok;
1.40 raeburn 5920: if (!$currroles{':'.$dom.':au'}) {
1.9 raeburn 5921: my $start = time;
5922: my $end = 0;
5923: $author_ok =
5924: &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
1.47 raeburn 5925: 'au',$end,$start,'','','domconfig');
1.9 raeburn 5926: } else {
5927: $author_ok = 'ok';
5928: }
5929: return $author_ok;
5930: }
5931:
5932: sub publishlogo {
1.46 raeburn 5933: my ($r,$action,$formname,$dom,$confname,$subdir,$thumbwidth,$thumbheight,$savefileas) = @_;
1.9 raeburn 5934: my ($output,$fname,$logourl);
5935: if ($action eq 'upload') {
5936: $fname=$env{'form.'.$formname.'.filename'};
5937: chop($env{'form.'.$formname});
5938: } else {
5939: ($fname) = ($formname =~ /([^\/]+)$/);
5940: }
1.46 raeburn 5941: if ($savefileas ne '') {
5942: $fname = $savefileas;
5943: }
1.9 raeburn 5944: $fname=&Apache::lonnet::clean_filename($fname);
5945: # See if there is anything left
5946: unless ($fname) { return ('error: no uploaded file'); }
5947: $fname="$subdir/$fname";
1.210 raeburn 5948: my $docroot=$r->dir_config('lonDocRoot');
1.164 raeburn 5949: my $filepath="$docroot/priv";
5950: my $relpath = "$dom/$confname";
1.9 raeburn 5951: my ($fnamepath,$file,$fetchthumb);
5952: $file=$fname;
5953: if ($fname=~m|/|) {
5954: ($fnamepath,$file) = ($fname =~ m|^(.*)/([^/]+)$|);
5955: }
1.164 raeburn 5956: my @parts=split(/\//,"$filepath/$relpath/$fnamepath");
1.9 raeburn 5957: my $count;
1.164 raeburn 5958: for ($count=5;$count<=$#parts;$count++) {
1.9 raeburn 5959: $filepath.="/$parts[$count]";
5960: if ((-e $filepath)!=1) {
5961: mkdir($filepath,02770);
5962: }
5963: }
5964: # Check for bad extension and disallow upload
5965: if ($file=~/\.(\w+)$/ &&
5966: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
5967: $output =
1.207 bisitz 5968: &mt('Invalid file extension ([_1]) - reserved for internal use.',$1);
1.9 raeburn 5969: } elsif ($file=~/\.(\w+)$/ &&
5970: !defined(&Apache::loncommon::fileembstyle($1))) {
5971: $output = &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
5972: } elsif ($file=~/\.(\d+)\.(\w+)$/) {
1.195 bisitz 5973: $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 5974: } elsif (-d "$filepath/$file") {
1.195 bisitz 5975: $output = &mt('Filename is a directory name - rename the file and re-upload');
1.9 raeburn 5976: } else {
5977: my $source = $filepath.'/'.$file;
5978: my $logfile;
5979: if (!open($logfile,">>$source".'.log')) {
1.196 raeburn 5980: return (&mt('No write permission to Authoring Space'));
1.9 raeburn 5981: }
5982: print $logfile
5983: "\n================= Publish ".localtime()." ================\n".
5984: $env{'user.name'}.':'.$env{'user.domain'}."\n";
5985: # Save the file
5986: if (!open(FH,'>'.$source)) {
5987: &Apache::lonnet::logthis('Failed to create '.$source);
5988: return (&mt('Failed to create file'));
5989: }
5990: if ($action eq 'upload') {
5991: if (!print FH ($env{'form.'.$formname})) {
5992: &Apache::lonnet::logthis('Failed to write to '.$source);
5993: return (&mt('Failed to write file'));
5994: }
5995: } else {
5996: my $original = &Apache::lonnet::filelocation('',$formname);
5997: if(!copy($original,$source)) {
5998: &Apache::lonnet::logthis('Failed to copy '.$original.' to '.$source);
5999: return (&mt('Failed to write file'));
6000: }
6001: }
6002: close(FH);
6003: chmod(0660, $source); # Permissions to rw-rw---.
6004:
6005: my $targetdir=$docroot.'/res/'.$dom.'/'.$confname .'/'.$fnamepath;
6006: my $copyfile=$targetdir.'/'.$file;
6007:
6008: my @parts=split(/\//,$targetdir);
6009: my $path="/$parts[1]/$parts[2]/$parts[3]/$parts[4]";
6010: for (my $count=5;$count<=$#parts;$count++) {
6011: $path.="/$parts[$count]";
6012: if (!-e $path) {
6013: print $logfile "\nCreating directory ".$path;
6014: mkdir($path,02770);
6015: }
6016: }
6017: my $versionresult;
6018: if (-e $copyfile) {
6019: $versionresult = &logo_versioning($targetdir,$file,$logfile);
6020: } else {
6021: $versionresult = 'ok';
6022: }
6023: if ($versionresult eq 'ok') {
6024: if (copy($source,$copyfile)) {
6025: print $logfile "\nCopied original source to ".$copyfile."\n";
6026: $output = 'ok';
6027: $logourl = '/res/'.$dom.'/'.$confname.'/'.$fname;
1.155 raeburn 6028: push(@{$modified_urls},[$copyfile,$source]);
6029: my $metaoutput =
6030: &write_metadata($dom,$confname,$formname,$targetdir,$file,$logfile);
6031: unless ($registered_cleanup) {
6032: my $handlers = $r->get_handlers('PerlCleanupHandler');
6033: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
6034: $registered_cleanup=1;
6035: }
1.9 raeburn 6036: } else {
6037: print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";
6038: $output = &mt('Failed to copy file to RES space').", $!";
6039: }
6040: if (($thumbwidth =~ /^\d+$/) && ($thumbheight =~ /^\d+$/)) {
6041: my $inputfile = $filepath.'/'.$file;
6042: my $outfile = $filepath.'/'.'tn-'.$file;
1.16 raeburn 6043: my ($fullwidth,$fullheight) = &check_dimensions($inputfile);
6044: if ($fullwidth ne '' && $fullheight ne '') {
6045: if ($fullwidth > $thumbwidth && $fullheight > $thumbheight) {
6046: my $thumbsize = $thumbwidth.'x'.$thumbheight;
6047: system("convert -sample $thumbsize $inputfile $outfile");
6048: chmod(0660, $filepath.'/tn-'.$file);
6049: if (-e $outfile) {
6050: my $copyfile=$targetdir.'/tn-'.$file;
6051: if (copy($outfile,$copyfile)) {
6052: print $logfile "\nCopied source to ".$copyfile."\n";
1.155 raeburn 6053: my $thumb_metaoutput =
6054: &write_metadata($dom,$confname,$formname,
6055: $targetdir,'tn-'.$file,$logfile);
6056: push(@{$modified_urls},[$copyfile,$outfile]);
6057: unless ($registered_cleanup) {
6058: my $handlers = $r->get_handlers('PerlCleanupHandler');
6059: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
6060: $registered_cleanup=1;
6061: }
1.16 raeburn 6062: } else {
6063: print $logfile "\nUnable to write ".$copyfile.
6064: ':'.$!."\n";
6065: }
6066: }
1.9 raeburn 6067: }
6068: }
6069: }
6070: } else {
6071: $output = $versionresult;
6072: }
6073: }
6074: return ($output,$logourl);
6075: }
6076:
6077: sub logo_versioning {
6078: my ($targetdir,$file,$logfile) = @_;
6079: my $target = $targetdir.'/'.$file;
6080: my ($maxversion,$fn,$extn,$output);
6081: $maxversion = 0;
6082: if ($file =~ /^(.+)\.(\w+)$/) {
6083: $fn=$1;
6084: $extn=$2;
6085: }
6086: opendir(DIR,$targetdir);
6087: while (my $filename=readdir(DIR)) {
6088: if ($filename=~/\Q$fn\E\.(\d+)\.\Q$extn\E$/) {
6089: $maxversion=($1>$maxversion)?$1:$maxversion;
6090: }
6091: }
6092: $maxversion++;
6093: print $logfile "\nCreating old version ".$maxversion."\n";
6094: my $copyfile=$targetdir.'/'.$fn.'.'.$maxversion.'.'.$extn;
6095: if (copy($target,$copyfile)) {
6096: print $logfile "Copied old target to ".$copyfile."\n";
6097: $copyfile=$copyfile.'.meta';
6098: if (copy($target.'.meta',$copyfile)) {
6099: print $logfile "Copied old target metadata to ".$copyfile."\n";
6100: $output = 'ok';
6101: } else {
6102: print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";
6103: $output = &mt('Failed to copy old meta').", $!, ";
6104: }
6105: } else {
6106: print $logfile "Unable to write ".$copyfile.':'.$!."\n";
6107: $output = &mt('Failed to copy old target').", $!, ";
6108: }
6109: return $output;
6110: }
6111:
6112: sub write_metadata {
6113: my ($dom,$confname,$formname,$targetdir,$file,$logfile) = @_;
6114: my (%metadatafields,%metadatakeys,$output);
6115: $metadatafields{'title'}=$formname;
6116: $metadatafields{'creationdate'}=time;
6117: $metadatafields{'lastrevisiondate'}=time;
6118: $metadatafields{'copyright'}='public';
6119: $metadatafields{'modifyinguser'}=$env{'user.name'}.':'.
6120: $env{'user.domain'};
6121: $metadatafields{'authorspace'}=$confname.':'.$dom;
6122: $metadatafields{'domain'}=$dom;
6123: {
6124: print $logfile "\nWrite metadata file for ".$targetdir.'/'.$file;
6125: my $mfh;
1.155 raeburn 6126: if (open($mfh,'>'.$targetdir.'/'.$file.'.meta')) {
1.184 raeburn 6127: foreach (sort(keys(%metadatafields))) {
1.155 raeburn 6128: unless ($_=~/\./) {
6129: my $unikey=$_;
6130: $unikey=~/^([A-Za-z]+)/;
6131: my $tag=$1;
6132: $tag=~tr/A-Z/a-z/;
6133: print $mfh "\n\<$tag";
6134: foreach (split(/\,/,$metadatakeys{$unikey})) {
6135: my $value=$metadatafields{$unikey.'.'.$_};
6136: $value=~s/\"/\'\'/g;
6137: print $mfh ' '.$_.'="'.$value.'"';
6138: }
6139: print $mfh '>'.
6140: &HTML::Entities::encode($metadatafields{$unikey},'<>&"')
6141: .'</'.$tag.'>';
6142: }
6143: }
6144: $output = 'ok';
6145: print $logfile "\nWrote metadata";
6146: close($mfh);
6147: } else {
6148: print $logfile "\nFailed to open metadata file";
1.9 raeburn 6149: $output = &mt('Could not write metadata');
6150: }
6151: }
1.155 raeburn 6152: return $output;
6153: }
6154:
6155: sub notifysubscribed {
6156: foreach my $targetsource (@{$modified_urls}){
6157: next unless (ref($targetsource) eq 'ARRAY');
6158: my ($target,$source)=@{$targetsource};
6159: if ($source ne '') {
6160: if (open(my $logfh,'>>'.$source.'.log')) {
6161: print $logfh "\nCleanup phase: Notifications\n";
6162: my @subscribed=&subscribed_hosts($target);
6163: foreach my $subhost (@subscribed) {
6164: print $logfh "\nNotifying host ".$subhost.':';
6165: my $reply=&Apache::lonnet::critical('update:'.$target,$subhost);
6166: print $logfh $reply;
6167: }
6168: my @subscribedmeta=&subscribed_hosts("$target.meta");
6169: foreach my $subhost (@subscribedmeta) {
6170: print $logfh "\nNotifying host for metadata only ".$subhost.':';
6171: my $reply=&Apache::lonnet::critical('update:'.$target.'.meta',
6172: $subhost);
6173: print $logfh $reply;
6174: }
6175: print $logfh "\n============ Done ============\n";
1.160 raeburn 6176: close($logfh);
1.155 raeburn 6177: }
6178: }
6179: }
6180: return OK;
6181: }
6182:
6183: sub subscribed_hosts {
6184: my ($target) = @_;
6185: my @subscribed;
6186: if (open(my $fh,"<$target.subscription")) {
6187: while (my $subline=<$fh>) {
6188: if ($subline =~ /^($match_lonid):/) {
6189: my $host = $1;
6190: if ($host ne $Apache::lonnet::perlvar{'lonHostID'}) {
6191: unless (grep(/^\Q$host\E$/,@subscribed)) {
6192: push(@subscribed,$host);
6193: }
6194: }
6195: }
6196: }
6197: }
6198: return @subscribed;
1.9 raeburn 6199: }
6200:
6201: sub check_switchserver {
6202: my ($dom,$confname) = @_;
6203: my ($allowed,$switchserver);
6204: my $home = &Apache::lonnet::homeserver($confname,$dom);
6205: if ($home eq 'no_host') {
6206: $home = &Apache::lonnet::domain($dom,'primary');
6207: }
6208: my @ids=&Apache::lonnet::current_machine_ids();
1.10 albertel 6209: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
6210: if (!$allowed) {
1.180 raeburn 6211: $switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role=dc./'.$dom.'/&destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
1.9 raeburn 6212: }
6213: return $switchserver;
6214: }
6215:
1.1 raeburn 6216: sub modify_quotas {
1.216 raeburn 6217: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
1.101 raeburn 6218: my ($context,@usertools,@options,%validations,%titles,%confhash,%toolshash,
1.216 raeburn 6219: %limithash,$toolregexp,%conditions,$resulttext,%changes,$confname,$configuserok,
6220: $author_ok,$switchserver,$errors);
1.86 raeburn 6221: if ($action eq 'quotas') {
6222: $context = 'tools';
1.163 raeburn 6223: } else {
1.86 raeburn 6224: $context = $action;
6225: }
6226: if ($context eq 'requestcourses') {
1.216 raeburn 6227: @usertools = ('official','unofficial','community','textbook');
1.106 raeburn 6228: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 6229: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
6230: %titles = &courserequest_titles();
6231: $toolregexp = join('|',@usertools);
6232: %conditions = &courserequest_conditions();
1.216 raeburn 6233: $confname = $dom.'-domainconfig';
6234: my $servadm = $r->dir_config('lonAdmEMail');
6235: ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
1.163 raeburn 6236: } elsif ($context eq 'requestauthor') {
6237: @usertools = ('author');
6238: %titles = &authorrequest_titles();
1.86 raeburn 6239: } else {
1.162 raeburn 6240: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 6241: %titles = &tool_titles();
1.86 raeburn 6242: }
1.212 raeburn 6243: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.44 raeburn 6244: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 6245: foreach my $key (keys(%env)) {
1.101 raeburn 6246: if ($context eq 'requestcourses') {
6247: if ($key =~ /^form\.crsreq_($toolregexp)_(.+)$/) {
6248: my $item = $1;
6249: my $type = $2;
6250: if ($type =~ /^limit_(.+)/) {
6251: $limithash{$item}{$1} = $env{$key};
6252: } else {
6253: $confhash{$item}{$type} = $env{$key};
6254: }
6255: }
1.163 raeburn 6256: } elsif ($context eq 'requestauthor') {
6257: if ($key =~ /^\Qform.authorreq_\E(.+)$/) {
6258: $confhash{$1} = $env{$key};
6259: }
1.101 raeburn 6260: } else {
1.86 raeburn 6261: if ($key =~ /^form\.quota_(.+)$/) {
6262: $confhash{'defaultquota'}{$1} = $env{$key};
1.197 raeburn 6263: } elsif ($key =~ /^form\.authorquota_(.+)$/) {
6264: $confhash{'authorquota'}{$1} = $env{$key};
6265: } elsif ($key =~ /^form\.\Q$context\E_(.+)$/) {
1.101 raeburn 6266: @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key);
6267: }
1.72 raeburn 6268: }
6269: }
1.163 raeburn 6270: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.224 raeburn 6271: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.'.$context.'notifyapproval');
1.102 raeburn 6272: @approvalnotify = sort(@approvalnotify);
6273: $confhash{'notify'}{'approval'} = join(',',@approvalnotify);
1.218 raeburn 6274: my @crstypes = ('official','unofficial','community','textbook');
6275: my @hasuniquecode = &Apache::loncommon::get_env_multiple('form.uniquecode');
6276: foreach my $type (@hasuniquecode) {
6277: if (grep(/^\Q$type\E$/,@crstypes)) {
6278: $confhash{'uniquecode'}{$type} = 1;
6279: }
1.216 raeburn 6280: }
6281: my ($newbook,@allpos);
6282: if ($context eq 'requestcourses') {
6283: if ($env{'form.addbook'}) {
6284: if (($env{'form.addbook_cnum'} =~ /^$match_courseid$/) &&
6285: ($env{'form.addbook_cdom'} =~ /^$match_domain$/)) {
6286: if (&Apache::lonnet::homeserver($env{'form.addbook_cnum'},
6287: $env{'form.addbook_cdom'}) eq 'no_host') {
6288: $errors .= '<li><span class="LC_error">'.&mt('Invalid LON-CAPA course for textbook').
6289: '</span></li>';
6290: } else {
6291: $newbook = $env{'form.addbook_cdom'}.'_'.$env{'form.addbook_cnum'};
6292: my $position = $env{'form.addbook_pos'};
6293: $position =~ s/\D+//g;
6294: if ($position ne '') {
6295: $allpos[$position] = $newbook;
6296: }
6297: }
6298: } else {
6299: $errors .= '<li><span class="LC_error">'.&mt('Invalid LON-CAPA course for textbook').
6300: '</span></li>';
6301: }
6302: }
6303: }
1.102 raeburn 6304: if (ref($domconfig{$action}) eq 'HASH') {
6305: if (ref($domconfig{$action}{'notify'}) eq 'HASH') {
6306: if ($domconfig{$action}{'notify'}{'approval'} ne $confhash{'notify'}{'approval'}) {
6307: $changes{'notify'}{'approval'} = 1;
6308: }
6309: } else {
1.144 raeburn 6310: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 6311: $changes{'notify'}{'approval'} = 1;
6312: }
6313: }
1.218 raeburn 6314: if (ref($domconfig{$action}{'uniquecode'}) eq 'HASH') {
6315: if (ref($confhash{'uniquecode'}) eq 'HASH') {
6316: foreach my $crstype (keys(%{$domconfig{$action}{'uniquecode'}})) {
6317: unless ($confhash{'uniquecode'}{$crstype}) {
6318: $changes{'uniquecode'} = 1;
6319: }
6320: }
6321: unless ($changes{'uniquecode'}) {
6322: foreach my $crstype (keys(%{$confhash{'uniquecode'}})) {
6323: unless ($domconfig{$action}{'uniquecode'}{$crstype}) {
6324: $changes{'uniquecode'} = 1;
6325: }
6326: }
6327: }
6328: } else {
6329: $changes{'uniquecode'} = 1;
6330: }
6331: } elsif (ref($confhash{'uniquecode'}) eq 'HASH') {
6332: $changes{'uniquecode'} = 1;
1.216 raeburn 6333: }
6334: if ($context eq 'requestcourses') {
6335: if (ref($domconfig{$action}{'textbooks'}) eq 'HASH') {
6336: my %deletions;
6337: my @todelete = &Apache::loncommon::get_env_multiple('form.book_del');
6338: if (@todelete) {
6339: map { $deletions{$_} = 1; } @todelete;
6340: }
6341: my %imgdeletions;
6342: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.book_image_del');
6343: if (@todeleteimages) {
6344: map { $imgdeletions{$_} = 1; } @todeleteimages;
6345: }
6346: my $maxnum = $env{'form.book_maxnum'};
6347: for (my $i=0; $i<=$maxnum; $i++) {
6348: my $key = $env{'form.book_id_'.$i};
6349: if (ref($domconfig{$action}{'textbooks'}{$key}) eq 'HASH') {
6350: if ($deletions{$key}) {
6351: if ($domconfig{$action}{'textbooks'}{$key}{'image'}) {
6352: #FIXME need to obsolete item in RES space
6353: }
6354: next;
6355: } else {
6356: my $newpos = $env{'form.'.$key};
6357: $newpos =~ s/\D+//g;
6358: foreach my $item ('subject','title','author') {
6359: $confhash{'textbooks'}{$key}{$item} = $env{'form.book_'.$item.'_'.$i};
6360: if ($domconfig{$action}{'textbooks'}{$key}{$item} ne $confhash{'textbooks'}{$key}{$item}) {
6361: $changes{'textbooks'}{$key} = 1;
6362: }
6363: }
6364: $allpos[$newpos] = $key;
6365: }
6366: if ($imgdeletions{$key}) {
6367: $changes{'textbooks'}{$key} = 1;
6368: #FIXME need to obsolete item in RES space
6369: } elsif ($env{'form.book_image_'.$i.'.filename'}) {
6370: my ($cdom,$cnum) = split(/_/,$key);
6371: my ($imgurl,$error) = &process_textbook_image($r,$dom,$confname,'book_image_'.$i,
6372: $cdom,$cnum,$configuserok,
6373: $switchserver,$author_ok);
6374: if ($imgurl) {
6375: $confhash{'textbooks'}{$key}{'image'} = $imgurl;
6376: $changes{'textbooks'}{$key} = 1;
6377: }
6378: if ($error) {
6379: &Apache::lonnet::logthis($error);
6380: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
6381: }
6382: } elsif ($domconfig{$action}{'textbooks'}{$key}{'image'}) {
6383: $confhash{'textbooks'}{$key}{'image'} =
6384: $domconfig{$action}{'textbooks'}{$key}{'image'};
6385: }
6386: }
6387: }
6388: }
6389: }
1.102 raeburn 6390: } else {
1.144 raeburn 6391: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 6392: $changes{'notify'}{'approval'} = 1;
6393: }
1.218 raeburn 6394: if (ref($confhash{'uniquecode'} eq 'HASH')) {
1.216 raeburn 6395: $changes{'uniquecode'} = 1;
6396: }
6397: }
6398: if ($context eq 'requestcourses') {
6399: if ($newbook) {
6400: $changes{'textbooks'}{$newbook} = 1;
6401: foreach my $item ('subject','title','author') {
6402: $env{'form.addbook_'.$item} =~ s/(`)/'/g;
6403: if ($env{'form.addbook_'.$item}) {
6404: $confhash{'textbooks'}{$newbook}{$item} = $env{'form.addbook_'.$item};
6405: }
6406: }
6407: if ($env{'form.addbook_image.filename'} ne '') {
6408: my ($cdom,$cnum) = split(/_/,$newbook);
6409: my ($imageurl,$error) =
6410: &process_textbook_image($r,$dom,$confname,'addbook_image',$cdom,$cnum,$configuserok,
6411: $switchserver,$author_ok);
6412: if ($imageurl) {
6413: $confhash{'textbooks'}{$newbook}{'image'} = $imageurl;
6414: }
6415: if ($error) {
6416: &Apache::lonnet::logthis($error);
6417: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
6418: }
6419: }
6420: }
6421: if (@allpos > 0) {
6422: my $idx = 0;
6423: foreach my $item (@allpos) {
6424: if ($item ne '') {
6425: $confhash{'textbooks'}{$item}{'order'} = $idx;
6426: if (ref($domconfig{$action}) eq 'HASH') {
6427: if (ref($domconfig{$action}{'textbooks'}) eq 'HASH') {
6428: if (ref($domconfig{$action}{'textbooks'}{$item}) eq 'HASH') {
6429: if ($domconfig{$action}{'textbooks'}{$item}{'order'} ne $idx) {
6430: $changes{'textbooks'}{$item} = 1;
6431: }
6432: }
6433: }
6434: }
6435: $idx ++;
6436: }
6437: }
6438: }
1.102 raeburn 6439: }
6440: } else {
1.86 raeburn 6441: $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
1.197 raeburn 6442: $confhash{'authorquota'}{'default'} = $env{'form.authorquota'};
1.86 raeburn 6443: }
1.72 raeburn 6444: foreach my $item (@usertools) {
6445: foreach my $type (@{$types},'default','_LC_adv') {
1.104 raeburn 6446: my $unset;
1.101 raeburn 6447: if ($context eq 'requestcourses') {
1.104 raeburn 6448: $unset = '0';
6449: if ($type eq '_LC_adv') {
6450: $unset = '';
6451: }
1.101 raeburn 6452: if ($confhash{$item}{$type} eq 'autolimit') {
6453: $confhash{$item}{$type} .= '=';
6454: unless ($limithash{$item}{$type} =~ /\D/) {
6455: $confhash{$item}{$type} .= $limithash{$item}{$type};
6456: }
6457: }
1.163 raeburn 6458: } elsif ($context eq 'requestauthor') {
6459: $unset = '0';
6460: if ($type eq '_LC_adv') {
6461: $unset = '';
6462: }
1.72 raeburn 6463: } else {
1.101 raeburn 6464: if (grep(/^\Q$type\E$/,@{$toolshash{$item}})) {
6465: $confhash{$item}{$type} = 1;
6466: } else {
6467: $confhash{$item}{$type} = 0;
6468: }
1.72 raeburn 6469: }
1.86 raeburn 6470: if (ref($domconfig{$action}) eq 'HASH') {
1.163 raeburn 6471: if ($action eq 'requestauthor') {
6472: if ($domconfig{$action}{$type} ne $confhash{$type}) {
6473: $changes{$type} = 1;
6474: }
6475: } elsif (ref($domconfig{$action}{$item}) eq 'HASH') {
1.86 raeburn 6476: if ($domconfig{$action}{$item}{$type} ne $confhash{$item}{$type}) {
6477: $changes{$item}{$type} = 1;
6478: }
6479: } else {
6480: if ($context eq 'requestcourses') {
1.104 raeburn 6481: if ($confhash{$item}{$type} ne $unset) {
1.86 raeburn 6482: $changes{$item}{$type} = 1;
6483: }
6484: } else {
6485: if (!$confhash{$item}{$type}) {
6486: $changes{$item}{$type} = 1;
6487: }
6488: }
6489: }
6490: } else {
6491: if ($context eq 'requestcourses') {
1.104 raeburn 6492: if ($confhash{$item}{$type} ne $unset) {
1.72 raeburn 6493: $changes{$item}{$type} = 1;
6494: }
1.163 raeburn 6495: } elsif ($context eq 'requestauthor') {
6496: if ($confhash{$type} ne $unset) {
6497: $changes{$type} = 1;
6498: }
1.72 raeburn 6499: } else {
6500: if (!$confhash{$item}{$type}) {
6501: $changes{$item}{$type} = 1;
6502: }
6503: }
6504: }
1.1 raeburn 6505: }
6506: }
1.163 raeburn 6507: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 6508: if (ref($domconfig{'quotas'}) eq 'HASH') {
6509: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
6510: foreach my $key (keys(%{$domconfig{'quotas'}{'defaultquota'}})) {
6511: if (exists($confhash{'defaultquota'}{$key})) {
6512: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{'defaultquota'}{$key}) {
6513: $changes{'defaultquota'}{$key} = 1;
6514: }
6515: } else {
6516: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{'defaultquota'}{$key};
1.72 raeburn 6517: }
6518: }
1.86 raeburn 6519: } else {
6520: foreach my $key (keys(%{$domconfig{'quotas'}})) {
6521: if (exists($confhash{'defaultquota'}{$key})) {
6522: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{$key}) {
6523: $changes{'defaultquota'}{$key} = 1;
6524: }
6525: } else {
6526: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{$key};
1.72 raeburn 6527: }
1.1 raeburn 6528: }
6529: }
1.197 raeburn 6530: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
6531: foreach my $key (keys(%{$domconfig{'quotas'}{'authorquota'}})) {
6532: if (exists($confhash{'authorquota'}{$key})) {
6533: if ($confhash{'authorquota'}{$key} ne $domconfig{'quotas'}{'authorquota'}{$key}) {
6534: $changes{'authorquota'}{$key} = 1;
6535: }
6536: } else {
6537: $confhash{'authorquota'}{$key} = $domconfig{'quotas'}{'authorquota'}{$key};
6538: }
6539: }
6540: }
1.1 raeburn 6541: }
1.86 raeburn 6542: if (ref($confhash{'defaultquota'}) eq 'HASH') {
6543: foreach my $key (keys(%{$confhash{'defaultquota'}})) {
6544: if (ref($domconfig{'quotas'}) eq 'HASH') {
6545: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
6546: if (!exists($domconfig{'quotas'}{'defaultquota'}{$key})) {
6547: $changes{'defaultquota'}{$key} = 1;
6548: }
6549: } else {
6550: if (!exists($domconfig{'quotas'}{$key})) {
6551: $changes{'defaultquota'}{$key} = 1;
6552: }
1.72 raeburn 6553: }
6554: } else {
1.86 raeburn 6555: $changes{'defaultquota'}{$key} = 1;
1.55 raeburn 6556: }
1.1 raeburn 6557: }
6558: }
1.197 raeburn 6559: if (ref($confhash{'authorquota'}) eq 'HASH') {
6560: foreach my $key (keys(%{$confhash{'authorquota'}})) {
6561: if (ref($domconfig{'quotas'}) eq 'HASH') {
6562: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
6563: if (!exists($domconfig{'quotas'}{'authorquota'}{$key})) {
6564: $changes{'authorquota'}{$key} = 1;
6565: }
6566: } else {
6567: $changes{'authorquota'}{$key} = 1;
6568: }
6569: } else {
6570: $changes{'authorquota'}{$key} = 1;
6571: }
6572: }
6573: }
1.1 raeburn 6574: }
1.72 raeburn 6575:
1.163 raeburn 6576: if ($context eq 'requestauthor') {
6577: $domdefaults{'requestauthor'} = \%confhash;
6578: } else {
6579: foreach my $key (keys(%confhash)) {
1.216 raeburn 6580: unless (($context eq 'requestcourses') && ($key eq 'textbooks')) {
6581: $domdefaults{$key} = $confhash{$key};
6582: }
1.163 raeburn 6583: }
1.72 raeburn 6584: }
1.163 raeburn 6585:
1.1 raeburn 6586: my %quotahash = (
1.86 raeburn 6587: $action => { %confhash }
1.1 raeburn 6588: );
6589: my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
6590: $dom);
6591: if ($putresult eq 'ok') {
6592: if (keys(%changes) > 0) {
1.72 raeburn 6593: my $cachetime = 24*60*60;
6594: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 6595: if (ref($lastactref) eq 'HASH') {
6596: $lastactref->{'domdefaults'} = 1;
6597: }
1.1 raeburn 6598: $resulttext = &mt('Changes made:').'<ul>';
1.210 raeburn 6599: unless (($context eq 'requestcourses') ||
1.163 raeburn 6600: ($context eq 'requestauthor')) {
1.86 raeburn 6601: if (ref($changes{'defaultquota'}) eq 'HASH') {
6602: $resulttext .= '<li>'.&mt('Portfolio default quotas').'<ul>';
6603: foreach my $type (@{$types},'default') {
6604: if (defined($changes{'defaultquota'}{$type})) {
6605: my $typetitle = $usertypes->{$type};
6606: if ($type eq 'default') {
6607: $typetitle = $othertitle;
6608: }
1.213 raeburn 6609: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'defaultquota'}{$type}).'</li>';
1.72 raeburn 6610: }
6611: }
1.86 raeburn 6612: $resulttext .= '</ul></li>';
1.72 raeburn 6613: }
1.197 raeburn 6614: if (ref($changes{'authorquota'}) eq 'HASH') {
1.223 bisitz 6615: $resulttext .= '<li>'.&mt('Authoring Space default quotas').'<ul>';
1.197 raeburn 6616: foreach my $type (@{$types},'default') {
6617: if (defined($changes{'authorquota'}{$type})) {
6618: my $typetitle = $usertypes->{$type};
6619: if ($type eq 'default') {
6620: $typetitle = $othertitle;
6621: }
1.213 raeburn 6622: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'authorquota'}{$type}).'</li>';
1.197 raeburn 6623: }
6624: }
6625: $resulttext .= '</ul></li>';
6626: }
1.72 raeburn 6627: }
1.80 raeburn 6628: my %newenv;
1.72 raeburn 6629: foreach my $item (@usertools) {
1.163 raeburn 6630: my (%haschgs,%inconf);
6631: if ($context eq 'requestauthor') {
6632: %haschgs = %changes;
1.210 raeburn 6633: %inconf = %confhash;
1.163 raeburn 6634: } else {
6635: if (ref($changes{$item}) eq 'HASH') {
6636: %haschgs = %{$changes{$item}};
6637: }
6638: if (ref($confhash{$item}) eq 'HASH') {
6639: %inconf = %{$confhash{$item}};
6640: }
6641: }
6642: if (keys(%haschgs) > 0) {
1.80 raeburn 6643: my $newacc =
6644: &Apache::lonnet::usertools_access($env{'user.name'},
6645: $env{'user.domain'},
1.86 raeburn 6646: $item,'reload',$context);
1.210 raeburn 6647: if (($context eq 'requestcourses') ||
1.163 raeburn 6648: ($context eq 'requestauthor')) {
1.108 raeburn 6649: if ($env{'environment.canrequest.'.$item} ne $newacc) {
6650: $newenv{'environment.canrequest.'.$item} = $newacc;
1.86 raeburn 6651: }
6652: } else {
6653: if ($env{'environment.availabletools.'.$item} ne $newacc) {
6654: $newenv{'environment.availabletools.'.$item} = $newacc;
6655: }
1.80 raeburn 6656: }
1.163 raeburn 6657: unless ($context eq 'requestauthor') {
6658: $resulttext .= '<li>'.$titles{$item}.'<ul>';
6659: }
1.72 raeburn 6660: foreach my $type (@{$types},'default','_LC_adv') {
1.163 raeburn 6661: if ($haschgs{$type}) {
1.72 raeburn 6662: my $typetitle = $usertypes->{$type};
6663: if ($type eq 'default') {
6664: $typetitle = $othertitle;
6665: } elsif ($type eq '_LC_adv') {
6666: $typetitle = 'LON-CAPA Advanced Users';
6667: }
1.163 raeburn 6668: if ($inconf{$type}) {
1.101 raeburn 6669: if ($context eq 'requestcourses') {
6670: my $cond;
1.163 raeburn 6671: if ($inconf{$type} =~ /^autolimit=(\d*)$/) {
1.101 raeburn 6672: if ($1 eq '') {
6673: $cond = &mt('(Automatic processing of any request).');
6674: } else {
6675: $cond = &mt('(Automatic processing of requests up to limit of [quant,_1,request] per user).',$1);
6676: }
6677: } else {
1.163 raeburn 6678: $cond = $conditions{$inconf{$type}};
1.101 raeburn 6679: }
6680: $resulttext .= '<li>'.&mt('Set to be available to [_1].',$typetitle).' '.$cond.'</li>';
1.172 raeburn 6681: } elsif ($context eq 'requestauthor') {
6682: $resulttext .= '<li>'.&mt('Set to "[_1]" for "[_2]".',
6683: $titles{$inconf{$type}},$typetitle);
6684:
1.101 raeburn 6685: } else {
6686: $resulttext .= '<li>'.&mt('Set to be available to [_1]',$typetitle).'</li>';
6687: }
1.72 raeburn 6688: } else {
1.104 raeburn 6689: if ($type eq '_LC_adv') {
1.163 raeburn 6690: if ($inconf{$type} eq '0') {
1.104 raeburn 6691: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
6692: } else {
6693: $resulttext .= '<li>'.&mt('No override set for [_1]',$typetitle).'</li>';
6694: }
6695: } else {
6696: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
6697: }
1.72 raeburn 6698: }
6699: }
1.26 raeburn 6700: }
1.163 raeburn 6701: unless ($context eq 'requestauthor') {
6702: $resulttext .= '</ul></li>';
6703: }
1.26 raeburn 6704: }
1.1 raeburn 6705: }
1.163 raeburn 6706: if (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.102 raeburn 6707: if (ref($changes{'notify'}) eq 'HASH') {
6708: if ($changes{'notify'}{'approval'}) {
6709: if (ref($confhash{'notify'}) eq 'HASH') {
6710: if ($confhash{'notify'}{'approval'}) {
6711: $resulttext .= '<li>'.&mt('Notification of requests requiring approval will be sent to: ').$confhash{'notify'}{'approval'}.'</li>';
6712: } else {
1.163 raeburn 6713: $resulttext .= '<li>'.&mt('No Domain Coordinators will receive notification of requests requiring approval.').'</li>';
1.102 raeburn 6714: }
6715: }
6716: }
6717: }
6718: }
1.216 raeburn 6719: if ($action eq 'requestcourses') {
6720: my @offon = ('off','on');
6721: if ($changes{'uniquecode'}) {
1.218 raeburn 6722: if (ref($confhash{'uniquecode'}) eq 'HASH') {
6723: my $codestr = join(' ',map{ &mt($_); } sort(keys(%{$confhash{'uniquecode'}})));
6724: $resulttext .= '<li>'.
6725: &mt('Generation of six character code as course identifier for distribution to students set to on for: [_1].','<b>'.$codestr.'</b>').
6726: '</li>';
6727: } else {
6728: $resulttext .= '<li>'.&mt('Generation of six character code as course identifier for distribution to students set to off.').
6729: '</li>';
6730: }
1.216 raeburn 6731: }
6732: if (ref($changes{'textbooks'}) eq 'HASH') {
6733: $resulttext .= '<li>'.&mt('Available textbooks updated').'<ul>';
6734: foreach my $key (sort(keys(%{$changes{'textbooks'}}))) {
6735: my %coursehash = &Apache::lonnet::coursedescription($key);
6736: my $coursetitle = $coursehash{'description'};
6737: my $position = $confhash{'textbooks'}{$key}{'order'} + 1;
6738: $resulttext .= '<li>';
6739: foreach my $item ('subject','title','author') {
6740: my $name = $item.':';
6741: $name =~ s/^(\w)/\U$1/;
6742: $resulttext .= &mt($name).' '.$confhash{'textbooks'}{$key}{$item}.'<br />';
6743: }
6744: $resulttext .= ' '.&mt('Order: [_1]',$position).'<br />';
6745: if ($confhash{'textbooks'}{$key}{'image'}) {
6746: $resulttext .= ' '.&mt('Image: [_1]',
6747: '<img src="'.$confhash{'textbooks'}{$key}{'image'}.'"'.
6748: ' alt="Textbook cover" />').'<br />';
6749: }
6750: $resulttext .= ' '.&mt('LON-CAPA Course: [_1]',$coursetitle).'</li>';
6751: }
6752: $resulttext .= '</ul></li>';
6753: }
6754: }
1.1 raeburn 6755: $resulttext .= '</ul>';
1.80 raeburn 6756: if (keys(%newenv)) {
6757: &Apache::lonnet::appenv(\%newenv);
6758: }
1.1 raeburn 6759: } else {
1.86 raeburn 6760: if ($context eq 'requestcourses') {
6761: $resulttext = &mt('No changes made to rights to request creation of courses.');
1.163 raeburn 6762: } elsif ($context eq 'requestauthor') {
6763: $resulttext = &mt('No changes made to rights to request author space.');
1.86 raeburn 6764: } else {
1.90 weissno 6765: $resulttext = &mt('No changes made to availability of personal information pages, blogs, portfolios or default quotas');
1.86 raeburn 6766: }
1.1 raeburn 6767: }
6768: } else {
1.11 albertel 6769: $resulttext = '<span class="LC_error">'.
6770: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 6771: }
1.216 raeburn 6772: if ($errors) {
6773: $resulttext .= '<p>'.&mt('The following errors occurred when modifying Textbook settings.').
6774: '<ul>'.$errors.'</ul></p>';
6775: }
1.3 raeburn 6776: return $resulttext;
1.1 raeburn 6777: }
6778:
1.216 raeburn 6779: sub process_textbook_image {
6780: my ($r,$dom,$confname,$caller,$cdom,$cnum,$configuserok,$switchserver,$author_ok) = @_;
6781: my $filename = $env{'form.'.$caller.'.filename'};
6782: my ($error,$url);
6783: my ($width,$height) = (50,50);
6784: if ($configuserok eq 'ok') {
6785: if ($switchserver) {
6786: $error = &mt('Upload of textbook image is not permitted to this server: [_1]',
6787: $switchserver);
6788: } elsif ($author_ok eq 'ok') {
6789: my ($result,$imageurl) =
6790: &publishlogo($r,'upload',$caller,$dom,$confname,
6791: "textbooks/$dom/$cnum/cover",$width,$height);
6792: if ($result eq 'ok') {
6793: $url = $imageurl;
6794: } else {
6795: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
6796: }
6797: } else {
6798: $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);
6799: }
6800: } else {
6801: $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);
6802: }
6803: return ($url,$error);
6804: }
6805:
1.3 raeburn 6806: sub modify_autoenroll {
1.205 raeburn 6807: my ($dom,$lastactref,%domconfig) = @_;
1.1 raeburn 6808: my ($resulttext,%changes);
6809: my %currautoenroll;
6810: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
6811: foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
6812: $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
6813: }
6814: }
6815: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
6816: my %title = ( run => 'Auto-enrollment active',
1.129 raeburn 6817: sender => 'Sender for notification messages',
6818: coowners => 'Automatic assignment of co-ownership to instructors of record (institutional data)');
1.1 raeburn 6819: my @offon = ('off','on');
1.17 raeburn 6820: my $sender_uname = $env{'form.sender_uname'};
6821: my $sender_domain = $env{'form.sender_domain'};
6822: if ($sender_domain eq '') {
6823: $sender_uname = '';
6824: } elsif ($sender_uname eq '') {
6825: $sender_domain = '';
6826: }
1.129 raeburn 6827: my $coowners = $env{'form.autoassign_coowners'};
1.1 raeburn 6828: my %autoenrollhash = (
1.129 raeburn 6829: autoenroll => { 'run' => $env{'form.autoenroll_run'},
6830: 'sender_uname' => $sender_uname,
6831: 'sender_domain' => $sender_domain,
6832: 'co-owners' => $coowners,
1.1 raeburn 6833: }
6834: );
1.4 raeburn 6835: my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
6836: $dom);
1.1 raeburn 6837: if ($putresult eq 'ok') {
6838: if (exists($currautoenroll{'run'})) {
6839: if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
6840: $changes{'run'} = 1;
6841: }
6842: } elsif ($autorun) {
6843: if ($env{'form.autoenroll_run'} ne '1') {
1.23 raeburn 6844: $changes{'run'} = 1;
1.1 raeburn 6845: }
6846: }
1.17 raeburn 6847: if ($currautoenroll{'sender_uname'} ne $sender_uname) {
1.1 raeburn 6848: $changes{'sender'} = 1;
6849: }
1.17 raeburn 6850: if ($currautoenroll{'sender_domain'} ne $sender_domain) {
1.1 raeburn 6851: $changes{'sender'} = 1;
6852: }
1.129 raeburn 6853: if ($currautoenroll{'co-owners'} ne '') {
6854: if ($currautoenroll{'co-owners'} ne $coowners) {
6855: $changes{'coowners'} = 1;
6856: }
6857: } elsif ($coowners) {
6858: $changes{'coowners'} = 1;
6859: }
1.1 raeburn 6860: if (keys(%changes) > 0) {
6861: $resulttext = &mt('Changes made:').'<ul>';
1.3 raeburn 6862: if ($changes{'run'}) {
1.1 raeburn 6863: $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
6864: }
6865: if ($changes{'sender'}) {
1.17 raeburn 6866: if ($sender_uname eq '' || $sender_domain eq '') {
6867: $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
6868: } else {
6869: $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
6870: }
1.1 raeburn 6871: }
1.129 raeburn 6872: if ($changes{'coowners'}) {
6873: $resulttext .= '<li>'.&mt("$title{'coowners'} set to $offon[$env{'form.autoassign_coowners'}]").'</li>';
6874: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 6875: if (ref($lastactref) eq 'HASH') {
6876: $lastactref->{'domainconfig'} = 1;
6877: }
1.129 raeburn 6878: }
1.1 raeburn 6879: $resulttext .= '</ul>';
6880: } else {
6881: $resulttext = &mt('No changes made to auto-enrollment settings');
6882: }
6883: } else {
1.11 albertel 6884: $resulttext = '<span class="LC_error">'.
6885: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 6886: }
1.3 raeburn 6887: return $resulttext;
1.1 raeburn 6888: }
6889:
6890: sub modify_autoupdate {
1.3 raeburn 6891: my ($dom,%domconfig) = @_;
1.1 raeburn 6892: my ($resulttext,%currautoupdate,%fields,%changes);
6893: if (ref($domconfig{'autoupdate'}) eq 'HASH') {
6894: foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
6895: $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
6896: }
6897: }
6898: my @offon = ('off','on');
6899: my %title = &Apache::lonlocal::texthash (
6900: run => 'Auto-update:',
6901: classlists => 'Updates to user information in classlists?'
6902: );
1.44 raeburn 6903: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 6904: my %fieldtitles = &Apache::lonlocal::texthash (
6905: id => 'Student/Employee ID',
1.20 raeburn 6906: permanentemail => 'E-mail address',
1.1 raeburn 6907: lastname => 'Last Name',
6908: firstname => 'First Name',
6909: middlename => 'Middle Name',
1.132 raeburn 6910: generation => 'Generation',
1.1 raeburn 6911: );
1.142 raeburn 6912: $othertitle = &mt('All users');
1.1 raeburn 6913: if (keys(%{$usertypes}) > 0) {
1.26 raeburn 6914: $othertitle = &mt('Other users');
1.1 raeburn 6915: }
6916: foreach my $key (keys(%env)) {
6917: if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
1.132 raeburn 6918: my ($usertype,$item) = ($1,$2);
6919: if (grep(/^\Q$item\E$/,keys(%fieldtitles))) {
6920: if ($usertype eq 'default') {
6921: push(@{$fields{$1}},$2);
6922: } elsif (ref($types) eq 'ARRAY') {
6923: if (grep(/^\Q$usertype\E$/,@{$types})) {
6924: push(@{$fields{$1}},$2);
6925: }
6926: }
6927: }
1.1 raeburn 6928: }
6929: }
1.131 raeburn 6930: my @lockablenames = &Apache::loncommon::get_env_multiple('form.lockablenames');
6931: @lockablenames = sort(@lockablenames);
6932: if (ref($currautoupdate{'lockablenames'}) eq 'ARRAY') {
6933: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
6934: if (@changed) {
6935: $changes{'lockablenames'} = 1;
6936: }
6937: } else {
6938: if (@lockablenames) {
6939: $changes{'lockablenames'} = 1;
6940: }
6941: }
1.1 raeburn 6942: my %updatehash = (
6943: autoupdate => { run => $env{'form.autoupdate_run'},
6944: classlists => $env{'form.classlists'},
6945: fields => {%fields},
1.131 raeburn 6946: lockablenames => \@lockablenames,
1.1 raeburn 6947: }
6948: );
6949: foreach my $key (keys(%currautoupdate)) {
6950: if (($key eq 'run') || ($key eq 'classlists')) {
6951: if (exists($updatehash{autoupdate}{$key})) {
6952: if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
6953: $changes{$key} = 1;
6954: }
6955: }
6956: } elsif ($key eq 'fields') {
6957: if (ref($currautoupdate{$key}) eq 'HASH') {
1.26 raeburn 6958: foreach my $item (@{$types},'default') {
1.1 raeburn 6959: if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
6960: my $change = 0;
6961: foreach my $type (@{$currautoupdate{$key}{$item}}) {
6962: if (!exists($fields{$item})) {
6963: $change = 1;
1.132 raeburn 6964: last;
1.1 raeburn 6965: } elsif (ref($fields{$item}) eq 'ARRAY') {
1.26 raeburn 6966: if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
1.1 raeburn 6967: $change = 1;
1.132 raeburn 6968: last;
1.1 raeburn 6969: }
6970: }
6971: }
6972: if ($change) {
6973: push(@{$changes{$key}},$item);
6974: }
1.26 raeburn 6975: }
1.1 raeburn 6976: }
6977: }
1.131 raeburn 6978: } elsif ($key eq 'lockablenames') {
6979: if (ref($currautoupdate{$key}) eq 'ARRAY') {
6980: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
6981: if (@changed) {
6982: $changes{'lockablenames'} = 1;
6983: }
6984: } else {
6985: if (@lockablenames) {
6986: $changes{'lockablenames'} = 1;
6987: }
6988: }
6989: }
6990: }
6991: unless (grep(/^\Qlockablenames\E$/,keys(%currautoupdate))) {
6992: if (@lockablenames) {
6993: $changes{'lockablenames'} = 1;
1.1 raeburn 6994: }
6995: }
1.26 raeburn 6996: foreach my $item (@{$types},'default') {
6997: if (defined($fields{$item})) {
6998: if (ref($currautoupdate{'fields'}) eq 'HASH') {
1.132 raeburn 6999: if (ref($currautoupdate{'fields'}{$item}) eq 'ARRAY') {
7000: my $change = 0;
7001: if (ref($fields{$item}) eq 'ARRAY') {
7002: foreach my $type (@{$fields{$item}}) {
7003: if (!grep(/^\Q$type\E$/,@{$currautoupdate{'fields'}{$item}})) {
7004: $change = 1;
7005: last;
7006: }
7007: }
7008: }
7009: if ($change) {
7010: push(@{$changes{'fields'}},$item);
7011: }
7012: } else {
1.26 raeburn 7013: push(@{$changes{'fields'}},$item);
7014: }
7015: } else {
7016: push(@{$changes{'fields'}},$item);
1.1 raeburn 7017: }
7018: }
7019: }
7020: my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
7021: $dom);
7022: if ($putresult eq 'ok') {
7023: if (keys(%changes) > 0) {
7024: $resulttext = &mt('Changes made:').'<ul>';
7025: foreach my $key (sort(keys(%changes))) {
1.131 raeburn 7026: if ($key eq 'lockablenames') {
7027: $resulttext .= '<li>';
7028: if (@lockablenames) {
7029: $usertypes->{'default'} = $othertitle;
7030: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update), available for the following affiliations:").' '.
7031: join(', ', map { $usertypes->{$_}; } @lockablenames).'</li>';
7032: } else {
7033: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update) is unavailable.");
7034: }
7035: $resulttext .= '</li>';
7036: } elsif (ref($changes{$key}) eq 'ARRAY') {
1.1 raeburn 7037: foreach my $item (@{$changes{$key}}) {
7038: my @newvalues;
7039: foreach my $type (@{$fields{$item}}) {
7040: push(@newvalues,$fieldtitles{$type});
7041: }
1.3 raeburn 7042: my $newvaluestr;
7043: if (@newvalues > 0) {
7044: $newvaluestr = join(', ',@newvalues);
7045: } else {
7046: $newvaluestr = &mt('none');
1.6 raeburn 7047: }
1.1 raeburn 7048: if ($item eq 'default') {
1.26 raeburn 7049: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
1.1 raeburn 7050: } else {
1.26 raeburn 7051: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
1.1 raeburn 7052: }
7053: }
7054: } else {
7055: my $newvalue;
7056: if ($key eq 'run') {
7057: $newvalue = $offon[$env{'form.autoupdate_run'}];
7058: } else {
7059: $newvalue = $offon[$env{'form.'.$key}];
1.3 raeburn 7060: }
1.1 raeburn 7061: $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
7062: }
7063: }
7064: $resulttext .= '</ul>';
7065: } else {
1.3 raeburn 7066: $resulttext = &mt('No changes made to autoupdates');
1.1 raeburn 7067: }
7068: } else {
1.11 albertel 7069: $resulttext = '<span class="LC_error">'.
7070: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 7071: }
1.3 raeburn 7072: return $resulttext;
1.1 raeburn 7073: }
7074:
1.125 raeburn 7075: sub modify_autocreate {
7076: my ($dom,%domconfig) = @_;
7077: my ($resulttext,%changes,%currautocreate,%newvals,%autocreatehash);
7078: if (ref($domconfig{'autocreate'}) eq 'HASH') {
7079: foreach my $key (keys(%{$domconfig{'autocreate'}})) {
7080: $currautocreate{$key} = $domconfig{'autocreate'}{$key};
7081: }
7082: }
7083: my %title= ( xml => 'Auto-creation of courses in XML course description files',
7084: req => 'Auto-creation of validated requests for official courses',
7085: xmldc => 'Identity of course creator of courses from XML files',
7086: );
7087: my @types = ('xml','req');
7088: foreach my $item (@types) {
7089: $newvals{$item} = $env{'form.autocreate_'.$item};
7090: $newvals{$item} =~ s/\D//g;
7091: $newvals{$item} = 0 if ($newvals{$item} eq '');
7092: }
7093: $newvals{'xmldc'} = $env{'form.autocreate_xmldc'};
7094: my %domcoords = &get_active_dcs($dom);
7095: unless (exists($domcoords{$newvals{'xmldc'}})) {
7096: $newvals{'xmldc'} = '';
7097: }
7098: %autocreatehash = (
7099: autocreate => { xml => $newvals{'xml'},
7100: req => $newvals{'req'},
7101: }
7102: );
7103: if ($newvals{'xmldc'} ne '') {
7104: $autocreatehash{'autocreate'}{'xmldc'} = $newvals{'xmldc'};
7105: }
7106: my $putresult = &Apache::lonnet::put_dom('configuration',\%autocreatehash,
7107: $dom);
7108: if ($putresult eq 'ok') {
7109: my @items = @types;
7110: if ($newvals{'xml'}) {
7111: push(@items,'xmldc');
7112: }
7113: foreach my $item (@items) {
7114: if (exists($currautocreate{$item})) {
7115: if ($currautocreate{$item} ne $newvals{$item}) {
7116: $changes{$item} = 1;
7117: }
7118: } elsif ($newvals{$item}) {
7119: $changes{$item} = 1;
7120: }
7121: }
7122: if (keys(%changes) > 0) {
7123: my @offon = ('off','on');
7124: $resulttext = &mt('Changes made:').'<ul>';
7125: foreach my $item (@types) {
7126: if ($changes{$item}) {
7127: my $newtxt = $offon[$newvals{$item}];
1.178 raeburn 7128: $resulttext .= '<li>'.
7129: &mt("$title{$item} set to [_1]$newtxt [_2]",
7130: '<b>','</b>').
7131: '</li>';
1.125 raeburn 7132: }
7133: }
7134: if ($changes{'xmldc'}) {
7135: my ($dcname,$dcdom) = split(':',$newvals{'xmldc'});
7136: my $newtxt = &Apache::loncommon::plainname($dcname,$dcdom);
1.178 raeburn 7137: $resulttext .= '<li>'.&mt("$title{'xmldc'} set to [_1]",'<b>'.$newtxt.'</b>').'</li>';
1.125 raeburn 7138: }
7139: $resulttext .= '</ul>';
7140: } else {
7141: $resulttext = &mt('No changes made to auto-creation settings');
7142: }
7143: } else {
7144: $resulttext = '<span class="LC_error">'.
7145: &mt('An error occurred: [_1]',$putresult).'</span>';
7146: }
7147: return $resulttext;
7148: }
7149:
1.23 raeburn 7150: sub modify_directorysrch {
7151: my ($dom,%domconfig) = @_;
7152: my ($resulttext,%changes);
7153: my %currdirsrch;
7154: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
7155: foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
7156: $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
7157: }
7158: }
7159: my %title = ( available => 'Directory search available',
1.24 raeburn 7160: localonly => 'Other domains can search',
1.23 raeburn 7161: searchby => 'Search types',
7162: searchtypes => 'Search latitude');
7163: my @offon = ('off','on');
1.24 raeburn 7164: my @otherdoms = ('Yes','No');
1.23 raeburn 7165:
1.25 raeburn 7166: my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');
1.23 raeburn 7167: my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
7168: my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
7169:
1.44 raeburn 7170: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.26 raeburn 7171: if (keys(%{$usertypes}) == 0) {
7172: @cansearch = ('default');
7173: } else {
7174: if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
7175: foreach my $type (@{$currdirsrch{'cansearch'}}) {
7176: if (!grep(/^\Q$type\E$/,@cansearch)) {
7177: push(@{$changes{'cansearch'}},$type);
7178: }
1.23 raeburn 7179: }
1.26 raeburn 7180: foreach my $type (@cansearch) {
7181: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
7182: push(@{$changes{'cansearch'}},$type);
7183: }
1.23 raeburn 7184: }
1.26 raeburn 7185: } else {
7186: push(@{$changes{'cansearch'}},@cansearch);
1.23 raeburn 7187: }
7188: }
7189:
7190: if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
7191: foreach my $by (@{$currdirsrch{'searchby'}}) {
7192: if (!grep(/^\Q$by\E$/,@searchby)) {
7193: push(@{$changes{'searchby'}},$by);
7194: }
7195: }
7196: foreach my $by (@searchby) {
7197: if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
7198: push(@{$changes{'searchby'}},$by);
7199: }
7200: }
7201: } else {
7202: push(@{$changes{'searchby'}},@searchby);
7203: }
1.25 raeburn 7204:
7205: if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
7206: foreach my $type (@{$currdirsrch{'searchtypes'}}) {
7207: if (!grep(/^\Q$type\E$/,@searchtypes)) {
7208: push(@{$changes{'searchtypes'}},$type);
7209: }
7210: }
7211: foreach my $type (@searchtypes) {
7212: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
7213: push(@{$changes{'searchtypes'}},$type);
7214: }
7215: }
7216: } else {
7217: if (exists($currdirsrch{'searchtypes'})) {
7218: foreach my $type (@searchtypes) {
7219: if ($type ne $currdirsrch{'searchtypes'}) {
7220: push(@{$changes{'searchtypes'}},$type);
7221: }
7222: }
7223: if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
7224: push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
7225: }
7226: } else {
7227: push(@{$changes{'searchtypes'}},@searchtypes);
7228: }
7229: }
7230:
1.23 raeburn 7231: my %dirsrch_hash = (
7232: directorysrch => { available => $env{'form.dirsrch_available'},
7233: cansearch => \@cansearch,
1.24 raeburn 7234: localonly => $env{'form.dirsrch_localonly'},
1.23 raeburn 7235: searchby => \@searchby,
1.25 raeburn 7236: searchtypes => \@searchtypes,
1.23 raeburn 7237: }
7238: );
7239: my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
7240: $dom);
7241: if ($putresult eq 'ok') {
7242: if (exists($currdirsrch{'available'})) {
7243: if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
7244: $changes{'available'} = 1;
7245: }
7246: } else {
7247: if ($env{'form.dirsrch_available'} eq '1') {
7248: $changes{'available'} = 1;
7249: }
7250: }
1.24 raeburn 7251: if (exists($currdirsrch{'localonly'})) {
7252: if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_localonly'}) {
7253: $changes{'localonly'} = 1;
7254: }
7255: } else {
7256: if ($env{'form.dirsrch_localonly'} eq '1') {
7257: $changes{'localonly'} = 1;
7258: }
7259: }
1.23 raeburn 7260: if (keys(%changes) > 0) {
7261: $resulttext = &mt('Changes made:').'<ul>';
7262: if ($changes{'available'}) {
7263: $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
7264: }
1.24 raeburn 7265: if ($changes{'localonly'}) {
7266: $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_localonly'}]").'</li>';
7267: }
7268:
1.23 raeburn 7269: if (ref($changes{'cansearch'}) eq 'ARRAY') {
7270: my $chgtext;
1.26 raeburn 7271: if (ref($usertypes) eq 'HASH') {
7272: if (keys(%{$usertypes}) > 0) {
7273: foreach my $type (@{$types}) {
7274: if (grep(/^\Q$type\E$/,@cansearch)) {
7275: $chgtext .= $usertypes->{$type}.'; ';
7276: }
7277: }
7278: if (grep(/^default$/,@cansearch)) {
7279: $chgtext .= $othertitle;
7280: } else {
7281: $chgtext =~ s/\; $//;
7282: }
1.210 raeburn 7283: $resulttext .=
1.178 raeburn 7284: '<li>'.
7285: &mt("Users from domain '[_1]' permitted to search the institutional directory set to: [_2]",
7286: '<span class="LC_cusr_emph">'.$dom.'</span>',$chgtext).
7287: '</li>';
1.23 raeburn 7288: }
7289: }
7290: }
7291: if (ref($changes{'searchby'}) eq 'ARRAY') {
7292: my ($searchtitles,$titleorder) = &sorted_searchtitles();
7293: my $chgtext;
7294: foreach my $type (@{$titleorder}) {
7295: if (grep(/^\Q$type\E$/,@searchby)) {
7296: if (defined($searchtitles->{$type})) {
7297: $chgtext .= $searchtitles->{$type}.'; ';
7298: }
7299: }
7300: }
7301: $chgtext =~ s/\; $//;
7302: $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
7303: }
1.25 raeburn 7304: if (ref($changes{'searchtypes'}) eq 'ARRAY') {
7305: my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes();
7306: my $chgtext;
7307: foreach my $type (@{$srchtypeorder}) {
7308: if (grep(/^\Q$type\E$/,@searchtypes)) {
7309: if (defined($srchtypes_desc->{$type})) {
7310: $chgtext .= $srchtypes_desc->{$type}.'; ';
7311: }
7312: }
7313: }
7314: $chgtext =~ s/\; $//;
1.178 raeburn 7315: $resulttext .= '<li>'.&mt($title{'searchtypes'}.' set to: "[_1]"',$chgtext).'</li>';
1.23 raeburn 7316: }
7317: $resulttext .= '</ul>';
7318: } else {
7319: $resulttext = &mt('No changes made to institution directory search settings');
7320: }
7321: } else {
7322: $resulttext = '<span class="LC_error">'.
1.27 raeburn 7323: &mt('An error occurred: [_1]',$putresult).'</span>';
7324: }
7325: return $resulttext;
7326: }
7327:
1.28 raeburn 7328: sub modify_contacts {
1.205 raeburn 7329: my ($dom,$lastactref,%domconfig) = @_;
1.28 raeburn 7330: my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
7331: if (ref($domconfig{'contacts'}) eq 'HASH') {
7332: foreach my $key (keys(%{$domconfig{'contacts'}})) {
7333: $currsetting{$key} = $domconfig{'contacts'}{$key};
7334: }
7335: }
1.134 raeburn 7336: my (%others,%to,%bcc);
1.28 raeburn 7337: my @contacts = ('supportemail','adminemail');
1.102 raeburn 7338: my @mailings = ('errormail','packagesmail','helpdeskmail','lonstatusmail',
1.203 raeburn 7339: 'requestsmail','updatesmail','idconflictsmail');
7340: my @toggles = ('reporterrors','reportupdates');
1.28 raeburn 7341: foreach my $type (@mailings) {
7342: @{$newsetting{$type}} =
7343: &Apache::loncommon::get_env_multiple('form.'.$type);
7344: foreach my $item (@contacts) {
7345: if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
7346: $contacts_hash{contacts}{$type}{$item} = 1;
7347: } else {
7348: $contacts_hash{contacts}{$type}{$item} = 0;
7349: }
7350: }
7351: $others{$type} = $env{'form.'.$type.'_others'};
7352: $contacts_hash{contacts}{$type}{'others'} = $others{$type};
1.134 raeburn 7353: if ($type eq 'helpdeskmail') {
7354: $bcc{$type} = $env{'form.'.$type.'_bcc'};
7355: $contacts_hash{contacts}{$type}{'bcc'} = $bcc{$type};
7356: }
1.28 raeburn 7357: }
7358: foreach my $item (@contacts) {
7359: $to{$item} = $env{'form.'.$item};
7360: $contacts_hash{'contacts'}{$item} = $to{$item};
7361: }
1.203 raeburn 7362: foreach my $item (@toggles) {
7363: if ($env{'form.'.$item} =~ /^(0|1)$/) {
7364: $contacts_hash{'contacts'}{$item} = $env{'form.'.$item};
7365: }
7366: }
1.28 raeburn 7367: if (keys(%currsetting) > 0) {
7368: foreach my $item (@contacts) {
7369: if ($to{$item} ne $currsetting{$item}) {
7370: $changes{$item} = 1;
7371: }
7372: }
7373: foreach my $type (@mailings) {
7374: foreach my $item (@contacts) {
7375: if (ref($currsetting{$type}) eq 'HASH') {
7376: if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
7377: push(@{$changes{$type}},$item);
7378: }
7379: } else {
7380: push(@{$changes{$type}},@{$newsetting{$type}});
7381: }
7382: }
7383: if ($others{$type} ne $currsetting{$type}{'others'}) {
7384: push(@{$changes{$type}},'others');
7385: }
1.134 raeburn 7386: if ($type eq 'helpdeskmail') {
7387: if ($bcc{$type} ne $currsetting{$type}{'bcc'}) {
7388: push(@{$changes{$type}},'bcc');
7389: }
7390: }
1.28 raeburn 7391: }
7392: } else {
7393: my %default;
7394: $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
7395: $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
7396: $default{'errormail'} = 'adminemail';
7397: $default{'packagesmail'} = 'adminemail';
7398: $default{'helpdeskmail'} = 'supportemail';
1.89 raeburn 7399: $default{'lonstatusmail'} = 'adminemail';
1.102 raeburn 7400: $default{'requestsmail'} = 'adminemail';
1.190 raeburn 7401: $default{'updatesmail'} = 'adminemail';
1.28 raeburn 7402: foreach my $item (@contacts) {
7403: if ($to{$item} ne $default{$item}) {
7404: $changes{$item} = 1;
1.203 raeburn 7405: }
1.28 raeburn 7406: }
7407: foreach my $type (@mailings) {
7408: if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
7409:
7410: push(@{$changes{$type}},@{$newsetting{$type}});
7411: }
7412: if ($others{$type} ne '') {
7413: push(@{$changes{$type}},'others');
1.134 raeburn 7414: }
7415: if ($type eq 'helpdeskmail') {
7416: if ($bcc{$type} ne '') {
7417: push(@{$changes{$type}},'bcc');
7418: }
7419: }
1.28 raeburn 7420: }
7421: }
1.203 raeburn 7422: foreach my $item (@toggles) {
7423: if (($env{'form.'.$item} == 1) && ($currsetting{$item} == 0)) {
7424: $changes{$item} = 1;
7425: } elsif ((!$env{'form.'.$item}) &&
7426: (($currsetting{$item} eq '') || ($currsetting{$item} == 1))) {
7427: $changes{$item} = 1;
7428: }
7429: }
1.28 raeburn 7430: my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
7431: $dom);
7432: if ($putresult eq 'ok') {
7433: if (keys(%changes) > 0) {
1.205 raeburn 7434: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 7435: if (ref($lastactref) eq 'HASH') {
7436: $lastactref->{'domainconfig'} = 1;
7437: }
1.28 raeburn 7438: my ($titles,$short_titles) = &contact_titles();
7439: $resulttext = &mt('Changes made:').'<ul>';
7440: foreach my $item (@contacts) {
7441: if ($changes{$item}) {
7442: $resulttext .= '<li>'.$titles->{$item}.
7443: &mt(' set to: ').
7444: '<span class="LC_cusr_emph">'.
7445: $to{$item}.'</span></li>';
7446: }
7447: }
7448: foreach my $type (@mailings) {
7449: if (ref($changes{$type}) eq 'ARRAY') {
7450: $resulttext .= '<li>'.$titles->{$type}.': ';
7451: my @text;
7452: foreach my $item (@{$newsetting{$type}}) {
7453: push(@text,$short_titles->{$item});
7454: }
7455: if ($others{$type} ne '') {
7456: push(@text,$others{$type});
7457: }
7458: $resulttext .= '<span class="LC_cusr_emph">'.
1.134 raeburn 7459: join(', ',@text).'</span>';
7460: if ($type eq 'helpdeskmail') {
7461: if ($bcc{$type} ne '') {
7462: $resulttext .= ' '.&mt('with Bcc to').': <span class="LC_cusr_emph">'.$bcc{$type}.'</span>';
7463: }
7464: }
7465: $resulttext .= '</li>';
1.28 raeburn 7466: }
7467: }
1.203 raeburn 7468: my @offon = ('off','on');
7469: if ($changes{'reporterrors'}) {
7470: $resulttext .= '<li>'.
7471: &mt('E-mail error reports to [_1] set to "'.
7472: $offon[$env{'form.reporterrors'}].'".',
7473: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
7474: &mt('LON-CAPA core group - MSU'),600,500)).
7475: '</li>';
7476: }
7477: if ($changes{'reportupdates'}) {
7478: $resulttext .= '<li>'.
7479: &mt('E-mail record of completed LON-CAPA updates to [_1] set to "'.
7480: $offon[$env{'form.reportupdates'}].'".',
7481: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
7482: &mt('LON-CAPA core group - MSU'),600,500)).
7483: '</li>';
7484: }
1.28 raeburn 7485: $resulttext .= '</ul>';
7486: } else {
1.34 raeburn 7487: $resulttext = &mt('No changes made to contact information');
1.28 raeburn 7488: }
7489: } else {
7490: $resulttext = '<span class="LC_error">'.
7491: &mt('An error occurred: [_1].',$putresult).'</span>';
7492: }
7493: return $resulttext;
7494: }
7495:
7496: sub modify_usercreation {
1.27 raeburn 7497: my ($dom,%domconfig) = @_;
1.224 raeburn 7498: my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate,%save_usercreate);
1.43 raeburn 7499: my $warningmsg;
1.27 raeburn 7500: if (ref($domconfig{'usercreation'}) eq 'HASH') {
7501: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
1.224 raeburn 7502: if ($key eq 'cancreate') {
7503: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
7504: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
7505: if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
7506: ($item eq 'captcha') || ($item eq 'recaptchakeys')) {
7507: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
7508: } else {
7509: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
7510: }
7511: }
7512: }
7513: } elsif ($key eq 'email_rule') {
7514: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
7515: } else {
7516: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
7517: }
1.27 raeburn 7518: }
7519: }
7520: my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
1.32 raeburn 7521: my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
1.224 raeburn 7522: my @contexts = ('author','course','requestcrs');
1.34 raeburn 7523: foreach my $item(@contexts) {
1.224 raeburn 7524: $cancreate{$item} = $env{'form.can_createuser_'.$item};
1.93 raeburn 7525: }
1.34 raeburn 7526: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
7527: foreach my $item (@contexts) {
1.224 raeburn 7528: if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
7529: push(@{$changes{'cancreate'}},$item);
1.50 raeburn 7530: }
1.27 raeburn 7531: }
1.34 raeburn 7532: } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
7533: foreach my $item (@contexts) {
1.43 raeburn 7534: if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
1.34 raeburn 7535: if ($cancreate{$item} ne 'any') {
7536: push(@{$changes{'cancreate'}},$item);
7537: }
7538: } else {
7539: if ($cancreate{$item} ne 'none') {
7540: push(@{$changes{'cancreate'}},$item);
7541: }
1.27 raeburn 7542: }
7543: }
7544: } else {
1.43 raeburn 7545: foreach my $item (@contexts) {
1.34 raeburn 7546: push(@{$changes{'cancreate'}},$item);
7547: }
1.27 raeburn 7548: }
1.34 raeburn 7549:
1.27 raeburn 7550: if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
7551: foreach my $type (@{$curr_usercreation{'username_rule'}}) {
7552: if (!grep(/^\Q$type\E$/,@username_rule)) {
7553: push(@{$changes{'username_rule'}},$type);
7554: }
7555: }
7556: foreach my $type (@username_rule) {
7557: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
7558: push(@{$changes{'username_rule'}},$type);
7559: }
7560: }
7561: } else {
7562: push(@{$changes{'username_rule'}},@username_rule);
7563: }
7564:
1.32 raeburn 7565: if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
7566: foreach my $type (@{$curr_usercreation{'id_rule'}}) {
7567: if (!grep(/^\Q$type\E$/,@id_rule)) {
7568: push(@{$changes{'id_rule'}},$type);
7569: }
7570: }
7571: foreach my $type (@id_rule) {
7572: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
7573: push(@{$changes{'id_rule'}},$type);
7574: }
7575: }
7576: } else {
7577: push(@{$changes{'id_rule'}},@id_rule);
7578: }
7579:
1.43 raeburn 7580: my @authen_contexts = ('author','course','domain');
1.28 raeburn 7581: my @authtypes = ('int','krb4','krb5','loc');
7582: my %authhash;
1.43 raeburn 7583: foreach my $item (@authen_contexts) {
1.28 raeburn 7584: my @authallowed = &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
7585: foreach my $auth (@authtypes) {
7586: if (grep(/^\Q$auth\E$/,@authallowed)) {
7587: $authhash{$item}{$auth} = 1;
7588: } else {
7589: $authhash{$item}{$auth} = 0;
7590: }
7591: }
7592: }
7593: if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
1.43 raeburn 7594: foreach my $item (@authen_contexts) {
1.28 raeburn 7595: if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
7596: foreach my $auth (@authtypes) {
7597: if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
7598: push(@{$changes{'authtypes'}},$item);
7599: last;
7600: }
7601: }
7602: }
7603: }
7604: } else {
1.43 raeburn 7605: foreach my $item (@authen_contexts) {
1.28 raeburn 7606: push(@{$changes{'authtypes'}},$item);
7607: }
7608: }
7609:
1.224 raeburn 7610: $save_usercreate{'cancreate'}{'course'} = $cancreate{'course'};
7611: $save_usercreate{'cancreate'}{'author'} = $cancreate{'author'};
7612: $save_usercreate{'cancreate'}{'requestcrs'} = $cancreate{'requestcrs'};
7613: $save_usercreate{'id_rule'} = \@id_rule;
7614: $save_usercreate{'username_rule'} = \@username_rule,
7615: $save_usercreate{'authtypes'} = \%authhash;
7616:
1.27 raeburn 7617: my %usercreation_hash = (
1.224 raeburn 7618: usercreation => \%save_usercreate,
7619: );
1.27 raeburn 7620:
7621: my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
7622: $dom);
1.50 raeburn 7623:
1.224 raeburn 7624: if ($putresult eq 'ok') {
7625: if (keys(%changes) > 0) {
7626: $resulttext = &mt('Changes made:').'<ul>';
7627: if (ref($changes{'cancreate'}) eq 'ARRAY') {
7628: my %lt = &usercreation_types();
7629: foreach my $type (@{$changes{'cancreate'}}) {
7630: my $chgtext = $lt{$type}.', ';
7631: if ($cancreate{$type} eq 'none') {
7632: $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
7633: } elsif ($cancreate{$type} eq 'any') {
7634: $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
7635: } elsif ($cancreate{$type} eq 'official') {
7636: $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
7637: } elsif ($cancreate{$type} eq 'unofficial') {
7638: $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
7639: }
7640: $resulttext .= '<li>'.$chgtext.'</li>';
7641: }
7642: }
7643: if (ref($changes{'username_rule'}) eq 'ARRAY') {
7644: my ($rules,$ruleorder) =
7645: &Apache::lonnet::inst_userrules($dom,'username');
7646: my $chgtext = '<ul>';
7647: foreach my $type (@username_rule) {
7648: if (ref($rules->{$type}) eq 'HASH') {
7649: $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
7650: }
7651: }
7652: $chgtext .= '</ul>';
7653: if (@username_rule > 0) {
7654: $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
7655: } else {
7656: $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>';
7657: }
7658: }
7659: if (ref($changes{'id_rule'}) eq 'ARRAY') {
7660: my ($idrules,$idruleorder) =
7661: &Apache::lonnet::inst_userrules($dom,'id');
7662: my $chgtext = '<ul>';
7663: foreach my $type (@id_rule) {
7664: if (ref($idrules->{$type}) eq 'HASH') {
7665: $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
7666: }
7667: }
7668: $chgtext .= '</ul>';
7669: if (@id_rule > 0) {
7670: $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
7671: } else {
7672: $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
7673: }
7674: }
7675: my %authname = &authtype_names();
7676: my %context_title = &context_names();
7677: if (ref($changes{'authtypes'}) eq 'ARRAY') {
7678: my $chgtext = '<ul>';
7679: foreach my $type (@{$changes{'authtypes'}}) {
7680: my @allowed;
7681: $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
7682: foreach my $auth (@authtypes) {
7683: if ($authhash{$type}{$auth}) {
7684: push(@allowed,$authname{$auth});
7685: }
7686: }
7687: if (@allowed > 0) {
7688: $chgtext .= join(', ',@allowed).'</li>';
7689: } else {
7690: $chgtext .= &mt('none').'</li>';
7691: }
7692: }
7693: $chgtext .= '</ul>';
7694: $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
7695: $resulttext .= '</li>';
7696: }
7697: $resulttext .= '</ul>';
7698: } else {
7699: $resulttext = &mt('No changes made to user creation settings');
7700: }
7701: } else {
7702: $resulttext = '<span class="LC_error">'.
7703: &mt('An error occurred: [_1]',$putresult).'</span>';
7704: }
7705: if ($warningmsg ne '') {
7706: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
7707: }
7708: return $resulttext;
7709: }
7710:
7711: sub modify_selfcreation {
7712: my ($dom,%domconfig) = @_;
7713: my ($resulttext,$warningmsg,%curr_usercreation,%curr_usermodify,%changes,%cancreate);
7714: my (%save_usercreate,%save_usermodify);
1.228 ! raeburn 7715: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
! 7716: if (ref($types) eq 'ARRAY') {
! 7717: $usertypes->{'default'} = $othertitle;
! 7718: push(@{$types},'default');
! 7719: }
1.224 raeburn 7720: #
7721: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usercreation'}.
7722: #
7723: if (ref($domconfig{'usercreation'}) eq 'HASH') {
7724: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
7725: if ($key eq 'cancreate') {
7726: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
7727: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
7728: if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
7729: ($item eq 'captcha') || ($item eq 'recaptchakeys') ||
7730: ($item eq 'emailusername') || ($item eq 'notify')) {
7731: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
7732: } else {
7733: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
7734: }
7735: }
7736: }
7737: } elsif ($key eq 'email_rule') {
7738: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
7739: } else {
7740: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
7741: }
7742: }
7743: }
7744: #
7745: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usermodification'}.
7746: #
7747: if (ref($domconfig{'usermodification'}) eq 'HASH') {
7748: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
7749: if ($key eq 'selfcreate') {
7750: $curr_usermodify{$key} = $domconfig{'usermodification'}{$key};
7751: } else {
7752: $save_usermodify{$key} = $domconfig{'usermodification'}{$key};
7753: }
7754: }
7755: }
7756:
7757: my @contexts = ('selfcreate');
7758: @{$cancreate{'selfcreate'}} = ();
7759: %{$cancreate{'emailusername'}} = ();
7760: @{$cancreate{'statustocreate'}} = ();
1.50 raeburn 7761: my %selfcreatetypes = (
7762: sso => 'users authenticated by institutional single sign on',
7763: login => 'users authenticated by institutional log-in',
1.224 raeburn 7764: email => 'users who provide a valid e-mail address for use as username (automatic creation)',
7765: emailapproval => 'users who provide a valid e-mail address for use as username (queued for Domain Coordinator review)',
1.50 raeburn 7766: );
1.224 raeburn 7767: #
7768: # Populate $cancreate{'selfcreate'} array reference with types of user, for which self-creation of user accounts
7769: # is permitted.
7770: #
1.228 ! raeburn 7771: foreach my $item ('login','sso','email') {
1.224 raeburn 7772: if ($item eq 'email') {
7773: if ($env{'form.cancreate_email'} eq 'email') {
7774: push(@{$cancreate{'selfcreate'}},'email');
7775: } elsif ($env{'form.cancreate_email'} eq 'emailapproval') {
7776: push(@{$cancreate{'selfcreate'}},'emailapproval');
7777: }
7778: } else {
7779: if ($env{'form.cancreate_'.$item}) {
7780: push(@{$cancreate{'selfcreate'}},$item);
7781: }
7782: }
7783: }
7784: my (@email_rule,%userinfo,%savecaptcha);
7785: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
7786: #
1.228 ! raeburn 7787: # Populate $cancreate{'emailusername'}{$type} hash ref with information fields (if new user will provide data
! 7788: # value set to one), if self-creation with e-mail address permitted, where $type is user type: faculty, staff, student etc.
1.224 raeburn 7789: #
7790: if (($env{'form.cancreate_email'} eq 'email') || ($env{'form.cancreate_email'} eq 'emailapproval')) {
1.228 ! raeburn 7791: push(@contexts,'emailusername');
! 7792: if (ref($types) eq 'ARRAY') {
! 7793: foreach my $type (@{$types}) {
! 7794: if (ref($infofields) eq 'ARRAY') {
! 7795: foreach my $field (@{$infofields}) {
! 7796: if ($env{'form.canmodify_emailusername_'.$type.'_'.$field} =~ /^(required|optional)$/) {
! 7797: $cancreate{'emailusername'}{$type}{$field} = $1;
! 7798: }
! 7799: }
1.224 raeburn 7800: }
7801: }
7802: }
7803: #
7804: # Populate $cancreate{'notify'} hash ref with names of Domain Coordinators who are to be notified of
7805: # queued requests for self-creation of account using e-mail address as username
7806: #
7807:
7808: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.selfcreationnotifyapproval');
7809: @approvalnotify = sort(@approvalnotify);
7810: $cancreate{'notify'}{'approval'} = join(',',@approvalnotify);
7811: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
7812: if (ref($curr_usercreation{'cancreate'}{'notify'}) eq 'HASH') {
7813: if ($curr_usercreation{'cancreate'}{'notify'}{'approval'} ne $cancreate{'notify'}{'approval'}) {
7814: push(@{$changes{'cancreate'}},'notify');
7815: }
7816: } else {
7817: if ($cancreate{'notify'}{'approval'}) {
7818: push(@{$changes{'cancreate'}},'notify');
7819: }
7820: }
7821: } elsif ($cancreate{'notify'}{'approval'}) {
7822: push(@{$changes{'cancreate'}},'notify');
7823: }
7824:
7825: #
7826: # Retrieve rules (if any) governing types of e-mail address which may be used as a username
7827: #
7828: @email_rule = &Apache::loncommon::get_env_multiple('form.email_rule');
7829: &process_captcha('cancreate',\%changes,\%savecaptcha,$curr_usercreation{'cancreate'});
7830: if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
7831: if (@{$curr_usercreation{'email_rule'}} > 0) {
7832: foreach my $type (@{$curr_usercreation{'email_rule'}}) {
7833: if (!grep(/^\Q$type\E$/,@email_rule)) {
7834: push(@{$changes{'email_rule'}},$type);
7835: }
7836: }
7837: }
7838: if (@email_rule > 0) {
7839: foreach my $type (@email_rule) {
7840: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'email_rule'}})) {
7841: push(@{$changes{'email_rule'}},$type);
7842: }
7843: }
7844: }
7845: } elsif (@email_rule > 0) {
7846: push(@{$changes{'email_rule'}},@email_rule);
7847: }
7848: }
7849: #
7850: # Check if domain default is set appropriately, if selef-creation of accounts is to be available for
7851: # institutional log-in.
7852: #
7853: if (grep(/^login$/,@{$cancreate{'selfcreate'}})) {
7854: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
7855: if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) ||
7856: ($domdefaults{'auth_def'} eq 'localauth'))) {
7857: $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.').' '.
7858: &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.');
7859: }
7860: }
7861: my @fields = ('lastname','firstname','middlename','generation',
7862: 'permanentemail','id');
7863: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
7864: #
7865: # Where usernames may created for institutional log-in and/or institutional single sign on:
7866: # (a) populate $cancreate{'statustocreate'} array reference with institutional status types who
7867: # may self-create accounts
7868: # (b) populate $save_usermodify{'selfcreate'} hash reference with status types, and information fields
7869: # which the user may supply, if institutional data is unavailable.
7870: #
7871: if (($env{'form.cancreate_login'}) || ($env{'form.cancreate_sso'})) {
7872: if (ref($types) eq 'ARRAY') {
1.228 ! raeburn 7873: if (@{$types} > 1) {
1.224 raeburn 7874: @{$cancreate{'statustocreate'}} = &Apache::loncommon::get_env_multiple('form.statustocreate');
7875: push(@contexts,'statustocreate');
7876: } else {
7877: undef($cancreate{'statustocreate'});
7878: }
7879: foreach my $type (@{$types}) {
7880: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$type);
7881: foreach my $field (@fields) {
7882: if (grep(/^\Q$field\E$/,@modifiable)) {
7883: $save_usermodify{'selfcreate'}{$type}{$field} = 1;
7884: } else {
7885: $save_usermodify{'selfcreate'}{$type}{$field} = 0;
7886: }
7887: }
7888: }
7889: if (ref($curr_usermodify{'selfcreate'}) eq 'HASH') {
7890: foreach my $type (@{$types}) {
7891: if (ref($curr_usermodify{'selfcreate'}{$type}) eq 'HASH') {
7892: foreach my $field (@fields) {
7893: if ($save_usermodify{'selfcreate'}{$type}{$field} ne
7894: $curr_usermodify{'selfcreate'}{$type}{$field}) {
7895: push(@{$changes{'selfcreate'}},$type);
7896: last;
7897: }
7898: }
7899: }
7900: }
7901: } else {
7902: foreach my $type (@{$types}) {
7903: push(@{$changes{'selfcreate'}},$type);
7904: }
7905: }
7906: }
7907: }
7908: foreach my $item (@contexts) {
7909: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
7910: foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
7911: if (ref($cancreate{$item}) eq 'ARRAY') {
7912: if (!grep(/^$curr$/,@{$cancreate{$item}})) {
7913: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
7914: push(@{$changes{'cancreate'}},$item);
7915: }
7916: }
7917: }
7918: }
7919: if (ref($cancreate{$item}) eq 'ARRAY') {
7920: foreach my $type (@{$cancreate{$item}}) {
7921: if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
7922: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
7923: push(@{$changes{'cancreate'}},$item);
7924: }
7925: }
7926: }
7927: }
7928: } elsif (ref($curr_usercreation{'cancreate'}{$item}) eq 'HASH') {
7929: if (ref($cancreate{$item}) eq 'HASH') {
7930: foreach my $curr (keys(%{$curr_usercreation{'cancreate'}{$item}})) {
1.228 ! raeburn 7931: if (ref($curr_usercreation{'cancreate'}{$item}{$curr}) eq 'HASH') {
! 7932: foreach my $field (keys(%{$curr_usercreation{'cancreate'}{$item}{$curr}})) {
! 7933: unless ($curr_usercreation{'cancreate'}{$item}{$curr}{$field} eq $cancreate{$item}{$curr}{$field}) {
! 7934: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
! 7935: push(@{$changes{'cancreate'}},$item);
! 7936: }
! 7937: }
! 7938: }
! 7939: } else {
! 7940: if (!$cancreate{$item}{$curr}) {
! 7941: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
! 7942: push(@{$changes{'cancreate'}},$item);
! 7943: }
1.224 raeburn 7944: }
7945: }
7946: }
7947: foreach my $field (keys(%{$cancreate{$item}})) {
1.228 ! raeburn 7948: if (ref($cancreate{$item}{$field}) eq 'HASH') {
! 7949: foreach my $inner (keys(%{$cancreate{$item}{$field}})) {
! 7950: if (ref($curr_usercreation{'cancreate'}{$item}{$field}) eq 'HASH') {
! 7951: unless ($curr_usercreation{'cancreate'}{$item}{$field}{$inner} eq $cancreate{$item}{$field}{$inner}) {
! 7952: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
! 7953: push(@{$changes{'cancreate'}},$item);
! 7954: }
! 7955: }
! 7956: } else {
! 7957: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
! 7958: push(@{$changes{'cancreate'}},$item);
! 7959: }
! 7960: }
! 7961: }
! 7962: } else {
! 7963: if (!$curr_usercreation{'cancreate'}{$item}{$field}) {
! 7964: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
! 7965: push(@{$changes{'cancreate'}},$item);
! 7966: }
1.224 raeburn 7967: }
7968: }
7969: }
7970: }
7971: } elsif ($curr_usercreation{'cancreate'}{$item}) {
7972: if (ref($cancreate{$item}) eq 'ARRAY') {
7973: if (!grep(/^\Q$curr_usercreation{'cancreate'}{$item}\E$/,@{$cancreate{$item}})) {
7974: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
7975: push(@{$changes{'cancreate'}},$item);
7976: }
7977: }
7978: } elsif (ref($cancreate{$item}) eq 'HASH') {
7979: if (!$cancreate{$item}{$curr_usercreation{'cancreate'}{$item}}) {
7980: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
7981: push(@{$changes{'cancreate'}},$item);
7982: }
7983: }
7984: }
7985: } elsif ($item eq 'emailusername') {
1.228 ! raeburn 7986: if (ref($cancreate{$item}) eq 'HASH') {
! 7987: foreach my $type (keys(%{$cancreate{$item}})) {
! 7988: if (ref($cancreate{$item}{$type}) eq 'HASH') {
! 7989: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
! 7990: if ($cancreate{$item}{$type}{$field}) {
! 7991: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
! 7992: push(@{$changes{'cancreate'}},$item);
! 7993: }
! 7994: last;
! 7995: }
! 7996: }
! 7997: }
! 7998: }
1.224 raeburn 7999: }
8000: }
8001: }
8002: #
8003: # Populate %save_usercreate hash with updates to self-creation configuration.
8004: #
8005: $save_usercreate{'cancreate'}{'captcha'} = $savecaptcha{'captcha'};
8006: $save_usercreate{'cancreate'}{'recaptchakeys'} = $savecaptcha{'recaptchakeys'};
8007: $save_usercreate{'cancreate'}{'selfcreate'} = $cancreate{'selfcreate'};
8008: if (ref($cancreate{'notify'}) eq 'HASH') {
8009: $save_usercreate{'cancreate'}{'notify'} = $cancreate{'notify'};
8010: }
8011: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
8012: $save_usercreate{'cancreate'}{'statustocreate'} = $cancreate{'statustocreate'};
8013: }
8014: $save_usercreate{'cancreate'}{'emailusername'} = $cancreate{'emailusername'};
8015: $save_usercreate{'emailrule'} = \@email_rule;
8016:
8017: my %userconfig_hash = (
8018: usercreation => \%save_usercreate,
8019: usermodification => \%save_usermodify,
8020: );
8021: my $putresult = &Apache::lonnet::put_dom('configuration',\%userconfig_hash,
8022: $dom);
8023: #
8024: # Accumulate details of changes to domain cofiguration for self-creation of usernames in $resulttext
8025: #
1.27 raeburn 8026: if ($putresult eq 'ok') {
8027: if (keys(%changes) > 0) {
8028: $resulttext = &mt('Changes made:').'<ul>';
8029: if (ref($changes{'cancreate'}) eq 'ARRAY') {
1.224 raeburn 8030: my %lt = &selfcreation_types();
1.34 raeburn 8031: foreach my $type (@{$changes{'cancreate'}}) {
1.100 raeburn 8032: my $chgtext;
1.45 raeburn 8033: if ($type eq 'selfcreate') {
1.50 raeburn 8034: if (@{$cancreate{$type}} == 0) {
1.224 raeburn 8035: $chgtext .= &mt('Self creation of a new user account is not permitted.');
1.50 raeburn 8036: } else {
1.224 raeburn 8037: $chgtext .= &mt('Self-creation of a new account is permitted for:').
8038: '<ul>';
1.50 raeburn 8039: foreach my $case (@{$cancreate{$type}}) {
8040: $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
8041: }
8042: $chgtext .= '</ul>';
1.100 raeburn 8043: if (ref($cancreate{$type}) eq 'ARRAY') {
8044: if (grep(/^(login|sso)$/,@{$cancreate{$type}})) {
8045: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
8046: if (@{$cancreate{'statustocreate'}} == 0) {
1.224 raeburn 8047: $chgtext .= '<br />'.
8048: '<span class="LC_warning">'.
8049: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
8050: '</span>';
1.100 raeburn 8051: }
8052: }
8053: }
8054: }
1.43 raeburn 8055: }
1.93 raeburn 8056: } elsif ($type eq 'statustocreate') {
1.96 raeburn 8057: if ((ref($cancreate{'selfcreate'}) eq 'ARRAY') &&
8058: (ref($cancreate{'statustocreate'}) eq 'ARRAY')) {
8059: if (@{$cancreate{'selfcreate'}} > 0) {
8060: if (@{$cancreate{'statustocreate'}} == 0) {
1.100 raeburn 8061: $chgtext .= &mt("Institutional affiliations permitted to create accounts set to 'None'.");
1.96 raeburn 8062: if (!grep(/^email$/,@{$cancreate{'selfcreate'}})) {
1.224 raeburn 8063: $chgtext .= '<br />'.
8064: '<span class="LC_warning">'.
8065: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
8066: '</span>';
8067: }
1.96 raeburn 8068: } elsif (ref($usertypes) eq 'HASH') {
8069: if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.100 raeburn 8070: $chgtext .= &mt('Creation of a new account for an institutional user is restricted to the following institutional affiliation(s):');
8071: } else {
8072: $chgtext .= &mt('Institutional affiliations permitted to create accounts with institutional authentication were set as follows:');
8073: }
8074: $chgtext .= '<ul>';
8075: foreach my $case (@{$cancreate{$type}}) {
8076: if ($case eq 'default') {
8077: $chgtext .= '<li>'.$othertitle.'</li>';
8078: } else {
8079: $chgtext .= '<li>'.$usertypes->{$case}.'</li>';
1.93 raeburn 8080: }
8081: }
1.100 raeburn 8082: $chgtext .= '</ul>';
8083: if (!grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.224 raeburn 8084: $chgtext .= '<br /><span class="LC_warning">'.
8085: &mt('However, users authenticated by institutional login/single sign on are not currently permitted to create accounts.').
8086: '</span>';
1.100 raeburn 8087: }
8088: }
8089: } else {
8090: if (@{$cancreate{$type}} == 0) {
8091: $chgtext .= &mt("Institutional affiliations permitted to create accounts were set to 'none'.");
8092: } else {
8093: $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 8094: }
8095: }
8096: }
1.165 raeburn 8097: } elsif ($type eq 'captcha') {
1.224 raeburn 8098: if ($savecaptcha{$type} eq 'notused') {
1.165 raeburn 8099: $chgtext .= &mt('No CAPTCHA validation in use for self-creation screen.');
8100: } else {
8101: my %captchas = &captcha_phrases();
1.224 raeburn 8102: if ($captchas{$savecaptcha{$type}}) {
8103: $chgtext .= &mt("Validation for self-creation screen set to $captchas{$savecaptcha{$type}}.");
1.165 raeburn 8104: } else {
1.210 raeburn 8105: $chgtext .= &mt('Validation for self-creation screen set to unknown type.');
1.165 raeburn 8106: }
8107: }
8108: } elsif ($type eq 'recaptchakeys') {
8109: my ($privkey,$pubkey);
1.224 raeburn 8110: if (ref($savecaptcha{$type}) eq 'HASH') {
8111: $pubkey = $savecaptcha{$type}{'public'};
8112: $privkey = $savecaptcha{$type}{'private'};
1.165 raeburn 8113: }
8114: $chgtext .= &mt('ReCAPTCHA keys changes').'<ul>';
8115: if (!$pubkey) {
8116: $chgtext .= '<li>'.&mt('Public key deleted').'</li>';
8117: } else {
8118: $chgtext .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
8119: }
8120: if (!$privkey) {
8121: $chgtext .= '<li>'.&mt('Private key deleted').'</li>';
8122: } else {
8123: $chgtext .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
8124: }
8125: $chgtext .= '</ul>';
1.224 raeburn 8126: } elsif ($type eq 'emailusername') {
8127: if (ref($cancreate{'emailusername'}) eq 'HASH') {
1.228 ! raeburn 8128: if (ref($types) eq 'ARRAY') {
! 8129: foreach my $type (@{$types}) {
! 8130: if (ref($cancreate{'emailusername'}{$type}) eq 'HASH') {
! 8131: if (keys(%{$cancreate{'emailusername'}{$type}}) > 0) {
! 8132: $chgtext .= &mt('When self-creating account with e-mail as username, the following information will be provided by [_1]:',$usertypes->{$type}).
! 8133: '<ul>';
! 8134: foreach my $field (@{$infofields}) {
! 8135: if ($cancreate{'emailusername'}{$type}{$field}) {
! 8136: $chgtext .= '<li>'.$infotitles->{$field}.'</li>';
! 8137: }
! 8138: }
! 8139: }
! 8140: $chgtext .= '</ul>';
! 8141: } else {
! 8142: $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 8143: }
8144: }
8145: }
8146: }
8147: } elsif ($type eq 'notify') {
8148: $chgtext = &mt('No Domain Coordinators will receive notification of username requests requiring approval.');
8149: if (ref($changes{'cancreate'}) eq 'ARRAY') {
8150: if ((grep(/^notify$/,@{$changes{'cancreate'}})) && (ref($cancreate{'notify'}) eq 'HASH')) {
8151: if ($cancreate{'notify'}{'approval'}) {
8152: $chgtext = &mt('Notification of username requests requiring approval will be sent to: ').$cancreate{'notify'}{'approval'};
8153: }
8154: }
1.43 raeburn 8155: }
1.34 raeburn 8156: }
1.224 raeburn 8157: if ($chgtext) {
8158: $resulttext .= '<li>'.$chgtext.'</li>';
1.32 raeburn 8159: }
8160: }
8161: }
1.43 raeburn 8162: if (ref($changes{'email_rule'}) eq 'ARRAY') {
8163: my ($emailrules,$emailruleorder) =
8164: &Apache::lonnet::inst_userrules($dom,'email');
8165: my $chgtext = '<ul>';
8166: foreach my $type (@email_rule) {
8167: if (ref($emailrules->{$type}) eq 'HASH') {
8168: $chgtext .= '<li>'.$emailrules->{$type}{'name'}.'</li>';
8169: }
8170: }
8171: $chgtext .= '</ul>';
8172: if (@email_rule > 0) {
1.224 raeburn 8173: $resulttext .= '<li>'.
8174: &mt('Accounts may not be created by users self-enrolling with e-mail addresses of the following types: ').
8175: $chgtext.
8176: '</li>';
1.43 raeburn 8177: } else {
1.224 raeburn 8178: $resulttext .= '<li>'.
8179: &mt('There are now no restrictions on e-mail addresses which may be used as a username when self-enrolling.').
8180: '</li>';
1.43 raeburn 8181: }
8182: }
1.224 raeburn 8183: if (ref($changes{'selfcreate'}) eq 'ARRAY') {
8184: $resulttext .= '<li>'.&mt('When self-creating institutional account:').'<ul>';
8185: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
8186: foreach my $type (@{$changes{'selfcreate'}}) {
8187: my $typename = $type;
8188: if (ref($usertypes) eq 'HASH') {
8189: if ($usertypes->{$type} ne '') {
8190: $typename = $usertypes->{$type};
8191: }
8192: }
8193: my @modifiable;
8194: $resulttext .= '<li>'.
8195: &mt('Self-creation of account by users with status: [_1]',
8196: '<span class="LC_cusr_emph">'.$typename.'</span>').
8197: ' - '.&mt('modifiable fields (if institutional data blank): ');
8198: foreach my $field (@fields) {
8199: if ($save_usermodify{'selfcreate'}{$type}{$field}) {
8200: push(@modifiable,'<b>'.$fieldtitles{$field}.'</b>');
1.28 raeburn 8201: }
8202: }
1.224 raeburn 8203: if (@modifiable > 0) {
8204: $resulttext .= join(', ',@modifiable);
1.43 raeburn 8205: } else {
1.224 raeburn 8206: $resulttext .= &mt('none');
1.43 raeburn 8207: }
1.224 raeburn 8208: $resulttext .= '</li>';
1.28 raeburn 8209: }
1.224 raeburn 8210: $resulttext .= '</ul></li>';
1.28 raeburn 8211: }
1.27 raeburn 8212: $resulttext .= '</ul>';
8213: } else {
1.224 raeburn 8214: $resulttext = &mt('No changes made to self-creation settings');
1.27 raeburn 8215: }
8216: } else {
8217: $resulttext = '<span class="LC_error">'.
1.23 raeburn 8218: &mt('An error occurred: [_1]',$putresult).'</span>';
8219: }
1.43 raeburn 8220: if ($warningmsg ne '') {
8221: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
8222: }
1.23 raeburn 8223: return $resulttext;
8224: }
8225:
1.165 raeburn 8226: sub process_captcha {
8227: my ($container,$changes,$newsettings,$current) = @_;
8228: return unless ((ref($changes) eq 'HASH') && (ref($newsettings) eq 'HASH') || (ref($current) eq 'HASH'));
8229: $newsettings->{'captcha'} = $env{'form.'.$container.'_captcha'};
8230: unless ($newsettings->{'captcha'} eq 'recaptcha' || $newsettings->{'captcha'} eq 'notused') {
8231: $newsettings->{'captcha'} = 'original';
8232: }
8233: if ($current->{'captcha'} ne $newsettings->{'captcha'}) {
1.210 raeburn 8234: if ($container eq 'cancreate') {
1.169 raeburn 8235: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
8236: push(@{$changes->{'cancreate'}},'captcha');
8237: } elsif (!defined($changes->{'cancreate'})) {
8238: $changes->{'cancreate'} = ['captcha'];
8239: }
8240: } else {
8241: $changes->{'captcha'} = 1;
1.165 raeburn 8242: }
8243: }
8244: my ($newpub,$newpriv,$currpub,$currpriv);
8245: if ($newsettings->{'captcha'} eq 'recaptcha') {
8246: $newpub = $env{'form.'.$container.'_recaptchapub'};
8247: $newpriv = $env{'form.'.$container.'_recaptchapriv'};
1.169 raeburn 8248: $newpub =~ s/\W//g;
8249: $newpriv =~ s/\W//g;
8250: $newsettings->{'recaptchakeys'} = {
8251: public => $newpub,
8252: private => $newpriv,
8253: };
1.165 raeburn 8254: }
8255: if (ref($current->{'recaptchakeys'}) eq 'HASH') {
8256: $currpub = $current->{'recaptchakeys'}{'public'};
8257: $currpriv = $current->{'recaptchakeys'}{'private'};
1.179 raeburn 8258: unless ($newsettings->{'captcha'} eq 'recaptcha') {
8259: $newsettings->{'recaptchakeys'} = {
8260: public => '',
8261: private => '',
8262: }
8263: }
1.165 raeburn 8264: }
8265: if (($newpub ne $currpub) || ($newpriv ne $currpriv)) {
1.169 raeburn 8266: if ($container eq 'cancreate') {
8267: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
8268: push(@{$changes->{'cancreate'}},'recaptchakeys');
8269: } elsif (!defined($changes->{'cancreate'})) {
8270: $changes->{'cancreate'} = ['recaptchakeys'];
8271: }
8272: } else {
1.210 raeburn 8273: $changes->{'recaptchakeys'} = 1;
1.165 raeburn 8274: }
8275: }
8276: return;
8277: }
8278:
1.33 raeburn 8279: sub modify_usermodification {
8280: my ($dom,%domconfig) = @_;
1.224 raeburn 8281: my ($resulttext,%curr_usermodification,%changes,%modifyhash);
1.33 raeburn 8282: if (ref($domconfig{'usermodification'}) eq 'HASH') {
8283: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
1.224 raeburn 8284: if ($key eq 'selfcreate') {
8285: $modifyhash{$key} = $domconfig{'usermodification'}{$key};
8286: } else {
8287: $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
8288: }
1.33 raeburn 8289: }
8290: }
1.224 raeburn 8291: my @contexts = ('author','course');
1.33 raeburn 8292: my %context_title = (
8293: author => 'In author context',
8294: course => 'In course context',
8295: );
8296: my @fields = ('lastname','firstname','middlename','generation',
8297: 'permanentemail','id');
8298: my %roles = (
8299: author => ['ca','aa'],
8300: course => ['st','ep','ta','in','cr'],
8301: );
8302: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
8303: foreach my $context (@contexts) {
8304: foreach my $role (@{$roles{$context}}) {
8305: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$role);
8306: foreach my $item (@fields) {
8307: if (grep(/^\Q$item\E$/,@modifiable)) {
8308: $modifyhash{$context}{$role}{$item} = 1;
8309: } else {
8310: $modifyhash{$context}{$role}{$item} = 0;
8311: }
8312: }
8313: }
8314: if (ref($curr_usermodification{$context}) eq 'HASH') {
8315: foreach my $role (@{$roles{$context}}) {
8316: if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
8317: foreach my $field (@fields) {
8318: if ($modifyhash{$context}{$role}{$field} ne
8319: $curr_usermodification{$context}{$role}{$field}) {
8320: push(@{$changes{$context}},$role);
8321: last;
8322: }
8323: }
8324: }
8325: }
8326: } else {
8327: foreach my $context (@contexts) {
8328: foreach my $role (@{$roles{$context}}) {
8329: push(@{$changes{$context}},$role);
8330: }
8331: }
8332: }
8333: }
8334: my %usermodification_hash = (
8335: usermodification => \%modifyhash,
8336: );
8337: my $putresult = &Apache::lonnet::put_dom('configuration',
8338: \%usermodification_hash,$dom);
8339: if ($putresult eq 'ok') {
8340: if (keys(%changes) > 0) {
8341: $resulttext = &mt('Changes made: ').'<ul>';
8342: foreach my $context (@contexts) {
8343: if (ref($changes{$context}) eq 'ARRAY') {
8344: $resulttext .= '<li>'.$context_title{$context}.':<ul>';
8345: if (ref($changes{$context}) eq 'ARRAY') {
8346: foreach my $role (@{$changes{$context}}) {
8347: my $rolename;
1.224 raeburn 8348: if ($role eq 'cr') {
8349: $rolename = &mt('Custom');
1.33 raeburn 8350: } else {
1.224 raeburn 8351: $rolename = &Apache::lonnet::plaintext($role);
1.33 raeburn 8352: }
8353: my @modifiable;
1.224 raeburn 8354: $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
1.33 raeburn 8355: foreach my $field (@fields) {
8356: if ($modifyhash{$context}{$role}{$field}) {
8357: push(@modifiable,$fieldtitles{$field});
8358: }
8359: }
8360: if (@modifiable > 0) {
8361: $resulttext .= join(', ',@modifiable);
8362: } else {
8363: $resulttext .= &mt('none');
8364: }
8365: $resulttext .= '</li>';
8366: }
8367: $resulttext .= '</ul></li>';
8368: }
8369: }
8370: }
8371: $resulttext .= '</ul>';
8372: } else {
8373: $resulttext = &mt('No changes made to user modification settings');
8374: }
8375: } else {
8376: $resulttext = '<span class="LC_error">'.
8377: &mt('An error occurred: [_1]',$putresult).'</span>';
8378: }
8379: return $resulttext;
8380: }
8381:
1.43 raeburn 8382: sub modify_defaults {
1.212 raeburn 8383: my ($dom,$lastactref,%domconfig) = @_;
1.43 raeburn 8384: my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
1.212 raeburn 8385: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.141 raeburn 8386: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def','portal_def');
1.43 raeburn 8387: my @authtypes = ('internal','krb4','krb5','localauth');
8388: foreach my $item (@items) {
8389: $newvalues{$item} = $env{'form.'.$item};
8390: if ($item eq 'auth_def') {
8391: if ($newvalues{$item} ne '') {
8392: if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
8393: push(@errors,$item);
8394: }
8395: }
8396: } elsif ($item eq 'lang_def') {
8397: if ($newvalues{$item} ne '') {
8398: if ($newvalues{$item} =~ /^(\w+)/) {
8399: my $langcode = $1;
1.103 raeburn 8400: if ($langcode ne 'x_chef') {
8401: if (code2language($langcode) eq '') {
8402: push(@errors,$item);
8403: }
1.43 raeburn 8404: }
8405: } else {
8406: push(@errors,$item);
8407: }
8408: }
1.54 raeburn 8409: } elsif ($item eq 'timezone_def') {
8410: if ($newvalues{$item} ne '') {
1.62 raeburn 8411: if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
1.54 raeburn 8412: push(@errors,$item);
8413: }
8414: }
1.68 raeburn 8415: } elsif ($item eq 'datelocale_def') {
8416: if ($newvalues{$item} ne '') {
8417: my @datelocale_ids = DateTime::Locale->ids();
8418: if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
8419: push(@errors,$item);
8420: }
8421: }
1.141 raeburn 8422: } elsif ($item eq 'portal_def') {
8423: if ($newvalues{$item} ne '') {
8424: 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])\/?$/) {
8425: push(@errors,$item);
8426: }
8427: }
1.43 raeburn 8428: }
8429: if (grep(/^\Q$item\E$/,@errors)) {
8430: $newvalues{$item} = $domdefaults{$item};
8431: } elsif ($domdefaults{$item} ne $newvalues{$item}) {
8432: $changes{$item} = 1;
8433: }
1.72 raeburn 8434: $domdefaults{$item} = $newvalues{$item};
1.43 raeburn 8435: }
8436: my %defaults_hash = (
1.72 raeburn 8437: defaults => \%newvalues,
8438: );
1.43 raeburn 8439: my $title = &defaults_titles();
8440: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
8441: $dom);
8442: if ($putresult eq 'ok') {
8443: if (keys(%changes) > 0) {
8444: $resulttext = &mt('Changes made:').'<ul>';
1.212 raeburn 8445: my $version = &Apache::lonnet::get_server_loncaparev($dom);
1.43 raeburn 8446: 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";
8447: foreach my $item (sort(keys(%changes))) {
8448: my $value = $env{'form.'.$item};
8449: if ($value eq '') {
8450: $value = &mt('none');
8451: } elsif ($item eq 'auth_def') {
8452: my %authnames = &authtype_names();
8453: my %shortauth = (
8454: internal => 'int',
8455: krb4 => 'krb4',
8456: krb5 => 'krb5',
8457: localauth => 'loc',
8458: );
8459: $value = $authnames{$shortauth{$value}};
8460: }
8461: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
8462: $mailmsgtext .= "$title->{$item} set to $value\n";
8463: }
8464: $resulttext .= '</ul>';
8465: $mailmsgtext .= "\n";
8466: my $cachetime = 24*60*60;
1.72 raeburn 8467: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 8468: if (ref($lastactref) eq 'HASH') {
8469: $lastactref->{'domdefaults'} = 1;
8470: }
1.68 raeburn 8471: if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
1.203 raeburn 8472: my $notify = 1;
8473: if (ref($domconfig{'contacts'}) eq 'HASH') {
8474: if ($domconfig{'contacts'}{'reportupdates'} == 0) {
8475: $notify = 0;
8476: }
8477: }
8478: if ($notify) {
8479: &Apache::lonmsg::sendemail('installrecord@loncapa.org',
8480: "LON-CAPA Domain Settings Change - $dom",
8481: $mailmsgtext);
8482: }
1.54 raeburn 8483: }
1.43 raeburn 8484: } else {
1.54 raeburn 8485: $resulttext = &mt('No changes made to default authentication/language/timezone settings');
1.43 raeburn 8486: }
8487: } else {
8488: $resulttext = '<span class="LC_error">'.
8489: &mt('An error occurred: [_1]',$putresult).'</span>';
8490: }
8491: if (@errors > 0) {
8492: $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
8493: foreach my $item (@errors) {
8494: $resulttext .= ' "'.$title->{$item}.'",';
8495: }
8496: $resulttext =~ s/,$//;
8497: }
8498: return $resulttext;
8499: }
8500:
1.46 raeburn 8501: sub modify_scantron {
1.205 raeburn 8502: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.46 raeburn 8503: my ($resulttext,%confhash,%changes,$errors);
8504: my $custom = 'custom.tab';
8505: my $default = 'default.tab';
8506: my $servadm = $r->dir_config('lonAdmEMail');
8507: my ($configuserok,$author_ok,$switchserver) =
8508: &config_check($dom,$confname,$servadm);
8509: if ($env{'form.scantronformat.filename'} ne '') {
8510: my $error;
8511: if ($configuserok eq 'ok') {
8512: if ($switchserver) {
1.130 raeburn 8513: $error = &mt("Upload of bubblesheet format file is not permitted to this server: [_1]",$switchserver);
1.46 raeburn 8514: } else {
8515: if ($author_ok eq 'ok') {
8516: my ($result,$scantronurl) =
8517: &publishlogo($r,'upload','scantronformat',$dom,
8518: $confname,'scantron','','',$custom);
8519: if ($result eq 'ok') {
8520: $confhash{'scantron'}{'scantronformat'} = $scantronurl;
1.48 raeburn 8521: $changes{'scantronformat'} = 1;
1.46 raeburn 8522: } else {
8523: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
8524: }
8525: } else {
8526: $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);
8527: }
8528: }
8529: } else {
8530: $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);
8531: }
8532: if ($error) {
8533: &Apache::lonnet::logthis($error);
8534: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
8535: }
8536: }
1.48 raeburn 8537: if (ref($domconfig{'scantron'}) eq 'HASH') {
8538: if ($domconfig{'scantron'}{'scantronformat'} ne '') {
8539: if ($env{'form.scantronformat_del'}) {
8540: $confhash{'scantron'}{'scantronformat'} = '';
8541: $changes{'scantronformat'} = 1;
1.46 raeburn 8542: }
8543: }
8544: }
8545: if (keys(%confhash) > 0) {
8546: my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
8547: $dom);
8548: if ($putresult eq 'ok') {
8549: if (keys(%changes) > 0) {
1.48 raeburn 8550: if (ref($confhash{'scantron'}) eq 'HASH') {
8551: $resulttext = &mt('Changes made:').'<ul>';
8552: if ($confhash{'scantron'}{'scantronformat'} eq '') {
1.130 raeburn 8553: $resulttext .= '<li>'.&mt('[_1] bubblesheet format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
1.48 raeburn 8554: } else {
1.130 raeburn 8555: $resulttext .= '<li>'.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
1.46 raeburn 8556: }
1.48 raeburn 8557: $resulttext .= '</ul>';
8558: } else {
1.130 raeburn 8559: $resulttext = &mt('Changes made to bubblesheet format file.');
1.46 raeburn 8560: }
8561: $resulttext .= '</ul>';
8562: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 8563: if (ref($lastactref) eq 'HASH') {
8564: $lastactref->{'domainconfig'} = 1;
8565: }
1.46 raeburn 8566: } else {
1.130 raeburn 8567: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 8568: }
8569: } else {
8570: $resulttext = '<span class="LC_error">'.
8571: &mt('An error occurred: [_1]',$putresult).'</span>';
8572: }
8573: } else {
1.130 raeburn 8574: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 8575: }
8576: if ($errors) {
8577: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
8578: $errors.'</ul>';
8579: }
8580: return $resulttext;
8581: }
8582:
1.48 raeburn 8583: sub modify_coursecategories {
8584: my ($dom,%domconfig) = @_;
1.57 raeburn 8585: my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
8586: $cathash);
1.48 raeburn 8587: my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
1.55 raeburn 8588: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
1.57 raeburn 8589: $cathash = $domconfig{'coursecategories'}{'cats'};
8590: if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
8591: $changes{'togglecats'} = 1;
8592: $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
8593: }
8594: if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
8595: $changes{'categorize'} = 1;
8596: $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
8597: }
1.120 raeburn 8598: if ($domconfig{'coursecategories'}{'togglecatscomm'} ne $env{'form.togglecatscomm'}) {
8599: $changes{'togglecatscomm'} = 1;
8600: $domconfig{'coursecategories'}{'togglecatscomm'} = $env{'form.togglecatscomm'};
8601: }
8602: if ($domconfig{'coursecategories'}{'categorizecomm'} ne $env{'form.categorizecomm'}) {
8603: $changes{'categorizecomm'} = 1;
8604: $domconfig{'coursecategories'}{'categorizecomm'} = $env{'form.categorizecomm'};
8605: }
1.57 raeburn 8606: } else {
8607: $changes{'togglecats'} = 1;
8608: $changes{'categorize'} = 1;
1.124 raeburn 8609: $changes{'togglecatscomm'} = 1;
8610: $changes{'categorizecomm'} = 1;
1.87 raeburn 8611: $domconfig{'coursecategories'} = {
8612: togglecats => $env{'form.togglecats'},
8613: categorize => $env{'form.categorize'},
1.124 raeburn 8614: togglecatscomm => $env{'form.togglecatscomm'},
8615: categorizecomm => $env{'form.categorizecomm'},
1.120 raeburn 8616: };
1.57 raeburn 8617: }
8618: if (ref($cathash) eq 'HASH') {
8619: if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '') && ($env{'form.instcode'} == 0)) {
1.55 raeburn 8620: push (@deletecategory,'instcode::0');
8621: }
1.120 raeburn 8622: if (($domconfig{'coursecategories'}{'cats'}{'communities::0'} ne '') && ($env{'form.communities'} == 0)) {
8623: push(@deletecategory,'communities::0');
8624: }
1.48 raeburn 8625: }
1.57 raeburn 8626: my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
8627: if (ref($cathash) eq 'HASH') {
1.48 raeburn 8628: if (@deletecategory > 0) {
8629: #FIXME Need to remove category from all courses using a deleted category
1.57 raeburn 8630: &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
1.48 raeburn 8631: foreach my $item (@deletecategory) {
1.57 raeburn 8632: if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
8633: delete($domconfig{'coursecategories'}{'cats'}{$item});
1.48 raeburn 8634: $deletions{$item} = 1;
1.57 raeburn 8635: &recurse_cat_deletes($item,$cathash,\%deletions);
1.48 raeburn 8636: }
8637: }
8638: }
1.57 raeburn 8639: foreach my $item (keys(%{$cathash})) {
1.48 raeburn 8640: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
1.57 raeburn 8641: if ($cathash->{$item} ne $env{'form.'.$item}) {
1.48 raeburn 8642: $reorderings{$item} = 1;
1.57 raeburn 8643: $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
1.48 raeburn 8644: }
8645: if ($env{'form.addcategory_name_'.$item} ne '') {
8646: my $newcat = $env{'form.addcategory_name_'.$item};
8647: my $newdepth = $depth+1;
8648: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 8649: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
1.48 raeburn 8650: $adds{$newitem} = 1;
8651: }
8652: if ($env{'form.subcat_'.$item} ne '') {
8653: my $newcat = $env{'form.subcat_'.$item};
8654: my $newdepth = $depth+1;
8655: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 8656: $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
1.48 raeburn 8657: $adds{$newitem} = 1;
8658: }
8659: }
8660: }
8661: if ($env{'form.instcode'} eq '1') {
1.57 raeburn 8662: if (ref($cathash) eq 'HASH') {
1.48 raeburn 8663: my $newitem = 'instcode::0';
1.57 raeburn 8664: if ($cathash->{$newitem} eq '') {
8665: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 8666: $adds{$newitem} = 1;
8667: }
8668: } else {
8669: my $newitem = 'instcode::0';
1.57 raeburn 8670: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 8671: $adds{$newitem} = 1;
8672: }
8673: }
1.120 raeburn 8674: if ($env{'form.communities'} eq '1') {
8675: if (ref($cathash) eq 'HASH') {
8676: my $newitem = 'communities::0';
8677: if ($cathash->{$newitem} eq '') {
8678: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
8679: $adds{$newitem} = 1;
8680: }
8681: } else {
8682: my $newitem = 'communities::0';
8683: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
8684: $adds{$newitem} = 1;
8685: }
8686: }
1.48 raeburn 8687: if ($env{'form.addcategory_name'} ne '') {
1.120 raeburn 8688: if (($env{'form.addcategory_name'} ne 'instcode') &&
8689: ($env{'form.addcategory_name'} ne 'communities')) {
8690: my $newitem = &escape($env{'form.addcategory_name'}).'::0';
8691: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
8692: $adds{$newitem} = 1;
8693: }
1.48 raeburn 8694: }
1.57 raeburn 8695: my $putresult;
1.48 raeburn 8696: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
8697: if (keys(%deletions) > 0) {
8698: foreach my $key (keys(%deletions)) {
8699: if ($predelallitems{$key} ne '') {
8700: $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
8701: }
8702: }
8703: }
8704: my (@chkcats,@chktrails,%chkallitems);
1.57 raeburn 8705: &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
1.48 raeburn 8706: if (ref($chkcats[0]) eq 'ARRAY') {
8707: my $depth = 0;
8708: my $chg = 0;
8709: for (my $i=0; $i<@{$chkcats[0]}; $i++) {
8710: my $name = $chkcats[0][$i];
8711: my $item;
8712: if ($name eq '') {
8713: $chg ++;
8714: } else {
8715: $item = &escape($name).'::0';
8716: if ($chg) {
1.57 raeburn 8717: $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
1.48 raeburn 8718: }
8719: $depth ++;
1.57 raeburn 8720: &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
1.48 raeburn 8721: $depth --;
8722: }
8723: }
8724: }
1.57 raeburn 8725: }
8726: if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
8727: $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
1.48 raeburn 8728: if ($putresult eq 'ok') {
1.57 raeburn 8729: my %title = (
1.120 raeburn 8730: togglecats => 'Show/Hide a course in catalog',
8731: categorize => 'Assign a category to a course',
8732: togglecatscomm => 'Show/Hide a community in catalog',
8733: categorizecomm => 'Assign a category to a community',
1.57 raeburn 8734: );
8735: my %level = (
1.120 raeburn 8736: dom => 'set in Domain ("Modify Course/Community")',
8737: crs => 'set in Course ("Course Configuration")',
8738: comm => 'set in Community ("Community Configuration")',
1.57 raeburn 8739: );
1.48 raeburn 8740: $resulttext = &mt('Changes made:').'<ul>';
1.57 raeburn 8741: if ($changes{'togglecats'}) {
8742: $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>';
8743: }
8744: if ($changes{'categorize'}) {
8745: $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
1.48 raeburn 8746: }
1.120 raeburn 8747: if ($changes{'togglecatscomm'}) {
8748: $resulttext .= '<li>'.&mt("$title{'togglecatscomm'} $level{$env{'form.togglecatscomm'}}").'</li>';
8749: }
8750: if ($changes{'categorizecomm'}) {
8751: $resulttext .= '<li>'.&mt("$title{'categorizecomm'} $level{$env{'form.categorizecomm'}}").'</li>';
8752: }
1.57 raeburn 8753: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
8754: my $cathash;
8755: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
8756: $cathash = $domconfig{'coursecategories'}{'cats'};
8757: } else {
8758: $cathash = {};
8759: }
8760: my (@cats,@trails,%allitems);
8761: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
8762: if (keys(%deletions) > 0) {
8763: $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
8764: foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) {
8765: $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
8766: }
8767: $resulttext .= '</ul></li>';
8768: }
8769: if (keys(%reorderings) > 0) {
8770: my %sort_by_trail;
8771: $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
8772: foreach my $key (keys(%reorderings)) {
8773: if ($allitems{$key} ne '') {
8774: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
8775: }
1.48 raeburn 8776: }
1.57 raeburn 8777: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
8778: $resulttext .= '<li>'.$trails[$trail].'</li>';
8779: }
8780: $resulttext .= '</ul></li>';
1.48 raeburn 8781: }
1.57 raeburn 8782: if (keys(%adds) > 0) {
8783: my %sort_by_trail;
8784: $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
8785: foreach my $key (keys(%adds)) {
8786: if ($allitems{$key} ne '') {
8787: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
8788: }
8789: }
8790: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
8791: $resulttext .= '<li>'.$trails[$trail].'</li>';
1.48 raeburn 8792: }
1.57 raeburn 8793: $resulttext .= '</ul></li>';
1.48 raeburn 8794: }
8795: }
8796: $resulttext .= '</ul>';
8797: } else {
8798: $resulttext = '<span class="LC_error">'.
1.57 raeburn 8799: &mt('An error occurred: [_1]',$putresult).'</span>';
1.48 raeburn 8800: }
8801: } else {
1.120 raeburn 8802: $resulttext = &mt('No changes made to course and community categories');
1.48 raeburn 8803: }
8804: return $resulttext;
8805: }
8806:
1.69 raeburn 8807: sub modify_serverstatuses {
8808: my ($dom,%domconfig) = @_;
8809: my ($resulttext,%changes,%currserverstatus,%newserverstatus);
8810: if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
8811: %currserverstatus = %{$domconfig{'serverstatuses'}};
8812: }
8813: my @pages = &serverstatus_pages();
8814: foreach my $type (@pages) {
8815: $newserverstatus{$type}{'namedusers'} = '';
8816: $newserverstatus{$type}{'machines'} = '';
8817: if (defined($env{'form.'.$type.'_namedusers'})) {
8818: my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
8819: my @okusers;
8820: foreach my $user (@users) {
8821: my ($uname,$udom) = split(/:/,$user);
8822: if (($udom =~ /^$match_domain$/) &&
8823: (&Apache::lonnet::domain($udom)) &&
8824: ($uname =~ /^$match_username$/)) {
8825: if (!grep(/^\Q$user\E/,@okusers)) {
8826: push(@okusers,$user);
8827: }
8828: }
8829: }
8830: if (@okusers > 0) {
8831: @okusers = sort(@okusers);
8832: $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
8833: }
8834: }
8835: if (defined($env{'form.'.$type.'_machines'})) {
8836: my @machines = split(/,/,$env{'form.'.$type.'_machines'});
8837: my @okmachines;
8838: foreach my $ip (@machines) {
8839: my @parts = split(/\./,$ip);
8840: next if (@parts < 4);
8841: my $badip = 0;
8842: for (my $i=0; $i<4; $i++) {
8843: if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
8844: $badip = 1;
8845: last;
8846: }
8847: }
8848: if (!$badip) {
8849: push(@okmachines,$ip);
8850: }
8851: }
8852: @okmachines = sort(@okmachines);
8853: $newserverstatus{$type}{'machines'} = join(',',@okmachines);
8854: }
8855: }
8856: my %serverstatushash = (
8857: serverstatuses => \%newserverstatus,
8858: );
8859: foreach my $type (@pages) {
1.83 raeburn 8860: foreach my $setting ('namedusers','machines') {
1.84 raeburn 8861: my (@current,@new);
1.83 raeburn 8862: if (ref($currserverstatus{$type}) eq 'HASH') {
1.84 raeburn 8863: if ($currserverstatus{$type}{$setting} ne '') {
8864: @current = split(/,/,$currserverstatus{$type}{$setting});
8865: }
8866: }
8867: if ($newserverstatus{$type}{$setting} ne '') {
8868: @new = split(/,/,$newserverstatus{$type}{$setting});
1.83 raeburn 8869: }
8870: if (@current > 0) {
8871: if (@new > 0) {
8872: foreach my $item (@current) {
8873: if (!grep(/^\Q$item\E$/,@new)) {
8874: $changes{$type}{$setting} = 1;
1.82 raeburn 8875: last;
8876: }
8877: }
1.84 raeburn 8878: foreach my $item (@new) {
8879: if (!grep(/^\Q$item\E$/,@current)) {
8880: $changes{$type}{$setting} = 1;
8881: last;
1.82 raeburn 8882: }
8883: }
8884: } else {
1.83 raeburn 8885: $changes{$type}{$setting} = 1;
1.69 raeburn 8886: }
1.83 raeburn 8887: } elsif (@new > 0) {
8888: $changes{$type}{$setting} = 1;
1.69 raeburn 8889: }
8890: }
8891: }
8892: if (keys(%changes) > 0) {
1.81 raeburn 8893: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 8894: my $putresult = &Apache::lonnet::put_dom('configuration',
8895: \%serverstatushash,$dom);
8896: if ($putresult eq 'ok') {
8897: $resulttext .= &mt('Changes made:').'<ul>';
8898: foreach my $type (@pages) {
1.84 raeburn 8899: if (ref($changes{$type}) eq 'HASH') {
1.69 raeburn 8900: $resulttext .= '<li>'.$titles->{$type}.'<ul>';
1.84 raeburn 8901: if ($changes{$type}{'namedusers'}) {
1.69 raeburn 8902: if ($newserverstatus{$type}{'namedusers'} eq '') {
8903: $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n";
8904: } else {
8905: $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n";
8906: }
1.84 raeburn 8907: }
8908: if ($changes{$type}{'machines'}) {
1.69 raeburn 8909: if ($newserverstatus{$type}{'machines'} eq '') {
8910: $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n";
8911: } else {
8912: $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n";
8913: }
8914:
8915: }
8916: $resulttext .= '</ul></li>';
8917: }
8918: }
8919: $resulttext .= '</ul>';
8920: } else {
8921: $resulttext = '<span class="LC_error">'.
8922: &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>';
8923:
8924: }
8925: } else {
8926: $resulttext = &mt('No changes made to access to server status pages');
8927: }
8928: return $resulttext;
8929: }
8930:
1.118 jms 8931: sub modify_helpsettings {
1.122 jms 8932: my ($r,$dom,$confname,%domconfig) = @_;
1.166 raeburn 8933: my ($resulttext,$errors,%changes,%helphash);
8934: my %defaultchecked = ('submitbugs' => 'on');
8935: my @offon = ('off','on');
1.118 jms 8936: my @toggles = ('submitbugs');
8937: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
8938: foreach my $item (@toggles) {
1.166 raeburn 8939: if ($defaultchecked{$item} eq 'on') {
8940: if ($domconfig{'helpsettings'}{$item} eq '') {
8941: if ($env{'form.'.$item} eq '0') {
8942: $changes{$item} = 1;
8943: }
8944: } elsif ($domconfig{'helpsettings'}{$item} ne $env{'form.'.$item}) {
8945: $changes{$item} = 1;
8946: }
8947: } elsif ($defaultchecked{$item} eq 'off') {
8948: if ($domconfig{'helpsettings'}{$item} eq '') {
8949: if ($env{'form.'.$item} eq '1') {
8950: $changes{$item} = 1;
8951: }
8952: } elsif ($domconfig{'helpsettings'}{$item} ne $env{'form.'.$item}) {
8953: $changes{$item} = 1;
8954: }
8955: }
1.210 raeburn 8956: if (($env{'form.'.$item} eq '0') || ($env{'form.'.$item} eq '1')) {
1.166 raeburn 8957: $helphash{'helpsettings'}{$item} = $env{'form.'.$item};
8958: }
8959: }
1.118 jms 8960: }
1.123 jms 8961: my $putresult;
8962: if (keys(%changes) > 0) {
1.166 raeburn 8963: $putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom);
1.168 raeburn 8964: if ($putresult eq 'ok') {
1.166 raeburn 8965: $resulttext = &mt('Changes made:').'<ul>';
8966: foreach my $item (sort(keys(%changes))) {
8967: if ($item eq 'submitbugs') {
8968: $resulttext .= '<li>'.&mt('Display link to: [_1] set to "'.$offon[$env{'form.'.$item}].'".',
8969: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
8970: &mt('LON-CAPA bug tracker'),600,500)).'</li>';
8971: }
8972: }
8973: $resulttext .= '</ul>';
8974: } else {
8975: $resulttext = &mt('No changes made to help settings');
1.168 raeburn 8976: $errors .= '<li><span class="LC_error">'.
8977: &mt('An error occurred storing the settings: [_1]',
8978: $putresult).'</span></li>';
1.166 raeburn 8979: }
1.118 jms 8980: }
8981: if ($errors) {
1.168 raeburn 8982: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.118 jms 8983: $errors.'</ul>';
8984: }
8985: return $resulttext;
8986: }
8987:
1.121 raeburn 8988: sub modify_coursedefaults {
1.212 raeburn 8989: my ($dom,$lastactref,%domconfig) = @_;
1.121 raeburn 8990: my ($resulttext,$errors,%changes,%defaultshash);
8991: my %defaultchecked = ('canuse_pdfforms' => 'off');
8992: my @toggles = ('canuse_pdfforms');
1.198 raeburn 8993: my @numbers = ('anonsurvey_threshold','uploadquota_official','uploadquota_unofficial',
1.216 raeburn 8994: 'uploadquota_community','uploadquota_textbook');
8995: my @types = ('official','unofficial','community','textbook');
1.198 raeburn 8996: my %staticdefaults = (
8997: anonsurvey_threshold => 10,
8998: uploadquota => 500,
8999: );
1.121 raeburn 9000:
9001: $defaultshash{'coursedefaults'} = {};
9002:
9003: if (ref($domconfig{'coursedefaults'}) ne 'HASH') {
9004: if ($domconfig{'coursedefaults'} eq '') {
9005: $domconfig{'coursedefaults'} = {};
9006: }
9007: }
9008:
9009: if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
9010: foreach my $item (@toggles) {
9011: if ($defaultchecked{$item} eq 'on') {
9012: if (($domconfig{'coursedefaults'}{$item} eq '') &&
9013: ($env{'form.'.$item} eq '0')) {
9014: $changes{$item} = 1;
1.192 raeburn 9015: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
1.121 raeburn 9016: $changes{$item} = 1;
9017: }
9018: } elsif ($defaultchecked{$item} eq 'off') {
9019: if (($domconfig{'coursedefaults'}{$item} eq '') &&
9020: ($env{'form.'.$item} eq '1')) {
9021: $changes{$item} = 1;
9022: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
9023: $changes{$item} = 1;
9024: }
9025: }
9026: $defaultshash{'coursedefaults'}{$item} = $env{'form.'.$item};
9027: }
1.198 raeburn 9028: foreach my $item (@numbers) {
9029: my ($currdef,$newdef);
1.208 raeburn 9030: $newdef = $env{'form.'.$item};
1.198 raeburn 9031: if ($item eq 'anonsurvey_threshold') {
9032: $currdef = $domconfig{'coursedefaults'}{$item};
9033: $newdef =~ s/\D//g;
9034: if ($newdef eq '' || $newdef < 1) {
9035: $newdef = 1;
9036: }
9037: $defaultshash{'coursedefaults'}{$item} = $newdef;
9038: } else {
9039: my ($type) = ($item =~ /^\Quploadquota_\E(\w+)$/);
9040: if (ref($domconfig{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
9041: $currdef = $domconfig{'coursedefaults'}{'uploadquota'}{$type};
9042: }
9043: $newdef =~ s/[^\w.\-]//g;
9044: $defaultshash{'coursedefaults'}{'uploadquota'}{$type} = $newdef;
9045: }
9046: if ($currdef ne $newdef) {
9047: my $staticdef;
9048: if ($item eq 'anonsurvey_threshold') {
9049: unless (($currdef eq '') && ($newdef == $staticdefaults{$item})) {
9050: $changes{$item} = 1;
9051: }
9052: } else {
9053: unless (($currdef eq '') && ($newdef == $staticdefaults{'uploadquota'})) {
9054: $changes{'uploadquota'} = 1;
9055: }
9056: }
1.139 raeburn 9057: }
9058: }
1.192 raeburn 9059: my $officialcreds = $env{'form.official_credits'};
1.216 raeburn 9060: $officialcreds =~ s/[^\d.]+//g;
1.192 raeburn 9061: my $unofficialcreds = $env{'form.unofficial_credits'};
1.216 raeburn 9062: $unofficialcreds =~ s/[^\d.]+//g;
9063: my $textbookcreds = $env{'form.textbook_credits'};
9064: $textbookcreds =~ s/[^\d.]+//g;
1.192 raeburn 9065: if (ref($domconfig{'coursedefaults'}{'coursecredits'} ne 'HASH') &&
9066: ($env{'form.coursecredits'} eq '1')) {
9067: $changes{'coursecredits'} = 1;
9068: } else {
9069: if (($domconfig{'coursedefaults'}{'coursecredits'}{'official'} ne $officialcreds) ||
1.216 raeburn 9070: ($domconfig{'coursedefaults'}{'coursecredits'}{'unofficial'} ne $unofficialcreds) ||
9071: ($domconfig{'coursedefaults'}{'coursecredits'}{'textbook'} ne $textbookcreds)) {
1.192 raeburn 9072: $changes{'coursecredits'} = 1;
9073: }
9074: }
9075: $defaultshash{'coursedefaults'}{'coursecredits'} = {
9076: official => $officialcreds,
9077: unofficial => $unofficialcreds,
1.216 raeburn 9078: textbook => $textbookcreds,
1.192 raeburn 9079: }
1.121 raeburn 9080: }
9081: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
9082: $dom);
9083: if ($putresult eq 'ok') {
9084: if (keys(%changes) > 0) {
1.213 raeburn 9085: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.198 raeburn 9086: if (($changes{'canuse_pdfforms'}) || ($changes{'coursecredits'}) || ($changes{'uploadquota'})) {
1.192 raeburn 9087: if ($changes{'canuse_pdfforms'}) {
9088: $domdefaults{'canuse_pdfforms'}=$defaultshash{'coursedefaults'}{'canuse_pdfforms'};
9089: }
9090: if ($changes{'coursecredits'}) {
9091: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
9092: $domdefaults{'officialcredits'} =
9093: $defaultshash{'coursedefaults'}{'coursecredits'}{'official'};
9094: $domdefaults{'unofficialcredits'} =
9095: $defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'};
1.216 raeburn 9096: $domdefaults{'textbookcredits'} =
9097: $domdefaults{'coursedefaults'}{'coursecredits'}{'textbook'};
1.192 raeburn 9098: }
9099: }
1.198 raeburn 9100: if ($changes{'uploadquota'}) {
9101: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
9102: foreach my $type (@types) {
9103: $domdefaults{$type.'quota'}=$defaultshash{'coursedefaults'}{'uploadquota'}{$type};
9104: }
9105: }
9106: }
1.121 raeburn 9107: my $cachetime = 24*60*60;
9108: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 9109: if (ref($lastactref) eq 'HASH') {
9110: $lastactref->{'domdefaults'} = 1;
9111: }
1.121 raeburn 9112: }
9113: $resulttext = &mt('Changes made:').'<ul>';
9114: foreach my $item (sort(keys(%changes))) {
9115: if ($item eq 'canuse_pdfforms') {
9116: if ($env{'form.'.$item} eq '1') {
9117: $resulttext .= '<li>'.&mt("Course/Community users can create/upload PDF forms set to 'on'").'</li>';
9118: } else {
9119: $resulttext .= '<li>'.&mt('Course/Community users can create/upload PDF forms set to "off"').'</li>';
9120: }
1.139 raeburn 9121: } elsif ($item eq 'anonsurvey_threshold') {
1.192 raeburn 9122: $resulttext .= '<li>'.&mt('Responder count required for display of anonymous survey submissions set to [_1].',$defaultshash{'coursedefaults'}{'anonsurvey_threshold'}).'</li>';
1.198 raeburn 9123: } elsif ($item eq 'uploadquota') {
9124: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
9125: $resulttext .= '<li>'.&mt('Default quota for content uploaded to a course/community via Course Editor set as follows:').'<ul>'.
9126: '<li>'.&mt('Official courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'official'}.'</b>').'</li>'.
9127: '<li>'.&mt('Unofficial courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'unofficial'}.'</b>').'</li>'.
1.216 raeburn 9128: '<li>'.&mt('Textbook courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'textbook'}.'</b>').'</li>'.
9129:
1.198 raeburn 9130: '<li>'.&mt('Communities: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'community'}.'</b>').'</li>'.
9131: '</ul>'.
9132: '</li>';
9133: } else {
9134: $resulttext .= '<li>'.&mt('Default quota for content uploaded via Course Editor remains default: [_1] MB',$staticdefaults{'uploadquota'}).'</li>';
9135: }
1.192 raeburn 9136: } elsif ($item eq 'coursecredits') {
9137: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
9138: if (($domdefaults{'officialcredits'} eq '') &&
1.216 raeburn 9139: ($domdefaults{'unofficialcredits'} eq '') &&
9140: ($domdefaults{'textbookcredits'} eq '')) {
1.192 raeburn 9141: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
9142: } else {
9143: $resulttext .= '<li>'.&mt('Student credits can be set per course by a Domain Coordinator, with the following defaults applying:').'<ul>'.
9144: '<li>'.&mt('Official courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'official'}).'</li>'.
9145: '<li>'.&mt('Unofficial courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'}).'</li>'.
1.216 raeburn 9146: '<li>'.&mt('Textbook courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'textbook'}).'</li>'.
1.192 raeburn 9147: '</ul>'.
9148: '</li>';
9149: }
9150: } else {
9151: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
9152: }
1.140 raeburn 9153: }
1.121 raeburn 9154: }
9155: $resulttext .= '</ul>';
9156: } else {
9157: $resulttext = &mt('No changes made to course defaults');
9158: }
9159: } else {
9160: $resulttext = '<span class="LC_error">'.
9161: &mt('An error occurred: [_1]',$putresult).'</span>';
9162: }
9163: return $resulttext;
9164: }
9165:
1.137 raeburn 9166: sub modify_usersessions {
1.212 raeburn 9167: my ($dom,$lastactref,%domconfig) = @_;
1.145 raeburn 9168: my @hostingtypes = ('version','excludedomain','includedomain');
9169: my @offloadtypes = ('primary','default');
9170: my %types = (
9171: remote => \@hostingtypes,
9172: hosted => \@hostingtypes,
9173: spares => \@offloadtypes,
9174: );
9175: my @prefixes = ('remote','hosted','spares');
1.137 raeburn 9176: my @lcversions = &Apache::lonnet::all_loncaparevs();
1.138 raeburn 9177: my (%by_ip,%by_location,@intdoms);
9178: &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
9179: my @locations = sort(keys(%by_location));
1.137 raeburn 9180: my (%defaultshash,%changes);
9181: foreach my $prefix (@prefixes) {
9182: $defaultshash{'usersessions'}{$prefix} = {};
9183: }
1.212 raeburn 9184: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.137 raeburn 9185: my $resulttext;
1.138 raeburn 9186: my %iphost = &Apache::lonnet::get_iphost();
1.137 raeburn 9187: foreach my $prefix (@prefixes) {
1.145 raeburn 9188: next if ($prefix eq 'spares');
9189: foreach my $type (@{$types{$prefix}}) {
1.137 raeburn 9190: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
9191: if ($type eq 'version') {
9192: my $value = $env{'form.'.$prefix.'_'.$type};
9193: my $okvalue;
9194: if ($value ne '') {
9195: if (grep(/^\Q$value\E$/,@lcversions)) {
9196: $okvalue = $value;
9197: }
9198: }
9199: if (ref($domconfig{'usersessions'}) eq 'HASH') {
9200: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
9201: if ($domconfig{'usersessions'}{$prefix}{$type} ne '') {
9202: if ($inuse == 0) {
9203: $changes{$prefix}{$type} = 1;
9204: } else {
9205: if ($okvalue ne $domconfig{'usersessions'}{$prefix}{$type}) {
9206: $changes{$prefix}{$type} = 1;
9207: }
9208: if ($okvalue ne '') {
9209: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
9210: }
9211: }
9212: } else {
9213: if (($inuse == 1) && ($okvalue ne '')) {
9214: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
9215: $changes{$prefix}{$type} = 1;
9216: }
9217: }
9218: } else {
9219: if (($inuse == 1) && ($okvalue ne '')) {
9220: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
9221: $changes{$prefix}{$type} = 1;
9222: }
9223: }
9224: } else {
9225: if (($inuse == 1) && ($okvalue ne '')) {
9226: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
9227: $changes{$prefix}{$type} = 1;
9228: }
9229: }
9230: } else {
9231: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
9232: my @okvals;
9233: foreach my $val (@vals) {
1.138 raeburn 9234: if ($val =~ /:/) {
9235: my @items = split(/:/,$val);
9236: foreach my $item (@items) {
9237: if (ref($by_location{$item}) eq 'ARRAY') {
9238: push(@okvals,$item);
9239: }
9240: }
9241: } else {
9242: if (ref($by_location{$val}) eq 'ARRAY') {
9243: push(@okvals,$val);
9244: }
1.137 raeburn 9245: }
9246: }
9247: @okvals = sort(@okvals);
9248: if (ref($domconfig{'usersessions'}) eq 'HASH') {
9249: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
9250: if (ref($domconfig{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
9251: if ($inuse == 0) {
9252: $changes{$prefix}{$type} = 1;
9253: } else {
9254: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
9255: my @changed = &Apache::loncommon::compare_arrays($domconfig{'usersessions'}{$prefix}{$type},$defaultshash{'usersessions'}{$prefix}{$type});
9256: if (@changed > 0) {
9257: $changes{$prefix}{$type} = 1;
9258: }
9259: }
9260: } else {
9261: if ($inuse == 1) {
9262: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
9263: $changes{$prefix}{$type} = 1;
9264: }
9265: }
9266: } else {
9267: if ($inuse == 1) {
9268: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
9269: $changes{$prefix}{$type} = 1;
9270: }
9271: }
9272: } else {
9273: if ($inuse == 1) {
9274: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
9275: $changes{$prefix}{$type} = 1;
9276: }
9277: }
9278: }
9279: }
9280: }
1.145 raeburn 9281:
9282: my @alldoms = &Apache::lonnet::all_domains();
1.149 raeburn 9283: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.145 raeburn 9284: my %spareid = ¤t_offloads_to($dom,$domconfig{'usersessions'},\%servers);
9285: my $savespares;
9286:
9287: foreach my $lonhost (sort(keys(%servers))) {
9288: my $serverhomeID =
9289: &Apache::lonnet::get_server_homeID($servers{$lonhost});
1.152 raeburn 9290: my $serverhostname = &Apache::lonnet::hostname($lonhost);
1.145 raeburn 9291: $defaultshash{'usersessions'}{'spares'}{$lonhost} = {};
9292: my %spareschg;
9293: foreach my $type (@{$types{'spares'}}) {
9294: my @okspares;
9295: my @checked = &Apache::loncommon::get_env_multiple('form.spare_'.$type.'_'.$lonhost);
9296: foreach my $server (@checked) {
1.152 raeburn 9297: if (&Apache::lonnet::hostname($server) ne '') {
9298: unless (&Apache::lonnet::hostname($server) eq $serverhostname) {
9299: unless (grep(/^\Q$server\E$/,@okspares)) {
9300: push(@okspares,$server);
9301: }
1.145 raeburn 9302: }
9303: }
9304: }
9305: my $new = $env{'form.newspare_'.$type.'_'.$lonhost};
9306: my $newspare;
1.152 raeburn 9307: if (($new ne '') && (&Apache::lonnet::hostname($new))) {
9308: unless (&Apache::lonnet::hostname($new) eq $serverhostname) {
1.145 raeburn 9309: $newspare = $new;
9310: }
9311: }
1.152 raeburn 9312: my @spares;
9313: if (($newspare ne '') && (!grep(/^\Q$newspare\E$/,@okspares))) {
9314: @spares = sort(@okspares,$newspare);
9315: } else {
9316: @spares = sort(@okspares);
9317: }
9318: $defaultshash{'usersessions'}{'spares'}{$lonhost}{$type} = \@spares;
1.145 raeburn 9319: if (ref($spareid{$lonhost}) eq 'HASH') {
9320: if (ref($spareid{$lonhost}{$type}) eq 'ARRAY') {
1.152 raeburn 9321: my @diffs = &Apache::loncommon::compare_arrays($spareid{$lonhost}{$type},\@spares);
1.145 raeburn 9322: if (@diffs > 0) {
9323: $spareschg{$type} = 1;
9324: }
9325: }
9326: }
9327: }
9328: if (keys(%spareschg) > 0) {
9329: $changes{'spares'}{$lonhost} = \%spareschg;
9330: }
9331: }
9332:
9333: if (ref($domconfig{'usersessions'}) eq 'HASH') {
9334: if (ref($domconfig{'usersessions'}{'spares'}) eq 'HASH') {
9335: if (ref($changes{'spares'}) eq 'HASH') {
9336: if (keys(%{$changes{'spares'}}) > 0) {
9337: $savespares = 1;
9338: }
9339: }
9340: } else {
9341: $savespares = 1;
9342: }
9343: }
9344:
1.147 raeburn 9345: my $nochgmsg = &mt('No changes made to settings for user session hosting/offloading.');
9346: if ((keys(%changes) > 0) || ($savespares)) {
1.137 raeburn 9347: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
9348: $dom);
9349: if ($putresult eq 'ok') {
9350: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
9351: if (ref($defaultshash{'usersessions'}{'remote'}) eq 'HASH') {
9352: $domdefaults{'remotesessions'} = $defaultshash{'usersessions'}{'remote'};
9353: }
9354: if (ref($defaultshash{'usersessions'}{'hosted'}) eq 'HASH') {
9355: $domdefaults{'hostedsessions'} = $defaultshash{'usersessions'}{'hosted'};
9356: }
9357: }
9358: my $cachetime = 24*60*60;
9359: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 9360: if (ref($lastactref) eq 'HASH') {
9361: $lastactref->{'domdefaults'} = 1;
9362: }
1.147 raeburn 9363: if (keys(%changes) > 0) {
9364: my %lt = &usersession_titles();
9365: $resulttext = &mt('Changes made:').'<ul>';
9366: foreach my $prefix (@prefixes) {
9367: if (ref($changes{$prefix}) eq 'HASH') {
9368: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
9369: if ($prefix eq 'spares') {
9370: if (ref($changes{$prefix}) eq 'HASH') {
9371: foreach my $lonhost (sort(keys(%{$changes{$prefix}}))) {
9372: $resulttext .= '<li><b>'.$lonhost.'</b> ';
1.148 raeburn 9373: my $lonhostdom = &Apache::lonnet::host_domain($lonhost);
1.211 raeburn 9374: my $cachekey = &escape('spares').':'.&escape($lonhostdom);
9375: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
1.147 raeburn 9376: if (ref($changes{$prefix}{$lonhost}) eq 'HASH') {
9377: foreach my $type (@{$types{$prefix}}) {
9378: if ($changes{$prefix}{$lonhost}{$type}) {
9379: my $offloadto = &mt('None');
9380: if (ref($defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}) eq 'ARRAY') {
9381: if (@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}} > 0) {
9382: $offloadto = join(', ',@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}});
9383: }
1.145 raeburn 9384: }
1.147 raeburn 9385: $resulttext .= &mt('[_1] set to: [_2].','<i>'.$lt{$type}.'</i>',$offloadto).(' 'x3);
1.145 raeburn 9386: }
1.137 raeburn 9387: }
9388: }
1.147 raeburn 9389: $resulttext .= '</li>';
1.137 raeburn 9390: }
9391: }
1.147 raeburn 9392: } else {
9393: foreach my $type (@{$types{$prefix}}) {
9394: if (defined($changes{$prefix}{$type})) {
9395: my $newvalue;
9396: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
9397: if (ref($defaultshash{'usersessions'}{$prefix})) {
9398: if ($type eq 'version') {
9399: $newvalue = $defaultshash{'usersessions'}{$prefix}{$type};
9400: } elsif (ref($defaultshash{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
9401: if (@{$defaultshash{'usersessions'}{$prefix}{$type}} > 0) {
9402: $newvalue = join(', ',@{$defaultshash{'usersessions'}{$prefix}{$type}});
9403: }
1.145 raeburn 9404: }
9405: }
9406: }
1.147 raeburn 9407: if ($newvalue eq '') {
9408: if ($type eq 'version') {
9409: $resulttext .= '<li>'.&mt('[_1] set to: off',$lt{$type}).'</li>';
9410: } else {
9411: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
9412: }
1.145 raeburn 9413: } else {
1.147 raeburn 9414: if ($type eq 'version') {
9415: $newvalue .= ' '.&mt('(or later)');
9416: }
9417: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
1.145 raeburn 9418: }
1.137 raeburn 9419: }
9420: }
9421: }
1.147 raeburn 9422: $resulttext .= '</ul>';
1.137 raeburn 9423: }
9424: }
1.147 raeburn 9425: $resulttext .= '</ul>';
9426: } else {
9427: $resulttext = $nochgmsg;
1.137 raeburn 9428: }
9429: } else {
9430: $resulttext = '<span class="LC_error">'.
9431: &mt('An error occurred: [_1]',$putresult).'</span>';
9432: }
9433: } else {
1.147 raeburn 9434: $resulttext = $nochgmsg;
1.137 raeburn 9435: }
9436: return $resulttext;
9437: }
9438:
1.150 raeburn 9439: sub modify_loadbalancing {
9440: my ($dom,%domconfig) = @_;
9441: my $primary_id = &Apache::lonnet::domain($dom,'primary');
9442: my $intdom = &Apache::lonnet::internet_dom($primary_id);
9443: my ($othertitle,$usertypes,$types) =
9444: &Apache::loncommon::sorted_inst_types($dom);
9445: my %servers = &Apache::lonnet::internet_dom_servers($dom);
9446: my @sparestypes = ('primary','default');
9447: my %typetitles = &sparestype_titles();
9448: my $resulttext;
1.171 raeburn 9449: my (%currbalancer,%currtargets,%currrules,%existing);
9450: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
9451: %existing = %{$domconfig{'loadbalancing'}};
9452: }
9453: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
9454: \%currtargets,\%currrules);
9455: my ($saveloadbalancing,%defaultshash,%changes);
9456: my ($alltypes,$othertypes,$titles) =
9457: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
9458: my %ruletitles = &offloadtype_text();
9459: my @deletions = &Apache::loncommon::get_env_multiple('form.loadbalancing_delete');
9460: for (my $i=0; $i<$env{'form.loadbalancing_total'}; $i++) {
9461: my $balancer = $env{'form.loadbalancing_lonhost_'.$i};
9462: if ($balancer eq '') {
9463: next;
9464: }
1.210 raeburn 9465: if (!exists($servers{$balancer})) {
1.171 raeburn 9466: if (exists($currbalancer{$balancer})) {
9467: push(@{$changes{'delete'}},$balancer);
1.150 raeburn 9468: }
1.171 raeburn 9469: next;
9470: }
9471: if ((@deletions > 0) && (grep(/^\Q$i\E$/,@deletions))) {
9472: push(@{$changes{'delete'}},$balancer);
9473: next;
9474: }
9475: if (!exists($currbalancer{$balancer})) {
9476: push(@{$changes{'add'}},$balancer);
9477: }
9478: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'} = [];
9479: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'default'} = [];
9480: $defaultshash{'loadbalancing'}{$balancer}{'rules'} = {};
9481: unless (ref($domconfig{'loadbalancing'}) eq 'HASH') {
9482: $saveloadbalancing = 1;
9483: }
9484: foreach my $sparetype (@sparestypes) {
9485: my @targets = &Apache::loncommon::get_env_multiple('form.loadbalancing_target_'.$i.'_'.$sparetype);
9486: my @offloadto;
9487: foreach my $target (@targets) {
9488: if (($servers{$target}) && ($target ne $balancer)) {
9489: if ($sparetype eq 'default') {
9490: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}) eq 'ARRAY') {
9491: next if (grep(/^\Q$target\E$/,@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}}));
1.150 raeburn 9492: }
9493: }
1.171 raeburn 9494: unless(grep(/^\Q$target\E$/,@offloadto)) {
9495: push(@offloadto,$target);
9496: }
1.150 raeburn 9497: }
1.171 raeburn 9498: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype} = \@offloadto;
1.150 raeburn 9499: }
9500: }
1.171 raeburn 9501: if (ref($currtargets{$balancer}) eq 'HASH') {
1.150 raeburn 9502: foreach my $sparetype (@sparestypes) {
1.171 raeburn 9503: if (ref($currtargets{$balancer}{$sparetype}) eq 'ARRAY') {
9504: my @targetdiffs = &Apache::loncommon::compare_arrays($currtargets{$balancer}{$sparetype},$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype});
1.150 raeburn 9505: if (@targetdiffs > 0) {
1.171 raeburn 9506: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 9507: }
1.171 raeburn 9508: } elsif (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
9509: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
9510: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 9511: }
9512: }
9513: }
9514: } else {
1.171 raeburn 9515: if (ref($defaultshash{'loadbalancing'}{$balancer}) eq 'HASH') {
1.210 raeburn 9516: foreach my $sparetype (@sparestypes) {
1.171 raeburn 9517: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
9518: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
9519: $changes{'curr'}{$balancer}{'targets'} = 1;
9520: }
1.150 raeburn 9521: }
9522: }
1.210 raeburn 9523: }
1.150 raeburn 9524: }
9525: my $ishomedom;
1.171 raeburn 9526: if (&Apache::lonnet::host_domain($balancer) eq $dom) {
9527: $ishomedom = 1;
1.150 raeburn 9528: }
9529: if (ref($alltypes) eq 'ARRAY') {
9530: foreach my $type (@{$alltypes}) {
9531: my $rule;
1.210 raeburn 9532: unless ((($type eq '_LC_external') || ($type eq '_LC_internetdom')) &&
1.150 raeburn 9533: (!$ishomedom)) {
1.171 raeburn 9534: $rule = $env{'form.loadbalancing_rules_'.$i.'_'.$type};
9535: }
9536: if ($rule eq 'specific') {
9537: $rule = $env{'form.loadbalancing_singleserver_'.$i.'_'.$type};
1.150 raeburn 9538: }
1.171 raeburn 9539: $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type} = $rule;
9540: if (ref($currrules{$balancer}) eq 'HASH') {
9541: if ($rule ne $currrules{$balancer}{$type}) {
9542: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 9543: }
9544: } elsif ($rule ne '') {
1.171 raeburn 9545: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 9546: }
9547: }
9548: }
1.171 raeburn 9549: }
9550: my $nochgmsg = &mt('No changes made to Load Balancer settings.');
9551: if ((keys(%changes) > 0) || ($saveloadbalancing)) {
9552: unless (ref($defaultshash{'loadbalancing'}) eq 'HASH') {
9553: $defaultshash{'loadbalancing'} = {};
9554: }
9555: my $putresult = &Apache::lonnet::put_dom('configuration',
9556: \%defaultshash,$dom);
9557: if ($putresult eq 'ok') {
9558: if (keys(%changes) > 0) {
9559: if (ref($changes{'delete'}) eq 'ARRAY') {
9560: foreach my $balancer (sort(@{$changes{'delete'}})) {
9561: $resulttext .= '<li>'.&mt('Load Balancing discontinued for: [_1]',$balancer).'</li>';
1.211 raeburn 9562: my $cachekey = &escape('loadbalancing').':'.&escape($dom);
9563: &Apache::lonnet::remote_devalidate_cache($balancer,[$cachekey]);
1.150 raeburn 9564: }
1.171 raeburn 9565: }
9566: if (ref($changes{'add'}) eq 'ARRAY') {
1.210 raeburn 9567: foreach my $balancer (sort(@{$changes{'add'}})) {
1.171 raeburn 9568: $resulttext .= '<li>'.&mt('Load Balancing enabled for: [_1]',$balancer);
9569: }
9570: }
9571: if (ref($changes{'curr'}) eq 'HASH') {
9572: foreach my $balancer (sort(keys(%{$changes{'curr'}}))) {
9573: if (ref($changes{'curr'}{$balancer}) eq 'HASH') {
9574: if ($changes{'curr'}{$balancer}{'targets'}) {
9575: my %offloadstr;
9576: foreach my $sparetype (@sparestypes) {
9577: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
9578: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
9579: $offloadstr{$sparetype} = join(', ',@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
9580: }
9581: }
1.150 raeburn 9582: }
1.171 raeburn 9583: if (keys(%offloadstr) == 0) {
9584: $resulttext .= '<li>'.&mt("Servers to which Load Balance server offloads set to 'None', by default").'</li>';
1.150 raeburn 9585: } else {
1.171 raeburn 9586: my $showoffload;
9587: foreach my $sparetype (@sparestypes) {
9588: $showoffload .= '<i>'.$typetitles{$sparetype}.'</i>: ';
9589: if (defined($offloadstr{$sparetype})) {
9590: $showoffload .= $offloadstr{$sparetype};
9591: } else {
9592: $showoffload .= &mt('None');
9593: }
9594: $showoffload .= (' 'x3);
9595: }
9596: $resulttext .= '<li>'.&mt('By default, Load Balancer: [_1] set to offload to - [_2]',$balancer,$showoffload).'</li>';
1.150 raeburn 9597: }
9598: }
9599: }
1.171 raeburn 9600: if (ref($changes{'curr'}{$balancer}{'rules'}) eq 'HASH') {
9601: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
9602: foreach my $type (@{$alltypes}) {
9603: if ($changes{'curr'}{$balancer}{'rules'}{$type}) {
9604: my $rule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
9605: my $balancetext;
9606: if ($rule eq '') {
9607: $balancetext = $ruletitles{'default'};
1.209 raeburn 9608: } elsif (($rule eq 'homeserver') || ($rule eq 'externalbalancer') ||
9609: ($rule eq 'balancer') || ($rule eq 'offloadedto')) {
1.171 raeburn 9610: $balancetext = $ruletitles{$rule};
9611: } else {
9612: $balancetext = &mt('offload to [_1]',$defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type});
9613: }
1.210 raeburn 9614: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- balancing for [_2] set to - "[_3]"',$balancer,$titles->{$type},$balancetext).'</li>';
1.150 raeburn 9615: }
9616: }
9617: }
9618: }
1.215 raeburn 9619: my $cachekey = &escape('loadbalancing').':'.&escape($dom);
1.211 raeburn 9620: &Apache::lonnet::remote_devalidate_cache($balancer,[$cachekey]);
1.150 raeburn 9621: }
1.171 raeburn 9622: }
9623: if ($resulttext ne '') {
9624: $resulttext = &mt('Changes made:').'<ul>'.$resulttext.'</ul>';
1.150 raeburn 9625: } else {
9626: $resulttext = $nochgmsg;
9627: }
9628: } else {
1.171 raeburn 9629: $resulttext = $nochgmsg;
1.150 raeburn 9630: }
9631: } else {
1.171 raeburn 9632: $resulttext = '<span class="LC_error">'.
9633: &mt('An error occurred: [_1]',$putresult).'</span>';
1.150 raeburn 9634: }
9635: } else {
1.171 raeburn 9636: $resulttext = $nochgmsg;
1.150 raeburn 9637: }
9638: return $resulttext;
9639: }
9640:
1.48 raeburn 9641: sub recurse_check {
9642: my ($chkcats,$categories,$depth,$name) = @_;
9643: if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
9644: my $chg = 0;
9645: for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
9646: my $category = $chkcats->[$depth]{$name}[$j];
9647: my $item;
9648: if ($category eq '') {
9649: $chg ++;
9650: } else {
9651: my $deeper = $depth + 1;
9652: $item = &escape($category).':'.&escape($name).':'.$depth;
9653: if ($chg) {
9654: $categories->{$item} -= $chg;
9655: }
9656: &recurse_check($chkcats,$categories,$deeper,$category);
9657: $deeper --;
9658: }
9659: }
9660: }
9661: return;
9662: }
9663:
9664: sub recurse_cat_deletes {
9665: my ($item,$coursecategories,$deletions) = @_;
9666: my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
9667: my $subdepth = $depth + 1;
9668: if (ref($coursecategories) eq 'HASH') {
9669: foreach my $subitem (keys(%{$coursecategories})) {
9670: my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
9671: if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
9672: delete($coursecategories->{$subitem});
9673: $deletions->{$subitem} = 1;
9674: &recurse_cat_deletes($subitem,$coursecategories,$deletions);
1.168 raeburn 9675: }
1.48 raeburn 9676: }
9677: }
9678: return;
9679: }
9680:
1.125 raeburn 9681: sub get_active_dcs {
9682: my ($dom) = @_;
1.191 raeburn 9683: my $now = time;
9684: my %dompersonnel = &Apache::lonnet::get_domain_roles($dom,['dc'],$now,$now);
1.125 raeburn 9685: my %domcoords;
9686: my $numdcs = 0;
9687: foreach my $server (keys(%dompersonnel)) {
9688: foreach my $user (sort(keys(%{$dompersonnel{$server}}))) {
9689: my ($trole,$uname,$udom,$runame,$rudom,$rsec) = split(/:/,$user);
1.191 raeburn 9690: $domcoords{$uname.':'.$udom} = $dompersonnel{$server}{$user};
1.125 raeburn 9691: }
9692: }
9693: return %domcoords;
9694: }
9695:
9696: sub active_dc_picker {
1.191 raeburn 9697: my ($dom,$numinrow,$inputtype,$name,%currhash) = @_;
1.125 raeburn 9698: my %domcoords = &get_active_dcs($dom);
1.191 raeburn 9699: my @domcoord = keys(%domcoords);
9700: if (keys(%currhash)) {
9701: foreach my $dc (keys(%currhash)) {
9702: unless (exists($domcoords{$dc})) {
9703: push(@domcoord,$dc);
9704: }
9705: }
9706: }
9707: @domcoord = sort(@domcoord);
1.210 raeburn 9708: my $numdcs = scalar(@domcoord);
1.191 raeburn 9709: my $rows = 0;
9710: my $table;
1.125 raeburn 9711: if ($numdcs > 1) {
1.191 raeburn 9712: $table = '<table>';
9713: for (my $i=0; $i<@domcoord; $i++) {
1.125 raeburn 9714: my $rem = $i%($numinrow);
9715: if ($rem == 0) {
9716: if ($i > 0) {
1.191 raeburn 9717: $table .= '</tr>';
1.125 raeburn 9718: }
1.191 raeburn 9719: $table .= '<tr>';
9720: $rows ++;
1.125 raeburn 9721: }
1.191 raeburn 9722: my $check = '';
9723: if ($inputtype eq 'radio') {
9724: if (keys(%currhash) == 0) {
9725: if (!$i) {
9726: $check = ' checked="checked"';
9727: }
9728: } elsif (exists($currhash{$domcoord[$i]})) {
9729: $check = ' checked="checked"';
9730: }
9731: } else {
9732: if (exists($currhash{$domcoord[$i]})) {
9733: $check = ' checked="checked"';
1.125 raeburn 9734: }
9735: }
1.191 raeburn 9736: if ($i == @domcoord - 1) {
1.125 raeburn 9737: my $colsleft = $numinrow - $rem;
9738: if ($colsleft > 1) {
1.191 raeburn 9739: $table .= '<td class="LC_left_item" colspan="'.$colsleft.'">';
1.125 raeburn 9740: } else {
1.191 raeburn 9741: $table .= '<td class="LC_left_item">';
1.125 raeburn 9742: }
9743: } else {
1.191 raeburn 9744: $table .= '<td class="LC_left_item">';
9745: }
9746: my ($dcname,$dcdom) = split(':',$domcoord[$i]);
9747: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
9748: $table .= '<span class="LC_nobreak"><label>'.
9749: '<input type="'.$inputtype.'" name="'.$name.'"'.
9750: ' value="'.$domcoord[$i].'"'.$check.' />'.$user;
9751: if ($user ne $dcname.':'.$dcdom) {
1.219 raeburn 9752: $table .= ' ('.$dcname.':'.$dcdom.')';
1.191 raeburn 9753: }
1.219 raeburn 9754: $table .= '</label></span></td>';
1.191 raeburn 9755: }
9756: $table .= '</tr></table>';
9757: } elsif ($numdcs == 1) {
1.219 raeburn 9758: my ($dcname,$dcdom) = split(':',$domcoord[0]);
9759: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
1.191 raeburn 9760: if ($inputtype eq 'radio') {
1.219 raeburn 9761: $table .= '<input type="hidden" name="'.$name.'" value="'.$domcoord[0].'" />'.$user;
9762: if ($user ne $dcname.':'.$dcdom) {
9763: $table .= ' ('.$dcname.':'.$dcdom.')';
9764: }
1.191 raeburn 9765: } else {
9766: my $check;
9767: if (exists($currhash{$domcoord[0]})) {
9768: $check = ' checked="checked"';
1.125 raeburn 9769: }
1.219 raeburn 9770: $table .= '<span class="LC_nobreak"><label>'.
9771: '<input type="checkbox" name="'.$name.'" '.
9772: 'value="'.$domcoord[0].'"'.$check.' />'.$user;
9773: if ($user ne $dcname.':'.$dcdom) {
1.220 raeburn 9774: $table .= ' ('.$dcname.':'.$dcdom.')';
1.219 raeburn 9775: }
1.220 raeburn 9776: $table .= '</label></span>';
1.191 raeburn 9777: $rows ++;
1.125 raeburn 9778: }
9779: }
1.191 raeburn 9780: return ($numdcs,$table,$rows);
1.125 raeburn 9781: }
9782:
1.137 raeburn 9783: sub usersession_titles {
9784: return &Apache::lonlocal::texthash(
9785: hosted => 'Hosting of sessions for users from other domains on servers in this domain',
9786: remote => 'Hosting of sessions for users in this domain on servers in other domains',
1.145 raeburn 9787: spares => 'Servers offloaded to, when busy',
1.137 raeburn 9788: version => 'LON-CAPA version requirement',
1.138 raeburn 9789: excludedomain => 'Allow all, but exclude specific domains',
9790: includedomain => 'Deny all, but include specific domains',
1.145 raeburn 9791: primary => 'Primary (checked first)',
1.154 raeburn 9792: default => 'Default',
1.137 raeburn 9793: );
9794: }
9795:
1.152 raeburn 9796: sub id_for_thisdom {
9797: my (%servers) = @_;
9798: my %altids;
9799: foreach my $server (keys(%servers)) {
9800: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
9801: if ($serverhome ne $server) {
9802: $altids{$serverhome} = $server;
9803: }
9804: }
9805: return %altids;
9806: }
9807:
1.150 raeburn 9808: sub count_servers {
9809: my ($currbalancer,%servers) = @_;
9810: my (@spares,$numspares);
9811: foreach my $lonhost (sort(keys(%servers))) {
9812: next if ($currbalancer eq $lonhost);
9813: push(@spares,$lonhost);
9814: }
9815: if ($currbalancer) {
9816: $numspares = scalar(@spares);
9817: } else {
9818: $numspares = scalar(@spares) - 1;
9819: }
9820: return ($numspares,@spares);
9821: }
9822:
9823: sub lonbalance_targets_js {
1.171 raeburn 9824: my ($dom,$types,$servers,$settings) = @_;
1.150 raeburn 9825: my $select = &mt('Select');
9826: my ($alltargets,$allishome,$allinsttypes,@alltypes);
9827: if (ref($servers) eq 'HASH') {
9828: $alltargets = join("','",sort(keys(%{$servers})));
9829: my @homedoms;
9830: foreach my $server (sort(keys(%{$servers}))) {
9831: if (&Apache::lonnet::host_domain($server) eq $dom) {
9832: push(@homedoms,'1');
9833: } else {
9834: push(@homedoms,'0');
9835: }
9836: }
9837: $allishome = join("','",@homedoms);
9838: }
9839: if (ref($types) eq 'ARRAY') {
9840: if (@{$types} > 0) {
9841: @alltypes = @{$types};
9842: }
9843: }
9844: push(@alltypes,'default','_LC_adv','_LC_author','_LC_internetdom','_LC_external');
9845: $allinsttypes = join("','",@alltypes);
1.171 raeburn 9846: my (%currbalancer,%currtargets,%currrules,%existing);
9847: if (ref($settings) eq 'HASH') {
9848: %existing = %{$settings};
9849: }
9850: &get_loadbalancers_config($servers,\%existing,\%currbalancer,
9851: \%currtargets,\%currrules);
1.210 raeburn 9852: my $balancers = join("','",sort(keys(%currbalancer)));
1.150 raeburn 9853: return <<"END";
9854:
9855: <script type="text/javascript">
9856: // <![CDATA[
9857:
1.171 raeburn 9858: currBalancers = new Array('$balancers');
9859:
9860: function toggleTargets(balnum) {
9861: var lonhostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
9862: var prevhostitem = document.getElementById('loadbalancing_prevlonhost_'+balnum);
9863: var balancer = lonhostitem.options[lonhostitem.selectedIndex].value;
9864: var prevbalancer = prevhostitem.value;
9865: var baltotal = document.getElementById('loadbalancing_total').value;
9866: prevhostitem.value = balancer;
9867: if (prevbalancer != '') {
9868: var prevIdx = currBalancers.indexOf(prevbalancer);
9869: if (prevIdx != -1) {
9870: currBalancers.splice(prevIdx,1);
9871: }
9872: }
1.150 raeburn 9873: if (balancer == '') {
1.171 raeburn 9874: hideSpares(balnum);
1.150 raeburn 9875: } else {
1.171 raeburn 9876: var currIdx = currBalancers.indexOf(balancer);
9877: if (currIdx == -1) {
9878: currBalancers.push(balancer);
9879: }
1.150 raeburn 9880: var homedoms = new Array('$allishome');
1.171 raeburn 9881: var ishomedom = homedoms[lonhostitem.selectedIndex];
9882: showSpares(balancer,ishomedom,balnum);
1.150 raeburn 9883: }
1.171 raeburn 9884: balancerChange(balnum,baltotal,'change',prevbalancer,balancer);
1.150 raeburn 9885: return;
9886: }
9887:
1.171 raeburn 9888: function showSpares(balancer,ishomedom,balnum) {
1.150 raeburn 9889: var alltargets = new Array('$alltargets');
9890: var insttypes = new Array('$allinsttypes');
1.151 raeburn 9891: var offloadtypes = new Array('primary','default');
9892:
1.171 raeburn 9893: document.getElementById('loadbalancing_targets_'+balnum).style.display='block';
9894: document.getElementById('loadbalancing_disabled_'+balnum).style.display='none';
1.152 raeburn 9895:
1.151 raeburn 9896: for (var i=0; i<offloadtypes.length; i++) {
9897: var count = 0;
9898: for (var j=0; j<alltargets.length; j++) {
9899: if (alltargets[j] != balancer) {
1.171 raeburn 9900: var item = document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+count);
9901: item.value = alltargets[j];
9902: item.style.textAlign='left';
9903: item.style.textFace='normal';
9904: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+count).innerHTML = alltargets[j];
9905: if (currBalancers.indexOf(alltargets[j]) == -1) {
9906: item.disabled = '';
9907: } else {
9908: item.disabled = 'disabled';
9909: item.checked = false;
9910: }
1.151 raeburn 9911: count ++;
9912: }
1.150 raeburn 9913: }
9914: }
1.151 raeburn 9915: for (var k=0; k<insttypes.length; k++) {
9916: if ((insttypes[k] == '_LC_external') || (insttypes[k] == '_LC_internetdom')) {
1.150 raeburn 9917: if (ishomedom == 1) {
1.171 raeburn 9918: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
9919: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 9920: } else {
1.171 raeburn 9921: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
9922: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.150 raeburn 9923: }
9924: } else {
1.171 raeburn 9925: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
9926: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 9927: }
1.151 raeburn 9928: if ((insttypes[k] != '_LC_external') &&
9929: ((insttypes[k] != '_LC_internetdom') ||
9930: ((insttypes[k] == '_LC_internetdom') && (ishomedom == 1)))) {
1.171 raeburn 9931: var item = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]);
9932: item.options.length = 0;
9933: item.options[0] = new Option("","",true,true);
1.210 raeburn 9934: var idx = 0;
1.151 raeburn 9935: for (var m=0; m<alltargets.length; m++) {
1.171 raeburn 9936: if ((currBalancers.indexOf(alltargets[m]) == -1) && (alltargets[m] != balancer)) {
9937: idx ++;
9938: item.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
1.150 raeburn 9939: }
9940: }
9941: }
9942: }
9943: return;
9944: }
9945:
1.171 raeburn 9946: function hideSpares(balnum) {
1.150 raeburn 9947: var alltargets = new Array('$alltargets');
9948: var insttypes = new Array('$allinsttypes');
9949: var offloadtypes = new Array('primary','default');
9950:
1.171 raeburn 9951: document.getElementById('loadbalancing_targets_'+balnum).style.display='none';
9952: document.getElementById('loadbalancing_disabled_'+balnum).style.display='block';
1.150 raeburn 9953:
9954: var total = alltargets.length - 1;
9955: for (var i=0; i<offloadtypes; i++) {
9956: for (var j=0; j<total; j++) {
1.171 raeburn 9957: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).checked = false;
9958: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).value = '';
9959: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+j).innerHTML = '';
1.151 raeburn 9960: }
1.150 raeburn 9961: }
9962: for (var k=0; k<insttypes.length; k++) {
1.171 raeburn 9963: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
9964: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.151 raeburn 9965: if (insttypes[k] != '_LC_external') {
1.171 raeburn 9966: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).length = 0;
9967: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).options[0] = new Option("","",true,true);
1.150 raeburn 9968: }
9969: }
9970: return;
9971: }
9972:
1.171 raeburn 9973: function checkOffloads(item,balnum,type) {
1.150 raeburn 9974: var alltargets = new Array('$alltargets');
9975: var offloadtypes = new Array('primary','default');
9976: if (item.checked) {
9977: var total = alltargets.length - 1;
9978: var other;
9979: if (type == offloadtypes[0]) {
1.151 raeburn 9980: other = offloadtypes[1];
1.150 raeburn 9981: } else {
1.151 raeburn 9982: other = offloadtypes[0];
1.150 raeburn 9983: }
9984: for (var i=0; i<total; i++) {
1.171 raeburn 9985: var server = document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).value;
1.150 raeburn 9986: if (server == item.value) {
1.171 raeburn 9987: if (document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked) {
9988: document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked = false;
1.150 raeburn 9989: }
9990: }
9991: }
9992: }
9993: return;
9994: }
9995:
1.171 raeburn 9996: function singleServerToggle(balnum,type) {
9997: var offloadtoSelIdx = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex;
1.150 raeburn 9998: if (offloadtoSelIdx == 0) {
1.171 raeburn 9999: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_0').checked = true;
10000: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 10001:
10002: } else {
1.171 raeburn 10003: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_2').checked = true;
10004: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
1.150 raeburn 10005: }
10006: return;
10007: }
10008:
1.171 raeburn 10009: function balanceruleChange(formname,balnum,type) {
1.150 raeburn 10010: if (type == '_LC_external') {
1.171 raeburn 10011: return;
1.150 raeburn 10012: }
1.171 raeburn 10013: var typesRules = getIndicesByName(formname,'loadbalancing_rules_'+balnum+'_'+type);
1.150 raeburn 10014: for (var i=0; i<typesRules.length; i++) {
10015: if (formname.elements[typesRules[i]].checked) {
10016: if (formname.elements[typesRules[i]].value != 'specific') {
1.171 raeburn 10017: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex = 0;
10018: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 10019: } else {
1.171 raeburn 10020: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
10021: }
10022: }
10023: }
10024: return;
10025: }
10026:
10027: function balancerDeleteChange(balnum) {
10028: var hostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
10029: var baltotal = document.getElementById('loadbalancing_total').value;
10030: var addtarget;
10031: var removetarget;
10032: var action = 'delete';
10033: if (document.getElementById('loadbalancing_delete_'+balnum)) {
10034: var lonhost = hostitem.value;
10035: var currIdx = currBalancers.indexOf(lonhost);
10036: if (document.getElementById('loadbalancing_delete_'+balnum).checked) {
10037: if (currIdx != -1) {
10038: currBalancers.splice(currIdx,1);
10039: }
10040: addtarget = lonhost;
10041: } else {
10042: if (currIdx == -1) {
10043: currBalancers.push(lonhost);
10044: }
10045: removetarget = lonhost;
10046: action = 'undelete';
10047: }
10048: balancerChange(balnum,baltotal,action,addtarget,removetarget);
10049: }
10050: return;
10051: }
10052:
10053: function balancerChange(balnum,baltotal,action,addtarget,removetarget) {
10054: if (baltotal > 1) {
10055: var offloadtypes = new Array('primary','default');
10056: var alltargets = new Array('$alltargets');
10057: var insttypes = new Array('$allinsttypes');
10058: for (var i=0; i<baltotal; i++) {
10059: if (i != balnum) {
10060: for (var j=0; j<offloadtypes.length; j++) {
10061: var total = alltargets.length - 1;
10062: for (var k=0; k<total; k++) {
10063: var serveritem = document.getElementById('loadbalancing_target_'+i+'_'+offloadtypes[j]+'_'+k);
10064: var server = serveritem.value;
10065: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
10066: if (server == addtarget) {
10067: serveritem.disabled = '';
10068: }
10069: }
10070: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
10071: if (server == removetarget) {
10072: serveritem.disabled = 'disabled';
10073: serveritem.checked = false;
10074: }
10075: }
10076: }
10077: }
10078: for (var j=0; j<insttypes.length; j++) {
10079: if (insttypes[j] != '_LC_external') {
10080: if (document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j])) {
10081: var singleserver = document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j]);
10082: var currSel = singleserver.selectedIndex;
10083: var currVal = singleserver.options[currSel].value;
10084: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
10085: var numoptions = singleserver.options.length;
10086: var needsnew = 1;
10087: for (var k=0; k<numoptions; k++) {
10088: if (singleserver.options[k] == addtarget) {
10089: needsnew = 0;
10090: break;
10091: }
10092: }
10093: if (needsnew == 1) {
10094: singleserver.options[numoptions] = new Option(addtarget,addtarget,false,false);
10095: }
10096: }
10097: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
10098: singleserver.options.length = 0;
10099: if ((currVal) && (currVal != removetarget)) {
10100: singleserver.options[0] = new Option("","",false,false);
10101: } else {
10102: singleserver.options[0] = new Option("","",true,true);
10103: }
10104: var idx = 0;
10105: for (var m=0; m<alltargets.length; m++) {
10106: if (currBalancers.indexOf(alltargets[m]) == -1) {
10107: idx ++;
10108: if (currVal == alltargets[m]) {
10109: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],true,true);
10110: } else {
10111: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
10112: }
10113: }
10114: }
10115: }
10116: }
10117: }
10118: }
1.150 raeburn 10119: }
10120: }
10121: }
10122: return;
10123: }
10124:
1.152 raeburn 10125: // ]]>
10126: </script>
10127:
10128: END
10129: }
10130:
10131: sub new_spares_js {
10132: my @sparestypes = ('primary','default');
10133: my $types = join("','",@sparestypes);
10134: my $select = &mt('Select');
10135: return <<"END";
10136:
10137: <script type="text/javascript">
10138: // <![CDATA[
10139:
10140: function updateNewSpares(formname,lonhost) {
10141: var types = new Array('$types');
10142: var include = new Array();
10143: var exclude = new Array();
10144: for (var i=0; i<types.length; i++) {
10145: var spareboxes = getIndicesByName(formname,'spare_'+types[i]+'_'+lonhost);
10146: for (var j=0; j<spareboxes.length; j++) {
10147: if (formname.elements[spareboxes[j]].checked) {
10148: exclude.push(formname.elements[spareboxes[j]].value);
10149: } else {
10150: include.push(formname.elements[spareboxes[j]].value);
10151: }
10152: }
10153: }
10154: for (var i=0; i<types.length; i++) {
10155: var newSpare = document.getElementById('newspare_'+types[i]+'_'+lonhost);
10156: var selIdx = newSpare.selectedIndex;
10157: var currnew = newSpare.options[selIdx].value;
10158: var okSpares = new Array();
10159: for (var j=0; j<newSpare.options.length; j++) {
10160: var possible = newSpare.options[j].value;
10161: if (possible != '') {
10162: if (exclude.indexOf(possible) == -1) {
10163: okSpares.push(possible);
10164: } else {
10165: if (currnew == possible) {
10166: selIdx = 0;
10167: }
10168: }
10169: }
10170: }
10171: for (var k=0; k<include.length; k++) {
10172: if (okSpares.indexOf(include[k]) == -1) {
10173: okSpares.push(include[k]);
10174: }
10175: }
10176: okSpares.sort();
10177: newSpare.options.length = 0;
10178: if (selIdx == 0) {
10179: newSpare.options[0] = new Option("$select","",true,true);
10180: } else {
10181: newSpare.options[0] = new Option("$select","",false,false);
10182: }
10183: for (var m=0; m<okSpares.length; m++) {
10184: var idx = m+1;
10185: var selThis = 0;
10186: if (selIdx != 0) {
10187: if (okSpares[m] == currnew) {
10188: selThis = 1;
10189: }
10190: }
10191: if (selThis == 1) {
10192: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],true,true);
10193: } else {
10194: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],false,false);
10195: }
10196: }
10197: }
10198: return;
10199: }
10200:
10201: function checkNewSpares(lonhost,type) {
10202: var newSpare = document.getElementById('newspare_'+type+'_'+lonhost);
10203: var chosen = newSpare.options[newSpare.selectedIndex].value;
10204: if (chosen != '') {
10205: var othertype;
10206: var othernewSpare;
10207: if (type == 'primary') {
10208: othernewSpare = document.getElementById('newspare_default_'+lonhost);
10209: }
10210: if (type == 'default') {
10211: othernewSpare = document.getElementById('newspare_primary_'+lonhost);
10212: }
10213: if (othernewSpare.options[othernewSpare.selectedIndex].value == chosen) {
10214: othernewSpare.selectedIndex = 0;
10215: }
10216: }
10217: return;
10218: }
10219:
10220: // ]]>
10221: </script>
10222:
10223: END
10224:
10225: }
10226:
10227: sub common_domprefs_js {
10228: return <<"END";
10229:
10230: <script type="text/javascript">
10231: // <![CDATA[
10232:
1.150 raeburn 10233: function getIndicesByName(formname,item) {
1.152 raeburn 10234: var group = new Array();
1.150 raeburn 10235: for (var i=0;i<formname.elements.length;i++) {
10236: if (formname.elements[i].name == item) {
1.152 raeburn 10237: group.push(formname.elements[i].id);
1.150 raeburn 10238: }
10239: }
1.152 raeburn 10240: return group;
1.150 raeburn 10241: }
10242:
10243: // ]]>
10244: </script>
10245:
10246: END
1.152 raeburn 10247:
1.150 raeburn 10248: }
10249:
1.165 raeburn 10250: sub recaptcha_js {
10251: my %lt = &captcha_phrases();
10252: return <<"END";
10253:
10254: <script type="text/javascript">
10255: // <![CDATA[
10256:
10257: function updateCaptcha(caller,context) {
10258: var privitem;
10259: var pubitem;
10260: var privtext;
10261: var pubtext;
10262: if (document.getElementById(context+'_recaptchapub')) {
10263: pubitem = document.getElementById(context+'_recaptchapub');
10264: } else {
10265: return;
10266: }
10267: if (document.getElementById(context+'_recaptchapriv')) {
10268: privitem = document.getElementById(context+'_recaptchapriv');
10269: } else {
10270: return;
10271: }
10272: if (document.getElementById(context+'_recaptchapubtxt')) {
10273: pubtext = document.getElementById(context+'_recaptchapubtxt');
10274: } else {
10275: return;
10276: }
10277: if (document.getElementById(context+'_recaptchaprivtxt')) {
10278: privtext = document.getElementById(context+'_recaptchaprivtxt');
10279: } else {
10280: return;
10281: }
10282: if (caller.checked) {
10283: if (caller.value == 'recaptcha') {
10284: pubitem.type = 'text';
10285: privitem.type = 'text';
10286: pubitem.size = '40';
10287: privitem.size = '40';
10288: pubtext.innerHTML = "$lt{'pub'}";
10289: privtext.innerHTML = "$lt{'priv'}";
10290: } else {
10291: pubitem.type = 'hidden';
10292: privitem.type = 'hidden';
10293: pubtext.innerHTML = '';
10294: privtext.innerHTML = '';
10295: }
10296: }
10297: return;
10298: }
10299:
10300: // ]]>
10301: </script>
10302:
10303: END
10304:
10305: }
10306:
1.192 raeburn 10307: sub credits_js {
10308: return <<"END";
10309:
10310: <script type="text/javascript">
10311: // <![CDATA[
10312:
10313: function toggleCredits(domForm) {
10314: if (document.getElementById('credits')) {
10315: creditsitem = document.getElementById('credits');
10316: var creditsLength = domForm.coursecredits.length;
10317: if (creditsLength) {
10318: var currval;
10319: for (var i=0; i<creditsLength; i++) {
10320: if (domForm.coursecredits[i].checked) {
10321: currval = domForm.coursecredits[i].value;
10322: }
10323: }
10324: if (currval == 1) {
10325: creditsitem.style.display = 'block';
10326: } else {
10327: creditsitem.style.display = 'none';
10328: }
10329: }
10330: }
10331: return;
10332: }
10333:
10334: // ]]>
10335: </script>
10336:
10337: END
10338:
10339: }
10340:
1.165 raeburn 10341: sub captcha_phrases {
10342: return &Apache::lonlocal::texthash (
10343: priv => 'Private key',
10344: pub => 'Public key',
10345: original => 'original (CAPTCHA)',
10346: recaptcha => 'successor (ReCAPTCHA)',
10347: notused => 'unused',
10348: );
10349: }
10350:
1.205 raeburn 10351: sub devalidate_remote_domconfs {
1.212 raeburn 10352: my ($dom,$cachekeys) = @_;
10353: return unless (ref($cachekeys) eq 'HASH');
1.205 raeburn 10354: my %servers = &Apache::lonnet::internet_dom_servers($dom);
10355: my %thismachine;
10356: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
1.212 raeburn 10357: my @posscached = ('domainconfig','domdefaults');
1.205 raeburn 10358: if (keys(%servers) > 1) {
10359: foreach my $server (keys(%servers)) {
10360: next if ($thismachine{$server});
1.212 raeburn 10361: my @cached;
10362: foreach my $name (@posscached) {
10363: if ($cachekeys->{$name}) {
10364: push(@cached,&escape($name).':'.&escape($dom));
10365: }
10366: }
10367: if (@cached) {
10368: &Apache::lonnet::remote_devalidate_cache($server,\@cached);
10369: }
1.205 raeburn 10370: }
10371: }
10372: return;
10373: }
10374:
1.3 raeburn 10375: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>