Annotation of loncom/interface/domainprefs.pm, revision 1.167
1.1 raeburn 1: # The LearningOnline Network with CAPA
2: # Handler to set domain-wide configuration settings
3: #
1.167 ! raeburn 4: # $Id: domainprefs.pm,v 1.166 2012/08/25 21:48:12 raeburn Exp $
1.2 albertel 5: #
1.1 raeburn 6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA#
23: # /home/httpd/html/adm/gpl.txt
24: #
25: # http://www.lon-capa.org/
26: #
27: #
28: ###############################################################
29: ##############################################################
30:
1.101 raeburn 31: =pod
32:
33: =head1 NAME
34:
35: Apache::domainprefs.pm
36:
37: =head1 SYNOPSIS
38:
39: Handles configuration of a LON-CAPA domain.
40:
41: This is part of the LearningOnline Network with CAPA project
42: described at http://www.lon-capa.org.
43:
44:
45: =head1 OVERVIEW
46:
47: Each institution using LON-CAPA will typically have a single domain designated
48: for use by individuals affliated with the institution. Accordingly, each domain
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.163 raeburn 89: number of rows displayed on the page, and $action is the context (quotas,
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,
97: used by course owners to request creation of a course.
98:
99: Outputs: 1
100:
101: $datatable - HTML containing form elements which allow settings to be changed.
102:
103: In the case of course requests, radio buttons are displayed for each institutional
104: affiliate type (and also default, and _LC_adv) for each of the course types
105: (official, unofficial and community). In each case the radio buttons allow the
106: selection of one of four values:
107:
1.104 raeburn 108: 0, approval, validate, autolimit=N (where N is blank, or a positive integer).
1.101 raeburn 109: which have the following effects:
110:
111: 0
112:
113: =over
114:
115: - course requests are not allowed for this course types/affiliation
116:
117: =back
118:
1.104 raeburn 119: approval
1.101 raeburn 120:
121: =over
122:
123: - course requests must be approved by a Doman Coordinator in the
124: course's domain
125:
126: =back
127:
128: validate
129:
130: =over
131:
132: - an institutional validation (e.g., check requestor is instructor
133: of record) needs to be passed before the course will be created. The required
134: validation is in localenroll.pm on the primary library server for the course
135: domain.
136:
137: =back
138:
139: autolimit
140:
141: =over
142:
1.143 raeburn 143: - course requests will be processed automatically up to a limit of
1.101 raeburn 144: N requests for the course type for the particular requestor.
145: If N is undefined, there is no limit to the number of course requests
146: which a course owner may submit and have processed automatically.
147:
148: =back
149:
150: =item modify_quotas()
151:
152: =back
153:
154: =cut
155:
1.1 raeburn 156: package Apache::domainprefs;
157:
158: use strict;
159: use Apache::Constants qw(:common :http);
160: use Apache::lonnet;
161: use Apache::loncommon();
162: use Apache::lonhtmlcommon();
163: use Apache::lonlocal;
1.43 raeburn 164: use Apache::lonmsg();
1.91 raeburn 165: use Apache::lonconfigsettings;
1.69 raeburn 166: use LONCAPA qw(:DEFAULT :match);
1.6 raeburn 167: use LONCAPA::Enrollment;
1.81 raeburn 168: use LONCAPA::lonauthcgi();
1.9 raeburn 169: use File::Copy;
1.43 raeburn 170: use Locale::Language;
1.62 raeburn 171: use DateTime::TimeZone;
1.68 raeburn 172: use DateTime::Locale;
1.1 raeburn 173:
1.155 raeburn 174: my $registered_cleanup;
175: my $modified_urls;
176:
1.1 raeburn 177: sub handler {
178: my $r=shift;
179: if ($r->header_only) {
180: &Apache::loncommon::content_type($r,'text/html');
181: $r->send_http_header;
182: return OK;
183: }
184:
1.91 raeburn 185: my $context = 'domain';
1.1 raeburn 186: my $dom = $env{'request.role.domain'};
1.5 albertel 187: my $domdesc = &Apache::lonnet::domain($dom,'description');
1.1 raeburn 188: if (&Apache::lonnet::allowed('mau',$dom)) {
189: &Apache::loncommon::content_type($r,'text/html');
190: $r->send_http_header;
191: } else {
192: $env{'user.error.msg'}=
193: "/adm/domainprefs:mau:0:0:Cannot modify domain settings";
194: return HTTP_NOT_ACCEPTABLE;
195: }
1.155 raeburn 196:
197: $registered_cleanup=0;
198: @{$modified_urls}=();
199:
1.1 raeburn 200: &Apache::lonhtmlcommon::clear_breadcrumbs();
201: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.58 raeburn 202: ['phase','actions']);
1.30 raeburn 203: my $phase = 'pickactions';
1.3 raeburn 204: if ( exists($env{'form.phase'}) ) {
205: $phase = $env{'form.phase'};
206: }
1.150 raeburn 207: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.3 raeburn 208: my %domconfig =
1.6 raeburn 209: &Apache::lonnet::get_dom('configuration',['login','rolecolors',
1.125 raeburn 210: 'quotas','autoenroll','autoupdate','autocreate',
211: 'directorysrch','usercreation','usermodification',
212: 'contacts','defaults','scantron','coursecategories',
213: 'serverstatuses','requestcourses','helpsettings',
1.163 raeburn 214: 'coursedefaults','usersessions','loadbalancing',
215: 'requestauthor'],$dom);
1.43 raeburn 216: my @prefs_order = ('rolecolors','login','defaults','quotas','autoenroll',
1.125 raeburn 217: 'autoupdate','autocreate','directorysrch','contacts',
1.48 raeburn 218: 'usercreation','usermodification','scantron',
1.163 raeburn 219: 'requestcourses','requestauthor','coursecategories',
220: 'serverstatuses','helpsettings',
1.137 raeburn 221: 'coursedefaults','usersessions');
1.150 raeburn 222: if (keys(%servers) > 1) {
223: push(@prefs_order,'loadbalancing');
224: }
1.30 raeburn 225: my %prefs = (
226: 'rolecolors' =>
227: { text => 'Default color schemes',
1.67 raeburn 228: help => 'Domain_Configuration_Color_Schemes',
1.30 raeburn 229: header => [{col1 => 'Student Settings',
230: col2 => '',},
231: {col1 => 'Coordinator Settings',
232: col2 => '',},
233: {col1 => 'Author Settings',
234: col2 => '',},
235: {col1 => 'Administrator Settings',
236: col2 => '',}],
237: },
1.110 raeburn 238: 'login' =>
1.30 raeburn 239: { text => 'Log-in page options',
1.67 raeburn 240: help => 'Domain_Configuration_Login_Page',
1.30 raeburn 241: header => [{col1 => 'Item',
242: col2 => '',}],
243: },
1.110 raeburn 244:
1.43 raeburn 245: 'defaults' =>
1.141 raeburn 246: { text => 'Default authentication/language/timezone/portal',
1.67 raeburn 247: help => 'Domain_Configuration_LangTZAuth',
1.43 raeburn 248: header => [{col1 => 'Setting',
249: col2 => 'Value'}],
250: },
1.30 raeburn 251: 'quotas' =>
1.162 raeburn 252: { text => 'Blogs, personal web pages, webDAV, portfolios',
1.67 raeburn 253: help => 'Domain_Configuration_Quotas',
1.77 raeburn 254: header => [{col1 => 'User affiliation',
1.72 raeburn 255: col2 => 'Available tools',
256: col3 => 'Portfolio quota',}],
1.30 raeburn 257: },
258: 'autoenroll' =>
259: { text => 'Auto-enrollment settings',
1.67 raeburn 260: help => 'Domain_Configuration_Auto_Enrollment',
1.30 raeburn 261: header => [{col1 => 'Configuration setting',
262: col2 => 'Value(s)'}],
263: },
264: 'autoupdate' =>
265: { text => 'Auto-update settings',
1.67 raeburn 266: help => 'Domain_Configuration_Auto_Updates',
1.30 raeburn 267: header => [{col1 => 'Setting',
268: col2 => 'Value',},
1.131 raeburn 269: {col1 => 'Setting',
270: col2 => 'Affiliation'},
1.43 raeburn 271: {col1 => 'User population',
1.131 raeburn 272: col2 => 'Updateable user data'}],
1.30 raeburn 273: },
1.125 raeburn 274: 'autocreate' =>
275: { text => 'Auto-course creation settings',
276: help => 'Domain_Configuration_Auto_Creation',
277: header => [{col1 => 'Configuration Setting',
278: col2 => 'Value',}],
279: },
1.30 raeburn 280: 'directorysrch' =>
281: { text => 'Institutional directory searches',
1.67 raeburn 282: help => 'Domain_Configuration_InstDirectory_Search',
1.30 raeburn 283: header => [{col1 => 'Setting',
284: col2 => 'Value',}],
285: },
286: 'contacts' =>
287: { text => 'Contact Information',
1.67 raeburn 288: help => 'Domain_Configuration_Contact_Info',
1.30 raeburn 289: header => [{col1 => 'Setting',
290: col2 => 'Value',}],
291: },
292:
293: 'usercreation' =>
294: { text => 'User creation',
1.67 raeburn 295: help => 'Domain_Configuration_User_Creation',
1.43 raeburn 296: header => [{col1 => 'Format rule type',
297: col2 => 'Format rules in force'},
1.34 raeburn 298: {col1 => 'User account creation',
299: col2 => 'Usernames which may be created',},
1.30 raeburn 300: {col1 => 'Context',
1.43 raeburn 301: col2 => 'Assignable authentication types'}],
1.30 raeburn 302: },
1.69 raeburn 303: 'usermodification' =>
1.33 raeburn 304: { text => 'User modification',
1.67 raeburn 305: help => 'Domain_Configuration_User_Modification',
1.33 raeburn 306: header => [{col1 => 'Target user has role',
307: col2 => 'User information updateable in author context'},
308: {col1 => 'Target user has role',
1.63 raeburn 309: col2 => 'User information updateable in course context'},
310: {col1 => "Status of user",
311: col2 => 'Information settable when self-creating account (if directory data blank)'}],
1.33 raeburn 312: },
1.69 raeburn 313: 'scantron' =>
1.95 www 314: { text => 'Bubblesheet format file',
1.67 raeburn 315: help => 'Domain_Configuration_Scantron_Format',
1.46 raeburn 316: header => [ {col1 => 'Item',
317: col2 => '',
318: }],
319: },
1.86 raeburn 320: 'requestcourses' =>
321: {text => 'Request creation of courses',
322: help => 'Domain_Configuration_Request_Courses',
323: header => [{col1 => 'User affiliation',
1.102 raeburn 324: col2 => 'Availability/Processing of requests',},
325: {col1 => 'Setting',
326: col2 => 'Value'}],
1.86 raeburn 327: },
1.163 raeburn 328: 'requestauthor' =>
329: {text => 'Request authoring space',
330: help => 'Domain_Configuration_Request_Author',
331: header => [{col1 => 'User affiliation',
332: col2 => 'Availability/Processing of requests',},
333: {col1 => 'Setting',
334: col2 => 'Value'}],
335: },
1.69 raeburn 336: 'coursecategories' =>
1.120 raeburn 337: { text => 'Cataloging of courses/communities',
1.67 raeburn 338: help => 'Domain_Configuration_Cataloging_Courses',
1.69 raeburn 339: header => [{col1 => 'Category settings',
1.57 raeburn 340: col2 => '',},
341: {col1 => 'Categories',
342: col2 => '',
343: }],
1.69 raeburn 344: },
345: 'serverstatuses' =>
1.77 raeburn 346: {text => 'Access to server status pages',
1.69 raeburn 347: help => 'Domain_Configuration_Server_Status',
348: header => [{col1 => 'Status Page',
349: col2 => 'Other named users',
350: col3 => 'Specific IPs',
351: }],
352: },
1.118 jms 353: 'helpsettings' =>
354: {text => 'Help page settings',
355: help => 'Domain_Configuration_Help_Settings',
1.166 raeburn 356: header => [{col1 => 'Help Settings (logged-in users)',
357: col2 => 'Value'},
358: {col1 => 'Help Settings (before log-in)',
359: col2 => 'Value'}],
1.118 jms 360: },
1.121 raeburn 361: 'coursedefaults' =>
362: {text => 'Course/Community defaults',
363: help => 'Domain_Configuration_Course_Defaults',
1.139 raeburn 364: header => [{col1 => 'Defaults which can be overridden in each course by a CC',
365: col2 => 'Value',},
366: {col1 => 'Defaults which can be overridden for each course by a DC',
367: col2 => 'Value',},],
1.121 raeburn 368: },
1.120 raeburn 369: 'privacy' =>
370: {text => 'User Privacy',
371: help => 'Domain_Configuration_User_Privacy',
372: header => [{col1 => 'Setting',
373: col2 => 'Value',}],
374: },
1.141 raeburn 375: 'usersessions' =>
1.145 raeburn 376: {text => 'User session hosting/offloading',
1.137 raeburn 377: help => 'Domain_Configuration_User_Sessions',
1.145 raeburn 378: header => [{col1 => 'Domain server',
379: col2 => 'Servers to offload sessions to when busy'},
380: {col1 => 'Hosting of users from other domains',
1.137 raeburn 381: col2 => 'Rules'},
382: {col1 => "Hosting domain's own users elsewhere",
383: col2 => 'Rules'}],
384: },
1.150 raeburn 385: 'loadbalancing' =>
386: {text => 'Dedicated Load Balancer',
387: help => 'Domain_Configuration_Load_Balancing',
388: header => [{col1 => 'Server',
389: col2 => 'Default destinations',
390: col3 => 'User affliation',
391: col4 => 'Overrides'},
392: ],
393: },
1.3 raeburn 394: );
1.110 raeburn 395: if (keys(%servers) > 1) {
396: $prefs{'login'} = { text => 'Log-in page options',
397: help => 'Domain_Configuration_Login_Page',
398: header => [{col1 => 'Log-in Service',
399: col2 => 'Server Setting',},
400: {col1 => 'Log-in Page Items',
401: col2 => ''}],
402: };
403: }
1.6 raeburn 404: my @roles = ('student','coordinator','author','admin');
1.30 raeburn 405: my @actions = &Apache::loncommon::get_env_multiple('form.actions');
1.3 raeburn 406: &Apache::lonhtmlcommon::add_breadcrumb
1.30 raeburn 407: ({href=>"javascript:changePage(document.$phase,'pickactions')",
1.133 raeburn 408: text=>"Settings to display/modify"});
1.9 raeburn 409: my $confname = $dom.'-domainconfig';
1.3 raeburn 410: if ($phase eq 'process') {
1.91 raeburn 411: &Apache::lonconfigsettings::make_changes($r,$dom,$phase,$context,\@prefs_order,\%prefs,\%domconfig,$confname,\@roles);
1.30 raeburn 412: } elsif ($phase eq 'display') {
1.165 raeburn 413: my $js = &recaptcha_js();
1.152 raeburn 414: if (keys(%servers) > 1) {
415: my ($othertitle,$usertypes,$types) =
416: &Apache::loncommon::sorted_inst_types($dom);
417: $js = &lonbalance_targets_js($dom,$types,\%servers).
418: &new_spares_js().
1.153 raeburn 419: &common_domprefs_js().
420: &Apache::loncommon::javascript_array_indexof();
1.152 raeburn 421: }
1.150 raeburn 422: &Apache::lonconfigsettings::display_settings($r,$dom,$phase,$context,\@prefs_order,\%prefs,\%domconfig,$confname,$js);
1.1 raeburn 423: } else {
1.21 raeburn 424: if (keys(%domconfig) == 0) {
425: my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
1.29 raeburn 426: my @ids=&Apache::lonnet::current_machine_ids();
427: if (!grep(/^\Q$primarylibserv\E$/,@ids)) {
1.21 raeburn 428: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.41 raeburn 429: my @loginimages = ('img','logo','domlogo','login');
1.21 raeburn 430: my $custom_img_count = 0;
431: foreach my $img (@loginimages) {
432: if ($designhash{$dom.'.login.'.$img} ne '') {
433: $custom_img_count ++;
434: }
435: }
436: foreach my $role (@roles) {
437: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
438: $custom_img_count ++;
439: }
440: }
441: if ($custom_img_count > 0) {
1.94 raeburn 442: &Apache::lonconfigsettings::print_header($r,$phase,$context);
1.21 raeburn 443: my $switch_server = &check_switchserver($dom,$confname);
1.29 raeburn 444: $r->print(
445: &mt('Domain configuration settings have yet to be saved for this domain via the web-based domain preferences interface.').'<br />'.
446: &mt("While this remains so, you must switch to the domain's primary library server in order to update settings.").'<br /><br />'.
447: &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 />'.
448: &mt("However, you will still need to switch to the domain's primary library server to upload new images or logos.").'<br /><br />');
449: if ($switch_server) {
1.30 raeburn 450: $r->print($switch_server.' '.&mt('to primary library server for domain: [_1]',$dom));
1.29 raeburn 451: }
1.91 raeburn 452: $r->print(&Apache::loncommon::end_page());
1.21 raeburn 453: return OK;
454: }
455: }
456: }
1.91 raeburn 457: &Apache::lonconfigsettings::display_choices($r,$phase,$context,\@prefs_order,\%prefs);
1.3 raeburn 458: }
459: return OK;
460: }
461:
462: sub process_changes {
1.92 raeburn 463: my ($r,$dom,$confname,$action,$roles,$values) = @_;
464: my %domconfig;
465: if (ref($values) eq 'HASH') {
466: %domconfig = %{$values};
467: }
1.3 raeburn 468: my $output;
469: if ($action eq 'login') {
1.9 raeburn 470: $output = &modify_login($r,$dom,$confname,%domconfig);
1.6 raeburn 471: } elsif ($action eq 'rolecolors') {
1.9 raeburn 472: $output = &modify_rolecolors($r,$dom,$confname,$roles,
473: %domconfig);
1.3 raeburn 474: } elsif ($action eq 'quotas') {
1.86 raeburn 475: $output = &modify_quotas($dom,$action,%domconfig);
1.3 raeburn 476: } elsif ($action eq 'autoenroll') {
477: $output = &modify_autoenroll($dom,%domconfig);
478: } elsif ($action eq 'autoupdate') {
479: $output = &modify_autoupdate($dom,%domconfig);
1.125 raeburn 480: } elsif ($action eq 'autocreate') {
481: $output = &modify_autocreate($dom,%domconfig);
1.23 raeburn 482: } elsif ($action eq 'directorysrch') {
483: $output = &modify_directorysrch($dom,%domconfig);
1.27 raeburn 484: } elsif ($action eq 'usercreation') {
1.28 raeburn 485: $output = &modify_usercreation($dom,%domconfig);
1.33 raeburn 486: } elsif ($action eq 'usermodification') {
487: $output = &modify_usermodification($dom,%domconfig);
1.28 raeburn 488: } elsif ($action eq 'contacts') {
489: $output = &modify_contacts($dom,%domconfig);
1.43 raeburn 490: } elsif ($action eq 'defaults') {
491: $output = &modify_defaults($dom,$r);
1.46 raeburn 492: } elsif ($action eq 'scantron') {
1.48 raeburn 493: $output = &modify_scantron($r,$dom,$confname,%domconfig);
494: } elsif ($action eq 'coursecategories') {
495: $output = &modify_coursecategories($dom,%domconfig);
1.69 raeburn 496: } elsif ($action eq 'serverstatuses') {
497: $output = &modify_serverstatuses($dom,%domconfig);
1.86 raeburn 498: } elsif ($action eq 'requestcourses') {
499: $output = &modify_quotas($dom,$action,%domconfig);
1.163 raeburn 500: } elsif ($action eq 'requestauthor') {
501: $output = &modify_quotas($dom,$action,%domconfig);
1.118 jms 502: } elsif ($action eq 'helpsettings') {
1.122 jms 503: $output = &modify_helpsettings($r,$dom,$confname,%domconfig);
1.121 raeburn 504: } elsif ($action eq 'coursedefaults') {
505: $output = &modify_coursedefaults($dom,%domconfig);
1.137 raeburn 506: } elsif ($action eq 'usersessions') {
507: $output = &modify_usersessions($dom,%domconfig);
1.150 raeburn 508: } elsif ($action eq 'loadbalancing') {
509: $output = &modify_loadbalancing($dom,%domconfig);
1.3 raeburn 510: }
511: return $output;
512: }
513:
514: sub print_config_box {
1.9 raeburn 515: my ($r,$dom,$confname,$phase,$action,$item,$settings) = @_;
1.30 raeburn 516: my $rowtotal = 0;
1.49 raeburn 517: my $output;
518: if ($action eq 'coursecategories') {
519: $output = &coursecategories_javascript($settings);
1.91 raeburn 520: }
1.49 raeburn 521: $output .=
1.30 raeburn 522: '<table class="LC_nested_outer">
1.3 raeburn 523: <tr>
1.66 raeburn 524: <th align="left" valign="middle"><span class="LC_nobreak">'.
525: &mt($item->{text}).' '.
526: &Apache::loncommon::help_open_topic($item->{'help'}).'</span></th>'."\n".
527: '</tr>';
1.30 raeburn 528: $rowtotal ++;
1.110 raeburn 529: my $numheaders = 1;
530: if (ref($item->{'header'}) eq 'ARRAY') {
531: $numheaders = scalar(@{$item->{'header'}});
532: }
533: if ($numheaders > 1) {
1.64 raeburn 534: my $colspan = '';
1.145 raeburn 535: my $rightcolspan = '';
1.166 raeburn 536: if (($action eq 'rolecolors') || ($action eq 'coursecategories')) {
1.64 raeburn 537: $colspan = ' colspan="2"';
538: }
1.145 raeburn 539: if ($action eq 'usersessions') {
540: $rightcolspan = ' colspan="3"';
541: }
1.30 raeburn 542: $output .= '
1.3 raeburn 543: <tr>
544: <td>
545: <table class="LC_nested">
546: <tr class="LC_info_row">
1.59 bisitz 547: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[0]->{'col1'}).'</td>
1.145 raeburn 548: <td class="LC_right_item"'.$rightcolspan.'>'.&mt($item->{'header'}->[0]->{'col2'}).'</td>
1.30 raeburn 549: </tr>';
1.69 raeburn 550: $rowtotal ++;
1.6 raeburn 551: if ($action eq 'autoupdate') {
1.30 raeburn 552: $output .= &print_autoupdate('top',$dom,$settings,\$rowtotal);
1.28 raeburn 553: } elsif ($action eq 'usercreation') {
1.33 raeburn 554: $output .= &print_usercreation('top',$dom,$settings,\$rowtotal);
555: } elsif ($action eq 'usermodification') {
556: $output .= &print_usermodification('top',$dom,$settings,\$rowtotal);
1.57 raeburn 557: } elsif ($action eq 'coursecategories') {
558: $output .= &print_coursecategories('top',$dom,$item,$settings,\$rowtotal);
1.110 raeburn 559: } elsif ($action eq 'login') {
560: $output .= &print_login('top',$dom,$confname,$phase,$settings,\$rowtotal);
561: $colspan = ' colspan="2"';
1.102 raeburn 562: } elsif ($action eq 'requestcourses') {
563: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.163 raeburn 564: } elsif ($action eq 'requestauthor') {
565: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.118 jms 566: } elsif ($action eq 'helpsettings') {
1.122 jms 567: $output .= &print_helpsettings('top',$dom,$confname,$settings,\$rowtotal);
1.137 raeburn 568: } elsif ($action eq 'usersessions') {
569: $output .= &print_usersessions('top',$dom,$settings,\$rowtotal);
1.122 jms 570: } elsif ($action eq 'rolecolors') {
1.30 raeburn 571: $output .= &print_rolecolors($phase,'student',$dom,$confname,$settings,\$rowtotal);
1.139 raeburn 572: } elsif ($action eq 'coursedefaults') {
573: $output .= &print_coursedefaults('top',$dom,$settings,\$rowtotal);
1.6 raeburn 574: }
1.30 raeburn 575: $output .= '
1.6 raeburn 576: </table>
577: </td>
578: </tr>
579: <tr>
580: <td>
581: <table class="LC_nested">
582: <tr class="LC_info_row">
1.59 bisitz 583: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col1'}).'</td>';
1.57 raeburn 584: $output .= '
1.59 bisitz 585: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col2'}).'</td>
1.30 raeburn 586: </tr>';
587: $rowtotal ++;
1.6 raeburn 588: if ($action eq 'autoupdate') {
1.131 raeburn 589: $output .= &print_autoupdate('middle',$dom,$settings,\$rowtotal).'
590: </table>
591: </td>
592: </tr>
593: <tr>
594: <td>
595: <table class="LC_nested">
596: <tr class="LC_info_row">
597: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
598: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
599: &print_autoupdate('bottom',$dom,$settings,\$rowtotal);
600: $rowtotal ++;
1.28 raeburn 601: } elsif ($action eq 'usercreation') {
1.34 raeburn 602: $output .= &print_usercreation('middle',$dom,$settings,\$rowtotal).'
603: </table>
604: </td>
605: </tr>
606: <tr>
607: <td>
608: <table class="LC_nested">
609: <tr class="LC_info_row">
1.59 bisitz 610: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
611: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
1.34 raeburn 612: &print_usercreation('bottom',$dom,$settings,\$rowtotal);
613: $rowtotal ++;
1.33 raeburn 614: } elsif ($action eq 'usermodification') {
1.63 raeburn 615: $output .= &print_usermodification('middle',$dom,$settings,\$rowtotal).'
616: </table>
617: </td>
618: </tr>
619: <tr>
620: <td>
621: <table class="LC_nested">
622: <tr class="LC_info_row">
623: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
624: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
625: &print_usermodification('bottom',$dom,$settings,\$rowtotal);
626: $rowtotal ++;
1.57 raeburn 627: } elsif ($action eq 'coursecategories') {
628: $output .= &print_coursecategories('bottom',$dom,$item,$settings,\$rowtotal);
1.110 raeburn 629: } elsif ($action eq 'login') {
630: $output .= &print_login('bottom',$dom,$confname,$phase,$settings,\$rowtotal);
1.102 raeburn 631: } elsif ($action eq 'requestcourses') {
1.163 raeburn 632: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
633: } elsif ($action eq 'requestauthor') {
634: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
1.122 jms 635: } elsif ($action eq 'helpsettings') {
636: $output .= &print_helpsettings('bottom',$dom,$confname,$settings,\$rowtotal);
1.137 raeburn 637: } elsif ($action eq 'usersessions') {
1.145 raeburn 638: $output .= &print_usersessions('middle',$dom,$settings,\$rowtotal).'
639: </table>
640: </td>
641: </tr>
642: <tr>
643: <td>
644: <table class="LC_nested">
645: <tr class="LC_info_row">
646: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
647: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
648: &print_usersessions('bottom',$dom,$settings,\$rowtotal);
649: $rowtotal ++;
1.139 raeburn 650: } elsif ($action eq 'coursedefaults') {
651: $output .= &print_coursedefaults('bottom',$dom,$settings,\$rowtotal);
1.122 jms 652: } elsif ($action eq 'rolecolors') {
1.30 raeburn 653: $output .= &print_rolecolors($phase,'coordinator',$dom,$confname,$settings,\$rowtotal).'
1.6 raeburn 654: </table>
655: </td>
656: </tr>
657: <tr>
658: <td>
659: <table class="LC_nested">
660: <tr class="LC_info_row">
1.69 raeburn 661: <td class="LC_left_item"'.$colspan.' valign="top">'.
662: &mt($item->{'header'}->[2]->{'col1'}).'</td>
663: <td class="LC_right_item" valign="top">'.
664: &mt($item->{'header'}->[2]->{'col2'}).'</td>
1.3 raeburn 665: </tr>'.
1.30 raeburn 666: &print_rolecolors($phase,'author',$dom,$confname,$settings,\$rowtotal).'
1.3 raeburn 667: </table>
668: </td>
669: </tr>
670: <tr>
671: <td>
672: <table class="LC_nested">
673: <tr class="LC_info_row">
1.59 bisitz 674: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
675: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
1.3 raeburn 676: </tr>'.
1.30 raeburn 677: &print_rolecolors($phase,'admin',$dom,$confname,$settings,\$rowtotal);
678: $rowtotal += 2;
1.6 raeburn 679: }
1.3 raeburn 680: } else {
1.30 raeburn 681: $output .= '
1.3 raeburn 682: <tr>
683: <td>
684: <table class="LC_nested">
1.30 raeburn 685: <tr class="LC_info_row">';
1.24 raeburn 686: if (($action eq 'login') || ($action eq 'directorysrch')) {
1.30 raeburn 687: $output .= '
1.59 bisitz 688: <td class="LC_left_item" colspan="2">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
1.69 raeburn 689: } elsif ($action eq 'serverstatuses') {
690: $output .= '
691: <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).
692: '<br />('.&mt('Automatic access for Dom. Coords.').')</td>';
693:
1.6 raeburn 694: } else {
1.30 raeburn 695: $output .= '
1.69 raeburn 696: <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
697: }
1.72 raeburn 698: if (defined($item->{'header'}->[0]->{'col3'})) {
699: $output .= '<td class="LC_left_item" valign="top">'.
700: &mt($item->{'header'}->[0]->{'col2'});
701: if ($action eq 'serverstatuses') {
702: $output .= '<br />(<tt>'.&mt('user1:domain1,user2:domain2 etc.').'</tt>)';
703: }
1.69 raeburn 704: } else {
705: $output .= '<td class="LC_right_item" valign="top">'.
706: &mt($item->{'header'}->[0]->{'col2'});
707: }
708: $output .= '</td>';
709: if ($item->{'header'}->[0]->{'col3'}) {
1.150 raeburn 710: if (defined($item->{'header'}->[0]->{'col4'})) {
711: $output .= '<td class="LC_left_item" valign="top">'.
712: &mt($item->{'header'}->[0]->{'col3'});
713: } else {
714: $output .= '<td class="LC_right_item" valign="top">'.
715: &mt($item->{'header'}->[0]->{'col3'});
716: }
1.69 raeburn 717: if ($action eq 'serverstatuses') {
718: $output .= '<br />(<tt>'.&mt('IP1,IP2 etc.').'</tt>)';
719: }
720: $output .= '</td>';
1.6 raeburn 721: }
1.150 raeburn 722: if ($item->{'header'}->[0]->{'col4'}) {
723: $output .= '<td class="LC_right_item" valign="top">'.
724: &mt($item->{'header'}->[0]->{'col4'});
725: }
1.69 raeburn 726: $output .= '</tr>';
1.48 raeburn 727: $rowtotal ++;
1.3 raeburn 728: if ($action eq 'login') {
1.110 raeburn 729: $output .= &print_login('bottom',$dom,$confname,$phase,$settings,
730: \$rowtotal);
1.3 raeburn 731: } elsif ($action eq 'quotas') {
1.86 raeburn 732: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.3 raeburn 733: } elsif ($action eq 'autoenroll') {
1.30 raeburn 734: $output .= &print_autoenroll($dom,$settings,\$rowtotal);
1.125 raeburn 735: } elsif ($action eq 'autocreate') {
736: $output .= &print_autocreate($dom,$settings,\$rowtotal);
1.23 raeburn 737: } elsif ($action eq 'directorysrch') {
1.30 raeburn 738: $output .= &print_directorysrch($dom,$settings,\$rowtotal);
1.28 raeburn 739: } elsif ($action eq 'contacts') {
1.30 raeburn 740: $output .= &print_contacts($dom,$settings,\$rowtotal);
1.43 raeburn 741: } elsif ($action eq 'defaults') {
742: $output .= &print_defaults($dom,\$rowtotal);
1.46 raeburn 743: } elsif ($action eq 'scantron') {
744: $output .= &print_scantronformat($r,$dom,$confname,$settings,\$rowtotal);
1.69 raeburn 745: } elsif ($action eq 'serverstatuses') {
746: $output .= &print_serverstatuses($dom,$settings,\$rowtotal);
1.118 jms 747: } elsif ($action eq 'helpsettings') {
1.122 jms 748: $output .= &print_helpsettings('top',$dom,$confname,$settings,\$rowtotal);
1.150 raeburn 749: } elsif ($action eq 'loadbalancing') {
750: $output .= &print_loadbalancing($dom,$settings,\$rowtotal);
1.121 raeburn 751: }
1.3 raeburn 752: }
1.30 raeburn 753: $output .= '
1.3 raeburn 754: </table>
755: </td>
756: </tr>
1.30 raeburn 757: </table><br />';
758: return ($output,$rowtotal);
1.1 raeburn 759: }
760:
1.3 raeburn 761: sub print_login {
1.110 raeburn 762: my ($position,$dom,$confname,$phase,$settings,$rowtotal) = @_;
763: my ($css_class,$datatable);
1.6 raeburn 764: my %choices = &login_choices();
1.110 raeburn 765:
766: if ($position eq 'top') {
1.149 raeburn 767: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.110 raeburn 768: my $choice = $choices{'disallowlogin'};
769: $css_class = ' class="LC_odd_row"';
1.128 raeburn 770: $datatable .= '<tr'.$css_class.'><td>'.$choice.'</td>'.
1.110 raeburn 771: '<td align="right"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1.128 raeburn 772: '<th>'.$choices{'server'}.'</th>'.
773: '<th>'.$choices{'serverpath'}.'</th>'.
774: '<th>'.$choices{'custompath'}.'</th>'.
775: '<th><span class="LC_nobreak">'.$choices{'exempt'}.'</span></th></tr>'."\n";
1.110 raeburn 776: my %disallowed;
777: if (ref($settings) eq 'HASH') {
778: if (ref($settings->{'loginvia'}) eq 'HASH') {
779: %disallowed = %{$settings->{'loginvia'}};
780: }
781: }
782: foreach my $lonhost (sort(keys(%servers))) {
783: my $direct = 'selected="selected"';
1.128 raeburn 784: if (ref($disallowed{$lonhost}) eq 'HASH') {
785: if ($disallowed{$lonhost}{'server'} ne '') {
786: $direct = '';
787: }
1.110 raeburn 788: }
1.115 raeburn 789: $datatable .= '<tr><td>'.$servers{$lonhost}.'</td>'.
1.128 raeburn 790: '<td><select name="'.$lonhost.'_server">'.
1.110 raeburn 791: '<option value=""'.$direct.'>'.$choices{'directlogin'}.
792: '</option>';
793: foreach my $hostid (keys(%servers)) {
1.115 raeburn 794: next if ($servers{$hostid} eq $servers{$lonhost});
1.110 raeburn 795: my $selected = '';
1.128 raeburn 796: if (ref($disallowed{$lonhost}) eq 'HASH') {
797: if ($hostid eq $disallowed{$lonhost}{'server'}) {
798: $selected = 'selected="selected"';
799: }
1.110 raeburn 800: }
801: $datatable .= '<option value="'.$hostid.'"'.$selected.'>'.
802: $servers{$hostid}.'</option>';
803: }
1.128 raeburn 804: $datatable .= '</select></td>'.
805: '<td><select name="'.$lonhost.'_serverpath">';
806: foreach my $path ('','/','/adm/login','/adm/roles','custom') {
807: my $pathname = $path;
808: if ($path eq 'custom') {
809: $pathname = &mt('Custom Path').' ->';
810: }
811: my $selected = '';
812: if (ref($disallowed{$lonhost}) eq 'HASH') {
813: if ($path eq $disallowed{$lonhost}{'serverpath'}) {
814: $selected = 'selected="selected"';
815: }
816: } elsif ($path eq '') {
817: $selected = 'selected="selected"';
818: }
819: $datatable .= '<option value="'.$path.'"'.$selected.'>'.$pathname.'</option>';
820: }
821: $datatable .= '</select></td>';
822: my ($custom,$exempt);
823: if (ref($disallowed{$lonhost}) eq 'HASH') {
824: $custom = $disallowed{$lonhost}{'custompath'};
825: $exempt = $disallowed{$lonhost}{'exempt'};
826: }
827: $datatable .= '<td><input type="text" name="'.$lonhost.'_custompath" size="6" value="'.$custom.'" /></td>'.
828: '<td><input type="text" name="'.$lonhost.'_exempt" size="8" value="'.$exempt.'" /></td>'.
829: '</tr>';
1.110 raeburn 830: }
831: $datatable .= '</table></td></tr>';
832: return $datatable;
833: }
834:
1.42 raeburn 835: my %defaultchecked = (
1.43 raeburn 836: 'coursecatalog' => 'on',
837: 'adminmail' => 'off',
838: 'newuser' => 'off',
839: );
1.118 jms 840: my @toggles = ('coursecatalog','adminmail','newuser');
1.42 raeburn 841: my (%checkedon,%checkedoff);
842: foreach my $item (@toggles) {
843: if ($defaultchecked{$item} eq 'on') {
844: $checkedon{$item} = ' checked="checked" ';
845: $checkedoff{$item} = ' ';
846: } elsif ($defaultchecked{$item} eq 'off') {
847: $checkedoff{$item} = ' checked="checked" ';
848: $checkedon{$item} = ' ';
849: }
850: }
1.41 raeburn 851: my @images = ('img','logo','domlogo','login');
852: my @logintext = ('textcol','bgcol');
1.6 raeburn 853: my @bgs = ('pgbg','mainbg','sidebg');
854: my @links = ('link','alink','vlink');
1.7 albertel 855: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.6 raeburn 856: my %defaultdesign = %Apache::loncommon::defaultdesign;
857: my (%is_custom,%designs);
858: my %defaults = (
859: font => $defaultdesign{'login.font'},
860: );
861: foreach my $item (@images) {
862: $defaults{$item} = $defaultdesign{'login.'.$item};
1.70 raeburn 863: $defaults{'showlogo'}{$item} = 1;
1.6 raeburn 864: }
865: foreach my $item (@bgs) {
866: $defaults{'bgs'}{$item} = $defaultdesign{'login.'.$item};
867: }
1.41 raeburn 868: foreach my $item (@logintext) {
869: $defaults{'logintext'}{$item} = $defaultdesign{'login.'.$item};
870: }
1.6 raeburn 871: foreach my $item (@links) {
872: $defaults{'links'}{$item} = $defaultdesign{'login.'.$item};
873: }
1.3 raeburn 874: if (ref($settings) eq 'HASH') {
1.42 raeburn 875: foreach my $item (@toggles) {
876: if ($settings->{$item} eq '1') {
877: $checkedon{$item} = ' checked="checked" ';
878: $checkedoff{$item} = ' ';
879: } elsif ($settings->{$item} eq '0') {
880: $checkedoff{$item} = ' checked="checked" ';
881: $checkedon{$item} = ' ';
882: }
1.1 raeburn 883: }
1.6 raeburn 884: foreach my $item (@images) {
1.70 raeburn 885: if (defined($settings->{$item})) {
1.6 raeburn 886: $designs{$item} = $settings->{$item};
887: $is_custom{$item} = 1;
888: }
1.70 raeburn 889: if (defined($settings->{'showlogo'}{$item})) {
890: $designs{'showlogo'}{$item} = $settings->{'showlogo'}{$item};
891: }
1.6 raeburn 892: }
1.41 raeburn 893: foreach my $item (@logintext) {
894: if ($settings->{$item} ne '') {
895: $designs{'logintext'}{$item} = $settings->{$item};
896: $is_custom{$item} = 1;
897: }
898: }
1.6 raeburn 899: if ($settings->{'font'} ne '') {
900: $designs{'font'} = $settings->{'font'};
901: $is_custom{'font'} = 1;
902: }
903: foreach my $item (@bgs) {
904: if ($settings->{$item} ne '') {
905: $designs{'bgs'}{$item} = $settings->{$item};
906: $is_custom{$item} = 1;
907: }
908: }
909: foreach my $item (@links) {
910: if ($settings->{$item} ne '') {
911: $designs{'links'}{$item} = $settings->{$item};
912: $is_custom{$item} = 1;
913: }
914: }
915: } else {
916: if ($designhash{$dom.'.login.font'} ne '') {
917: $designs{'font'} = $designhash{$dom.'.login.font'};
918: $is_custom{'font'} = 1;
919: }
1.8 raeburn 920: foreach my $item (@images) {
921: if ($designhash{$dom.'.login.'.$item} ne '') {
922: $designs{$item} = $designhash{$dom.'.login.'.$item};
923: $is_custom{$item} = 1;
924: }
925: }
1.6 raeburn 926: foreach my $item (@bgs) {
927: if ($designhash{$dom.'.login.'.$item} ne '') {
928: $designs{'bgs'}{$item} = $designhash{$dom.'.login.'.$item};
929: $is_custom{$item} = 1;
930: }
931: }
932: foreach my $item (@links) {
933: if ($designhash{$dom.'.login.'.$item} ne '') {
934: $designs{'links'}{$item} = $designhash{$dom.'.login.'.$item};
935: $is_custom{$item} = 1;
936: }
937: }
1.1 raeburn 938: }
1.6 raeburn 939: my %alt_text = &Apache::lonlocal::texthash ( img => 'Log-in banner',
940: logo => 'Institution Logo',
1.41 raeburn 941: domlogo => 'Domain Logo',
942: login => 'Login box');
1.6 raeburn 943: my $itemcount = 1;
1.42 raeburn 944: foreach my $item (@toggles) {
945: $css_class = $itemcount%2?' class="LC_odd_row"':'';
946: $datatable .=
947: '<tr'.$css_class.'><td colspan="2">'.$choices{$item}.
948: '</td><td>'.
949: '<span class="LC_nobreak"><label><input type="radio" name="'.
950: $item.'"'.$checkedon{$item}.' value="1" />'.&mt('Yes').
951: '</label> <label><input type="radio" name="'.$item.'"'.
952: $checkedoff{$item}.' value="0" />'.&mt('No').'</label></span></td>'.
953: '</tr>';
954: $itemcount ++;
955: }
1.135 bisitz 956: $datatable .= &display_color_options($dom,$confname,$phase,'login',$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal,\@logintext);
1.6 raeburn 957: $datatable .= '</tr></table></td></tr>';
958: return $datatable;
959: }
960:
961: sub login_choices {
962: my %choices =
963: &Apache::lonlocal::texthash (
1.116 bisitz 964: coursecatalog => 'Display Course/Community Catalog link?',
1.110 raeburn 965: adminmail => "Display Administrator's E-mail Address?",
966: disallowlogin => "Login page requests redirected",
967: hostid => "Server",
1.128 raeburn 968: server => "Redirect to:",
969: serverpath => "Path",
970: custompath => "Custom",
971: exempt => "Exempt IP(s)",
1.110 raeburn 972: directlogin => "No redirect",
973: newuser => "Link to create a user account",
974: img => "Header",
975: logo => "Main Logo",
976: domlogo => "Domain Logo",
977: login => "Log-in Header",
978: textcol => "Text color",
979: bgcol => "Box color",
980: bgs => "Background colors",
981: links => "Link colors",
982: font => "Font color",
983: pgbg => "Header",
984: mainbg => "Page",
985: sidebg => "Login box",
986: link => "Link",
987: alink => "Active link",
988: vlink => "Visited link",
1.6 raeburn 989: );
990: return %choices;
991: }
992:
993: sub print_rolecolors {
1.30 raeburn 994: my ($phase,$role,$dom,$confname,$settings,$rowtotal) = @_;
1.6 raeburn 995: my %choices = &color_font_choices();
996: my @bgs = ('pgbg','tabbg','sidebg');
997: my @links = ('link','alink','vlink');
998: my @images = ('img');
999: my %alt_text = &Apache::lonlocal::texthash(img => "Banner for $role role");
1.7 albertel 1000: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.6 raeburn 1001: my %defaultdesign = %Apache::loncommon::defaultdesign;
1002: my (%is_custom,%designs);
1003: my %defaults = (
1004: img => $defaultdesign{$role.'.img'},
1005: font => $defaultdesign{$role.'.font'},
1.97 tempelho 1006: fontmenu => $defaultdesign{$role.'.fontmenu'},
1.6 raeburn 1007: );
1008: foreach my $item (@bgs) {
1009: $defaults{'bgs'}{$item} = $defaultdesign{$role.'.'.$item};
1010: }
1011: foreach my $item (@links) {
1012: $defaults{'links'}{$item} = $defaultdesign{$role.'.'.$item};
1013: }
1014: if (ref($settings) eq 'HASH') {
1015: if (ref($settings->{$role}) eq 'HASH') {
1016: if ($settings->{$role}->{'img'} ne '') {
1017: $designs{'img'} = $settings->{$role}->{'img'};
1018: $is_custom{'img'} = 1;
1019: }
1020: if ($settings->{$role}->{'font'} ne '') {
1021: $designs{'font'} = $settings->{$role}->{'font'};
1022: $is_custom{'font'} = 1;
1023: }
1.97 tempelho 1024: if ($settings->{$role}->{'fontmenu'} ne '') {
1025: $designs{'fontmenu'} = $settings->{$role}->{'fontmenu'};
1026: $is_custom{'fontmenu'} = 1;
1027: }
1.6 raeburn 1028: foreach my $item (@bgs) {
1029: if ($settings->{$role}->{$item} ne '') {
1030: $designs{'bgs'}{$item} = $settings->{$role}->{$item};
1031: $is_custom{$item} = 1;
1032: }
1033: }
1034: foreach my $item (@links) {
1035: if ($settings->{$role}->{$item} ne '') {
1036: $designs{'links'}{$item} = $settings->{$role}->{$item};
1037: $is_custom{$item} = 1;
1038: }
1039: }
1040: }
1041: } else {
1042: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
1043: $designs{img} = $designhash{$dom.'.'.$role.'.img'};
1044: $is_custom{'img'} = 1;
1045: }
1.97 tempelho 1046: if ($designhash{$dom.'.'.$role.'.fontmenu'} ne '') {
1047: $designs{fontmenu} = $designhash{$dom.'.'.$role.'.fontmenu'};
1048: $is_custom{'fontmenu'} = 1;
1049: }
1.6 raeburn 1050: if ($designhash{$dom.'.'.$role.'.font'} ne '') {
1051: $designs{font} = $designhash{$dom.'.'.$role.'.font'};
1052: $is_custom{'font'} = 1;
1053: }
1054: foreach my $item (@bgs) {
1055: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1056: $designs{'bgs'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1057: $is_custom{$item} = 1;
1058:
1059: }
1060: }
1061: foreach my $item (@links) {
1062: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1063: $designs{'links'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1064: $is_custom{$item} = 1;
1065: }
1066: }
1067: }
1068: my $itemcount = 1;
1.30 raeburn 1069: my $datatable = &display_color_options($dom,$confname,$phase,$role,$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal);
1.6 raeburn 1070: $datatable .= '</tr></table></td></tr>';
1071: return $datatable;
1072: }
1073:
1074: sub display_color_options {
1.9 raeburn 1075: my ($dom,$confname,$phase,$role,$itemcount,$choices,$is_custom,$defaults,$designs,
1.135 bisitz 1076: $images,$bgs,$links,$alt_text,$rowtotal,$logintext) = @_;
1.159 raeburn 1077: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.6 raeburn 1078: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.134 raeburn 1079: my $datatable = '<tr'.$css_class.'>'.
1.6 raeburn 1080: '<td>'.$choices->{'font'}.'</td>';
1081: if (!$is_custom->{'font'}) {
1.30 raeburn 1082: $datatable .= '<td>'.&mt('Default in use:').' <span id="css_default_'.$role.'_font" style="color: '.$defaults->{'font'}.';">'.$defaults->{'font'}.'</span></td>';
1.6 raeburn 1083: } else {
1084: $datatable .= '<td> </td>';
1085: }
1086: my $fontlink = &color_pick($phase,$role,'font',$choices->{'font'},$designs->{'font'});
1.8 raeburn 1087: $datatable .= '<td><span class="LC_nobreak">'.
1.6 raeburn 1088: '<input type="text" size="10" name="'.$role.'_font"'.
1.8 raeburn 1089: ' value="'.$designs->{'font'}.'" /> '.$fontlink.
1.30 raeburn 1090: ' <span id="css_'.$role.'_font" style="background-color: '.
1091: $designs->{'font'}.';"> </span>'.
1.8 raeburn 1092: '</span></td></tr>';
1.107 raeburn 1093: unless ($role eq 'login') {
1094: $datatable .= '<tr'.$css_class.'>'.
1095: '<td>'.$choices->{'fontmenu'}.'</td>';
1096: if (!$is_custom->{'fontmenu'}) {
1097: $datatable .= '<td>'.&mt('Default in use:').' <span id="css_default_'.$role.'_font" style="color: '.$defaults->{'fontmenu'}.';">'.$defaults->{'fontmenu'}.'</span></td>';
1098: } else {
1099: $datatable .= '<td> </td>';
1100: }
1101: $fontlink = &color_pick($phase,$role,'fontmenu',$choices->{'fontmenu'},$designs->{'fontmenu'});
1102: $datatable .= '<td><span class="LC_nobreak">'.
1103: '<input type="text" size="10" name="'.$role.'_fontmenu"'.
1104: ' value="'.$designs->{'fontmenu'}.'" /> '.$fontlink.
1105: ' <span id="css_'.$role.'_fontmenu" style="background-color: '.
1106: $designs->{'fontmenu'}.';"> </span>'.
1107: '</span></td></tr>';
1.97 tempelho 1108: }
1.9 raeburn 1109: my $switchserver = &check_switchserver($dom,$confname);
1.6 raeburn 1110: foreach my $img (@{$images}) {
1.18 albertel 1111: $itemcount ++;
1.6 raeburn 1112: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.8 raeburn 1113: $datatable .= '<tr'.$css_class.'>'.
1.70 raeburn 1114: '<td>'.$choices->{$img};
1.41 raeburn 1115: my ($imgfile,$img_import,$login_hdr_pick,$logincolors);
1.70 raeburn 1116: if ($role eq 'login') {
1117: if ($img eq 'login') {
1118: $login_hdr_pick =
1.135 bisitz 1119: &login_header_options($img,$role,$defaults,$is_custom,$choices);
1.70 raeburn 1120: $logincolors =
1121: &login_text_colors($img,$role,$logintext,$phase,$choices,
1122: $designs);
1123: } elsif ($img ne 'domlogo') {
1124: $datatable.= &logo_display_options($img,$defaults,$designs);
1125: }
1126: }
1127: $datatable .= '</td>';
1.6 raeburn 1128: if ($designs->{$img} ne '') {
1129: $imgfile = $designs->{$img};
1.18 albertel 1130: $img_import = ($imgfile =~ m{^/adm/});
1.6 raeburn 1131: } else {
1132: $imgfile = $defaults->{$img};
1133: }
1134: if ($imgfile) {
1.9 raeburn 1135: my ($showfile,$fullsize);
1136: if ($imgfile =~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
1.6 raeburn 1137: my $urldir = $1;
1138: my $filename = $2;
1139: my @info = &Apache::lonnet::stat_file($designs->{$img});
1140: if (@info) {
1141: my $thumbfile = 'tn-'.$filename;
1142: my @thumb=&Apache::lonnet::stat_file($urldir.'/'.$thumbfile);
1143: if (@thumb) {
1144: $showfile = $urldir.'/'.$thumbfile;
1145: } else {
1146: $showfile = $imgfile;
1147: }
1148: } else {
1149: $showfile = '';
1150: }
1151: } elsif ($imgfile =~ m-^/(adm/[^/]+)/([^/]+)$-) {
1.16 raeburn 1152: $showfile = $imgfile;
1.6 raeburn 1153: my $imgdir = $1;
1154: my $filename = $2;
1.159 raeburn 1155: if (-e "$londocroot/$imgdir/tn-".$filename) {
1.6 raeburn 1156: $showfile = "/$imgdir/tn-".$filename;
1157: } else {
1.159 raeburn 1158: my $input = $londocroot.$imgfile;
1159: my $output = "$londocroot/$imgdir/tn-".$filename;
1.6 raeburn 1160: if (!-e $output) {
1.9 raeburn 1161: my ($width,$height) = &thumb_dimensions();
1.16 raeburn 1162: my ($fullwidth,$fullheight) = &check_dimensions($input);
1163: if ($fullwidth ne '' && $fullheight ne '') {
1164: if ($fullwidth > $width && $fullheight > $height) {
1165: my $size = $width.'x'.$height;
1166: system("convert -sample $size $input $output");
1.159 raeburn 1167: $showfile = "/$imgdir/tn-".$filename;
1.16 raeburn 1168: }
1169: }
1.6 raeburn 1170: }
1171: }
1.16 raeburn 1172: }
1.6 raeburn 1173: if ($showfile) {
1.40 raeburn 1174: if ($showfile =~ m{^/(adm|res)/}) {
1175: if ($showfile =~ m{^/res/}) {
1176: my $local_showfile =
1177: &Apache::lonnet::filelocation('',$showfile);
1178: &Apache::lonnet::repcopy($local_showfile);
1179: }
1180: $showfile = &Apache::loncommon::lonhttpdurl($showfile);
1181: }
1182: if ($imgfile) {
1183: if ($imgfile =~ m{^/(adm|res)/}) {
1184: if ($imgfile =~ m{^/res/}) {
1185: my $local_imgfile =
1186: &Apache::lonnet::filelocation('',$imgfile);
1187: &Apache::lonnet::repcopy($local_imgfile);
1188: }
1189: $fullsize = &Apache::loncommon::lonhttpdurl($imgfile);
1190: } else {
1191: $fullsize = $imgfile;
1192: }
1193: }
1.41 raeburn 1194: $datatable .= '<td>';
1195: if ($img eq 'login') {
1.135 bisitz 1196: $datatable .= $login_hdr_pick;
1197: }
1.41 raeburn 1198: $datatable .= &image_changes($is_custom->{$img},$alt_text->{$img},$img_import,
1199: $showfile,$fullsize,$role,$img,$imgfile,$logincolors);
1.6 raeburn 1200: } else {
1201: $datatable .= '<td colspan="2" class="LC_right_item"><br />'.
1202: &mt('Upload:');
1203: }
1204: } else {
1205: $datatable .= '<td colspan="2" class="LC_right_item"><br />'.
1206: &mt('Upload:');
1207: }
1.9 raeburn 1208: if ($switchserver) {
1209: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1210: } else {
1.135 bisitz 1211: if ($img ne 'login') { # suppress file selection for Log-in header
1212: $datatable .=' <input type="file" name="'.$role.'_'.$img.'" />';
1213: }
1.9 raeburn 1214: }
1215: $datatable .= '</td></tr>';
1.6 raeburn 1216: }
1217: $itemcount ++;
1218: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1219: $datatable .= '<tr'.$css_class.'>'.
1220: '<td>'.$choices->{'bgs'}.'</td>';
1221: my $bgs_def;
1222: foreach my $item (@{$bgs}) {
1223: if (!$is_custom->{$item}) {
1.70 raeburn 1224: $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 1225: }
1226: }
1227: if ($bgs_def) {
1.8 raeburn 1228: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$bgs_def.'</tr></table></td>';
1.6 raeburn 1229: } else {
1230: $datatable .= '<td> </td>';
1231: }
1232: $datatable .= '<td class="LC_right_item">'.
1233: '<table border="0"><tr>';
1234: foreach my $item (@{$bgs}) {
1235: my $link = &color_pick($phase,$role,$item,$choices->{$item},$designs->{'bgs'}{$item});
1236: $datatable .= '<td align="center">'.$link;
1237: if ($designs->{'bgs'}{$item}) {
1.30 raeburn 1238: $datatable .= ' <span id="css_'.$role.'_'.$item.'" style="background-color: '.$designs->{'bgs'}{$item}.';"> </span>';
1.6 raeburn 1239: }
1240: $datatable .= '<br /><input type="text" size="8" name="'.$role.'_'.$item.'" value="'.$designs->{'bgs'}{$item}.
1.41 raeburn 1241: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.6 raeburn 1242: }
1243: $datatable .= '</tr></table></td></tr>';
1244: $itemcount ++;
1245: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1246: $datatable .= '<tr'.$css_class.'>'.
1247: '<td>'.$choices->{'links'}.'</td>';
1248: my $links_def;
1249: foreach my $item (@{$links}) {
1250: if (!$is_custom->{$item}) {
1.30 raeburn 1251: $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 1252: }
1253: }
1254: if ($links_def) {
1.8 raeburn 1255: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$links_def.'</tr></table></td>';
1.6 raeburn 1256: } else {
1257: $datatable .= '<td> </td>';
1258: }
1259: $datatable .= '<td class="LC_right_item">'.
1260: '<table border="0"><tr>';
1261: foreach my $item (@{$links}) {
1.30 raeburn 1262: $datatable .= '<td align="center">'."\n".
1263: &color_pick($phase,$role,$item,$choices->{$item},
1264: $designs->{'links'}{$item});
1.6 raeburn 1265: if ($designs->{'links'}{$item}) {
1.30 raeburn 1266: $datatable.=' <span id="css_'.$role.'_'.$item.'" style="background-color: '.$designs->{'links'}{$item}.';"> </span>';
1.6 raeburn 1267: }
1268: $datatable .= '<br /><input type="text" size="8" name="'.$role.'_'.$item.'" value="'.$designs->{'links'}{$item}.
1269: '" /></td>';
1270: }
1.30 raeburn 1271: $$rowtotal += $itemcount;
1.3 raeburn 1272: return $datatable;
1273: }
1274:
1.70 raeburn 1275: sub logo_display_options {
1276: my ($img,$defaults,$designs) = @_;
1277: my $checkedon;
1278: if (ref($defaults) eq 'HASH') {
1279: if (ref($defaults->{'showlogo'}) eq 'HASH') {
1280: if ($defaults->{'showlogo'}{$img}) {
1281: $checkedon = 'checked="checked" ';
1282: }
1283: }
1284: }
1285: if (ref($designs) eq 'HASH') {
1286: if (ref($designs->{'showlogo'}) eq 'HASH') {
1287: if (defined($designs->{'showlogo'}{$img})) {
1288: if ($designs->{'showlogo'}{$img} == 0) {
1289: $checkedon = '';
1290: } elsif ($designs->{'showlogo'}{$img} == 1) {
1291: $checkedon = 'checked="checked" ';
1292: }
1293: }
1294: }
1295: }
1296: return '<br /><label> <input type="checkbox" name="'.
1297: 'login_showlogo_'.$img.'" value="1" '.$checkedon.'/>'.
1298: &mt('show').'</label>'."\n";
1299: }
1300:
1.41 raeburn 1301: sub login_header_options {
1.135 bisitz 1302: my ($img,$role,$defaults,$is_custom,$choices) = @_;
1303: my $output = '';
1.41 raeburn 1304: if ((!$is_custom->{'textcol'}) || (!$is_custom->{'bgcol'})) {
1.135 bisitz 1305: $output .= &mt('Text default(s):').'<br />';
1.41 raeburn 1306: if (!$is_custom->{'textcol'}) {
1307: $output .= $choices->{'textcol'}.': '.$defaults->{'logintext'}{'textcol'}.
1308: ' ';
1309: }
1310: if (!$is_custom->{'bgcol'}) {
1311: $output .= $choices->{'bgcol'}.': '.
1312: '<span id="css_'.$role.'_font" style="background-color: '.
1313: $defaults->{'logintext'}{'bgcol'}.';"> </span>';
1314: }
1315: $output .= '<br />';
1316: }
1317: $output .='<br />';
1318: return $output;
1319: }
1320:
1321: sub login_text_colors {
1322: my ($img,$role,$logintext,$phase,$choices,$designs) = @_;
1323: my $color_menu = '<table border="0"><tr>';
1324: foreach my $item (@{$logintext}) {
1325: my $link = &color_pick($phase,$role,$item,$choices->{$item},$designs->{'logintext'}{$item});
1326: $color_menu .= '<td align="center">'.$link;
1327: if ($designs->{'logintext'}{$item}) {
1328: $color_menu .= ' <span id="css_'.$role.'_'.$item.'" style="background-color: '.$designs->{'logintext'}{$item}.';"> </span>';
1329: }
1330: $color_menu .= '<br /><input type="text" size="8" name="'.$role.'_'.$item.'" value="'.
1331: $designs->{'logintext'}{$item}.'" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>'.
1332: '<td> </td>';
1333: }
1334: $color_menu .= '</tr></table><br />';
1335: return $color_menu;
1336: }
1337:
1338: sub image_changes {
1339: my ($is_custom,$alt_text,$img_import,$showfile,$fullsize,$role,$img,$imgfile,$logincolors) = @_;
1340: my $output;
1.135 bisitz 1341: if ($img eq 'login') {
1342: # suppress image for Log-in header
1343: } elsif (!$is_custom) {
1.70 raeburn 1344: if ($img ne 'domlogo') {
1.41 raeburn 1345: $output .= &mt('Default image:').'<br />';
1346: } else {
1347: $output .= &mt('Default in use:').'<br />';
1348: }
1349: }
1.135 bisitz 1350: if ($img eq 'login') { # suppress image for Log-in header
1351: $output .= '<td>'.$logincolors;
1.41 raeburn 1352: } else {
1.135 bisitz 1353: if ($img_import) {
1354: $output .= '<input type="hidden" name="'.$role.'_import_'.$img.'" value="'.$imgfile.'" />';
1355: }
1356: $output .= '<a href="'.$fullsize.'" target="_blank"><img src="'.
1357: $showfile.'" alt="'.$alt_text.'" border="0" /></a></td>';
1358: if ($is_custom) {
1359: $output .= '<td>'.$logincolors.'<span class="LC_nobreak"><label>'.
1360: '<input type="checkbox" name="'.
1361: $role.'_del_'.$img.'" value="1" />'.&mt('Delete?').
1362: '</label> '.&mt('Replace:').'</span><br />';
1363: } else {
1364: $output .= '<td valign="bottom">'.$logincolors.&mt('Upload:').'<br />';
1365: }
1.41 raeburn 1366: }
1367: return $output;
1368: }
1369:
1.6 raeburn 1370: sub color_pick {
1371: my ($phase,$role,$item,$desc,$curcol) = @_;
1372: my $link = '<a href="javascript:pjump('."'color_custom','".$desc.
1373: "','".$curcol."','".$role.'_'.$item."','parmform.pres','psub'".
1374: ');">'.$desc.'</a>';
1375: return $link;
1376: }
1377:
1.3 raeburn 1378: sub print_quotas {
1.86 raeburn 1379: my ($dom,$settings,$rowtotal,$action) = @_;
1380: my $context;
1381: if ($action eq 'quotas') {
1382: $context = 'tools';
1383: } else {
1384: $context = $action;
1385: }
1.101 raeburn 1386: my ($datatable,$defaultquota,@usertools,@options,%validations);
1.44 raeburn 1387: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.3 raeburn 1388: my $typecount = 0;
1.101 raeburn 1389: my ($css_class,%titles);
1.86 raeburn 1390: if ($context eq 'requestcourses') {
1.98 raeburn 1391: @usertools = ('official','unofficial','community');
1.106 raeburn 1392: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 1393: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
1394: %titles = &courserequest_titles();
1.163 raeburn 1395: } elsif ($context eq 'requestauthor') {
1396: @usertools = ('author');
1397: @options = ('norequest','approval','automatic');
1398: %titles = &authorrequest_titles();
1.86 raeburn 1399: } else {
1.162 raeburn 1400: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 1401: %titles = &tool_titles();
1.86 raeburn 1402: }
1.26 raeburn 1403: if (ref($types) eq 'ARRAY') {
1.23 raeburn 1404: foreach my $type (@{$types}) {
1.72 raeburn 1405: my $currdefquota;
1.163 raeburn 1406: unless (($context eq 'requestcourses') ||
1407: ($context eq 'requestauthor')) {
1.86 raeburn 1408: if (ref($settings) eq 'HASH') {
1409: if (ref($settings->{defaultquota}) eq 'HASH') {
1410: $currdefquota = $settings->{defaultquota}->{$type};
1411: } else {
1412: $currdefquota = $settings->{$type};
1413: }
1.78 raeburn 1414: }
1.72 raeburn 1415: }
1.3 raeburn 1416: if (defined($usertypes->{$type})) {
1417: $typecount ++;
1418: $css_class = $typecount%2?' class="LC_odd_row"':'';
1.72 raeburn 1419: $datatable .= '<tr'.$css_class.'>'.
1.3 raeburn 1420: '<td>'.$usertypes->{$type}.'</td>'.
1.72 raeburn 1421: '<td class="LC_left_item">';
1.101 raeburn 1422: if ($context eq 'requestcourses') {
1423: $datatable .= '<table><tr>';
1424: }
1425: my %cell;
1.72 raeburn 1426: foreach my $item (@usertools) {
1.101 raeburn 1427: if ($context eq 'requestcourses') {
1428: my ($curroption,$currlimit);
1429: if (ref($settings) eq 'HASH') {
1430: if (ref($settings->{$item}) eq 'HASH') {
1431: $curroption = $settings->{$item}->{$type};
1432: if ($curroption =~ /^autolimit=(\d*)$/) {
1433: $currlimit = $1;
1434: }
1435: }
1436: }
1437: if (!$curroption) {
1438: $curroption = 'norequest';
1439: }
1440: $datatable .= '<th>'.$titles{$item}.'</th>';
1441: foreach my $option (@options) {
1442: my $val = $option;
1443: if ($option eq 'norequest') {
1444: $val = 0;
1445: }
1446: if ($option eq 'validate') {
1447: my $canvalidate = 0;
1448: if (ref($validations{$item}) eq 'HASH') {
1449: if ($validations{$item}{$type}) {
1450: $canvalidate = 1;
1451: }
1452: }
1453: next if (!$canvalidate);
1454: }
1455: my $checked = '';
1456: if ($option eq $curroption) {
1457: $checked = ' checked="checked"';
1458: } elsif ($option eq 'autolimit') {
1459: if ($curroption =~ /^autolimit/) {
1460: $checked = ' checked="checked"';
1461: }
1462: }
1463: $cell{$item} .= '<span class="LC_nobreak"><label>'.
1464: '<input type="radio" name="crsreq_'.$item.
1465: '_'.$type.'" value="'.$val.'"'.$checked.' />'.
1.127 raeburn 1466: $titles{$option}.'</label>';
1.101 raeburn 1467: if ($option eq 'autolimit') {
1.127 raeburn 1468: $cell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 1469: $item.'_limit_'.$type.'" size="1" '.
1.103 raeburn 1470: 'value="'.$currlimit.'" />';
1.101 raeburn 1471: }
1.127 raeburn 1472: $cell{$item} .= '</span> ';
1.103 raeburn 1473: if ($option eq 'autolimit') {
1.127 raeburn 1474: $cell{$item} .= $titles{'unlimited'};
1.103 raeburn 1475: }
1.101 raeburn 1476: }
1.163 raeburn 1477: } elsif ($context eq 'requestauthor') {
1478: my $curroption;
1479: if (ref($settings) eq 'HASH') {
1480: $curroption = $settings->{$type};
1481: }
1482: if (!$curroption) {
1483: $curroption = 'norequest';
1484: }
1485: foreach my $option (@options) {
1486: my $val = $option;
1487: if ($option eq 'norequest') {
1488: $val = 0;
1489: }
1490: my $checked = '';
1491: if ($option eq $curroption) {
1492: $checked = ' checked="checked"';
1493: }
1494: $datatable .= '<span class="LC_nobreak"><label>'.
1495: '<input type="radio" name="authorreq_'.$type.
1496: '" value="'.$val.'"'.$checked.' />'.
1497: $titles{$option}.'</label></span> ';
1498: }
1.101 raeburn 1499: } else {
1500: my $checked = 'checked="checked" ';
1501: if (ref($settings) eq 'HASH') {
1502: if (ref($settings->{$item}) eq 'HASH') {
1503: if ($settings->{$item}->{$type} == 0) {
1504: $checked = '';
1505: } elsif ($settings->{$item}->{$type} == 1) {
1506: $checked = 'checked="checked" ';
1507: }
1.78 raeburn 1508: }
1.72 raeburn 1509: }
1.101 raeburn 1510: $datatable .= '<span class="LC_nobreak"><label>'.
1511: '<input type="checkbox" name="'.$context.'_'.$item.
1512: '" value="'.$type.'" '.$checked.'/>'.$titles{$item}.
1513: '</label></span> ';
1.72 raeburn 1514: }
1.101 raeburn 1515: }
1516: if ($context eq 'requestcourses') {
1517: $datatable .= '</tr><tr>';
1518: foreach my $item (@usertools) {
1.106 raeburn 1519: $datatable .= '<td style="vertical-align: top">'.$cell{$item}.'</td>';
1.101 raeburn 1520: }
1521: $datatable .= '</tr></table>';
1.72 raeburn 1522: }
1.86 raeburn 1523: $datatable .= '</td>';
1.163 raeburn 1524: unless (($context eq 'requestcourses') ||
1525: ($context eq 'requestauthor')) {
1.86 raeburn 1526: $datatable .=
1527: '<td class="LC_right_item"><span class="LC_nobreak">'.
1.3 raeburn 1528: '<input type="text" name="quota_'.$type.
1.72 raeburn 1529: '" value="'.$currdefquota.
1.86 raeburn 1530: '" size="5" /> Mb</span></td>';
1531: }
1532: $datatable .= '</tr>';
1.3 raeburn 1533: }
1534: }
1535: }
1.163 raeburn 1536: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 1537: $defaultquota = '20';
1538: if (ref($settings) eq 'HASH') {
1539: if (ref($settings->{'defaultquota'}) eq 'HASH') {
1540: $defaultquota = $settings->{'defaultquota'}->{'default'};
1541: } elsif (defined($settings->{'default'})) {
1542: $defaultquota = $settings->{'default'};
1543: }
1.3 raeburn 1544: }
1545: }
1546: $typecount ++;
1547: $css_class = $typecount%2?' class="LC_odd_row"':'';
1548: $datatable .= '<tr'.$css_class.'>'.
1.26 raeburn 1549: '<td>'.$othertitle.'</td>'.
1.72 raeburn 1550: '<td class="LC_left_item">';
1.101 raeburn 1551: if ($context eq 'requestcourses') {
1552: $datatable .= '<table><tr>';
1553: }
1554: my %defcell;
1.72 raeburn 1555: foreach my $item (@usertools) {
1.101 raeburn 1556: if ($context eq 'requestcourses') {
1557: my ($curroption,$currlimit);
1558: if (ref($settings) eq 'HASH') {
1559: if (ref($settings->{$item}) eq 'HASH') {
1560: $curroption = $settings->{$item}->{'default'};
1561: if ($curroption =~ /^autolimit=(\d*)$/) {
1562: $currlimit = $1;
1563: }
1564: }
1565: }
1566: if (!$curroption) {
1567: $curroption = 'norequest';
1568: }
1569: $datatable .= '<th>'.$titles{$item}.'</th>';
1570: foreach my $option (@options) {
1571: my $val = $option;
1572: if ($option eq 'norequest') {
1573: $val = 0;
1574: }
1575: if ($option eq 'validate') {
1576: my $canvalidate = 0;
1577: if (ref($validations{$item}) eq 'HASH') {
1578: if ($validations{$item}{'default'}) {
1579: $canvalidate = 1;
1580: }
1581: }
1582: next if (!$canvalidate);
1583: }
1584: my $checked = '';
1585: if ($option eq $curroption) {
1586: $checked = ' checked="checked"';
1587: } elsif ($option eq 'autolimit') {
1588: if ($curroption =~ /^autolimit/) {
1589: $checked = ' checked="checked"';
1590: }
1591: }
1592: $defcell{$item} .= '<span class="LC_nobreak"><label>'.
1593: '<input type="radio" name="crsreq_'.$item.
1594: '_default" value="'.$val.'"'.$checked.' />'.
1595: $titles{$option}.'</label>';
1596: if ($option eq 'autolimit') {
1.127 raeburn 1597: $defcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 1598: $item.'_limit_default" size="1" '.
1599: 'value="'.$currlimit.'" />';
1600: }
1.127 raeburn 1601: $defcell{$item} .= '</span> ';
1.104 raeburn 1602: if ($option eq 'autolimit') {
1.127 raeburn 1603: $defcell{$item} .= $titles{'unlimited'};
1.104 raeburn 1604: }
1.101 raeburn 1605: }
1.163 raeburn 1606: } elsif ($context eq 'requestauthor') {
1607: my $curroption;
1608: if (ref($settings) eq 'HASH') {
1609: if (ref($settings->{'requestauthor'}) eq 'HASH') {
1610: $curroption = $settings->{'requestauthor'};
1611: }
1612: }
1613: if (!$curroption) {
1614: $curroption = 'norequest';
1615: }
1616: foreach my $option (@options) {
1617: my $val = $option;
1618: if ($option eq 'norequest') {
1619: $val = 0;
1620: }
1621: my $checked = '';
1622: if ($option eq $curroption) {
1623: $checked = ' checked="checked"';
1624: }
1625: $datatable .= '<span class="LC_nobreak"><label>'.
1626: '<input type="radio" name="authorreq_default"'.
1627: ' value="'.$val.'"'.$checked.' />'.
1628: $titles{$option}.'</label></span> ';
1629: }
1.101 raeburn 1630: } else {
1631: my $checked = 'checked="checked" ';
1632: if (ref($settings) eq 'HASH') {
1633: if (ref($settings->{$item}) eq 'HASH') {
1634: if ($settings->{$item}->{'default'} == 0) {
1635: $checked = '';
1636: } elsif ($settings->{$item}->{'default'} == 1) {
1637: $checked = 'checked="checked" ';
1638: }
1.78 raeburn 1639: }
1.72 raeburn 1640: }
1.101 raeburn 1641: $datatable .= '<span class="LC_nobreak"><label>'.
1642: '<input type="checkbox" name="'.$context.'_'.$item.
1643: '" value="default" '.$checked.'/>'.$titles{$item}.
1644: '</label></span> ';
1645: }
1646: }
1647: if ($context eq 'requestcourses') {
1648: $datatable .= '</tr><tr>';
1649: foreach my $item (@usertools) {
1.106 raeburn 1650: $datatable .= '<td style="vertical-align: top">'.$defcell{$item}.'</td>';
1.72 raeburn 1651: }
1.101 raeburn 1652: $datatable .= '</tr></table>';
1.72 raeburn 1653: }
1.86 raeburn 1654: $datatable .= '</td>';
1.163 raeburn 1655: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 1656: $datatable .= '<td class="LC_right_item"><span class="LC_nobreak">'.
1657: '<input type="text" name="defaultquota" value="'.
1658: $defaultquota.'" size="5" /> Mb</span></td>';
1659: }
1660: $datatable .= '</tr>';
1.72 raeburn 1661: $typecount ++;
1662: $css_class = $typecount%2?' class="LC_odd_row"':'';
1663: $datatable .= '<tr'.$css_class.'>'.
1.104 raeburn 1664: '<td>'.&mt('LON-CAPA Advanced Users').' ';
1665: if ($context eq 'requestcourses') {
1.109 raeburn 1666: $datatable .= &mt('(overrides affiliation, if set)').
1667: '</td>'.
1668: '<td class="LC_left_item">'.
1669: '<table><tr>';
1.101 raeburn 1670: } else {
1.109 raeburn 1671: $datatable .= &mt('(overrides affiliation, if checked)').
1672: '</td>'.
1673: '<td class="LC_left_item" colspan="2">'.
1674: '<br />';
1.101 raeburn 1675: }
1676: my %advcell;
1.72 raeburn 1677: foreach my $item (@usertools) {
1.101 raeburn 1678: if ($context eq 'requestcourses') {
1679: my ($curroption,$currlimit);
1680: if (ref($settings) eq 'HASH') {
1681: if (ref($settings->{$item}) eq 'HASH') {
1682: $curroption = $settings->{$item}->{'_LC_adv'};
1683: if ($curroption =~ /^autolimit=(\d*)$/) {
1684: $currlimit = $1;
1685: }
1686: }
1687: }
1688: $datatable .= '<th>'.$titles{$item}.'</th>';
1.104 raeburn 1689: my $checked = '';
1690: if ($curroption eq '') {
1691: $checked = ' checked="checked"';
1692: }
1693: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
1694: '<input type="radio" name="crsreq_'.$item.
1695: '__LC_adv" value=""'.$checked.' />'.
1696: &mt('No override set').'</label></span> ';
1.101 raeburn 1697: foreach my $option (@options) {
1698: my $val = $option;
1699: if ($option eq 'norequest') {
1700: $val = 0;
1701: }
1702: if ($option eq 'validate') {
1703: my $canvalidate = 0;
1704: if (ref($validations{$item}) eq 'HASH') {
1705: if ($validations{$item}{'_LC_adv'}) {
1706: $canvalidate = 1;
1707: }
1708: }
1709: next if (!$canvalidate);
1710: }
1711: my $checked = '';
1.104 raeburn 1712: if ($val eq $curroption) {
1.101 raeburn 1713: $checked = ' checked="checked"';
1714: } elsif ($option eq 'autolimit') {
1715: if ($curroption =~ /^autolimit/) {
1716: $checked = ' checked="checked"';
1717: }
1718: }
1719: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
1720: '<input type="radio" name="crsreq_'.$item.
1721: '__LC_adv" value="'.$val.'"'.$checked.' />'.
1722: $titles{$option}.'</label>';
1723: if ($option eq 'autolimit') {
1.127 raeburn 1724: $advcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 1725: $item.'_limit__LC_adv" size="1" '.
1726: 'value="'.$currlimit.'" />';
1727: }
1.127 raeburn 1728: $advcell{$item} .= '</span> ';
1.104 raeburn 1729: if ($option eq 'autolimit') {
1.127 raeburn 1730: $advcell{$item} .= $titles{'unlimited'};
1.104 raeburn 1731: }
1.101 raeburn 1732: }
1.163 raeburn 1733: } elsif ($context eq 'requestauthor') {
1734: my $curroption;
1735: if (ref($settings) eq 'HASH') {
1736: $curroption = $settings->{'_LC_adv'};
1737: }
1738: my $checked = '';
1739: if ($curroption eq '') {
1740: $checked = ' checked="checked"';
1741: }
1742: $datatable .= '<span class="LC_nobreak"><label>'.
1743: '<input type="radio" name="authorreq__LC_adv"'.
1744: ' value=""'.$checked.' />'.
1745: &mt('No override set').'</label></span> ';
1746: foreach my $option (@options) {
1747: my $val = $option;
1748: if ($option eq 'norequest') {
1749: $val = 0;
1750: }
1751: my $checked = '';
1752: if ($val eq $curroption) {
1753: $checked = ' checked="checked"';
1754: }
1755: $datatable .= '<span class="LC_nobreak"><label>'.
1756: '<input type="radio" name="crsreq_'.$item.
1757: '__LC_adv" value="'.$val.'"'.$checked.' />'.
1758: $titles{$option}.'</label></span> ';
1759: }
1.101 raeburn 1760: } else {
1761: my $checked = 'checked="checked" ';
1762: if (ref($settings) eq 'HASH') {
1763: if (ref($settings->{$item}) eq 'HASH') {
1764: if ($settings->{$item}->{'_LC_adv'} == 0) {
1765: $checked = '';
1766: } elsif ($settings->{$item}->{'_LC_adv'} == 1) {
1767: $checked = 'checked="checked" ';
1768: }
1.79 raeburn 1769: }
1.72 raeburn 1770: }
1.101 raeburn 1771: $datatable .= '<span class="LC_nobreak"><label>'.
1772: '<input type="checkbox" name="'.$context.'_'.$item.
1773: '" value="_LC_adv" '.$checked.'/>'.$titles{$item}.
1774: '</label></span> ';
1775: }
1776: }
1777: if ($context eq 'requestcourses') {
1778: $datatable .= '</tr><tr>';
1779: foreach my $item (@usertools) {
1.106 raeburn 1780: $datatable .= '<td style="vertical-align: top">'.$advcell{$item}.'</td>';
1.72 raeburn 1781: }
1.101 raeburn 1782: $datatable .= '</tr></table>';
1.72 raeburn 1783: }
1.98 raeburn 1784: $datatable .= '</td></tr>';
1.30 raeburn 1785: $$rowtotal += $typecount;
1.3 raeburn 1786: return $datatable;
1787: }
1788:
1.163 raeburn 1789: sub print_requestmail {
1790: my ($dom,$action,$settings,$rowtotal) = @_;
1.104 raeburn 1791: my ($now,$datatable,%dompersonnel,@domcoord,@currapproval,$rows);
1.102 raeburn 1792: $now = time;
1793: $rows = 0;
1794: %dompersonnel = &Apache::lonnet::get_domain_roles($dom,['dc'],$now,$now);
1795: foreach my $server (keys(%dompersonnel)) {
1796: foreach my $user (sort(keys(%{$dompersonnel{$server}}))) {
1797: my ($trole,$uname,$udom,$runame,$rudom,$rsec) = split(/:/,$user);
1798: if (!grep(/^$uname:$udom$/,@domcoord)) {
1799: push(@domcoord,$uname.':'.$udom);
1800: }
1801: }
1802: }
1803: if (ref($settings) eq 'HASH') {
1804: if (ref($settings->{'notify'}) eq 'HASH') {
1805: if ($settings->{'notify'}{'approval'} ne '') {
1.104 raeburn 1806: @currapproval = split(',',$settings->{'notify'}{'approval'});
1.102 raeburn 1807: }
1808: }
1809: }
1.104 raeburn 1810: if (@currapproval) {
1811: foreach my $dc (@currapproval) {
1.102 raeburn 1812: unless (grep(/^\Q$dc\E$/,@domcoord)) {
1813: push(@domcoord,$dc);
1814: }
1815: }
1816: }
1817: @domcoord = sort(@domcoord);
1818: my $numinrow = 4;
1819: my $numdc = @domcoord;
1820: my $css_class = 'class="LC_odd_row"';
1.163 raeburn 1821: my $text;
1822: if ($action eq 'requestcourses') {
1823: $text = &mt('Receive notification of course requests requiring approval');
1824: } else {
1825: $text = &mt('Receive notification of authoring space requests requiring approval')
1826: }
1827: $datatable = '<tr '.$css_class.'>'.
1828: ' <td>'.$text.'</td>'.
1.102 raeburn 1829: ' <td class="LC_left_item">';
1830: if (@domcoord > 0) {
1831: $datatable .= '<table>';
1832: for (my $i=0; $i<$numdc; $i++) {
1833: my $rem = $i%($numinrow);
1834: if ($rem == 0) {
1835: if ($i > 0) {
1836: $datatable .= '</tr>';
1837: }
1838: $datatable .= '<tr>';
1839: $rows ++;
1840: }
1841: my $check = ' ';
1.104 raeburn 1842: if (grep(/^\Q$domcoord[$i]\E$/,@currapproval)) {
1.102 raeburn 1843: $check = ' checked="checked" ';
1844: }
1845: my ($uname,$udom) = split(':',$domcoord[$i]);
1846: my $fullname = &Apache::loncommon::plainname($uname,$udom);
1847: if ($i == $numdc-1) {
1848: my $colsleft = $numinrow-$rem;
1849: if ($colsleft > 1) {
1850: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
1851: } else {
1852: $datatable .= '<td class="LC_left_item">';
1853: }
1854: } else {
1855: $datatable .= '<td class="LC_left_item">';
1856: }
1857: $datatable .= '<span class="LC_nobreak"><label>'.
1858: '<input type="checkbox" name="reqapprovalnotify" '.
1859: 'value="'.$domcoord[$i].'"'.$check.'/>'.
1860: $fullname.'</label></span></td>';
1861: }
1862: $datatable .= '</tr></table>';
1863: } else {
1864: $datatable .= &mt('There are no active Domain Coordinators');
1865: $rows ++;
1866: }
1867: $datatable .='</td></tr>';
1868: $$rowtotal += $rows;
1869: return $datatable;
1870: }
1871:
1.3 raeburn 1872: sub print_autoenroll {
1.30 raeburn 1873: my ($dom,$settings,$rowtotal) = @_;
1.3 raeburn 1874: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
1.129 raeburn 1875: my ($defdom,$runon,$runoff,$coownerson,$coownersoff);
1.3 raeburn 1876: if (ref($settings) eq 'HASH') {
1877: if (exists($settings->{'run'})) {
1878: if ($settings->{'run'} eq '0') {
1879: $runoff = ' checked="checked" ';
1880: $runon = ' ';
1881: } else {
1882: $runon = ' checked="checked" ';
1883: $runoff = ' ';
1884: }
1885: } else {
1886: if ($autorun) {
1887: $runon = ' checked="checked" ';
1888: $runoff = ' ';
1889: } else {
1890: $runoff = ' checked="checked" ';
1891: $runon = ' ';
1892: }
1893: }
1.129 raeburn 1894: if (exists($settings->{'co-owners'})) {
1895: if ($settings->{'co-owners'} eq '0') {
1896: $coownersoff = ' checked="checked" ';
1897: $coownerson = ' ';
1898: } else {
1899: $coownerson = ' checked="checked" ';
1900: $coownersoff = ' ';
1901: }
1902: } else {
1903: $coownersoff = ' checked="checked" ';
1904: $coownerson = ' ';
1905: }
1.3 raeburn 1906: if (exists($settings->{'sender_domain'})) {
1907: $defdom = $settings->{'sender_domain'};
1908: }
1.14 raeburn 1909: } else {
1910: if ($autorun) {
1911: $runon = ' checked="checked" ';
1912: $runoff = ' ';
1913: } else {
1914: $runoff = ' checked="checked" ';
1915: $runon = ' ';
1916: }
1.3 raeburn 1917: }
1918: my $domform = &Apache::loncommon::select_dom_form($defdom,'sender_domain',1);
1.39 raeburn 1919: my $notif_sender;
1920: if (ref($settings) eq 'HASH') {
1921: $notif_sender = $settings->{'sender_uname'};
1922: }
1.3 raeburn 1923: my $datatable='<tr class="LC_odd_row">'.
1924: '<td>'.&mt('Auto-enrollment active?').'</td>'.
1.8 raeburn 1925: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 1926: '<input type="radio" name="autoenroll_run"'.
1.8 raeburn 1927: $runon.' value="1" />'.&mt('Yes').'</label> '.
1928: '<label><input type="radio" name="autoenroll_run"'.
1.14 raeburn 1929: $runoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 1930: '</tr><tr>'.
1931: '<td>'.&mt('Notification messages - sender').
1.8 raeburn 1932: '</td><td class="LC_right_item"><span class="LC_nobreak">'.
1.3 raeburn 1933: &mt('username').': '.
1934: '<input type="text" name="sender_uname" value="'.
1.39 raeburn 1935: $notif_sender.'" size="10" /> '.&mt('domain').
1.129 raeburn 1936: ': '.$domform.'</span></td></tr>'.
1937: '<tr class="LC_odd_row">'.
1938: '<td>'.&mt('Automatically assign co-ownership').'</td>'.
1939: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1940: '<input type="radio" name="autoassign_coowners"'.
1941: $coownerson.' value="1" />'.&mt('Yes').'</label> '.
1942: '<label><input type="radio" name="autoassign_coowners"'.
1943: $coownersoff.' value="0" />'.&mt('No').'</label></span></td>'.
1944: '</tr>';
1945: $$rowtotal += 3;
1.3 raeburn 1946: return $datatable;
1947: }
1948:
1949: sub print_autoupdate {
1.30 raeburn 1950: my ($position,$dom,$settings,$rowtotal) = @_;
1.3 raeburn 1951: my $datatable;
1952: if ($position eq 'top') {
1953: my $updateon = ' ';
1954: my $updateoff = ' checked="checked" ';
1955: my $classlistson = ' ';
1956: my $classlistsoff = ' checked="checked" ';
1957: if (ref($settings) eq 'HASH') {
1958: if ($settings->{'run'} eq '1') {
1959: $updateon = $updateoff;
1960: $updateoff = ' ';
1961: }
1962: if ($settings->{'classlists'} eq '1') {
1963: $classlistson = $classlistsoff;
1964: $classlistsoff = ' ';
1965: }
1966: }
1967: my %title = (
1968: run => 'Auto-update active?',
1969: classlists => 'Update information in classlists?',
1970: );
1971: $datatable = '<tr class="LC_odd_row">'.
1972: '<td>'.&mt($title{'run'}).'</td>'.
1.8 raeburn 1973: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 1974: '<input type="radio" name="autoupdate_run"'.
1.8 raeburn 1975: $updateon.' value="1" />'.&mt('Yes').'</label> '.
1976: '<label><input type="radio" name="autoupdate_run"'.
1977: $updateoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 1978: '</tr><tr>'.
1979: '<td>'.&mt($title{'classlists'}).'</td>'.
1.8 raeburn 1980: '<td class="LC_right_item"><span class="LC_nobreak">'.
1981: '<label><input type="radio" name="classlists"'.
1982: $classlistson.' value="1" />'.&mt('Yes').'</label> '.
1983: '<label><input type="radio" name="classlists"'.
1984: $classlistsoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 1985: '</tr>';
1.30 raeburn 1986: $$rowtotal += 2;
1.131 raeburn 1987: } elsif ($position eq 'middle') {
1988: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1989: my $numinrow = 3;
1990: my $locknamesettings;
1991: $datatable .= &insttypes_row($settings,$types,$usertypes,
1992: $dom,$numinrow,$othertitle,
1993: 'lockablenames');
1994: $$rowtotal ++;
1.3 raeburn 1995: } else {
1.44 raeburn 1996: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.132 raeburn 1997: my @fields = ('lastname','firstname','middlename','generation',
1.20 raeburn 1998: 'permanentemail','id');
1.33 raeburn 1999: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1.3 raeburn 2000: my $numrows = 0;
1.26 raeburn 2001: if (ref($types) eq 'ARRAY') {
2002: if (@{$types} > 0) {
2003: $datatable =
2004: &usertype_update_row($settings,$usertypes,\%fieldtitles,
2005: \@fields,$types,\$numrows);
1.30 raeburn 2006: $$rowtotal += @{$types};
1.26 raeburn 2007: }
1.3 raeburn 2008: }
2009: $datatable .=
2010: &usertype_update_row($settings,{'default' => $othertitle},
2011: \%fieldtitles,\@fields,['default'],
2012: \$numrows);
1.30 raeburn 2013: $$rowtotal ++;
1.3 raeburn 2014: }
2015: return $datatable;
2016: }
2017:
1.125 raeburn 2018: sub print_autocreate {
2019: my ($dom,$settings,$rowtotal) = @_;
2020: my (%createon,%createoff);
2021: my $curr_dc;
2022: my @types = ('xml','req');
2023: if (ref($settings) eq 'HASH') {
2024: foreach my $item (@types) {
2025: $createoff{$item} = ' checked="checked" ';
2026: $createon{$item} = ' ';
2027: if (exists($settings->{$item})) {
2028: if ($settings->{$item}) {
2029: $createon{$item} = ' checked="checked" ';
2030: $createoff{$item} = ' ';
2031: }
2032: }
2033: }
2034: $curr_dc = $settings->{'xmldc'};
2035: } else {
2036: foreach my $item (@types) {
2037: $createoff{$item} = ' checked="checked" ';
2038: $createon{$item} = ' ';
2039: }
2040: }
2041: $$rowtotal += 2;
2042: my $datatable='<tr class="LC_odd_row">'.
2043: '<td>'.&mt('Create pending official courses from XML files').'</td>'.
2044: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2045: '<input type="radio" name="autocreate_xml"'.
2046: $createon{'xml'}.' value="1" />'.&mt('Yes').'</label> '.
2047: '<label><input type="radio" name="autocreate_xml"'.
1.143 raeburn 2048: $createoff{'xml'}.' value="0" />'.&mt('No').'</label></span>'.
2049: '</td></tr><tr>'.
2050: '<td>'.&mt('Create pending requests for official courses (if validated)').'</td>'.
2051: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2052: '<input type="radio" name="autocreate_req"'.
2053: $createon{'req'}.' value="1" />'.&mt('Yes').'</label> '.
2054: '<label><input type="radio" name="autocreate_req"'.
2055: $createoff{'req'}.' value="0" />'.&mt('No').'</label></span>';
1.125 raeburn 2056: my ($numdc,$dctable) = &active_dc_picker($dom,$curr_dc);
2057: if ($numdc > 1) {
1.143 raeburn 2058: $datatable .= '</td></tr><tr class="LC_odd_row"><td>'.
2059: &mt('Course creation processed as: (choose Dom. Coord.)').
2060: '</td><td class="LC_left_item">'.$dctable.'</td></tr>';
1.125 raeburn 2061: $$rowtotal ++ ;
2062: } else {
1.143 raeburn 2063: $datatable .= $dctable.'</td></tr>';
1.125 raeburn 2064: }
2065: return $datatable;
2066: }
2067:
1.23 raeburn 2068: sub print_directorysrch {
1.30 raeburn 2069: my ($dom,$settings,$rowtotal) = @_;
1.23 raeburn 2070: my $srchon = ' ';
2071: my $srchoff = ' checked="checked" ';
1.25 raeburn 2072: my ($exacton,$containson,$beginson);
1.24 raeburn 2073: my $localon = ' ';
2074: my $localoff = ' checked="checked" ';
1.23 raeburn 2075: if (ref($settings) eq 'HASH') {
2076: if ($settings->{'available'} eq '1') {
2077: $srchon = $srchoff;
2078: $srchoff = ' ';
2079: }
1.24 raeburn 2080: if ($settings->{'localonly'} eq '1') {
2081: $localon = $localoff;
2082: $localoff = ' ';
2083: }
1.25 raeburn 2084: if (ref($settings->{'searchtypes'}) eq 'ARRAY') {
2085: foreach my $type (@{$settings->{'searchtypes'}}) {
2086: if ($type eq 'exact') {
2087: $exacton = ' checked="checked" ';
2088: } elsif ($type eq 'contains') {
2089: $containson = ' checked="checked" ';
2090: } elsif ($type eq 'begins') {
2091: $beginson = ' checked="checked" ';
2092: }
2093: }
2094: } else {
2095: if ($settings->{'searchtypes'} eq 'exact') {
2096: $exacton = ' checked="checked" ';
2097: } elsif ($settings->{'searchtypes'} eq 'contains') {
2098: $containson = ' checked="checked" ';
2099: } elsif ($settings->{'searchtypes'} eq 'specify') {
2100: $exacton = ' checked="checked" ';
2101: $containson = ' checked="checked" ';
2102: }
1.23 raeburn 2103: }
2104: }
2105: my ($searchtitles,$titleorder) = &sorted_searchtitles();
1.45 raeburn 2106: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.23 raeburn 2107:
2108: my $numinrow = 4;
1.26 raeburn 2109: my $cansrchrow = 0;
1.23 raeburn 2110: my $datatable='<tr class="LC_odd_row">'.
1.30 raeburn 2111: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Directory search available?').'</span></td>'.
1.23 raeburn 2112: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2113: '<input type="radio" name="dirsrch_available"'.
2114: $srchon.' value="1" />'.&mt('Yes').'</label> '.
2115: '<label><input type="radio" name="dirsrch_available"'.
2116: $srchoff.' value="0" />'.&mt('No').'</label></span></td>'.
2117: '</tr><tr>'.
1.30 raeburn 2118: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search?').'</span></td>'.
1.24 raeburn 2119: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2120: '<input type="radio" name="dirsrch_localonly"'.
2121: $localoff.' value="0" />'.&mt('Yes').'</label> '.
2122: '<label><input type="radio" name="dirsrch_localonly"'.
2123: $localon.' value="1" />'.&mt('No').'</label></span></td>'.
1.25 raeburn 2124: '</tr>';
1.30 raeburn 2125: $$rowtotal += 2;
1.26 raeburn 2126: if (ref($usertypes) eq 'HASH') {
2127: if (keys(%{$usertypes}) > 0) {
1.93 raeburn 2128: $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
2129: $numinrow,$othertitle,'cansearch');
1.26 raeburn 2130: $cansrchrow = 1;
2131: }
2132: }
2133: if ($cansrchrow) {
1.30 raeburn 2134: $$rowtotal ++;
1.26 raeburn 2135: $datatable .= '<tr>';
2136: } else {
2137: $datatable .= '<tr class="LC_odd_row">';
2138: }
1.30 raeburn 2139: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Supported search methods').
2140: '</span></td><td class="LC_left_item" colspan="2"><table><tr>';
1.25 raeburn 2141: foreach my $title (@{$titleorder}) {
2142: if (defined($searchtitles->{$title})) {
2143: my $check = ' ';
1.93 raeburn 2144: if (ref($settings) eq 'HASH') {
1.39 raeburn 2145: if (ref($settings->{'searchby'}) eq 'ARRAY') {
2146: if (grep(/^\Q$title\E$/,@{$settings->{'searchby'}})) {
2147: $check = ' checked="checked" ';
2148: }
1.25 raeburn 2149: }
2150: }
2151: $datatable .= '<td class="LC_left_item">'.
2152: '<span class="LC_nobreak"><label>'.
2153: '<input type="checkbox" name="searchby" '.
2154: 'value="'.$title.'"'.$check.'/>'.
2155: $searchtitles->{$title}.'</label></span></td>';
2156: }
2157: }
1.26 raeburn 2158: $datatable .= '</tr></table></td></tr>';
1.30 raeburn 2159: $$rowtotal ++;
1.26 raeburn 2160: if ($cansrchrow) {
2161: $datatable .= '<tr class="LC_odd_row">';
2162: } else {
2163: $datatable .= '<tr>';
2164: }
1.30 raeburn 2165: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Search latitude').'</span></td>'.
1.26 raeburn 2166: '<td class="LC_left_item" colspan="2">'.
1.25 raeburn 2167: '<span class="LC_nobreak"><label>'.
2168: '<input type="checkbox" name="searchtypes" '.
2169: $exacton.' value="exact" />'.&mt('Exact match').
2170: '</label> '.
2171: '<label><input type="checkbox" name="searchtypes" '.
2172: $beginson.' value="begins" />'.&mt('Begins with').
2173: '</label> '.
2174: '<label><input type="checkbox" name="searchtypes" '.
2175: $containson.' value="contains" />'.&mt('Contains').
2176: '</label></span></td></tr>';
1.30 raeburn 2177: $$rowtotal ++;
1.25 raeburn 2178: return $datatable;
2179: }
2180:
1.28 raeburn 2181: sub print_contacts {
1.30 raeburn 2182: my ($dom,$settings,$rowtotal) = @_;
1.28 raeburn 2183: my $datatable;
2184: my @contacts = ('adminemail','supportemail');
1.134 raeburn 2185: my (%checked,%to,%otheremails,%bccemails);
1.102 raeburn 2186: my @mailings = ('errormail','packagesmail','lonstatusmail','helpdeskmail',
2187: 'requestsmail');
1.28 raeburn 2188: foreach my $type (@mailings) {
2189: $otheremails{$type} = '';
2190: }
1.134 raeburn 2191: $bccemails{'helpdeskmail'} = '';
1.28 raeburn 2192: if (ref($settings) eq 'HASH') {
2193: foreach my $item (@contacts) {
2194: if (exists($settings->{$item})) {
2195: $to{$item} = $settings->{$item};
2196: }
2197: }
2198: foreach my $type (@mailings) {
2199: if (exists($settings->{$type})) {
2200: if (ref($settings->{$type}) eq 'HASH') {
2201: foreach my $item (@contacts) {
2202: if ($settings->{$type}{$item}) {
2203: $checked{$type}{$item} = ' checked="checked" ';
2204: }
2205: }
2206: $otheremails{$type} = $settings->{$type}{'others'};
1.134 raeburn 2207: if ($type eq 'helpdeskmail') {
2208: $bccemails{$type} = $settings->{$type}{'bcc'};
2209: }
1.28 raeburn 2210: }
1.89 raeburn 2211: } elsif ($type eq 'lonstatusmail') {
2212: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
1.28 raeburn 2213: }
2214: }
2215: } else {
2216: $to{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
2217: $to{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
2218: $checked{'errormail'}{'adminemail'} = ' checked="checked" ';
2219: $checked{'packagesmail'}{'adminemail'} = ' checked="checked" ';
1.89 raeburn 2220: $checked{'helpdeskmail'}{'supportemail'} = ' checked="checked" ';
2221: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
1.102 raeburn 2222: $checked{'requestsmail'}{'adminemail'} = ' checked="checked" ';
1.28 raeburn 2223: }
2224: my ($titles,$short_titles) = &contact_titles();
2225: my $rownum = 0;
2226: my $css_class;
2227: foreach my $item (@contacts) {
1.69 raeburn 2228: $rownum ++;
2229: $css_class = $rownum%2?' class="LC_odd_row"':'';
1.30 raeburn 2230: $datatable .= '<tr'.$css_class.'>'.
2231: '<td><span class="LC_nobreak">'.$titles->{$item}.
2232: '</span></td><td class="LC_right_item">'.
1.28 raeburn 2233: '<input type="text" name="'.$item.'" value="'.
2234: $to{$item}.'" /></td></tr>';
2235: }
2236: foreach my $type (@mailings) {
1.69 raeburn 2237: $rownum ++;
2238: $css_class = $rownum%2?' class="LC_odd_row"':'';
1.28 raeburn 2239: $datatable .= '<tr'.$css_class.'>'.
1.30 raeburn 2240: '<td><span class="LC_nobreak">'.
2241: $titles->{$type}.': </span></td>'.
1.28 raeburn 2242: '<td class="LC_left_item">'.
2243: '<span class="LC_nobreak">';
2244: foreach my $item (@contacts) {
2245: $datatable .= '<label>'.
2246: '<input type="checkbox" name="'.$type.'"'.
2247: $checked{$type}{$item}.
2248: ' value="'.$item.'" />'.$short_titles->{$item}.
2249: '</label> ';
2250: }
2251: $datatable .= '</span><br />'.&mt('Others').': '.
2252: '<input type="text" name="'.$type.'_others" '.
1.134 raeburn 2253: 'value="'.$otheremails{$type}.'" />';
2254: if ($type eq 'helpdeskmail') {
1.136 raeburn 2255: $datatable .= '<br />'.&mt('Bcc:').(' 'x6).
1.134 raeburn 2256: '<input type="text" name="'.$type.'_bcc" '.
2257: 'value="'.$bccemails{$type}.'" />';
2258: }
2259: $datatable .= '</td></tr>'."\n";
1.28 raeburn 2260: }
1.30 raeburn 2261: $$rowtotal += $rownum;
1.28 raeburn 2262: return $datatable;
2263: }
2264:
1.118 jms 2265: sub print_helpsettings {
1.166 raeburn 2266: my ($position,$dom,$confname,$settings,$rowtotal) = @_;
2267: my ($css_class,$datatable,$itemcount);
2268: my $switchserver = &check_switchserver($dom,$confname);
2269: $itemcount = 1;
2270: if ($position eq 'top') {
2271: my (%checkedon,%checkedoff,%choices,%defaultchecked,@toggles,$align);
2272: $choices{'submitbugs'} = &mt('Display link to: [_1]?',
2273: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
2274: &mt('LON-CAPA bug tracker'),600,500));
2275: %defaultchecked = ('submitbugs' => 'on');
2276: @toggles = ('submitbugs',);
2277: $align = 'LC_left_item';
2278:
2279: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
2280: \%choices,$itemcount);
2281: } else {
2282: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
2283: $datatable .= '<tr'.$css_class.'>';
2284: my $url = '/adm/loginproblems.html';
2285: my $type = 'default';
2286: my %lt = &Apache::lonlocal::texthash (
2287: del => 'Delete?',
2288: rep => 'Replace:',
2289: upl => 'Upload:',
2290: default => 'Default',
2291: custom => 'Custom',
2292: );
2293: if (ref($settings) eq 'HASH') {
2294: if (ref($settings->{'loginhelpurl'}) eq 'HASH') {
1.122 jms 2295:
1.166 raeburn 2296: } elsif ($settings->{'loginhelpurl'} ne '') {
2297: $type = 'custom';
2298: $url = $settings->{'loginhelpurl'}.'?inhibitmenu=yes';
2299: }
2300: }
2301: $datatable .= '<td class="LC_left_item"><span class="LC_nobreak">'.
2302: &mt('Log-in help page currently in use: [_1]',
2303: &Apache::loncommon::modal_link($url,$lt{$type},600,500)).
2304: '</span></td>'."\n".
2305: '<td class="LC_left_item">';
2306: if ($type eq 'custom') {
2307: $datatable .= '<span class="LC_nobreak"><label>'.
2308: '<input type="checkbox" name="loginhelpurl_del" value="1" />'.$lt{'del'}.
2309: '</label> '.$lt{'rep'}.'</span>';
2310: } else {
2311: $datatable .= $lt{'upl'};
2312: }
2313: $datatable .='<br />';
2314: if ($switchserver) {
1.122 jms 2315: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2316: } else {
1.166 raeburn 2317: $datatable .= '<input type="file" name="loginhelpurl" />';
2318: }
2319: $datatable .= '</td></tr>';
2320: }
2321: return $datatable;
1.121 raeburn 2322: }
2323:
2324: sub radiobutton_prefs {
2325: my ($settings,$toggles,$defaultchecked,$choices,$itemcount) = @_;
2326: return unless ((ref($toggles) eq 'ARRAY') && (ref($defaultchecked) eq 'HASH') &&
2327: (ref($choices) eq 'HASH'));
2328:
1.166 raeburn 2329: my (%checkedon,%checkedoff,$datatable,$css_class,$cell_colspan);
1.121 raeburn 2330:
2331: foreach my $item (@{$toggles}) {
2332: if ($defaultchecked->{$item} eq 'on') {
1.118 jms 2333: $checkedon{$item} = ' checked="checked" ';
2334: $checkedoff{$item} = ' ';
1.121 raeburn 2335: } elsif ($defaultchecked->{$item} eq 'off') {
1.118 jms 2336: $checkedoff{$item} = ' checked="checked" ';
2337: $checkedon{$item} = ' ';
2338: }
2339: }
2340: if (ref($settings) eq 'HASH') {
1.121 raeburn 2341: foreach my $item (@{$toggles}) {
1.118 jms 2342: if ($settings->{$item} eq '1') {
2343: $checkedon{$item} = ' checked="checked" ';
2344: $checkedoff{$item} = ' ';
2345: } elsif ($settings->{$item} eq '0') {
2346: $checkedoff{$item} = ' checked="checked" ';
2347: $checkedon{$item} = ' ';
2348: }
2349: }
1.121 raeburn 2350: }
2351: foreach my $item (@{$toggles}) {
1.118 jms 2352: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.121 raeburn 2353: $datatable .=
2354: '<tr'.$css_class.'><td><span class="LC_nobreak">'.$choices->{$item}.
1.118 jms 2355: '</span></td>'.
2356: '<td class="LC_right_item"><span class="LC_nobreak">'.
2357: '<label><input type="radio" name="'.
2358: $item.'" '.$checkedon{$item}.' value="1" />'.&mt('Yes').
2359: '</label> <label><input type="radio" name="'.$item.'" '.
2360: $checkedoff{$item}.' value="0" />'.&mt('No').'</label>'.
2361: '</span></td>'.
2362: '</tr>';
2363: $itemcount ++;
1.121 raeburn 2364: }
2365: return ($datatable,$itemcount);
2366: }
2367:
2368: sub print_coursedefaults {
1.139 raeburn 2369: my ($position,$dom,$settings,$rowtotal) = @_;
1.121 raeburn 2370: my ($css_class,$datatable);
2371: my $itemcount = 1;
1.139 raeburn 2372: if ($position eq 'top') {
2373: my (%checkedon,%checkedoff,%choices,%defaultchecked,@toggles);
2374: %choices =
2375: &Apache::lonlocal::texthash (
2376: canuse_pdfforms => 'Course/Community users can create/upload PDF forms',
2377: );
2378: %defaultchecked = ('canuse_pdfforms' => 'off');
2379: @toggles = ('canuse_pdfforms',);
2380: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
1.121 raeburn 2381: \%choices,$itemcount);
1.139 raeburn 2382: $$rowtotal += $itemcount;
2383: } else {
2384: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
2385: my %choices =
2386: &Apache::lonlocal::texthash (
2387: anonsurvey_threshold => 'Responder count needed before showing submissions for anonymous surveys',
2388: );
2389: my $currdefresponder;
2390: if (ref($settings) eq 'HASH') {
2391: $currdefresponder = $settings->{'anonsurvey_threshold'};
2392: }
2393: if (!$currdefresponder) {
2394: $currdefresponder = 10;
2395: } elsif ($currdefresponder < 1) {
2396: $currdefresponder = 1;
2397: }
2398: $datatable .=
2399: '<tr'.$css_class.'><td><span class="LC_nobreak">'.$choices{'anonsurvey_threshold'}.
2400: '</span></td>'.
2401: '<td class="LC_right_item"><span class="LC_nobreak">'.
2402: '<input type="text" name="anonsurvey_threshold"'.
2403: ' value="'.$currdefresponder.'" size="5" /></span>'.
2404: '</td></tr>';
2405: }
1.121 raeburn 2406: return $datatable;
1.118 jms 2407: }
2408:
1.137 raeburn 2409: sub print_usersessions {
2410: my ($position,$dom,$settings,$rowtotal) = @_;
2411: my ($css_class,$datatable,%checked,%choices);
1.140 raeburn 2412: my (%by_ip,%by_location,@intdoms);
2413: &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
1.145 raeburn 2414:
2415: my @alldoms = &Apache::lonnet::all_domains();
1.152 raeburn 2416: my %serverhomes = %Apache::lonnet::serverhomeIDs;
1.149 raeburn 2417: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.152 raeburn 2418: my %altids = &id_for_thisdom(%servers);
1.145 raeburn 2419: my $itemcount = 1;
2420: if ($position eq 'top') {
1.152 raeburn 2421: if (keys(%serverhomes) > 1) {
1.145 raeburn 2422: my %spareid = ¤t_offloads_to($dom,$settings,\%servers);
1.152 raeburn 2423: $datatable .= &spares_row($dom,\%servers,\%spareid,\%serverhomes,\%altids,$rowtotal);
1.145 raeburn 2424: } else {
1.140 raeburn 2425: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.150 raeburn 2426: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one server.');
1.140 raeburn 2427: }
1.137 raeburn 2428: } else {
1.145 raeburn 2429: if (keys(%by_location) == 0) {
2430: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.150 raeburn 2431: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one institution.');
1.145 raeburn 2432: } else {
2433: my %lt = &usersession_titles();
2434: my $numinrow = 5;
2435: my $prefix;
2436: my @types;
2437: if ($position eq 'bottom') {
2438: $prefix = 'remote';
2439: @types = ('version','excludedomain','includedomain');
2440: } else {
2441: $prefix = 'hosted';
2442: @types = ('excludedomain','includedomain');
2443: }
2444: my (%current,%checkedon,%checkedoff);
2445: my @lcversions = &Apache::lonnet::all_loncaparevs();
2446: my @locations = sort(keys(%by_location));
2447: foreach my $type (@types) {
2448: $checkedon{$type} = '';
2449: $checkedoff{$type} = ' checked="checked"';
2450: }
2451: if (ref($settings) eq 'HASH') {
2452: if (ref($settings->{$prefix}) eq 'HASH') {
2453: foreach my $key (keys(%{$settings->{$prefix}})) {
2454: $current{$key} = $settings->{$prefix}{$key};
2455: if ($key eq 'version') {
2456: if ($current{$key} ne '') {
2457: $checkedon{$key} = ' checked="checked"';
2458: $checkedoff{$key} = '';
2459: }
2460: } elsif (ref($current{$key}) eq 'ARRAY') {
2461: $checkedon{$key} = ' checked="checked"';
2462: $checkedoff{$key} = '';
2463: }
1.137 raeburn 2464: }
2465: }
2466: }
1.145 raeburn 2467: foreach my $type (@types) {
2468: next if ($type ne 'version' && !@locations);
2469: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
2470: $datatable .= '<tr'.$css_class.'>
2471: <td><span class="LC_nobreak">'.$lt{$type}.'</span><br />
2472: <span class="LC_nobreak">
2473: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedoff{$type}.' value="0" />'.&mt('Not in use').'</label>
2474: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedon{$type}.' value="1" />'.&mt('In use').'</label></span></td><td>';
2475: if ($type eq 'version') {
2476: my $selector = '<select name="'.$prefix.'_version">';
2477: foreach my $version (@lcversions) {
2478: my $selected = '';
2479: if ($current{'version'} eq $version) {
2480: $selected = ' selected="selected"';
2481: }
2482: $selector .= ' <option value="'.$version.'"'.
2483: $selected.'>'.$version.'</option>';
2484: }
2485: $selector .= '</select> ';
2486: $datatable .= &mt('remote server must be version: [_1] or later',$selector);
2487: } else {
2488: $datatable.= '<div><input type="button" value="'.&mt('check all').'" '.
2489: 'onclick="javascript:checkAll(document.display.'.$prefix.'_'.$type.')"'.
2490: ' />'.(' 'x2).
2491: '<input type="button" value="'.&mt('uncheck all').'" '.
2492: 'onclick="javascript:uncheckAll(document.display.'.$prefix.'_'.$type.')" />'.
2493: "\n".
2494: '</div><div><table>';
2495: my $rem;
2496: for (my $i=0; $i<@locations; $i++) {
2497: my ($showloc,$value,$checkedtype);
2498: if (ref($by_location{$locations[$i]}) eq 'ARRAY') {
2499: my $ip = $by_location{$locations[$i]}->[0];
2500: if (ref($by_ip{$ip}) eq 'ARRAY') {
2501: $value = join(':',@{$by_ip{$ip}});
2502: $showloc = join(', ',@{$by_ip{$ip}});
2503: if (ref($current{$type}) eq 'ARRAY') {
2504: foreach my $loc (@{$by_ip{$ip}}) {
2505: if (grep(/^\Q$loc\E$/,@{$current{$type}})) {
2506: $checkedtype = ' checked="checked"';
2507: last;
2508: }
2509: }
1.138 raeburn 2510: }
2511: }
2512: }
1.145 raeburn 2513: $rem = $i%($numinrow);
2514: if ($rem == 0) {
2515: if ($i > 0) {
2516: $datatable .= '</tr>';
2517: }
2518: $datatable .= '<tr>';
2519: }
2520: $datatable .= '<td class="LC_left_item">'.
2521: '<span class="LC_nobreak"><label>'.
2522: '<input type="checkbox" name="'.$prefix.'_'.$type.
2523: '" value="'.$value.'"'.$checkedtype.' />'.$showloc.
2524: '</label></span></td>';
1.137 raeburn 2525: }
1.145 raeburn 2526: $rem = @locations%($numinrow);
2527: my $colsleft = $numinrow - $rem;
2528: if ($colsleft > 1 ) {
2529: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
2530: ' </td>';
2531: } elsif ($colsleft == 1) {
2532: $datatable .= '<td class="LC_left_item"> </td>';
1.137 raeburn 2533: }
1.145 raeburn 2534: $datatable .= '</tr></table>';
1.137 raeburn 2535: }
1.145 raeburn 2536: $datatable .= '</td></tr>';
2537: $itemcount ++;
1.137 raeburn 2538: }
2539: }
2540: }
2541: $$rowtotal += $itemcount;
2542: return $datatable;
2543: }
2544:
1.138 raeburn 2545: sub build_location_hashes {
2546: my ($intdoms,$by_ip,$by_location) = @_;
2547: return unless((ref($intdoms) eq 'ARRAY') && (ref($by_ip) eq 'HASH') &&
2548: (ref($by_location) eq 'HASH'));
2549: my %iphost = &Apache::lonnet::get_iphost();
2550: my $primary_id = &Apache::lonnet::domain($env{'request.role.domain'},'primary');
2551: my $primary_ip = &Apache::lonnet::get_host_ip($primary_id);
2552: if (ref($iphost{$primary_ip}) eq 'ARRAY') {
2553: foreach my $id (@{$iphost{$primary_ip}}) {
2554: my $intdom = &Apache::lonnet::internet_dom($id);
2555: unless(grep(/^\Q$intdom\E$/,@{$intdoms})) {
2556: push(@{$intdoms},$intdom);
2557: }
2558: }
2559: }
2560: foreach my $ip (keys(%iphost)) {
2561: if (ref($iphost{$ip}) eq 'ARRAY') {
2562: foreach my $id (@{$iphost{$ip}}) {
2563: my $location = &Apache::lonnet::internet_dom($id);
2564: if ($location) {
2565: next if (grep(/^\Q$location\E$/,@{$intdoms}));
2566: if (ref($by_ip->{$ip}) eq 'ARRAY') {
2567: unless(grep(/^\Q$location\E$/,@{$by_ip->{$ip}})) {
2568: push(@{$by_ip->{$ip}},$location);
2569: }
2570: } else {
2571: $by_ip->{$ip} = [$location];
2572: }
2573: }
2574: }
2575: }
2576: }
2577: foreach my $ip (sort(keys(%{$by_ip}))) {
2578: if (ref($by_ip->{$ip}) eq 'ARRAY') {
2579: @{$by_ip->{$ip}} = sort(@{$by_ip->{$ip}});
2580: my $first = $by_ip->{$ip}->[0];
2581: if (ref($by_location->{$first}) eq 'ARRAY') {
2582: unless (grep(/^\Q$ip\E$/,@{$by_location->{$first}})) {
2583: push(@{$by_location->{$first}},$ip);
2584: }
2585: } else {
2586: $by_location->{$first} = [$ip];
2587: }
2588: }
2589: }
2590: return;
2591: }
2592:
1.145 raeburn 2593: sub current_offloads_to {
2594: my ($dom,$settings,$servers) = @_;
2595: my (%spareid,%otherdomconfigs);
1.152 raeburn 2596: if (ref($servers) eq 'HASH') {
1.145 raeburn 2597: foreach my $lonhost (sort(keys(%{$servers}))) {
2598: my $gotspares;
1.152 raeburn 2599: if (ref($settings) eq 'HASH') {
2600: if (ref($settings->{'spares'}) eq 'HASH') {
2601: if (ref($settings->{'spares'}{$lonhost}) eq 'HASH') {
2602: $spareid{$lonhost}{'primary'} = $settings->{'spares'}{$lonhost}{'primary'};
2603: $spareid{$lonhost}{'default'} = $settings->{'spares'}{$lonhost}{'default'};
2604: $gotspares = 1;
2605: }
1.145 raeburn 2606: }
2607: }
2608: unless ($gotspares) {
2609: my $gotspares;
2610: my $serverhomeID =
2611: &Apache::lonnet::get_server_homeID($servers->{$lonhost});
2612: my $serverhomedom =
2613: &Apache::lonnet::host_domain($serverhomeID);
2614: if ($serverhomedom ne $dom) {
2615: if (ref($otherdomconfigs{$serverhomedom} eq 'HASH')) {
2616: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
2617: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
2618: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
2619: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
2620: $gotspares = 1;
2621: }
2622: }
2623: } else {
2624: $otherdomconfigs{$serverhomedom} =
2625: &Apache::lonnet::get_dom('configuration',['usersessions'],$serverhomedom);
2626: if (ref($otherdomconfigs{$serverhomedom}) eq 'HASH') {
2627: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
2628: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
2629: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{$lonhost}) eq 'HASH') {
2630: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
2631: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
2632: $gotspares = 1;
2633: }
2634: }
2635: }
2636: }
2637: }
2638: }
2639: }
2640: unless ($gotspares) {
2641: if ($lonhost eq $Apache::lonnet::perlvar{'lonHostID'}) {
2642: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
2643: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
2644: } else {
2645: my $server_hostname = &Apache::lonnet::hostname($lonhost);
2646: my $server_homeID = &Apache::lonnet::get_server_homeID($server_hostname);
2647: if ($server_homeID eq $Apache::lonnet::perlvar{'lonHostID'}) {
2648: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
2649: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
2650: } else {
1.150 raeburn 2651: my %what = (
2652: spareid => 1,
2653: );
2654: my ($result,$returnhash) =
2655: &Apache::lonnet::get_remote_globals($lonhost,\%what);
2656: if ($result eq 'ok') {
2657: if (ref($returnhash) eq 'HASH') {
2658: if (ref($returnhash->{'spareid'}) eq 'HASH') {
2659: $spareid{$lonhost}{'primary'} = $returnhash->{'spareid'}->{'primary'};
2660: $spareid{$lonhost}{'default'} = $returnhash->{'spareid'}->{'default'};
2661: }
2662: }
1.145 raeburn 2663: }
2664: }
2665: }
2666: }
2667: }
2668: }
2669: return %spareid;
2670: }
2671:
2672: sub spares_row {
1.152 raeburn 2673: my ($dom,$servers,$spareid,$serverhomes,$altids,$rowtotal) = @_;
1.145 raeburn 2674: my $css_class;
2675: my $numinrow = 4;
2676: my $itemcount = 1;
2677: my $datatable;
1.152 raeburn 2678: my %typetitles = &sparestype_titles();
2679: if ((ref($servers) eq 'HASH') && (ref($spareid) eq 'HASH') && (ref($altids) eq 'HASH')) {
1.145 raeburn 2680: foreach my $server (sort(keys(%{$servers}))) {
1.152 raeburn 2681: my $serverhome = &Apache::lonnet::get_server_homeID($servers->{$server});
2682: my ($othercontrol,$serverdom);
2683: if ($serverhome ne $server) {
2684: $serverdom = &Apache::lonnet::host_domain($serverhome);
2685: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
2686: } else {
2687: $serverdom = &Apache::lonnet::host_domain($server);
2688: if ($serverdom ne $dom) {
2689: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
2690: }
2691: }
2692: next unless (ref($spareid->{$server}) eq 'HASH');
1.145 raeburn 2693: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
2694: $datatable .= '<tr'.$css_class.'>
2695: <td rowspan="2">
1.152 raeburn 2696: <span class="LC_nobreak"><b>'.$server.'</b> when busy, offloads to:</span></td>'."\n";
1.145 raeburn 2697: my (%current,%canselect);
1.152 raeburn 2698: my @choices =
2699: &possible_newspares($server,$spareid->{$server},$serverhomes,$altids);
2700: foreach my $type ('primary','default') {
2701: if (ref($spareid->{$server}) eq 'HASH') {
1.145 raeburn 2702: if (ref($spareid->{$server}{$type}) eq 'ARRAY') {
2703: my @spares = @{$spareid->{$server}{$type}};
2704: if (@spares > 0) {
1.152 raeburn 2705: if ($othercontrol) {
2706: $current{$type} = join(', ',@spares);
2707: } else {
2708: $current{$type} .= '<table>';
2709: my $numspares = scalar(@spares);
2710: for (my $i=0; $i<@spares; $i++) {
2711: my $rem = $i%($numinrow);
2712: if ($rem == 0) {
2713: if ($i > 0) {
2714: $current{$type} .= '</tr>';
2715: }
2716: $current{$type} .= '<tr>';
1.145 raeburn 2717: }
1.152 raeburn 2718: $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'".');" /> '.
2719: $spareid->{$server}{$type}[$i].
2720: '</label></td>'."\n";
2721: }
2722: my $rem = @spares%($numinrow);
2723: my $colsleft = $numinrow - $rem;
2724: if ($colsleft > 1 ) {
2725: $current{$type} .= '<td colspan="'.$colsleft.
2726: '" class="LC_left_item">'.
2727: ' </td>';
2728: } elsif ($colsleft == 1) {
2729: $current{$type} .= '<td class="LC_left_item"> </td>'."\n";
1.145 raeburn 2730: }
1.152 raeburn 2731: $current{$type} .= '</tr></table>';
1.150 raeburn 2732: }
1.145 raeburn 2733: }
2734: }
2735: if ($current{$type} eq '') {
2736: $current{$type} = &mt('None specified');
2737: }
1.152 raeburn 2738: if ($othercontrol) {
2739: if ($type eq 'primary') {
2740: $canselect{$type} = $othercontrol;
2741: }
2742: } else {
2743: $canselect{$type} =
2744: &mt('Add new [_1]'.$type.'[_2]:','<i>','</i>').' '.
2745: '<select name="newspare_'.$type.'_'.$server.'" '.
2746: 'id="newspare_'.$type.'_'.$server.'" onchange="checkNewSpares('."'$server','$type'".');">'."\n".
2747: '<option value="" selected ="selected">'.&mt('Select').'</option>'."\n";
2748: if (@choices > 0) {
2749: foreach my $lonhost (@choices) {
2750: $canselect{$type} .= '<option value="'.$lonhost.'">'.$lonhost.'</option>'."\n";
2751: }
2752: }
2753: $canselect{$type} .= '</select>'."\n";
2754: }
2755: } else {
2756: $current{$type} = &mt('Could not be determined');
2757: if ($type eq 'primary') {
2758: $canselect{$type} = $othercontrol;
2759: }
1.145 raeburn 2760: }
1.152 raeburn 2761: if ($type eq 'default') {
2762: $datatable .= '<tr'.$css_class.'>';
2763: }
2764: $datatable .= '<td><i>'.$typetitles{$type}.'</i></td>'."\n".
2765: '<td>'.$current{$type}.'</td>'."\n".
2766: '<td>'.$canselect{$type}.'</td></tr>'."\n";
1.145 raeburn 2767: }
2768: $itemcount ++;
2769: }
2770: }
2771: $$rowtotal += $itemcount;
2772: return $datatable;
2773: }
2774:
1.152 raeburn 2775: sub possible_newspares {
2776: my ($server,$currspares,$serverhomes,$altids) = @_;
2777: my $serverhostname = &Apache::lonnet::hostname($server);
2778: my %excluded;
2779: if ($serverhostname ne '') {
2780: %excluded = (
2781: $serverhostname => 1,
2782: );
2783: }
2784: if (ref($currspares) eq 'HASH') {
2785: foreach my $type (keys(%{$currspares})) {
2786: if (ref($currspares->{$type}) eq 'ARRAY') {
2787: if (@{$currspares->{$type}} > 0) {
2788: foreach my $curr (@{$currspares->{$type}}) {
2789: my $hostname = &Apache::lonnet::hostname($curr);
2790: $excluded{$hostname} = 1;
2791: }
2792: }
2793: }
2794: }
2795: }
2796: my @choices;
2797: if ((ref($serverhomes) eq 'HASH') && (ref($altids) eq 'HASH')) {
2798: if (keys(%{$serverhomes}) > 1) {
2799: foreach my $name (sort(keys(%{$serverhomes}))) {
2800: unless ($excluded{$name}) {
2801: if (exists($altids->{$serverhomes->{$name}})) {
2802: push(@choices,$altids->{$serverhomes->{$name}});
2803: } else {
2804: push(@choices,$serverhomes->{$name});
1.145 raeburn 2805: }
2806: }
2807: }
2808: }
2809: }
1.152 raeburn 2810: return sort(@choices);
1.145 raeburn 2811: }
2812:
1.150 raeburn 2813: sub print_loadbalancing {
2814: my ($dom,$settings,$rowtotal) = @_;
2815: my $primary_id = &Apache::lonnet::domain($dom,'primary');
2816: my $intdom = &Apache::lonnet::internet_dom($primary_id);
2817: my $numinrow = 1;
2818: my $datatable;
2819: my %servers = &Apache::lonnet::internet_dom_servers($dom);
2820: my ($currbalancer,$currtargets,$currrules);
2821: if (keys(%servers) > 1) {
2822: if (ref($settings) eq 'HASH') {
2823: $currbalancer = $settings->{'lonhost'};
2824: $currtargets = $settings->{'targets'};
2825: $currrules = $settings->{'rules'};
2826: } else {
2827: ($currbalancer,$currtargets) =
2828: &Apache::lonnet::get_lonbalancer_config(\%servers);
2829: }
2830: } else {
2831: return;
2832: }
2833: my ($othertitle,$usertypes,$types) =
2834: &Apache::loncommon::sorted_inst_types($dom);
2835: my $rownum = 6;
2836: if (ref($types) eq 'ARRAY') {
2837: $rownum += scalar(@{$types});
2838: }
1.153 raeburn 2839: my $css_class = ' class="LC_odd_row"';
1.150 raeburn 2840: my $targets_div_style = 'display: none';
2841: my $disabled_div_style = 'display: block';
2842: my $homedom_div_style = 'display: none';
2843: $datatable = '<tr'.$css_class.'>'.
2844: '<td rowspan="'.$rownum.'" valign="top">'.
2845: '<p><select name="loadbalancing_lonhost" onchange="toggleTargets();">'."\n".
2846: '<option value=""';
2847: if (($currbalancer eq '') || (!grep(/^\Q$currbalancer\E$/,keys(%servers)))) {
2848: $datatable .= ' selected="selected"';
2849: } else {
2850: $targets_div_style = 'display: block';
2851: $disabled_div_style = 'display: none';
2852: if ($dom eq &Apache::lonnet::host_domain($currbalancer)) {
2853: $homedom_div_style = 'display: block';
2854: }
2855: }
2856: $datatable .= '>'.&mt('None').'</option>'."\n";
2857: foreach my $lonhost (sort(keys(%servers))) {
2858: my $selected;
2859: if ($lonhost eq $currbalancer) {
2860: $selected .= ' selected="selected"';
2861: }
2862: $datatable .= '<option value="'.$lonhost.'"'.$selected.'>'.$lonhost.'</option>'."\n";
2863: }
2864: $datatable .= '</select></p></td><td rowspan="'.$rownum.'" valign="top">'.
2865: '<div id="loadbalancing_disabled" style="'.$disabled_div_style.'">'.&mt('No dedicated Load Balancer').'</div>'."\n".
2866: '<div id="loadbalancing_targets" style="'.$targets_div_style.'">'.&mt('Offloads to:').'<br />';
2867: my ($numspares,@spares) = &count_servers($currbalancer,%servers);
2868: my @sparestypes = ('primary','default');
2869: my %typetitles = &sparestype_titles();
2870: foreach my $sparetype (@sparestypes) {
2871: my $targettable;
2872: for (my $i=0; $i<$numspares; $i++) {
2873: my $checked;
2874: if (ref($currtargets) eq 'HASH') {
2875: if (ref($currtargets->{$sparetype}) eq 'ARRAY') {
2876: if (grep(/^\Q$spares[$i]\E$/,@{$currtargets->{$sparetype}})) {
2877: $checked = ' checked="checked"';
2878: }
2879: }
2880: }
2881: my $chkboxval;
2882: if (($currbalancer ne '') && (grep((/^\Q$currbalancer\E$/,keys(%servers))))) {
2883: $chkboxval = $spares[$i];
2884: }
2885: $targettable .= '<td><label><input type="checkbox" name="loadbalancing_target_'.$sparetype.'"'.
2886: $checked.' value="'.$chkboxval.'" id="loadbalancing_target_'.$sparetype.'_'.$i.'" onclick="checkOffloads('."this,'$sparetype'".');" /><span id="loadbalancing_targettxt_'.$sparetype.'_'.$i.'"> '.$chkboxval.
2887: '</span></label></td>';
2888: my $rem = $i%($numinrow);
2889: if ($rem == 0) {
2890: if ($i > 0) {
2891: $targettable .= '</tr>';
2892: }
2893: $targettable .= '<tr>';
2894: }
2895: }
2896: if ($targettable ne '') {
2897: my $rem = $numspares%($numinrow);
2898: my $colsleft = $numinrow - $rem;
2899: if ($colsleft > 1 ) {
2900: $targettable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
2901: ' </td>';
2902: } elsif ($colsleft == 1) {
2903: $targettable .= '<td class="LC_left_item"> </td>';
2904: }
2905: $datatable .= '<i>'.$typetitles{$sparetype}.'</i><br />'.
2906: '<table><tr>'.$targettable.'</table><br />';
2907: }
2908: }
2909: $datatable .= '</div></td></tr>'.
2910: &loadbalancing_rules($dom,$intdom,$currrules,$othertitle,
2911: $usertypes,$types,\%servers,$currbalancer,
1.153 raeburn 2912: $targets_div_style,$homedom_div_style,$css_class);
1.150 raeburn 2913: $$rowtotal += $rownum;
2914: return $datatable;
2915: }
2916:
2917: sub loadbalancing_rules {
2918: my ($dom,$intdom,$currrules,$othertitle,$usertypes,$types,$servers,
1.153 raeburn 2919: $currbalancer,$targets_div_style,$homedom_div_style,$css_class) = @_;
1.150 raeburn 2920: my $output;
2921: my ($alltypes,$othertypes,$titles) =
2922: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
2923: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
2924: foreach my $type (@{$alltypes}) {
2925: my $current;
2926: if (ref($currrules) eq 'HASH') {
2927: $current = $currrules->{$type};
2928: }
2929: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
2930: if ($dom ne &Apache::lonnet::host_domain($currbalancer)) {
2931: $current = '';
2932: }
2933: }
2934: $output .= &loadbalance_rule_row($type,$titles->{$type},$current,
2935: $servers,$currbalancer,$dom,
1.153 raeburn 2936: $targets_div_style,$homedom_div_style,$css_class);
1.150 raeburn 2937: }
2938: }
2939: return $output;
2940: }
2941:
2942: sub loadbalancing_titles {
2943: my ($dom,$intdom,$usertypes,$types) = @_;
2944: my %othertypes = (
2945: '_LC_adv' => &mt('Advanced users from [_1]',$dom),
2946: '_LC_author' => &mt('Users from [_1] with author role',$dom),
2947: '_LC_internetdom' => &mt('Users not from [_1], but from [_2]',$dom,$intdom),
2948: '_LC_external' => &mt('Users not from [_1]',$intdom),
2949: );
2950: my @alltypes = ('_LC_adv','_LC_author','_LC_internetdom','_LC_external');
2951: if (ref($types) eq 'ARRAY') {
2952: unshift(@alltypes,@{$types},'default');
2953: }
2954: my %titles;
2955: foreach my $type (@alltypes) {
2956: if ($type =~ /^_LC_/) {
2957: $titles{$type} = $othertypes{$type};
2958: } elsif ($type eq 'default') {
2959: $titles{$type} = &mt('All users from [_1]',$dom);
2960: if (ref($types) eq 'ARRAY') {
2961: if (@{$types} > 0) {
2962: $titles{$type} = &mt('Other users from [_1]',$dom);
2963: }
2964: }
2965: } elsif (ref($usertypes) eq 'HASH') {
2966: $titles{$type} = $usertypes->{$type};
2967: }
2968: }
2969: return (\@alltypes,\%othertypes,\%titles);
2970: }
2971:
2972: sub loadbalance_rule_row {
2973: my ($type,$title,$current,$servers,$currbalancer,$dom,$targets_div_style,
1.153 raeburn 2974: $homedom_div_style,$css_class) = @_;
1.150 raeburn 2975: my @rulenames = ('default','homeserver');
2976: my %ruletitles = &offloadtype_text();
2977: if ($type eq '_LC_external') {
2978: push(@rulenames,'externalbalancer');
2979: } else {
2980: push(@rulenames,'specific');
2981: }
1.161 raeburn 2982: push(@rulenames,'none');
1.150 raeburn 2983: my $style = $targets_div_style;
2984: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
2985: $style = $homedom_div_style;
2986: }
2987: my $output =
1.153 raeburn 2988: '<tr'.$css_class.'><td valign="top"><div id="balanceruletitle_'.$type.'" style="'.$style.'">'.$title.'</div></td>'."\n".
1.150 raeburn 2989: '<td><div id="balancerule_'.$type.'" style="'.$style.'">'."\n";
2990: for (my $i=0; $i<@rulenames; $i++) {
2991: my $rule = $rulenames[$i];
2992: my ($checked,$extra);
2993: if ($rulenames[$i] eq 'default') {
2994: $rule = '';
2995: }
2996: if ($rulenames[$i] eq 'specific') {
2997: if (ref($servers) eq 'HASH') {
2998: my $default;
2999: if (($current ne '') && (exists($servers->{$current}))) {
3000: $checked = ' checked="checked"';
3001: }
3002: unless ($checked) {
3003: $default = ' selected="selected"';
3004: }
3005: $extra = ': <select name="loadbalancing_singleserver_'.$type.
3006: '" id="loadbalancing_singleserver_'.$type.
3007: '" onchange="singleServerToggle('."'$type'".')">'."\n".
3008: '<option value=""'.$default.'></option>'."\n";
3009: foreach my $lonhost (sort(keys(%{$servers}))) {
3010: next if ($lonhost eq $currbalancer);
3011: my $selected;
3012: if ($lonhost eq $current) {
3013: $selected = ' selected="selected"';
3014: }
3015: $extra .= '<option value="'.$lonhost.'"'.$selected.'>'.$lonhost.'</option>';
3016: }
3017: $extra .= '</select>';
3018: }
3019: } elsif ($rule eq $current) {
3020: $checked = ' checked="checked"';
3021: }
3022: $output .= '<span class="LC_nobreak"><label>'.
3023: '<input type="radio" name="loadbalancing_rules_'.$type.
3024: '" id="loadbalancing_rules_'.$type.'_'.$i.'" value="'.
3025: $rule.'" onclick="balanceruleChange('."this.form,'$type'".
3026: ')"'.$checked.' /> '.$ruletitles{$rulenames[$i]}.
3027: '</label>'.$extra.'</span><br />'."\n";
3028: }
3029: $output .= '</div></td></tr>'."\n";
3030: return $output;
3031: }
3032:
3033: sub offloadtype_text {
3034: my %ruletitles = &Apache::lonlocal::texthash (
3035: 'default' => 'Offloads to default destinations',
3036: 'homeserver' => "Offloads to user's home server",
3037: 'externalbalancer' => "Offloads to Load Balancer in user's domain",
3038: 'specific' => 'Offloads to specific server',
1.161 raeburn 3039: 'none' => 'No offload',
1.150 raeburn 3040: );
3041: return %ruletitles;
3042: }
3043:
3044: sub sparestype_titles {
3045: my %typestitles = &Apache::lonlocal::texthash (
3046: 'primary' => 'primary',
3047: 'default' => 'default',
3048: );
3049: return %typestitles;
3050: }
3051:
1.28 raeburn 3052: sub contact_titles {
3053: my %titles = &Apache::lonlocal::texthash (
3054: 'supportemail' => 'Support E-mail address',
1.69 raeburn 3055: 'adminemail' => 'Default Server Admin E-mail address',
1.28 raeburn 3056: 'errormail' => 'Error reports to be e-mailed to',
3057: 'packagesmail' => 'Package update alerts to be e-mailed to',
1.89 raeburn 3058: 'helpdeskmail' => 'Helpdesk requests to be e-mailed to',
3059: 'lonstatusmail' => 'E-mail from nightly status check (warnings/errors)',
1.102 raeburn 3060: 'requestsmail' => 'E-mail from course requests requiring approval',
1.28 raeburn 3061: );
3062: my %short_titles = &Apache::lonlocal::texthash (
3063: adminemail => 'Admin E-mail address',
3064: supportemail => 'Support E-mail',
3065: );
3066: return (\%titles,\%short_titles);
3067: }
3068:
1.72 raeburn 3069: sub tool_titles {
3070: my %titles = &Apache::lonlocal::texthash (
1.162 raeburn 3071: aboutme => 'Personal web page',
1.86 raeburn 3072: blog => 'Blog',
1.162 raeburn 3073: webdav => 'WebDAV',
1.86 raeburn 3074: portfolio => 'Portfolio',
1.88 bisitz 3075: official => 'Official courses (with institutional codes)',
3076: unofficial => 'Unofficial courses',
1.98 raeburn 3077: community => 'Communities',
1.86 raeburn 3078: );
1.72 raeburn 3079: return %titles;
3080: }
3081:
1.101 raeburn 3082: sub courserequest_titles {
3083: my %titles = &Apache::lonlocal::texthash (
3084: official => 'Official',
3085: unofficial => 'Unofficial',
3086: community => 'Communities',
3087: norequest => 'Not allowed',
1.104 raeburn 3088: approval => 'Approval by Dom. Coord.',
1.101 raeburn 3089: validate => 'With validation',
3090: autolimit => 'Numerical limit',
1.103 raeburn 3091: unlimited => '(blank for unlimited)',
1.101 raeburn 3092: );
3093: return %titles;
3094: }
3095:
1.163 raeburn 3096: sub authorrequest_titles {
3097: my %titles = &Apache::lonlocal::texthash (
3098: norequest => 'Not allowed',
3099: approval => 'Approval by Dom. Coord.',
3100: automatic => 'Automatic approval',
3101: );
3102: return %titles;
3103: }
3104:
1.101 raeburn 3105: sub courserequest_conditions {
3106: my %conditions = &Apache::lonlocal::texthash (
1.104 raeburn 3107: approval => '(Processing of request subject to approval by Domain Coordinator).',
1.101 raeburn 3108: validate => '(Processing of request subject to instittutional validation).',
3109: );
3110: return %conditions;
3111: }
3112:
3113:
1.27 raeburn 3114: sub print_usercreation {
1.30 raeburn 3115: my ($position,$dom,$settings,$rowtotal) = @_;
1.27 raeburn 3116: my $numinrow = 4;
1.28 raeburn 3117: my $datatable;
3118: if ($position eq 'top') {
1.30 raeburn 3119: $$rowtotal ++;
1.34 raeburn 3120: my $rowcount = 0;
1.32 raeburn 3121: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username');
1.28 raeburn 3122: if (ref($rules) eq 'HASH') {
3123: if (keys(%{$rules}) > 0) {
1.32 raeburn 3124: $datatable .= &user_formats_row('username',$settings,$rules,
3125: $ruleorder,$numinrow,$rowcount);
1.30 raeburn 3126: $$rowtotal ++;
1.32 raeburn 3127: $rowcount ++;
3128: }
3129: }
3130: my ($idrules,$idruleorder) = &Apache::lonnet::inst_userrules($dom,'id');
3131: if (ref($idrules) eq 'HASH') {
3132: if (keys(%{$idrules}) > 0) {
3133: $datatable .= &user_formats_row('id',$settings,$idrules,
3134: $idruleorder,$numinrow,$rowcount);
3135: $$rowtotal ++;
3136: $rowcount ++;
1.28 raeburn 3137: }
3138: }
1.43 raeburn 3139: my ($emailrules,$emailruleorder) =
3140: &Apache::lonnet::inst_userrules($dom,'email');
3141: if (ref($emailrules) eq 'HASH') {
3142: if (keys(%{$emailrules}) > 0) {
3143: $datatable .= &user_formats_row('email',$settings,$emailrules,
3144: $emailruleorder,$numinrow,$rowcount);
3145: $$rowtotal ++;
3146: $rowcount ++;
3147: }
3148: }
1.39 raeburn 3149: if ($rowcount == 0) {
3150: $datatable .= '<tr><td colspan="2">'.&mt('No format rules have been defined for usernames or IDs in this domain.').'</td></tr>';
3151: $$rowtotal ++;
3152: $rowcount ++;
3153: }
1.34 raeburn 3154: } elsif ($position eq 'middle') {
1.100 raeburn 3155: my @creators = ('author','course','requestcrs','selfcreate');
1.37 raeburn 3156: my ($rules,$ruleorder) =
3157: &Apache::lonnet::inst_userrules($dom,'username');
1.34 raeburn 3158: my %lt = &usercreation_types();
3159: my %checked;
1.50 raeburn 3160: my @selfcreate;
1.34 raeburn 3161: if (ref($settings) eq 'HASH') {
3162: if (ref($settings->{'cancreate'}) eq 'HASH') {
3163: foreach my $item (@creators) {
3164: $checked{$item} = $settings->{'cancreate'}{$item};
3165: }
1.50 raeburn 3166: if (ref($settings->{'cancreate'}{'selfcreate'}) eq 'ARRAY') {
3167: @selfcreate = @{$settings->{'cancreate'}{'selfcreate'}};
3168: } elsif ($settings->{'cancreate'}{'selfcreate'} ne '') {
3169: if ($settings->{'cancreate'}{'selfcreate'} eq 'any') {
3170: @selfcreate = ('email','login','sso');
3171: } elsif ($settings->{'cancreate'}{'selfcreate'} ne 'none') {
3172: @selfcreate = ($settings->{'cancreate'}{'selfcreate'});
3173: }
3174: }
1.34 raeburn 3175: } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {
3176: foreach my $item (@creators) {
3177: if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {
3178: $checked{$item} = 'none';
3179: }
3180: }
3181: }
3182: }
3183: my $rownum = 0;
3184: foreach my $item (@creators) {
3185: $rownum ++;
1.50 raeburn 3186: if ($item ne 'selfcreate') {
3187: if ($checked{$item} eq '') {
1.43 raeburn 3188: $checked{$item} = 'any';
3189: }
1.34 raeburn 3190: }
3191: my $css_class;
3192: if ($rownum%2) {
3193: $css_class = '';
3194: } else {
3195: $css_class = ' class="LC_odd_row" ';
3196: }
3197: $datatable .= '<tr'.$css_class.'>'.
3198: '<td><span class="LC_nobreak">'.$lt{$item}.
3199: '</span></td><td align="right">';
1.50 raeburn 3200: my @options;
1.45 raeburn 3201: if ($item eq 'selfcreate') {
1.43 raeburn 3202: push(@options,('email','login','sso'));
3203: } else {
1.50 raeburn 3204: @options = ('any');
1.43 raeburn 3205: if (ref($rules) eq 'HASH') {
3206: if (keys(%{$rules}) > 0) {
3207: push(@options,('official','unofficial'));
3208: }
1.37 raeburn 3209: }
1.50 raeburn 3210: push(@options,'none');
1.37 raeburn 3211: }
3212: foreach my $option (@options) {
1.50 raeburn 3213: my $type = 'radio';
1.34 raeburn 3214: my $check = ' ';
1.50 raeburn 3215: if ($item eq 'selfcreate') {
3216: $type = 'checkbox';
3217: if (grep(/^\Q$option\E$/,@selfcreate)) {
3218: $check = ' checked="checked" ';
3219: }
3220: } else {
3221: if ($checked{$item} eq $option) {
3222: $check = ' checked="checked" ';
3223: }
1.34 raeburn 3224: }
3225: $datatable .= '<span class="LC_nobreak"><label>'.
1.50 raeburn 3226: '<input type="'.$type.'" name="can_createuser_'.
1.34 raeburn 3227: $item.'" value="'.$option.'"'.$check.'/> '.
3228: $lt{$option}.'</label> </span>';
3229: }
3230: $datatable .= '</td></tr>';
3231: }
1.93 raeburn 3232: my ($othertitle,$usertypes,$types) =
3233: &Apache::loncommon::sorted_inst_types($dom);
1.165 raeburn 3234: my $createsettings;
3235: if (ref($settings) eq 'HASH') {
3236: $createsettings = $settings->{cancreate};
3237: }
1.93 raeburn 3238: if (ref($usertypes) eq 'HASH') {
3239: if (keys(%{$usertypes}) > 0) {
1.99 raeburn 3240: $datatable .= &insttypes_row($createsettings,$types,$usertypes,
1.93 raeburn 3241: $dom,$numinrow,$othertitle,
3242: 'statustocreate');
3243: $$rowtotal ++;
3244: }
3245: }
1.165 raeburn 3246: $datatable .= &captcha_choice('cancreate',$createsettings);
1.28 raeburn 3247: } else {
3248: my @contexts = ('author','course','domain');
3249: my @authtypes = ('int','krb4','krb5','loc');
3250: my %checked;
3251: if (ref($settings) eq 'HASH') {
3252: if (ref($settings->{'authtypes'}) eq 'HASH') {
3253: foreach my $item (@contexts) {
3254: if (ref($settings->{'authtypes'}{$item}) eq 'HASH') {
3255: foreach my $auth (@authtypes) {
3256: if ($settings->{'authtypes'}{$item}{$auth}) {
3257: $checked{$item}{$auth} = ' checked="checked" ';
3258: }
3259: }
3260: }
3261: }
1.27 raeburn 3262: }
1.35 raeburn 3263: } else {
3264: foreach my $item (@contexts) {
1.36 raeburn 3265: foreach my $auth (@authtypes) {
1.35 raeburn 3266: $checked{$item}{$auth} = ' checked="checked" ';
3267: }
3268: }
1.27 raeburn 3269: }
1.28 raeburn 3270: my %title = &context_names();
3271: my %authname = &authtype_names();
3272: my $rownum = 0;
3273: my $css_class;
3274: foreach my $item (@contexts) {
3275: if ($rownum%2) {
3276: $css_class = '';
3277: } else {
3278: $css_class = ' class="LC_odd_row" ';
3279: }
1.30 raeburn 3280: $datatable .= '<tr'.$css_class.'>'.
1.28 raeburn 3281: '<td>'.$title{$item}.
3282: '</td><td class="LC_left_item">'.
3283: '<span class="LC_nobreak">';
3284: foreach my $auth (@authtypes) {
3285: $datatable .= '<label>'.
3286: '<input type="checkbox" name="'.$item.'_auth" '.
3287: $checked{$item}{$auth}.' value="'.$auth.'" />'.
3288: $authname{$auth}.'</label> ';
3289: }
3290: $datatable .= '</span></td></tr>';
3291: $rownum ++;
1.27 raeburn 3292: }
1.30 raeburn 3293: $$rowtotal += $rownum;
1.27 raeburn 3294: }
3295: return $datatable;
3296: }
3297:
1.165 raeburn 3298: sub captcha_choice {
3299: my ($context,$settings) = @_;
3300: my ($keyentry,$currpub,$currpriv,%checked,$rowname,$pubtext,$privtext);
3301: my %lt = &captcha_phrases();
3302: $keyentry = 'hidden';
3303: if ($context eq 'cancreate') {
3304: $rowname = &mt('CAPTCHA validation (e-mail as username)');
3305: } elsif ($context eq 'help') {
3306: $rowname = &mt('CAPTCHA validation');
3307: }
3308: if (ref($settings) eq 'HASH') {
3309: if ($settings->{'captcha'}) {
3310: $checked{$settings->{'captcha'}} = ' checked="checked"';
3311: } else {
3312: $checked{'original'} = ' checked="checked"';
3313: }
3314: if ($settings->{'captcha'} eq 'recaptcha') {
3315: $pubtext = $lt{'pub'};
3316: $privtext = $lt{'priv'};
3317: $keyentry = 'text';
3318: }
3319: if (ref($settings->{'recaptchakeys'}) eq 'HASH') {
3320: $currpub = $settings->{'recaptchakeys'}{'public'};
3321: $currpriv = $settings->{'recaptchakeys'}{'private'};
3322: }
3323: } else {
3324: $checked{'original'} = ' checked="checked"';
3325: }
3326: my $output = '<tr class="LC_odd_row">'.
3327: '<td class="LC_left_item">'.$rowname.'</td><td class="LC_right_item" colspan="2">'."\n".
3328: '<table><tr><td>'."\n";
3329: foreach my $option ('original','recaptcha','notused') {
3330: $output .= '<span class="LC_nobreak"><label><input type="radio" name="'.$context.'_captcha" value="'.
3331: $option.'" '.$checked{$option}.' onchange="javascript:updateCaptcha('."this,'$context'".');" />'.
3332: $lt{$option}.'</label></span>';
3333: unless ($option eq 'notused') {
3334: $output .= (' 'x2)."\n";
3335: }
3336: }
3337: #
3338: # Note: If reCAPTCHA is to be used for LON-CAPA servers in a domain, a domain coordinator should visit:
3339: # https://www.google.com/recaptcha and generate a Public and Private key. For domains with multiple
3340: # servers a single key pair will be used for all servers, so the internet domain (e.g., yourcollege.edu)
3341: # specified for use with the key should be broad enough to accommodate all servers in the LON-CAPA domain.
3342: #
3343: $output .= '</td></tr>'."\n".
3344: '<tr><td>'."\n".
3345: '<span class="LC_nobreak"><span id="'.$context.'_recaptchapubtxt">'.$pubtext.'</span> '."\n".
3346: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapub" name="'.$context.'_recaptchapub" value="'.
3347: $currpub.'" size="40" /></span><br />'."\n".
3348: '<span class="LC_nobreak"><span id="'.$context.'_recaptchaprivtxt">'.$privtext.'</span> '."\n".
3349: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapriv" name="'.$context.'_recaptchapriv" value="'.
3350: $currpriv.'" size="40" /></span></td></tr></table>'."\n".
3351: '</td></tr>';
3352: return $output;
3353: }
3354:
1.32 raeburn 3355: sub user_formats_row {
3356: my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount) = @_;
3357: my $output;
3358: my %text = (
3359: 'username' => 'new usernames',
3360: 'id' => 'IDs',
1.45 raeburn 3361: 'email' => 'self-created accounts (e-mail)',
1.32 raeburn 3362: );
3363: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
3364: $output = '<tr '.$css_class.'>'.
1.63 raeburn 3365: '<td><span class="LC_nobreak">';
3366: if ($type eq 'email') {
3367: $output .= &mt("Formats disallowed for $text{$type}: ");
3368: } else {
3369: $output .= &mt("Format rules to check for $text{$type}: ");
3370: }
3371: $output .= '</span></td>'.
3372: '<td class="LC_left_item" colspan="2"><table>';
1.27 raeburn 3373: my $rem;
3374: if (ref($ruleorder) eq 'ARRAY') {
3375: for (my $i=0; $i<@{$ruleorder}; $i++) {
3376: if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
3377: my $rem = $i%($numinrow);
3378: if ($rem == 0) {
3379: if ($i > 0) {
3380: $output .= '</tr>';
3381: }
3382: $output .= '<tr>';
3383: }
3384: my $check = ' ';
1.39 raeburn 3385: if (ref($settings) eq 'HASH') {
3386: if (ref($settings->{$type.'_rule'}) eq 'ARRAY') {
3387: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) {
3388: $check = ' checked="checked" ';
3389: }
1.27 raeburn 3390: }
3391: }
3392: $output .= '<td class="LC_left_item">'.
3393: '<span class="LC_nobreak"><label>'.
1.32 raeburn 3394: '<input type="checkbox" name="'.$type.'_rule" '.
1.27 raeburn 3395: 'value="'.$ruleorder->[$i].'"'.$check.'/>'.
3396: $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
3397: }
3398: }
3399: $rem = @{$ruleorder}%($numinrow);
3400: }
3401: my $colsleft = $numinrow - $rem;
3402: if ($colsleft > 1 ) {
3403: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
3404: ' </td>';
3405: } elsif ($colsleft == 1) {
3406: $output .= '<td class="LC_left_item"> </td>';
3407: }
3408: $output .= '</tr></table></td></tr>';
3409: return $output;
3410: }
3411:
1.34 raeburn 3412: sub usercreation_types {
3413: my %lt = &Apache::lonlocal::texthash (
3414: author => 'When adding a co-author',
3415: course => 'When adding a user to a course',
1.100 raeburn 3416: requestcrs => 'When requesting a course',
1.45 raeburn 3417: selfcreate => 'User creates own account',
1.34 raeburn 3418: any => 'Any',
3419: official => 'Institutional only ',
3420: unofficial => 'Non-institutional only',
1.85 schafran 3421: email => 'E-mail address',
1.43 raeburn 3422: login => 'Institutional Login',
3423: sso => 'SSO',
1.34 raeburn 3424: none => 'None',
3425: );
3426: return %lt;
1.48 raeburn 3427: }
1.34 raeburn 3428:
1.28 raeburn 3429: sub authtype_names {
3430: my %lt = &Apache::lonlocal::texthash(
3431: int => 'Internal',
3432: krb4 => 'Kerberos 4',
3433: krb5 => 'Kerberos 5',
3434: loc => 'Local',
3435: );
3436: return %lt;
3437: }
3438:
3439: sub context_names {
3440: my %context_title = &Apache::lonlocal::texthash(
3441: author => 'Creating users when an Author',
3442: course => 'Creating users when in a course',
3443: domain => 'Creating users when a Domain Coordinator',
3444: );
3445: return %context_title;
3446: }
3447:
1.33 raeburn 3448: sub print_usermodification {
3449: my ($position,$dom,$settings,$rowtotal) = @_;
3450: my $numinrow = 4;
3451: my ($context,$datatable,$rowcount);
3452: if ($position eq 'top') {
3453: $rowcount = 0;
3454: $context = 'author';
3455: foreach my $role ('ca','aa') {
3456: $datatable .= &modifiable_userdata_row($context,$role,$settings,
3457: $numinrow,$rowcount);
3458: $$rowtotal ++;
3459: $rowcount ++;
3460: }
1.63 raeburn 3461: } elsif ($position eq 'middle') {
1.33 raeburn 3462: $context = 'course';
3463: $rowcount = 0;
3464: foreach my $role ('st','ep','ta','in','cr') {
3465: $datatable .= &modifiable_userdata_row($context,$role,$settings,
3466: $numinrow,$rowcount);
3467: $$rowtotal ++;
3468: $rowcount ++;
3469: }
1.63 raeburn 3470: } elsif ($position eq 'bottom') {
3471: $context = 'selfcreate';
3472: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
3473: $usertypes->{'default'} = $othertitle;
3474: if (ref($types) eq 'ARRAY') {
3475: push(@{$types},'default');
3476: $usertypes->{'default'} = $othertitle;
3477: foreach my $status (@{$types}) {
3478: $datatable .= &modifiable_userdata_row($context,$status,$settings,
3479: $numinrow,$rowcount,$usertypes);
3480: $$rowtotal ++;
3481: $rowcount ++;
3482: }
3483: }
1.33 raeburn 3484: }
3485: return $datatable;
3486: }
3487:
1.43 raeburn 3488: sub print_defaults {
3489: my ($dom,$rowtotal) = @_;
1.68 raeburn 3490: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def',
1.141 raeburn 3491: 'datelocale_def','portal_def');
1.43 raeburn 3492: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.141 raeburn 3493: my $titles = &defaults_titles($dom);
1.43 raeburn 3494: my $rownum = 0;
3495: my ($datatable,$css_class);
3496: foreach my $item (@items) {
3497: if ($rownum%2) {
3498: $css_class = '';
3499: } else {
3500: $css_class = ' class="LC_odd_row" ';
3501: }
3502: $datatable .= '<tr'.$css_class.'>'.
3503: '<td><span class="LC_nobreak">'.$titles->{$item}.
3504: '</span></td><td class="LC_right_item">';
3505: if ($item eq 'auth_def') {
3506: my @authtypes = ('internal','krb4','krb5','localauth');
3507: my %shortauth = (
3508: internal => 'int',
3509: krb4 => 'krb4',
3510: krb5 => 'krb5',
3511: localauth => 'loc'
3512: );
3513: my %authnames = &authtype_names();
3514: foreach my $auth (@authtypes) {
3515: my $checked = ' ';
3516: if ($domdefaults{$item} eq $auth) {
3517: $checked = ' checked="checked" ';
3518: }
3519: $datatable .= '<label><input type="radio" name="'.$item.
3520: '" value="'.$auth.'"'.$checked.'/>'.
3521: $authnames{$shortauth{$auth}}.'</label> ';
3522: }
1.54 raeburn 3523: } elsif ($item eq 'timezone_def') {
3524: my $includeempty = 1;
3525: $datatable .= &Apache::loncommon::select_timezone($item,$domdefaults{$item},undef,$includeempty);
1.68 raeburn 3526: } elsif ($item eq 'datelocale_def') {
3527: my $includeempty = 1;
3528: $datatable .= &Apache::loncommon::select_datelocale($item,$domdefaults{$item},undef,$includeempty);
1.167 ! raeburn 3529: } elsif ($item eq 'lang_def') {
! 3530: my %langchoices=('' => 'No language preference');
! 3531: foreach my $id (&Apache::loncommon::languageids()) {
! 3532: my $code = &Apache::loncommon::supportedlanguagecode($id);
! 3533: if ($code ne '') {
! 3534: $langchoices{$code} = &Apache::loncommon::plainlanguagedescription($id);
! 3535: }
! 3536: }
! 3537: %langchoices = &Apache::lonlocal::texthash(%langchoices);
! 3538: $datatable .= &Apache::loncommon::select_form($domdefaults{$item},$item,
! 3539: \%langchoices);
1.43 raeburn 3540: } else {
1.141 raeburn 3541: my $size;
3542: if ($item eq 'portal_def') {
3543: $size = ' size="25"';
3544: }
1.43 raeburn 3545: $datatable .= '<input type="text" name="'.$item.'" value="'.
1.141 raeburn 3546: $domdefaults{$item}.'"'.$size.' />';
1.43 raeburn 3547: }
3548: $datatable .= '</td></tr>';
3549: $rownum ++;
3550: }
3551: $$rowtotal += $rownum;
3552: return $datatable;
3553: }
3554:
3555: sub defaults_titles {
1.141 raeburn 3556: my ($dom) = @_;
1.43 raeburn 3557: my %titles = &Apache::lonlocal::texthash (
3558: 'auth_def' => 'Default authentication type',
3559: 'auth_arg_def' => 'Default authentication argument',
3560: 'lang_def' => 'Default language',
1.54 raeburn 3561: 'timezone_def' => 'Default timezone',
1.68 raeburn 3562: 'datelocale_def' => 'Default locale for dates',
1.141 raeburn 3563: 'portal_def' => 'Portal/Default URL',
1.43 raeburn 3564: );
1.141 raeburn 3565: if ($dom) {
3566: my $uprimary_id = &Apache::lonnet::domain($dom,'primary');
3567: my $uint_dom = &Apache::lonnet::internet_dom($uprimary_id);
3568: my $protocol = $Apache::lonnet::protocol{$uprimary_id};
3569: $protocol = 'http' if ($protocol ne 'https');
3570: if ($uint_dom) {
3571: $titles{'portal_def'} .= ' '.&mt('(for example: [_1])',$protocol.'://loncapa.'.
3572: $uint_dom);
3573: }
3574: }
1.43 raeburn 3575: return (\%titles);
3576: }
3577:
1.46 raeburn 3578: sub print_scantronformat {
3579: my ($r,$dom,$confname,$settings,$rowtotal) = @_;
3580: my $itemcount = 1;
1.60 raeburn 3581: my ($datatable,$css_class,$scantronurl,$is_custom,%error,%scantronurls,
3582: %confhash);
1.46 raeburn 3583: my $switchserver = &check_switchserver($dom,$confname);
3584: my %lt = &Apache::lonlocal::texthash (
1.95 www 3585: default => 'Default bubblesheet format file error',
3586: custom => 'Custom bubblesheet format file error',
1.46 raeburn 3587: );
3588: my %scantronfiles = (
3589: default => 'default.tab',
3590: custom => 'custom.tab',
3591: );
3592: foreach my $key (keys(%scantronfiles)) {
3593: $scantronurls{$key} = '/res/'.$dom.'/'.$confname.'/scantron/'
3594: .$scantronfiles{$key};
3595: }
3596: my @defaultinfo = &Apache::lonnet::stat_file($scantronurls{'default'});
3597: if ((!@defaultinfo) || ($defaultinfo[0] eq 'no_such_dir')) {
3598: if (!$switchserver) {
3599: my $servadm = $r->dir_config('lonAdmEMail');
3600: my ($configuserok,$author_ok) = &config_check($dom,$confname,$servadm);
3601: if ($configuserok eq 'ok') {
3602: if ($author_ok eq 'ok') {
3603: my %legacyfile = (
3604: default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab',
3605: custom => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab',
3606: );
3607: my %md5chk;
3608: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 3609: ($md5chk{$type}) = split(/ /,`md5sum $legacyfile{$type}`);
3610: chomp($md5chk{$type});
1.46 raeburn 3611: }
3612: if ($md5chk{'default'} ne $md5chk{'custom'}) {
3613: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 3614: ($scantronurls{$type},my $error) =
1.46 raeburn 3615: &legacy_scantronformat($r,$dom,$confname,
3616: $type,$legacyfile{$type},
3617: $scantronurls{$type},
3618: $scantronfiles{$type});
1.60 raeburn 3619: if ($error ne '') {
3620: $error{$type} = $error;
3621: }
3622: }
3623: if (keys(%error) == 0) {
3624: $is_custom = 1;
3625: $confhash{'scantron'}{'scantronformat'} =
3626: $scantronurls{'custom'};
3627: my $putresult =
3628: &Apache::lonnet::put_dom('configuration',
3629: \%confhash,$dom);
3630: if ($putresult ne 'ok') {
3631: $error{'custom'} =
3632: '<span class="LC_error">'.
3633: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
3634: }
1.46 raeburn 3635: }
3636: } else {
1.60 raeburn 3637: ($scantronurls{'default'},my $error) =
1.46 raeburn 3638: &legacy_scantronformat($r,$dom,$confname,
3639: 'default',$legacyfile{'default'},
3640: $scantronurls{'default'},
3641: $scantronfiles{'default'});
1.60 raeburn 3642: if ($error eq '') {
3643: $confhash{'scantron'}{'scantronformat'} = '';
3644: my $putresult =
3645: &Apache::lonnet::put_dom('configuration',
3646: \%confhash,$dom);
3647: if ($putresult ne 'ok') {
3648: $error{'default'} =
3649: '<span class="LC_error">'.
3650: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
3651: }
3652: } else {
3653: $error{'default'} = $error;
3654: }
1.46 raeburn 3655: }
3656: }
3657: }
3658: } else {
1.95 www 3659: $error{'default'} = &mt("Unable to copy default bubblesheet formatfile to domain's RES space: [_1]",$switchserver);
1.46 raeburn 3660: }
3661: }
3662: if (ref($settings) eq 'HASH') {
3663: if ($settings->{'scantronformat'} eq "/res/$dom/$confname/scantron/custom.tab") {
3664: my @info = &Apache::lonnet::stat_file($settings->{'scantronformat'});
3665: if ((!@info) || ($info[0] eq 'no_such_dir')) {
3666: $scantronurl = '';
3667: } else {
3668: $scantronurl = $settings->{'scantronformat'};
3669: }
3670: $is_custom = 1;
3671: } else {
3672: $scantronurl = $scantronurls{'default'};
3673: }
3674: } else {
1.60 raeburn 3675: if ($is_custom) {
3676: $scantronurl = $scantronurls{'custom'};
3677: } else {
3678: $scantronurl = $scantronurls{'default'};
3679: }
1.46 raeburn 3680: }
3681: $css_class = $itemcount%2?' class="LC_odd_row"':'';
3682: $datatable .= '<tr'.$css_class.'>';
3683: if (!$is_custom) {
1.65 raeburn 3684: $datatable .= '<td>'.&mt('Default in use:').'<br />'.
3685: '<span class="LC_nobreak">';
1.46 raeburn 3686: if ($scantronurl) {
3687: $datatable .= '<a href="'.$scantronurl.'" target="_blank">'.
1.130 raeburn 3688: &mt('Default bubblesheet format file').'</a>';
1.46 raeburn 3689: } else {
3690: $datatable = &mt('File unavailable for display');
3691: }
1.65 raeburn 3692: $datatable .= '</span></td>';
1.60 raeburn 3693: if (keys(%error) == 0) {
3694: $datatable .= '<td valign="bottom">';
3695: if (!$switchserver) {
3696: $datatable .= &mt('Upload:').'<br />';
3697: }
3698: } else {
3699: my $errorstr;
3700: foreach my $key (sort(keys(%error))) {
3701: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
3702: }
3703: $datatable .= '<td>'.$errorstr;
3704: }
1.46 raeburn 3705: } else {
3706: if (keys(%error) > 0) {
3707: my $errorstr;
3708: foreach my $key (sort(keys(%error))) {
3709: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
3710: }
1.60 raeburn 3711: $datatable .= '<td>'.$errorstr.'</td><td> ';
1.46 raeburn 3712: } elsif ($scantronurl) {
1.65 raeburn 3713: $datatable .= '<td><span class="LC_nobreak">'.
3714: '<a href="'.$scantronurl.'" target="_blank">'.
1.130 raeburn 3715: &mt('Custom bubblesheet format file').'</a><label>'.
1.65 raeburn 3716: '<input type="checkbox" name="scantronformat_del"'.
3717: '" value="1" />'.&mt('Delete?').'</label></span></td>'.
3718: '<td><span class="LC_nobreak"> '.
3719: &mt('Replace:').'</span><br />';
1.46 raeburn 3720: }
3721: }
3722: if (keys(%error) == 0) {
3723: if ($switchserver) {
3724: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
3725: } else {
1.65 raeburn 3726: $datatable .='<span class="LC_nobreak"> '.
3727: '<input type="file" name="scantronformat" /></span>';
1.46 raeburn 3728: }
3729: }
3730: $datatable .= '</td></tr>';
3731: $$rowtotal ++;
3732: return $datatable;
3733: }
3734:
3735: sub legacy_scantronformat {
3736: my ($r,$dom,$confname,$file,$legacyfile,$newurl,$newfile) = @_;
3737: my ($url,$error);
3738: my @statinfo = &Apache::lonnet::stat_file($newurl);
3739: if ((!@statinfo) || ($statinfo[0] eq 'no_such_dir')) {
3740: (my $result,$url) =
3741: &publishlogo($r,'copy',$legacyfile,$dom,$confname,'scantron',
3742: '','',$newfile);
3743: if ($result ne 'ok') {
1.130 raeburn 3744: $error = &mt("An error occurred publishing the [_1] bubblesheet format file in RES space. Error was: [_2].",$newfile,$result);
1.46 raeburn 3745: }
3746: }
3747: return ($url,$error);
3748: }
1.43 raeburn 3749:
1.49 raeburn 3750: sub print_coursecategories {
1.57 raeburn 3751: my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;
3752: my $datatable;
3753: if ($position eq 'top') {
3754: my $toggle_cats_crs = ' ';
3755: my $toggle_cats_dom = ' checked="checked" ';
3756: my $can_cat_crs = ' ';
3757: my $can_cat_dom = ' checked="checked" ';
1.120 raeburn 3758: my $toggle_catscomm_comm = ' ';
3759: my $toggle_catscomm_dom = ' checked="checked" ';
3760: my $can_catcomm_comm = ' ';
3761: my $can_catcomm_dom = ' checked="checked" ';
3762:
1.57 raeburn 3763: if (ref($settings) eq 'HASH') {
3764: if ($settings->{'togglecats'} eq 'crs') {
3765: $toggle_cats_crs = $toggle_cats_dom;
3766: $toggle_cats_dom = ' ';
3767: }
3768: if ($settings->{'categorize'} eq 'crs') {
3769: $can_cat_crs = $can_cat_dom;
3770: $can_cat_dom = ' ';
3771: }
1.120 raeburn 3772: if ($settings->{'togglecatscomm'} eq 'comm') {
3773: $toggle_catscomm_comm = $toggle_catscomm_dom;
3774: $toggle_catscomm_dom = ' ';
3775: }
3776: if ($settings->{'categorizecomm'} eq 'comm') {
3777: $can_catcomm_comm = $can_catcomm_dom;
3778: $can_catcomm_dom = ' ';
3779: }
1.57 raeburn 3780: }
3781: my %title = &Apache::lonlocal::texthash (
1.120 raeburn 3782: togglecats => 'Show/Hide a course in catalog',
3783: togglecatscomm => 'Show/Hide a community in catalog',
3784: categorize => 'Assign a category to a course',
3785: categorizecomm => 'Assign a category to a community',
1.57 raeburn 3786: );
3787: my %level = &Apache::lonlocal::texthash (
1.120 raeburn 3788: dom => 'Set in Domain',
3789: crs => 'Set in Course',
3790: comm => 'Set in Community',
1.57 raeburn 3791: );
3792: $datatable = '<tr class="LC_odd_row">'.
3793: '<td>'.$title{'togglecats'}.'</td>'.
3794: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3795: '<input type="radio" name="togglecats"'.
3796: $toggle_cats_dom.' value="dom" />'.$level{'dom'}.'</label> '.
3797: '<label><input type="radio" name="togglecats"'.
3798: $toggle_cats_crs.' value="crs" />'.$level{'crs'}.'</label></span></td>'.
3799: '</tr><tr>'.
3800: '<td>'.$title{'categorize'}.'</td>'.
3801: '<td class="LC_right_item"><span class="LC_nobreak">'.
3802: '<label><input type="radio" name="categorize"'.
3803: $can_cat_dom.' value="dom" />'.$level{'dom'}.'</label> '.
3804: '<label><input type="radio" name="categorize"'.
3805: $can_cat_crs.'value="crs" />'.$level{'crs'}.'</label></span></td>'.
1.120 raeburn 3806: '</tr><tr class="LC_odd_row">'.
3807: '<td>'.$title{'togglecatscomm'}.'</td>'.
3808: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3809: '<input type="radio" name="togglecatscomm"'.
3810: $toggle_catscomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
3811: '<label><input type="radio" name="togglecatscomm"'.
3812: $toggle_catscomm_comm.' value="comm" />'.$level{'comm'}.'</label></span></td>'.
3813: '</tr><tr>'.
3814: '<td>'.$title{'categorizecomm'}.'</td>'.
3815: '<td class="LC_right_item"><span class="LC_nobreak">'.
3816: '<label><input type="radio" name="categorizecomm"'.
3817: $can_catcomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
3818: '<label><input type="radio" name="categorizecomm"'.
3819: $can_catcomm_comm.'value="comm" />'.$level{'comm'}.'</label></span></td>'.
1.57 raeburn 3820: '</tr>';
1.120 raeburn 3821: $$rowtotal += 4;
1.57 raeburn 3822: } else {
3823: my $css_class;
3824: my $itemcount = 1;
3825: my $cathash;
3826: if (ref($settings) eq 'HASH') {
3827: $cathash = $settings->{'cats'};
3828: }
3829: if (ref($cathash) eq 'HASH') {
3830: my (@cats,@trails,%allitems,%idx,@jsarray);
3831: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
3832: \%allitems,\%idx,\@jsarray);
3833: my $maxdepth = scalar(@cats);
3834: my $colattrib = '';
3835: if ($maxdepth > 2) {
3836: $colattrib = ' colspan="2" ';
3837: }
3838: my @path;
3839: if (@cats > 0) {
3840: if (ref($cats[0]) eq 'ARRAY') {
3841: my $numtop = @{$cats[0]};
3842: my $maxnum = $numtop;
1.120 raeburn 3843: my %default_names = (
3844: instcode => &mt('Official courses'),
3845: communities => &mt('Communities'),
3846: );
3847:
3848: if ((!grep(/^instcode$/,@{$cats[0]})) ||
3849: ($cathash->{'instcode::0'} eq '') ||
3850: (!grep(/^communities$/,@{$cats[0]})) ||
3851: ($cathash->{'communities::0'} eq '')) {
1.57 raeburn 3852: $maxnum ++;
3853: }
3854: my $lastidx;
3855: for (my $i=0; $i<$numtop; $i++) {
3856: my $parent = $cats[0][$i];
3857: $css_class = $itemcount%2?' class="LC_odd_row"':'';
3858: my $item = &escape($parent).'::0';
3859: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$item','$idx{$item}'".');"';
3860: $lastidx = $idx{$item};
3861: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
3862: .'<select name="'.$item.'"'.$chgstr.'>';
3863: for (my $k=0; $k<=$maxnum; $k++) {
3864: my $vpos = $k+1;
3865: my $selstr;
3866: if ($k == $i) {
3867: $selstr = ' selected="selected" ';
3868: }
3869: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
3870: }
3871: $datatable .= '</select></td><td>';
1.120 raeburn 3872: if ($parent eq 'instcode' || $parent eq 'communities') {
3873: $datatable .= '<span class="LC_nobreak">'
3874: .$default_names{$parent}.'</span>';
3875: if ($parent eq 'instcode') {
3876: $datatable .= '<br /><span class="LC_nobreak">('
3877: .&mt('with institutional codes')
3878: .')</span></td><td'.$colattrib.'>';
3879: } else {
3880: $datatable .= '<table><tr><td>';
3881: }
3882: $datatable .= '<span class="LC_nobreak">'
3883: .'<label><input type="radio" name="'
3884: .$parent.'" value="1" checked="checked" />'
3885: .&mt('Display').'</label>';
3886: if ($parent eq 'instcode') {
3887: $datatable .= ' ';
3888: } else {
3889: $datatable .= '</span></td></tr><tr><td>'
3890: .'<span class="LC_nobreak">';
3891: }
3892: $datatable .= '<label><input type="radio" name="'
3893: .$parent.'" value="0" />'
3894: .&mt('Do not display').'</label></span>';
3895: if ($parent eq 'communities') {
3896: $datatable .= '</td></tr></table>';
3897: }
3898: $datatable .= '</td>';
1.57 raeburn 3899: } else {
3900: $datatable .= $parent
3901: .' <label><input type="checkbox" name="deletecategory" '
3902: .'value="'.$item.'" />'.&mt('Delete').'</label></span></td>';
3903: }
3904: my $depth = 1;
3905: push(@path,$parent);
3906: $datatable .= &build_category_rows($itemcount,\@cats,$depth,$parent,\@path,\%idx);
3907: pop(@path);
3908: $datatable .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
3909: $itemcount ++;
3910: }
1.48 raeburn 3911: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.57 raeburn 3912: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','$lastidx'".');"';
3913: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="addcategory_pos"'.$chgstr.'>';
1.48 raeburn 3914: for (my $k=0; $k<=$maxnum; $k++) {
3915: my $vpos = $k+1;
3916: my $selstr;
1.57 raeburn 3917: if ($k == $numtop) {
1.48 raeburn 3918: $selstr = ' selected="selected" ';
3919: }
3920: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
3921: }
1.59 bisitz 3922: $datatable .= '</select></span></td><td colspan="2">'.&mt('Add category:').' '
1.57 raeburn 3923: .'<input type="text" size="20" name="addcategory_name" value="" /></td>'
3924: .'</tr>'."\n";
1.48 raeburn 3925: $itemcount ++;
1.120 raeburn 3926: foreach my $default ('instcode','communities') {
3927: if ((!grep(/^\Q$default\E$/,@{$cats[0]})) || ($cathash->{$default.'::0'} eq '')) {
3928: $css_class = $itemcount%2?' class="LC_odd_row"':'';
3929: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','$lastidx'".');"';
3930: $datatable .= '<tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr><tr '.$css_class.'><td>'.
3931: '<span class="LC_nobreak"><select name="'.$default.'_pos"'.$chgstr.'>';
3932: for (my $k=0; $k<=$maxnum; $k++) {
3933: my $vpos = $k+1;
3934: my $selstr;
3935: if ($k == $maxnum) {
3936: $selstr = ' selected="selected" ';
3937: }
3938: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.57 raeburn 3939: }
1.120 raeburn 3940: $datatable .= '</select></span></td>'.
3941: '<td><span class="LC_nobreak">'.
3942: $default_names{$default}.'</span>';
3943: if ($default eq 'instcode') {
3944: $datatable .= '<br /><span class="LC_nobreak">('
3945: .&mt('with institutional codes').')</span>';
3946: }
3947: $datatable .= '</td>'
3948: .'<td><span class="LC_nobreak"><label><input type="radio" name="'.$default.'" value="1" />'
3949: .&mt('Display').'</label> '
3950: .'<label><input type="radio" name="'.$default.'" value="0" checked="checked"/>'
3951: .&mt('Do not display').'</label></span></td></tr>';
1.48 raeburn 3952: }
3953: }
3954: }
1.57 raeburn 3955: } else {
3956: $datatable .= &initialize_categories($itemcount);
1.48 raeburn 3957: }
3958: } else {
1.57 raeburn 3959: $datatable .= '<td class="LC_right_item">'.$hdritem->{'header'}->[0]->{'col2'}.'</td>'
3960: .&initialize_categories($itemcount);
1.48 raeburn 3961: }
1.57 raeburn 3962: $$rowtotal += $itemcount;
1.48 raeburn 3963: }
3964: return $datatable;
3965: }
3966:
1.69 raeburn 3967: sub print_serverstatuses {
3968: my ($dom,$settings,$rowtotal) = @_;
3969: my $datatable;
3970: my @pages = &serverstatus_pages();
3971: my (%namedaccess,%machineaccess);
3972: foreach my $type (@pages) {
3973: $namedaccess{$type} = '';
3974: $machineaccess{$type}= '';
3975: }
3976: if (ref($settings) eq 'HASH') {
3977: foreach my $type (@pages) {
3978: if (exists($settings->{$type})) {
3979: if (ref($settings->{$type}) eq 'HASH') {
3980: foreach my $key (keys(%{$settings->{$type}})) {
3981: if ($key eq 'namedusers') {
3982: $namedaccess{$type} = $settings->{$type}->{$key};
3983: } elsif ($key eq 'machines') {
3984: $machineaccess{$type} = $settings->{$type}->{$key};
3985: }
3986: }
3987: }
3988: }
3989: }
3990: }
1.81 raeburn 3991: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 3992: my $rownum = 0;
3993: my $css_class;
3994: foreach my $type (@pages) {
3995: $rownum ++;
3996: $css_class = $rownum%2?' class="LC_odd_row"':'';
3997: $datatable .= '<tr'.$css_class.'>'.
3998: '<td><span class="LC_nobreak">'.
3999: $titles->{$type}.'</span></td>'.
4000: '<td class="LC_left_item">'.
4001: '<input type="text" name="'.$type.'_namedusers" '.
4002: 'value="'.$namedaccess{$type}.'" size="30" /></td>'.
4003: '<td class="LC_right_item">'.
4004: '<span class="LC_nobreak">'.
4005: '<input type="text" name="'.$type.'_machines" '.
4006: 'value="'.$machineaccess{$type}.'" size="10" />'.
4007: '</td></tr>'."\n";
4008: }
4009: $$rowtotal += $rownum;
4010: return $datatable;
4011: }
4012:
4013: sub serverstatus_pages {
4014: return ('userstatus','lonstatus','loncron','server-status','codeversions',
4015: 'clusterstatus','metadata_keywords','metadata_harvest',
1.156 raeburn 4016: 'takeoffline','takeonline','showenv','toggledebug','ping','domconf');
1.69 raeburn 4017: }
4018:
1.49 raeburn 4019: sub coursecategories_javascript {
4020: my ($settings) = @_;
1.57 raeburn 4021: my ($output,$jstext,$cathash);
1.49 raeburn 4022: if (ref($settings) eq 'HASH') {
1.57 raeburn 4023: $cathash = $settings->{'cats'};
4024: }
4025: if (ref($cathash) eq 'HASH') {
1.49 raeburn 4026: my (@cats,@jsarray,%idx);
1.57 raeburn 4027: &Apache::loncommon::gather_categories($cathash,\@cats,\%idx,\@jsarray);
1.49 raeburn 4028: if (@jsarray > 0) {
4029: $jstext = ' var categories = Array('.scalar(@jsarray).');'."\n";
4030: for (my $i=0; $i<@jsarray; $i++) {
4031: if (ref($jsarray[$i]) eq 'ARRAY') {
4032: my $catstr = join('","',@{$jsarray[$i]});
4033: $jstext .= ' categories['.$i.'] = Array("'.$catstr.'");'."\n";
4034: }
4035: }
4036: }
4037: } else {
4038: $jstext = ' var categories = Array(1);'."\n".
4039: ' categories[0] = Array("instcode_pos");'."\n";
4040: }
1.120 raeburn 4041: my $instcode_reserved = &mt('The name: "instcode" is a reserved category');
4042: my $communities_reserved = &mt('The name: "communities" is a reserved category');
4043: my $choose_again = '\\n'.&mt('Please use a different name for the new top level category');
1.49 raeburn 4044: $output = <<"ENDSCRIPT";
4045: <script type="text/javascript">
1.109 raeburn 4046: // <![CDATA[
1.49 raeburn 4047: function reorderCats(form,parent,item,idx) {
4048: var changedVal;
4049: $jstext
4050: var newpos = 'addcategory_pos';
4051: var current = new Array;
4052: if (parent == '') {
4053: var has_instcode = 0;
4054: var maxtop = categories[idx].length;
4055: for (var j=0; j<maxtop; j++) {
4056: if (categories[idx][j] == 'instcode::0') {
4057: has_instcode == 1;
4058: }
4059: }
4060: if (has_instcode == 0) {
4061: categories[idx][maxtop] = 'instcode_pos';
4062: }
4063: } else {
4064: newpos += '_'+parent;
4065: }
4066: var maxh = 1 + categories[idx].length;
4067: var current = new Array;
4068: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
4069: if (item == newpos) {
4070: changedVal = newitemVal;
4071: } else {
4072: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
4073: current[newitemVal] = newpos;
4074: }
4075: for (var i=0; i<categories[idx].length; i++) {
4076: var elementName = categories[idx][i];
4077: if (elementName != item) {
4078: if (form.elements[elementName]) {
4079: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
4080: current[currVal] = elementName;
4081: }
4082: }
4083: }
4084: var oldVal;
4085: for (var j=0; j<maxh; j++) {
4086: if (current[j] == undefined) {
4087: oldVal = j;
4088: }
4089: }
4090: if (oldVal < changedVal) {
4091: for (var k=oldVal+1; k<=changedVal ; k++) {
4092: var elementName = current[k];
4093: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
4094: }
4095: } else {
4096: for (var k=changedVal; k<oldVal; k++) {
4097: var elementName = current[k];
4098: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
4099: }
4100: }
4101: return;
4102: }
1.120 raeburn 4103:
4104: function categoryCheck(form) {
4105: if (form.elements['addcategory_name'].value == 'instcode') {
4106: alert('$instcode_reserved\\n$choose_again');
4107: return false;
4108: }
4109: if (form.elements['addcategory_name'].value == 'communities') {
4110: alert('$communities_reserved\\n$choose_again');
4111: return false;
4112: }
4113: return true;
4114: }
4115:
1.109 raeburn 4116: // ]]>
1.49 raeburn 4117: </script>
4118:
4119: ENDSCRIPT
4120: return $output;
4121: }
4122:
1.48 raeburn 4123: sub initialize_categories {
4124: my ($itemcount) = @_;
1.120 raeburn 4125: my ($datatable,$css_class,$chgstr);
4126: my %default_names = (
4127: instcode => 'Official courses (with institutional codes)',
4128: communities => 'Communities',
4129: );
4130: my $select0 = ' selected="selected"';
4131: my $select1 = '';
4132: foreach my $default ('instcode','communities') {
4133: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4134: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'',$default"."_pos','0'".');"';
4135: if ($default eq 'communities') {
4136: $select1 = $select0;
4137: $select0 = '';
4138: }
4139: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
4140: .'<select name="'.$default.'_pos">'
4141: .'<option value="0"'.$select0.'>1</option>'
4142: .'<option value="1"'.$select1.'>2</option>'
4143: .'<option value="2">3</option></select> '
4144: .$default_names{$default}
4145: .'</span></td><td><span class="LC_nobreak">'
4146: .'<label><input type="radio" name="'.$default.'" value="1" checked="checked" />'
4147: .&mt('Display').'</label> <label>'
4148: .'<input type="radio" name="'.$default.'" value="0" />'.&mt('Do not display')
1.48 raeburn 4149: .'</label></span></td></tr>';
1.120 raeburn 4150: $itemcount ++;
4151: }
1.48 raeburn 4152: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.49 raeburn 4153: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','0'".');"';
1.48 raeburn 4154: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.120 raeburn 4155: .'<select name="addcategory_pos"'.$chgstr.'>'
4156: .'<option value="0">1</option>'
4157: .'<option value="1">2</option>'
4158: .'<option value="2" selected="selected">3</option></select> '
1.48 raeburn 4159: .&mt('Add category').'</td><td>'.&mt('Name:')
4160: .' <input type="text" size="20" name="addcategory_name" value="" /></td></tr>';
4161: return $datatable;
4162: }
4163:
4164: sub build_category_rows {
1.49 raeburn 4165: my ($itemcount,$cats,$depth,$parent,$path,$idx) = @_;
4166: my ($text,$name,$item,$chgstr);
1.48 raeburn 4167: if (ref($cats) eq 'ARRAY') {
4168: my $maxdepth = scalar(@{$cats});
4169: if (ref($cats->[$depth]) eq 'HASH') {
4170: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
4171: my $numchildren = @{$cats->[$depth]{$parent}};
4172: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
4173: $text .= '<td><table class="LC_datatable">';
1.49 raeburn 4174: my ($idxnum,$parent_name,$parent_item);
4175: my $higher = $depth - 1;
4176: if ($higher == 0) {
4177: $parent_name = &escape($parent).'::'.$higher;
4178: } else {
4179: if (ref($path) eq 'ARRAY') {
4180: $parent_name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
4181: }
4182: }
4183: $parent_item = 'addcategory_pos_'.$parent_name;
1.48 raeburn 4184: for (my $j=0; $j<=$numchildren; $j++) {
1.49 raeburn 4185: if ($j < $numchildren) {
1.48 raeburn 4186: $name = $cats->[$depth]{$parent}[$j];
4187: $item = &escape($name).':'.&escape($parent).':'.$depth;
1.49 raeburn 4188: $idxnum = $idx->{$item};
4189: } else {
4190: $name = $parent_name;
4191: $item = $parent_item;
1.48 raeburn 4192: }
1.49 raeburn 4193: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'$parent_name','$item','$idxnum'".');"';
4194: $text .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="'.$item.'"'.$chgstr.'>';
1.48 raeburn 4195: for (my $i=0; $i<=$numchildren; $i++) {
4196: my $vpos = $i+1;
4197: my $selstr;
4198: if ($j == $i) {
4199: $selstr = ' selected="selected" ';
4200: }
4201: $text .= '<option value="'.$i.'"'.$selstr.'>'.$vpos.'</option>';
4202: }
4203: $text .= '</select> ';
4204: if ($j < $numchildren) {
4205: my $deeper = $depth+1;
4206: $text .= $name.' '
4207: .'<label><input type="checkbox" name="deletecategory" value="'
4208: .$item.'" />'.&mt('Delete').'</label></span></td><td>';
4209: if(ref($path) eq 'ARRAY') {
4210: push(@{$path},$name);
1.49 raeburn 4211: $text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path,$idx);
1.48 raeburn 4212: pop(@{$path});
4213: }
4214: } else {
1.59 bisitz 4215: $text .= &mt('Add subcategory:').' </span><input type="textbox" size="20" name="addcategory_name_';
1.48 raeburn 4216: if ($j == $numchildren) {
4217: $text .= $name;
4218: } else {
4219: $text .= $item;
4220: }
4221: $text .= '" value="" />';
4222: }
4223: $text .= '</td></tr>';
4224: }
4225: $text .= '</table></td>';
4226: } else {
4227: my $higher = $depth-1;
4228: if ($higher == 0) {
4229: $name = &escape($parent).'::'.$higher;
4230: } else {
4231: if (ref($path) eq 'ARRAY') {
4232: $name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
4233: }
4234: }
4235: my $colspan;
4236: if ($parent ne 'instcode') {
4237: $colspan = $maxdepth - $depth - 1;
4238: $text .= '<td colspan="'.$colspan.'">'.&mt('Add subcategory:').'<input type="textbox" size="20" name="subcat_'.$name.'" value="" /></td>';
4239: }
4240: }
4241: }
4242: }
4243: return $text;
4244: }
4245:
1.33 raeburn 4246: sub modifiable_userdata_row {
1.63 raeburn 4247: my ($context,$role,$settings,$numinrow,$rowcount,$usertypes) = @_;
1.33 raeburn 4248: my $rolename;
1.63 raeburn 4249: if ($context eq 'selfcreate') {
4250: if (ref($usertypes) eq 'HASH') {
4251: $rolename = $usertypes->{$role};
4252: } else {
4253: $rolename = $role;
4254: }
1.33 raeburn 4255: } else {
1.63 raeburn 4256: if ($role eq 'cr') {
4257: $rolename = &mt('Custom role');
4258: } else {
4259: $rolename = &Apache::lonnet::plaintext($role);
4260: }
1.33 raeburn 4261: }
4262: my @fields = ('lastname','firstname','middlename','generation',
4263: 'permanentemail','id');
4264: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
4265: my $output;
4266: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
4267: $output = '<tr '.$css_class.'>'.
4268: '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
4269: '<td class="LC_left_item" colspan="2"><table>';
4270: my $rem;
4271: my %checks;
4272: if (ref($settings) eq 'HASH') {
4273: if (ref($settings->{$context}) eq 'HASH') {
4274: if (ref($settings->{$context}->{$role}) eq 'HASH') {
4275: foreach my $field (@fields) {
4276: if ($settings->{$context}->{$role}->{$field}) {
4277: $checks{$field} = ' checked="checked" ';
4278: }
4279: }
4280: }
4281: }
4282: }
4283: for (my $i=0; $i<@fields; $i++) {
4284: my $rem = $i%($numinrow);
4285: if ($rem == 0) {
4286: if ($i > 0) {
4287: $output .= '</tr>';
4288: }
4289: $output .= '<tr>';
4290: }
4291: my $check = ' ';
4292: if (exists($checks{$fields[$i]})) {
4293: $check = $checks{$fields[$i]}
4294: } else {
4295: if ($role eq 'st') {
4296: if (ref($settings) ne 'HASH') {
4297: $check = ' checked="checked" ';
4298: }
4299: }
4300: }
4301: $output .= '<td class="LC_left_item">'.
4302: '<span class="LC_nobreak"><label>'.
4303: '<input type="checkbox" name="canmodify_'.$role.'" '.
4304: 'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
4305: '</label></span></td>';
4306: $rem = @fields%($numinrow);
4307: }
4308: my $colsleft = $numinrow - $rem;
4309: if ($colsleft > 1 ) {
4310: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
4311: ' </td>';
4312: } elsif ($colsleft == 1) {
4313: $output .= '<td class="LC_left_item"> </td>';
4314: }
4315: $output .= '</tr></table></td></tr>';
4316: return $output;
4317: }
1.28 raeburn 4318:
1.93 raeburn 4319: sub insttypes_row {
4320: my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle,$context) = @_;
4321: my %lt = &Apache::lonlocal::texthash (
4322: cansearch => 'Users allowed to search',
4323: statustocreate => 'Institutional affiliation(s) able to create own account (login/SSO)',
1.131 raeburn 4324: lockablenames => 'User preference to lock name',
1.93 raeburn 4325: );
4326: my $showdom;
4327: if ($context eq 'cansearch') {
4328: $showdom = ' ('.$dom.')';
4329: }
1.165 raeburn 4330: my $class = 'LC_left_item';
4331: if ($context eq 'statustocreate') {
4332: $class = 'LC_right_item';
4333: }
1.25 raeburn 4334: my $output = '<tr class="LC_odd_row">'.
1.93 raeburn 4335: '<td>'.$lt{$context}.$showdom.
1.165 raeburn 4336: '</td><td class="'.$class.'" colspan="2"><table>';
1.26 raeburn 4337: my $rem;
4338: if (ref($types) eq 'ARRAY') {
4339: for (my $i=0; $i<@{$types}; $i++) {
4340: if (defined($usertypes->{$types->[$i]})) {
4341: my $rem = $i%($numinrow);
4342: if ($rem == 0) {
4343: if ($i > 0) {
4344: $output .= '</tr>';
4345: }
4346: $output .= '<tr>';
1.23 raeburn 4347: }
1.26 raeburn 4348: my $check = ' ';
1.99 raeburn 4349: if (ref($settings) eq 'HASH') {
4350: if (ref($settings->{$context}) eq 'ARRAY') {
4351: if (grep(/^\Q$types->[$i]\E$/,@{$settings->{$context}})) {
4352: $check = ' checked="checked" ';
4353: }
4354: } elsif ($context eq 'statustocreate') {
1.26 raeburn 4355: $check = ' checked="checked" ';
4356: }
1.23 raeburn 4357: }
1.26 raeburn 4358: $output .= '<td class="LC_left_item">'.
4359: '<span class="LC_nobreak"><label>'.
1.93 raeburn 4360: '<input type="checkbox" name="'.$context.'" '.
1.26 raeburn 4361: 'value="'.$types->[$i].'"'.$check.'/>'.
4362: $usertypes->{$types->[$i]}.'</label></span></td>';
1.23 raeburn 4363: }
4364: }
1.26 raeburn 4365: $rem = @{$types}%($numinrow);
1.23 raeburn 4366: }
4367: my $colsleft = $numinrow - $rem;
1.131 raeburn 4368: if (($rem == 0) && (@{$types} > 0)) {
4369: $output .= '<tr>';
4370: }
1.23 raeburn 4371: if ($colsleft > 1) {
1.25 raeburn 4372: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
1.23 raeburn 4373: } else {
1.25 raeburn 4374: $output .= '<td class="LC_left_item">';
1.23 raeburn 4375: }
4376: my $defcheck = ' ';
1.99 raeburn 4377: if (ref($settings) eq 'HASH') {
4378: if (ref($settings->{$context}) eq 'ARRAY') {
4379: if (grep(/^default$/,@{$settings->{$context}})) {
4380: $defcheck = ' checked="checked" ';
4381: }
4382: } elsif ($context eq 'statustocreate') {
1.26 raeburn 4383: $defcheck = ' checked="checked" ';
4384: }
1.23 raeburn 4385: }
1.25 raeburn 4386: $output .= '<span class="LC_nobreak"><label>'.
1.93 raeburn 4387: '<input type="checkbox" name="'.$context.'" '.
1.25 raeburn 4388: 'value="default"'.$defcheck.'/>'.
4389: $othertitle.'</label></span></td>'.
4390: '</tr></table></td></tr>';
4391: return $output;
1.23 raeburn 4392: }
4393:
4394: sub sorted_searchtitles {
4395: my %searchtitles = &Apache::lonlocal::texthash(
4396: 'uname' => 'username',
4397: 'lastname' => 'last name',
4398: 'lastfirst' => 'last name, first name',
4399: );
4400: my @titleorder = ('uname','lastname','lastfirst');
4401: return (\%searchtitles,\@titleorder);
4402: }
4403:
1.25 raeburn 4404: sub sorted_searchtypes {
4405: my %srchtypes_desc = (
4406: exact => 'is exact match',
4407: contains => 'contains ..',
4408: begins => 'begins with ..',
4409: );
4410: my @srchtypeorder = ('exact','begins','contains');
4411: return (\%srchtypes_desc,\@srchtypeorder);
4412: }
4413:
1.3 raeburn 4414: sub usertype_update_row {
4415: my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
4416: my $datatable;
4417: my $numinrow = 4;
4418: foreach my $type (@{$types}) {
4419: if (defined($usertypes->{$type})) {
4420: $$rownums ++;
4421: my $css_class = $$rownums%2?' class="LC_odd_row"':'';
4422: $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
4423: '</td><td class="LC_left_item"><table>';
4424: for (my $i=0; $i<@{$fields}; $i++) {
4425: my $rem = $i%($numinrow);
4426: if ($rem == 0) {
4427: if ($i > 0) {
4428: $datatable .= '</tr>';
4429: }
4430: $datatable .= '<tr>';
4431: }
4432: my $check = ' ';
1.39 raeburn 4433: if (ref($settings) eq 'HASH') {
4434: if (ref($settings->{'fields'}) eq 'HASH') {
4435: if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
4436: if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
4437: $check = ' checked="checked" ';
4438: }
1.3 raeburn 4439: }
4440: }
4441: }
4442:
4443: if ($i == @{$fields}-1) {
4444: my $colsleft = $numinrow - $rem;
4445: if ($colsleft > 1) {
4446: $datatable .= '<td colspan="'.$colsleft.'">';
4447: } else {
4448: $datatable .= '<td>';
4449: }
4450: } else {
4451: $datatable .= '<td>';
4452: }
1.8 raeburn 4453: $datatable .= '<span class="LC_nobreak"><label>'.
4454: '<input type="checkbox" name="updateable_'.$type.
4455: '_'.$fields->[$i].'" value="1"'.$check.'/>'.
4456: $fieldtitles->{$fields->[$i]}.'</label></span></td>';
1.3 raeburn 4457: }
4458: $datatable .= '</tr></table></td></tr>';
4459: }
4460: }
4461: return $datatable;
1.1 raeburn 4462: }
4463:
4464: sub modify_login {
1.9 raeburn 4465: my ($r,$dom,$confname,%domconfig) = @_;
1.6 raeburn 4466: my ($resulttext,$errors,$colchgtext,%changes,%colchanges);
1.1 raeburn 4467: my %title = ( coursecatalog => 'Display course catalog',
1.41 raeburn 4468: adminmail => 'Display administrator E-mail address',
1.43 raeburn 4469: newuser => 'Link for visitors to create a user account',
1.41 raeburn 4470: loginheader => 'Log-in box header');
1.3 raeburn 4471: my @offon = ('off','on');
1.112 raeburn 4472: my %curr_loginvia;
4473: if (ref($domconfig{login}) eq 'HASH') {
4474: if (ref($domconfig{login}{loginvia}) eq 'HASH') {
4475: foreach my $lonhost (keys(%{$domconfig{login}{loginvia}})) {
4476: $curr_loginvia{$lonhost} = $domconfig{login}{loginvia}{$lonhost};
4477: }
4478: }
4479: }
1.6 raeburn 4480: my %loginhash;
1.9 raeburn 4481: ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
4482: \%domconfig,\%loginhash);
1.118 jms 4483: my @toggles = ('coursecatalog','adminmail','newuser');
1.42 raeburn 4484: foreach my $item (@toggles) {
4485: $loginhash{login}{$item} = $env{'form.'.$item};
4486: }
1.41 raeburn 4487: $loginhash{login}{loginheader} = $env{'form.loginheader'};
1.6 raeburn 4488: if (ref($colchanges{'login'}) eq 'HASH') {
4489: $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
4490: \%loginhash);
4491: }
1.110 raeburn 4492:
1.149 raeburn 4493: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.128 raeburn 4494: my @loginvia_attribs = ('serverpath','custompath','exempt');
1.110 raeburn 4495: if (keys(%servers) > 1) {
4496: foreach my $lonhost (keys(%servers)) {
1.128 raeburn 4497: next if ($env{'form.'.$lonhost.'_server'} eq $lonhost);
4498: if (ref($curr_loginvia{$lonhost}) eq 'HASH') {
4499: if ($env{'form.'.$lonhost.'_server'} eq $curr_loginvia{$lonhost}{'server'}) {
4500: $loginhash{login}{loginvia}{$lonhost}{'server'} = $curr_loginvia{$lonhost}{'server'};
4501: } elsif ($curr_loginvia{$lonhost}{'server'} ne '') {
4502: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
4503: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
4504: $changes{'loginvia'}{$lonhost} = 1;
4505: } else {
4506: $loginhash{login}{loginvia}{$lonhost}{'server'} = '';
4507: $changes{'loginvia'}{$lonhost} = 1;
4508: }
4509: } else {
4510: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
4511: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
4512: $changes{'loginvia'}{$lonhost} = 1;
4513: }
4514: }
4515: if ($loginhash{login}{loginvia}{$lonhost}{'server'} eq '') {
4516: foreach my $item (@loginvia_attribs) {
4517: $loginhash{login}{loginvia}{$lonhost}{$item} = '';
4518: }
4519: } else {
4520: foreach my $item (@loginvia_attribs) {
4521: my $new = $env{'form.'.$lonhost.'_'.$item};
4522: if (($item eq 'serverpath') && ($new eq 'custom')) {
4523: $env{'form.'.$lonhost.'_custompath'} =~ s/\s+//g;
4524: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
4525: $new = '/';
4526: }
4527: }
4528: if (($item eq 'custompath') &&
4529: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
4530: $new = '';
4531: }
4532: if ($new ne $curr_loginvia{$lonhost}{$item}) {
4533: $changes{'loginvia'}{$lonhost} = 1;
4534: }
4535: if ($item eq 'exempt') {
4536: $new =~ s/^\s+//;
4537: $new =~ s/\s+$//;
4538: my @poss_ips = split(/\s*[,:]\s*/,$new);
4539: my @okips;
4540: foreach my $ip (@poss_ips) {
4541: if ($ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
4542: if (($1 <= 255) && ($2 <= 255) && ($3 <= 255) && ($4 <= 255)) {
4543: push(@okips,$ip);
4544: }
4545: }
4546: }
4547: if (@okips > 0) {
4548: $new = join(',',@okips);
4549: } else {
4550: $new = '';
4551: }
4552: }
4553:
4554: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
4555: }
4556: }
1.112 raeburn 4557: } else {
1.128 raeburn 4558: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
4559: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
1.112 raeburn 4560: $changes{'loginvia'}{$lonhost} = 1;
1.128 raeburn 4561: foreach my $item (@loginvia_attribs) {
4562: my $new = $env{'form.'.$lonhost.'_'.$item};
4563: if (($item eq 'serverpath') && ($new eq 'custom')) {
4564: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
4565: $new = '/';
4566: }
4567: }
4568: if (($item eq 'custompath') &&
4569: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
4570: $new = '';
4571: }
4572: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
4573: }
1.110 raeburn 4574: }
4575: }
4576: }
4577: }
1.119 raeburn 4578:
1.1 raeburn 4579: my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
4580: $dom);
4581: if ($putresult eq 'ok') {
1.118 jms 4582: my @toggles = ('coursecatalog','adminmail','newuser');
1.42 raeburn 4583: my %defaultchecked = (
4584: 'coursecatalog' => 'on',
4585: 'adminmail' => 'off',
1.43 raeburn 4586: 'newuser' => 'off',
1.42 raeburn 4587: );
1.55 raeburn 4588: if (ref($domconfig{'login'}) eq 'HASH') {
4589: foreach my $item (@toggles) {
4590: if ($defaultchecked{$item} eq 'on') {
4591: if (($domconfig{'login'}{$item} eq '0') &&
4592: ($env{'form.'.$item} eq '1')) {
4593: $changes{$item} = 1;
4594: } elsif (($domconfig{'login'}{$item} eq '' ||
4595: $domconfig{'login'}{$item} eq '1') &&
4596: ($env{'form.'.$item} eq '0')) {
4597: $changes{$item} = 1;
4598: }
4599: } elsif ($defaultchecked{$item} eq 'off') {
4600: if (($domconfig{'login'}{$item} eq '1') &&
4601: ($env{'form.'.$item} eq '0')) {
4602: $changes{$item} = 1;
4603: } elsif (($domconfig{'login'}{$item} eq '' ||
4604: $domconfig{'login'}{$item} eq '0') &&
4605: ($env{'form.'.$item} eq '1')) {
4606: $changes{$item} = 1;
4607: }
1.42 raeburn 4608: }
4609: }
1.41 raeburn 4610: }
1.6 raeburn 4611: if (keys(%changes) > 0 || $colchgtext) {
1.41 raeburn 4612: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.1 raeburn 4613: $resulttext = &mt('Changes made:').'<ul>';
4614: foreach my $item (sort(keys(%changes))) {
1.135 bisitz 4615: if ($item eq 'loginvia') {
1.112 raeburn 4616: if (ref($changes{$item}) eq 'HASH') {
4617: $resulttext .= '<li>'.&mt('Log-in page availability:').'<ul>';
4618: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
1.128 raeburn 4619: if (defined($servers{$loginhash{login}{loginvia}{$lonhost}{'server'}})) {
4620: if (ref($loginhash{login}{loginvia}{$lonhost}) eq 'HASH') {
4621: my $protocol = $Apache::lonnet::protocol{$env{'form.'.$lonhost.'_server'}};
4622: $protocol = 'http' if ($protocol ne 'https');
4623: my $target = $protocol.'://'.$servers{$env{'form.'.$lonhost.'_server'}};
4624:
4625: if ($loginhash{login}{loginvia}{$lonhost}{'serverpath'} eq 'custom') {
4626: $target .= $loginhash{login}{loginvia}{$lonhost}{'custompath'};
4627: } else {
4628: $target .= $loginhash{login}{loginvia}{$lonhost}{'serverpath'};
4629: }
4630: $resulttext .= '<li>'.&mt('Server: [_1] log-in page redirects to [_2].',$servers{$lonhost},'<a href="'.$target.'">'.$target.'</a>');
4631: if ($loginhash{login}{loginvia}{$lonhost}{'exempt'} ne '') {
4632: $resulttext .= ' '.&mt('No redirection for clients from following IPs:').' '.$loginhash{login}{loginvia}{$lonhost}{'exempt'};
4633: }
4634: $resulttext .= '</li>';
4635: } else {
4636: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$lonhost).'</li>';
4637: }
1.112 raeburn 4638: } else {
1.128 raeburn 4639: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$servers{$lonhost}).'</li>';
1.112 raeburn 4640: }
4641: }
1.128 raeburn 4642: $resulttext .= '</ul></li>';
1.112 raeburn 4643: }
1.41 raeburn 4644: } else {
4645: $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
4646: }
1.1 raeburn 4647: }
1.6 raeburn 4648: $resulttext .= $colchgtext.'</ul>';
1.1 raeburn 4649: } else {
4650: $resulttext = &mt('No changes made to log-in page settings');
4651: }
4652: } else {
1.11 albertel 4653: $resulttext = '<span class="LC_error">'.
4654: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 4655: }
1.6 raeburn 4656: if ($errors) {
1.9 raeburn 4657: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.6 raeburn 4658: $errors.'</ul>';
4659: }
4660: return $resulttext;
4661: }
4662:
4663: sub color_font_choices {
4664: my %choices =
4665: &Apache::lonlocal::texthash (
4666: img => "Header",
4667: bgs => "Background colors",
4668: links => "Link colors",
1.55 raeburn 4669: images => "Images",
1.6 raeburn 4670: font => "Font color",
1.97 tempelho 4671: fontmenu => "Font Menu",
1.76 raeburn 4672: pgbg => "Page",
1.6 raeburn 4673: tabbg => "Header",
4674: sidebg => "Border",
4675: link => "Link",
4676: alink => "Active link",
4677: vlink => "Visited link",
4678: );
4679: return %choices;
4680: }
4681:
4682: sub modify_rolecolors {
1.9 raeburn 4683: my ($r,$dom,$confname,$roles,%domconfig) = @_;
1.6 raeburn 4684: my ($resulttext,%rolehash);
4685: $rolehash{'rolecolors'} = {};
1.55 raeburn 4686: if (ref($domconfig{'rolecolors'}) ne 'HASH') {
4687: if ($domconfig{'rolecolors'} eq '') {
4688: $domconfig{'rolecolors'} = {};
4689: }
4690: }
1.9 raeburn 4691: my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
1.6 raeburn 4692: $domconfig{'rolecolors'},$rolehash{'rolecolors'});
4693: my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
4694: $dom);
4695: if ($putresult eq 'ok') {
4696: if (keys(%changes) > 0) {
1.41 raeburn 4697: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.6 raeburn 4698: $resulttext = &display_colorchgs($dom,\%changes,$roles,
4699: $rolehash{'rolecolors'});
4700: } else {
4701: $resulttext = &mt('No changes made to default color schemes');
4702: }
4703: } else {
1.11 albertel 4704: $resulttext = '<span class="LC_error">'.
4705: &mt('An error occurred: [_1]',$putresult).'</span>';
1.6 raeburn 4706: }
4707: if ($errors) {
4708: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
4709: $errors.'</ul>';
4710: }
4711: return $resulttext;
4712: }
4713:
4714: sub modify_colors {
1.9 raeburn 4715: my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
1.12 raeburn 4716: my (%changes,%choices);
1.51 raeburn 4717: my @bgs;
1.6 raeburn 4718: my @links = ('link','alink','vlink');
1.41 raeburn 4719: my @logintext;
1.6 raeburn 4720: my @images;
4721: my $servadm = $r->dir_config('lonAdmEMail');
4722: my $errors;
4723: foreach my $role (@{$roles}) {
4724: if ($role eq 'login') {
1.12 raeburn 4725: %choices = &login_choices();
1.41 raeburn 4726: @logintext = ('textcol','bgcol');
1.12 raeburn 4727: } else {
4728: %choices = &color_font_choices();
1.107 raeburn 4729: $confhash->{$role}{'fontmenu'} = $env{'form.'.$role.'_fontmenu'};
1.12 raeburn 4730: }
4731: if ($role eq 'login') {
1.41 raeburn 4732: @images = ('img','logo','domlogo','login');
1.51 raeburn 4733: @bgs = ('pgbg','mainbg','sidebg');
1.6 raeburn 4734: } else {
4735: @images = ('img');
1.51 raeburn 4736: @bgs = ('pgbg','tabbg','sidebg');
1.6 raeburn 4737: }
4738: $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
1.41 raeburn 4739: foreach my $item (@bgs,@links,@logintext) {
1.6 raeburn 4740: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
4741: }
1.46 raeburn 4742: my ($configuserok,$author_ok,$switchserver) =
4743: &config_check($dom,$confname,$servadm);
1.9 raeburn 4744: my ($width,$height) = &thumb_dimensions();
1.40 raeburn 4745: if (ref($domconfig->{$role}) ne 'HASH') {
4746: $domconfig->{$role} = {};
4747: }
1.8 raeburn 4748: foreach my $img (@images) {
1.70 raeburn 4749: if (($role eq 'login') && (($img eq 'img') || ($img eq 'logo'))) {
4750: if (defined($env{'form.login_showlogo_'.$img})) {
4751: $confhash->{$role}{'showlogo'}{$img} = 1;
4752: } else {
4753: $confhash->{$role}{'showlogo'}{$img} = 0;
4754: }
4755: }
1.18 albertel 4756: if ( ! $env{'form.'.$role.'_'.$img.'.filename'}
4757: && !defined($domconfig->{$role}{$img})
4758: && !$env{'form.'.$role.'_del_'.$img}
4759: && $env{'form.'.$role.'_import_'.$img}) {
4760: # import the old configured image from the .tab setting
4761: # if they haven't provided a new one
4762: $domconfig->{$role}{$img} =
4763: $env{'form.'.$role.'_import_'.$img};
4764: }
1.6 raeburn 4765: if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
1.9 raeburn 4766: my $error;
1.6 raeburn 4767: if ($configuserok eq 'ok') {
1.9 raeburn 4768: if ($switchserver) {
1.12 raeburn 4769: $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
1.9 raeburn 4770: } else {
4771: if ($author_ok eq 'ok') {
4772: my ($result,$logourl) =
4773: &publishlogo($r,'upload',$role.'_'.$img,
4774: $dom,$confname,$img,$width,$height);
4775: if ($result eq 'ok') {
4776: $confhash->{$role}{$img} = $logourl;
1.12 raeburn 4777: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 4778: } else {
1.12 raeburn 4779: $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 4780: }
4781: } else {
1.46 raeburn 4782: $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 4783: }
4784: }
4785: } else {
1.46 raeburn 4786: $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 4787: }
4788: if ($error) {
1.8 raeburn 4789: &Apache::lonnet::logthis($error);
1.11 albertel 4790: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
1.8 raeburn 4791: }
4792: } elsif ($domconfig->{$role}{$img} ne '') {
1.9 raeburn 4793: if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
4794: my $error;
4795: if ($configuserok eq 'ok') {
4796: # is confname an author?
4797: if ($switchserver eq '') {
4798: if ($author_ok eq 'ok') {
4799: my ($result,$logourl) =
4800: &publishlogo($r,'copy',$domconfig->{$role}{$img},
4801: $dom,$confname,$img,$width,$height);
4802: if ($result eq 'ok') {
4803: $confhash->{$role}{$img} = $logourl;
1.18 albertel 4804: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 4805: }
4806: }
4807: }
4808: }
1.6 raeburn 4809: }
4810: }
4811: }
4812: if (ref($domconfig) eq 'HASH') {
4813: if (ref($domconfig->{$role}) eq 'HASH') {
4814: foreach my $img (@images) {
4815: if ($domconfig->{$role}{$img} ne '') {
4816: if ($env{'form.'.$role.'_del_'.$img}) {
4817: $confhash->{$role}{$img} = '';
1.12 raeburn 4818: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 4819: } else {
1.9 raeburn 4820: if ($confhash->{$role}{$img} eq '') {
4821: $confhash->{$role}{$img} = $domconfig->{$role}{$img};
4822: }
1.6 raeburn 4823: }
4824: } else {
4825: if ($env{'form.'.$role.'_del_'.$img}) {
4826: $confhash->{$role}{$img} = '';
1.12 raeburn 4827: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 4828: }
4829: }
1.70 raeburn 4830: if (($role eq 'login') && (($img eq 'logo') || ($img eq 'img'))) {
4831: if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') {
4832: if ($confhash->{$role}{'showlogo'}{$img} ne
4833: $domconfig->{$role}{'showlogo'}{$img}) {
4834: $changes{$role}{'showlogo'}{$img} = 1;
4835: }
4836: } else {
4837: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
4838: $changes{$role}{'showlogo'}{$img} = 1;
4839: }
4840: }
4841: }
4842: }
1.6 raeburn 4843: if ($domconfig->{$role}{'font'} ne '') {
4844: if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
4845: $changes{$role}{'font'} = 1;
4846: }
4847: } else {
4848: if ($confhash->{$role}{'font'}) {
4849: $changes{$role}{'font'} = 1;
4850: }
4851: }
1.107 raeburn 4852: if ($role ne 'login') {
4853: if ($domconfig->{$role}{'fontmenu'} ne '') {
4854: if ($confhash->{$role}{'fontmenu'} ne $domconfig->{$role}{'fontmenu'}) {
4855: $changes{$role}{'fontmenu'} = 1;
4856: }
4857: } else {
4858: if ($confhash->{$role}{'fontmenu'}) {
4859: $changes{$role}{'fontmenu'} = 1;
4860: }
1.97 tempelho 4861: }
4862: }
1.6 raeburn 4863: foreach my $item (@bgs) {
4864: if ($domconfig->{$role}{$item} ne '') {
4865: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
4866: $changes{$role}{'bgs'}{$item} = 1;
4867: }
4868: } else {
4869: if ($confhash->{$role}{$item}) {
4870: $changes{$role}{'bgs'}{$item} = 1;
4871: }
4872: }
4873: }
4874: foreach my $item (@links) {
4875: if ($domconfig->{$role}{$item} ne '') {
4876: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
4877: $changes{$role}{'links'}{$item} = 1;
4878: }
4879: } else {
4880: if ($confhash->{$role}{$item}) {
4881: $changes{$role}{'links'}{$item} = 1;
4882: }
4883: }
4884: }
1.41 raeburn 4885: foreach my $item (@logintext) {
4886: if ($domconfig->{$role}{$item} ne '') {
4887: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
4888: $changes{$role}{'logintext'}{$item} = 1;
4889: }
4890: } else {
4891: if ($confhash->{$role}{$item}) {
4892: $changes{$role}{'logintext'}{$item} = 1;
4893: }
4894: }
4895: }
1.6 raeburn 4896: } else {
4897: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 4898: \@logintext,$confhash,\%changes);
1.6 raeburn 4899: }
4900: } else {
4901: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 4902: \@logintext,$confhash,\%changes);
1.6 raeburn 4903: }
4904: }
4905: return ($errors,%changes);
4906: }
4907:
1.46 raeburn 4908: sub config_check {
4909: my ($dom,$confname,$servadm) = @_;
4910: my ($configuserok,$author_ok,$switchserver,%currroles);
4911: my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
4912: ($configuserok,%currroles) = &check_configuser($uhome,$dom,
4913: $confname,$servadm);
4914: if ($configuserok eq 'ok') {
4915: $switchserver = &check_switchserver($dom,$confname);
4916: if ($switchserver eq '') {
4917: $author_ok = &check_authorstatus($dom,$confname,%currroles);
4918: }
4919: }
4920: return ($configuserok,$author_ok,$switchserver);
4921: }
4922:
1.6 raeburn 4923: sub default_change_checker {
1.41 raeburn 4924: my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
1.6 raeburn 4925: foreach my $item (@{$links}) {
4926: if ($confhash->{$role}{$item}) {
4927: $changes->{$role}{'links'}{$item} = 1;
4928: }
4929: }
4930: foreach my $item (@{$bgs}) {
4931: if ($confhash->{$role}{$item}) {
4932: $changes->{$role}{'bgs'}{$item} = 1;
4933: }
4934: }
1.41 raeburn 4935: foreach my $item (@{$logintext}) {
4936: if ($confhash->{$role}{$item}) {
4937: $changes->{$role}{'logintext'}{$item} = 1;
4938: }
4939: }
1.6 raeburn 4940: foreach my $img (@{$images}) {
4941: if ($env{'form.'.$role.'_del_'.$img}) {
4942: $confhash->{$role}{$img} = '';
1.12 raeburn 4943: $changes->{$role}{'images'}{$img} = 1;
1.6 raeburn 4944: }
1.70 raeburn 4945: if ($role eq 'login') {
4946: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
4947: $changes->{$role}{'showlogo'}{$img} = 1;
4948: }
4949: }
1.6 raeburn 4950: }
4951: if ($confhash->{$role}{'font'}) {
4952: $changes->{$role}{'font'} = 1;
4953: }
1.48 raeburn 4954: }
1.6 raeburn 4955:
4956: sub display_colorchgs {
4957: my ($dom,$changes,$roles,$confhash) = @_;
4958: my (%choices,$resulttext);
4959: if (!grep(/^login$/,@{$roles})) {
4960: $resulttext = &mt('Changes made:').'<br />';
4961: }
4962: foreach my $role (@{$roles}) {
4963: if ($role eq 'login') {
4964: %choices = &login_choices();
4965: } else {
4966: %choices = &color_font_choices();
4967: }
4968: if (ref($changes->{$role}) eq 'HASH') {
4969: if ($role ne 'login') {
4970: $resulttext .= '<h4>'.&mt($role).'</h4>';
4971: }
4972: foreach my $key (sort(keys(%{$changes->{$role}}))) {
4973: if ($role ne 'login') {
4974: $resulttext .= '<ul>';
4975: }
4976: if (ref($changes->{$role}{$key}) eq 'HASH') {
4977: if ($role ne 'login') {
4978: $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
4979: }
4980: foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
1.70 raeburn 4981: if (($role eq 'login') && ($key eq 'showlogo')) {
4982: if ($confhash->{$role}{$key}{$item}) {
4983: $resulttext .= '<li>'.&mt("$choices{$item} set to be displayed").'</li>';
4984: } else {
4985: $resulttext .= '<li>'.&mt("$choices{$item} set to not be displayed").'</li>';
4986: }
4987: } elsif ($confhash->{$role}{$item} eq '') {
1.6 raeburn 4988: $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
4989: } else {
1.12 raeburn 4990: my $newitem = $confhash->{$role}{$item};
4991: if ($key eq 'images') {
4992: $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" valign="bottom" />';
4993: }
4994: $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
1.6 raeburn 4995: }
4996: }
4997: if ($role ne 'login') {
4998: $resulttext .= '</ul></li>';
4999: }
5000: } else {
5001: if ($confhash->{$role}{$key} eq '') {
5002: $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
5003: } else {
5004: $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
5005: }
5006: }
5007: if ($role ne 'login') {
5008: $resulttext .= '</ul>';
5009: }
5010: }
5011: }
5012: }
1.3 raeburn 5013: return $resulttext;
1.1 raeburn 5014: }
5015:
1.9 raeburn 5016: sub thumb_dimensions {
5017: return ('200','50');
5018: }
5019:
1.16 raeburn 5020: sub check_dimensions {
5021: my ($inputfile) = @_;
5022: my ($fullwidth,$fullheight);
5023: if ($inputfile =~ m|^[/\w.\-]+$|) {
5024: if (open(PIPE,"identify $inputfile 2>&1 |")) {
5025: my $imageinfo = <PIPE>;
5026: if (!close(PIPE)) {
5027: &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
5028: }
5029: chomp($imageinfo);
5030: my ($fullsize) =
1.21 raeburn 5031: ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
1.16 raeburn 5032: if ($fullsize) {
5033: ($fullwidth,$fullheight) = split(/x/,$fullsize);
5034: }
5035: }
5036: }
5037: return ($fullwidth,$fullheight);
5038: }
5039:
1.9 raeburn 5040: sub check_configuser {
5041: my ($uhome,$dom,$confname,$servadm) = @_;
5042: my ($configuserok,%currroles);
5043: if ($uhome eq 'no_host') {
5044: srand( time() ^ ($$ + ($$ << 15)) ); # Seed rand.
5045: my $configpass = &LONCAPA::Enrollment::create_password();
5046: $configuserok =
5047: &Apache::lonnet::modifyuser($dom,$confname,'','internal',
5048: $configpass,'','','','','',undef,$servadm);
5049: } else {
5050: $configuserok = 'ok';
5051: %currroles =
5052: &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
5053: }
5054: return ($configuserok,%currroles);
5055: }
5056:
5057: sub check_authorstatus {
5058: my ($dom,$confname,%currroles) = @_;
5059: my $author_ok;
1.40 raeburn 5060: if (!$currroles{':'.$dom.':au'}) {
1.9 raeburn 5061: my $start = time;
5062: my $end = 0;
5063: $author_ok =
5064: &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
1.47 raeburn 5065: 'au',$end,$start,'','','domconfig');
1.9 raeburn 5066: } else {
5067: $author_ok = 'ok';
5068: }
5069: return $author_ok;
5070: }
5071:
5072: sub publishlogo {
1.46 raeburn 5073: my ($r,$action,$formname,$dom,$confname,$subdir,$thumbwidth,$thumbheight,$savefileas) = @_;
1.9 raeburn 5074: my ($output,$fname,$logourl);
5075: if ($action eq 'upload') {
5076: $fname=$env{'form.'.$formname.'.filename'};
5077: chop($env{'form.'.$formname});
5078: } else {
5079: ($fname) = ($formname =~ /([^\/]+)$/);
5080: }
1.46 raeburn 5081: if ($savefileas ne '') {
5082: $fname = $savefileas;
5083: }
1.9 raeburn 5084: $fname=&Apache::lonnet::clean_filename($fname);
5085: # See if there is anything left
5086: unless ($fname) { return ('error: no uploaded file'); }
5087: $fname="$subdir/$fname";
1.164 raeburn 5088: my $docroot=$r->dir_config('lonDocRoot');
5089: my $filepath="$docroot/priv";
5090: my $relpath = "$dom/$confname";
1.9 raeburn 5091: my ($fnamepath,$file,$fetchthumb);
5092: $file=$fname;
5093: if ($fname=~m|/|) {
5094: ($fnamepath,$file) = ($fname =~ m|^(.*)/([^/]+)$|);
5095: }
1.164 raeburn 5096: my @parts=split(/\//,"$filepath/$relpath/$fnamepath");
1.9 raeburn 5097: my $count;
1.164 raeburn 5098: for ($count=5;$count<=$#parts;$count++) {
1.9 raeburn 5099: $filepath.="/$parts[$count]";
5100: if ((-e $filepath)!=1) {
5101: mkdir($filepath,02770);
5102: }
5103: }
5104: # Check for bad extension and disallow upload
5105: if ($file=~/\.(\w+)$/ &&
5106: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
5107: $output =
5108: &mt('Invalid file extension ([_1]) - reserved for LONCAPA use.',$1);
5109: } elsif ($file=~/\.(\w+)$/ &&
5110: !defined(&Apache::loncommon::fileembstyle($1))) {
5111: $output = &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
5112: } elsif ($file=~/\.(\d+)\.(\w+)$/) {
1.46 raeburn 5113: $output = &mt('File name not allowed - rename the file to remove the number immediately before the file extension([_1]) and re-upload.',$2);
1.9 raeburn 5114: } elsif (-d "$filepath/$file") {
5115: $output = &mt('File name is a directory name - rename the file and re-upload');
5116: } else {
5117: my $source = $filepath.'/'.$file;
5118: my $logfile;
5119: if (!open($logfile,">>$source".'.log')) {
5120: return (&mt('No write permission to Construction Space'));
5121: }
5122: print $logfile
5123: "\n================= Publish ".localtime()." ================\n".
5124: $env{'user.name'}.':'.$env{'user.domain'}."\n";
5125: # Save the file
5126: if (!open(FH,'>'.$source)) {
5127: &Apache::lonnet::logthis('Failed to create '.$source);
5128: return (&mt('Failed to create file'));
5129: }
5130: if ($action eq 'upload') {
5131: if (!print FH ($env{'form.'.$formname})) {
5132: &Apache::lonnet::logthis('Failed to write to '.$source);
5133: return (&mt('Failed to write file'));
5134: }
5135: } else {
5136: my $original = &Apache::lonnet::filelocation('',$formname);
5137: if(!copy($original,$source)) {
5138: &Apache::lonnet::logthis('Failed to copy '.$original.' to '.$source);
5139: return (&mt('Failed to write file'));
5140: }
5141: }
5142: close(FH);
5143: chmod(0660, $source); # Permissions to rw-rw---.
5144:
5145: my $targetdir=$docroot.'/res/'.$dom.'/'.$confname .'/'.$fnamepath;
5146: my $copyfile=$targetdir.'/'.$file;
5147:
5148: my @parts=split(/\//,$targetdir);
5149: my $path="/$parts[1]/$parts[2]/$parts[3]/$parts[4]";
5150: for (my $count=5;$count<=$#parts;$count++) {
5151: $path.="/$parts[$count]";
5152: if (!-e $path) {
5153: print $logfile "\nCreating directory ".$path;
5154: mkdir($path,02770);
5155: }
5156: }
5157: my $versionresult;
5158: if (-e $copyfile) {
5159: $versionresult = &logo_versioning($targetdir,$file,$logfile);
5160: } else {
5161: $versionresult = 'ok';
5162: }
5163: if ($versionresult eq 'ok') {
5164: if (copy($source,$copyfile)) {
5165: print $logfile "\nCopied original source to ".$copyfile."\n";
5166: $output = 'ok';
5167: $logourl = '/res/'.$dom.'/'.$confname.'/'.$fname;
1.155 raeburn 5168: push(@{$modified_urls},[$copyfile,$source]);
5169: my $metaoutput =
5170: &write_metadata($dom,$confname,$formname,$targetdir,$file,$logfile);
5171: unless ($registered_cleanup) {
5172: my $handlers = $r->get_handlers('PerlCleanupHandler');
5173: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
5174: $registered_cleanup=1;
5175: }
1.9 raeburn 5176: } else {
5177: print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";
5178: $output = &mt('Failed to copy file to RES space').", $!";
5179: }
5180: if (($thumbwidth =~ /^\d+$/) && ($thumbheight =~ /^\d+$/)) {
5181: my $inputfile = $filepath.'/'.$file;
5182: my $outfile = $filepath.'/'.'tn-'.$file;
1.16 raeburn 5183: my ($fullwidth,$fullheight) = &check_dimensions($inputfile);
5184: if ($fullwidth ne '' && $fullheight ne '') {
5185: if ($fullwidth > $thumbwidth && $fullheight > $thumbheight) {
5186: my $thumbsize = $thumbwidth.'x'.$thumbheight;
5187: system("convert -sample $thumbsize $inputfile $outfile");
5188: chmod(0660, $filepath.'/tn-'.$file);
5189: if (-e $outfile) {
5190: my $copyfile=$targetdir.'/tn-'.$file;
5191: if (copy($outfile,$copyfile)) {
5192: print $logfile "\nCopied source to ".$copyfile."\n";
1.155 raeburn 5193: my $thumb_metaoutput =
5194: &write_metadata($dom,$confname,$formname,
5195: $targetdir,'tn-'.$file,$logfile);
5196: push(@{$modified_urls},[$copyfile,$outfile]);
5197: unless ($registered_cleanup) {
5198: my $handlers = $r->get_handlers('PerlCleanupHandler');
5199: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
5200: $registered_cleanup=1;
5201: }
1.16 raeburn 5202: } else {
5203: print $logfile "\nUnable to write ".$copyfile.
5204: ':'.$!."\n";
5205: }
5206: }
1.9 raeburn 5207: }
5208: }
5209: }
5210: } else {
5211: $output = $versionresult;
5212: }
5213: }
5214: return ($output,$logourl);
5215: }
5216:
5217: sub logo_versioning {
5218: my ($targetdir,$file,$logfile) = @_;
5219: my $target = $targetdir.'/'.$file;
5220: my ($maxversion,$fn,$extn,$output);
5221: $maxversion = 0;
5222: if ($file =~ /^(.+)\.(\w+)$/) {
5223: $fn=$1;
5224: $extn=$2;
5225: }
5226: opendir(DIR,$targetdir);
5227: while (my $filename=readdir(DIR)) {
5228: if ($filename=~/\Q$fn\E\.(\d+)\.\Q$extn\E$/) {
5229: $maxversion=($1>$maxversion)?$1:$maxversion;
5230: }
5231: }
5232: $maxversion++;
5233: print $logfile "\nCreating old version ".$maxversion."\n";
5234: my $copyfile=$targetdir.'/'.$fn.'.'.$maxversion.'.'.$extn;
5235: if (copy($target,$copyfile)) {
5236: print $logfile "Copied old target to ".$copyfile."\n";
5237: $copyfile=$copyfile.'.meta';
5238: if (copy($target.'.meta',$copyfile)) {
5239: print $logfile "Copied old target metadata to ".$copyfile."\n";
5240: $output = 'ok';
5241: } else {
5242: print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";
5243: $output = &mt('Failed to copy old meta').", $!, ";
5244: }
5245: } else {
5246: print $logfile "Unable to write ".$copyfile.':'.$!."\n";
5247: $output = &mt('Failed to copy old target').", $!, ";
5248: }
5249: return $output;
5250: }
5251:
5252: sub write_metadata {
5253: my ($dom,$confname,$formname,$targetdir,$file,$logfile) = @_;
5254: my (%metadatafields,%metadatakeys,$output);
5255: $metadatafields{'title'}=$formname;
5256: $metadatafields{'creationdate'}=time;
5257: $metadatafields{'lastrevisiondate'}=time;
5258: $metadatafields{'copyright'}='public';
5259: $metadatafields{'modifyinguser'}=$env{'user.name'}.':'.
5260: $env{'user.domain'};
5261: $metadatafields{'authorspace'}=$confname.':'.$dom;
5262: $metadatafields{'domain'}=$dom;
5263: {
5264: print $logfile "\nWrite metadata file for ".$targetdir.'/'.$file;
5265: my $mfh;
1.155 raeburn 5266: if (open($mfh,'>'.$targetdir.'/'.$file.'.meta')) {
5267: foreach (sort keys %metadatafields) {
5268: unless ($_=~/\./) {
5269: my $unikey=$_;
5270: $unikey=~/^([A-Za-z]+)/;
5271: my $tag=$1;
5272: $tag=~tr/A-Z/a-z/;
5273: print $mfh "\n\<$tag";
5274: foreach (split(/\,/,$metadatakeys{$unikey})) {
5275: my $value=$metadatafields{$unikey.'.'.$_};
5276: $value=~s/\"/\'\'/g;
5277: print $mfh ' '.$_.'="'.$value.'"';
5278: }
5279: print $mfh '>'.
5280: &HTML::Entities::encode($metadatafields{$unikey},'<>&"')
5281: .'</'.$tag.'>';
5282: }
5283: }
5284: $output = 'ok';
5285: print $logfile "\nWrote metadata";
5286: close($mfh);
5287: } else {
5288: print $logfile "\nFailed to open metadata file";
1.9 raeburn 5289: $output = &mt('Could not write metadata');
5290: }
5291: }
1.155 raeburn 5292: return $output;
5293: }
5294:
5295: sub notifysubscribed {
5296: foreach my $targetsource (@{$modified_urls}){
5297: next unless (ref($targetsource) eq 'ARRAY');
5298: my ($target,$source)=@{$targetsource};
5299: if ($source ne '') {
5300: if (open(my $logfh,'>>'.$source.'.log')) {
5301: print $logfh "\nCleanup phase: Notifications\n";
5302: my @subscribed=&subscribed_hosts($target);
5303: foreach my $subhost (@subscribed) {
5304: print $logfh "\nNotifying host ".$subhost.':';
5305: my $reply=&Apache::lonnet::critical('update:'.$target,$subhost);
5306: print $logfh $reply;
5307: }
5308: my @subscribedmeta=&subscribed_hosts("$target.meta");
5309: foreach my $subhost (@subscribedmeta) {
5310: print $logfh "\nNotifying host for metadata only ".$subhost.':';
5311: my $reply=&Apache::lonnet::critical('update:'.$target.'.meta',
5312: $subhost);
5313: print $logfh $reply;
5314: }
5315: print $logfh "\n============ Done ============\n";
1.160 raeburn 5316: close($logfh);
1.155 raeburn 5317: }
5318: }
5319: }
5320: return OK;
5321: }
5322:
5323: sub subscribed_hosts {
5324: my ($target) = @_;
5325: my @subscribed;
5326: if (open(my $fh,"<$target.subscription")) {
5327: while (my $subline=<$fh>) {
5328: if ($subline =~ /^($match_lonid):/) {
5329: my $host = $1;
5330: if ($host ne $Apache::lonnet::perlvar{'lonHostID'}) {
5331: unless (grep(/^\Q$host\E$/,@subscribed)) {
5332: push(@subscribed,$host);
5333: }
5334: }
5335: }
5336: }
5337: }
5338: return @subscribed;
1.9 raeburn 5339: }
5340:
5341: sub check_switchserver {
5342: my ($dom,$confname) = @_;
5343: my ($allowed,$switchserver);
5344: my $home = &Apache::lonnet::homeserver($confname,$dom);
5345: if ($home eq 'no_host') {
5346: $home = &Apache::lonnet::domain($dom,'primary');
5347: }
5348: my @ids=&Apache::lonnet::current_machine_ids();
1.10 albertel 5349: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
5350: if (!$allowed) {
5351: $switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role=dc./'.$dom.'/">'.&mt('Switch Server').'</a>';
1.9 raeburn 5352: }
5353: return $switchserver;
5354: }
5355:
1.1 raeburn 5356: sub modify_quotas {
1.86 raeburn 5357: my ($dom,$action,%domconfig) = @_;
1.101 raeburn 5358: my ($context,@usertools,@options,%validations,%titles,%confhash,%toolshash,
5359: %limithash,$toolregexp,%conditions,$resulttext,%changes);
1.86 raeburn 5360: if ($action eq 'quotas') {
5361: $context = 'tools';
1.163 raeburn 5362: } else {
1.86 raeburn 5363: $context = $action;
5364: }
5365: if ($context eq 'requestcourses') {
1.98 raeburn 5366: @usertools = ('official','unofficial','community');
1.106 raeburn 5367: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 5368: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
5369: %titles = &courserequest_titles();
5370: $toolregexp = join('|',@usertools);
5371: %conditions = &courserequest_conditions();
1.163 raeburn 5372: } elsif ($context eq 'requestauthor') {
5373: @usertools = ('author');
5374: %titles = &authorrequest_titles();
1.86 raeburn 5375: } else {
1.162 raeburn 5376: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 5377: %titles = &tool_titles();
1.86 raeburn 5378: }
1.72 raeburn 5379: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.44 raeburn 5380: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 5381: foreach my $key (keys(%env)) {
1.101 raeburn 5382: if ($context eq 'requestcourses') {
5383: if ($key =~ /^form\.crsreq_($toolregexp)_(.+)$/) {
5384: my $item = $1;
5385: my $type = $2;
5386: if ($type =~ /^limit_(.+)/) {
5387: $limithash{$item}{$1} = $env{$key};
5388: } else {
5389: $confhash{$item}{$type} = $env{$key};
5390: }
5391: }
1.163 raeburn 5392: } elsif ($context eq 'requestauthor') {
5393: if ($key =~ /^\Qform.authorreq_\E(.+)$/) {
5394: $confhash{$1} = $env{$key};
5395: }
1.101 raeburn 5396: } else {
1.86 raeburn 5397: if ($key =~ /^form\.quota_(.+)$/) {
5398: $confhash{'defaultquota'}{$1} = $env{$key};
5399: }
1.101 raeburn 5400: if ($key =~ /^form\.\Q$context\E_(.+)$/) {
5401: @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key);
5402: }
1.72 raeburn 5403: }
5404: }
1.163 raeburn 5405: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.102 raeburn 5406: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.reqapprovalnotify');
5407: @approvalnotify = sort(@approvalnotify);
5408: $confhash{'notify'}{'approval'} = join(',',@approvalnotify);
5409: if (ref($domconfig{$action}) eq 'HASH') {
5410: if (ref($domconfig{$action}{'notify'}) eq 'HASH') {
5411: if ($domconfig{$action}{'notify'}{'approval'} ne $confhash{'notify'}{'approval'}) {
5412: $changes{'notify'}{'approval'} = 1;
5413: }
5414: } else {
1.144 raeburn 5415: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 5416: $changes{'notify'}{'approval'} = 1;
5417: }
5418: }
5419: } else {
1.144 raeburn 5420: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 5421: $changes{'notify'}{'approval'} = 1;
5422: }
5423: }
5424: } else {
1.86 raeburn 5425: $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
5426: }
1.72 raeburn 5427: foreach my $item (@usertools) {
5428: foreach my $type (@{$types},'default','_LC_adv') {
1.104 raeburn 5429: my $unset;
1.101 raeburn 5430: if ($context eq 'requestcourses') {
1.104 raeburn 5431: $unset = '0';
5432: if ($type eq '_LC_adv') {
5433: $unset = '';
5434: }
1.101 raeburn 5435: if ($confhash{$item}{$type} eq 'autolimit') {
5436: $confhash{$item}{$type} .= '=';
5437: unless ($limithash{$item}{$type} =~ /\D/) {
5438: $confhash{$item}{$type} .= $limithash{$item}{$type};
5439: }
5440: }
1.163 raeburn 5441: } elsif ($context eq 'requestauthor') {
5442: $unset = '0';
5443: if ($type eq '_LC_adv') {
5444: $unset = '';
5445: }
1.72 raeburn 5446: } else {
1.101 raeburn 5447: if (grep(/^\Q$type\E$/,@{$toolshash{$item}})) {
5448: $confhash{$item}{$type} = 1;
5449: } else {
5450: $confhash{$item}{$type} = 0;
5451: }
1.72 raeburn 5452: }
1.86 raeburn 5453: if (ref($domconfig{$action}) eq 'HASH') {
1.163 raeburn 5454: if ($action eq 'requestauthor') {
5455: if ($domconfig{$action}{$type} ne $confhash{$type}) {
5456: $changes{$type} = 1;
5457: }
5458: } elsif (ref($domconfig{$action}{$item}) eq 'HASH') {
1.86 raeburn 5459: if ($domconfig{$action}{$item}{$type} ne $confhash{$item}{$type}) {
5460: $changes{$item}{$type} = 1;
5461: }
5462: } else {
5463: if ($context eq 'requestcourses') {
1.104 raeburn 5464: if ($confhash{$item}{$type} ne $unset) {
1.86 raeburn 5465: $changes{$item}{$type} = 1;
5466: }
5467: } else {
5468: if (!$confhash{$item}{$type}) {
5469: $changes{$item}{$type} = 1;
5470: }
5471: }
5472: }
5473: } else {
5474: if ($context eq 'requestcourses') {
1.104 raeburn 5475: if ($confhash{$item}{$type} ne $unset) {
1.72 raeburn 5476: $changes{$item}{$type} = 1;
5477: }
1.163 raeburn 5478: } elsif ($context eq 'requestauthor') {
5479: if ($confhash{$type} ne $unset) {
5480: $changes{$type} = 1;
5481: }
1.72 raeburn 5482: } else {
5483: if (!$confhash{$item}{$type}) {
5484: $changes{$item}{$type} = 1;
5485: }
5486: }
5487: }
1.1 raeburn 5488: }
5489: }
1.163 raeburn 5490: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 5491: if (ref($domconfig{'quotas'}) eq 'HASH') {
5492: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
5493: foreach my $key (keys(%{$domconfig{'quotas'}{'defaultquota'}})) {
5494: if (exists($confhash{'defaultquota'}{$key})) {
5495: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{'defaultquota'}{$key}) {
5496: $changes{'defaultquota'}{$key} = 1;
5497: }
5498: } else {
5499: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{'defaultquota'}{$key};
1.72 raeburn 5500: }
5501: }
1.86 raeburn 5502: } else {
5503: foreach my $key (keys(%{$domconfig{'quotas'}})) {
5504: if (exists($confhash{'defaultquota'}{$key})) {
5505: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{$key}) {
5506: $changes{'defaultquota'}{$key} = 1;
5507: }
5508: } else {
5509: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{$key};
1.72 raeburn 5510: }
1.1 raeburn 5511: }
5512: }
5513: }
1.86 raeburn 5514: if (ref($confhash{'defaultquota'}) eq 'HASH') {
5515: foreach my $key (keys(%{$confhash{'defaultquota'}})) {
5516: if (ref($domconfig{'quotas'}) eq 'HASH') {
5517: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
5518: if (!exists($domconfig{'quotas'}{'defaultquota'}{$key})) {
5519: $changes{'defaultquota'}{$key} = 1;
5520: }
5521: } else {
5522: if (!exists($domconfig{'quotas'}{$key})) {
5523: $changes{'defaultquota'}{$key} = 1;
5524: }
1.72 raeburn 5525: }
5526: } else {
1.86 raeburn 5527: $changes{'defaultquota'}{$key} = 1;
1.55 raeburn 5528: }
1.1 raeburn 5529: }
5530: }
5531: }
1.72 raeburn 5532:
1.163 raeburn 5533: if ($context eq 'requestauthor') {
5534: $domdefaults{'requestauthor'} = \%confhash;
5535: } else {
5536: foreach my $key (keys(%confhash)) {
5537: $domdefaults{$key} = $confhash{$key};
5538: }
1.72 raeburn 5539: }
1.163 raeburn 5540:
1.1 raeburn 5541: my %quotahash = (
1.86 raeburn 5542: $action => { %confhash }
1.1 raeburn 5543: );
5544: my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
5545: $dom);
5546: if ($putresult eq 'ok') {
5547: if (keys(%changes) > 0) {
1.72 raeburn 5548: my $cachetime = 24*60*60;
5549: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
5550:
1.1 raeburn 5551: $resulttext = &mt('Changes made:').'<ul>';
1.163 raeburn 5552: unless (($context eq 'requestcourses') ||
5553: ($context eq 'requestauthor')) {
1.86 raeburn 5554: if (ref($changes{'defaultquota'}) eq 'HASH') {
5555: $resulttext .= '<li>'.&mt('Portfolio default quotas').'<ul>';
5556: foreach my $type (@{$types},'default') {
5557: if (defined($changes{'defaultquota'}{$type})) {
5558: my $typetitle = $usertypes->{$type};
5559: if ($type eq 'default') {
5560: $typetitle = $othertitle;
5561: }
5562: $resulttext .= '<li>'.&mt('[_1] set to [_2] Mb',$typetitle,$confhash{'defaultquota'}{$type}).'</li>';
1.72 raeburn 5563: }
5564: }
1.86 raeburn 5565: $resulttext .= '</ul></li>';
1.72 raeburn 5566: }
5567: }
1.80 raeburn 5568: my %newenv;
1.72 raeburn 5569: foreach my $item (@usertools) {
1.163 raeburn 5570: my (%haschgs,%inconf);
5571: if ($context eq 'requestauthor') {
5572: %haschgs = %changes;
5573: %inconf = %confhash;
5574: } else {
5575: if (ref($changes{$item}) eq 'HASH') {
5576: %haschgs = %{$changes{$item}};
5577: }
5578: if (ref($confhash{$item}) eq 'HASH') {
5579: %inconf = %{$confhash{$item}};
5580: }
5581: }
5582: if (keys(%haschgs) > 0) {
1.80 raeburn 5583: my $newacc =
5584: &Apache::lonnet::usertools_access($env{'user.name'},
5585: $env{'user.domain'},
1.86 raeburn 5586: $item,'reload',$context);
1.163 raeburn 5587: if (($context eq 'requestcourses') ||
5588: ($context eq 'requestauthor')) {
1.108 raeburn 5589: if ($env{'environment.canrequest.'.$item} ne $newacc) {
5590: $newenv{'environment.canrequest.'.$item} = $newacc;
1.86 raeburn 5591: }
5592: } else {
5593: if ($env{'environment.availabletools.'.$item} ne $newacc) {
5594: $newenv{'environment.availabletools.'.$item} = $newacc;
5595: }
1.80 raeburn 5596: }
1.163 raeburn 5597: unless ($context eq 'requestauthor') {
5598: $resulttext .= '<li>'.$titles{$item}.'<ul>';
5599: }
1.72 raeburn 5600: foreach my $type (@{$types},'default','_LC_adv') {
1.163 raeburn 5601: if ($haschgs{$type}) {
1.72 raeburn 5602: my $typetitle = $usertypes->{$type};
5603: if ($type eq 'default') {
5604: $typetitle = $othertitle;
5605: } elsif ($type eq '_LC_adv') {
5606: $typetitle = 'LON-CAPA Advanced Users';
5607: }
1.163 raeburn 5608: if ($inconf{$type}) {
1.101 raeburn 5609: if ($context eq 'requestcourses') {
5610: my $cond;
1.163 raeburn 5611: if ($inconf{$type} =~ /^autolimit=(\d*)$/) {
1.101 raeburn 5612: if ($1 eq '') {
5613: $cond = &mt('(Automatic processing of any request).');
5614: } else {
5615: $cond = &mt('(Automatic processing of requests up to limit of [quant,_1,request] per user).',$1);
5616: }
5617: } else {
1.163 raeburn 5618: $cond = $conditions{$inconf{$type}};
1.101 raeburn 5619: }
5620: $resulttext .= '<li>'.&mt('Set to be available to [_1].',$typetitle).' '.$cond.'</li>';
5621: } else {
5622: $resulttext .= '<li>'.&mt('Set to be available to [_1]',$typetitle).'</li>';
5623: }
1.72 raeburn 5624: } else {
1.104 raeburn 5625: if ($type eq '_LC_adv') {
1.163 raeburn 5626: if ($inconf{$type} eq '0') {
1.104 raeburn 5627: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
5628: } else {
5629: $resulttext .= '<li>'.&mt('No override set for [_1]',$typetitle).'</li>';
5630: }
5631: } else {
5632: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
5633: }
1.72 raeburn 5634: }
5635: }
1.26 raeburn 5636: }
1.163 raeburn 5637: unless ($context eq 'requestauthor') {
5638: $resulttext .= '</ul></li>';
5639: }
1.26 raeburn 5640: }
1.1 raeburn 5641: }
1.163 raeburn 5642: if (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.102 raeburn 5643: if (ref($changes{'notify'}) eq 'HASH') {
5644: if ($changes{'notify'}{'approval'}) {
5645: if (ref($confhash{'notify'}) eq 'HASH') {
5646: if ($confhash{'notify'}{'approval'}) {
5647: $resulttext .= '<li>'.&mt('Notification of requests requiring approval will be sent to: ').$confhash{'notify'}{'approval'}.'</li>';
5648: } else {
1.163 raeburn 5649: $resulttext .= '<li>'.&mt('No Domain Coordinators will receive notification of requests requiring approval.').'</li>';
1.102 raeburn 5650: }
5651: }
5652: }
5653: }
5654: }
1.1 raeburn 5655: $resulttext .= '</ul>';
1.80 raeburn 5656: if (keys(%newenv)) {
5657: &Apache::lonnet::appenv(\%newenv);
5658: }
1.1 raeburn 5659: } else {
1.86 raeburn 5660: if ($context eq 'requestcourses') {
5661: $resulttext = &mt('No changes made to rights to request creation of courses.');
1.163 raeburn 5662: } elsif ($context eq 'requestauthor') {
5663: $resulttext = &mt('No changes made to rights to request author space.');
1.86 raeburn 5664: } else {
1.90 weissno 5665: $resulttext = &mt('No changes made to availability of personal information pages, blogs, portfolios or default quotas');
1.86 raeburn 5666: }
1.1 raeburn 5667: }
5668: } else {
1.11 albertel 5669: $resulttext = '<span class="LC_error">'.
5670: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 5671: }
1.3 raeburn 5672: return $resulttext;
1.1 raeburn 5673: }
5674:
1.3 raeburn 5675: sub modify_autoenroll {
5676: my ($dom,%domconfig) = @_;
1.1 raeburn 5677: my ($resulttext,%changes);
5678: my %currautoenroll;
5679: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
5680: foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
5681: $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
5682: }
5683: }
5684: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
5685: my %title = ( run => 'Auto-enrollment active',
1.129 raeburn 5686: sender => 'Sender for notification messages',
5687: coowners => 'Automatic assignment of co-ownership to instructors of record (institutional data)');
1.1 raeburn 5688: my @offon = ('off','on');
1.17 raeburn 5689: my $sender_uname = $env{'form.sender_uname'};
5690: my $sender_domain = $env{'form.sender_domain'};
5691: if ($sender_domain eq '') {
5692: $sender_uname = '';
5693: } elsif ($sender_uname eq '') {
5694: $sender_domain = '';
5695: }
1.129 raeburn 5696: my $coowners = $env{'form.autoassign_coowners'};
1.1 raeburn 5697: my %autoenrollhash = (
1.129 raeburn 5698: autoenroll => { 'run' => $env{'form.autoenroll_run'},
5699: 'sender_uname' => $sender_uname,
5700: 'sender_domain' => $sender_domain,
5701: 'co-owners' => $coowners,
1.1 raeburn 5702: }
5703: );
1.4 raeburn 5704: my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
5705: $dom);
1.1 raeburn 5706: if ($putresult eq 'ok') {
5707: if (exists($currautoenroll{'run'})) {
5708: if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
5709: $changes{'run'} = 1;
5710: }
5711: } elsif ($autorun) {
5712: if ($env{'form.autoenroll_run'} ne '1') {
1.23 raeburn 5713: $changes{'run'} = 1;
1.1 raeburn 5714: }
5715: }
1.17 raeburn 5716: if ($currautoenroll{'sender_uname'} ne $sender_uname) {
1.1 raeburn 5717: $changes{'sender'} = 1;
5718: }
1.17 raeburn 5719: if ($currautoenroll{'sender_domain'} ne $sender_domain) {
1.1 raeburn 5720: $changes{'sender'} = 1;
5721: }
1.129 raeburn 5722: if ($currautoenroll{'co-owners'} ne '') {
5723: if ($currautoenroll{'co-owners'} ne $coowners) {
5724: $changes{'coowners'} = 1;
5725: }
5726: } elsif ($coowners) {
5727: $changes{'coowners'} = 1;
5728: }
1.1 raeburn 5729: if (keys(%changes) > 0) {
5730: $resulttext = &mt('Changes made:').'<ul>';
1.3 raeburn 5731: if ($changes{'run'}) {
1.1 raeburn 5732: $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
5733: }
5734: if ($changes{'sender'}) {
1.17 raeburn 5735: if ($sender_uname eq '' || $sender_domain eq '') {
5736: $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
5737: } else {
5738: $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
5739: }
1.1 raeburn 5740: }
1.129 raeburn 5741: if ($changes{'coowners'}) {
5742: $resulttext .= '<li>'.&mt("$title{'coowners'} set to $offon[$env{'form.autoassign_coowners'}]").'</li>';
5743: &Apache::loncommon::devalidate_domconfig_cache($dom);
5744: }
1.1 raeburn 5745: $resulttext .= '</ul>';
5746: } else {
5747: $resulttext = &mt('No changes made to auto-enrollment settings');
5748: }
5749: } else {
1.11 albertel 5750: $resulttext = '<span class="LC_error">'.
5751: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 5752: }
1.3 raeburn 5753: return $resulttext;
1.1 raeburn 5754: }
5755:
5756: sub modify_autoupdate {
1.3 raeburn 5757: my ($dom,%domconfig) = @_;
1.1 raeburn 5758: my ($resulttext,%currautoupdate,%fields,%changes);
5759: if (ref($domconfig{'autoupdate'}) eq 'HASH') {
5760: foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
5761: $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
5762: }
5763: }
5764: my @offon = ('off','on');
5765: my %title = &Apache::lonlocal::texthash (
5766: run => 'Auto-update:',
5767: classlists => 'Updates to user information in classlists?'
5768: );
1.44 raeburn 5769: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 5770: my %fieldtitles = &Apache::lonlocal::texthash (
5771: id => 'Student/Employee ID',
1.20 raeburn 5772: permanentemail => 'E-mail address',
1.1 raeburn 5773: lastname => 'Last Name',
5774: firstname => 'First Name',
5775: middlename => 'Middle Name',
1.132 raeburn 5776: generation => 'Generation',
1.1 raeburn 5777: );
1.142 raeburn 5778: $othertitle = &mt('All users');
1.1 raeburn 5779: if (keys(%{$usertypes}) > 0) {
1.26 raeburn 5780: $othertitle = &mt('Other users');
1.1 raeburn 5781: }
5782: foreach my $key (keys(%env)) {
5783: if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
1.132 raeburn 5784: my ($usertype,$item) = ($1,$2);
5785: if (grep(/^\Q$item\E$/,keys(%fieldtitles))) {
5786: if ($usertype eq 'default') {
5787: push(@{$fields{$1}},$2);
5788: } elsif (ref($types) eq 'ARRAY') {
5789: if (grep(/^\Q$usertype\E$/,@{$types})) {
5790: push(@{$fields{$1}},$2);
5791: }
5792: }
5793: }
1.1 raeburn 5794: }
5795: }
1.131 raeburn 5796: my @lockablenames = &Apache::loncommon::get_env_multiple('form.lockablenames');
5797: @lockablenames = sort(@lockablenames);
5798: if (ref($currautoupdate{'lockablenames'}) eq 'ARRAY') {
5799: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
5800: if (@changed) {
5801: $changes{'lockablenames'} = 1;
5802: }
5803: } else {
5804: if (@lockablenames) {
5805: $changes{'lockablenames'} = 1;
5806: }
5807: }
1.1 raeburn 5808: my %updatehash = (
5809: autoupdate => { run => $env{'form.autoupdate_run'},
5810: classlists => $env{'form.classlists'},
5811: fields => {%fields},
1.131 raeburn 5812: lockablenames => \@lockablenames,
1.1 raeburn 5813: }
5814: );
5815: foreach my $key (keys(%currautoupdate)) {
5816: if (($key eq 'run') || ($key eq 'classlists')) {
5817: if (exists($updatehash{autoupdate}{$key})) {
5818: if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
5819: $changes{$key} = 1;
5820: }
5821: }
5822: } elsif ($key eq 'fields') {
5823: if (ref($currautoupdate{$key}) eq 'HASH') {
1.26 raeburn 5824: foreach my $item (@{$types},'default') {
1.1 raeburn 5825: if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
5826: my $change = 0;
5827: foreach my $type (@{$currautoupdate{$key}{$item}}) {
5828: if (!exists($fields{$item})) {
5829: $change = 1;
1.132 raeburn 5830: last;
1.1 raeburn 5831: } elsif (ref($fields{$item}) eq 'ARRAY') {
1.26 raeburn 5832: if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
1.1 raeburn 5833: $change = 1;
1.132 raeburn 5834: last;
1.1 raeburn 5835: }
5836: }
5837: }
5838: if ($change) {
5839: push(@{$changes{$key}},$item);
5840: }
1.26 raeburn 5841: }
1.1 raeburn 5842: }
5843: }
1.131 raeburn 5844: } elsif ($key eq 'lockablenames') {
5845: if (ref($currautoupdate{$key}) eq 'ARRAY') {
5846: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
5847: if (@changed) {
5848: $changes{'lockablenames'} = 1;
5849: }
5850: } else {
5851: if (@lockablenames) {
5852: $changes{'lockablenames'} = 1;
5853: }
5854: }
5855: }
5856: }
5857: unless (grep(/^\Qlockablenames\E$/,keys(%currautoupdate))) {
5858: if (@lockablenames) {
5859: $changes{'lockablenames'} = 1;
1.1 raeburn 5860: }
5861: }
1.26 raeburn 5862: foreach my $item (@{$types},'default') {
5863: if (defined($fields{$item})) {
5864: if (ref($currautoupdate{'fields'}) eq 'HASH') {
1.132 raeburn 5865: if (ref($currautoupdate{'fields'}{$item}) eq 'ARRAY') {
5866: my $change = 0;
5867: if (ref($fields{$item}) eq 'ARRAY') {
5868: foreach my $type (@{$fields{$item}}) {
5869: if (!grep(/^\Q$type\E$/,@{$currautoupdate{'fields'}{$item}})) {
5870: $change = 1;
5871: last;
5872: }
5873: }
5874: }
5875: if ($change) {
5876: push(@{$changes{'fields'}},$item);
5877: }
5878: } else {
1.26 raeburn 5879: push(@{$changes{'fields'}},$item);
5880: }
5881: } else {
5882: push(@{$changes{'fields'}},$item);
1.1 raeburn 5883: }
5884: }
5885: }
5886: my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
5887: $dom);
5888: if ($putresult eq 'ok') {
5889: if (keys(%changes) > 0) {
5890: $resulttext = &mt('Changes made:').'<ul>';
5891: foreach my $key (sort(keys(%changes))) {
1.131 raeburn 5892: if ($key eq 'lockablenames') {
5893: $resulttext .= '<li>';
5894: if (@lockablenames) {
5895: $usertypes->{'default'} = $othertitle;
5896: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update), available for the following affiliations:").' '.
5897: join(', ', map { $usertypes->{$_}; } @lockablenames).'</li>';
5898: } else {
5899: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update) is unavailable.");
5900: }
5901: $resulttext .= '</li>';
5902: } elsif (ref($changes{$key}) eq 'ARRAY') {
1.1 raeburn 5903: foreach my $item (@{$changes{$key}}) {
5904: my @newvalues;
5905: foreach my $type (@{$fields{$item}}) {
5906: push(@newvalues,$fieldtitles{$type});
5907: }
1.3 raeburn 5908: my $newvaluestr;
5909: if (@newvalues > 0) {
5910: $newvaluestr = join(', ',@newvalues);
5911: } else {
5912: $newvaluestr = &mt('none');
1.6 raeburn 5913: }
1.1 raeburn 5914: if ($item eq 'default') {
1.26 raeburn 5915: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
1.1 raeburn 5916: } else {
1.26 raeburn 5917: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
1.1 raeburn 5918: }
5919: }
5920: } else {
5921: my $newvalue;
5922: if ($key eq 'run') {
5923: $newvalue = $offon[$env{'form.autoupdate_run'}];
5924: } else {
5925: $newvalue = $offon[$env{'form.'.$key}];
1.3 raeburn 5926: }
1.1 raeburn 5927: $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
5928: }
5929: }
5930: $resulttext .= '</ul>';
5931: } else {
1.3 raeburn 5932: $resulttext = &mt('No changes made to autoupdates');
1.1 raeburn 5933: }
5934: } else {
1.11 albertel 5935: $resulttext = '<span class="LC_error">'.
5936: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 5937: }
1.3 raeburn 5938: return $resulttext;
1.1 raeburn 5939: }
5940:
1.125 raeburn 5941: sub modify_autocreate {
5942: my ($dom,%domconfig) = @_;
5943: my ($resulttext,%changes,%currautocreate,%newvals,%autocreatehash);
5944: if (ref($domconfig{'autocreate'}) eq 'HASH') {
5945: foreach my $key (keys(%{$domconfig{'autocreate'}})) {
5946: $currautocreate{$key} = $domconfig{'autocreate'}{$key};
5947: }
5948: }
5949: my %title= ( xml => 'Auto-creation of courses in XML course description files',
5950: req => 'Auto-creation of validated requests for official courses',
5951: xmldc => 'Identity of course creator of courses from XML files',
5952: );
5953: my @types = ('xml','req');
5954: foreach my $item (@types) {
5955: $newvals{$item} = $env{'form.autocreate_'.$item};
5956: $newvals{$item} =~ s/\D//g;
5957: $newvals{$item} = 0 if ($newvals{$item} eq '');
5958: }
5959: $newvals{'xmldc'} = $env{'form.autocreate_xmldc'};
5960: my %domcoords = &get_active_dcs($dom);
5961: unless (exists($domcoords{$newvals{'xmldc'}})) {
5962: $newvals{'xmldc'} = '';
5963: }
5964: %autocreatehash = (
5965: autocreate => { xml => $newvals{'xml'},
5966: req => $newvals{'req'},
5967: }
5968: );
5969: if ($newvals{'xmldc'} ne '') {
5970: $autocreatehash{'autocreate'}{'xmldc'} = $newvals{'xmldc'};
5971: }
5972: my $putresult = &Apache::lonnet::put_dom('configuration',\%autocreatehash,
5973: $dom);
5974: if ($putresult eq 'ok') {
5975: my @items = @types;
5976: if ($newvals{'xml'}) {
5977: push(@items,'xmldc');
5978: }
5979: foreach my $item (@items) {
5980: if (exists($currautocreate{$item})) {
5981: if ($currautocreate{$item} ne $newvals{$item}) {
5982: $changes{$item} = 1;
5983: }
5984: } elsif ($newvals{$item}) {
5985: $changes{$item} = 1;
5986: }
5987: }
5988: if (keys(%changes) > 0) {
5989: my @offon = ('off','on');
5990: $resulttext = &mt('Changes made:').'<ul>';
5991: foreach my $item (@types) {
5992: if ($changes{$item}) {
5993: my $newtxt = $offon[$newvals{$item}];
5994: $resulttext .= '<li>'.&mt("$title{$item} set to [_1]$newtxt [_2]",'<b>','</b>').'</li>';
5995: }
5996: }
5997: if ($changes{'xmldc'}) {
5998: my ($dcname,$dcdom) = split(':',$newvals{'xmldc'});
5999: my $newtxt = &Apache::loncommon::plainname($dcname,$dcdom);
6000: $resulttext .= '<li>'.&mt("$title{'xmldc'} set to [_1]$newtxt [_2]",'<b>','</b>').'</li>';
6001: }
6002: $resulttext .= '</ul>';
6003: } else {
6004: $resulttext = &mt('No changes made to auto-creation settings');
6005: }
6006: } else {
6007: $resulttext = '<span class="LC_error">'.
6008: &mt('An error occurred: [_1]',$putresult).'</span>';
6009: }
6010: return $resulttext;
6011: }
6012:
1.23 raeburn 6013: sub modify_directorysrch {
6014: my ($dom,%domconfig) = @_;
6015: my ($resulttext,%changes);
6016: my %currdirsrch;
6017: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
6018: foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
6019: $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
6020: }
6021: }
6022: my %title = ( available => 'Directory search available',
1.24 raeburn 6023: localonly => 'Other domains can search',
1.23 raeburn 6024: searchby => 'Search types',
6025: searchtypes => 'Search latitude');
6026: my @offon = ('off','on');
1.24 raeburn 6027: my @otherdoms = ('Yes','No');
1.23 raeburn 6028:
1.25 raeburn 6029: my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');
1.23 raeburn 6030: my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
6031: my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
6032:
1.44 raeburn 6033: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.26 raeburn 6034: if (keys(%{$usertypes}) == 0) {
6035: @cansearch = ('default');
6036: } else {
6037: if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
6038: foreach my $type (@{$currdirsrch{'cansearch'}}) {
6039: if (!grep(/^\Q$type\E$/,@cansearch)) {
6040: push(@{$changes{'cansearch'}},$type);
6041: }
1.23 raeburn 6042: }
1.26 raeburn 6043: foreach my $type (@cansearch) {
6044: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
6045: push(@{$changes{'cansearch'}},$type);
6046: }
1.23 raeburn 6047: }
1.26 raeburn 6048: } else {
6049: push(@{$changes{'cansearch'}},@cansearch);
1.23 raeburn 6050: }
6051: }
6052:
6053: if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
6054: foreach my $by (@{$currdirsrch{'searchby'}}) {
6055: if (!grep(/^\Q$by\E$/,@searchby)) {
6056: push(@{$changes{'searchby'}},$by);
6057: }
6058: }
6059: foreach my $by (@searchby) {
6060: if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
6061: push(@{$changes{'searchby'}},$by);
6062: }
6063: }
6064: } else {
6065: push(@{$changes{'searchby'}},@searchby);
6066: }
1.25 raeburn 6067:
6068: if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
6069: foreach my $type (@{$currdirsrch{'searchtypes'}}) {
6070: if (!grep(/^\Q$type\E$/,@searchtypes)) {
6071: push(@{$changes{'searchtypes'}},$type);
6072: }
6073: }
6074: foreach my $type (@searchtypes) {
6075: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
6076: push(@{$changes{'searchtypes'}},$type);
6077: }
6078: }
6079: } else {
6080: if (exists($currdirsrch{'searchtypes'})) {
6081: foreach my $type (@searchtypes) {
6082: if ($type ne $currdirsrch{'searchtypes'}) {
6083: push(@{$changes{'searchtypes'}},$type);
6084: }
6085: }
6086: if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
6087: push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
6088: }
6089: } else {
6090: push(@{$changes{'searchtypes'}},@searchtypes);
6091: }
6092: }
6093:
1.23 raeburn 6094: my %dirsrch_hash = (
6095: directorysrch => { available => $env{'form.dirsrch_available'},
6096: cansearch => \@cansearch,
1.24 raeburn 6097: localonly => $env{'form.dirsrch_localonly'},
1.23 raeburn 6098: searchby => \@searchby,
1.25 raeburn 6099: searchtypes => \@searchtypes,
1.23 raeburn 6100: }
6101: );
6102: my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
6103: $dom);
6104: if ($putresult eq 'ok') {
6105: if (exists($currdirsrch{'available'})) {
6106: if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
6107: $changes{'available'} = 1;
6108: }
6109: } else {
6110: if ($env{'form.dirsrch_available'} eq '1') {
6111: $changes{'available'} = 1;
6112: }
6113: }
1.24 raeburn 6114: if (exists($currdirsrch{'localonly'})) {
6115: if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_localonly'}) {
6116: $changes{'localonly'} = 1;
6117: }
6118: } else {
6119: if ($env{'form.dirsrch_localonly'} eq '1') {
6120: $changes{'localonly'} = 1;
6121: }
6122: }
1.23 raeburn 6123: if (keys(%changes) > 0) {
6124: $resulttext = &mt('Changes made:').'<ul>';
6125: if ($changes{'available'}) {
6126: $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
6127: }
1.24 raeburn 6128: if ($changes{'localonly'}) {
6129: $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_localonly'}]").'</li>';
6130: }
6131:
1.23 raeburn 6132: if (ref($changes{'cansearch'}) eq 'ARRAY') {
6133: my $chgtext;
1.26 raeburn 6134: if (ref($usertypes) eq 'HASH') {
6135: if (keys(%{$usertypes}) > 0) {
6136: foreach my $type (@{$types}) {
6137: if (grep(/^\Q$type\E$/,@cansearch)) {
6138: $chgtext .= $usertypes->{$type}.'; ';
6139: }
6140: }
6141: if (grep(/^default$/,@cansearch)) {
6142: $chgtext .= $othertitle;
6143: } else {
6144: $chgtext =~ s/\; $//;
6145: }
6146: $resulttext .= '<li>'.&mt("Users from domain '<span class=\"LC_cusr_emph\">[_1]</span>' permitted to search the institutional directory set to: [_2]",$dom,$chgtext).'</li>';
1.23 raeburn 6147: }
6148: }
6149: }
6150: if (ref($changes{'searchby'}) eq 'ARRAY') {
6151: my ($searchtitles,$titleorder) = &sorted_searchtitles();
6152: my $chgtext;
6153: foreach my $type (@{$titleorder}) {
6154: if (grep(/^\Q$type\E$/,@searchby)) {
6155: if (defined($searchtitles->{$type})) {
6156: $chgtext .= $searchtitles->{$type}.'; ';
6157: }
6158: }
6159: }
6160: $chgtext =~ s/\; $//;
6161: $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
6162: }
1.25 raeburn 6163: if (ref($changes{'searchtypes'}) eq 'ARRAY') {
6164: my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes();
6165: my $chgtext;
6166: foreach my $type (@{$srchtypeorder}) {
6167: if (grep(/^\Q$type\E$/,@searchtypes)) {
6168: if (defined($srchtypes_desc->{$type})) {
6169: $chgtext .= $srchtypes_desc->{$type}.'; ';
6170: }
6171: }
6172: }
6173: $chgtext =~ s/\; $//;
6174: $resulttext .= '<li>'.&mt("$title{'searchtypes'} set to: \"[_1]\"",$chgtext).'</li>';
1.23 raeburn 6175: }
6176: $resulttext .= '</ul>';
6177: } else {
6178: $resulttext = &mt('No changes made to institution directory search settings');
6179: }
6180: } else {
6181: $resulttext = '<span class="LC_error">'.
1.27 raeburn 6182: &mt('An error occurred: [_1]',$putresult).'</span>';
6183: }
6184: return $resulttext;
6185: }
6186:
1.28 raeburn 6187: sub modify_contacts {
6188: my ($dom,%domconfig) = @_;
6189: my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
6190: if (ref($domconfig{'contacts'}) eq 'HASH') {
6191: foreach my $key (keys(%{$domconfig{'contacts'}})) {
6192: $currsetting{$key} = $domconfig{'contacts'}{$key};
6193: }
6194: }
1.134 raeburn 6195: my (%others,%to,%bcc);
1.28 raeburn 6196: my @contacts = ('supportemail','adminemail');
1.102 raeburn 6197: my @mailings = ('errormail','packagesmail','helpdeskmail','lonstatusmail',
6198: 'requestsmail');
1.28 raeburn 6199: foreach my $type (@mailings) {
6200: @{$newsetting{$type}} =
6201: &Apache::loncommon::get_env_multiple('form.'.$type);
6202: foreach my $item (@contacts) {
6203: if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
6204: $contacts_hash{contacts}{$type}{$item} = 1;
6205: } else {
6206: $contacts_hash{contacts}{$type}{$item} = 0;
6207: }
6208: }
6209: $others{$type} = $env{'form.'.$type.'_others'};
6210: $contacts_hash{contacts}{$type}{'others'} = $others{$type};
1.134 raeburn 6211: if ($type eq 'helpdeskmail') {
6212: $bcc{$type} = $env{'form.'.$type.'_bcc'};
6213: $contacts_hash{contacts}{$type}{'bcc'} = $bcc{$type};
6214: }
1.28 raeburn 6215: }
6216: foreach my $item (@contacts) {
6217: $to{$item} = $env{'form.'.$item};
6218: $contacts_hash{'contacts'}{$item} = $to{$item};
6219: }
6220: if (keys(%currsetting) > 0) {
6221: foreach my $item (@contacts) {
6222: if ($to{$item} ne $currsetting{$item}) {
6223: $changes{$item} = 1;
6224: }
6225: }
6226: foreach my $type (@mailings) {
6227: foreach my $item (@contacts) {
6228: if (ref($currsetting{$type}) eq 'HASH') {
6229: if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
6230: push(@{$changes{$type}},$item);
6231: }
6232: } else {
6233: push(@{$changes{$type}},@{$newsetting{$type}});
6234: }
6235: }
6236: if ($others{$type} ne $currsetting{$type}{'others'}) {
6237: push(@{$changes{$type}},'others');
6238: }
1.134 raeburn 6239: if ($type eq 'helpdeskmail') {
6240: if ($bcc{$type} ne $currsetting{$type}{'bcc'}) {
6241: push(@{$changes{$type}},'bcc');
6242: }
6243: }
1.28 raeburn 6244: }
6245: } else {
6246: my %default;
6247: $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
6248: $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
6249: $default{'errormail'} = 'adminemail';
6250: $default{'packagesmail'} = 'adminemail';
6251: $default{'helpdeskmail'} = 'supportemail';
1.89 raeburn 6252: $default{'lonstatusmail'} = 'adminemail';
1.102 raeburn 6253: $default{'requestsmail'} = 'adminemail';
1.28 raeburn 6254: foreach my $item (@contacts) {
6255: if ($to{$item} ne $default{$item}) {
6256: $changes{$item} = 1;
6257: }
6258: }
6259: foreach my $type (@mailings) {
6260: if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
6261:
6262: push(@{$changes{$type}},@{$newsetting{$type}});
6263: }
6264: if ($others{$type} ne '') {
6265: push(@{$changes{$type}},'others');
1.134 raeburn 6266: }
6267: if ($type eq 'helpdeskmail') {
6268: if ($bcc{$type} ne '') {
6269: push(@{$changes{$type}},'bcc');
6270: }
6271: }
1.28 raeburn 6272: }
6273: }
6274: my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
6275: $dom);
6276: if ($putresult eq 'ok') {
6277: if (keys(%changes) > 0) {
6278: my ($titles,$short_titles) = &contact_titles();
6279: $resulttext = &mt('Changes made:').'<ul>';
6280: foreach my $item (@contacts) {
6281: if ($changes{$item}) {
6282: $resulttext .= '<li>'.$titles->{$item}.
6283: &mt(' set to: ').
6284: '<span class="LC_cusr_emph">'.
6285: $to{$item}.'</span></li>';
6286: }
6287: }
6288: foreach my $type (@mailings) {
6289: if (ref($changes{$type}) eq 'ARRAY') {
6290: $resulttext .= '<li>'.$titles->{$type}.': ';
6291: my @text;
6292: foreach my $item (@{$newsetting{$type}}) {
6293: push(@text,$short_titles->{$item});
6294: }
6295: if ($others{$type} ne '') {
6296: push(@text,$others{$type});
6297: }
6298: $resulttext .= '<span class="LC_cusr_emph">'.
1.134 raeburn 6299: join(', ',@text).'</span>';
6300: if ($type eq 'helpdeskmail') {
6301: if ($bcc{$type} ne '') {
6302: $resulttext .= ' '.&mt('with Bcc to').': <span class="LC_cusr_emph">'.$bcc{$type}.'</span>';
6303: }
6304: }
6305: $resulttext .= '</li>';
1.28 raeburn 6306: }
6307: }
6308: $resulttext .= '</ul>';
6309: } else {
1.34 raeburn 6310: $resulttext = &mt('No changes made to contact information');
1.28 raeburn 6311: }
6312: } else {
6313: $resulttext = '<span class="LC_error">'.
6314: &mt('An error occurred: [_1].',$putresult).'</span>';
6315: }
6316: return $resulttext;
6317: }
6318:
6319: sub modify_usercreation {
1.27 raeburn 6320: my ($dom,%domconfig) = @_;
1.34 raeburn 6321: my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate);
1.43 raeburn 6322: my $warningmsg;
1.27 raeburn 6323: if (ref($domconfig{'usercreation'}) eq 'HASH') {
6324: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
6325: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
6326: }
6327: }
6328: my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
1.32 raeburn 6329: my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
1.43 raeburn 6330: my @email_rule = &Apache::loncommon::get_env_multiple('form.email_rule');
1.100 raeburn 6331: my @contexts = ('author','course','requestcrs','selfcreate');
1.34 raeburn 6332: foreach my $item(@contexts) {
1.45 raeburn 6333: if ($item eq 'selfcreate') {
1.50 raeburn 6334: @{$cancreate{$item}} = &Apache::loncommon::get_env_multiple('form.can_createuser_'.$item);
1.43 raeburn 6335: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
6336: if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) || ($domdefaults{'auth_def'} eq 'localauth'))) {
1.50 raeburn 6337: if (ref($cancreate{$item}) eq 'ARRAY') {
6338: if (grep(/^login$/,@{$cancreate{$item}})) {
6339: $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.').' '.&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.');
6340: }
1.43 raeburn 6341: }
6342: }
1.50 raeburn 6343: } else {
6344: $cancreate{$item} = $env{'form.can_createuser_'.$item};
1.43 raeburn 6345: }
1.34 raeburn 6346: }
1.93 raeburn 6347: my ($othertitle,$usertypes,$types) =
6348: &Apache::loncommon::sorted_inst_types($dom);
6349: if (ref($types) eq 'ARRAY') {
6350: if (@{$types} > 0) {
6351: @{$cancreate{'statustocreate'}} =
6352: &Apache::loncommon::get_env_multiple('form.statustocreate');
1.103 raeburn 6353: } else {
6354: @{$cancreate{'statustocreate'}} = ();
1.93 raeburn 6355: }
6356: push(@contexts,'statustocreate');
6357: }
1.165 raeburn 6358: &process_captcha('cancreate',\%changes,\%cancreate,\%curr_usercreation);
1.34 raeburn 6359: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
6360: foreach my $item (@contexts) {
1.93 raeburn 6361: if (($item eq 'selfcreate') || ($item eq 'statustocreate')) {
6362: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
1.50 raeburn 6363: foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
1.103 raeburn 6364: if (ref($cancreate{$item}) eq 'ARRAY') {
6365: if (!grep(/^$curr$/,@{$cancreate{$item}})) {
6366: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6367: push(@{$changes{'cancreate'}},$item);
6368: }
1.50 raeburn 6369: }
6370: }
6371: }
6372: } else {
6373: if ($curr_usercreation{'cancreate'}{$item} eq '') {
6374: if (@{$cancreate{$item}} > 0) {
6375: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6376: push(@{$changes{'cancreate'}},$item);
6377: }
6378: }
6379: } else {
6380: if ($curr_usercreation{'cancreate'}{$item} eq 'any') {
6381: if (@{$cancreate{$item}} < 3) {
6382: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6383: push(@{$changes{'cancreate'}},$item);
6384: }
6385: }
6386: } elsif ($curr_usercreation{'cancreate'}{$item} eq 'none') {
6387: if (@{$cancreate{$item}} > 0) {
6388: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6389: push(@{$changes{'cancreate'}},$item);
6390: }
6391: }
6392: } elsif (!grep(/^$curr_usercreation{'cancreate'}{$item}$/,@{$cancreate{$item}})) {
6393: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6394: push(@{$changes{'cancreate'}},$item);
6395: }
6396: }
6397: }
6398: }
6399: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6400: foreach my $type (@{$cancreate{$item}}) {
6401: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
6402: if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
6403: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6404: push(@{$changes{'cancreate'}},$item);
6405: }
6406: }
6407: } elsif (($curr_usercreation{'cancreate'}{$item} ne 'any') &&
6408: ($curr_usercreation{'cancreate'}{$item} ne 'none')) {
6409: if ($curr_usercreation{'cancreate'}{$item} ne $type) {
6410: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6411: push(@{$changes{'cancreate'}},$item);
6412: }
6413: }
6414: }
6415: }
6416: }
6417: } else {
6418: if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
6419: push(@{$changes{'cancreate'}},$item);
6420: }
6421: }
1.27 raeburn 6422: }
1.34 raeburn 6423: } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
6424: foreach my $item (@contexts) {
1.43 raeburn 6425: if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
1.34 raeburn 6426: if ($cancreate{$item} ne 'any') {
6427: push(@{$changes{'cancreate'}},$item);
6428: }
6429: } else {
6430: if ($cancreate{$item} ne 'none') {
6431: push(@{$changes{'cancreate'}},$item);
6432: }
1.27 raeburn 6433: }
6434: }
6435: } else {
1.43 raeburn 6436: foreach my $item (@contexts) {
1.34 raeburn 6437: push(@{$changes{'cancreate'}},$item);
6438: }
1.27 raeburn 6439: }
1.34 raeburn 6440:
1.27 raeburn 6441: if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
6442: foreach my $type (@{$curr_usercreation{'username_rule'}}) {
6443: if (!grep(/^\Q$type\E$/,@username_rule)) {
6444: push(@{$changes{'username_rule'}},$type);
6445: }
6446: }
6447: foreach my $type (@username_rule) {
6448: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
6449: push(@{$changes{'username_rule'}},$type);
6450: }
6451: }
6452: } else {
6453: push(@{$changes{'username_rule'}},@username_rule);
6454: }
6455:
1.32 raeburn 6456: if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
6457: foreach my $type (@{$curr_usercreation{'id_rule'}}) {
6458: if (!grep(/^\Q$type\E$/,@id_rule)) {
6459: push(@{$changes{'id_rule'}},$type);
6460: }
6461: }
6462: foreach my $type (@id_rule) {
6463: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
6464: push(@{$changes{'id_rule'}},$type);
6465: }
6466: }
6467: } else {
6468: push(@{$changes{'id_rule'}},@id_rule);
6469: }
6470:
1.43 raeburn 6471: if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
6472: foreach my $type (@{$curr_usercreation{'email_rule'}}) {
6473: if (!grep(/^\Q$type\E$/,@email_rule)) {
6474: push(@{$changes{'email_rule'}},$type);
6475: }
6476: }
6477: foreach my $type (@email_rule) {
6478: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'email_rule'}})) {
6479: push(@{$changes{'email_rule'}},$type);
6480: }
6481: }
6482: } else {
6483: push(@{$changes{'email_rule'}},@email_rule);
6484: }
6485:
6486: my @authen_contexts = ('author','course','domain');
1.28 raeburn 6487: my @authtypes = ('int','krb4','krb5','loc');
6488: my %authhash;
1.43 raeburn 6489: foreach my $item (@authen_contexts) {
1.28 raeburn 6490: my @authallowed = &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
6491: foreach my $auth (@authtypes) {
6492: if (grep(/^\Q$auth\E$/,@authallowed)) {
6493: $authhash{$item}{$auth} = 1;
6494: } else {
6495: $authhash{$item}{$auth} = 0;
6496: }
6497: }
6498: }
6499: if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
1.43 raeburn 6500: foreach my $item (@authen_contexts) {
1.28 raeburn 6501: if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
6502: foreach my $auth (@authtypes) {
6503: if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
6504: push(@{$changes{'authtypes'}},$item);
6505: last;
6506: }
6507: }
6508: }
6509: }
6510: } else {
1.43 raeburn 6511: foreach my $item (@authen_contexts) {
1.28 raeburn 6512: push(@{$changes{'authtypes'}},$item);
6513: }
6514: }
6515:
1.27 raeburn 6516: my %usercreation_hash = (
1.28 raeburn 6517: usercreation => {
1.34 raeburn 6518: cancreate => \%cancreate,
1.27 raeburn 6519: username_rule => \@username_rule,
1.32 raeburn 6520: id_rule => \@id_rule,
1.43 raeburn 6521: email_rule => \@email_rule,
1.32 raeburn 6522: authtypes => \%authhash,
1.27 raeburn 6523: }
6524: );
6525:
6526: my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
6527: $dom);
1.50 raeburn 6528:
6529: my %selfcreatetypes = (
6530: sso => 'users authenticated by institutional single sign on',
6531: login => 'users authenticated by institutional log-in',
6532: email => 'users who provide a valid e-mail address for use as the username',
6533: );
1.27 raeburn 6534: if ($putresult eq 'ok') {
6535: if (keys(%changes) > 0) {
6536: $resulttext = &mt('Changes made:').'<ul>';
6537: if (ref($changes{'cancreate'}) eq 'ARRAY') {
1.34 raeburn 6538: my %lt = &usercreation_types();
6539: foreach my $type (@{$changes{'cancreate'}}) {
1.100 raeburn 6540: my $chgtext;
1.165 raeburn 6541: unless (($type eq 'statustocreate') || ($type eq 'captcha') || ($type eq 'recaptchakeys')) {
1.100 raeburn 6542: $chgtext = $lt{$type}.', ';
6543: }
1.45 raeburn 6544: if ($type eq 'selfcreate') {
1.50 raeburn 6545: if (@{$cancreate{$type}} == 0) {
1.43 raeburn 6546: $chgtext .= &mt('creation of a new user account is not permitted.');
1.50 raeburn 6547: } else {
1.100 raeburn 6548: $chgtext .= &mt('creation of a new account is permitted for:').'<ul>';
1.50 raeburn 6549: foreach my $case (@{$cancreate{$type}}) {
6550: $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
6551: }
6552: $chgtext .= '</ul>';
1.100 raeburn 6553: if (ref($cancreate{$type}) eq 'ARRAY') {
6554: if (grep(/^(login|sso)$/,@{$cancreate{$type}})) {
6555: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
6556: if (@{$cancreate{'statustocreate'}} == 0) {
6557: $chgtext .= '<br /><span class="LC_warning">'.&mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").'</span>';
6558: }
6559: }
6560: }
6561: }
1.43 raeburn 6562: }
1.93 raeburn 6563: } elsif ($type eq 'statustocreate') {
1.96 raeburn 6564: if ((ref($cancreate{'selfcreate'}) eq 'ARRAY') &&
6565: (ref($cancreate{'statustocreate'}) eq 'ARRAY')) {
6566: if (@{$cancreate{'selfcreate'}} > 0) {
6567: if (@{$cancreate{'statustocreate'}} == 0) {
1.100 raeburn 6568:
6569: $chgtext .= &mt("Institutional affiliations permitted to create accounts set to 'None'.");
1.96 raeburn 6570: if (!grep(/^email$/,@{$cancreate{'selfcreate'}})) {
1.100 raeburn 6571: $chgtext .= '<br /><span class="LC_warning">'.&mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").'</span>';
6572: }
1.96 raeburn 6573: } elsif (ref($usertypes) eq 'HASH') {
6574: if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.100 raeburn 6575: $chgtext .= &mt('Creation of a new account for an institutional user is restricted to the following institutional affiliation(s):');
6576: } else {
6577: $chgtext .= &mt('Institutional affiliations permitted to create accounts with institutional authentication were set as follows:');
6578: }
6579: $chgtext .= '<ul>';
6580: foreach my $case (@{$cancreate{$type}}) {
6581: if ($case eq 'default') {
6582: $chgtext .= '<li>'.$othertitle.'</li>';
6583: } else {
6584: $chgtext .= '<li>'.$usertypes->{$case}.'</li>';
1.93 raeburn 6585: }
6586: }
1.100 raeburn 6587: $chgtext .= '</ul>';
6588: if (!grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
6589: $chgtext .= '<br /><span class="LC_warning">'.&mt('However, users authenticated by institutional login/single sign on are not currently permitted to create accounts.').'</span>';
6590: }
6591: }
6592: } else {
6593: if (@{$cancreate{$type}} == 0) {
6594: $chgtext .= &mt("Institutional affiliations permitted to create accounts were set to 'none'.");
6595: } else {
6596: $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 6597: }
6598: }
6599: }
1.165 raeburn 6600: } elsif ($type eq 'captcha') {
6601: if ($cancreate{$type} eq 'notused') {
6602: $chgtext .= &mt('No CAPTCHA validation in use for self-creation screen.');
6603: } else {
6604: my %captchas = &captcha_phrases();
6605: if ($captchas{$cancreate{$type}}) {
6606: $chgtext .= &mt("Validation for self-creation screen set to $captchas{$cancreate{$type}}.");
6607: } else {
6608: $chgtext .= &mt('Validation for self-creation screen set to unknown type.');
6609: }
6610: }
6611: } elsif ($type eq 'recaptchakeys') {
6612: my ($privkey,$pubkey);
6613: if (ref($cancreate{$type}) eq 'HASH') {
6614: $pubkey = $cancreate{$type}{'public'};
6615: $privkey = $cancreate{$type}{'private'};
6616: }
6617: $chgtext .= &mt('ReCAPTCHA keys changes').'<ul>';
6618: if (!$pubkey) {
6619: $chgtext .= '<li>'.&mt('Public key deleted').'</li>';
6620: } else {
6621: $chgtext .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
6622: }
6623: if (!$privkey) {
6624: $chgtext .= '<li>'.&mt('Private key deleted').'</li>';
6625: } else {
6626: $chgtext .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
6627: }
6628: $chgtext .= '</ul>';
1.43 raeburn 6629: } else {
6630: if ($cancreate{$type} eq 'none') {
6631: $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
6632: } elsif ($cancreate{$type} eq 'any') {
6633: $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
6634: } elsif ($cancreate{$type} eq 'official') {
6635: $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
6636: } elsif ($cancreate{$type} eq 'unofficial') {
6637: $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
6638: }
1.34 raeburn 6639: }
6640: $resulttext .= '<li>'.$chgtext.'</li>';
1.27 raeburn 6641: }
6642: }
6643: if (ref($changes{'username_rule'}) eq 'ARRAY') {
1.32 raeburn 6644: my ($rules,$ruleorder) =
6645: &Apache::lonnet::inst_userrules($dom,'username');
1.27 raeburn 6646: my $chgtext = '<ul>';
6647: foreach my $type (@username_rule) {
6648: if (ref($rules->{$type}) eq 'HASH') {
6649: $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
6650: }
6651: }
6652: $chgtext .= '</ul>';
6653: if (@username_rule > 0) {
6654: $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
6655: } else {
1.28 raeburn 6656: $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>';
1.27 raeburn 6657: }
6658: }
1.32 raeburn 6659: if (ref($changes{'id_rule'}) eq 'ARRAY') {
6660: my ($idrules,$idruleorder) =
6661: &Apache::lonnet::inst_userrules($dom,'id');
6662: my $chgtext = '<ul>';
6663: foreach my $type (@id_rule) {
6664: if (ref($idrules->{$type}) eq 'HASH') {
6665: $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
6666: }
6667: }
6668: $chgtext .= '</ul>';
6669: if (@id_rule > 0) {
6670: $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
6671: } else {
6672: $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
6673: }
6674: }
1.43 raeburn 6675: if (ref($changes{'email_rule'}) eq 'ARRAY') {
6676: my ($emailrules,$emailruleorder) =
6677: &Apache::lonnet::inst_userrules($dom,'email');
6678: my $chgtext = '<ul>';
6679: foreach my $type (@email_rule) {
6680: if (ref($emailrules->{$type}) eq 'HASH') {
6681: $chgtext .= '<li>'.$emailrules->{$type}{'name'}.'</li>';
6682: }
6683: }
6684: $chgtext .= '</ul>';
6685: if (@email_rule > 0) {
6686: $resulttext .= '<li>'.&mt('Accounts may not be created by users self-enrolling with e-mail addresses of the following types: ').$chgtext.'</li>';
6687: } else {
6688: $resulttext .= '<li>'.&mt('There are now no restrictions on e-mail addresses which may be used as a username when self-enrolling.').'</li>';
6689: }
6690: }
6691:
1.28 raeburn 6692: my %authname = &authtype_names();
6693: my %context_title = &context_names();
6694: if (ref($changes{'authtypes'}) eq 'ARRAY') {
6695: my $chgtext = '<ul>';
6696: foreach my $type (@{$changes{'authtypes'}}) {
6697: my @allowed;
6698: $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
6699: foreach my $auth (@authtypes) {
6700: if ($authhash{$type}{$auth}) {
6701: push(@allowed,$authname{$auth});
6702: }
6703: }
1.43 raeburn 6704: if (@allowed > 0) {
6705: $chgtext .= join(', ',@allowed).'</li>';
6706: } else {
6707: $chgtext .= &mt('none').'</li>';
6708: }
1.28 raeburn 6709: }
6710: $chgtext .= '</ul>';
6711: $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
6712: $resulttext .= '</li>';
6713: }
1.27 raeburn 6714: $resulttext .= '</ul>';
6715: } else {
1.28 raeburn 6716: $resulttext = &mt('No changes made to user creation settings');
1.27 raeburn 6717: }
6718: } else {
6719: $resulttext = '<span class="LC_error">'.
1.23 raeburn 6720: &mt('An error occurred: [_1]',$putresult).'</span>';
6721: }
1.43 raeburn 6722: if ($warningmsg ne '') {
6723: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
6724: }
1.23 raeburn 6725: return $resulttext;
6726: }
6727:
1.165 raeburn 6728: sub process_captcha {
6729: my ($container,$changes,$newsettings,$current) = @_;
6730: return unless ((ref($changes) eq 'HASH') && (ref($newsettings) eq 'HASH') || (ref($current) eq 'HASH'));
6731: $newsettings->{'captcha'} = $env{'form.'.$container.'_captcha'};
6732: unless ($newsettings->{'captcha'} eq 'recaptcha' || $newsettings->{'captcha'} eq 'notused') {
6733: $newsettings->{'captcha'} = 'original';
6734: }
6735: if ($current->{'captcha'} ne $newsettings->{'captcha'}) {
6736: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
6737: push(@{$changes->{'cancreate'}},'captcha');
6738: } elsif (!defined($changes->{'cancreate'})) {
6739: $changes->{'cancreate'} = ['captcha'];
6740: }
6741: }
6742: my ($newpub,$newpriv,$currpub,$currpriv);
6743: if ($newsettings->{'captcha'} eq 'recaptcha') {
6744: $newpub = $env{'form.'.$container.'_recaptchapub'};
6745: $newpriv = $env{'form.'.$container.'_recaptchapriv'};
6746: }
6747: $newsettings->{'recaptchakeys'} = {
6748: public => $newpub,
6749: private => $newpriv,
6750: };
6751: if (ref($current->{'recaptchakeys'}) eq 'HASH') {
6752: $currpub = $current->{'recaptchakeys'}{'public'};
6753: $currpriv = $current->{'recaptchakeys'}{'private'};
6754: }
6755: if (($newpub ne $currpub) || ($newpriv ne $currpriv)) {
6756: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
6757: push(@{$changes->{'cancreate'}},'recaptchakeys');
6758: } elsif (!defined($changes->{'cancreate'})) {
6759: $changes->{'cancreate'} = ['recaptchakeys'];
6760: }
6761: }
6762: return;
6763: }
6764:
1.33 raeburn 6765: sub modify_usermodification {
6766: my ($dom,%domconfig) = @_;
6767: my ($resulttext,%curr_usermodification,%changes);
6768: if (ref($domconfig{'usermodification'}) eq 'HASH') {
6769: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
6770: $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
6771: }
6772: }
1.63 raeburn 6773: my @contexts = ('author','course','selfcreate');
1.33 raeburn 6774: my %context_title = (
6775: author => 'In author context',
6776: course => 'In course context',
1.63 raeburn 6777: selfcreate => 'When self creating account',
1.33 raeburn 6778: );
6779: my @fields = ('lastname','firstname','middlename','generation',
6780: 'permanentemail','id');
6781: my %roles = (
6782: author => ['ca','aa'],
6783: course => ['st','ep','ta','in','cr'],
6784: );
1.63 raeburn 6785: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
6786: if (ref($types) eq 'ARRAY') {
6787: push(@{$types},'default');
6788: $usertypes->{'default'} = $othertitle;
6789: }
6790: $roles{'selfcreate'} = $types;
1.33 raeburn 6791: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
6792: my %modifyhash;
6793: foreach my $context (@contexts) {
6794: foreach my $role (@{$roles{$context}}) {
6795: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$role);
6796: foreach my $item (@fields) {
6797: if (grep(/^\Q$item\E$/,@modifiable)) {
6798: $modifyhash{$context}{$role}{$item} = 1;
6799: } else {
6800: $modifyhash{$context}{$role}{$item} = 0;
6801: }
6802: }
6803: }
6804: if (ref($curr_usermodification{$context}) eq 'HASH') {
6805: foreach my $role (@{$roles{$context}}) {
6806: if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
6807: foreach my $field (@fields) {
6808: if ($modifyhash{$context}{$role}{$field} ne
6809: $curr_usermodification{$context}{$role}{$field}) {
6810: push(@{$changes{$context}},$role);
6811: last;
6812: }
6813: }
6814: }
6815: }
6816: } else {
6817: foreach my $context (@contexts) {
6818: foreach my $role (@{$roles{$context}}) {
6819: push(@{$changes{$context}},$role);
6820: }
6821: }
6822: }
6823: }
6824: my %usermodification_hash = (
6825: usermodification => \%modifyhash,
6826: );
6827: my $putresult = &Apache::lonnet::put_dom('configuration',
6828: \%usermodification_hash,$dom);
6829: if ($putresult eq 'ok') {
6830: if (keys(%changes) > 0) {
6831: $resulttext = &mt('Changes made: ').'<ul>';
6832: foreach my $context (@contexts) {
6833: if (ref($changes{$context}) eq 'ARRAY') {
6834: $resulttext .= '<li>'.$context_title{$context}.':<ul>';
6835: if (ref($changes{$context}) eq 'ARRAY') {
6836: foreach my $role (@{$changes{$context}}) {
6837: my $rolename;
1.63 raeburn 6838: if ($context eq 'selfcreate') {
6839: $rolename = $role;
6840: if (ref($usertypes) eq 'HASH') {
6841: if ($usertypes->{$role} ne '') {
6842: $rolename = $usertypes->{$role};
6843: }
6844: }
1.33 raeburn 6845: } else {
1.63 raeburn 6846: if ($role eq 'cr') {
6847: $rolename = &mt('Custom');
6848: } else {
6849: $rolename = &Apache::lonnet::plaintext($role);
6850: }
1.33 raeburn 6851: }
6852: my @modifiable;
1.63 raeburn 6853: if ($context eq 'selfcreate') {
1.126 bisitz 6854: $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Self-creation of account by users with status: [_1]',$rolename).'</span> - '.&mt('modifiable fields (if institutional data blank): ');
1.63 raeburn 6855: } else {
6856: $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
6857: }
1.33 raeburn 6858: foreach my $field (@fields) {
6859: if ($modifyhash{$context}{$role}{$field}) {
6860: push(@modifiable,$fieldtitles{$field});
6861: }
6862: }
6863: if (@modifiable > 0) {
6864: $resulttext .= join(', ',@modifiable);
6865: } else {
6866: $resulttext .= &mt('none');
6867: }
6868: $resulttext .= '</li>';
6869: }
6870: $resulttext .= '</ul></li>';
6871: }
6872: }
6873: }
6874: $resulttext .= '</ul>';
6875: } else {
6876: $resulttext = &mt('No changes made to user modification settings');
6877: }
6878: } else {
6879: $resulttext = '<span class="LC_error">'.
6880: &mt('An error occurred: [_1]',$putresult).'</span>';
6881: }
6882: return $resulttext;
6883: }
6884:
1.43 raeburn 6885: sub modify_defaults {
6886: my ($dom,$r) = @_;
6887: my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
6888: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.141 raeburn 6889: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def','portal_def');
1.43 raeburn 6890: my @authtypes = ('internal','krb4','krb5','localauth');
6891: foreach my $item (@items) {
6892: $newvalues{$item} = $env{'form.'.$item};
6893: if ($item eq 'auth_def') {
6894: if ($newvalues{$item} ne '') {
6895: if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
6896: push(@errors,$item);
6897: }
6898: }
6899: } elsif ($item eq 'lang_def') {
6900: if ($newvalues{$item} ne '') {
6901: if ($newvalues{$item} =~ /^(\w+)/) {
6902: my $langcode = $1;
1.103 raeburn 6903: if ($langcode ne 'x_chef') {
6904: if (code2language($langcode) eq '') {
6905: push(@errors,$item);
6906: }
1.43 raeburn 6907: }
6908: } else {
6909: push(@errors,$item);
6910: }
6911: }
1.54 raeburn 6912: } elsif ($item eq 'timezone_def') {
6913: if ($newvalues{$item} ne '') {
1.62 raeburn 6914: if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
1.54 raeburn 6915: push(@errors,$item);
6916: }
6917: }
1.68 raeburn 6918: } elsif ($item eq 'datelocale_def') {
6919: if ($newvalues{$item} ne '') {
6920: my @datelocale_ids = DateTime::Locale->ids();
6921: if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
6922: push(@errors,$item);
6923: }
6924: }
1.141 raeburn 6925: } elsif ($item eq 'portal_def') {
6926: if ($newvalues{$item} ne '') {
6927: 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])\/?$/) {
6928: push(@errors,$item);
6929: }
6930: }
1.43 raeburn 6931: }
6932: if (grep(/^\Q$item\E$/,@errors)) {
6933: $newvalues{$item} = $domdefaults{$item};
6934: } elsif ($domdefaults{$item} ne $newvalues{$item}) {
6935: $changes{$item} = 1;
6936: }
1.72 raeburn 6937: $domdefaults{$item} = $newvalues{$item};
1.43 raeburn 6938: }
6939: my %defaults_hash = (
1.72 raeburn 6940: defaults => \%newvalues,
6941: );
1.43 raeburn 6942: my $title = &defaults_titles();
6943: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
6944: $dom);
6945: if ($putresult eq 'ok') {
6946: if (keys(%changes) > 0) {
6947: $resulttext = &mt('Changes made:').'<ul>';
6948: my $version = $r->dir_config('lonVersion');
6949: 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";
6950: foreach my $item (sort(keys(%changes))) {
6951: my $value = $env{'form.'.$item};
6952: if ($value eq '') {
6953: $value = &mt('none');
6954: } elsif ($item eq 'auth_def') {
6955: my %authnames = &authtype_names();
6956: my %shortauth = (
6957: internal => 'int',
6958: krb4 => 'krb4',
6959: krb5 => 'krb5',
6960: localauth => 'loc',
6961: );
6962: $value = $authnames{$shortauth{$value}};
6963: }
6964: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
6965: $mailmsgtext .= "$title->{$item} set to $value\n";
6966: }
6967: $resulttext .= '</ul>';
6968: $mailmsgtext .= "\n";
6969: my $cachetime = 24*60*60;
1.72 raeburn 6970: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.68 raeburn 6971: if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
1.54 raeburn 6972: my $sysmail = $r->dir_config('lonSysEMail');
6973: &Apache::lonmsg::sendemail($sysmail,"LON-CAPA Domain Settings Change - $dom",$mailmsgtext);
6974: }
1.43 raeburn 6975: } else {
1.54 raeburn 6976: $resulttext = &mt('No changes made to default authentication/language/timezone settings');
1.43 raeburn 6977: }
6978: } else {
6979: $resulttext = '<span class="LC_error">'.
6980: &mt('An error occurred: [_1]',$putresult).'</span>';
6981: }
6982: if (@errors > 0) {
6983: $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
6984: foreach my $item (@errors) {
6985: $resulttext .= ' "'.$title->{$item}.'",';
6986: }
6987: $resulttext =~ s/,$//;
6988: }
6989: return $resulttext;
6990: }
6991:
1.46 raeburn 6992: sub modify_scantron {
1.48 raeburn 6993: my ($r,$dom,$confname,%domconfig) = @_;
1.46 raeburn 6994: my ($resulttext,%confhash,%changes,$errors);
6995: my $custom = 'custom.tab';
6996: my $default = 'default.tab';
6997: my $servadm = $r->dir_config('lonAdmEMail');
6998: my ($configuserok,$author_ok,$switchserver) =
6999: &config_check($dom,$confname,$servadm);
7000: if ($env{'form.scantronformat.filename'} ne '') {
7001: my $error;
7002: if ($configuserok eq 'ok') {
7003: if ($switchserver) {
1.130 raeburn 7004: $error = &mt("Upload of bubblesheet format file is not permitted to this server: [_1]",$switchserver);
1.46 raeburn 7005: } else {
7006: if ($author_ok eq 'ok') {
7007: my ($result,$scantronurl) =
7008: &publishlogo($r,'upload','scantronformat',$dom,
7009: $confname,'scantron','','',$custom);
7010: if ($result eq 'ok') {
7011: $confhash{'scantron'}{'scantronformat'} = $scantronurl;
1.48 raeburn 7012: $changes{'scantronformat'} = 1;
1.46 raeburn 7013: } else {
7014: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
7015: }
7016: } else {
7017: $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);
7018: }
7019: }
7020: } else {
7021: $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);
7022: }
7023: if ($error) {
7024: &Apache::lonnet::logthis($error);
7025: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
7026: }
7027: }
1.48 raeburn 7028: if (ref($domconfig{'scantron'}) eq 'HASH') {
7029: if ($domconfig{'scantron'}{'scantronformat'} ne '') {
7030: if ($env{'form.scantronformat_del'}) {
7031: $confhash{'scantron'}{'scantronformat'} = '';
7032: $changes{'scantronformat'} = 1;
1.46 raeburn 7033: }
7034: }
7035: }
7036: if (keys(%confhash) > 0) {
7037: my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
7038: $dom);
7039: if ($putresult eq 'ok') {
7040: if (keys(%changes) > 0) {
1.48 raeburn 7041: if (ref($confhash{'scantron'}) eq 'HASH') {
7042: $resulttext = &mt('Changes made:').'<ul>';
7043: if ($confhash{'scantron'}{'scantronformat'} eq '') {
1.130 raeburn 7044: $resulttext .= '<li>'.&mt('[_1] bubblesheet format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
1.48 raeburn 7045: } else {
1.130 raeburn 7046: $resulttext .= '<li>'.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
1.46 raeburn 7047: }
1.48 raeburn 7048: $resulttext .= '</ul>';
7049: } else {
1.130 raeburn 7050: $resulttext = &mt('Changes made to bubblesheet format file.');
1.46 raeburn 7051: }
7052: $resulttext .= '</ul>';
7053: &Apache::loncommon::devalidate_domconfig_cache($dom);
7054: } else {
1.130 raeburn 7055: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 7056: }
7057: } else {
7058: $resulttext = '<span class="LC_error">'.
7059: &mt('An error occurred: [_1]',$putresult).'</span>';
7060: }
7061: } else {
1.130 raeburn 7062: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 7063: }
7064: if ($errors) {
7065: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
7066: $errors.'</ul>';
7067: }
7068: return $resulttext;
7069: }
7070:
1.48 raeburn 7071: sub modify_coursecategories {
7072: my ($dom,%domconfig) = @_;
1.57 raeburn 7073: my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
7074: $cathash);
1.48 raeburn 7075: my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
1.55 raeburn 7076: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
1.57 raeburn 7077: $cathash = $domconfig{'coursecategories'}{'cats'};
7078: if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
7079: $changes{'togglecats'} = 1;
7080: $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
7081: }
7082: if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
7083: $changes{'categorize'} = 1;
7084: $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
7085: }
1.120 raeburn 7086: if ($domconfig{'coursecategories'}{'togglecatscomm'} ne $env{'form.togglecatscomm'}) {
7087: $changes{'togglecatscomm'} = 1;
7088: $domconfig{'coursecategories'}{'togglecatscomm'} = $env{'form.togglecatscomm'};
7089: }
7090: if ($domconfig{'coursecategories'}{'categorizecomm'} ne $env{'form.categorizecomm'}) {
7091: $changes{'categorizecomm'} = 1;
7092: $domconfig{'coursecategories'}{'categorizecomm'} = $env{'form.categorizecomm'};
7093: }
1.57 raeburn 7094: } else {
7095: $changes{'togglecats'} = 1;
7096: $changes{'categorize'} = 1;
1.124 raeburn 7097: $changes{'togglecatscomm'} = 1;
7098: $changes{'categorizecomm'} = 1;
1.87 raeburn 7099: $domconfig{'coursecategories'} = {
7100: togglecats => $env{'form.togglecats'},
7101: categorize => $env{'form.categorize'},
1.124 raeburn 7102: togglecatscomm => $env{'form.togglecatscomm'},
7103: categorizecomm => $env{'form.categorizecomm'},
1.120 raeburn 7104: };
1.57 raeburn 7105: }
7106: if (ref($cathash) eq 'HASH') {
7107: if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '') && ($env{'form.instcode'} == 0)) {
1.55 raeburn 7108: push (@deletecategory,'instcode::0');
7109: }
1.120 raeburn 7110: if (($domconfig{'coursecategories'}{'cats'}{'communities::0'} ne '') && ($env{'form.communities'} == 0)) {
7111: push(@deletecategory,'communities::0');
7112: }
1.48 raeburn 7113: }
1.57 raeburn 7114: my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
7115: if (ref($cathash) eq 'HASH') {
1.48 raeburn 7116: if (@deletecategory > 0) {
7117: #FIXME Need to remove category from all courses using a deleted category
1.57 raeburn 7118: &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
1.48 raeburn 7119: foreach my $item (@deletecategory) {
1.57 raeburn 7120: if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
7121: delete($domconfig{'coursecategories'}{'cats'}{$item});
1.48 raeburn 7122: $deletions{$item} = 1;
1.57 raeburn 7123: &recurse_cat_deletes($item,$cathash,\%deletions);
1.48 raeburn 7124: }
7125: }
7126: }
1.57 raeburn 7127: foreach my $item (keys(%{$cathash})) {
1.48 raeburn 7128: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
1.57 raeburn 7129: if ($cathash->{$item} ne $env{'form.'.$item}) {
1.48 raeburn 7130: $reorderings{$item} = 1;
1.57 raeburn 7131: $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
1.48 raeburn 7132: }
7133: if ($env{'form.addcategory_name_'.$item} ne '') {
7134: my $newcat = $env{'form.addcategory_name_'.$item};
7135: my $newdepth = $depth+1;
7136: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 7137: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
1.48 raeburn 7138: $adds{$newitem} = 1;
7139: }
7140: if ($env{'form.subcat_'.$item} ne '') {
7141: my $newcat = $env{'form.subcat_'.$item};
7142: my $newdepth = $depth+1;
7143: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 7144: $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
1.48 raeburn 7145: $adds{$newitem} = 1;
7146: }
7147: }
7148: }
7149: if ($env{'form.instcode'} eq '1') {
1.57 raeburn 7150: if (ref($cathash) eq 'HASH') {
1.48 raeburn 7151: my $newitem = 'instcode::0';
1.57 raeburn 7152: if ($cathash->{$newitem} eq '') {
7153: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 7154: $adds{$newitem} = 1;
7155: }
7156: } else {
7157: my $newitem = 'instcode::0';
1.57 raeburn 7158: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 7159: $adds{$newitem} = 1;
7160: }
7161: }
1.120 raeburn 7162: if ($env{'form.communities'} eq '1') {
7163: if (ref($cathash) eq 'HASH') {
7164: my $newitem = 'communities::0';
7165: if ($cathash->{$newitem} eq '') {
7166: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
7167: $adds{$newitem} = 1;
7168: }
7169: } else {
7170: my $newitem = 'communities::0';
7171: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
7172: $adds{$newitem} = 1;
7173: }
7174: }
1.48 raeburn 7175: if ($env{'form.addcategory_name'} ne '') {
1.120 raeburn 7176: if (($env{'form.addcategory_name'} ne 'instcode') &&
7177: ($env{'form.addcategory_name'} ne 'communities')) {
7178: my $newitem = &escape($env{'form.addcategory_name'}).'::0';
7179: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
7180: $adds{$newitem} = 1;
7181: }
1.48 raeburn 7182: }
1.57 raeburn 7183: my $putresult;
1.48 raeburn 7184: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
7185: if (keys(%deletions) > 0) {
7186: foreach my $key (keys(%deletions)) {
7187: if ($predelallitems{$key} ne '') {
7188: $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
7189: }
7190: }
7191: }
7192: my (@chkcats,@chktrails,%chkallitems);
1.57 raeburn 7193: &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
1.48 raeburn 7194: if (ref($chkcats[0]) eq 'ARRAY') {
7195: my $depth = 0;
7196: my $chg = 0;
7197: for (my $i=0; $i<@{$chkcats[0]}; $i++) {
7198: my $name = $chkcats[0][$i];
7199: my $item;
7200: if ($name eq '') {
7201: $chg ++;
7202: } else {
7203: $item = &escape($name).'::0';
7204: if ($chg) {
1.57 raeburn 7205: $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
1.48 raeburn 7206: }
7207: $depth ++;
1.57 raeburn 7208: &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
1.48 raeburn 7209: $depth --;
7210: }
7211: }
7212: }
1.57 raeburn 7213: }
7214: if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
7215: $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
1.48 raeburn 7216: if ($putresult eq 'ok') {
1.57 raeburn 7217: my %title = (
1.120 raeburn 7218: togglecats => 'Show/Hide a course in catalog',
7219: categorize => 'Assign a category to a course',
7220: togglecatscomm => 'Show/Hide a community in catalog',
7221: categorizecomm => 'Assign a category to a community',
1.57 raeburn 7222: );
7223: my %level = (
1.120 raeburn 7224: dom => 'set in Domain ("Modify Course/Community")',
7225: crs => 'set in Course ("Course Configuration")',
7226: comm => 'set in Community ("Community Configuration")',
1.57 raeburn 7227: );
1.48 raeburn 7228: $resulttext = &mt('Changes made:').'<ul>';
1.57 raeburn 7229: if ($changes{'togglecats'}) {
7230: $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>';
7231: }
7232: if ($changes{'categorize'}) {
7233: $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
1.48 raeburn 7234: }
1.120 raeburn 7235: if ($changes{'togglecatscomm'}) {
7236: $resulttext .= '<li>'.&mt("$title{'togglecatscomm'} $level{$env{'form.togglecatscomm'}}").'</li>';
7237: }
7238: if ($changes{'categorizecomm'}) {
7239: $resulttext .= '<li>'.&mt("$title{'categorizecomm'} $level{$env{'form.categorizecomm'}}").'</li>';
7240: }
1.57 raeburn 7241: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
7242: my $cathash;
7243: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
7244: $cathash = $domconfig{'coursecategories'}{'cats'};
7245: } else {
7246: $cathash = {};
7247: }
7248: my (@cats,@trails,%allitems);
7249: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
7250: if (keys(%deletions) > 0) {
7251: $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
7252: foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) {
7253: $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
7254: }
7255: $resulttext .= '</ul></li>';
7256: }
7257: if (keys(%reorderings) > 0) {
7258: my %sort_by_trail;
7259: $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
7260: foreach my $key (keys(%reorderings)) {
7261: if ($allitems{$key} ne '') {
7262: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
7263: }
1.48 raeburn 7264: }
1.57 raeburn 7265: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
7266: $resulttext .= '<li>'.$trails[$trail].'</li>';
7267: }
7268: $resulttext .= '</ul></li>';
1.48 raeburn 7269: }
1.57 raeburn 7270: if (keys(%adds) > 0) {
7271: my %sort_by_trail;
7272: $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
7273: foreach my $key (keys(%adds)) {
7274: if ($allitems{$key} ne '') {
7275: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
7276: }
7277: }
7278: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
7279: $resulttext .= '<li>'.$trails[$trail].'</li>';
1.48 raeburn 7280: }
1.57 raeburn 7281: $resulttext .= '</ul></li>';
1.48 raeburn 7282: }
7283: }
7284: $resulttext .= '</ul>';
7285: } else {
7286: $resulttext = '<span class="LC_error">'.
1.57 raeburn 7287: &mt('An error occurred: [_1]',$putresult).'</span>';
1.48 raeburn 7288: }
7289: } else {
1.120 raeburn 7290: $resulttext = &mt('No changes made to course and community categories');
1.48 raeburn 7291: }
7292: return $resulttext;
7293: }
7294:
1.69 raeburn 7295: sub modify_serverstatuses {
7296: my ($dom,%domconfig) = @_;
7297: my ($resulttext,%changes,%currserverstatus,%newserverstatus);
7298: if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
7299: %currserverstatus = %{$domconfig{'serverstatuses'}};
7300: }
7301: my @pages = &serverstatus_pages();
7302: foreach my $type (@pages) {
7303: $newserverstatus{$type}{'namedusers'} = '';
7304: $newserverstatus{$type}{'machines'} = '';
7305: if (defined($env{'form.'.$type.'_namedusers'})) {
7306: my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
7307: my @okusers;
7308: foreach my $user (@users) {
7309: my ($uname,$udom) = split(/:/,$user);
7310: if (($udom =~ /^$match_domain$/) &&
7311: (&Apache::lonnet::domain($udom)) &&
7312: ($uname =~ /^$match_username$/)) {
7313: if (!grep(/^\Q$user\E/,@okusers)) {
7314: push(@okusers,$user);
7315: }
7316: }
7317: }
7318: if (@okusers > 0) {
7319: @okusers = sort(@okusers);
7320: $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
7321: }
7322: }
7323: if (defined($env{'form.'.$type.'_machines'})) {
7324: my @machines = split(/,/,$env{'form.'.$type.'_machines'});
7325: my @okmachines;
7326: foreach my $ip (@machines) {
7327: my @parts = split(/\./,$ip);
7328: next if (@parts < 4);
7329: my $badip = 0;
7330: for (my $i=0; $i<4; $i++) {
7331: if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
7332: $badip = 1;
7333: last;
7334: }
7335: }
7336: if (!$badip) {
7337: push(@okmachines,$ip);
7338: }
7339: }
7340: @okmachines = sort(@okmachines);
7341: $newserverstatus{$type}{'machines'} = join(',',@okmachines);
7342: }
7343: }
7344: my %serverstatushash = (
7345: serverstatuses => \%newserverstatus,
7346: );
7347: foreach my $type (@pages) {
1.83 raeburn 7348: foreach my $setting ('namedusers','machines') {
1.84 raeburn 7349: my (@current,@new);
1.83 raeburn 7350: if (ref($currserverstatus{$type}) eq 'HASH') {
1.84 raeburn 7351: if ($currserverstatus{$type}{$setting} ne '') {
7352: @current = split(/,/,$currserverstatus{$type}{$setting});
7353: }
7354: }
7355: if ($newserverstatus{$type}{$setting} ne '') {
7356: @new = split(/,/,$newserverstatus{$type}{$setting});
1.83 raeburn 7357: }
7358: if (@current > 0) {
7359: if (@new > 0) {
7360: foreach my $item (@current) {
7361: if (!grep(/^\Q$item\E$/,@new)) {
7362: $changes{$type}{$setting} = 1;
1.82 raeburn 7363: last;
7364: }
7365: }
1.84 raeburn 7366: foreach my $item (@new) {
7367: if (!grep(/^\Q$item\E$/,@current)) {
7368: $changes{$type}{$setting} = 1;
7369: last;
1.82 raeburn 7370: }
7371: }
7372: } else {
1.83 raeburn 7373: $changes{$type}{$setting} = 1;
1.69 raeburn 7374: }
1.83 raeburn 7375: } elsif (@new > 0) {
7376: $changes{$type}{$setting} = 1;
1.69 raeburn 7377: }
7378: }
7379: }
7380: if (keys(%changes) > 0) {
1.81 raeburn 7381: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 7382: my $putresult = &Apache::lonnet::put_dom('configuration',
7383: \%serverstatushash,$dom);
7384: if ($putresult eq 'ok') {
7385: $resulttext .= &mt('Changes made:').'<ul>';
7386: foreach my $type (@pages) {
1.84 raeburn 7387: if (ref($changes{$type}) eq 'HASH') {
1.69 raeburn 7388: $resulttext .= '<li>'.$titles->{$type}.'<ul>';
1.84 raeburn 7389: if ($changes{$type}{'namedusers'}) {
1.69 raeburn 7390: if ($newserverstatus{$type}{'namedusers'} eq '') {
7391: $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n";
7392: } else {
7393: $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n";
7394: }
1.84 raeburn 7395: }
7396: if ($changes{$type}{'machines'}) {
1.69 raeburn 7397: if ($newserverstatus{$type}{'machines'} eq '') {
7398: $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n";
7399: } else {
7400: $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n";
7401: }
7402:
7403: }
7404: $resulttext .= '</ul></li>';
7405: }
7406: }
7407: $resulttext .= '</ul>';
7408: } else {
7409: $resulttext = '<span class="LC_error">'.
7410: &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>';
7411:
7412: }
7413: } else {
7414: $resulttext = &mt('No changes made to access to server status pages');
7415: }
7416: return $resulttext;
7417: }
7418:
1.118 jms 7419: sub modify_helpsettings {
1.122 jms 7420: my ($r,$dom,$confname,%domconfig) = @_;
1.166 raeburn 7421: my ($resulttext,$errors,%changes,%helphash);
7422: my $customhelpfile = $env{'form.loginhelpurl.filename'};
7423: my $defaulthelpfile = '/adm/loginproblems.html';
7424: my $defaulttext = &mt('Default in use');
7425: my $servadm = $r->dir_config('lonAdmEMail');
7426: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
7427: my %defaultchecked = ('submitbugs' => 'on');
7428: my @offon = ('off','on');
7429: my %title = (
7430: submitbugs => 'Display link for users to submit a bug',
7431: loginhelpurl => 'Unauthenticated login help page set to custom file'
7432: );
1.118 jms 7433: my @toggles = ('submitbugs');
7434: $helphash{'helpsettings'} = {};
7435: if (ref($domconfig{'helpsettings'}) ne 'HASH') {
7436: if ($domconfig{'helpsettings'} eq '') {
7437: $domconfig{'helpsettings'} = {};
7438: }
7439: }
7440: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
7441: foreach my $item (@toggles) {
1.166 raeburn 7442: if ($defaultchecked{$item} eq 'on') {
7443: if ($domconfig{'helpsettings'}{$item} eq '') {
7444: if ($env{'form.'.$item} eq '0') {
7445: $changes{$item} = 1;
7446: }
7447: } elsif ($domconfig{'helpsettings'}{$item} ne $env{'form.'.$item}) {
7448: $changes{$item} = 1;
7449: }
7450: } elsif ($defaultchecked{$item} eq 'off') {
7451: if ($domconfig{'helpsettings'}{$item} eq '') {
7452: if ($env{'form.'.$item} eq '1') {
7453: $changes{$item} = 1;
7454: }
7455: } elsif ($domconfig{'helpsettings'}{$item} ne $env{'form.'.$item}) {
7456: $changes{$item} = 1;
7457: }
7458: }
7459: if (($env{'form.'.$item} eq '0') || ($env{'form.'.$item} eq '1')) {
7460: $helphash{'helpsettings'}{$item} = $env{'form.'.$item};
7461: }
7462: }
7463: if ($customhelpfile ne '') {
7464: my $error;
7465: if ($configuserok eq 'ok') {
7466: if ($switchserver) {
7467: $error = &mt("Upload of custom help file is not permitted to this server: [_1]",$switchserver);
7468: } else {
7469: if ($author_ok eq 'ok') {
7470: my ($result,$loginhelpurl) = &publishlogo($r,'upload','loginhelpurl',$dom,
7471: $confname,'help','','',$customhelpfile);
7472: if ($result eq 'ok') {
7473: $helphash{'helpsettings'}{'loginhelpurl'} = $loginhelpurl;
7474: $changes{'loginhelpurl'} = 1;
7475: } else {
7476: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$customhelpfile,$result);
7477: }
7478: } else {
7479: $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].",$customhelpfile,$confname,$dom,$author_ok);
7480: }
7481: }
7482: } else {
7483: $error = &mt("Upload of [_1] failed because a Domain Configuration user ([_2]) could not be created in domain: [_3]. Error was: [_4].",$customhelpfile,$confname,$dom,$configuserok);
7484: }
7485: if ($error) {
7486: &Apache::lonnet::logthis($error);
7487: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
7488: }
7489: }
1.122 jms 7490: if ($domconfig{'helpsettings'}{'loginhelpurl'} ne '') {
7491: if ($env{'form.loginhelpurl_del'}) {
7492: $helphash{'helpsettings'}{'loginhelpurl'} = '';
7493: $changes{'loginhelpurl'} = 1;
7494: }
7495: }
1.118 jms 7496: }
1.123 jms 7497: my $putresult;
7498: if (keys(%changes) > 0) {
1.166 raeburn 7499: $putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom);
1.123 jms 7500: } else {
1.166 raeburn 7501: $putresult = 'ok';
1.123 jms 7502: }
1.118 jms 7503: if ($putresult eq 'ok') {
7504: if (keys(%changes) > 0) {
1.166 raeburn 7505: $resulttext = &mt('Changes made:').'<ul>';
7506: foreach my $item (sort(keys(%changes))) {
7507: if ($item eq 'submitbugs') {
7508: $resulttext .= '<li>'.&mt('Display link to: [_1] set to "'.$offon[$env{'form.'.$item}].'".',
7509: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
7510: &mt('LON-CAPA bug tracker'),600,500)).'</li>';
7511: }
7512: if ($item eq 'loginhelpurl') {
7513: if ($helphash{'helpsettings'}{'loginhelpurl'} eq '') {
7514: $resulttext .= '<li>'.&mt('custom log-in help file removed.').' '.
7515: &Apache::loncommon::modal_link($defaulthelpfile,
7516: $defaulttext,600,500).'</li>';
7517: } else {
7518: $resulttext .= '<li>'.&Apache::loncommon::modal_link(
7519: $helphash{'helpsettings'}{'loginhelpurl'}.
7520: '?inhibitmenu=yes',
7521: &mt('custom log-in help file'),600,500).
7522: '</li>';
7523: }
7524: }
7525: }
7526: $resulttext .= '</ul>';
7527: } else {
7528: $resulttext = &mt('No changes made to help settings');
7529: }
1.118 jms 7530: } else {
1.166 raeburn 7531: $errors .= '<li><span class="LC_error">'.&mt('An error occurred storing the settings: [_1]',
7532: $putresult).'</span></li>';
1.118 jms 7533: }
7534: if ($errors) {
7535: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
7536: $errors.'</ul>';
7537: }
7538: return $resulttext;
7539: }
7540:
1.121 raeburn 7541: sub modify_coursedefaults {
7542: my ($dom,%domconfig) = @_;
7543: my ($resulttext,$errors,%changes,%defaultshash);
7544: my %defaultchecked = ('canuse_pdfforms' => 'off');
7545: my @offon = ('off','on');
7546: my @toggles = ('canuse_pdfforms');
7547:
7548: $defaultshash{'coursedefaults'} = {};
7549:
7550: if (ref($domconfig{'coursedefaults'}) ne 'HASH') {
7551: if ($domconfig{'coursedefaults'} eq '') {
7552: $domconfig{'coursedefaults'} = {};
7553: }
7554: }
7555:
7556: if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
7557: foreach my $item (@toggles) {
7558: if ($defaultchecked{$item} eq 'on') {
7559: if (($domconfig{'coursedefaults'}{$item} eq '') &&
7560: ($env{'form.'.$item} eq '0')) {
7561: $changes{$item} = 1;
7562: } elsif ($domconfig{'coursdefaults'}{$item} ne $env{'form.'.$item}) {
7563: $changes{$item} = 1;
7564: }
7565: } elsif ($defaultchecked{$item} eq 'off') {
7566: if (($domconfig{'coursedefaults'}{$item} eq '') &&
7567: ($env{'form.'.$item} eq '1')) {
7568: $changes{$item} = 1;
7569: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
7570: $changes{$item} = 1;
7571: }
7572: }
7573: $defaultshash{'coursedefaults'}{$item} = $env{'form.'.$item};
7574: }
1.139 raeburn 7575: my $currdefresponder = $domconfig{'coursedefaults'}{'anonsurvey_threshold'};
7576: my $newdefresponder = $env{'form.anonsurvey_threshold'};
7577: $newdefresponder =~ s/\D//g;
7578: if ($newdefresponder eq '' || $newdefresponder < 1) {
7579: $newdefresponder = 1;
7580: }
7581: $defaultshash{'coursedefaults'}{'anonsurvey_threshold'} = $newdefresponder;
7582: if ($currdefresponder ne $newdefresponder) {
7583: unless ($currdefresponder eq '' && $newdefresponder == 10) {
7584: $changes{'anonsurvey_threshold'} = 1;
7585: }
7586: }
1.121 raeburn 7587: }
7588: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
7589: $dom);
7590: if ($putresult eq 'ok') {
7591: if (keys(%changes) > 0) {
7592: if ($changes{'canuse_pdfforms'}) {
7593: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
7594: $domdefaults{'canuse_pdfforms'}=$defaultshash{'coursedefaults'}{'canuse_pdfforms'};
7595: my $cachetime = 24*60*60;
7596: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
7597: }
7598: $resulttext = &mt('Changes made:').'<ul>';
7599: foreach my $item (sort(keys(%changes))) {
7600: if ($item eq 'canuse_pdfforms') {
7601: if ($env{'form.'.$item} eq '1') {
7602: $resulttext .= '<li>'.&mt("Course/Community users can create/upload PDF forms set to 'on'").'</li>';
7603: } else {
7604: $resulttext .= '<li>'.&mt('Course/Community users can create/upload PDF forms set to "off"').'</li>';
7605: }
1.139 raeburn 7606: } elsif ($item eq 'anonsurvey_threshold') {
7607: $resulttext .= '<li>'.&mt('Responder count required for display of anonymous survey submissions set to [_1].',$defaultshash{'coursedefaults'}{'anonsurvey_threshold'}).'</li>';
1.140 raeburn 7608: }
1.121 raeburn 7609: }
7610: $resulttext .= '</ul>';
7611: } else {
7612: $resulttext = &mt('No changes made to course defaults');
7613: }
7614: } else {
7615: $resulttext = '<span class="LC_error">'.
7616: &mt('An error occurred: [_1]',$putresult).'</span>';
7617: }
7618: return $resulttext;
7619: }
7620:
1.137 raeburn 7621: sub modify_usersessions {
7622: my ($dom,%domconfig) = @_;
1.145 raeburn 7623: my @hostingtypes = ('version','excludedomain','includedomain');
7624: my @offloadtypes = ('primary','default');
7625: my %types = (
7626: remote => \@hostingtypes,
7627: hosted => \@hostingtypes,
7628: spares => \@offloadtypes,
7629: );
7630: my @prefixes = ('remote','hosted','spares');
1.137 raeburn 7631: my @lcversions = &Apache::lonnet::all_loncaparevs();
1.138 raeburn 7632: my (%by_ip,%by_location,@intdoms);
7633: &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
7634: my @locations = sort(keys(%by_location));
1.137 raeburn 7635: my (%defaultshash,%changes);
7636: foreach my $prefix (@prefixes) {
7637: $defaultshash{'usersessions'}{$prefix} = {};
7638: }
7639: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
7640: my $resulttext;
1.138 raeburn 7641: my %iphost = &Apache::lonnet::get_iphost();
1.137 raeburn 7642: foreach my $prefix (@prefixes) {
1.145 raeburn 7643: next if ($prefix eq 'spares');
7644: foreach my $type (@{$types{$prefix}}) {
1.137 raeburn 7645: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
7646: if ($type eq 'version') {
7647: my $value = $env{'form.'.$prefix.'_'.$type};
7648: my $okvalue;
7649: if ($value ne '') {
7650: if (grep(/^\Q$value\E$/,@lcversions)) {
7651: $okvalue = $value;
7652: }
7653: }
7654: if (ref($domconfig{'usersessions'}) eq 'HASH') {
7655: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
7656: if ($domconfig{'usersessions'}{$prefix}{$type} ne '') {
7657: if ($inuse == 0) {
7658: $changes{$prefix}{$type} = 1;
7659: } else {
7660: if ($okvalue ne $domconfig{'usersessions'}{$prefix}{$type}) {
7661: $changes{$prefix}{$type} = 1;
7662: }
7663: if ($okvalue ne '') {
7664: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
7665: }
7666: }
7667: } else {
7668: if (($inuse == 1) && ($okvalue ne '')) {
7669: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
7670: $changes{$prefix}{$type} = 1;
7671: }
7672: }
7673: } else {
7674: if (($inuse == 1) && ($okvalue ne '')) {
7675: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
7676: $changes{$prefix}{$type} = 1;
7677: }
7678: }
7679: } else {
7680: if (($inuse == 1) && ($okvalue ne '')) {
7681: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
7682: $changes{$prefix}{$type} = 1;
7683: }
7684: }
7685: } else {
7686: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
7687: my @okvals;
7688: foreach my $val (@vals) {
1.138 raeburn 7689: if ($val =~ /:/) {
7690: my @items = split(/:/,$val);
7691: foreach my $item (@items) {
7692: if (ref($by_location{$item}) eq 'ARRAY') {
7693: push(@okvals,$item);
7694: }
7695: }
7696: } else {
7697: if (ref($by_location{$val}) eq 'ARRAY') {
7698: push(@okvals,$val);
7699: }
1.137 raeburn 7700: }
7701: }
7702: @okvals = sort(@okvals);
7703: if (ref($domconfig{'usersessions'}) eq 'HASH') {
7704: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
7705: if (ref($domconfig{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
7706: if ($inuse == 0) {
7707: $changes{$prefix}{$type} = 1;
7708: } else {
7709: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
7710: my @changed = &Apache::loncommon::compare_arrays($domconfig{'usersessions'}{$prefix}{$type},$defaultshash{'usersessions'}{$prefix}{$type});
7711: if (@changed > 0) {
7712: $changes{$prefix}{$type} = 1;
7713: }
7714: }
7715: } else {
7716: if ($inuse == 1) {
7717: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
7718: $changes{$prefix}{$type} = 1;
7719: }
7720: }
7721: } else {
7722: if ($inuse == 1) {
7723: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
7724: $changes{$prefix}{$type} = 1;
7725: }
7726: }
7727: } else {
7728: if ($inuse == 1) {
7729: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
7730: $changes{$prefix}{$type} = 1;
7731: }
7732: }
7733: }
7734: }
7735: }
1.145 raeburn 7736:
7737: my @alldoms = &Apache::lonnet::all_domains();
1.149 raeburn 7738: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.145 raeburn 7739: my %spareid = ¤t_offloads_to($dom,$domconfig{'usersessions'},\%servers);
7740: my $savespares;
7741:
7742: foreach my $lonhost (sort(keys(%servers))) {
7743: my $serverhomeID =
7744: &Apache::lonnet::get_server_homeID($servers{$lonhost});
1.152 raeburn 7745: my $serverhostname = &Apache::lonnet::hostname($lonhost);
1.145 raeburn 7746: $defaultshash{'usersessions'}{'spares'}{$lonhost} = {};
7747: my %spareschg;
7748: foreach my $type (@{$types{'spares'}}) {
7749: my @okspares;
7750: my @checked = &Apache::loncommon::get_env_multiple('form.spare_'.$type.'_'.$lonhost);
7751: foreach my $server (@checked) {
1.152 raeburn 7752: if (&Apache::lonnet::hostname($server) ne '') {
7753: unless (&Apache::lonnet::hostname($server) eq $serverhostname) {
7754: unless (grep(/^\Q$server\E$/,@okspares)) {
7755: push(@okspares,$server);
7756: }
1.145 raeburn 7757: }
7758: }
7759: }
7760: my $new = $env{'form.newspare_'.$type.'_'.$lonhost};
7761: my $newspare;
1.152 raeburn 7762: if (($new ne '') && (&Apache::lonnet::hostname($new))) {
7763: unless (&Apache::lonnet::hostname($new) eq $serverhostname) {
1.145 raeburn 7764: $newspare = $new;
7765: }
7766: }
1.152 raeburn 7767: my @spares;
7768: if (($newspare ne '') && (!grep(/^\Q$newspare\E$/,@okspares))) {
7769: @spares = sort(@okspares,$newspare);
7770: } else {
7771: @spares = sort(@okspares);
7772: }
7773: $defaultshash{'usersessions'}{'spares'}{$lonhost}{$type} = \@spares;
1.145 raeburn 7774: if (ref($spareid{$lonhost}) eq 'HASH') {
7775: if (ref($spareid{$lonhost}{$type}) eq 'ARRAY') {
1.152 raeburn 7776: my @diffs = &Apache::loncommon::compare_arrays($spareid{$lonhost}{$type},\@spares);
1.145 raeburn 7777: if (@diffs > 0) {
7778: $spareschg{$type} = 1;
7779: }
7780: }
7781: }
7782: }
7783: if (keys(%spareschg) > 0) {
7784: $changes{'spares'}{$lonhost} = \%spareschg;
7785: }
7786: }
7787:
7788: if (ref($domconfig{'usersessions'}) eq 'HASH') {
7789: if (ref($domconfig{'usersessions'}{'spares'}) eq 'HASH') {
7790: if (ref($changes{'spares'}) eq 'HASH') {
7791: if (keys(%{$changes{'spares'}}) > 0) {
7792: $savespares = 1;
7793: }
7794: }
7795: } else {
7796: $savespares = 1;
7797: }
7798: }
7799:
1.147 raeburn 7800: my $nochgmsg = &mt('No changes made to settings for user session hosting/offloading.');
7801: if ((keys(%changes) > 0) || ($savespares)) {
1.137 raeburn 7802: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
7803: $dom);
7804: if ($putresult eq 'ok') {
7805: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
7806: if (ref($defaultshash{'usersessions'}{'remote'}) eq 'HASH') {
7807: $domdefaults{'remotesessions'} = $defaultshash{'usersessions'}{'remote'};
7808: }
7809: if (ref($defaultshash{'usersessions'}{'hosted'}) eq 'HASH') {
7810: $domdefaults{'hostedsessions'} = $defaultshash{'usersessions'}{'hosted'};
7811: }
7812: }
7813: my $cachetime = 24*60*60;
7814: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.147 raeburn 7815: if (keys(%changes) > 0) {
7816: my %lt = &usersession_titles();
7817: $resulttext = &mt('Changes made:').'<ul>';
7818: foreach my $prefix (@prefixes) {
7819: if (ref($changes{$prefix}) eq 'HASH') {
7820: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
7821: if ($prefix eq 'spares') {
7822: if (ref($changes{$prefix}) eq 'HASH') {
7823: foreach my $lonhost (sort(keys(%{$changes{$prefix}}))) {
7824: $resulttext .= '<li><b>'.$lonhost.'</b> ';
1.148 raeburn 7825: my $lonhostdom = &Apache::lonnet::host_domain($lonhost);
7826: &Apache::lonnet::remote_devalidate_cache($lonhost,'spares',$lonhostdom);
1.147 raeburn 7827: if (ref($changes{$prefix}{$lonhost}) eq 'HASH') {
7828: foreach my $type (@{$types{$prefix}}) {
7829: if ($changes{$prefix}{$lonhost}{$type}) {
7830: my $offloadto = &mt('None');
7831: if (ref($defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}) eq 'ARRAY') {
7832: if (@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}} > 0) {
7833: $offloadto = join(', ',@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}});
7834: }
1.145 raeburn 7835: }
1.147 raeburn 7836: $resulttext .= &mt('[_1] set to: [_2].','<i>'.$lt{$type}.'</i>',$offloadto).(' 'x3);
1.145 raeburn 7837: }
1.137 raeburn 7838: }
7839: }
1.147 raeburn 7840: $resulttext .= '</li>';
1.137 raeburn 7841: }
7842: }
1.147 raeburn 7843: } else {
7844: foreach my $type (@{$types{$prefix}}) {
7845: if (defined($changes{$prefix}{$type})) {
7846: my $newvalue;
7847: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
7848: if (ref($defaultshash{'usersessions'}{$prefix})) {
7849: if ($type eq 'version') {
7850: $newvalue = $defaultshash{'usersessions'}{$prefix}{$type};
7851: } elsif (ref($defaultshash{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
7852: if (@{$defaultshash{'usersessions'}{$prefix}{$type}} > 0) {
7853: $newvalue = join(', ',@{$defaultshash{'usersessions'}{$prefix}{$type}});
7854: }
1.145 raeburn 7855: }
7856: }
7857: }
1.147 raeburn 7858: if ($newvalue eq '') {
7859: if ($type eq 'version') {
7860: $resulttext .= '<li>'.&mt('[_1] set to: off',$lt{$type}).'</li>';
7861: } else {
7862: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
7863: }
1.145 raeburn 7864: } else {
1.147 raeburn 7865: if ($type eq 'version') {
7866: $newvalue .= ' '.&mt('(or later)');
7867: }
7868: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
1.145 raeburn 7869: }
1.137 raeburn 7870: }
7871: }
7872: }
1.147 raeburn 7873: $resulttext .= '</ul>';
1.137 raeburn 7874: }
7875: }
1.147 raeburn 7876: $resulttext .= '</ul>';
7877: } else {
7878: $resulttext = $nochgmsg;
1.137 raeburn 7879: }
7880: } else {
7881: $resulttext = '<span class="LC_error">'.
7882: &mt('An error occurred: [_1]',$putresult).'</span>';
7883: }
7884: } else {
1.147 raeburn 7885: $resulttext = $nochgmsg;
1.137 raeburn 7886: }
7887: return $resulttext;
7888: }
7889:
1.150 raeburn 7890: sub modify_loadbalancing {
7891: my ($dom,%domconfig) = @_;
7892: my $primary_id = &Apache::lonnet::domain($dom,'primary');
7893: my $intdom = &Apache::lonnet::internet_dom($primary_id);
7894: my ($othertitle,$usertypes,$types) =
7895: &Apache::loncommon::sorted_inst_types($dom);
7896: my %servers = &Apache::lonnet::internet_dom_servers($dom);
7897: my @sparestypes = ('primary','default');
7898: my %typetitles = &sparestype_titles();
7899: my $resulttext;
7900: if (keys(%servers) > 1) {
7901: my ($currbalancer,$currtargets,$currrules);
7902: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
7903: $currbalancer = $domconfig{'loadbalancing'}{'lonhost'};
7904: $currtargets = $domconfig{'loadbalancing'}{'targets'};
7905: $currrules = $domconfig{'loadbalancing'}{'rules'};
7906: } else {
7907: ($currbalancer,$currtargets) =
7908: &Apache::lonnet::get_lonbalancer_config(\%servers);
7909: }
7910: my ($saveloadbalancing,%defaultshash,%changes);
7911: my ($alltypes,$othertypes,$titles) =
7912: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
7913: my %ruletitles = &offloadtype_text();
7914: my $balancer = $env{'form.loadbalancing_lonhost'};
7915: if (!$servers{$balancer}) {
7916: undef($balancer);
7917: }
7918: if ($currbalancer ne $balancer) {
7919: $changes{'lonhost'} = 1;
7920: }
7921: $defaultshash{'loadbalancing'}{'lonhost'} = $balancer;
7922: if ($balancer ne '') {
7923: unless (ref($domconfig{'loadbalancing'}) eq 'HASH') {
7924: $saveloadbalancing = 1;
7925: }
7926: foreach my $sparetype (@sparestypes) {
7927: my @targets = &Apache::loncommon::get_env_multiple('form.loadbalancing_target_'.$sparetype);
1.151 raeburn 7928: my @offloadto;
1.150 raeburn 7929: foreach my $target (@targets) {
7930: if (($servers{$target}) && ($target ne $balancer)) {
7931: if ($sparetype eq 'default') {
7932: if (ref($defaultshash{'loadbalancing'}{'targets'}{'primary'}) eq 'ARRAY') {
7933: next if (grep(/^\Q$target\E$/,@{$defaultshash{'loadbalancing'}{'targets'}{'primary'}}));
7934: }
7935: }
7936: unless(grep(/^\Q$target\E$/,@offloadto)) {
7937: push(@offloadto,$target);
7938: }
7939: }
7940: $defaultshash{'loadbalancing'}{'targets'}{$sparetype} = \@offloadto;
7941: }
7942: }
7943: } else {
7944: foreach my $sparetype (@sparestypes) {
7945: $defaultshash{'loadbalancing'}{'targets'}{$sparetype} = [];
7946: }
7947: }
7948: if (ref($currtargets) eq 'HASH') {
7949: foreach my $sparetype (@sparestypes) {
7950: if (ref($currtargets->{$sparetype}) eq 'ARRAY') {
7951: my @targetdiffs = &Apache::loncommon::compare_arrays($currtargets->{$sparetype},$defaultshash{'loadbalancing'}{'targets'}{$sparetype});
7952: if (@targetdiffs > 0) {
7953: $changes{'targets'} = 1;
7954: }
7955: } elsif (ref($defaultshash{'loadbalancing'}{'targets'}{$sparetype}) eq 'ARRAY') {
7956: if (@{$defaultshash{'loadbalancing'}{'targets'}{$sparetype}} > 0) {
7957: $changes{'targets'} = 1;
7958: }
7959: }
7960: }
7961: } else {
7962: foreach my $sparetype (@sparestypes) {
7963: if (ref($defaultshash{'loadbalancing'}{'targets'}{$sparetype}) eq 'ARRAY') {
7964: if (@{$defaultshash{'loadbalancing'}{'targets'}{$sparetype}} > 0) {
7965: $changes{'targets'} = 1;
7966: }
7967: }
7968: }
7969: }
7970: my $ishomedom;
7971: if ($balancer ne '') {
7972: if (&Apache::lonnet::host_domain($balancer) eq $dom) {
7973: $ishomedom = 1;
7974: }
7975: }
7976: if (ref($alltypes) eq 'ARRAY') {
7977: foreach my $type (@{$alltypes}) {
7978: my $rule;
7979: if ($balancer ne '') {
7980: unless ((($type eq '_LC_external') || ($type eq '_LC_internetdom')) &&
7981: (!$ishomedom)) {
7982: $rule = $env{'form.loadbalancing_rules_'.$type};
7983: }
7984: if ($rule eq 'specific') {
7985: $rule = $env{'form.loadbalancing_singleserver_'.$type};
7986: }
7987: }
7988: $defaultshash{'loadbalancing'}{'rules'}{$type} = $rule;
7989: if (ref($currrules) eq 'HASH') {
7990: if ($rule ne $currrules->{$type}) {
7991: $changes{'rules'}{$type} = 1;
7992: }
7993: } elsif ($rule ne '') {
7994: $changes{'rules'}{$type} = 1;
7995: }
7996: }
7997: }
7998: my $nochgmsg = &mt('No changes made to Load Balancer settings.');
7999: if ((keys(%changes) > 0) || ($saveloadbalancing)) {
8000: my $putresult = &Apache::lonnet::put_dom('configuration',
8001: \%defaultshash,$dom);
8002: if ($putresult eq 'ok') {
8003: if (keys(%changes) > 0) {
8004: if ($changes{'lonhost'}) {
8005: if ($currbalancer ne '') {
8006: &Apache::lonnet::remote_devalidate_cache($currbalancer,'loadbalancing',$dom);
8007: }
8008: if ($balancer eq '') {
8009: $resulttext .= '<li>'.&mt('Load Balancing with dedicated server discontinued').'</li>';
8010: } else {
8011: &Apache::lonnet::remote_devalidate_cache($balancer,'loadbalancing',$dom);
8012: $resulttext .= '<li>'.&mt('Dedicated Load Balancer server set to [_1]',$balancer);
8013: }
8014: } else {
8015: &Apache::lonnet::remote_devalidate_cache($balancer,'loadbalancing',$dom);
8016: }
8017: if (($changes{'targets'}) && ($balancer ne '')) {
8018: my %offloadstr;
8019: foreach my $sparetype (@sparestypes) {
8020: if (ref($defaultshash{'loadbalancing'}{'targets'}{$sparetype}) eq 'ARRAY') {
8021: if (@{$defaultshash{'loadbalancing'}{'targets'}{$sparetype}} > 0) {
8022: $offloadstr{$sparetype} = join(', ',@{$defaultshash{'loadbalancing'}{'targets'}{$sparetype}});
8023: }
8024: }
8025: }
8026: if (keys(%offloadstr) == 0) {
8027: $resulttext .= '<li>'.&mt("Servers to which Load Balance server offloads set to 'None', by default").'</li>';
8028: } else {
8029: my $showoffload;
8030: foreach my $sparetype (@sparestypes) {
8031: $showoffload .= '<i>'.$typetitles{$sparetype}.'</i>: ';
8032: if (defined($offloadstr{$sparetype})) {
8033: $showoffload .= $offloadstr{$sparetype};
8034: } else {
8035: $showoffload .= &mt('None');
8036: }
8037: $showoffload .= (' 'x3);
8038: }
8039: $resulttext .= '<li>'.&mt('By default, Load Balancer server set to offload to: [_1]',$showoffload).'</li>';
8040: }
8041: }
8042: if ((ref($changes{'rules'}) eq 'HASH') && ($balancer ne '')) {
8043: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
8044: foreach my $type (@{$alltypes}) {
8045: if ($changes{'rules'}{$type}) {
8046: my $rule = $defaultshash{'loadbalancing'}{'rules'}{$type};
8047: my $balancetext;
8048: if ($rule eq '') {
8049: $balancetext = $ruletitles{'default'};
8050: } elsif (($rule eq 'homeserver') || ($rule eq 'externalbalancer')) {
8051: $balancetext = $ruletitles{$rule};
8052: } else {
8053: $balancetext = &mt('offload to [_1]',$defaultshash{'loadbalancing'}{'rules'}{$type});
8054: }
8055: $resulttext .= '<li>'.&mt('Load Balancing for [_1] set to: [_2]',$titles->{$type},$balancetext).'</li>';
8056: }
8057: }
8058: }
8059: }
8060: if ($resulttext ne '') {
8061: $resulttext = &mt('Changes made:').'<ul>'.$resulttext.'</ul>';
8062: } else {
8063: $resulttext = $nochgmsg;
8064: }
8065: } else {
8066: $resulttext = $nochgmsg;
8067: if ($balancer ne '') {
8068: &Apache::lonnet::remote_devalidate_cache($balancer,'loadbalancing',$dom);
8069: }
8070: }
8071: } else {
8072: $resulttext = '<span class="LC_error">'.
8073: &mt('An error occurred: [_1]',$putresult).'</span>';
8074: }
8075: } else {
8076: $resulttext = $nochgmsg;
8077: }
8078: } else {
8079: $resulttext = &mt('Load Balancing unavailable as this domain only has one server.');
8080: }
8081: return $resulttext;
8082: }
8083:
1.48 raeburn 8084: sub recurse_check {
8085: my ($chkcats,$categories,$depth,$name) = @_;
8086: if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
8087: my $chg = 0;
8088: for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
8089: my $category = $chkcats->[$depth]{$name}[$j];
8090: my $item;
8091: if ($category eq '') {
8092: $chg ++;
8093: } else {
8094: my $deeper = $depth + 1;
8095: $item = &escape($category).':'.&escape($name).':'.$depth;
8096: if ($chg) {
8097: $categories->{$item} -= $chg;
8098: }
8099: &recurse_check($chkcats,$categories,$deeper,$category);
8100: $deeper --;
8101: }
8102: }
8103: }
8104: return;
8105: }
8106:
8107: sub recurse_cat_deletes {
8108: my ($item,$coursecategories,$deletions) = @_;
8109: my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
8110: my $subdepth = $depth + 1;
8111: if (ref($coursecategories) eq 'HASH') {
8112: foreach my $subitem (keys(%{$coursecategories})) {
8113: my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
8114: if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
8115: delete($coursecategories->{$subitem});
8116: $deletions->{$subitem} = 1;
8117: &recurse_cat_deletes($subitem,$coursecategories,$deletions);
8118: }
8119: }
8120: }
8121: return;
8122: }
8123:
1.125 raeburn 8124: sub get_active_dcs {
8125: my ($dom) = @_;
8126: my %dompersonnel = &Apache::lonnet::get_domain_roles($dom,['dc']);
8127: my %domcoords;
8128: my $numdcs = 0;
8129: my $now = time;
8130: foreach my $server (keys(%dompersonnel)) {
8131: foreach my $user (sort(keys(%{$dompersonnel{$server}}))) {
8132: my ($trole,$uname,$udom,$runame,$rudom,$rsec) = split(/:/,$user);
8133: my ($end,$start) = split(':',$dompersonnel{$server}{$user});
8134: if (($end eq '') || ($end == 0) || ($end > $now)) {
8135: if ($start <= $now) {
8136: $domcoords{$uname.':'.$udom} = $dompersonnel{$server}{$user};
8137: }
8138: }
8139: }
8140: }
8141: return %domcoords;
8142: }
8143:
8144: sub active_dc_picker {
8145: my ($dom,$curr_dc) = @_;
8146: my %domcoords = &get_active_dcs($dom);
8147: my @dcs = sort(keys(%domcoords));
8148: my $numdcs = scalar(@dcs);
8149: my $datatable;
8150: my $numinrow = 2;
8151: if ($numdcs > 1) {
8152: $datatable = '<table>';
8153: for (my $i=0; $i<@dcs; $i++) {
8154: my $rem = $i%($numinrow);
8155: if ($rem == 0) {
8156: if ($i > 0) {
8157: $datatable .= '</tr>';
8158: }
8159: $datatable .= '<tr>';
8160: }
8161: my $check = ' ';
8162: if ($curr_dc eq '') {
8163: if (!$i) {
8164: $check = ' checked="checked" ';
8165: }
8166: } elsif ($dcs[$i] eq $curr_dc) {
8167: $check = ' checked="checked" ';
8168: }
8169: if ($i == @dcs - 1) {
8170: my $colsleft = $numinrow - $rem;
8171: if ($colsleft > 1) {
8172: $datatable .= '<td colspan="'.$colsleft.'">';
8173: } else {
8174: $datatable .= '<td>';
8175: }
8176: } else {
8177: $datatable .= '<td>';
8178: }
8179: my ($dcname,$dcdom) = split(':',$dcs[$i]);
8180: $datatable .= '<span class="LC_nobreak"><label>'.
8181: '<input type="radio" name="autocreate_xmldc"'.
8182: ' value="'.$dcs[$i].'"'.$check.'/>'.
8183: &Apache::loncommon::plainname($dcname,$dcdom).
8184: '</label></span></td>';
8185: }
8186: $datatable .= '</tr></table>';
8187: } elsif (@dcs) {
8188: $datatable .= '<input type="hidden" name="autocreate_dc" value="'.
8189: $dcs[0].'" />';
8190: }
8191: return ($numdcs,$datatable);
8192: }
8193:
1.137 raeburn 8194: sub usersession_titles {
8195: return &Apache::lonlocal::texthash(
8196: hosted => 'Hosting of sessions for users from other domains on servers in this domain',
8197: remote => 'Hosting of sessions for users in this domain on servers in other domains',
1.145 raeburn 8198: spares => 'Servers offloaded to, when busy',
1.137 raeburn 8199: version => 'LON-CAPA version requirement',
1.138 raeburn 8200: excludedomain => 'Allow all, but exclude specific domains',
8201: includedomain => 'Deny all, but include specific domains',
1.145 raeburn 8202: primary => 'Primary (checked first)',
1.154 raeburn 8203: default => 'Default',
1.137 raeburn 8204: );
8205: }
8206:
1.152 raeburn 8207: sub id_for_thisdom {
8208: my (%servers) = @_;
8209: my %altids;
8210: foreach my $server (keys(%servers)) {
8211: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
8212: if ($serverhome ne $server) {
8213: $altids{$serverhome} = $server;
8214: }
8215: }
8216: return %altids;
8217: }
8218:
1.150 raeburn 8219: sub count_servers {
8220: my ($currbalancer,%servers) = @_;
8221: my (@spares,$numspares);
8222: foreach my $lonhost (sort(keys(%servers))) {
8223: next if ($currbalancer eq $lonhost);
8224: push(@spares,$lonhost);
8225: }
8226: if ($currbalancer) {
8227: $numspares = scalar(@spares);
8228: } else {
8229: $numspares = scalar(@spares) - 1;
8230: }
8231: return ($numspares,@spares);
8232: }
8233:
8234: sub lonbalance_targets_js {
8235: my ($dom,$types,$servers) = @_;
8236: my $select = &mt('Select');
8237: my ($alltargets,$allishome,$allinsttypes,@alltypes);
8238: if (ref($servers) eq 'HASH') {
8239: $alltargets = join("','",sort(keys(%{$servers})));
8240: my @homedoms;
8241: foreach my $server (sort(keys(%{$servers}))) {
8242: if (&Apache::lonnet::host_domain($server) eq $dom) {
8243: push(@homedoms,'1');
8244: } else {
8245: push(@homedoms,'0');
8246: }
8247: }
8248: $allishome = join("','",@homedoms);
8249: }
8250: if (ref($types) eq 'ARRAY') {
8251: if (@{$types} > 0) {
8252: @alltypes = @{$types};
8253: }
8254: }
8255: push(@alltypes,'default','_LC_adv','_LC_author','_LC_internetdom','_LC_external');
8256: $allinsttypes = join("','",@alltypes);
8257: return <<"END";
8258:
8259: <script type="text/javascript">
8260: // <![CDATA[
8261:
8262: function toggleTargets() {
8263: var balancer = document.display.loadbalancing_lonhost.options[document.display.loadbalancing_lonhost.selectedIndex].value;
8264: if (balancer == '') {
8265: hideSpares();
8266: } else {
8267: var homedoms = new Array('$allishome');
8268: var ishomedom = homedoms[document.display.loadbalancing_lonhost.selectedIndex];
8269: showSpares(balancer,ishomedom);
8270: }
8271: return;
8272: }
8273:
8274: function showSpares(balancer,ishomedom) {
8275: var alltargets = new Array('$alltargets');
8276: var insttypes = new Array('$allinsttypes');
1.151 raeburn 8277: var offloadtypes = new Array('primary','default');
8278:
1.150 raeburn 8279: document.getElementById('loadbalancing_targets').style.display='block';
8280: document.getElementById('loadbalancing_disabled').style.display='none';
1.152 raeburn 8281:
1.151 raeburn 8282: for (var i=0; i<offloadtypes.length; i++) {
8283: var count = 0;
8284: for (var j=0; j<alltargets.length; j++) {
8285: if (alltargets[j] != balancer) {
8286: document.getElementById('loadbalancing_target_'+offloadtypes[i]+'_'+count).value = alltargets[j];
8287: document.getElementById('loadbalancing_targettxt_'+offloadtypes[i]+'_'+count).style.textAlign='left';
8288: document.getElementById('loadbalancing_targettxt_'+offloadtypes[i]+'_'+count).style.textFace='normal';
8289: document.getElementById('loadbalancing_targettxt_'+offloadtypes[i]+'_'+count).innerHTML = alltargets[j];
8290: count ++;
8291: }
1.150 raeburn 8292: }
8293: }
1.151 raeburn 8294: for (var k=0; k<insttypes.length; k++) {
8295: if ((insttypes[k] == '_LC_external') || (insttypes[k] == '_LC_internetdom')) {
1.150 raeburn 8296: if (ishomedom == 1) {
1.151 raeburn 8297: document.getElementById('balanceruletitle_'+insttypes[k]).style.display='block';
8298: document.getElementById('balancerule_'+insttypes[k]).style.display='block';
1.150 raeburn 8299: } else {
1.151 raeburn 8300: document.getElementById('balanceruletitle_'+insttypes[k]).style.display='none';
8301: document.getElementById('balancerule_'+insttypes[k]).style.display='none';
1.150 raeburn 8302:
8303: }
8304: } else {
1.151 raeburn 8305: document.getElementById('balanceruletitle_'+insttypes[k]).style.display='block';
8306: document.getElementById('balancerule_'+insttypes[k]).style.display='block';
1.150 raeburn 8307: }
1.151 raeburn 8308: if ((insttypes[k] != '_LC_external') &&
8309: ((insttypes[k] != '_LC_internetdom') ||
8310: ((insttypes[k] == '_LC_internetdom') && (ishomedom == 1)))) {
8311: document.getElementById('loadbalancing_singleserver_'+insttypes[k]).options[0] = new Option("","",true,true);
8312: for (var m=0; m<alltargets.length; m++) {
8313: var idx = m+1;
8314: if (alltargets[m] != balancer) {
8315: document.getElementById('loadbalancing_singleserver_'+insttypes[k]).options[idx] = new Option(alltargets[m],alltargets[m],false,false);
1.150 raeburn 8316: }
8317: }
8318: }
8319: }
8320: return;
8321: }
8322:
8323: function hideSpares() {
8324: var alltargets = new Array('$alltargets');
8325: var insttypes = new Array('$allinsttypes');
8326: var offloadtypes = new Array('primary','default');
8327:
8328: document.getElementById('loadbalancing_targets').style.display='none';
8329: document.getElementById('loadbalancing_disabled').style.display='block';
8330:
8331: var total = alltargets.length - 1;
8332: for (var i=0; i<offloadtypes; i++) {
8333: for (var j=0; j<total; j++) {
8334: document.getElementById('loadbalancing_target_'+offloadtypes[i]+'_'+j).checked = false;
8335: document.getElementById('loadbalancing_target_'+offloadtypes[i]+'_'+j).value = '';
8336: document.getElementById('loadbalancing_targettxt_'+offloadtypes[i]+'_'+j).innerHTML = '';
1.151 raeburn 8337: }
1.150 raeburn 8338: }
8339: for (var k=0; k<insttypes.length; k++) {
1.151 raeburn 8340: document.getElementById('balanceruletitle_'+insttypes[k]).style.display='none';
8341: document.getElementById('balancerule_'+insttypes[k]).style.display='none';
8342: if (insttypes[k] != '_LC_external') {
8343: document.getElementById('loadbalancing_singleserver_'+insttypes[k]).length = 0;
8344: document.getElementById('loadbalancing_singleserver_'+insttypes[k]).options[0] = new Option("","",true,true);
1.150 raeburn 8345: }
8346: }
8347: return;
8348: }
8349:
8350: function checkOffloads(item,type) {
8351: var alltargets = new Array('$alltargets');
8352: var offloadtypes = new Array('primary','default');
8353: if (item.checked) {
8354: var total = alltargets.length - 1;
8355: var other;
8356: if (type == offloadtypes[0]) {
1.151 raeburn 8357: other = offloadtypes[1];
1.150 raeburn 8358: } else {
1.151 raeburn 8359: other = offloadtypes[0];
1.150 raeburn 8360: }
8361: for (var i=0; i<total; i++) {
8362: var server = document.getElementById('loadbalancing_target_'+other+'_'+i).value;
8363: if (server == item.value) {
8364: if (document.getElementById('loadbalancing_target_'+other+'_'+i).checked) {
8365: document.getElementById('loadbalancing_target_'+other+'_'+i).checked = false;
8366: }
8367: }
8368: }
8369: }
8370: return;
8371: }
8372:
8373: function singleServerToggle(type) {
8374: var offloadtoSelIdx = document.getElementById('loadbalancing_singleserver_'+type).selectedIndex;
8375: if (offloadtoSelIdx == 0) {
8376: document.getElementById('loadbalancing_rules_'+type+'_0').checked = true;
8377: document.getElementById('loadbalancing_singleserver_'+type).options[0].text = '';
8378:
8379: } else {
8380: document.getElementById('loadbalancing_rules_'+type+'_2').checked = true;
8381: document.getElementById('loadbalancing_singleserver_'+type).options[0].text = '$select';
8382: }
8383: return;
8384: }
8385:
8386: function balanceruleChange(formname,type) {
8387: if (type == '_LC_external') {
8388: return;
8389: }
8390: var typesRules = getIndicesByName(formname,'loadbalancing_rules_'+type);
8391: for (var i=0; i<typesRules.length; i++) {
8392: if (formname.elements[typesRules[i]].checked) {
8393: if (formname.elements[typesRules[i]].value != 'specific') {
8394: document.getElementById('loadbalancing_singleserver_'+type).selectedIndex = 0;
8395: document.getElementById('loadbalancing_singleserver_'+type).options[0].text = '';
8396: } else {
8397: document.getElementById('loadbalancing_singleserver_'+type).options[0].text = '$select';
8398: }
8399: }
8400: }
8401: return;
8402: }
8403:
1.152 raeburn 8404: // ]]>
8405: </script>
8406:
8407: END
8408: }
8409:
8410: sub new_spares_js {
8411: my @sparestypes = ('primary','default');
8412: my $types = join("','",@sparestypes);
8413: my $select = &mt('Select');
8414: return <<"END";
8415:
8416: <script type="text/javascript">
8417: // <![CDATA[
8418:
8419: function updateNewSpares(formname,lonhost) {
8420: var types = new Array('$types');
8421: var include = new Array();
8422: var exclude = new Array();
8423: for (var i=0; i<types.length; i++) {
8424: var spareboxes = getIndicesByName(formname,'spare_'+types[i]+'_'+lonhost);
8425: for (var j=0; j<spareboxes.length; j++) {
8426: if (formname.elements[spareboxes[j]].checked) {
8427: exclude.push(formname.elements[spareboxes[j]].value);
8428: } else {
8429: include.push(formname.elements[spareboxes[j]].value);
8430: }
8431: }
8432: }
8433: for (var i=0; i<types.length; i++) {
8434: var newSpare = document.getElementById('newspare_'+types[i]+'_'+lonhost);
8435: var selIdx = newSpare.selectedIndex;
8436: var currnew = newSpare.options[selIdx].value;
8437: var okSpares = new Array();
8438: for (var j=0; j<newSpare.options.length; j++) {
8439: var possible = newSpare.options[j].value;
8440: if (possible != '') {
8441: if (exclude.indexOf(possible) == -1) {
8442: okSpares.push(possible);
8443: } else {
8444: if (currnew == possible) {
8445: selIdx = 0;
8446: }
8447: }
8448: }
8449: }
8450: for (var k=0; k<include.length; k++) {
8451: if (okSpares.indexOf(include[k]) == -1) {
8452: okSpares.push(include[k]);
8453: }
8454: }
8455: okSpares.sort();
8456: newSpare.options.length = 0;
8457: if (selIdx == 0) {
8458: newSpare.options[0] = new Option("$select","",true,true);
8459: } else {
8460: newSpare.options[0] = new Option("$select","",false,false);
8461: }
8462: for (var m=0; m<okSpares.length; m++) {
8463: var idx = m+1;
8464: var selThis = 0;
8465: if (selIdx != 0) {
8466: if (okSpares[m] == currnew) {
8467: selThis = 1;
8468: }
8469: }
8470: if (selThis == 1) {
8471: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],true,true);
8472: } else {
8473: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],false,false);
8474: }
8475: }
8476: }
8477: return;
8478: }
8479:
8480: function checkNewSpares(lonhost,type) {
8481: var newSpare = document.getElementById('newspare_'+type+'_'+lonhost);
8482: var chosen = newSpare.options[newSpare.selectedIndex].value;
8483: if (chosen != '') {
8484: var othertype;
8485: var othernewSpare;
8486: if (type == 'primary') {
8487: othernewSpare = document.getElementById('newspare_default_'+lonhost);
8488: }
8489: if (type == 'default') {
8490: othernewSpare = document.getElementById('newspare_primary_'+lonhost);
8491: }
8492: if (othernewSpare.options[othernewSpare.selectedIndex].value == chosen) {
8493: othernewSpare.selectedIndex = 0;
8494: }
8495: }
8496: return;
8497: }
8498:
8499: // ]]>
8500: </script>
8501:
8502: END
8503:
8504: }
8505:
8506: sub common_domprefs_js {
8507: return <<"END";
8508:
8509: <script type="text/javascript">
8510: // <![CDATA[
8511:
1.150 raeburn 8512: function getIndicesByName(formname,item) {
1.152 raeburn 8513: var group = new Array();
1.150 raeburn 8514: for (var i=0;i<formname.elements.length;i++) {
8515: if (formname.elements[i].name == item) {
1.152 raeburn 8516: group.push(formname.elements[i].id);
1.150 raeburn 8517: }
8518: }
1.152 raeburn 8519: return group;
1.150 raeburn 8520: }
8521:
8522: // ]]>
8523: </script>
8524:
8525: END
1.152 raeburn 8526:
1.150 raeburn 8527: }
8528:
1.165 raeburn 8529: sub recaptcha_js {
8530: my %lt = &captcha_phrases();
8531: return <<"END";
8532:
8533: <script type="text/javascript">
8534: // <![CDATA[
8535:
8536: function updateCaptcha(caller,context) {
8537: var privitem;
8538: var pubitem;
8539: var privtext;
8540: var pubtext;
8541: if (document.getElementById(context+'_recaptchapub')) {
8542: pubitem = document.getElementById(context+'_recaptchapub');
8543: } else {
8544: return;
8545: }
8546: if (document.getElementById(context+'_recaptchapriv')) {
8547: privitem = document.getElementById(context+'_recaptchapriv');
8548: } else {
8549: return;
8550: }
8551: if (document.getElementById(context+'_recaptchapubtxt')) {
8552: pubtext = document.getElementById(context+'_recaptchapubtxt');
8553: } else {
8554: return;
8555: }
8556: if (document.getElementById(context+'_recaptchaprivtxt')) {
8557: privtext = document.getElementById(context+'_recaptchaprivtxt');
8558: } else {
8559: return;
8560: }
8561: if (caller.checked) {
8562: if (caller.value == 'recaptcha') {
8563: pubitem.type = 'text';
8564: privitem.type = 'text';
8565: pubitem.size = '40';
8566: privitem.size = '40';
8567: pubtext.innerHTML = "$lt{'pub'}";
8568: privtext.innerHTML = "$lt{'priv'}";
8569: } else {
8570: pubitem.type = 'hidden';
8571: privitem.type = 'hidden';
8572: pubtext.innerHTML = '';
8573: privtext.innerHTML = '';
8574: }
8575: }
8576: return;
8577: }
8578:
8579: // ]]>
8580: </script>
8581:
8582: END
8583:
8584: }
8585:
8586: sub captcha_phrases {
8587: return &Apache::lonlocal::texthash (
8588: priv => 'Private key',
8589: pub => 'Public key',
8590: original => 'original (CAPTCHA)',
8591: recaptcha => 'successor (ReCAPTCHA)',
8592: notused => 'unused',
8593: );
8594: }
8595:
1.3 raeburn 8596: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>