Annotation of loncom/interface/domainprefs.pm, revision 1.150
1.1 raeburn 1: # The LearningOnline Network with CAPA
2: # Handler to set domain-wide configuration settings
3: #
1.150 ! raeburn 4: # $Id: domainprefs.pm,v 1.149 2011/08/09 00:54:43 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
89: number of rows displayed on the page, and $action is the context (either quotas
90: or requestcourses).
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:
174: sub handler {
175: my $r=shift;
176: if ($r->header_only) {
177: &Apache::loncommon::content_type($r,'text/html');
178: $r->send_http_header;
179: return OK;
180: }
181:
1.91 raeburn 182: my $context = 'domain';
1.1 raeburn 183: my $dom = $env{'request.role.domain'};
1.5 albertel 184: my $domdesc = &Apache::lonnet::domain($dom,'description');
1.1 raeburn 185: if (&Apache::lonnet::allowed('mau',$dom)) {
186: &Apache::loncommon::content_type($r,'text/html');
187: $r->send_http_header;
188: } else {
189: $env{'user.error.msg'}=
190: "/adm/domainprefs:mau:0:0:Cannot modify domain settings";
191: return HTTP_NOT_ACCEPTABLE;
192: }
193: &Apache::lonhtmlcommon::clear_breadcrumbs();
194: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.58 raeburn 195: ['phase','actions']);
1.30 raeburn 196: my $phase = 'pickactions';
1.3 raeburn 197: if ( exists($env{'form.phase'}) ) {
198: $phase = $env{'form.phase'};
199: }
1.150 ! raeburn 200: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.3 raeburn 201: my %domconfig =
1.6 raeburn 202: &Apache::lonnet::get_dom('configuration',['login','rolecolors',
1.125 raeburn 203: 'quotas','autoenroll','autoupdate','autocreate',
204: 'directorysrch','usercreation','usermodification',
205: 'contacts','defaults','scantron','coursecategories',
206: 'serverstatuses','requestcourses','helpsettings',
1.150 ! raeburn 207: 'coursedefaults','usersessions','loadbalancing'],$dom);
1.43 raeburn 208: my @prefs_order = ('rolecolors','login','defaults','quotas','autoenroll',
1.125 raeburn 209: 'autoupdate','autocreate','directorysrch','contacts',
1.48 raeburn 210: 'usercreation','usermodification','scantron',
1.121 raeburn 211: 'requestcourses','coursecategories','serverstatuses','helpsettings',
1.137 raeburn 212: 'coursedefaults','usersessions');
1.150 ! raeburn 213: if (keys(%servers) > 1) {
! 214: push(@prefs_order,'loadbalancing');
! 215: }
1.30 raeburn 216: my %prefs = (
217: 'rolecolors' =>
218: { text => 'Default color schemes',
1.67 raeburn 219: help => 'Domain_Configuration_Color_Schemes',
1.30 raeburn 220: header => [{col1 => 'Student Settings',
221: col2 => '',},
222: {col1 => 'Coordinator Settings',
223: col2 => '',},
224: {col1 => 'Author Settings',
225: col2 => '',},
226: {col1 => 'Administrator Settings',
227: col2 => '',}],
228: },
1.110 raeburn 229: 'login' =>
1.30 raeburn 230: { text => 'Log-in page options',
1.67 raeburn 231: help => 'Domain_Configuration_Login_Page',
1.30 raeburn 232: header => [{col1 => 'Item',
233: col2 => '',}],
234: },
1.110 raeburn 235:
1.43 raeburn 236: 'defaults' =>
1.141 raeburn 237: { text => 'Default authentication/language/timezone/portal',
1.67 raeburn 238: help => 'Domain_Configuration_LangTZAuth',
1.43 raeburn 239: header => [{col1 => 'Setting',
240: col2 => 'Value'}],
241: },
1.30 raeburn 242: 'quotas' =>
1.133 raeburn 243: { text => 'User blogs, personal information pages, portfolios',
1.67 raeburn 244: help => 'Domain_Configuration_Quotas',
1.77 raeburn 245: header => [{col1 => 'User affiliation',
1.72 raeburn 246: col2 => 'Available tools',
247: col3 => 'Portfolio quota',}],
1.30 raeburn 248: },
249: 'autoenroll' =>
250: { text => 'Auto-enrollment settings',
1.67 raeburn 251: help => 'Domain_Configuration_Auto_Enrollment',
1.30 raeburn 252: header => [{col1 => 'Configuration setting',
253: col2 => 'Value(s)'}],
254: },
255: 'autoupdate' =>
256: { text => 'Auto-update settings',
1.67 raeburn 257: help => 'Domain_Configuration_Auto_Updates',
1.30 raeburn 258: header => [{col1 => 'Setting',
259: col2 => 'Value',},
1.131 raeburn 260: {col1 => 'Setting',
261: col2 => 'Affiliation'},
1.43 raeburn 262: {col1 => 'User population',
1.131 raeburn 263: col2 => 'Updateable user data'}],
1.30 raeburn 264: },
1.125 raeburn 265: 'autocreate' =>
266: { text => 'Auto-course creation settings',
267: help => 'Domain_Configuration_Auto_Creation',
268: header => [{col1 => 'Configuration Setting',
269: col2 => 'Value',}],
270: },
1.30 raeburn 271: 'directorysrch' =>
272: { text => 'Institutional directory searches',
1.67 raeburn 273: help => 'Domain_Configuration_InstDirectory_Search',
1.30 raeburn 274: header => [{col1 => 'Setting',
275: col2 => 'Value',}],
276: },
277: 'contacts' =>
278: { text => 'Contact Information',
1.67 raeburn 279: help => 'Domain_Configuration_Contact_Info',
1.30 raeburn 280: header => [{col1 => 'Setting',
281: col2 => 'Value',}],
282: },
283:
284: 'usercreation' =>
285: { text => 'User creation',
1.67 raeburn 286: help => 'Domain_Configuration_User_Creation',
1.43 raeburn 287: header => [{col1 => 'Format rule type',
288: col2 => 'Format rules in force'},
1.34 raeburn 289: {col1 => 'User account creation',
290: col2 => 'Usernames which may be created',},
1.30 raeburn 291: {col1 => 'Context',
1.43 raeburn 292: col2 => 'Assignable authentication types'}],
1.30 raeburn 293: },
1.69 raeburn 294: 'usermodification' =>
1.33 raeburn 295: { text => 'User modification',
1.67 raeburn 296: help => 'Domain_Configuration_User_Modification',
1.33 raeburn 297: header => [{col1 => 'Target user has role',
298: col2 => 'User information updateable in author context'},
299: {col1 => 'Target user has role',
1.63 raeburn 300: col2 => 'User information updateable in course context'},
301: {col1 => "Status of user",
302: col2 => 'Information settable when self-creating account (if directory data blank)'}],
1.33 raeburn 303: },
1.69 raeburn 304: 'scantron' =>
1.95 www 305: { text => 'Bubblesheet format file',
1.67 raeburn 306: help => 'Domain_Configuration_Scantron_Format',
1.46 raeburn 307: header => [ {col1 => 'Item',
308: col2 => '',
309: }],
310: },
1.86 raeburn 311: 'requestcourses' =>
312: {text => 'Request creation of courses',
313: help => 'Domain_Configuration_Request_Courses',
314: header => [{col1 => 'User affiliation',
1.102 raeburn 315: col2 => 'Availability/Processing of requests',},
316: {col1 => 'Setting',
317: col2 => 'Value'}],
1.86 raeburn 318: },
1.69 raeburn 319: 'coursecategories' =>
1.120 raeburn 320: { text => 'Cataloging of courses/communities',
1.67 raeburn 321: help => 'Domain_Configuration_Cataloging_Courses',
1.69 raeburn 322: header => [{col1 => 'Category settings',
1.57 raeburn 323: col2 => '',},
324: {col1 => 'Categories',
325: col2 => '',
326: }],
1.69 raeburn 327: },
328: 'serverstatuses' =>
1.77 raeburn 329: {text => 'Access to server status pages',
1.69 raeburn 330: help => 'Domain_Configuration_Server_Status',
331: header => [{col1 => 'Status Page',
332: col2 => 'Other named users',
333: col3 => 'Specific IPs',
334: }],
335: },
1.118 jms 336: 'helpsettings' =>
337: {text => 'Help page settings',
338: help => 'Domain_Configuration_Help_Settings',
1.122 jms 339: header => [{col1 => 'Authenticated Help Settings',
340: col2 => ''},
341: {col1 => 'Unauthenticated Help Settings',
342: col2 => ''}],
1.118 jms 343: },
1.121 raeburn 344: 'coursedefaults' =>
345: {text => 'Course/Community defaults',
346: help => 'Domain_Configuration_Course_Defaults',
1.139 raeburn 347: header => [{col1 => 'Defaults which can be overridden in each course by a CC',
348: col2 => 'Value',},
349: {col1 => 'Defaults which can be overridden for each course by a DC',
350: col2 => 'Value',},],
1.121 raeburn 351: },
1.120 raeburn 352: 'privacy' =>
353: {text => 'User Privacy',
354: help => 'Domain_Configuration_User_Privacy',
355: header => [{col1 => 'Setting',
356: col2 => 'Value',}],
357: },
1.141 raeburn 358: 'usersessions' =>
1.145 raeburn 359: {text => 'User session hosting/offloading',
1.137 raeburn 360: help => 'Domain_Configuration_User_Sessions',
1.145 raeburn 361: header => [{col1 => 'Domain server',
362: col2 => 'Servers to offload sessions to when busy'},
363: {col1 => 'Hosting of users from other domains',
1.137 raeburn 364: col2 => 'Rules'},
365: {col1 => "Hosting domain's own users elsewhere",
366: col2 => 'Rules'}],
367: },
1.150 ! raeburn 368: 'loadbalancing' =>
! 369: {text => 'Dedicated Load Balancer',
! 370: help => 'Domain_Configuration_Load_Balancing',
! 371: header => [{col1 => 'Server',
! 372: col2 => 'Default destinations',
! 373: col3 => 'User affliation',
! 374: col4 => 'Overrides'},
! 375: ],
! 376: },
1.3 raeburn 377: );
1.150 ! raeburn 378: my $js;
1.110 raeburn 379: if (keys(%servers) > 1) {
380: $prefs{'login'} = { text => 'Log-in page options',
381: help => 'Domain_Configuration_Login_Page',
382: header => [{col1 => 'Log-in Service',
383: col2 => 'Server Setting',},
384: {col1 => 'Log-in Page Items',
385: col2 => ''}],
386: };
1.150 ! raeburn 387: my ($othertitle,$usertypes,$types) =
! 388: &Apache::loncommon::sorted_inst_types($dom);
! 389:
! 390: $js = &lonbalance_targets_js($dom,$types,\%servers);
1.110 raeburn 391: }
1.6 raeburn 392: my @roles = ('student','coordinator','author','admin');
1.30 raeburn 393: my @actions = &Apache::loncommon::get_env_multiple('form.actions');
1.3 raeburn 394: &Apache::lonhtmlcommon::add_breadcrumb
1.30 raeburn 395: ({href=>"javascript:changePage(document.$phase,'pickactions')",
1.133 raeburn 396: text=>"Settings to display/modify"});
1.9 raeburn 397: my $confname = $dom.'-domainconfig';
1.3 raeburn 398: if ($phase eq 'process') {
1.91 raeburn 399: &Apache::lonconfigsettings::make_changes($r,$dom,$phase,$context,\@prefs_order,\%prefs,\%domconfig,$confname,\@roles);
1.30 raeburn 400: } elsif ($phase eq 'display') {
1.150 ! raeburn 401: &Apache::lonconfigsettings::display_settings($r,$dom,$phase,$context,\@prefs_order,\%prefs,\%domconfig,$confname,$js);
1.1 raeburn 402: } else {
1.21 raeburn 403: if (keys(%domconfig) == 0) {
404: my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
1.29 raeburn 405: my @ids=&Apache::lonnet::current_machine_ids();
406: if (!grep(/^\Q$primarylibserv\E$/,@ids)) {
1.21 raeburn 407: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.41 raeburn 408: my @loginimages = ('img','logo','domlogo','login');
1.21 raeburn 409: my $custom_img_count = 0;
410: foreach my $img (@loginimages) {
411: if ($designhash{$dom.'.login.'.$img} ne '') {
412: $custom_img_count ++;
413: }
414: }
415: foreach my $role (@roles) {
416: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
417: $custom_img_count ++;
418: }
419: }
420: if ($custom_img_count > 0) {
1.94 raeburn 421: &Apache::lonconfigsettings::print_header($r,$phase,$context);
1.21 raeburn 422: my $switch_server = &check_switchserver($dom,$confname);
1.29 raeburn 423: $r->print(
424: &mt('Domain configuration settings have yet to be saved for this domain via the web-based domain preferences interface.').'<br />'.
425: &mt("While this remains so, you must switch to the domain's primary library server in order to update settings.").'<br /><br />'.
426: &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 />'.
427: &mt("However, you will still need to switch to the domain's primary library server to upload new images or logos.").'<br /><br />');
428: if ($switch_server) {
1.30 raeburn 429: $r->print($switch_server.' '.&mt('to primary library server for domain: [_1]',$dom));
1.29 raeburn 430: }
1.91 raeburn 431: $r->print(&Apache::loncommon::end_page());
1.21 raeburn 432: return OK;
433: }
434: }
435: }
1.91 raeburn 436: &Apache::lonconfigsettings::display_choices($r,$phase,$context,\@prefs_order,\%prefs);
1.3 raeburn 437: }
438: return OK;
439: }
440:
441: sub process_changes {
1.92 raeburn 442: my ($r,$dom,$confname,$action,$roles,$values) = @_;
443: my %domconfig;
444: if (ref($values) eq 'HASH') {
445: %domconfig = %{$values};
446: }
1.3 raeburn 447: my $output;
448: if ($action eq 'login') {
1.9 raeburn 449: $output = &modify_login($r,$dom,$confname,%domconfig);
1.6 raeburn 450: } elsif ($action eq 'rolecolors') {
1.9 raeburn 451: $output = &modify_rolecolors($r,$dom,$confname,$roles,
452: %domconfig);
1.3 raeburn 453: } elsif ($action eq 'quotas') {
1.86 raeburn 454: $output = &modify_quotas($dom,$action,%domconfig);
1.3 raeburn 455: } elsif ($action eq 'autoenroll') {
456: $output = &modify_autoenroll($dom,%domconfig);
457: } elsif ($action eq 'autoupdate') {
458: $output = &modify_autoupdate($dom,%domconfig);
1.125 raeburn 459: } elsif ($action eq 'autocreate') {
460: $output = &modify_autocreate($dom,%domconfig);
1.23 raeburn 461: } elsif ($action eq 'directorysrch') {
462: $output = &modify_directorysrch($dom,%domconfig);
1.27 raeburn 463: } elsif ($action eq 'usercreation') {
1.28 raeburn 464: $output = &modify_usercreation($dom,%domconfig);
1.33 raeburn 465: } elsif ($action eq 'usermodification') {
466: $output = &modify_usermodification($dom,%domconfig);
1.28 raeburn 467: } elsif ($action eq 'contacts') {
468: $output = &modify_contacts($dom,%domconfig);
1.43 raeburn 469: } elsif ($action eq 'defaults') {
470: $output = &modify_defaults($dom,$r);
1.46 raeburn 471: } elsif ($action eq 'scantron') {
1.48 raeburn 472: $output = &modify_scantron($r,$dom,$confname,%domconfig);
473: } elsif ($action eq 'coursecategories') {
474: $output = &modify_coursecategories($dom,%domconfig);
1.69 raeburn 475: } elsif ($action eq 'serverstatuses') {
476: $output = &modify_serverstatuses($dom,%domconfig);
1.86 raeburn 477: } elsif ($action eq 'requestcourses') {
478: $output = &modify_quotas($dom,$action,%domconfig);
1.118 jms 479: } elsif ($action eq 'helpsettings') {
1.122 jms 480: $output = &modify_helpsettings($r,$dom,$confname,%domconfig);
1.121 raeburn 481: } elsif ($action eq 'coursedefaults') {
482: $output = &modify_coursedefaults($dom,%domconfig);
1.137 raeburn 483: } elsif ($action eq 'usersessions') {
484: $output = &modify_usersessions($dom,%domconfig);
1.150 ! raeburn 485: } elsif ($action eq 'loadbalancing') {
! 486: $output = &modify_loadbalancing($dom,%domconfig);
1.3 raeburn 487: }
488: return $output;
489: }
490:
491: sub print_config_box {
1.9 raeburn 492: my ($r,$dom,$confname,$phase,$action,$item,$settings) = @_;
1.30 raeburn 493: my $rowtotal = 0;
1.49 raeburn 494: my $output;
495: if ($action eq 'coursecategories') {
496: $output = &coursecategories_javascript($settings);
1.91 raeburn 497: }
1.49 raeburn 498: $output .=
1.30 raeburn 499: '<table class="LC_nested_outer">
1.3 raeburn 500: <tr>
1.66 raeburn 501: <th align="left" valign="middle"><span class="LC_nobreak">'.
502: &mt($item->{text}).' '.
503: &Apache::loncommon::help_open_topic($item->{'help'}).'</span></th>'."\n".
504: '</tr>';
1.30 raeburn 505: $rowtotal ++;
1.110 raeburn 506: my $numheaders = 1;
507: if (ref($item->{'header'}) eq 'ARRAY') {
508: $numheaders = scalar(@{$item->{'header'}});
509: }
510: if ($numheaders > 1) {
1.64 raeburn 511: my $colspan = '';
1.145 raeburn 512: my $rightcolspan = '';
1.122 jms 513: if (($action eq 'rolecolors') || ($action eq 'coursecategories') || ($action eq 'helpsettings')) {
1.64 raeburn 514: $colspan = ' colspan="2"';
515: }
1.145 raeburn 516: if ($action eq 'usersessions') {
517: $rightcolspan = ' colspan="3"';
518: }
1.30 raeburn 519: $output .= '
1.3 raeburn 520: <tr>
521: <td>
522: <table class="LC_nested">
523: <tr class="LC_info_row">
1.59 bisitz 524: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[0]->{'col1'}).'</td>
1.145 raeburn 525: <td class="LC_right_item"'.$rightcolspan.'>'.&mt($item->{'header'}->[0]->{'col2'}).'</td>
1.30 raeburn 526: </tr>';
1.69 raeburn 527: $rowtotal ++;
1.6 raeburn 528: if ($action eq 'autoupdate') {
1.30 raeburn 529: $output .= &print_autoupdate('top',$dom,$settings,\$rowtotal);
1.28 raeburn 530: } elsif ($action eq 'usercreation') {
1.33 raeburn 531: $output .= &print_usercreation('top',$dom,$settings,\$rowtotal);
532: } elsif ($action eq 'usermodification') {
533: $output .= &print_usermodification('top',$dom,$settings,\$rowtotal);
1.57 raeburn 534: } elsif ($action eq 'coursecategories') {
535: $output .= &print_coursecategories('top',$dom,$item,$settings,\$rowtotal);
1.110 raeburn 536: } elsif ($action eq 'login') {
537: $output .= &print_login('top',$dom,$confname,$phase,$settings,\$rowtotal);
538: $colspan = ' colspan="2"';
1.102 raeburn 539: } elsif ($action eq 'requestcourses') {
540: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.118 jms 541: } elsif ($action eq 'helpsettings') {
1.122 jms 542: $output .= &print_helpsettings('top',$dom,$confname,$settings,\$rowtotal);
1.137 raeburn 543: } elsif ($action eq 'usersessions') {
544: $output .= &print_usersessions('top',$dom,$settings,\$rowtotal);
1.122 jms 545: } elsif ($action eq 'rolecolors') {
1.30 raeburn 546: $output .= &print_rolecolors($phase,'student',$dom,$confname,$settings,\$rowtotal);
1.139 raeburn 547: } elsif ($action eq 'coursedefaults') {
548: $output .= &print_coursedefaults('top',$dom,$settings,\$rowtotal);
1.6 raeburn 549: }
1.30 raeburn 550: $output .= '
1.6 raeburn 551: </table>
552: </td>
553: </tr>
554: <tr>
555: <td>
556: <table class="LC_nested">
557: <tr class="LC_info_row">
1.59 bisitz 558: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col1'}).'</td>';
1.57 raeburn 559: $output .= '
1.59 bisitz 560: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col2'}).'</td>
1.30 raeburn 561: </tr>';
562: $rowtotal ++;
1.6 raeburn 563: if ($action eq 'autoupdate') {
1.131 raeburn 564: $output .= &print_autoupdate('middle',$dom,$settings,\$rowtotal).'
565: </table>
566: </td>
567: </tr>
568: <tr>
569: <td>
570: <table class="LC_nested">
571: <tr class="LC_info_row">
572: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
573: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
574: &print_autoupdate('bottom',$dom,$settings,\$rowtotal);
575: $rowtotal ++;
1.28 raeburn 576: } elsif ($action eq 'usercreation') {
1.34 raeburn 577: $output .= &print_usercreation('middle',$dom,$settings,\$rowtotal).'
578: </table>
579: </td>
580: </tr>
581: <tr>
582: <td>
583: <table class="LC_nested">
584: <tr class="LC_info_row">
1.59 bisitz 585: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
586: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
1.34 raeburn 587: &print_usercreation('bottom',$dom,$settings,\$rowtotal);
588: $rowtotal ++;
1.33 raeburn 589: } elsif ($action eq 'usermodification') {
1.63 raeburn 590: $output .= &print_usermodification('middle',$dom,$settings,\$rowtotal).'
591: </table>
592: </td>
593: </tr>
594: <tr>
595: <td>
596: <table class="LC_nested">
597: <tr class="LC_info_row">
598: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
599: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
600: &print_usermodification('bottom',$dom,$settings,\$rowtotal);
601: $rowtotal ++;
1.57 raeburn 602: } elsif ($action eq 'coursecategories') {
603: $output .= &print_coursecategories('bottom',$dom,$item,$settings,\$rowtotal);
1.110 raeburn 604: } elsif ($action eq 'login') {
605: $output .= &print_login('bottom',$dom,$confname,$phase,$settings,\$rowtotal);
1.102 raeburn 606: } elsif ($action eq 'requestcourses') {
607: $output .= &print_courserequestmail($dom,$settings,\$rowtotal);
1.122 jms 608: } elsif ($action eq 'helpsettings') {
609: $output .= &print_helpsettings('bottom',$dom,$confname,$settings,\$rowtotal);
1.137 raeburn 610: } elsif ($action eq 'usersessions') {
1.145 raeburn 611: $output .= &print_usersessions('middle',$dom,$settings,\$rowtotal).'
612: </table>
613: </td>
614: </tr>
615: <tr>
616: <td>
617: <table class="LC_nested">
618: <tr class="LC_info_row">
619: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
620: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
621: &print_usersessions('bottom',$dom,$settings,\$rowtotal);
622: $rowtotal ++;
1.139 raeburn 623: } elsif ($action eq 'coursedefaults') {
624: $output .= &print_coursedefaults('bottom',$dom,$settings,\$rowtotal);
1.122 jms 625: } elsif ($action eq 'rolecolors') {
1.30 raeburn 626: $output .= &print_rolecolors($phase,'coordinator',$dom,$confname,$settings,\$rowtotal).'
1.6 raeburn 627: </table>
628: </td>
629: </tr>
630: <tr>
631: <td>
632: <table class="LC_nested">
633: <tr class="LC_info_row">
1.69 raeburn 634: <td class="LC_left_item"'.$colspan.' valign="top">'.
635: &mt($item->{'header'}->[2]->{'col1'}).'</td>
636: <td class="LC_right_item" valign="top">'.
637: &mt($item->{'header'}->[2]->{'col2'}).'</td>
1.3 raeburn 638: </tr>'.
1.30 raeburn 639: &print_rolecolors($phase,'author',$dom,$confname,$settings,\$rowtotal).'
1.3 raeburn 640: </table>
641: </td>
642: </tr>
643: <tr>
644: <td>
645: <table class="LC_nested">
646: <tr class="LC_info_row">
1.59 bisitz 647: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
648: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
1.3 raeburn 649: </tr>'.
1.30 raeburn 650: &print_rolecolors($phase,'admin',$dom,$confname,$settings,\$rowtotal);
651: $rowtotal += 2;
1.6 raeburn 652: }
1.3 raeburn 653: } else {
1.30 raeburn 654: $output .= '
1.3 raeburn 655: <tr>
656: <td>
657: <table class="LC_nested">
1.30 raeburn 658: <tr class="LC_info_row">';
1.24 raeburn 659: if (($action eq 'login') || ($action eq 'directorysrch')) {
1.30 raeburn 660: $output .= '
1.59 bisitz 661: <td class="LC_left_item" colspan="2">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
1.69 raeburn 662: } elsif ($action eq 'serverstatuses') {
663: $output .= '
664: <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).
665: '<br />('.&mt('Automatic access for Dom. Coords.').')</td>';
666:
1.6 raeburn 667: } else {
1.30 raeburn 668: $output .= '
1.69 raeburn 669: <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
670: }
1.72 raeburn 671: if (defined($item->{'header'}->[0]->{'col3'})) {
672: $output .= '<td class="LC_left_item" valign="top">'.
673: &mt($item->{'header'}->[0]->{'col2'});
674: if ($action eq 'serverstatuses') {
675: $output .= '<br />(<tt>'.&mt('user1:domain1,user2:domain2 etc.').'</tt>)';
676: }
1.69 raeburn 677: } else {
678: $output .= '<td class="LC_right_item" valign="top">'.
679: &mt($item->{'header'}->[0]->{'col2'});
680: }
681: $output .= '</td>';
682: if ($item->{'header'}->[0]->{'col3'}) {
1.150 ! raeburn 683: if (defined($item->{'header'}->[0]->{'col4'})) {
! 684: $output .= '<td class="LC_left_item" valign="top">'.
! 685: &mt($item->{'header'}->[0]->{'col3'});
! 686: } else {
! 687: $output .= '<td class="LC_right_item" valign="top">'.
! 688: &mt($item->{'header'}->[0]->{'col3'});
! 689: }
1.69 raeburn 690: if ($action eq 'serverstatuses') {
691: $output .= '<br />(<tt>'.&mt('IP1,IP2 etc.').'</tt>)';
692: }
693: $output .= '</td>';
1.6 raeburn 694: }
1.150 ! raeburn 695: if ($item->{'header'}->[0]->{'col4'}) {
! 696: $output .= '<td class="LC_right_item" valign="top">'.
! 697: &mt($item->{'header'}->[0]->{'col4'});
! 698: }
1.69 raeburn 699: $output .= '</tr>';
1.48 raeburn 700: $rowtotal ++;
1.3 raeburn 701: if ($action eq 'login') {
1.110 raeburn 702: $output .= &print_login('bottom',$dom,$confname,$phase,$settings,
703: \$rowtotal);
1.3 raeburn 704: } elsif ($action eq 'quotas') {
1.86 raeburn 705: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.3 raeburn 706: } elsif ($action eq 'autoenroll') {
1.30 raeburn 707: $output .= &print_autoenroll($dom,$settings,\$rowtotal);
1.125 raeburn 708: } elsif ($action eq 'autocreate') {
709: $output .= &print_autocreate($dom,$settings,\$rowtotal);
1.23 raeburn 710: } elsif ($action eq 'directorysrch') {
1.30 raeburn 711: $output .= &print_directorysrch($dom,$settings,\$rowtotal);
1.28 raeburn 712: } elsif ($action eq 'contacts') {
1.30 raeburn 713: $output .= &print_contacts($dom,$settings,\$rowtotal);
1.43 raeburn 714: } elsif ($action eq 'defaults') {
715: $output .= &print_defaults($dom,\$rowtotal);
1.46 raeburn 716: } elsif ($action eq 'scantron') {
717: $output .= &print_scantronformat($r,$dom,$confname,$settings,\$rowtotal);
1.69 raeburn 718: } elsif ($action eq 'serverstatuses') {
719: $output .= &print_serverstatuses($dom,$settings,\$rowtotal);
1.118 jms 720: } elsif ($action eq 'helpsettings') {
1.122 jms 721: $output .= &print_helpsettings('top',$dom,$confname,$settings,\$rowtotal);
1.150 ! raeburn 722: } elsif ($action eq 'loadbalancing') {
! 723: $output .= &print_loadbalancing($dom,$settings,\$rowtotal);
1.121 raeburn 724: }
1.3 raeburn 725: }
1.30 raeburn 726: $output .= '
1.3 raeburn 727: </table>
728: </td>
729: </tr>
1.30 raeburn 730: </table><br />';
731: return ($output,$rowtotal);
1.1 raeburn 732: }
733:
1.3 raeburn 734: sub print_login {
1.110 raeburn 735: my ($position,$dom,$confname,$phase,$settings,$rowtotal) = @_;
736: my ($css_class,$datatable);
1.6 raeburn 737: my %choices = &login_choices();
1.110 raeburn 738:
739: if ($position eq 'top') {
1.149 raeburn 740: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.110 raeburn 741: my $choice = $choices{'disallowlogin'};
742: $css_class = ' class="LC_odd_row"';
1.128 raeburn 743: $datatable .= '<tr'.$css_class.'><td>'.$choice.'</td>'.
1.110 raeburn 744: '<td align="right"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1.128 raeburn 745: '<th>'.$choices{'server'}.'</th>'.
746: '<th>'.$choices{'serverpath'}.'</th>'.
747: '<th>'.$choices{'custompath'}.'</th>'.
748: '<th><span class="LC_nobreak">'.$choices{'exempt'}.'</span></th></tr>'."\n";
1.110 raeburn 749: my %disallowed;
750: if (ref($settings) eq 'HASH') {
751: if (ref($settings->{'loginvia'}) eq 'HASH') {
752: %disallowed = %{$settings->{'loginvia'}};
753: }
754: }
755: foreach my $lonhost (sort(keys(%servers))) {
756: my $direct = 'selected="selected"';
1.128 raeburn 757: if (ref($disallowed{$lonhost}) eq 'HASH') {
758: if ($disallowed{$lonhost}{'server'} ne '') {
759: $direct = '';
760: }
1.110 raeburn 761: }
1.115 raeburn 762: $datatable .= '<tr><td>'.$servers{$lonhost}.'</td>'.
1.128 raeburn 763: '<td><select name="'.$lonhost.'_server">'.
1.110 raeburn 764: '<option value=""'.$direct.'>'.$choices{'directlogin'}.
765: '</option>';
766: foreach my $hostid (keys(%servers)) {
1.115 raeburn 767: next if ($servers{$hostid} eq $servers{$lonhost});
1.110 raeburn 768: my $selected = '';
1.128 raeburn 769: if (ref($disallowed{$lonhost}) eq 'HASH') {
770: if ($hostid eq $disallowed{$lonhost}{'server'}) {
771: $selected = 'selected="selected"';
772: }
1.110 raeburn 773: }
774: $datatable .= '<option value="'.$hostid.'"'.$selected.'>'.
775: $servers{$hostid}.'</option>';
776: }
1.128 raeburn 777: $datatable .= '</select></td>'.
778: '<td><select name="'.$lonhost.'_serverpath">';
779: foreach my $path ('','/','/adm/login','/adm/roles','custom') {
780: my $pathname = $path;
781: if ($path eq 'custom') {
782: $pathname = &mt('Custom Path').' ->';
783: }
784: my $selected = '';
785: if (ref($disallowed{$lonhost}) eq 'HASH') {
786: if ($path eq $disallowed{$lonhost}{'serverpath'}) {
787: $selected = 'selected="selected"';
788: }
789: } elsif ($path eq '') {
790: $selected = 'selected="selected"';
791: }
792: $datatable .= '<option value="'.$path.'"'.$selected.'>'.$pathname.'</option>';
793: }
794: $datatable .= '</select></td>';
795: my ($custom,$exempt);
796: if (ref($disallowed{$lonhost}) eq 'HASH') {
797: $custom = $disallowed{$lonhost}{'custompath'};
798: $exempt = $disallowed{$lonhost}{'exempt'};
799: }
800: $datatable .= '<td><input type="text" name="'.$lonhost.'_custompath" size="6" value="'.$custom.'" /></td>'.
801: '<td><input type="text" name="'.$lonhost.'_exempt" size="8" value="'.$exempt.'" /></td>'.
802: '</tr>';
1.110 raeburn 803: }
804: $datatable .= '</table></td></tr>';
805: return $datatable;
806: }
807:
1.42 raeburn 808: my %defaultchecked = (
1.43 raeburn 809: 'coursecatalog' => 'on',
810: 'adminmail' => 'off',
811: 'newuser' => 'off',
812: );
1.118 jms 813: my @toggles = ('coursecatalog','adminmail','newuser');
1.42 raeburn 814: my (%checkedon,%checkedoff);
815: foreach my $item (@toggles) {
816: if ($defaultchecked{$item} eq 'on') {
817: $checkedon{$item} = ' checked="checked" ';
818: $checkedoff{$item} = ' ';
819: } elsif ($defaultchecked{$item} eq 'off') {
820: $checkedoff{$item} = ' checked="checked" ';
821: $checkedon{$item} = ' ';
822: }
823: }
1.41 raeburn 824: my @images = ('img','logo','domlogo','login');
825: my @logintext = ('textcol','bgcol');
1.6 raeburn 826: my @bgs = ('pgbg','mainbg','sidebg');
827: my @links = ('link','alink','vlink');
1.7 albertel 828: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.6 raeburn 829: my %defaultdesign = %Apache::loncommon::defaultdesign;
830: my (%is_custom,%designs);
831: my %defaults = (
832: font => $defaultdesign{'login.font'},
833: );
834: foreach my $item (@images) {
835: $defaults{$item} = $defaultdesign{'login.'.$item};
1.70 raeburn 836: $defaults{'showlogo'}{$item} = 1;
1.6 raeburn 837: }
838: foreach my $item (@bgs) {
839: $defaults{'bgs'}{$item} = $defaultdesign{'login.'.$item};
840: }
1.41 raeburn 841: foreach my $item (@logintext) {
842: $defaults{'logintext'}{$item} = $defaultdesign{'login.'.$item};
843: }
1.6 raeburn 844: foreach my $item (@links) {
845: $defaults{'links'}{$item} = $defaultdesign{'login.'.$item};
846: }
1.3 raeburn 847: if (ref($settings) eq 'HASH') {
1.42 raeburn 848: foreach my $item (@toggles) {
849: if ($settings->{$item} eq '1') {
850: $checkedon{$item} = ' checked="checked" ';
851: $checkedoff{$item} = ' ';
852: } elsif ($settings->{$item} eq '0') {
853: $checkedoff{$item} = ' checked="checked" ';
854: $checkedon{$item} = ' ';
855: }
1.1 raeburn 856: }
1.6 raeburn 857: foreach my $item (@images) {
1.70 raeburn 858: if (defined($settings->{$item})) {
1.6 raeburn 859: $designs{$item} = $settings->{$item};
860: $is_custom{$item} = 1;
861: }
1.70 raeburn 862: if (defined($settings->{'showlogo'}{$item})) {
863: $designs{'showlogo'}{$item} = $settings->{'showlogo'}{$item};
864: }
1.6 raeburn 865: }
1.41 raeburn 866: foreach my $item (@logintext) {
867: if ($settings->{$item} ne '') {
868: $designs{'logintext'}{$item} = $settings->{$item};
869: $is_custom{$item} = 1;
870: }
871: }
1.6 raeburn 872: if ($settings->{'font'} ne '') {
873: $designs{'font'} = $settings->{'font'};
874: $is_custom{'font'} = 1;
875: }
876: foreach my $item (@bgs) {
877: if ($settings->{$item} ne '') {
878: $designs{'bgs'}{$item} = $settings->{$item};
879: $is_custom{$item} = 1;
880: }
881: }
882: foreach my $item (@links) {
883: if ($settings->{$item} ne '') {
884: $designs{'links'}{$item} = $settings->{$item};
885: $is_custom{$item} = 1;
886: }
887: }
888: } else {
889: if ($designhash{$dom.'.login.font'} ne '') {
890: $designs{'font'} = $designhash{$dom.'.login.font'};
891: $is_custom{'font'} = 1;
892: }
1.8 raeburn 893: foreach my $item (@images) {
894: if ($designhash{$dom.'.login.'.$item} ne '') {
895: $designs{$item} = $designhash{$dom.'.login.'.$item};
896: $is_custom{$item} = 1;
897: }
898: }
1.6 raeburn 899: foreach my $item (@bgs) {
900: if ($designhash{$dom.'.login.'.$item} ne '') {
901: $designs{'bgs'}{$item} = $designhash{$dom.'.login.'.$item};
902: $is_custom{$item} = 1;
903: }
904: }
905: foreach my $item (@links) {
906: if ($designhash{$dom.'.login.'.$item} ne '') {
907: $designs{'links'}{$item} = $designhash{$dom.'.login.'.$item};
908: $is_custom{$item} = 1;
909: }
910: }
1.1 raeburn 911: }
1.6 raeburn 912: my %alt_text = &Apache::lonlocal::texthash ( img => 'Log-in banner',
913: logo => 'Institution Logo',
1.41 raeburn 914: domlogo => 'Domain Logo',
915: login => 'Login box');
1.6 raeburn 916: my $itemcount = 1;
1.42 raeburn 917: foreach my $item (@toggles) {
918: $css_class = $itemcount%2?' class="LC_odd_row"':'';
919: $datatable .=
920: '<tr'.$css_class.'><td colspan="2">'.$choices{$item}.
921: '</td><td>'.
922: '<span class="LC_nobreak"><label><input type="radio" name="'.
923: $item.'"'.$checkedon{$item}.' value="1" />'.&mt('Yes').
924: '</label> <label><input type="radio" name="'.$item.'"'.
925: $checkedoff{$item}.' value="0" />'.&mt('No').'</label></span></td>'.
926: '</tr>';
927: $itemcount ++;
928: }
1.135 bisitz 929: $datatable .= &display_color_options($dom,$confname,$phase,'login',$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal,\@logintext);
1.6 raeburn 930: $datatable .= '</tr></table></td></tr>';
931: return $datatable;
932: }
933:
934: sub login_choices {
935: my %choices =
936: &Apache::lonlocal::texthash (
1.116 bisitz 937: coursecatalog => 'Display Course/Community Catalog link?',
1.110 raeburn 938: adminmail => "Display Administrator's E-mail Address?",
939: disallowlogin => "Login page requests redirected",
940: hostid => "Server",
1.128 raeburn 941: server => "Redirect to:",
942: serverpath => "Path",
943: custompath => "Custom",
944: exempt => "Exempt IP(s)",
1.110 raeburn 945: directlogin => "No redirect",
946: newuser => "Link to create a user account",
947: img => "Header",
948: logo => "Main Logo",
949: domlogo => "Domain Logo",
950: login => "Log-in Header",
951: textcol => "Text color",
952: bgcol => "Box color",
953: bgs => "Background colors",
954: links => "Link colors",
955: font => "Font color",
956: pgbg => "Header",
957: mainbg => "Page",
958: sidebg => "Login box",
959: link => "Link",
960: alink => "Active link",
961: vlink => "Visited link",
1.6 raeburn 962: );
963: return %choices;
964: }
965:
966: sub print_rolecolors {
1.30 raeburn 967: my ($phase,$role,$dom,$confname,$settings,$rowtotal) = @_;
1.6 raeburn 968: my %choices = &color_font_choices();
969: my @bgs = ('pgbg','tabbg','sidebg');
970: my @links = ('link','alink','vlink');
971: my @images = ('img');
972: my %alt_text = &Apache::lonlocal::texthash(img => "Banner for $role role");
1.7 albertel 973: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.6 raeburn 974: my %defaultdesign = %Apache::loncommon::defaultdesign;
975: my (%is_custom,%designs);
976: my %defaults = (
977: img => $defaultdesign{$role.'.img'},
978: font => $defaultdesign{$role.'.font'},
1.97 tempelho 979: fontmenu => $defaultdesign{$role.'.fontmenu'},
1.6 raeburn 980: );
981: foreach my $item (@bgs) {
982: $defaults{'bgs'}{$item} = $defaultdesign{$role.'.'.$item};
983: }
984: foreach my $item (@links) {
985: $defaults{'links'}{$item} = $defaultdesign{$role.'.'.$item};
986: }
987: if (ref($settings) eq 'HASH') {
988: if (ref($settings->{$role}) eq 'HASH') {
989: if ($settings->{$role}->{'img'} ne '') {
990: $designs{'img'} = $settings->{$role}->{'img'};
991: $is_custom{'img'} = 1;
992: }
993: if ($settings->{$role}->{'font'} ne '') {
994: $designs{'font'} = $settings->{$role}->{'font'};
995: $is_custom{'font'} = 1;
996: }
1.97 tempelho 997: if ($settings->{$role}->{'fontmenu'} ne '') {
998: $designs{'fontmenu'} = $settings->{$role}->{'fontmenu'};
999: $is_custom{'fontmenu'} = 1;
1000: }
1.6 raeburn 1001: foreach my $item (@bgs) {
1002: if ($settings->{$role}->{$item} ne '') {
1003: $designs{'bgs'}{$item} = $settings->{$role}->{$item};
1004: $is_custom{$item} = 1;
1005: }
1006: }
1007: foreach my $item (@links) {
1008: if ($settings->{$role}->{$item} ne '') {
1009: $designs{'links'}{$item} = $settings->{$role}->{$item};
1010: $is_custom{$item} = 1;
1011: }
1012: }
1013: }
1014: } else {
1015: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
1016: $designs{img} = $designhash{$dom.'.'.$role.'.img'};
1017: $is_custom{'img'} = 1;
1018: }
1.97 tempelho 1019: if ($designhash{$dom.'.'.$role.'.fontmenu'} ne '') {
1020: $designs{fontmenu} = $designhash{$dom.'.'.$role.'.fontmenu'};
1021: $is_custom{'fontmenu'} = 1;
1022: }
1.6 raeburn 1023: if ($designhash{$dom.'.'.$role.'.font'} ne '') {
1024: $designs{font} = $designhash{$dom.'.'.$role.'.font'};
1025: $is_custom{'font'} = 1;
1026: }
1027: foreach my $item (@bgs) {
1028: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1029: $designs{'bgs'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1030: $is_custom{$item} = 1;
1031:
1032: }
1033: }
1034: foreach my $item (@links) {
1035: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1036: $designs{'links'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1037: $is_custom{$item} = 1;
1038: }
1039: }
1040: }
1041: my $itemcount = 1;
1.30 raeburn 1042: my $datatable = &display_color_options($dom,$confname,$phase,$role,$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal);
1.6 raeburn 1043: $datatable .= '</tr></table></td></tr>';
1044: return $datatable;
1045: }
1046:
1047: sub display_color_options {
1.9 raeburn 1048: my ($dom,$confname,$phase,$role,$itemcount,$choices,$is_custom,$defaults,$designs,
1.135 bisitz 1049: $images,$bgs,$links,$alt_text,$rowtotal,$logintext) = @_;
1.6 raeburn 1050: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.134 raeburn 1051: my $datatable = '<tr'.$css_class.'>'.
1.6 raeburn 1052: '<td>'.$choices->{'font'}.'</td>';
1053: if (!$is_custom->{'font'}) {
1.30 raeburn 1054: $datatable .= '<td>'.&mt('Default in use:').' <span id="css_default_'.$role.'_font" style="color: '.$defaults->{'font'}.';">'.$defaults->{'font'}.'</span></td>';
1.6 raeburn 1055: } else {
1056: $datatable .= '<td> </td>';
1057: }
1058: my $fontlink = &color_pick($phase,$role,'font',$choices->{'font'},$designs->{'font'});
1.8 raeburn 1059: $datatable .= '<td><span class="LC_nobreak">'.
1.6 raeburn 1060: '<input type="text" size="10" name="'.$role.'_font"'.
1.8 raeburn 1061: ' value="'.$designs->{'font'}.'" /> '.$fontlink.
1.30 raeburn 1062: ' <span id="css_'.$role.'_font" style="background-color: '.
1063: $designs->{'font'}.';"> </span>'.
1.8 raeburn 1064: '</span></td></tr>';
1.107 raeburn 1065: unless ($role eq 'login') {
1066: $datatable .= '<tr'.$css_class.'>'.
1067: '<td>'.$choices->{'fontmenu'}.'</td>';
1068: if (!$is_custom->{'fontmenu'}) {
1069: $datatable .= '<td>'.&mt('Default in use:').' <span id="css_default_'.$role.'_font" style="color: '.$defaults->{'fontmenu'}.';">'.$defaults->{'fontmenu'}.'</span></td>';
1070: } else {
1071: $datatable .= '<td> </td>';
1072: }
1073: $fontlink = &color_pick($phase,$role,'fontmenu',$choices->{'fontmenu'},$designs->{'fontmenu'});
1074: $datatable .= '<td><span class="LC_nobreak">'.
1075: '<input type="text" size="10" name="'.$role.'_fontmenu"'.
1076: ' value="'.$designs->{'fontmenu'}.'" /> '.$fontlink.
1077: ' <span id="css_'.$role.'_fontmenu" style="background-color: '.
1078: $designs->{'fontmenu'}.';"> </span>'.
1079: '</span></td></tr>';
1.97 tempelho 1080: }
1.9 raeburn 1081: my $switchserver = &check_switchserver($dom,$confname);
1.6 raeburn 1082: foreach my $img (@{$images}) {
1.18 albertel 1083: $itemcount ++;
1.6 raeburn 1084: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.8 raeburn 1085: $datatable .= '<tr'.$css_class.'>'.
1.70 raeburn 1086: '<td>'.$choices->{$img};
1.41 raeburn 1087: my ($imgfile,$img_import,$login_hdr_pick,$logincolors);
1.70 raeburn 1088: if ($role eq 'login') {
1089: if ($img eq 'login') {
1090: $login_hdr_pick =
1.135 bisitz 1091: &login_header_options($img,$role,$defaults,$is_custom,$choices);
1.70 raeburn 1092: $logincolors =
1093: &login_text_colors($img,$role,$logintext,$phase,$choices,
1094: $designs);
1095: } elsif ($img ne 'domlogo') {
1096: $datatable.= &logo_display_options($img,$defaults,$designs);
1097: }
1098: }
1099: $datatable .= '</td>';
1.6 raeburn 1100: if ($designs->{$img} ne '') {
1101: $imgfile = $designs->{$img};
1.18 albertel 1102: $img_import = ($imgfile =~ m{^/adm/});
1.6 raeburn 1103: } else {
1104: $imgfile = $defaults->{$img};
1105: }
1106: if ($imgfile) {
1.9 raeburn 1107: my ($showfile,$fullsize);
1108: if ($imgfile =~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
1.6 raeburn 1109: my $urldir = $1;
1110: my $filename = $2;
1111: my @info = &Apache::lonnet::stat_file($designs->{$img});
1112: if (@info) {
1113: my $thumbfile = 'tn-'.$filename;
1114: my @thumb=&Apache::lonnet::stat_file($urldir.'/'.$thumbfile);
1115: if (@thumb) {
1116: $showfile = $urldir.'/'.$thumbfile;
1117: } else {
1118: $showfile = $imgfile;
1119: }
1120: } else {
1121: $showfile = '';
1122: }
1123: } elsif ($imgfile =~ m-^/(adm/[^/]+)/([^/]+)$-) {
1.16 raeburn 1124: $showfile = $imgfile;
1.6 raeburn 1125: my $imgdir = $1;
1126: my $filename = $2;
1127: if (-e "/home/httpd/html/$imgdir/tn-".$filename) {
1128: $showfile = "/$imgdir/tn-".$filename;
1129: } else {
1130: my $input = "/home/httpd/html".$imgfile;
1131: my $output = '/home/httpd/html/'.$imgdir.'/tn-'.$filename;
1132: if (!-e $output) {
1.9 raeburn 1133: my ($width,$height) = &thumb_dimensions();
1.16 raeburn 1134: my ($fullwidth,$fullheight) = &check_dimensions($input);
1135: if ($fullwidth ne '' && $fullheight ne '') {
1136: if ($fullwidth > $width && $fullheight > $height) {
1137: my $size = $width.'x'.$height;
1138: system("convert -sample $size $input $output");
1139: $showfile = '/'.$imgdir.'/tn-'.$filename;
1140: }
1141: }
1.6 raeburn 1142: }
1143: }
1.16 raeburn 1144: }
1.6 raeburn 1145: if ($showfile) {
1.40 raeburn 1146: if ($showfile =~ m{^/(adm|res)/}) {
1147: if ($showfile =~ m{^/res/}) {
1148: my $local_showfile =
1149: &Apache::lonnet::filelocation('',$showfile);
1150: &Apache::lonnet::repcopy($local_showfile);
1151: }
1152: $showfile = &Apache::loncommon::lonhttpdurl($showfile);
1153: }
1154: if ($imgfile) {
1155: if ($imgfile =~ m{^/(adm|res)/}) {
1156: if ($imgfile =~ m{^/res/}) {
1157: my $local_imgfile =
1158: &Apache::lonnet::filelocation('',$imgfile);
1159: &Apache::lonnet::repcopy($local_imgfile);
1160: }
1161: $fullsize = &Apache::loncommon::lonhttpdurl($imgfile);
1162: } else {
1163: $fullsize = $imgfile;
1164: }
1165: }
1.41 raeburn 1166: $datatable .= '<td>';
1167: if ($img eq 'login') {
1.135 bisitz 1168: $datatable .= $login_hdr_pick;
1169: }
1.41 raeburn 1170: $datatable .= &image_changes($is_custom->{$img},$alt_text->{$img},$img_import,
1171: $showfile,$fullsize,$role,$img,$imgfile,$logincolors);
1.6 raeburn 1172: } else {
1173: $datatable .= '<td colspan="2" class="LC_right_item"><br />'.
1174: &mt('Upload:');
1175: }
1176: } else {
1177: $datatable .= '<td colspan="2" class="LC_right_item"><br />'.
1178: &mt('Upload:');
1179: }
1.9 raeburn 1180: if ($switchserver) {
1181: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1182: } else {
1.135 bisitz 1183: if ($img ne 'login') { # suppress file selection for Log-in header
1184: $datatable .=' <input type="file" name="'.$role.'_'.$img.'" />';
1185: }
1.9 raeburn 1186: }
1187: $datatable .= '</td></tr>';
1.6 raeburn 1188: }
1189: $itemcount ++;
1190: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1191: $datatable .= '<tr'.$css_class.'>'.
1192: '<td>'.$choices->{'bgs'}.'</td>';
1193: my $bgs_def;
1194: foreach my $item (@{$bgs}) {
1195: if (!$is_custom->{$item}) {
1.70 raeburn 1196: $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 1197: }
1198: }
1199: if ($bgs_def) {
1.8 raeburn 1200: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$bgs_def.'</tr></table></td>';
1.6 raeburn 1201: } else {
1202: $datatable .= '<td> </td>';
1203: }
1204: $datatable .= '<td class="LC_right_item">'.
1205: '<table border="0"><tr>';
1206: foreach my $item (@{$bgs}) {
1207: my $link = &color_pick($phase,$role,$item,$choices->{$item},$designs->{'bgs'}{$item});
1208: $datatable .= '<td align="center">'.$link;
1209: if ($designs->{'bgs'}{$item}) {
1.30 raeburn 1210: $datatable .= ' <span id="css_'.$role.'_'.$item.'" style="background-color: '.$designs->{'bgs'}{$item}.';"> </span>';
1.6 raeburn 1211: }
1212: $datatable .= '<br /><input type="text" size="8" name="'.$role.'_'.$item.'" value="'.$designs->{'bgs'}{$item}.
1.41 raeburn 1213: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.6 raeburn 1214: }
1215: $datatable .= '</tr></table></td></tr>';
1216: $itemcount ++;
1217: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1218: $datatable .= '<tr'.$css_class.'>'.
1219: '<td>'.$choices->{'links'}.'</td>';
1220: my $links_def;
1221: foreach my $item (@{$links}) {
1222: if (!$is_custom->{$item}) {
1.30 raeburn 1223: $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 1224: }
1225: }
1226: if ($links_def) {
1.8 raeburn 1227: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$links_def.'</tr></table></td>';
1.6 raeburn 1228: } else {
1229: $datatable .= '<td> </td>';
1230: }
1231: $datatable .= '<td class="LC_right_item">'.
1232: '<table border="0"><tr>';
1233: foreach my $item (@{$links}) {
1.30 raeburn 1234: $datatable .= '<td align="center">'."\n".
1235: &color_pick($phase,$role,$item,$choices->{$item},
1236: $designs->{'links'}{$item});
1.6 raeburn 1237: if ($designs->{'links'}{$item}) {
1.30 raeburn 1238: $datatable.=' <span id="css_'.$role.'_'.$item.'" style="background-color: '.$designs->{'links'}{$item}.';"> </span>';
1.6 raeburn 1239: }
1240: $datatable .= '<br /><input type="text" size="8" name="'.$role.'_'.$item.'" value="'.$designs->{'links'}{$item}.
1241: '" /></td>';
1242: }
1.30 raeburn 1243: $$rowtotal += $itemcount;
1.3 raeburn 1244: return $datatable;
1245: }
1246:
1.70 raeburn 1247: sub logo_display_options {
1248: my ($img,$defaults,$designs) = @_;
1249: my $checkedon;
1250: if (ref($defaults) eq 'HASH') {
1251: if (ref($defaults->{'showlogo'}) eq 'HASH') {
1252: if ($defaults->{'showlogo'}{$img}) {
1253: $checkedon = 'checked="checked" ';
1254: }
1255: }
1256: }
1257: if (ref($designs) eq 'HASH') {
1258: if (ref($designs->{'showlogo'}) eq 'HASH') {
1259: if (defined($designs->{'showlogo'}{$img})) {
1260: if ($designs->{'showlogo'}{$img} == 0) {
1261: $checkedon = '';
1262: } elsif ($designs->{'showlogo'}{$img} == 1) {
1263: $checkedon = 'checked="checked" ';
1264: }
1265: }
1266: }
1267: }
1268: return '<br /><label> <input type="checkbox" name="'.
1269: 'login_showlogo_'.$img.'" value="1" '.$checkedon.'/>'.
1270: &mt('show').'</label>'."\n";
1271: }
1272:
1.41 raeburn 1273: sub login_header_options {
1.135 bisitz 1274: my ($img,$role,$defaults,$is_custom,$choices) = @_;
1275: my $output = '';
1.41 raeburn 1276: if ((!$is_custom->{'textcol'}) || (!$is_custom->{'bgcol'})) {
1.135 bisitz 1277: $output .= &mt('Text default(s):').'<br />';
1.41 raeburn 1278: if (!$is_custom->{'textcol'}) {
1279: $output .= $choices->{'textcol'}.': '.$defaults->{'logintext'}{'textcol'}.
1280: ' ';
1281: }
1282: if (!$is_custom->{'bgcol'}) {
1283: $output .= $choices->{'bgcol'}.': '.
1284: '<span id="css_'.$role.'_font" style="background-color: '.
1285: $defaults->{'logintext'}{'bgcol'}.';"> </span>';
1286: }
1287: $output .= '<br />';
1288: }
1289: $output .='<br />';
1290: return $output;
1291: }
1292:
1293: sub login_text_colors {
1294: my ($img,$role,$logintext,$phase,$choices,$designs) = @_;
1295: my $color_menu = '<table border="0"><tr>';
1296: foreach my $item (@{$logintext}) {
1297: my $link = &color_pick($phase,$role,$item,$choices->{$item},$designs->{'logintext'}{$item});
1298: $color_menu .= '<td align="center">'.$link;
1299: if ($designs->{'logintext'}{$item}) {
1300: $color_menu .= ' <span id="css_'.$role.'_'.$item.'" style="background-color: '.$designs->{'logintext'}{$item}.';"> </span>';
1301: }
1302: $color_menu .= '<br /><input type="text" size="8" name="'.$role.'_'.$item.'" value="'.
1303: $designs->{'logintext'}{$item}.'" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>'.
1304: '<td> </td>';
1305: }
1306: $color_menu .= '</tr></table><br />';
1307: return $color_menu;
1308: }
1309:
1310: sub image_changes {
1311: my ($is_custom,$alt_text,$img_import,$showfile,$fullsize,$role,$img,$imgfile,$logincolors) = @_;
1312: my $output;
1.135 bisitz 1313: if ($img eq 'login') {
1314: # suppress image for Log-in header
1315: } elsif (!$is_custom) {
1.70 raeburn 1316: if ($img ne 'domlogo') {
1.41 raeburn 1317: $output .= &mt('Default image:').'<br />';
1318: } else {
1319: $output .= &mt('Default in use:').'<br />';
1320: }
1321: }
1.135 bisitz 1322: if ($img eq 'login') { # suppress image for Log-in header
1323: $output .= '<td>'.$logincolors;
1.41 raeburn 1324: } else {
1.135 bisitz 1325: if ($img_import) {
1326: $output .= '<input type="hidden" name="'.$role.'_import_'.$img.'" value="'.$imgfile.'" />';
1327: }
1328: $output .= '<a href="'.$fullsize.'" target="_blank"><img src="'.
1329: $showfile.'" alt="'.$alt_text.'" border="0" /></a></td>';
1330: if ($is_custom) {
1331: $output .= '<td>'.$logincolors.'<span class="LC_nobreak"><label>'.
1332: '<input type="checkbox" name="'.
1333: $role.'_del_'.$img.'" value="1" />'.&mt('Delete?').
1334: '</label> '.&mt('Replace:').'</span><br />';
1335: } else {
1336: $output .= '<td valign="bottom">'.$logincolors.&mt('Upload:').'<br />';
1337: }
1.41 raeburn 1338: }
1339: return $output;
1340: }
1341:
1.6 raeburn 1342: sub color_pick {
1343: my ($phase,$role,$item,$desc,$curcol) = @_;
1344: my $link = '<a href="javascript:pjump('."'color_custom','".$desc.
1345: "','".$curcol."','".$role.'_'.$item."','parmform.pres','psub'".
1346: ');">'.$desc.'</a>';
1347: return $link;
1348: }
1349:
1.3 raeburn 1350: sub print_quotas {
1.86 raeburn 1351: my ($dom,$settings,$rowtotal,$action) = @_;
1352: my $context;
1353: if ($action eq 'quotas') {
1354: $context = 'tools';
1355: } else {
1356: $context = $action;
1357: }
1.101 raeburn 1358: my ($datatable,$defaultquota,@usertools,@options,%validations);
1.44 raeburn 1359: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.3 raeburn 1360: my $typecount = 0;
1.101 raeburn 1361: my ($css_class,%titles);
1.86 raeburn 1362: if ($context eq 'requestcourses') {
1.98 raeburn 1363: @usertools = ('official','unofficial','community');
1.106 raeburn 1364: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 1365: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
1366: %titles = &courserequest_titles();
1.86 raeburn 1367: } else {
1368: @usertools = ('aboutme','blog','portfolio');
1.101 raeburn 1369: %titles = &tool_titles();
1.86 raeburn 1370: }
1.26 raeburn 1371: if (ref($types) eq 'ARRAY') {
1.23 raeburn 1372: foreach my $type (@{$types}) {
1.72 raeburn 1373: my $currdefquota;
1.86 raeburn 1374: unless ($context eq 'requestcourses') {
1375: if (ref($settings) eq 'HASH') {
1376: if (ref($settings->{defaultquota}) eq 'HASH') {
1377: $currdefquota = $settings->{defaultquota}->{$type};
1378: } else {
1379: $currdefquota = $settings->{$type};
1380: }
1.78 raeburn 1381: }
1.72 raeburn 1382: }
1.3 raeburn 1383: if (defined($usertypes->{$type})) {
1384: $typecount ++;
1385: $css_class = $typecount%2?' class="LC_odd_row"':'';
1.72 raeburn 1386: $datatable .= '<tr'.$css_class.'>'.
1.3 raeburn 1387: '<td>'.$usertypes->{$type}.'</td>'.
1.72 raeburn 1388: '<td class="LC_left_item">';
1.101 raeburn 1389: if ($context eq 'requestcourses') {
1390: $datatable .= '<table><tr>';
1391: }
1392: my %cell;
1.72 raeburn 1393: foreach my $item (@usertools) {
1.101 raeburn 1394: if ($context eq 'requestcourses') {
1395: my ($curroption,$currlimit);
1396: if (ref($settings) eq 'HASH') {
1397: if (ref($settings->{$item}) eq 'HASH') {
1398: $curroption = $settings->{$item}->{$type};
1399: if ($curroption =~ /^autolimit=(\d*)$/) {
1400: $currlimit = $1;
1401: }
1402: }
1403: }
1404: if (!$curroption) {
1405: $curroption = 'norequest';
1406: }
1407: $datatable .= '<th>'.$titles{$item}.'</th>';
1408: foreach my $option (@options) {
1409: my $val = $option;
1410: if ($option eq 'norequest') {
1411: $val = 0;
1412: }
1413: if ($option eq 'validate') {
1414: my $canvalidate = 0;
1415: if (ref($validations{$item}) eq 'HASH') {
1416: if ($validations{$item}{$type}) {
1417: $canvalidate = 1;
1418: }
1419: }
1420: next if (!$canvalidate);
1421: }
1422: my $checked = '';
1423: if ($option eq $curroption) {
1424: $checked = ' checked="checked"';
1425: } elsif ($option eq 'autolimit') {
1426: if ($curroption =~ /^autolimit/) {
1427: $checked = ' checked="checked"';
1428: }
1429: }
1430: $cell{$item} .= '<span class="LC_nobreak"><label>'.
1431: '<input type="radio" name="crsreq_'.$item.
1432: '_'.$type.'" value="'.$val.'"'.$checked.' />'.
1.127 raeburn 1433: $titles{$option}.'</label>';
1.101 raeburn 1434: if ($option eq 'autolimit') {
1.127 raeburn 1435: $cell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 1436: $item.'_limit_'.$type.'" size="1" '.
1.103 raeburn 1437: 'value="'.$currlimit.'" />';
1.101 raeburn 1438: }
1.127 raeburn 1439: $cell{$item} .= '</span> ';
1.103 raeburn 1440: if ($option eq 'autolimit') {
1.127 raeburn 1441: $cell{$item} .= $titles{'unlimited'};
1.103 raeburn 1442: }
1.101 raeburn 1443: }
1444: } else {
1445: my $checked = 'checked="checked" ';
1446: if (ref($settings) eq 'HASH') {
1447: if (ref($settings->{$item}) eq 'HASH') {
1448: if ($settings->{$item}->{$type} == 0) {
1449: $checked = '';
1450: } elsif ($settings->{$item}->{$type} == 1) {
1451: $checked = 'checked="checked" ';
1452: }
1.78 raeburn 1453: }
1.72 raeburn 1454: }
1.101 raeburn 1455: $datatable .= '<span class="LC_nobreak"><label>'.
1456: '<input type="checkbox" name="'.$context.'_'.$item.
1457: '" value="'.$type.'" '.$checked.'/>'.$titles{$item}.
1458: '</label></span> ';
1.72 raeburn 1459: }
1.101 raeburn 1460: }
1461: if ($context eq 'requestcourses') {
1462: $datatable .= '</tr><tr>';
1463: foreach my $item (@usertools) {
1.106 raeburn 1464: $datatable .= '<td style="vertical-align: top">'.$cell{$item}.'</td>';
1.101 raeburn 1465: }
1466: $datatable .= '</tr></table>';
1.72 raeburn 1467: }
1.86 raeburn 1468: $datatable .= '</td>';
1469: unless ($context eq 'requestcourses') {
1470: $datatable .=
1471: '<td class="LC_right_item"><span class="LC_nobreak">'.
1.3 raeburn 1472: '<input type="text" name="quota_'.$type.
1.72 raeburn 1473: '" value="'.$currdefquota.
1.86 raeburn 1474: '" size="5" /> Mb</span></td>';
1475: }
1476: $datatable .= '</tr>';
1.3 raeburn 1477: }
1478: }
1479: }
1.86 raeburn 1480: unless ($context eq 'requestcourses') {
1481: $defaultquota = '20';
1482: if (ref($settings) eq 'HASH') {
1483: if (ref($settings->{'defaultquota'}) eq 'HASH') {
1484: $defaultquota = $settings->{'defaultquota'}->{'default'};
1485: } elsif (defined($settings->{'default'})) {
1486: $defaultquota = $settings->{'default'};
1487: }
1.3 raeburn 1488: }
1489: }
1490: $typecount ++;
1491: $css_class = $typecount%2?' class="LC_odd_row"':'';
1492: $datatable .= '<tr'.$css_class.'>'.
1.26 raeburn 1493: '<td>'.$othertitle.'</td>'.
1.72 raeburn 1494: '<td class="LC_left_item">';
1.101 raeburn 1495: if ($context eq 'requestcourses') {
1496: $datatable .= '<table><tr>';
1497: }
1498: my %defcell;
1.72 raeburn 1499: foreach my $item (@usertools) {
1.101 raeburn 1500: if ($context eq 'requestcourses') {
1501: my ($curroption,$currlimit);
1502: if (ref($settings) eq 'HASH') {
1503: if (ref($settings->{$item}) eq 'HASH') {
1504: $curroption = $settings->{$item}->{'default'};
1505: if ($curroption =~ /^autolimit=(\d*)$/) {
1506: $currlimit = $1;
1507: }
1508: }
1509: }
1510: if (!$curroption) {
1511: $curroption = 'norequest';
1512: }
1513: $datatable .= '<th>'.$titles{$item}.'</th>';
1514: foreach my $option (@options) {
1515: my $val = $option;
1516: if ($option eq 'norequest') {
1517: $val = 0;
1518: }
1519: if ($option eq 'validate') {
1520: my $canvalidate = 0;
1521: if (ref($validations{$item}) eq 'HASH') {
1522: if ($validations{$item}{'default'}) {
1523: $canvalidate = 1;
1524: }
1525: }
1526: next if (!$canvalidate);
1527: }
1528: my $checked = '';
1529: if ($option eq $curroption) {
1530: $checked = ' checked="checked"';
1531: } elsif ($option eq 'autolimit') {
1532: if ($curroption =~ /^autolimit/) {
1533: $checked = ' checked="checked"';
1534: }
1535: }
1536: $defcell{$item} .= '<span class="LC_nobreak"><label>'.
1537: '<input type="radio" name="crsreq_'.$item.
1538: '_default" value="'.$val.'"'.$checked.' />'.
1539: $titles{$option}.'</label>';
1540: if ($option eq 'autolimit') {
1.127 raeburn 1541: $defcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 1542: $item.'_limit_default" size="1" '.
1543: 'value="'.$currlimit.'" />';
1544: }
1.127 raeburn 1545: $defcell{$item} .= '</span> ';
1.104 raeburn 1546: if ($option eq 'autolimit') {
1.127 raeburn 1547: $defcell{$item} .= $titles{'unlimited'};
1.104 raeburn 1548: }
1.101 raeburn 1549: }
1550: } else {
1551: my $checked = 'checked="checked" ';
1552: if (ref($settings) eq 'HASH') {
1553: if (ref($settings->{$item}) eq 'HASH') {
1554: if ($settings->{$item}->{'default'} == 0) {
1555: $checked = '';
1556: } elsif ($settings->{$item}->{'default'} == 1) {
1557: $checked = 'checked="checked" ';
1558: }
1.78 raeburn 1559: }
1.72 raeburn 1560: }
1.101 raeburn 1561: $datatable .= '<span class="LC_nobreak"><label>'.
1562: '<input type="checkbox" name="'.$context.'_'.$item.
1563: '" value="default" '.$checked.'/>'.$titles{$item}.
1564: '</label></span> ';
1565: }
1566: }
1567: if ($context eq 'requestcourses') {
1568: $datatable .= '</tr><tr>';
1569: foreach my $item (@usertools) {
1.106 raeburn 1570: $datatable .= '<td style="vertical-align: top">'.$defcell{$item}.'</td>';
1.72 raeburn 1571: }
1.101 raeburn 1572: $datatable .= '</tr></table>';
1.72 raeburn 1573: }
1.86 raeburn 1574: $datatable .= '</td>';
1575: unless ($context eq 'requestcourses') {
1576: $datatable .= '<td class="LC_right_item"><span class="LC_nobreak">'.
1577: '<input type="text" name="defaultquota" value="'.
1578: $defaultquota.'" size="5" /> Mb</span></td>';
1579: }
1580: $datatable .= '</tr>';
1.72 raeburn 1581: $typecount ++;
1582: $css_class = $typecount%2?' class="LC_odd_row"':'';
1583: $datatable .= '<tr'.$css_class.'>'.
1.104 raeburn 1584: '<td>'.&mt('LON-CAPA Advanced Users').' ';
1585: if ($context eq 'requestcourses') {
1.109 raeburn 1586: $datatable .= &mt('(overrides affiliation, if set)').
1587: '</td>'.
1588: '<td class="LC_left_item">'.
1589: '<table><tr>';
1.101 raeburn 1590: } else {
1.109 raeburn 1591: $datatable .= &mt('(overrides affiliation, if checked)').
1592: '</td>'.
1593: '<td class="LC_left_item" colspan="2">'.
1594: '<br />';
1.101 raeburn 1595: }
1596: my %advcell;
1.72 raeburn 1597: foreach my $item (@usertools) {
1.101 raeburn 1598: if ($context eq 'requestcourses') {
1599: my ($curroption,$currlimit);
1600: if (ref($settings) eq 'HASH') {
1601: if (ref($settings->{$item}) eq 'HASH') {
1602: $curroption = $settings->{$item}->{'_LC_adv'};
1603: if ($curroption =~ /^autolimit=(\d*)$/) {
1604: $currlimit = $1;
1605: }
1606: }
1607: }
1608: $datatable .= '<th>'.$titles{$item}.'</th>';
1.104 raeburn 1609: my $checked = '';
1610: if ($curroption eq '') {
1611: $checked = ' checked="checked"';
1612: }
1613: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
1614: '<input type="radio" name="crsreq_'.$item.
1615: '__LC_adv" value=""'.$checked.' />'.
1616: &mt('No override set').'</label></span> ';
1.101 raeburn 1617: foreach my $option (@options) {
1618: my $val = $option;
1619: if ($option eq 'norequest') {
1620: $val = 0;
1621: }
1622: if ($option eq 'validate') {
1623: my $canvalidate = 0;
1624: if (ref($validations{$item}) eq 'HASH') {
1625: if ($validations{$item}{'_LC_adv'}) {
1626: $canvalidate = 1;
1627: }
1628: }
1629: next if (!$canvalidate);
1630: }
1631: my $checked = '';
1.104 raeburn 1632: if ($val eq $curroption) {
1.101 raeburn 1633: $checked = ' checked="checked"';
1634: } elsif ($option eq 'autolimit') {
1635: if ($curroption =~ /^autolimit/) {
1636: $checked = ' checked="checked"';
1637: }
1638: }
1639: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
1640: '<input type="radio" name="crsreq_'.$item.
1641: '__LC_adv" value="'.$val.'"'.$checked.' />'.
1642: $titles{$option}.'</label>';
1643: if ($option eq 'autolimit') {
1.127 raeburn 1644: $advcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 1645: $item.'_limit__LC_adv" size="1" '.
1646: 'value="'.$currlimit.'" />';
1647: }
1.127 raeburn 1648: $advcell{$item} .= '</span> ';
1.104 raeburn 1649: if ($option eq 'autolimit') {
1.127 raeburn 1650: $advcell{$item} .= $titles{'unlimited'};
1.104 raeburn 1651: }
1.101 raeburn 1652: }
1653: } else {
1654: my $checked = 'checked="checked" ';
1655: if (ref($settings) eq 'HASH') {
1656: if (ref($settings->{$item}) eq 'HASH') {
1657: if ($settings->{$item}->{'_LC_adv'} == 0) {
1658: $checked = '';
1659: } elsif ($settings->{$item}->{'_LC_adv'} == 1) {
1660: $checked = 'checked="checked" ';
1661: }
1.79 raeburn 1662: }
1.72 raeburn 1663: }
1.101 raeburn 1664: $datatable .= '<span class="LC_nobreak"><label>'.
1665: '<input type="checkbox" name="'.$context.'_'.$item.
1666: '" value="_LC_adv" '.$checked.'/>'.$titles{$item}.
1667: '</label></span> ';
1668: }
1669: }
1670: if ($context eq 'requestcourses') {
1671: $datatable .= '</tr><tr>';
1672: foreach my $item (@usertools) {
1.106 raeburn 1673: $datatable .= '<td style="vertical-align: top">'.$advcell{$item}.'</td>';
1.72 raeburn 1674: }
1.101 raeburn 1675: $datatable .= '</tr></table>';
1.72 raeburn 1676: }
1.98 raeburn 1677: $datatable .= '</td></tr>';
1.30 raeburn 1678: $$rowtotal += $typecount;
1.3 raeburn 1679: return $datatable;
1680: }
1681:
1.102 raeburn 1682: sub print_courserequestmail {
1683: my ($dom,$settings,$rowtotal) = @_;
1.104 raeburn 1684: my ($now,$datatable,%dompersonnel,@domcoord,@currapproval,$rows);
1.102 raeburn 1685: $now = time;
1686: $rows = 0;
1687: %dompersonnel = &Apache::lonnet::get_domain_roles($dom,['dc'],$now,$now);
1688: foreach my $server (keys(%dompersonnel)) {
1689: foreach my $user (sort(keys(%{$dompersonnel{$server}}))) {
1690: my ($trole,$uname,$udom,$runame,$rudom,$rsec) = split(/:/,$user);
1691: if (!grep(/^$uname:$udom$/,@domcoord)) {
1692: push(@domcoord,$uname.':'.$udom);
1693: }
1694: }
1695: }
1696: if (ref($settings) eq 'HASH') {
1697: if (ref($settings->{'notify'}) eq 'HASH') {
1698: if ($settings->{'notify'}{'approval'} ne '') {
1.104 raeburn 1699: @currapproval = split(',',$settings->{'notify'}{'approval'});
1.102 raeburn 1700: }
1701: }
1702: }
1.104 raeburn 1703: if (@currapproval) {
1704: foreach my $dc (@currapproval) {
1.102 raeburn 1705: unless (grep(/^\Q$dc\E$/,@domcoord)) {
1706: push(@domcoord,$dc);
1707: }
1708: }
1709: }
1710: @domcoord = sort(@domcoord);
1711: my $numinrow = 4;
1712: my $numdc = @domcoord;
1713: my $css_class = 'class="LC_odd_row"';
1714: $datatable = '<tr'.$css_class.'>'.
1715: ' <td>'.&mt('Receive notification of course requests requiring approval.').
1716: ' </td>'.
1717: ' <td class="LC_left_item">';
1718: if (@domcoord > 0) {
1719: $datatable .= '<table>';
1720: for (my $i=0; $i<$numdc; $i++) {
1721: my $rem = $i%($numinrow);
1722: if ($rem == 0) {
1723: if ($i > 0) {
1724: $datatable .= '</tr>';
1725: }
1726: $datatable .= '<tr>';
1727: $rows ++;
1728: }
1729: my $check = ' ';
1.104 raeburn 1730: if (grep(/^\Q$domcoord[$i]\E$/,@currapproval)) {
1.102 raeburn 1731: $check = ' checked="checked" ';
1732: }
1733: my ($uname,$udom) = split(':',$domcoord[$i]);
1734: my $fullname = &Apache::loncommon::plainname($uname,$udom);
1735: if ($i == $numdc-1) {
1736: my $colsleft = $numinrow-$rem;
1737: if ($colsleft > 1) {
1738: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
1739: } else {
1740: $datatable .= '<td class="LC_left_item">';
1741: }
1742: } else {
1743: $datatable .= '<td class="LC_left_item">';
1744: }
1745: $datatable .= '<span class="LC_nobreak"><label>'.
1746: '<input type="checkbox" name="reqapprovalnotify" '.
1747: 'value="'.$domcoord[$i].'"'.$check.'/>'.
1748: $fullname.'</label></span></td>';
1749: }
1750: $datatable .= '</tr></table>';
1751: } else {
1752: $datatable .= &mt('There are no active Domain Coordinators');
1753: $rows ++;
1754: }
1755: $datatable .='</td></tr>';
1756: $$rowtotal += $rows;
1757: return $datatable;
1758: }
1759:
1.3 raeburn 1760: sub print_autoenroll {
1.30 raeburn 1761: my ($dom,$settings,$rowtotal) = @_;
1.3 raeburn 1762: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
1.129 raeburn 1763: my ($defdom,$runon,$runoff,$coownerson,$coownersoff);
1.3 raeburn 1764: if (ref($settings) eq 'HASH') {
1765: if (exists($settings->{'run'})) {
1766: if ($settings->{'run'} eq '0') {
1767: $runoff = ' checked="checked" ';
1768: $runon = ' ';
1769: } else {
1770: $runon = ' checked="checked" ';
1771: $runoff = ' ';
1772: }
1773: } else {
1774: if ($autorun) {
1775: $runon = ' checked="checked" ';
1776: $runoff = ' ';
1777: } else {
1778: $runoff = ' checked="checked" ';
1779: $runon = ' ';
1780: }
1781: }
1.129 raeburn 1782: if (exists($settings->{'co-owners'})) {
1783: if ($settings->{'co-owners'} eq '0') {
1784: $coownersoff = ' checked="checked" ';
1785: $coownerson = ' ';
1786: } else {
1787: $coownerson = ' checked="checked" ';
1788: $coownersoff = ' ';
1789: }
1790: } else {
1791: $coownersoff = ' checked="checked" ';
1792: $coownerson = ' ';
1793: }
1.3 raeburn 1794: if (exists($settings->{'sender_domain'})) {
1795: $defdom = $settings->{'sender_domain'};
1796: }
1.14 raeburn 1797: } else {
1798: if ($autorun) {
1799: $runon = ' checked="checked" ';
1800: $runoff = ' ';
1801: } else {
1802: $runoff = ' checked="checked" ';
1803: $runon = ' ';
1804: }
1.3 raeburn 1805: }
1806: my $domform = &Apache::loncommon::select_dom_form($defdom,'sender_domain',1);
1.39 raeburn 1807: my $notif_sender;
1808: if (ref($settings) eq 'HASH') {
1809: $notif_sender = $settings->{'sender_uname'};
1810: }
1.3 raeburn 1811: my $datatable='<tr class="LC_odd_row">'.
1812: '<td>'.&mt('Auto-enrollment active?').'</td>'.
1.8 raeburn 1813: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 1814: '<input type="radio" name="autoenroll_run"'.
1.8 raeburn 1815: $runon.' value="1" />'.&mt('Yes').'</label> '.
1816: '<label><input type="radio" name="autoenroll_run"'.
1.14 raeburn 1817: $runoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 1818: '</tr><tr>'.
1819: '<td>'.&mt('Notification messages - sender').
1.8 raeburn 1820: '</td><td class="LC_right_item"><span class="LC_nobreak">'.
1.3 raeburn 1821: &mt('username').': '.
1822: '<input type="text" name="sender_uname" value="'.
1.39 raeburn 1823: $notif_sender.'" size="10" /> '.&mt('domain').
1.129 raeburn 1824: ': '.$domform.'</span></td></tr>'.
1825: '<tr class="LC_odd_row">'.
1826: '<td>'.&mt('Automatically assign co-ownership').'</td>'.
1827: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1828: '<input type="radio" name="autoassign_coowners"'.
1829: $coownerson.' value="1" />'.&mt('Yes').'</label> '.
1830: '<label><input type="radio" name="autoassign_coowners"'.
1831: $coownersoff.' value="0" />'.&mt('No').'</label></span></td>'.
1832: '</tr>';
1833: $$rowtotal += 3;
1.3 raeburn 1834: return $datatable;
1835: }
1836:
1837: sub print_autoupdate {
1.30 raeburn 1838: my ($position,$dom,$settings,$rowtotal) = @_;
1.3 raeburn 1839: my $datatable;
1840: if ($position eq 'top') {
1841: my $updateon = ' ';
1842: my $updateoff = ' checked="checked" ';
1843: my $classlistson = ' ';
1844: my $classlistsoff = ' checked="checked" ';
1845: if (ref($settings) eq 'HASH') {
1846: if ($settings->{'run'} eq '1') {
1847: $updateon = $updateoff;
1848: $updateoff = ' ';
1849: }
1850: if ($settings->{'classlists'} eq '1') {
1851: $classlistson = $classlistsoff;
1852: $classlistsoff = ' ';
1853: }
1854: }
1855: my %title = (
1856: run => 'Auto-update active?',
1857: classlists => 'Update information in classlists?',
1858: );
1859: $datatable = '<tr class="LC_odd_row">'.
1860: '<td>'.&mt($title{'run'}).'</td>'.
1.8 raeburn 1861: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 1862: '<input type="radio" name="autoupdate_run"'.
1.8 raeburn 1863: $updateon.' value="1" />'.&mt('Yes').'</label> '.
1864: '<label><input type="radio" name="autoupdate_run"'.
1865: $updateoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 1866: '</tr><tr>'.
1867: '<td>'.&mt($title{'classlists'}).'</td>'.
1.8 raeburn 1868: '<td class="LC_right_item"><span class="LC_nobreak">'.
1869: '<label><input type="radio" name="classlists"'.
1870: $classlistson.' value="1" />'.&mt('Yes').'</label> '.
1871: '<label><input type="radio" name="classlists"'.
1872: $classlistsoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 1873: '</tr>';
1.30 raeburn 1874: $$rowtotal += 2;
1.131 raeburn 1875: } elsif ($position eq 'middle') {
1876: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1877: my $numinrow = 3;
1878: my $locknamesettings;
1879: $datatable .= &insttypes_row($settings,$types,$usertypes,
1880: $dom,$numinrow,$othertitle,
1881: 'lockablenames');
1882: $$rowtotal ++;
1.3 raeburn 1883: } else {
1.44 raeburn 1884: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.132 raeburn 1885: my @fields = ('lastname','firstname','middlename','generation',
1.20 raeburn 1886: 'permanentemail','id');
1.33 raeburn 1887: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1.3 raeburn 1888: my $numrows = 0;
1.26 raeburn 1889: if (ref($types) eq 'ARRAY') {
1890: if (@{$types} > 0) {
1891: $datatable =
1892: &usertype_update_row($settings,$usertypes,\%fieldtitles,
1893: \@fields,$types,\$numrows);
1.30 raeburn 1894: $$rowtotal += @{$types};
1.26 raeburn 1895: }
1.3 raeburn 1896: }
1897: $datatable .=
1898: &usertype_update_row($settings,{'default' => $othertitle},
1899: \%fieldtitles,\@fields,['default'],
1900: \$numrows);
1.30 raeburn 1901: $$rowtotal ++;
1.3 raeburn 1902: }
1903: return $datatable;
1904: }
1905:
1.125 raeburn 1906: sub print_autocreate {
1907: my ($dom,$settings,$rowtotal) = @_;
1908: my (%createon,%createoff);
1909: my $curr_dc;
1910: my @types = ('xml','req');
1911: if (ref($settings) eq 'HASH') {
1912: foreach my $item (@types) {
1913: $createoff{$item} = ' checked="checked" ';
1914: $createon{$item} = ' ';
1915: if (exists($settings->{$item})) {
1916: if ($settings->{$item}) {
1917: $createon{$item} = ' checked="checked" ';
1918: $createoff{$item} = ' ';
1919: }
1920: }
1921: }
1922: $curr_dc = $settings->{'xmldc'};
1923: } else {
1924: foreach my $item (@types) {
1925: $createoff{$item} = ' checked="checked" ';
1926: $createon{$item} = ' ';
1927: }
1928: }
1929: $$rowtotal += 2;
1930: my $datatable='<tr class="LC_odd_row">'.
1931: '<td>'.&mt('Create pending official courses from XML files').'</td>'.
1932: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1933: '<input type="radio" name="autocreate_xml"'.
1934: $createon{'xml'}.' value="1" />'.&mt('Yes').'</label> '.
1935: '<label><input type="radio" name="autocreate_xml"'.
1.143 raeburn 1936: $createoff{'xml'}.' value="0" />'.&mt('No').'</label></span>'.
1937: '</td></tr><tr>'.
1938: '<td>'.&mt('Create pending requests for official courses (if validated)').'</td>'.
1939: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1940: '<input type="radio" name="autocreate_req"'.
1941: $createon{'req'}.' value="1" />'.&mt('Yes').'</label> '.
1942: '<label><input type="radio" name="autocreate_req"'.
1943: $createoff{'req'}.' value="0" />'.&mt('No').'</label></span>';
1.125 raeburn 1944: my ($numdc,$dctable) = &active_dc_picker($dom,$curr_dc);
1945: if ($numdc > 1) {
1.143 raeburn 1946: $datatable .= '</td></tr><tr class="LC_odd_row"><td>'.
1947: &mt('Course creation processed as: (choose Dom. Coord.)').
1948: '</td><td class="LC_left_item">'.$dctable.'</td></tr>';
1.125 raeburn 1949: $$rowtotal ++ ;
1950: } else {
1.143 raeburn 1951: $datatable .= $dctable.'</td></tr>';
1.125 raeburn 1952: }
1953: return $datatable;
1954: }
1955:
1.23 raeburn 1956: sub print_directorysrch {
1.30 raeburn 1957: my ($dom,$settings,$rowtotal) = @_;
1.23 raeburn 1958: my $srchon = ' ';
1959: my $srchoff = ' checked="checked" ';
1.25 raeburn 1960: my ($exacton,$containson,$beginson);
1.24 raeburn 1961: my $localon = ' ';
1962: my $localoff = ' checked="checked" ';
1.23 raeburn 1963: if (ref($settings) eq 'HASH') {
1964: if ($settings->{'available'} eq '1') {
1965: $srchon = $srchoff;
1966: $srchoff = ' ';
1967: }
1.24 raeburn 1968: if ($settings->{'localonly'} eq '1') {
1969: $localon = $localoff;
1970: $localoff = ' ';
1971: }
1.25 raeburn 1972: if (ref($settings->{'searchtypes'}) eq 'ARRAY') {
1973: foreach my $type (@{$settings->{'searchtypes'}}) {
1974: if ($type eq 'exact') {
1975: $exacton = ' checked="checked" ';
1976: } elsif ($type eq 'contains') {
1977: $containson = ' checked="checked" ';
1978: } elsif ($type eq 'begins') {
1979: $beginson = ' checked="checked" ';
1980: }
1981: }
1982: } else {
1983: if ($settings->{'searchtypes'} eq 'exact') {
1984: $exacton = ' checked="checked" ';
1985: } elsif ($settings->{'searchtypes'} eq 'contains') {
1986: $containson = ' checked="checked" ';
1987: } elsif ($settings->{'searchtypes'} eq 'specify') {
1988: $exacton = ' checked="checked" ';
1989: $containson = ' checked="checked" ';
1990: }
1.23 raeburn 1991: }
1992: }
1993: my ($searchtitles,$titleorder) = &sorted_searchtitles();
1.45 raeburn 1994: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.23 raeburn 1995:
1996: my $numinrow = 4;
1.26 raeburn 1997: my $cansrchrow = 0;
1.23 raeburn 1998: my $datatable='<tr class="LC_odd_row">'.
1.30 raeburn 1999: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Directory search available?').'</span></td>'.
1.23 raeburn 2000: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2001: '<input type="radio" name="dirsrch_available"'.
2002: $srchon.' value="1" />'.&mt('Yes').'</label> '.
2003: '<label><input type="radio" name="dirsrch_available"'.
2004: $srchoff.' value="0" />'.&mt('No').'</label></span></td>'.
2005: '</tr><tr>'.
1.30 raeburn 2006: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search?').'</span></td>'.
1.24 raeburn 2007: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2008: '<input type="radio" name="dirsrch_localonly"'.
2009: $localoff.' value="0" />'.&mt('Yes').'</label> '.
2010: '<label><input type="radio" name="dirsrch_localonly"'.
2011: $localon.' value="1" />'.&mt('No').'</label></span></td>'.
1.25 raeburn 2012: '</tr>';
1.30 raeburn 2013: $$rowtotal += 2;
1.26 raeburn 2014: if (ref($usertypes) eq 'HASH') {
2015: if (keys(%{$usertypes}) > 0) {
1.93 raeburn 2016: $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
2017: $numinrow,$othertitle,'cansearch');
1.26 raeburn 2018: $cansrchrow = 1;
2019: }
2020: }
2021: if ($cansrchrow) {
1.30 raeburn 2022: $$rowtotal ++;
1.26 raeburn 2023: $datatable .= '<tr>';
2024: } else {
2025: $datatable .= '<tr class="LC_odd_row">';
2026: }
1.30 raeburn 2027: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Supported search methods').
2028: '</span></td><td class="LC_left_item" colspan="2"><table><tr>';
1.25 raeburn 2029: foreach my $title (@{$titleorder}) {
2030: if (defined($searchtitles->{$title})) {
2031: my $check = ' ';
1.93 raeburn 2032: if (ref($settings) eq 'HASH') {
1.39 raeburn 2033: if (ref($settings->{'searchby'}) eq 'ARRAY') {
2034: if (grep(/^\Q$title\E$/,@{$settings->{'searchby'}})) {
2035: $check = ' checked="checked" ';
2036: }
1.25 raeburn 2037: }
2038: }
2039: $datatable .= '<td class="LC_left_item">'.
2040: '<span class="LC_nobreak"><label>'.
2041: '<input type="checkbox" name="searchby" '.
2042: 'value="'.$title.'"'.$check.'/>'.
2043: $searchtitles->{$title}.'</label></span></td>';
2044: }
2045: }
1.26 raeburn 2046: $datatable .= '</tr></table></td></tr>';
1.30 raeburn 2047: $$rowtotal ++;
1.26 raeburn 2048: if ($cansrchrow) {
2049: $datatable .= '<tr class="LC_odd_row">';
2050: } else {
2051: $datatable .= '<tr>';
2052: }
1.30 raeburn 2053: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Search latitude').'</span></td>'.
1.26 raeburn 2054: '<td class="LC_left_item" colspan="2">'.
1.25 raeburn 2055: '<span class="LC_nobreak"><label>'.
2056: '<input type="checkbox" name="searchtypes" '.
2057: $exacton.' value="exact" />'.&mt('Exact match').
2058: '</label> '.
2059: '<label><input type="checkbox" name="searchtypes" '.
2060: $beginson.' value="begins" />'.&mt('Begins with').
2061: '</label> '.
2062: '<label><input type="checkbox" name="searchtypes" '.
2063: $containson.' value="contains" />'.&mt('Contains').
2064: '</label></span></td></tr>';
1.30 raeburn 2065: $$rowtotal ++;
1.25 raeburn 2066: return $datatable;
2067: }
2068:
1.28 raeburn 2069: sub print_contacts {
1.30 raeburn 2070: my ($dom,$settings,$rowtotal) = @_;
1.28 raeburn 2071: my $datatable;
2072: my @contacts = ('adminemail','supportemail');
1.134 raeburn 2073: my (%checked,%to,%otheremails,%bccemails);
1.102 raeburn 2074: my @mailings = ('errormail','packagesmail','lonstatusmail','helpdeskmail',
2075: 'requestsmail');
1.28 raeburn 2076: foreach my $type (@mailings) {
2077: $otheremails{$type} = '';
2078: }
1.134 raeburn 2079: $bccemails{'helpdeskmail'} = '';
1.28 raeburn 2080: if (ref($settings) eq 'HASH') {
2081: foreach my $item (@contacts) {
2082: if (exists($settings->{$item})) {
2083: $to{$item} = $settings->{$item};
2084: }
2085: }
2086: foreach my $type (@mailings) {
2087: if (exists($settings->{$type})) {
2088: if (ref($settings->{$type}) eq 'HASH') {
2089: foreach my $item (@contacts) {
2090: if ($settings->{$type}{$item}) {
2091: $checked{$type}{$item} = ' checked="checked" ';
2092: }
2093: }
2094: $otheremails{$type} = $settings->{$type}{'others'};
1.134 raeburn 2095: if ($type eq 'helpdeskmail') {
2096: $bccemails{$type} = $settings->{$type}{'bcc'};
2097: }
1.28 raeburn 2098: }
1.89 raeburn 2099: } elsif ($type eq 'lonstatusmail') {
2100: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
1.28 raeburn 2101: }
2102: }
2103: } else {
2104: $to{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
2105: $to{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
2106: $checked{'errormail'}{'adminemail'} = ' checked="checked" ';
2107: $checked{'packagesmail'}{'adminemail'} = ' checked="checked" ';
1.89 raeburn 2108: $checked{'helpdeskmail'}{'supportemail'} = ' checked="checked" ';
2109: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
1.102 raeburn 2110: $checked{'requestsmail'}{'adminemail'} = ' checked="checked" ';
1.28 raeburn 2111: }
2112: my ($titles,$short_titles) = &contact_titles();
2113: my $rownum = 0;
2114: my $css_class;
2115: foreach my $item (@contacts) {
1.69 raeburn 2116: $rownum ++;
2117: $css_class = $rownum%2?' class="LC_odd_row"':'';
1.30 raeburn 2118: $datatable .= '<tr'.$css_class.'>'.
2119: '<td><span class="LC_nobreak">'.$titles->{$item}.
2120: '</span></td><td class="LC_right_item">'.
1.28 raeburn 2121: '<input type="text" name="'.$item.'" value="'.
2122: $to{$item}.'" /></td></tr>';
2123: }
2124: foreach my $type (@mailings) {
1.69 raeburn 2125: $rownum ++;
2126: $css_class = $rownum%2?' class="LC_odd_row"':'';
1.28 raeburn 2127: $datatable .= '<tr'.$css_class.'>'.
1.30 raeburn 2128: '<td><span class="LC_nobreak">'.
2129: $titles->{$type}.': </span></td>'.
1.28 raeburn 2130: '<td class="LC_left_item">'.
2131: '<span class="LC_nobreak">';
2132: foreach my $item (@contacts) {
2133: $datatable .= '<label>'.
2134: '<input type="checkbox" name="'.$type.'"'.
2135: $checked{$type}{$item}.
2136: ' value="'.$item.'" />'.$short_titles->{$item}.
2137: '</label> ';
2138: }
2139: $datatable .= '</span><br />'.&mt('Others').': '.
2140: '<input type="text" name="'.$type.'_others" '.
1.134 raeburn 2141: 'value="'.$otheremails{$type}.'" />';
2142: if ($type eq 'helpdeskmail') {
1.136 raeburn 2143: $datatable .= '<br />'.&mt('Bcc:').(' 'x6).
1.134 raeburn 2144: '<input type="text" name="'.$type.'_bcc" '.
2145: 'value="'.$bccemails{$type}.'" />';
2146: }
2147: $datatable .= '</td></tr>'."\n";
1.28 raeburn 2148: }
1.30 raeburn 2149: $$rowtotal += $rownum;
1.28 raeburn 2150: return $datatable;
2151: }
2152:
1.118 jms 2153: sub print_helpsettings {
1.122 jms 2154:
2155: my ($position,$dom,$confname,$settings,$rowtotal) = @_;
2156: my ($css_class,$datatable);
2157:
2158: my $switchserver = &check_switchserver($dom,$confname);
2159:
2160: my $itemcount = 1;
2161:
2162: if ($position eq 'top') {
2163:
2164: my (%checkedon,%checkedoff,%choices,%defaultchecked,@toggles);
2165:
2166: %choices =
2167: &Apache::lonlocal::texthash (
2168: submitbugs => 'Display "Submit a bug" link?',
2169: );
2170:
2171: %defaultchecked = ('submitbugs' => 'on');
2172:
2173: @toggles = ('submitbugs',);
2174:
2175: foreach my $item (@toggles) {
2176: if ($defaultchecked{$item} eq 'on') {
2177: $checkedon{$item} = ' checked="checked" ';
2178: $checkedoff{$item} = ' ';
2179: } elsif ($defaultchecked{$item} eq 'off') {
2180: $checkedoff{$item} = ' checked="checked" ';
2181: $checkedon{$item} = ' ';
2182: }
2183: }
2184:
2185: if (ref($settings) eq 'HASH') {
2186: foreach my $item (@toggles) {
2187: if ($settings->{$item} eq '1') {
2188: $checkedon{$item} = ' checked="checked" ';
2189: $checkedoff{$item} = ' ';
2190: } elsif ($settings->{$item} eq '0') {
2191: $checkedoff{$item} = ' checked="checked" ';
2192: $checkedon{$item} = ' ';
2193: }
2194: }
2195: }
2196:
2197: foreach my $item (@toggles) {
2198: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
2199: $datatable .=
2200: '<tr'.$css_class.'>
2201: <td><span class="LC_nobreak">'.$choices{$item}.'</span></td>
2202: <td><span class="LC_nobreak"> </span></td>
2203: <td class="LC_right_item"><span class="LC_nobreak">
2204: <label><input type="radio" name="'.$item.'" '.$checkedon{$item}.' value="1" />'.&mt('Yes').'</label>
2205: <label><input type="radio" name="'.$item.'" '.$checkedoff{$item}.' value="0" />'.&mt('No').'</label>'.
2206: '</span></td>'.
2207: '</tr>';
2208: $itemcount ++;
2209: }
2210:
2211: } else {
2212:
2213: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
2214:
2215: $datatable .= '<tr'.$css_class.'>';
2216:
2217: if (ref($settings) eq 'HASH') {
2218: if ($settings->{'loginhelpurl'} ne '') {
2219: my($directory, $filename) = $settings->{'loginhelpurl'} =~ m/(.*\/)(.*)$/;
2220: $datatable .= '<td width="33%"><span class="LC_left_item"><label><a href="'.$settings->{'loginhelpurl'}.'" target="_blank">'.&mt('Custom Login Page Help File In Use').'</a></label></span></td>';
2221: $datatable .= '<td width="33%"><span class="LC_right_item"><label><input type="checkbox" name="loginhelpurl_del" value="1" />'.&mt('Delete?').'</label></span></td>'
2222: } else {
2223: $datatable .= '<td width="33%"><span class="LC_left_item"><label>'.&mt('Default Login Page Help File In Use').'</label></span></td>';
2224: $datatable .= '<td width="33%"><span class="LC_right_item"> </span></td>';
2225: }
2226: } else {
2227: $datatable .= '<td><span class="LC_left_item"> </span></td>';
2228: $datatable .= '<td><span class="LC_right_item"> </span></td>';
2229: }
2230:
2231: $datatable .= '<td width="33%"><span class="LC_right_item">';
2232: if ($switchserver) {
2233: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2234: } else {
2235: $datatable .= &mt('Upload Custom Login Page Help File:');
2236: $datatable .='<input type="file" name="loginhelpurl" />';
2237: }
2238: $datatable .= '</span></td></tr>';
2239:
2240: }
2241:
2242: return $datatable;
2243:
1.121 raeburn 2244: }
2245:
1.122 jms 2246:
1.121 raeburn 2247: sub radiobutton_prefs {
2248: my ($settings,$toggles,$defaultchecked,$choices,$itemcount) = @_;
2249: return unless ((ref($toggles) eq 'ARRAY') && (ref($defaultchecked) eq 'HASH') &&
2250: (ref($choices) eq 'HASH'));
2251:
2252: my (%checkedon,%checkedoff,$datatable,$css_class);
2253:
2254: foreach my $item (@{$toggles}) {
2255: if ($defaultchecked->{$item} eq 'on') {
1.118 jms 2256: $checkedon{$item} = ' checked="checked" ';
2257: $checkedoff{$item} = ' ';
1.121 raeburn 2258: } elsif ($defaultchecked->{$item} eq 'off') {
1.118 jms 2259: $checkedoff{$item} = ' checked="checked" ';
2260: $checkedon{$item} = ' ';
2261: }
2262: }
2263: if (ref($settings) eq 'HASH') {
1.121 raeburn 2264: foreach my $item (@{$toggles}) {
1.118 jms 2265: if ($settings->{$item} eq '1') {
2266: $checkedon{$item} = ' checked="checked" ';
2267: $checkedoff{$item} = ' ';
2268: } elsif ($settings->{$item} eq '0') {
2269: $checkedoff{$item} = ' checked="checked" ';
2270: $checkedon{$item} = ' ';
2271: }
2272: }
1.121 raeburn 2273: }
2274: foreach my $item (@{$toggles}) {
1.118 jms 2275: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.121 raeburn 2276: $datatable .=
2277: '<tr'.$css_class.'><td><span class="LC_nobreak">'.$choices->{$item}.
1.118 jms 2278: '</span></td>'.
2279: '<td class="LC_right_item"><span class="LC_nobreak">'.
2280: '<label><input type="radio" name="'.
2281: $item.'" '.$checkedon{$item}.' value="1" />'.&mt('Yes').
2282: '</label> <label><input type="radio" name="'.$item.'" '.
2283: $checkedoff{$item}.' value="0" />'.&mt('No').'</label>'.
2284: '</span></td>'.
2285: '</tr>';
2286: $itemcount ++;
1.121 raeburn 2287: }
2288: return ($datatable,$itemcount);
2289: }
2290:
2291: sub print_coursedefaults {
1.139 raeburn 2292: my ($position,$dom,$settings,$rowtotal) = @_;
1.121 raeburn 2293: my ($css_class,$datatable);
2294: my $itemcount = 1;
1.139 raeburn 2295: if ($position eq 'top') {
2296: my (%checkedon,%checkedoff,%choices,%defaultchecked,@toggles);
2297: %choices =
2298: &Apache::lonlocal::texthash (
2299: canuse_pdfforms => 'Course/Community users can create/upload PDF forms',
2300: );
2301: %defaultchecked = ('canuse_pdfforms' => 'off');
2302: @toggles = ('canuse_pdfforms',);
2303: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
1.121 raeburn 2304: \%choices,$itemcount);
1.139 raeburn 2305: $$rowtotal += $itemcount;
2306: } else {
2307: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
2308: my %choices =
2309: &Apache::lonlocal::texthash (
2310: anonsurvey_threshold => 'Responder count needed before showing submissions for anonymous surveys',
2311: );
2312: my $currdefresponder;
2313: if (ref($settings) eq 'HASH') {
2314: $currdefresponder = $settings->{'anonsurvey_threshold'};
2315: }
2316: if (!$currdefresponder) {
2317: $currdefresponder = 10;
2318: } elsif ($currdefresponder < 1) {
2319: $currdefresponder = 1;
2320: }
2321: $datatable .=
2322: '<tr'.$css_class.'><td><span class="LC_nobreak">'.$choices{'anonsurvey_threshold'}.
2323: '</span></td>'.
2324: '<td class="LC_right_item"><span class="LC_nobreak">'.
2325: '<input type="text" name="anonsurvey_threshold"'.
2326: ' value="'.$currdefresponder.'" size="5" /></span>'.
2327: '</td></tr>';
2328: }
1.121 raeburn 2329: return $datatable;
1.118 jms 2330: }
2331:
1.137 raeburn 2332: sub print_usersessions {
2333: my ($position,$dom,$settings,$rowtotal) = @_;
2334: my ($css_class,$datatable,%checked,%choices);
1.140 raeburn 2335: my (%by_ip,%by_location,@intdoms);
2336: &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
1.145 raeburn 2337:
2338: my @alldoms = &Apache::lonnet::all_domains();
2339: my %uniques = &Apache::lonnet::get_unique_servers(\@alldoms);
1.149 raeburn 2340: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.145 raeburn 2341: my $itemcount = 1;
2342: if ($position eq 'top') {
2343: if (keys(%uniques) > 1) {
2344: my %spareid = ¤t_offloads_to($dom,$settings,\%servers);
2345: $datatable .= &spares_row(\%servers,\%spareid,\%uniques,$rowtotal);
2346: } else {
1.140 raeburn 2347: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.150 ! raeburn 2348: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one server.');
1.140 raeburn 2349: }
1.137 raeburn 2350: } else {
1.145 raeburn 2351: if (keys(%by_location) == 0) {
2352: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.150 ! raeburn 2353: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one institution.');
1.145 raeburn 2354: } else {
2355: my %lt = &usersession_titles();
2356: my $numinrow = 5;
2357: my $prefix;
2358: my @types;
2359: if ($position eq 'bottom') {
2360: $prefix = 'remote';
2361: @types = ('version','excludedomain','includedomain');
2362: } else {
2363: $prefix = 'hosted';
2364: @types = ('excludedomain','includedomain');
2365: }
2366: my (%current,%checkedon,%checkedoff);
2367: my @lcversions = &Apache::lonnet::all_loncaparevs();
2368: my @locations = sort(keys(%by_location));
2369: foreach my $type (@types) {
2370: $checkedon{$type} = '';
2371: $checkedoff{$type} = ' checked="checked"';
2372: }
2373: if (ref($settings) eq 'HASH') {
2374: if (ref($settings->{$prefix}) eq 'HASH') {
2375: foreach my $key (keys(%{$settings->{$prefix}})) {
2376: $current{$key} = $settings->{$prefix}{$key};
2377: if ($key eq 'version') {
2378: if ($current{$key} ne '') {
2379: $checkedon{$key} = ' checked="checked"';
2380: $checkedoff{$key} = '';
2381: }
2382: } elsif (ref($current{$key}) eq 'ARRAY') {
2383: $checkedon{$key} = ' checked="checked"';
2384: $checkedoff{$key} = '';
2385: }
1.137 raeburn 2386: }
2387: }
2388: }
1.145 raeburn 2389: foreach my $type (@types) {
2390: next if ($type ne 'version' && !@locations);
2391: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
2392: $datatable .= '<tr'.$css_class.'>
2393: <td><span class="LC_nobreak">'.$lt{$type}.'</span><br />
2394: <span class="LC_nobreak">
2395: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedoff{$type}.' value="0" />'.&mt('Not in use').'</label>
2396: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedon{$type}.' value="1" />'.&mt('In use').'</label></span></td><td>';
2397: if ($type eq 'version') {
2398: my $selector = '<select name="'.$prefix.'_version">';
2399: foreach my $version (@lcversions) {
2400: my $selected = '';
2401: if ($current{'version'} eq $version) {
2402: $selected = ' selected="selected"';
2403: }
2404: $selector .= ' <option value="'.$version.'"'.
2405: $selected.'>'.$version.'</option>';
2406: }
2407: $selector .= '</select> ';
2408: $datatable .= &mt('remote server must be version: [_1] or later',$selector);
2409: } else {
2410: $datatable.= '<div><input type="button" value="'.&mt('check all').'" '.
2411: 'onclick="javascript:checkAll(document.display.'.$prefix.'_'.$type.')"'.
2412: ' />'.(' 'x2).
2413: '<input type="button" value="'.&mt('uncheck all').'" '.
2414: 'onclick="javascript:uncheckAll(document.display.'.$prefix.'_'.$type.')" />'.
2415: "\n".
2416: '</div><div><table>';
2417: my $rem;
2418: for (my $i=0; $i<@locations; $i++) {
2419: my ($showloc,$value,$checkedtype);
2420: if (ref($by_location{$locations[$i]}) eq 'ARRAY') {
2421: my $ip = $by_location{$locations[$i]}->[0];
2422: if (ref($by_ip{$ip}) eq 'ARRAY') {
2423: $value = join(':',@{$by_ip{$ip}});
2424: $showloc = join(', ',@{$by_ip{$ip}});
2425: if (ref($current{$type}) eq 'ARRAY') {
2426: foreach my $loc (@{$by_ip{$ip}}) {
2427: if (grep(/^\Q$loc\E$/,@{$current{$type}})) {
2428: $checkedtype = ' checked="checked"';
2429: last;
2430: }
2431: }
1.138 raeburn 2432: }
2433: }
2434: }
1.145 raeburn 2435: $rem = $i%($numinrow);
2436: if ($rem == 0) {
2437: if ($i > 0) {
2438: $datatable .= '</tr>';
2439: }
2440: $datatable .= '<tr>';
2441: }
2442: $datatable .= '<td class="LC_left_item">'.
2443: '<span class="LC_nobreak"><label>'.
2444: '<input type="checkbox" name="'.$prefix.'_'.$type.
2445: '" value="'.$value.'"'.$checkedtype.' />'.$showloc.
2446: '</label></span></td>';
1.137 raeburn 2447: }
1.145 raeburn 2448: $rem = @locations%($numinrow);
2449: my $colsleft = $numinrow - $rem;
2450: if ($colsleft > 1 ) {
2451: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
2452: ' </td>';
2453: } elsif ($colsleft == 1) {
2454: $datatable .= '<td class="LC_left_item"> </td>';
1.137 raeburn 2455: }
1.145 raeburn 2456: $datatable .= '</tr></table>';
1.137 raeburn 2457: }
1.145 raeburn 2458: $datatable .= '</td></tr>';
2459: $itemcount ++;
1.137 raeburn 2460: }
2461: }
2462: }
2463: $$rowtotal += $itemcount;
2464: return $datatable;
2465: }
2466:
1.138 raeburn 2467: sub build_location_hashes {
2468: my ($intdoms,$by_ip,$by_location) = @_;
2469: return unless((ref($intdoms) eq 'ARRAY') && (ref($by_ip) eq 'HASH') &&
2470: (ref($by_location) eq 'HASH'));
2471: my %iphost = &Apache::lonnet::get_iphost();
2472: my $primary_id = &Apache::lonnet::domain($env{'request.role.domain'},'primary');
2473: my $primary_ip = &Apache::lonnet::get_host_ip($primary_id);
2474: if (ref($iphost{$primary_ip}) eq 'ARRAY') {
2475: foreach my $id (@{$iphost{$primary_ip}}) {
2476: my $intdom = &Apache::lonnet::internet_dom($id);
2477: unless(grep(/^\Q$intdom\E$/,@{$intdoms})) {
2478: push(@{$intdoms},$intdom);
2479: }
2480: }
2481: }
2482: foreach my $ip (keys(%iphost)) {
2483: if (ref($iphost{$ip}) eq 'ARRAY') {
2484: foreach my $id (@{$iphost{$ip}}) {
2485: my $location = &Apache::lonnet::internet_dom($id);
2486: if ($location) {
2487: next if (grep(/^\Q$location\E$/,@{$intdoms}));
2488: if (ref($by_ip->{$ip}) eq 'ARRAY') {
2489: unless(grep(/^\Q$location\E$/,@{$by_ip->{$ip}})) {
2490: push(@{$by_ip->{$ip}},$location);
2491: }
2492: } else {
2493: $by_ip->{$ip} = [$location];
2494: }
2495: }
2496: }
2497: }
2498: }
2499: foreach my $ip (sort(keys(%{$by_ip}))) {
2500: if (ref($by_ip->{$ip}) eq 'ARRAY') {
2501: @{$by_ip->{$ip}} = sort(@{$by_ip->{$ip}});
2502: my $first = $by_ip->{$ip}->[0];
2503: if (ref($by_location->{$first}) eq 'ARRAY') {
2504: unless (grep(/^\Q$ip\E$/,@{$by_location->{$first}})) {
2505: push(@{$by_location->{$first}},$ip);
2506: }
2507: } else {
2508: $by_location->{$first} = [$ip];
2509: }
2510: }
2511: }
2512: return;
2513: }
2514:
1.145 raeburn 2515: sub current_offloads_to {
2516: my ($dom,$settings,$servers) = @_;
2517: my (%spareid,%otherdomconfigs);
2518: if ((ref($settings) eq 'HASH') && (ref($servers) eq 'HASH')) {
2519: foreach my $lonhost (sort(keys(%{$servers}))) {
2520: my $gotspares;
2521: if (ref($settings->{'spares'}) eq 'HASH') {
2522: if (ref($settings->{'spares'}{$lonhost}) eq 'HASH') {
2523: $spareid{$lonhost}{'primary'} = $settings->{'spares'}{$lonhost}{'primary'};
2524: $spareid{$lonhost}{'default'} = $settings->{'spares'}{$lonhost}{'default'};
2525: $gotspares = 1;
2526: }
2527: }
2528: unless ($gotspares) {
2529: my $gotspares;
2530: my $serverhomeID =
2531: &Apache::lonnet::get_server_homeID($servers->{$lonhost});
2532: my $serverhomedom =
2533: &Apache::lonnet::host_domain($serverhomeID);
2534: if ($serverhomedom ne $dom) {
2535: if (ref($otherdomconfigs{$serverhomedom} eq 'HASH')) {
2536: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
2537: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
2538: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
2539: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
2540: $gotspares = 1;
2541: }
2542: }
2543: } else {
2544: $otherdomconfigs{$serverhomedom} =
2545: &Apache::lonnet::get_dom('configuration',['usersessions'],$serverhomedom);
2546: if (ref($otherdomconfigs{$serverhomedom}) eq 'HASH') {
2547: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
2548: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
2549: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{$lonhost}) eq 'HASH') {
2550: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
2551: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
2552: $gotspares = 1;
2553: }
2554: }
2555: }
2556: }
2557: }
2558: }
2559: }
2560: unless ($gotspares) {
2561: if ($lonhost eq $Apache::lonnet::perlvar{'lonHostID'}) {
2562: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
2563: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
2564: } else {
2565: my $server_hostname = &Apache::lonnet::hostname($lonhost);
2566: my $server_homeID = &Apache::lonnet::get_server_homeID($server_hostname);
2567: if ($server_homeID eq $Apache::lonnet::perlvar{'lonHostID'}) {
2568: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
2569: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
2570: } else {
1.150 ! raeburn 2571: my %what = (
! 2572: spareid => 1,
! 2573: );
! 2574: my ($result,$returnhash) =
! 2575: &Apache::lonnet::get_remote_globals($lonhost,\%what);
! 2576: if ($result eq 'ok') {
! 2577: if (ref($returnhash) eq 'HASH') {
! 2578: if (ref($returnhash->{'spareid'}) eq 'HASH') {
! 2579: $spareid{$lonhost}{'primary'} = $returnhash->{'spareid'}->{'primary'};
! 2580: $spareid{$lonhost}{'default'} = $returnhash->{'spareid'}->{'default'};
! 2581: }
! 2582: }
1.145 raeburn 2583: }
2584: }
2585: }
2586: }
2587: }
2588: }
2589: return %spareid;
2590: }
2591:
2592: sub spares_row {
2593: my ($servers,$spareid,$uniques,$rowtotal) = @_;
2594: my $css_class;
2595: my $numinrow = 4;
2596: my $itemcount = 1;
2597: my $datatable;
2598: if ((ref($servers) eq 'HASH') && (ref($spareid) eq 'HASH')) {
2599: foreach my $server (sort(keys(%{$servers}))) {
2600: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
2601: $datatable .= '<tr'.$css_class.'>
2602: <td rowspan="2">
2603: <span class="LC_nobreak"><b>'.$server.'</b> when busy, offloads to:</span></td>';
2604: my (%current,%canselect);
2605: if (ref($spareid->{$server}) eq 'HASH') {
2606: foreach my $type ('primary','default') {
2607: if (ref($spareid->{$server}{$type}) eq 'ARRAY') {
2608: my @spares = @{$spareid->{$server}{$type}};
2609: if (@spares > 0) {
2610: $current{$type} .= '<table>';
2611: for (my $i=0; $i<@spares; $i++) {
2612: my $rem = $i%($numinrow);
2613: if ($rem == 0) {
2614: if ($i > 0) {
2615: $current{$type} .= '</tr>';
2616: }
2617: $current{$type} .= '<tr>';
2618: }
2619: $current{$type} .= '<td><label><input type="checkbox" name="spare_'.$type.'_'.$server.'" checked="checked" value="'.$spareid->{$server}{$type}[$i].'" /> '.
2620: $spareid->{$server}{$type}[$i].
2621: '</label></td>';
2622: }
1.150 ! raeburn 2623: my $rem = @spares%($numinrow);
! 2624: my $colsleft = $numinrow - $rem;
! 2625: if ($colsleft > 1 ) {
! 2626: $current{$type} .= '<td colspan="'.$colsleft.
! 2627: '" class="LC_left_item">'.
! 2628: ' </td>';
! 2629: } elsif ($colsleft == 1) {
! 2630: $current{$type} .= '<td class="LC_left_item"> </td>';
! 2631: }
1.145 raeburn 2632: }
1.150 ! raeburn 2633: $current{$type} .= '</tr></table>';
1.145 raeburn 2634: }
2635: if ($current{$type} eq '') {
2636: $current{$type} = &mt('None specified');
2637: }
2638: $canselect{$type} =
2639: &newspare_select($server,$type,$spareid->{$server}{$type},$uniques);
2640: }
2641: }
2642: $datatable .= '<td><i>'.&mt('primary').'</i><td>'.$current{'primary'}.'</td>'.
2643: '<td>'.&mt('Add new [_1]primary[_2]:','<i>','</i>').' '.
2644: $canselect{'primary'}.'</td></tr>'.
2645: '<tr'.$css_class.'>'.
2646: '<td><i>'.&mt('default').'</i></td>'.
2647: '<td>'.$current{'default'}.'</td>'.
2648: '<td>'.&mt('Add new [_1]default[_2]:','<i>','</i>').' '.
2649: $canselect{'default'}.'</td></tr>';
2650: $itemcount ++;
2651: }
2652: }
2653: $$rowtotal += $itemcount;
2654: return $datatable;
2655: }
2656:
2657: sub newspare_select {
2658: my ($server,$type,$currspares,$uniques) = @_;
2659: my $output;
2660: if (ref($uniques) eq 'HASH') {
2661: if (keys(%{$uniques}) > 1) {
2662: $output = '<select name="newspare_'.$type.'_'.$server.'">'."\n".
2663: '<option value="" selected ="selected">'.&mt('Select').'</option>'."\n";
2664: foreach my $lonhost (sort(keys(%{$uniques}))) {
2665: next if ($lonhost eq $server);
2666: if (ref($currspares) eq 'ARRAY') {
2667: if (@{$currspares} > 0) {
2668: next if (grep(/^\Q$lonhost\E$/,@{$currspares}));
2669: }
2670: }
2671: $output .= '<option value="'.$lonhost.'">'.$lonhost.'</option>'."\n";
2672: }
2673: $output .= '<select>';
2674: }
2675: }
2676: return $output;
2677: }
2678:
1.150 ! raeburn 2679: sub print_loadbalancing {
! 2680: my ($dom,$settings,$rowtotal) = @_;
! 2681: my $primary_id = &Apache::lonnet::domain($dom,'primary');
! 2682: my $intdom = &Apache::lonnet::internet_dom($primary_id);
! 2683: my $numinrow = 1;
! 2684: my $datatable;
! 2685: my %servers = &Apache::lonnet::internet_dom_servers($dom);
! 2686: my ($currbalancer,$currtargets,$currrules);
! 2687: if (keys(%servers) > 1) {
! 2688: if (ref($settings) eq 'HASH') {
! 2689: $currbalancer = $settings->{'lonhost'};
! 2690: $currtargets = $settings->{'targets'};
! 2691: $currrules = $settings->{'rules'};
! 2692: } else {
! 2693: ($currbalancer,$currtargets) =
! 2694: &Apache::lonnet::get_lonbalancer_config(\%servers);
! 2695: }
! 2696: } else {
! 2697: return;
! 2698: }
! 2699: my ($othertitle,$usertypes,$types) =
! 2700: &Apache::loncommon::sorted_inst_types($dom);
! 2701: my $rownum = 6;
! 2702: if (ref($types) eq 'ARRAY') {
! 2703: $rownum += scalar(@{$types});
! 2704: }
! 2705: my $css_class = 'class="LC_odd_row"';
! 2706: my $targets_div_style = 'display: none';
! 2707: my $disabled_div_style = 'display: block';
! 2708: my $homedom_div_style = 'display: none';
! 2709: $datatable = '<tr'.$css_class.'>'.
! 2710: '<td rowspan="'.$rownum.'" valign="top">'.
! 2711: '<p><select name="loadbalancing_lonhost" onchange="toggleTargets();">'."\n".
! 2712: '<option value=""';
! 2713: if (($currbalancer eq '') || (!grep(/^\Q$currbalancer\E$/,keys(%servers)))) {
! 2714: $datatable .= ' selected="selected"';
! 2715: } else {
! 2716: $targets_div_style = 'display: block';
! 2717: $disabled_div_style = 'display: none';
! 2718: if ($dom eq &Apache::lonnet::host_domain($currbalancer)) {
! 2719: $homedom_div_style = 'display: block';
! 2720: }
! 2721: }
! 2722: $datatable .= '>'.&mt('None').'</option>'."\n";
! 2723: foreach my $lonhost (sort(keys(%servers))) {
! 2724: my $selected;
! 2725: if ($lonhost eq $currbalancer) {
! 2726: $selected .= ' selected="selected"';
! 2727: }
! 2728: $datatable .= '<option value="'.$lonhost.'"'.$selected.'>'.$lonhost.'</option>'."\n";
! 2729: }
! 2730: $datatable .= '</select></p></td><td rowspan="'.$rownum.'" valign="top">'.
! 2731: '<div id="loadbalancing_disabled" style="'.$disabled_div_style.'">'.&mt('No dedicated Load Balancer').'</div>'."\n".
! 2732: '<div id="loadbalancing_targets" style="'.$targets_div_style.'">'.&mt('Offloads to:').'<br />';
! 2733: my ($numspares,@spares) = &count_servers($currbalancer,%servers);
! 2734: my @sparestypes = ('primary','default');
! 2735: my %typetitles = &sparestype_titles();
! 2736: foreach my $sparetype (@sparestypes) {
! 2737: my $targettable;
! 2738: for (my $i=0; $i<$numspares; $i++) {
! 2739: my $checked;
! 2740: if (ref($currtargets) eq 'HASH') {
! 2741: if (ref($currtargets->{$sparetype}) eq 'ARRAY') {
! 2742: if (grep(/^\Q$spares[$i]\E$/,@{$currtargets->{$sparetype}})) {
! 2743: $checked = ' checked="checked"';
! 2744: }
! 2745: }
! 2746: }
! 2747: my $chkboxval;
! 2748: if (($currbalancer ne '') && (grep((/^\Q$currbalancer\E$/,keys(%servers))))) {
! 2749: $chkboxval = $spares[$i];
! 2750: }
! 2751: $targettable .= '<td><label><input type="checkbox" name="loadbalancing_target_'.$sparetype.'"'.
! 2752: $checked.' value="'.$chkboxval.'" id="loadbalancing_target_'.$sparetype.'_'.$i.'" onclick="checkOffloads('."this,'$sparetype'".');" /><span id="loadbalancing_targettxt_'.$sparetype.'_'.$i.'"> '.$chkboxval.
! 2753: '</span></label></td>';
! 2754: my $rem = $i%($numinrow);
! 2755: if ($rem == 0) {
! 2756: if ($i > 0) {
! 2757: $targettable .= '</tr>';
! 2758: }
! 2759: $targettable .= '<tr>';
! 2760: }
! 2761: }
! 2762: if ($targettable ne '') {
! 2763: my $rem = $numspares%($numinrow);
! 2764: my $colsleft = $numinrow - $rem;
! 2765: if ($colsleft > 1 ) {
! 2766: $targettable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
! 2767: ' </td>';
! 2768: } elsif ($colsleft == 1) {
! 2769: $targettable .= '<td class="LC_left_item"> </td>';
! 2770: }
! 2771: $datatable .= '<i>'.$typetitles{$sparetype}.'</i><br />'.
! 2772: '<table><tr>'.$targettable.'</table><br />';
! 2773: }
! 2774: }
! 2775: $datatable .= '</div></td></tr>'.
! 2776: &loadbalancing_rules($dom,$intdom,$currrules,$othertitle,
! 2777: $usertypes,$types,\%servers,$currbalancer,
! 2778: $targets_div_style,$homedom_div_style);
! 2779: $$rowtotal += $rownum;
! 2780: return $datatable;
! 2781: }
! 2782:
! 2783: sub loadbalancing_rules {
! 2784: my ($dom,$intdom,$currrules,$othertitle,$usertypes,$types,$servers,
! 2785: $currbalancer,$targets_div_style,$homedom_div_style) = @_;
! 2786: my $output;
! 2787: my ($alltypes,$othertypes,$titles) =
! 2788: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
! 2789: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
! 2790: foreach my $type (@{$alltypes}) {
! 2791: my $current;
! 2792: if (ref($currrules) eq 'HASH') {
! 2793: $current = $currrules->{$type};
! 2794: }
! 2795: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
! 2796: if ($dom ne &Apache::lonnet::host_domain($currbalancer)) {
! 2797: $current = '';
! 2798: }
! 2799: }
! 2800: $output .= &loadbalance_rule_row($type,$titles->{$type},$current,
! 2801: $servers,$currbalancer,$dom,
! 2802: $targets_div_style,$homedom_div_style);
! 2803: }
! 2804: }
! 2805: return $output;
! 2806: }
! 2807:
! 2808: sub loadbalancing_titles {
! 2809: my ($dom,$intdom,$usertypes,$types) = @_;
! 2810: my %othertypes = (
! 2811: '_LC_adv' => &mt('Advanced users from [_1]',$dom),
! 2812: '_LC_author' => &mt('Users from [_1] with author role',$dom),
! 2813: '_LC_internetdom' => &mt('Users not from [_1], but from [_2]',$dom,$intdom),
! 2814: '_LC_external' => &mt('Users not from [_1]',$intdom),
! 2815: );
! 2816: my @alltypes = ('_LC_adv','_LC_author','_LC_internetdom','_LC_external');
! 2817: if (ref($types) eq 'ARRAY') {
! 2818: unshift(@alltypes,@{$types},'default');
! 2819: }
! 2820: my %titles;
! 2821: foreach my $type (@alltypes) {
! 2822: if ($type =~ /^_LC_/) {
! 2823: $titles{$type} = $othertypes{$type};
! 2824: } elsif ($type eq 'default') {
! 2825: $titles{$type} = &mt('All users from [_1]',$dom);
! 2826: if (ref($types) eq 'ARRAY') {
! 2827: if (@{$types} > 0) {
! 2828: $titles{$type} = &mt('Other users from [_1]',$dom);
! 2829: }
! 2830: }
! 2831: } elsif (ref($usertypes) eq 'HASH') {
! 2832: $titles{$type} = $usertypes->{$type};
! 2833: }
! 2834: }
! 2835: return (\@alltypes,\%othertypes,\%titles);
! 2836: }
! 2837:
! 2838: sub loadbalance_rule_row {
! 2839: my ($type,$title,$current,$servers,$currbalancer,$dom,$targets_div_style,
! 2840: $homedom_div_style) = @_;
! 2841: my @rulenames = ('default','homeserver');
! 2842: my %ruletitles = &offloadtype_text();
! 2843: if ($type eq '_LC_external') {
! 2844: push(@rulenames,'externalbalancer');
! 2845: } else {
! 2846: push(@rulenames,'specific');
! 2847: }
! 2848: my $style = $targets_div_style;
! 2849: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
! 2850: $style = $homedom_div_style;
! 2851: }
! 2852: my $output =
! 2853: '<tr><td valign="top"><div id="balanceruletitle_'.$type.'" style="'.$style.'">'.$title.'</div></td>'."\n".
! 2854: '<td><div id="balancerule_'.$type.'" style="'.$style.'">'."\n";
! 2855: for (my $i=0; $i<@rulenames; $i++) {
! 2856: my $rule = $rulenames[$i];
! 2857: my ($checked,$extra);
! 2858: if ($rulenames[$i] eq 'default') {
! 2859: $rule = '';
! 2860: }
! 2861: if ($rulenames[$i] eq 'specific') {
! 2862: if (ref($servers) eq 'HASH') {
! 2863: my $default;
! 2864: if (($current ne '') && (exists($servers->{$current}))) {
! 2865: $checked = ' checked="checked"';
! 2866: }
! 2867: unless ($checked) {
! 2868: $default = ' selected="selected"';
! 2869: }
! 2870: $extra = ': <select name="loadbalancing_singleserver_'.$type.
! 2871: '" id="loadbalancing_singleserver_'.$type.
! 2872: '" onchange="singleServerToggle('."'$type'".')">'."\n".
! 2873: '<option value=""'.$default.'></option>'."\n";
! 2874: foreach my $lonhost (sort(keys(%{$servers}))) {
! 2875: next if ($lonhost eq $currbalancer);
! 2876: my $selected;
! 2877: if ($lonhost eq $current) {
! 2878: $selected = ' selected="selected"';
! 2879: }
! 2880: $extra .= '<option value="'.$lonhost.'"'.$selected.'>'.$lonhost.'</option>';
! 2881: }
! 2882: $extra .= '</select>';
! 2883: }
! 2884: } elsif ($rule eq $current) {
! 2885: $checked = ' checked="checked"';
! 2886: }
! 2887: $output .= '<span class="LC_nobreak"><label>'.
! 2888: '<input type="radio" name="loadbalancing_rules_'.$type.
! 2889: '" id="loadbalancing_rules_'.$type.'_'.$i.'" value="'.
! 2890: $rule.'" onclick="balanceruleChange('."this.form,'$type'".
! 2891: ')"'.$checked.' /> '.$ruletitles{$rulenames[$i]}.
! 2892: '</label>'.$extra.'</span><br />'."\n";
! 2893: }
! 2894: $output .= '</div></td></tr>'."\n";
! 2895: return $output;
! 2896: }
! 2897:
! 2898: sub offloadtype_text {
! 2899: my %ruletitles = &Apache::lonlocal::texthash (
! 2900: 'default' => 'Offloads to default destinations',
! 2901: 'homeserver' => "Offloads to user's home server",
! 2902: 'externalbalancer' => "Offloads to Load Balancer in user's domain",
! 2903: 'specific' => 'Offloads to specific server',
! 2904: );
! 2905: return %ruletitles;
! 2906: }
! 2907:
! 2908: sub sparestype_titles {
! 2909: my %typestitles = &Apache::lonlocal::texthash (
! 2910: 'primary' => 'primary',
! 2911: 'default' => 'default',
! 2912: );
! 2913: return %typestitles;
! 2914: }
! 2915:
1.28 raeburn 2916: sub contact_titles {
2917: my %titles = &Apache::lonlocal::texthash (
2918: 'supportemail' => 'Support E-mail address',
1.69 raeburn 2919: 'adminemail' => 'Default Server Admin E-mail address',
1.28 raeburn 2920: 'errormail' => 'Error reports to be e-mailed to',
2921: 'packagesmail' => 'Package update alerts to be e-mailed to',
1.89 raeburn 2922: 'helpdeskmail' => 'Helpdesk requests to be e-mailed to',
2923: 'lonstatusmail' => 'E-mail from nightly status check (warnings/errors)',
1.102 raeburn 2924: 'requestsmail' => 'E-mail from course requests requiring approval',
1.28 raeburn 2925: );
2926: my %short_titles = &Apache::lonlocal::texthash (
2927: adminemail => 'Admin E-mail address',
2928: supportemail => 'Support E-mail',
2929: );
2930: return (\%titles,\%short_titles);
2931: }
2932:
1.72 raeburn 2933: sub tool_titles {
2934: my %titles = &Apache::lonlocal::texthash (
1.90 weissno 2935: aboutme => 'Personal Information Page',
1.86 raeburn 2936: blog => 'Blog',
2937: portfolio => 'Portfolio',
1.88 bisitz 2938: official => 'Official courses (with institutional codes)',
2939: unofficial => 'Unofficial courses',
1.98 raeburn 2940: community => 'Communities',
1.86 raeburn 2941: );
1.72 raeburn 2942: return %titles;
2943: }
2944:
1.101 raeburn 2945: sub courserequest_titles {
2946: my %titles = &Apache::lonlocal::texthash (
2947: official => 'Official',
2948: unofficial => 'Unofficial',
2949: community => 'Communities',
2950: norequest => 'Not allowed',
1.104 raeburn 2951: approval => 'Approval by Dom. Coord.',
1.101 raeburn 2952: validate => 'With validation',
2953: autolimit => 'Numerical limit',
1.103 raeburn 2954: unlimited => '(blank for unlimited)',
1.101 raeburn 2955: );
2956: return %titles;
2957: }
2958:
2959: sub courserequest_conditions {
2960: my %conditions = &Apache::lonlocal::texthash (
1.104 raeburn 2961: approval => '(Processing of request subject to approval by Domain Coordinator).',
1.101 raeburn 2962: validate => '(Processing of request subject to instittutional validation).',
2963: );
2964: return %conditions;
2965: }
2966:
2967:
1.27 raeburn 2968: sub print_usercreation {
1.30 raeburn 2969: my ($position,$dom,$settings,$rowtotal) = @_;
1.27 raeburn 2970: my $numinrow = 4;
1.28 raeburn 2971: my $datatable;
2972: if ($position eq 'top') {
1.30 raeburn 2973: $$rowtotal ++;
1.34 raeburn 2974: my $rowcount = 0;
1.32 raeburn 2975: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username');
1.28 raeburn 2976: if (ref($rules) eq 'HASH') {
2977: if (keys(%{$rules}) > 0) {
1.32 raeburn 2978: $datatable .= &user_formats_row('username',$settings,$rules,
2979: $ruleorder,$numinrow,$rowcount);
1.30 raeburn 2980: $$rowtotal ++;
1.32 raeburn 2981: $rowcount ++;
2982: }
2983: }
2984: my ($idrules,$idruleorder) = &Apache::lonnet::inst_userrules($dom,'id');
2985: if (ref($idrules) eq 'HASH') {
2986: if (keys(%{$idrules}) > 0) {
2987: $datatable .= &user_formats_row('id',$settings,$idrules,
2988: $idruleorder,$numinrow,$rowcount);
2989: $$rowtotal ++;
2990: $rowcount ++;
1.28 raeburn 2991: }
2992: }
1.43 raeburn 2993: my ($emailrules,$emailruleorder) =
2994: &Apache::lonnet::inst_userrules($dom,'email');
2995: if (ref($emailrules) eq 'HASH') {
2996: if (keys(%{$emailrules}) > 0) {
2997: $datatable .= &user_formats_row('email',$settings,$emailrules,
2998: $emailruleorder,$numinrow,$rowcount);
2999: $$rowtotal ++;
3000: $rowcount ++;
3001: }
3002: }
1.39 raeburn 3003: if ($rowcount == 0) {
3004: $datatable .= '<tr><td colspan="2">'.&mt('No format rules have been defined for usernames or IDs in this domain.').'</td></tr>';
3005: $$rowtotal ++;
3006: $rowcount ++;
3007: }
1.34 raeburn 3008: } elsif ($position eq 'middle') {
1.100 raeburn 3009: my @creators = ('author','course','requestcrs','selfcreate');
1.37 raeburn 3010: my ($rules,$ruleorder) =
3011: &Apache::lonnet::inst_userrules($dom,'username');
1.34 raeburn 3012: my %lt = &usercreation_types();
3013: my %checked;
1.50 raeburn 3014: my @selfcreate;
1.34 raeburn 3015: if (ref($settings) eq 'HASH') {
3016: if (ref($settings->{'cancreate'}) eq 'HASH') {
3017: foreach my $item (@creators) {
3018: $checked{$item} = $settings->{'cancreate'}{$item};
3019: }
1.50 raeburn 3020: if (ref($settings->{'cancreate'}{'selfcreate'}) eq 'ARRAY') {
3021: @selfcreate = @{$settings->{'cancreate'}{'selfcreate'}};
3022: } elsif ($settings->{'cancreate'}{'selfcreate'} ne '') {
3023: if ($settings->{'cancreate'}{'selfcreate'} eq 'any') {
3024: @selfcreate = ('email','login','sso');
3025: } elsif ($settings->{'cancreate'}{'selfcreate'} ne 'none') {
3026: @selfcreate = ($settings->{'cancreate'}{'selfcreate'});
3027: }
3028: }
1.34 raeburn 3029: } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {
3030: foreach my $item (@creators) {
3031: if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {
3032: $checked{$item} = 'none';
3033: }
3034: }
3035: }
3036: }
3037: my $rownum = 0;
3038: foreach my $item (@creators) {
3039: $rownum ++;
1.50 raeburn 3040: if ($item ne 'selfcreate') {
3041: if ($checked{$item} eq '') {
1.43 raeburn 3042: $checked{$item} = 'any';
3043: }
1.34 raeburn 3044: }
3045: my $css_class;
3046: if ($rownum%2) {
3047: $css_class = '';
3048: } else {
3049: $css_class = ' class="LC_odd_row" ';
3050: }
3051: $datatable .= '<tr'.$css_class.'>'.
3052: '<td><span class="LC_nobreak">'.$lt{$item}.
3053: '</span></td><td align="right">';
1.50 raeburn 3054: my @options;
1.45 raeburn 3055: if ($item eq 'selfcreate') {
1.43 raeburn 3056: push(@options,('email','login','sso'));
3057: } else {
1.50 raeburn 3058: @options = ('any');
1.43 raeburn 3059: if (ref($rules) eq 'HASH') {
3060: if (keys(%{$rules}) > 0) {
3061: push(@options,('official','unofficial'));
3062: }
1.37 raeburn 3063: }
1.50 raeburn 3064: push(@options,'none');
1.37 raeburn 3065: }
3066: foreach my $option (@options) {
1.50 raeburn 3067: my $type = 'radio';
1.34 raeburn 3068: my $check = ' ';
1.50 raeburn 3069: if ($item eq 'selfcreate') {
3070: $type = 'checkbox';
3071: if (grep(/^\Q$option\E$/,@selfcreate)) {
3072: $check = ' checked="checked" ';
3073: }
3074: } else {
3075: if ($checked{$item} eq $option) {
3076: $check = ' checked="checked" ';
3077: }
1.34 raeburn 3078: }
3079: $datatable .= '<span class="LC_nobreak"><label>'.
1.50 raeburn 3080: '<input type="'.$type.'" name="can_createuser_'.
1.34 raeburn 3081: $item.'" value="'.$option.'"'.$check.'/> '.
3082: $lt{$option}.'</label> </span>';
3083: }
3084: $datatable .= '</td></tr>';
3085: }
1.93 raeburn 3086: my ($othertitle,$usertypes,$types) =
3087: &Apache::loncommon::sorted_inst_types($dom);
3088: if (ref($usertypes) eq 'HASH') {
3089: if (keys(%{$usertypes}) > 0) {
1.99 raeburn 3090: my $createsettings;
3091: if (ref($settings) eq 'HASH') {
3092: $createsettings = $settings->{cancreate};
3093: }
3094: $datatable .= &insttypes_row($createsettings,$types,$usertypes,
1.93 raeburn 3095: $dom,$numinrow,$othertitle,
3096: 'statustocreate');
3097: $$rowtotal ++;
3098: }
3099: }
1.28 raeburn 3100: } else {
3101: my @contexts = ('author','course','domain');
3102: my @authtypes = ('int','krb4','krb5','loc');
3103: my %checked;
3104: if (ref($settings) eq 'HASH') {
3105: if (ref($settings->{'authtypes'}) eq 'HASH') {
3106: foreach my $item (@contexts) {
3107: if (ref($settings->{'authtypes'}{$item}) eq 'HASH') {
3108: foreach my $auth (@authtypes) {
3109: if ($settings->{'authtypes'}{$item}{$auth}) {
3110: $checked{$item}{$auth} = ' checked="checked" ';
3111: }
3112: }
3113: }
3114: }
1.27 raeburn 3115: }
1.35 raeburn 3116: } else {
3117: foreach my $item (@contexts) {
1.36 raeburn 3118: foreach my $auth (@authtypes) {
1.35 raeburn 3119: $checked{$item}{$auth} = ' checked="checked" ';
3120: }
3121: }
1.27 raeburn 3122: }
1.28 raeburn 3123: my %title = &context_names();
3124: my %authname = &authtype_names();
3125: my $rownum = 0;
3126: my $css_class;
3127: foreach my $item (@contexts) {
3128: if ($rownum%2) {
3129: $css_class = '';
3130: } else {
3131: $css_class = ' class="LC_odd_row" ';
3132: }
1.30 raeburn 3133: $datatable .= '<tr'.$css_class.'>'.
1.28 raeburn 3134: '<td>'.$title{$item}.
3135: '</td><td class="LC_left_item">'.
3136: '<span class="LC_nobreak">';
3137: foreach my $auth (@authtypes) {
3138: $datatable .= '<label>'.
3139: '<input type="checkbox" name="'.$item.'_auth" '.
3140: $checked{$item}{$auth}.' value="'.$auth.'" />'.
3141: $authname{$auth}.'</label> ';
3142: }
3143: $datatable .= '</span></td></tr>';
3144: $rownum ++;
1.27 raeburn 3145: }
1.30 raeburn 3146: $$rowtotal += $rownum;
1.27 raeburn 3147: }
3148: return $datatable;
3149: }
3150:
1.32 raeburn 3151: sub user_formats_row {
3152: my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount) = @_;
3153: my $output;
3154: my %text = (
3155: 'username' => 'new usernames',
3156: 'id' => 'IDs',
1.45 raeburn 3157: 'email' => 'self-created accounts (e-mail)',
1.32 raeburn 3158: );
3159: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
3160: $output = '<tr '.$css_class.'>'.
1.63 raeburn 3161: '<td><span class="LC_nobreak">';
3162: if ($type eq 'email') {
3163: $output .= &mt("Formats disallowed for $text{$type}: ");
3164: } else {
3165: $output .= &mt("Format rules to check for $text{$type}: ");
3166: }
3167: $output .= '</span></td>'.
3168: '<td class="LC_left_item" colspan="2"><table>';
1.27 raeburn 3169: my $rem;
3170: if (ref($ruleorder) eq 'ARRAY') {
3171: for (my $i=0; $i<@{$ruleorder}; $i++) {
3172: if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
3173: my $rem = $i%($numinrow);
3174: if ($rem == 0) {
3175: if ($i > 0) {
3176: $output .= '</tr>';
3177: }
3178: $output .= '<tr>';
3179: }
3180: my $check = ' ';
1.39 raeburn 3181: if (ref($settings) eq 'HASH') {
3182: if (ref($settings->{$type.'_rule'}) eq 'ARRAY') {
3183: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) {
3184: $check = ' checked="checked" ';
3185: }
1.27 raeburn 3186: }
3187: }
3188: $output .= '<td class="LC_left_item">'.
3189: '<span class="LC_nobreak"><label>'.
1.32 raeburn 3190: '<input type="checkbox" name="'.$type.'_rule" '.
1.27 raeburn 3191: 'value="'.$ruleorder->[$i].'"'.$check.'/>'.
3192: $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
3193: }
3194: }
3195: $rem = @{$ruleorder}%($numinrow);
3196: }
3197: my $colsleft = $numinrow - $rem;
3198: if ($colsleft > 1 ) {
3199: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
3200: ' </td>';
3201: } elsif ($colsleft == 1) {
3202: $output .= '<td class="LC_left_item"> </td>';
3203: }
3204: $output .= '</tr></table></td></tr>';
3205: return $output;
3206: }
3207:
1.34 raeburn 3208: sub usercreation_types {
3209: my %lt = &Apache::lonlocal::texthash (
3210: author => 'When adding a co-author',
3211: course => 'When adding a user to a course',
1.100 raeburn 3212: requestcrs => 'When requesting a course',
1.45 raeburn 3213: selfcreate => 'User creates own account',
1.34 raeburn 3214: any => 'Any',
3215: official => 'Institutional only ',
3216: unofficial => 'Non-institutional only',
1.85 schafran 3217: email => 'E-mail address',
1.43 raeburn 3218: login => 'Institutional Login',
3219: sso => 'SSO',
1.34 raeburn 3220: none => 'None',
3221: );
3222: return %lt;
1.48 raeburn 3223: }
1.34 raeburn 3224:
1.28 raeburn 3225: sub authtype_names {
3226: my %lt = &Apache::lonlocal::texthash(
3227: int => 'Internal',
3228: krb4 => 'Kerberos 4',
3229: krb5 => 'Kerberos 5',
3230: loc => 'Local',
3231: );
3232: return %lt;
3233: }
3234:
3235: sub context_names {
3236: my %context_title = &Apache::lonlocal::texthash(
3237: author => 'Creating users when an Author',
3238: course => 'Creating users when in a course',
3239: domain => 'Creating users when a Domain Coordinator',
3240: );
3241: return %context_title;
3242: }
3243:
1.33 raeburn 3244: sub print_usermodification {
3245: my ($position,$dom,$settings,$rowtotal) = @_;
3246: my $numinrow = 4;
3247: my ($context,$datatable,$rowcount);
3248: if ($position eq 'top') {
3249: $rowcount = 0;
3250: $context = 'author';
3251: foreach my $role ('ca','aa') {
3252: $datatable .= &modifiable_userdata_row($context,$role,$settings,
3253: $numinrow,$rowcount);
3254: $$rowtotal ++;
3255: $rowcount ++;
3256: }
1.63 raeburn 3257: } elsif ($position eq 'middle') {
1.33 raeburn 3258: $context = 'course';
3259: $rowcount = 0;
3260: foreach my $role ('st','ep','ta','in','cr') {
3261: $datatable .= &modifiable_userdata_row($context,$role,$settings,
3262: $numinrow,$rowcount);
3263: $$rowtotal ++;
3264: $rowcount ++;
3265: }
1.63 raeburn 3266: } elsif ($position eq 'bottom') {
3267: $context = 'selfcreate';
3268: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
3269: $usertypes->{'default'} = $othertitle;
3270: if (ref($types) eq 'ARRAY') {
3271: push(@{$types},'default');
3272: $usertypes->{'default'} = $othertitle;
3273: foreach my $status (@{$types}) {
3274: $datatable .= &modifiable_userdata_row($context,$status,$settings,
3275: $numinrow,$rowcount,$usertypes);
3276: $$rowtotal ++;
3277: $rowcount ++;
3278: }
3279: }
1.33 raeburn 3280: }
3281: return $datatable;
3282: }
3283:
1.43 raeburn 3284: sub print_defaults {
3285: my ($dom,$rowtotal) = @_;
1.68 raeburn 3286: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def',
1.141 raeburn 3287: 'datelocale_def','portal_def');
1.43 raeburn 3288: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.141 raeburn 3289: my $titles = &defaults_titles($dom);
1.43 raeburn 3290: my $rownum = 0;
3291: my ($datatable,$css_class);
3292: foreach my $item (@items) {
3293: if ($rownum%2) {
3294: $css_class = '';
3295: } else {
3296: $css_class = ' class="LC_odd_row" ';
3297: }
3298: $datatable .= '<tr'.$css_class.'>'.
3299: '<td><span class="LC_nobreak">'.$titles->{$item}.
3300: '</span></td><td class="LC_right_item">';
3301: if ($item eq 'auth_def') {
3302: my @authtypes = ('internal','krb4','krb5','localauth');
3303: my %shortauth = (
3304: internal => 'int',
3305: krb4 => 'krb4',
3306: krb5 => 'krb5',
3307: localauth => 'loc'
3308: );
3309: my %authnames = &authtype_names();
3310: foreach my $auth (@authtypes) {
3311: my $checked = ' ';
3312: if ($domdefaults{$item} eq $auth) {
3313: $checked = ' checked="checked" ';
3314: }
3315: $datatable .= '<label><input type="radio" name="'.$item.
3316: '" value="'.$auth.'"'.$checked.'/>'.
3317: $authnames{$shortauth{$auth}}.'</label> ';
3318: }
1.54 raeburn 3319: } elsif ($item eq 'timezone_def') {
3320: my $includeempty = 1;
3321: $datatable .= &Apache::loncommon::select_timezone($item,$domdefaults{$item},undef,$includeempty);
1.68 raeburn 3322: } elsif ($item eq 'datelocale_def') {
3323: my $includeempty = 1;
3324: $datatable .= &Apache::loncommon::select_datelocale($item,$domdefaults{$item},undef,$includeempty);
1.43 raeburn 3325: } else {
1.141 raeburn 3326: my $size;
3327: if ($item eq 'portal_def') {
3328: $size = ' size="25"';
3329: }
1.43 raeburn 3330: $datatable .= '<input type="text" name="'.$item.'" value="'.
1.141 raeburn 3331: $domdefaults{$item}.'"'.$size.' />';
1.43 raeburn 3332: }
3333: $datatable .= '</td></tr>';
3334: $rownum ++;
3335: }
3336: $$rowtotal += $rownum;
3337: return $datatable;
3338: }
3339:
3340: sub defaults_titles {
1.141 raeburn 3341: my ($dom) = @_;
1.43 raeburn 3342: my %titles = &Apache::lonlocal::texthash (
3343: 'auth_def' => 'Default authentication type',
3344: 'auth_arg_def' => 'Default authentication argument',
3345: 'lang_def' => 'Default language',
1.54 raeburn 3346: 'timezone_def' => 'Default timezone',
1.68 raeburn 3347: 'datelocale_def' => 'Default locale for dates',
1.141 raeburn 3348: 'portal_def' => 'Portal/Default URL',
1.43 raeburn 3349: );
1.141 raeburn 3350: if ($dom) {
3351: my $uprimary_id = &Apache::lonnet::domain($dom,'primary');
3352: my $uint_dom = &Apache::lonnet::internet_dom($uprimary_id);
3353: my $protocol = $Apache::lonnet::protocol{$uprimary_id};
3354: $protocol = 'http' if ($protocol ne 'https');
3355: if ($uint_dom) {
3356: $titles{'portal_def'} .= ' '.&mt('(for example: [_1])',$protocol.'://loncapa.'.
3357: $uint_dom);
3358: }
3359: }
1.43 raeburn 3360: return (\%titles);
3361: }
3362:
1.46 raeburn 3363: sub print_scantronformat {
3364: my ($r,$dom,$confname,$settings,$rowtotal) = @_;
3365: my $itemcount = 1;
1.60 raeburn 3366: my ($datatable,$css_class,$scantronurl,$is_custom,%error,%scantronurls,
3367: %confhash);
1.46 raeburn 3368: my $switchserver = &check_switchserver($dom,$confname);
3369: my %lt = &Apache::lonlocal::texthash (
1.95 www 3370: default => 'Default bubblesheet format file error',
3371: custom => 'Custom bubblesheet format file error',
1.46 raeburn 3372: );
3373: my %scantronfiles = (
3374: default => 'default.tab',
3375: custom => 'custom.tab',
3376: );
3377: foreach my $key (keys(%scantronfiles)) {
3378: $scantronurls{$key} = '/res/'.$dom.'/'.$confname.'/scantron/'
3379: .$scantronfiles{$key};
3380: }
3381: my @defaultinfo = &Apache::lonnet::stat_file($scantronurls{'default'});
3382: if ((!@defaultinfo) || ($defaultinfo[0] eq 'no_such_dir')) {
3383: if (!$switchserver) {
3384: my $servadm = $r->dir_config('lonAdmEMail');
3385: my ($configuserok,$author_ok) = &config_check($dom,$confname,$servadm);
3386: if ($configuserok eq 'ok') {
3387: if ($author_ok eq 'ok') {
3388: my %legacyfile = (
3389: default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab',
3390: custom => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab',
3391: );
3392: my %md5chk;
3393: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 3394: ($md5chk{$type}) = split(/ /,`md5sum $legacyfile{$type}`);
3395: chomp($md5chk{$type});
1.46 raeburn 3396: }
3397: if ($md5chk{'default'} ne $md5chk{'custom'}) {
3398: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 3399: ($scantronurls{$type},my $error) =
1.46 raeburn 3400: &legacy_scantronformat($r,$dom,$confname,
3401: $type,$legacyfile{$type},
3402: $scantronurls{$type},
3403: $scantronfiles{$type});
1.60 raeburn 3404: if ($error ne '') {
3405: $error{$type} = $error;
3406: }
3407: }
3408: if (keys(%error) == 0) {
3409: $is_custom = 1;
3410: $confhash{'scantron'}{'scantronformat'} =
3411: $scantronurls{'custom'};
3412: my $putresult =
3413: &Apache::lonnet::put_dom('configuration',
3414: \%confhash,$dom);
3415: if ($putresult ne 'ok') {
3416: $error{'custom'} =
3417: '<span class="LC_error">'.
3418: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
3419: }
1.46 raeburn 3420: }
3421: } else {
1.60 raeburn 3422: ($scantronurls{'default'},my $error) =
1.46 raeburn 3423: &legacy_scantronformat($r,$dom,$confname,
3424: 'default',$legacyfile{'default'},
3425: $scantronurls{'default'},
3426: $scantronfiles{'default'});
1.60 raeburn 3427: if ($error eq '') {
3428: $confhash{'scantron'}{'scantronformat'} = '';
3429: my $putresult =
3430: &Apache::lonnet::put_dom('configuration',
3431: \%confhash,$dom);
3432: if ($putresult ne 'ok') {
3433: $error{'default'} =
3434: '<span class="LC_error">'.
3435: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
3436: }
3437: } else {
3438: $error{'default'} = $error;
3439: }
1.46 raeburn 3440: }
3441: }
3442: }
3443: } else {
1.95 www 3444: $error{'default'} = &mt("Unable to copy default bubblesheet formatfile to domain's RES space: [_1]",$switchserver);
1.46 raeburn 3445: }
3446: }
3447: if (ref($settings) eq 'HASH') {
3448: if ($settings->{'scantronformat'} eq "/res/$dom/$confname/scantron/custom.tab") {
3449: my @info = &Apache::lonnet::stat_file($settings->{'scantronformat'});
3450: if ((!@info) || ($info[0] eq 'no_such_dir')) {
3451: $scantronurl = '';
3452: } else {
3453: $scantronurl = $settings->{'scantronformat'};
3454: }
3455: $is_custom = 1;
3456: } else {
3457: $scantronurl = $scantronurls{'default'};
3458: }
3459: } else {
1.60 raeburn 3460: if ($is_custom) {
3461: $scantronurl = $scantronurls{'custom'};
3462: } else {
3463: $scantronurl = $scantronurls{'default'};
3464: }
1.46 raeburn 3465: }
3466: $css_class = $itemcount%2?' class="LC_odd_row"':'';
3467: $datatable .= '<tr'.$css_class.'>';
3468: if (!$is_custom) {
1.65 raeburn 3469: $datatable .= '<td>'.&mt('Default in use:').'<br />'.
3470: '<span class="LC_nobreak">';
1.46 raeburn 3471: if ($scantronurl) {
3472: $datatable .= '<a href="'.$scantronurl.'" target="_blank">'.
1.130 raeburn 3473: &mt('Default bubblesheet format file').'</a>';
1.46 raeburn 3474: } else {
3475: $datatable = &mt('File unavailable for display');
3476: }
1.65 raeburn 3477: $datatable .= '</span></td>';
1.60 raeburn 3478: if (keys(%error) == 0) {
3479: $datatable .= '<td valign="bottom">';
3480: if (!$switchserver) {
3481: $datatable .= &mt('Upload:').'<br />';
3482: }
3483: } else {
3484: my $errorstr;
3485: foreach my $key (sort(keys(%error))) {
3486: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
3487: }
3488: $datatable .= '<td>'.$errorstr;
3489: }
1.46 raeburn 3490: } else {
3491: if (keys(%error) > 0) {
3492: my $errorstr;
3493: foreach my $key (sort(keys(%error))) {
3494: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
3495: }
1.60 raeburn 3496: $datatable .= '<td>'.$errorstr.'</td><td> ';
1.46 raeburn 3497: } elsif ($scantronurl) {
1.65 raeburn 3498: $datatable .= '<td><span class="LC_nobreak">'.
3499: '<a href="'.$scantronurl.'" target="_blank">'.
1.130 raeburn 3500: &mt('Custom bubblesheet format file').'</a><label>'.
1.65 raeburn 3501: '<input type="checkbox" name="scantronformat_del"'.
3502: '" value="1" />'.&mt('Delete?').'</label></span></td>'.
3503: '<td><span class="LC_nobreak"> '.
3504: &mt('Replace:').'</span><br />';
1.46 raeburn 3505: }
3506: }
3507: if (keys(%error) == 0) {
3508: if ($switchserver) {
3509: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
3510: } else {
1.65 raeburn 3511: $datatable .='<span class="LC_nobreak"> '.
3512: '<input type="file" name="scantronformat" /></span>';
1.46 raeburn 3513: }
3514: }
3515: $datatable .= '</td></tr>';
3516: $$rowtotal ++;
3517: return $datatable;
3518: }
3519:
3520: sub legacy_scantronformat {
3521: my ($r,$dom,$confname,$file,$legacyfile,$newurl,$newfile) = @_;
3522: my ($url,$error);
3523: my @statinfo = &Apache::lonnet::stat_file($newurl);
3524: if ((!@statinfo) || ($statinfo[0] eq 'no_such_dir')) {
3525: (my $result,$url) =
3526: &publishlogo($r,'copy',$legacyfile,$dom,$confname,'scantron',
3527: '','',$newfile);
3528: if ($result ne 'ok') {
1.130 raeburn 3529: $error = &mt("An error occurred publishing the [_1] bubblesheet format file in RES space. Error was: [_2].",$newfile,$result);
1.46 raeburn 3530: }
3531: }
3532: return ($url,$error);
3533: }
1.43 raeburn 3534:
1.49 raeburn 3535: sub print_coursecategories {
1.57 raeburn 3536: my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;
3537: my $datatable;
3538: if ($position eq 'top') {
3539: my $toggle_cats_crs = ' ';
3540: my $toggle_cats_dom = ' checked="checked" ';
3541: my $can_cat_crs = ' ';
3542: my $can_cat_dom = ' checked="checked" ';
1.120 raeburn 3543: my $toggle_catscomm_comm = ' ';
3544: my $toggle_catscomm_dom = ' checked="checked" ';
3545: my $can_catcomm_comm = ' ';
3546: my $can_catcomm_dom = ' checked="checked" ';
3547:
1.57 raeburn 3548: if (ref($settings) eq 'HASH') {
3549: if ($settings->{'togglecats'} eq 'crs') {
3550: $toggle_cats_crs = $toggle_cats_dom;
3551: $toggle_cats_dom = ' ';
3552: }
3553: if ($settings->{'categorize'} eq 'crs') {
3554: $can_cat_crs = $can_cat_dom;
3555: $can_cat_dom = ' ';
3556: }
1.120 raeburn 3557: if ($settings->{'togglecatscomm'} eq 'comm') {
3558: $toggle_catscomm_comm = $toggle_catscomm_dom;
3559: $toggle_catscomm_dom = ' ';
3560: }
3561: if ($settings->{'categorizecomm'} eq 'comm') {
3562: $can_catcomm_comm = $can_catcomm_dom;
3563: $can_catcomm_dom = ' ';
3564: }
1.57 raeburn 3565: }
3566: my %title = &Apache::lonlocal::texthash (
1.120 raeburn 3567: togglecats => 'Show/Hide a course in catalog',
3568: togglecatscomm => 'Show/Hide a community in catalog',
3569: categorize => 'Assign a category to a course',
3570: categorizecomm => 'Assign a category to a community',
1.57 raeburn 3571: );
3572: my %level = &Apache::lonlocal::texthash (
1.120 raeburn 3573: dom => 'Set in Domain',
3574: crs => 'Set in Course',
3575: comm => 'Set in Community',
1.57 raeburn 3576: );
3577: $datatable = '<tr class="LC_odd_row">'.
3578: '<td>'.$title{'togglecats'}.'</td>'.
3579: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3580: '<input type="radio" name="togglecats"'.
3581: $toggle_cats_dom.' value="dom" />'.$level{'dom'}.'</label> '.
3582: '<label><input type="radio" name="togglecats"'.
3583: $toggle_cats_crs.' value="crs" />'.$level{'crs'}.'</label></span></td>'.
3584: '</tr><tr>'.
3585: '<td>'.$title{'categorize'}.'</td>'.
3586: '<td class="LC_right_item"><span class="LC_nobreak">'.
3587: '<label><input type="radio" name="categorize"'.
3588: $can_cat_dom.' value="dom" />'.$level{'dom'}.'</label> '.
3589: '<label><input type="radio" name="categorize"'.
3590: $can_cat_crs.'value="crs" />'.$level{'crs'}.'</label></span></td>'.
1.120 raeburn 3591: '</tr><tr class="LC_odd_row">'.
3592: '<td>'.$title{'togglecatscomm'}.'</td>'.
3593: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3594: '<input type="radio" name="togglecatscomm"'.
3595: $toggle_catscomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
3596: '<label><input type="radio" name="togglecatscomm"'.
3597: $toggle_catscomm_comm.' value="comm" />'.$level{'comm'}.'</label></span></td>'.
3598: '</tr><tr>'.
3599: '<td>'.$title{'categorizecomm'}.'</td>'.
3600: '<td class="LC_right_item"><span class="LC_nobreak">'.
3601: '<label><input type="radio" name="categorizecomm"'.
3602: $can_catcomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
3603: '<label><input type="radio" name="categorizecomm"'.
3604: $can_catcomm_comm.'value="comm" />'.$level{'comm'}.'</label></span></td>'.
1.57 raeburn 3605: '</tr>';
1.120 raeburn 3606: $$rowtotal += 4;
1.57 raeburn 3607: } else {
3608: my $css_class;
3609: my $itemcount = 1;
3610: my $cathash;
3611: if (ref($settings) eq 'HASH') {
3612: $cathash = $settings->{'cats'};
3613: }
3614: if (ref($cathash) eq 'HASH') {
3615: my (@cats,@trails,%allitems,%idx,@jsarray);
3616: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
3617: \%allitems,\%idx,\@jsarray);
3618: my $maxdepth = scalar(@cats);
3619: my $colattrib = '';
3620: if ($maxdepth > 2) {
3621: $colattrib = ' colspan="2" ';
3622: }
3623: my @path;
3624: if (@cats > 0) {
3625: if (ref($cats[0]) eq 'ARRAY') {
3626: my $numtop = @{$cats[0]};
3627: my $maxnum = $numtop;
1.120 raeburn 3628: my %default_names = (
3629: instcode => &mt('Official courses'),
3630: communities => &mt('Communities'),
3631: );
3632:
3633: if ((!grep(/^instcode$/,@{$cats[0]})) ||
3634: ($cathash->{'instcode::0'} eq '') ||
3635: (!grep(/^communities$/,@{$cats[0]})) ||
3636: ($cathash->{'communities::0'} eq '')) {
1.57 raeburn 3637: $maxnum ++;
3638: }
3639: my $lastidx;
3640: for (my $i=0; $i<$numtop; $i++) {
3641: my $parent = $cats[0][$i];
3642: $css_class = $itemcount%2?' class="LC_odd_row"':'';
3643: my $item = &escape($parent).'::0';
3644: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$item','$idx{$item}'".');"';
3645: $lastidx = $idx{$item};
3646: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
3647: .'<select name="'.$item.'"'.$chgstr.'>';
3648: for (my $k=0; $k<=$maxnum; $k++) {
3649: my $vpos = $k+1;
3650: my $selstr;
3651: if ($k == $i) {
3652: $selstr = ' selected="selected" ';
3653: }
3654: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
3655: }
3656: $datatable .= '</select></td><td>';
1.120 raeburn 3657: if ($parent eq 'instcode' || $parent eq 'communities') {
3658: $datatable .= '<span class="LC_nobreak">'
3659: .$default_names{$parent}.'</span>';
3660: if ($parent eq 'instcode') {
3661: $datatable .= '<br /><span class="LC_nobreak">('
3662: .&mt('with institutional codes')
3663: .')</span></td><td'.$colattrib.'>';
3664: } else {
3665: $datatable .= '<table><tr><td>';
3666: }
3667: $datatable .= '<span class="LC_nobreak">'
3668: .'<label><input type="radio" name="'
3669: .$parent.'" value="1" checked="checked" />'
3670: .&mt('Display').'</label>';
3671: if ($parent eq 'instcode') {
3672: $datatable .= ' ';
3673: } else {
3674: $datatable .= '</span></td></tr><tr><td>'
3675: .'<span class="LC_nobreak">';
3676: }
3677: $datatable .= '<label><input type="radio" name="'
3678: .$parent.'" value="0" />'
3679: .&mt('Do not display').'</label></span>';
3680: if ($parent eq 'communities') {
3681: $datatable .= '</td></tr></table>';
3682: }
3683: $datatable .= '</td>';
1.57 raeburn 3684: } else {
3685: $datatable .= $parent
3686: .' <label><input type="checkbox" name="deletecategory" '
3687: .'value="'.$item.'" />'.&mt('Delete').'</label></span></td>';
3688: }
3689: my $depth = 1;
3690: push(@path,$parent);
3691: $datatable .= &build_category_rows($itemcount,\@cats,$depth,$parent,\@path,\%idx);
3692: pop(@path);
3693: $datatable .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
3694: $itemcount ++;
3695: }
1.48 raeburn 3696: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.57 raeburn 3697: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','$lastidx'".');"';
3698: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="addcategory_pos"'.$chgstr.'>';
1.48 raeburn 3699: for (my $k=0; $k<=$maxnum; $k++) {
3700: my $vpos = $k+1;
3701: my $selstr;
1.57 raeburn 3702: if ($k == $numtop) {
1.48 raeburn 3703: $selstr = ' selected="selected" ';
3704: }
3705: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
3706: }
1.59 bisitz 3707: $datatable .= '</select></span></td><td colspan="2">'.&mt('Add category:').' '
1.57 raeburn 3708: .'<input type="text" size="20" name="addcategory_name" value="" /></td>'
3709: .'</tr>'."\n";
1.48 raeburn 3710: $itemcount ++;
1.120 raeburn 3711: foreach my $default ('instcode','communities') {
3712: if ((!grep(/^\Q$default\E$/,@{$cats[0]})) || ($cathash->{$default.'::0'} eq '')) {
3713: $css_class = $itemcount%2?' class="LC_odd_row"':'';
3714: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','$lastidx'".');"';
3715: $datatable .= '<tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr><tr '.$css_class.'><td>'.
3716: '<span class="LC_nobreak"><select name="'.$default.'_pos"'.$chgstr.'>';
3717: for (my $k=0; $k<=$maxnum; $k++) {
3718: my $vpos = $k+1;
3719: my $selstr;
3720: if ($k == $maxnum) {
3721: $selstr = ' selected="selected" ';
3722: }
3723: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.57 raeburn 3724: }
1.120 raeburn 3725: $datatable .= '</select></span></td>'.
3726: '<td><span class="LC_nobreak">'.
3727: $default_names{$default}.'</span>';
3728: if ($default eq 'instcode') {
3729: $datatable .= '<br /><span class="LC_nobreak">('
3730: .&mt('with institutional codes').')</span>';
3731: }
3732: $datatable .= '</td>'
3733: .'<td><span class="LC_nobreak"><label><input type="radio" name="'.$default.'" value="1" />'
3734: .&mt('Display').'</label> '
3735: .'<label><input type="radio" name="'.$default.'" value="0" checked="checked"/>'
3736: .&mt('Do not display').'</label></span></td></tr>';
1.48 raeburn 3737: }
3738: }
3739: }
1.57 raeburn 3740: } else {
3741: $datatable .= &initialize_categories($itemcount);
1.48 raeburn 3742: }
3743: } else {
1.57 raeburn 3744: $datatable .= '<td class="LC_right_item">'.$hdritem->{'header'}->[0]->{'col2'}.'</td>'
3745: .&initialize_categories($itemcount);
1.48 raeburn 3746: }
1.57 raeburn 3747: $$rowtotal += $itemcount;
1.48 raeburn 3748: }
3749: return $datatable;
3750: }
3751:
1.69 raeburn 3752: sub print_serverstatuses {
3753: my ($dom,$settings,$rowtotal) = @_;
3754: my $datatable;
3755: my @pages = &serverstatus_pages();
3756: my (%namedaccess,%machineaccess);
3757: foreach my $type (@pages) {
3758: $namedaccess{$type} = '';
3759: $machineaccess{$type}= '';
3760: }
3761: if (ref($settings) eq 'HASH') {
3762: foreach my $type (@pages) {
3763: if (exists($settings->{$type})) {
3764: if (ref($settings->{$type}) eq 'HASH') {
3765: foreach my $key (keys(%{$settings->{$type}})) {
3766: if ($key eq 'namedusers') {
3767: $namedaccess{$type} = $settings->{$type}->{$key};
3768: } elsif ($key eq 'machines') {
3769: $machineaccess{$type} = $settings->{$type}->{$key};
3770: }
3771: }
3772: }
3773: }
3774: }
3775: }
1.81 raeburn 3776: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 3777: my $rownum = 0;
3778: my $css_class;
3779: foreach my $type (@pages) {
3780: $rownum ++;
3781: $css_class = $rownum%2?' class="LC_odd_row"':'';
3782: $datatable .= '<tr'.$css_class.'>'.
3783: '<td><span class="LC_nobreak">'.
3784: $titles->{$type}.'</span></td>'.
3785: '<td class="LC_left_item">'.
3786: '<input type="text" name="'.$type.'_namedusers" '.
3787: 'value="'.$namedaccess{$type}.'" size="30" /></td>'.
3788: '<td class="LC_right_item">'.
3789: '<span class="LC_nobreak">'.
3790: '<input type="text" name="'.$type.'_machines" '.
3791: 'value="'.$machineaccess{$type}.'" size="10" />'.
3792: '</td></tr>'."\n";
3793: }
3794: $$rowtotal += $rownum;
3795: return $datatable;
3796: }
3797:
3798: sub serverstatus_pages {
3799: return ('userstatus','lonstatus','loncron','server-status','codeversions',
3800: 'clusterstatus','metadata_keywords','metadata_harvest',
1.113 raeburn 3801: 'takeoffline','takeonline','showenv','toggledebug');
1.69 raeburn 3802: }
3803:
1.49 raeburn 3804: sub coursecategories_javascript {
3805: my ($settings) = @_;
1.57 raeburn 3806: my ($output,$jstext,$cathash);
1.49 raeburn 3807: if (ref($settings) eq 'HASH') {
1.57 raeburn 3808: $cathash = $settings->{'cats'};
3809: }
3810: if (ref($cathash) eq 'HASH') {
1.49 raeburn 3811: my (@cats,@jsarray,%idx);
1.57 raeburn 3812: &Apache::loncommon::gather_categories($cathash,\@cats,\%idx,\@jsarray);
1.49 raeburn 3813: if (@jsarray > 0) {
3814: $jstext = ' var categories = Array('.scalar(@jsarray).');'."\n";
3815: for (my $i=0; $i<@jsarray; $i++) {
3816: if (ref($jsarray[$i]) eq 'ARRAY') {
3817: my $catstr = join('","',@{$jsarray[$i]});
3818: $jstext .= ' categories['.$i.'] = Array("'.$catstr.'");'."\n";
3819: }
3820: }
3821: }
3822: } else {
3823: $jstext = ' var categories = Array(1);'."\n".
3824: ' categories[0] = Array("instcode_pos");'."\n";
3825: }
1.120 raeburn 3826: my $instcode_reserved = &mt('The name: "instcode" is a reserved category');
3827: my $communities_reserved = &mt('The name: "communities" is a reserved category');
3828: my $choose_again = '\\n'.&mt('Please use a different name for the new top level category');
1.49 raeburn 3829: $output = <<"ENDSCRIPT";
3830: <script type="text/javascript">
1.109 raeburn 3831: // <![CDATA[
1.49 raeburn 3832: function reorderCats(form,parent,item,idx) {
3833: var changedVal;
3834: $jstext
3835: var newpos = 'addcategory_pos';
3836: var current = new Array;
3837: if (parent == '') {
3838: var has_instcode = 0;
3839: var maxtop = categories[idx].length;
3840: for (var j=0; j<maxtop; j++) {
3841: if (categories[idx][j] == 'instcode::0') {
3842: has_instcode == 1;
3843: }
3844: }
3845: if (has_instcode == 0) {
3846: categories[idx][maxtop] = 'instcode_pos';
3847: }
3848: } else {
3849: newpos += '_'+parent;
3850: }
3851: var maxh = 1 + categories[idx].length;
3852: var current = new Array;
3853: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
3854: if (item == newpos) {
3855: changedVal = newitemVal;
3856: } else {
3857: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
3858: current[newitemVal] = newpos;
3859: }
3860: for (var i=0; i<categories[idx].length; i++) {
3861: var elementName = categories[idx][i];
3862: if (elementName != item) {
3863: if (form.elements[elementName]) {
3864: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
3865: current[currVal] = elementName;
3866: }
3867: }
3868: }
3869: var oldVal;
3870: for (var j=0; j<maxh; j++) {
3871: if (current[j] == undefined) {
3872: oldVal = j;
3873: }
3874: }
3875: if (oldVal < changedVal) {
3876: for (var k=oldVal+1; k<=changedVal ; k++) {
3877: var elementName = current[k];
3878: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
3879: }
3880: } else {
3881: for (var k=changedVal; k<oldVal; k++) {
3882: var elementName = current[k];
3883: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
3884: }
3885: }
3886: return;
3887: }
1.120 raeburn 3888:
3889: function categoryCheck(form) {
3890: if (form.elements['addcategory_name'].value == 'instcode') {
3891: alert('$instcode_reserved\\n$choose_again');
3892: return false;
3893: }
3894: if (form.elements['addcategory_name'].value == 'communities') {
3895: alert('$communities_reserved\\n$choose_again');
3896: return false;
3897: }
3898: return true;
3899: }
3900:
1.109 raeburn 3901: // ]]>
1.49 raeburn 3902: </script>
3903:
3904: ENDSCRIPT
3905: return $output;
3906: }
3907:
1.48 raeburn 3908: sub initialize_categories {
3909: my ($itemcount) = @_;
1.120 raeburn 3910: my ($datatable,$css_class,$chgstr);
3911: my %default_names = (
3912: instcode => 'Official courses (with institutional codes)',
3913: communities => 'Communities',
3914: );
3915: my $select0 = ' selected="selected"';
3916: my $select1 = '';
3917: foreach my $default ('instcode','communities') {
3918: $css_class = $itemcount%2?' class="LC_odd_row"':'';
3919: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'',$default"."_pos','0'".');"';
3920: if ($default eq 'communities') {
3921: $select1 = $select0;
3922: $select0 = '';
3923: }
3924: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
3925: .'<select name="'.$default.'_pos">'
3926: .'<option value="0"'.$select0.'>1</option>'
3927: .'<option value="1"'.$select1.'>2</option>'
3928: .'<option value="2">3</option></select> '
3929: .$default_names{$default}
3930: .'</span></td><td><span class="LC_nobreak">'
3931: .'<label><input type="radio" name="'.$default.'" value="1" checked="checked" />'
3932: .&mt('Display').'</label> <label>'
3933: .'<input type="radio" name="'.$default.'" value="0" />'.&mt('Do not display')
1.48 raeburn 3934: .'</label></span></td></tr>';
1.120 raeburn 3935: $itemcount ++;
3936: }
1.48 raeburn 3937: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.49 raeburn 3938: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','0'".');"';
1.48 raeburn 3939: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.120 raeburn 3940: .'<select name="addcategory_pos"'.$chgstr.'>'
3941: .'<option value="0">1</option>'
3942: .'<option value="1">2</option>'
3943: .'<option value="2" selected="selected">3</option></select> '
1.48 raeburn 3944: .&mt('Add category').'</td><td>'.&mt('Name:')
3945: .' <input type="text" size="20" name="addcategory_name" value="" /></td></tr>';
3946: return $datatable;
3947: }
3948:
3949: sub build_category_rows {
1.49 raeburn 3950: my ($itemcount,$cats,$depth,$parent,$path,$idx) = @_;
3951: my ($text,$name,$item,$chgstr);
1.48 raeburn 3952: if (ref($cats) eq 'ARRAY') {
3953: my $maxdepth = scalar(@{$cats});
3954: if (ref($cats->[$depth]) eq 'HASH') {
3955: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
3956: my $numchildren = @{$cats->[$depth]{$parent}};
3957: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
3958: $text .= '<td><table class="LC_datatable">';
1.49 raeburn 3959: my ($idxnum,$parent_name,$parent_item);
3960: my $higher = $depth - 1;
3961: if ($higher == 0) {
3962: $parent_name = &escape($parent).'::'.$higher;
3963: } else {
3964: if (ref($path) eq 'ARRAY') {
3965: $parent_name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
3966: }
3967: }
3968: $parent_item = 'addcategory_pos_'.$parent_name;
1.48 raeburn 3969: for (my $j=0; $j<=$numchildren; $j++) {
1.49 raeburn 3970: if ($j < $numchildren) {
1.48 raeburn 3971: $name = $cats->[$depth]{$parent}[$j];
3972: $item = &escape($name).':'.&escape($parent).':'.$depth;
1.49 raeburn 3973: $idxnum = $idx->{$item};
3974: } else {
3975: $name = $parent_name;
3976: $item = $parent_item;
1.48 raeburn 3977: }
1.49 raeburn 3978: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'$parent_name','$item','$idxnum'".');"';
3979: $text .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="'.$item.'"'.$chgstr.'>';
1.48 raeburn 3980: for (my $i=0; $i<=$numchildren; $i++) {
3981: my $vpos = $i+1;
3982: my $selstr;
3983: if ($j == $i) {
3984: $selstr = ' selected="selected" ';
3985: }
3986: $text .= '<option value="'.$i.'"'.$selstr.'>'.$vpos.'</option>';
3987: }
3988: $text .= '</select> ';
3989: if ($j < $numchildren) {
3990: my $deeper = $depth+1;
3991: $text .= $name.' '
3992: .'<label><input type="checkbox" name="deletecategory" value="'
3993: .$item.'" />'.&mt('Delete').'</label></span></td><td>';
3994: if(ref($path) eq 'ARRAY') {
3995: push(@{$path},$name);
1.49 raeburn 3996: $text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path,$idx);
1.48 raeburn 3997: pop(@{$path});
3998: }
3999: } else {
1.59 bisitz 4000: $text .= &mt('Add subcategory:').' </span><input type="textbox" size="20" name="addcategory_name_';
1.48 raeburn 4001: if ($j == $numchildren) {
4002: $text .= $name;
4003: } else {
4004: $text .= $item;
4005: }
4006: $text .= '" value="" />';
4007: }
4008: $text .= '</td></tr>';
4009: }
4010: $text .= '</table></td>';
4011: } else {
4012: my $higher = $depth-1;
4013: if ($higher == 0) {
4014: $name = &escape($parent).'::'.$higher;
4015: } else {
4016: if (ref($path) eq 'ARRAY') {
4017: $name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
4018: }
4019: }
4020: my $colspan;
4021: if ($parent ne 'instcode') {
4022: $colspan = $maxdepth - $depth - 1;
4023: $text .= '<td colspan="'.$colspan.'">'.&mt('Add subcategory:').'<input type="textbox" size="20" name="subcat_'.$name.'" value="" /></td>';
4024: }
4025: }
4026: }
4027: }
4028: return $text;
4029: }
4030:
1.33 raeburn 4031: sub modifiable_userdata_row {
1.63 raeburn 4032: my ($context,$role,$settings,$numinrow,$rowcount,$usertypes) = @_;
1.33 raeburn 4033: my $rolename;
1.63 raeburn 4034: if ($context eq 'selfcreate') {
4035: if (ref($usertypes) eq 'HASH') {
4036: $rolename = $usertypes->{$role};
4037: } else {
4038: $rolename = $role;
4039: }
1.33 raeburn 4040: } else {
1.63 raeburn 4041: if ($role eq 'cr') {
4042: $rolename = &mt('Custom role');
4043: } else {
4044: $rolename = &Apache::lonnet::plaintext($role);
4045: }
1.33 raeburn 4046: }
4047: my @fields = ('lastname','firstname','middlename','generation',
4048: 'permanentemail','id');
4049: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
4050: my $output;
4051: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
4052: $output = '<tr '.$css_class.'>'.
4053: '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
4054: '<td class="LC_left_item" colspan="2"><table>';
4055: my $rem;
4056: my %checks;
4057: if (ref($settings) eq 'HASH') {
4058: if (ref($settings->{$context}) eq 'HASH') {
4059: if (ref($settings->{$context}->{$role}) eq 'HASH') {
4060: foreach my $field (@fields) {
4061: if ($settings->{$context}->{$role}->{$field}) {
4062: $checks{$field} = ' checked="checked" ';
4063: }
4064: }
4065: }
4066: }
4067: }
4068: for (my $i=0; $i<@fields; $i++) {
4069: my $rem = $i%($numinrow);
4070: if ($rem == 0) {
4071: if ($i > 0) {
4072: $output .= '</tr>';
4073: }
4074: $output .= '<tr>';
4075: }
4076: my $check = ' ';
4077: if (exists($checks{$fields[$i]})) {
4078: $check = $checks{$fields[$i]}
4079: } else {
4080: if ($role eq 'st') {
4081: if (ref($settings) ne 'HASH') {
4082: $check = ' checked="checked" ';
4083: }
4084: }
4085: }
4086: $output .= '<td class="LC_left_item">'.
4087: '<span class="LC_nobreak"><label>'.
4088: '<input type="checkbox" name="canmodify_'.$role.'" '.
4089: 'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
4090: '</label></span></td>';
4091: $rem = @fields%($numinrow);
4092: }
4093: my $colsleft = $numinrow - $rem;
4094: if ($colsleft > 1 ) {
4095: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
4096: ' </td>';
4097: } elsif ($colsleft == 1) {
4098: $output .= '<td class="LC_left_item"> </td>';
4099: }
4100: $output .= '</tr></table></td></tr>';
4101: return $output;
4102: }
1.28 raeburn 4103:
1.93 raeburn 4104: sub insttypes_row {
4105: my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle,$context) = @_;
4106: my %lt = &Apache::lonlocal::texthash (
4107: cansearch => 'Users allowed to search',
4108: statustocreate => 'Institutional affiliation(s) able to create own account (login/SSO)',
1.131 raeburn 4109: lockablenames => 'User preference to lock name',
1.93 raeburn 4110: );
4111: my $showdom;
4112: if ($context eq 'cansearch') {
4113: $showdom = ' ('.$dom.')';
4114: }
1.25 raeburn 4115: my $output = '<tr class="LC_odd_row">'.
1.93 raeburn 4116: '<td>'.$lt{$context}.$showdom.
1.24 raeburn 4117: '</td><td class="LC_left_item" colspan="2"><table>';
1.26 raeburn 4118: my $rem;
4119: if (ref($types) eq 'ARRAY') {
4120: for (my $i=0; $i<@{$types}; $i++) {
4121: if (defined($usertypes->{$types->[$i]})) {
4122: my $rem = $i%($numinrow);
4123: if ($rem == 0) {
4124: if ($i > 0) {
4125: $output .= '</tr>';
4126: }
4127: $output .= '<tr>';
1.23 raeburn 4128: }
1.26 raeburn 4129: my $check = ' ';
1.99 raeburn 4130: if (ref($settings) eq 'HASH') {
4131: if (ref($settings->{$context}) eq 'ARRAY') {
4132: if (grep(/^\Q$types->[$i]\E$/,@{$settings->{$context}})) {
4133: $check = ' checked="checked" ';
4134: }
4135: } elsif ($context eq 'statustocreate') {
1.26 raeburn 4136: $check = ' checked="checked" ';
4137: }
1.23 raeburn 4138: }
1.26 raeburn 4139: $output .= '<td class="LC_left_item">'.
4140: '<span class="LC_nobreak"><label>'.
1.93 raeburn 4141: '<input type="checkbox" name="'.$context.'" '.
1.26 raeburn 4142: 'value="'.$types->[$i].'"'.$check.'/>'.
4143: $usertypes->{$types->[$i]}.'</label></span></td>';
1.23 raeburn 4144: }
4145: }
1.26 raeburn 4146: $rem = @{$types}%($numinrow);
1.23 raeburn 4147: }
4148: my $colsleft = $numinrow - $rem;
1.131 raeburn 4149: if (($rem == 0) && (@{$types} > 0)) {
4150: $output .= '<tr>';
4151: }
1.23 raeburn 4152: if ($colsleft > 1) {
1.25 raeburn 4153: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
1.23 raeburn 4154: } else {
1.25 raeburn 4155: $output .= '<td class="LC_left_item">';
1.23 raeburn 4156: }
4157: my $defcheck = ' ';
1.99 raeburn 4158: if (ref($settings) eq 'HASH') {
4159: if (ref($settings->{$context}) eq 'ARRAY') {
4160: if (grep(/^default$/,@{$settings->{$context}})) {
4161: $defcheck = ' checked="checked" ';
4162: }
4163: } elsif ($context eq 'statustocreate') {
1.26 raeburn 4164: $defcheck = ' checked="checked" ';
4165: }
1.23 raeburn 4166: }
1.25 raeburn 4167: $output .= '<span class="LC_nobreak"><label>'.
1.93 raeburn 4168: '<input type="checkbox" name="'.$context.'" '.
1.25 raeburn 4169: 'value="default"'.$defcheck.'/>'.
4170: $othertitle.'</label></span></td>'.
4171: '</tr></table></td></tr>';
4172: return $output;
1.23 raeburn 4173: }
4174:
4175: sub sorted_searchtitles {
4176: my %searchtitles = &Apache::lonlocal::texthash(
4177: 'uname' => 'username',
4178: 'lastname' => 'last name',
4179: 'lastfirst' => 'last name, first name',
4180: );
4181: my @titleorder = ('uname','lastname','lastfirst');
4182: return (\%searchtitles,\@titleorder);
4183: }
4184:
1.25 raeburn 4185: sub sorted_searchtypes {
4186: my %srchtypes_desc = (
4187: exact => 'is exact match',
4188: contains => 'contains ..',
4189: begins => 'begins with ..',
4190: );
4191: my @srchtypeorder = ('exact','begins','contains');
4192: return (\%srchtypes_desc,\@srchtypeorder);
4193: }
4194:
1.3 raeburn 4195: sub usertype_update_row {
4196: my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
4197: my $datatable;
4198: my $numinrow = 4;
4199: foreach my $type (@{$types}) {
4200: if (defined($usertypes->{$type})) {
4201: $$rownums ++;
4202: my $css_class = $$rownums%2?' class="LC_odd_row"':'';
4203: $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
4204: '</td><td class="LC_left_item"><table>';
4205: for (my $i=0; $i<@{$fields}; $i++) {
4206: my $rem = $i%($numinrow);
4207: if ($rem == 0) {
4208: if ($i > 0) {
4209: $datatable .= '</tr>';
4210: }
4211: $datatable .= '<tr>';
4212: }
4213: my $check = ' ';
1.39 raeburn 4214: if (ref($settings) eq 'HASH') {
4215: if (ref($settings->{'fields'}) eq 'HASH') {
4216: if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
4217: if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
4218: $check = ' checked="checked" ';
4219: }
1.3 raeburn 4220: }
4221: }
4222: }
4223:
4224: if ($i == @{$fields}-1) {
4225: my $colsleft = $numinrow - $rem;
4226: if ($colsleft > 1) {
4227: $datatable .= '<td colspan="'.$colsleft.'">';
4228: } else {
4229: $datatable .= '<td>';
4230: }
4231: } else {
4232: $datatable .= '<td>';
4233: }
1.8 raeburn 4234: $datatable .= '<span class="LC_nobreak"><label>'.
4235: '<input type="checkbox" name="updateable_'.$type.
4236: '_'.$fields->[$i].'" value="1"'.$check.'/>'.
4237: $fieldtitles->{$fields->[$i]}.'</label></span></td>';
1.3 raeburn 4238: }
4239: $datatable .= '</tr></table></td></tr>';
4240: }
4241: }
4242: return $datatable;
1.1 raeburn 4243: }
4244:
4245: sub modify_login {
1.9 raeburn 4246: my ($r,$dom,$confname,%domconfig) = @_;
1.6 raeburn 4247: my ($resulttext,$errors,$colchgtext,%changes,%colchanges);
1.1 raeburn 4248: my %title = ( coursecatalog => 'Display course catalog',
1.41 raeburn 4249: adminmail => 'Display administrator E-mail address',
1.43 raeburn 4250: newuser => 'Link for visitors to create a user account',
1.41 raeburn 4251: loginheader => 'Log-in box header');
1.3 raeburn 4252: my @offon = ('off','on');
1.112 raeburn 4253: my %curr_loginvia;
4254: if (ref($domconfig{login}) eq 'HASH') {
4255: if (ref($domconfig{login}{loginvia}) eq 'HASH') {
4256: foreach my $lonhost (keys(%{$domconfig{login}{loginvia}})) {
4257: $curr_loginvia{$lonhost} = $domconfig{login}{loginvia}{$lonhost};
4258: }
4259: }
4260: }
1.6 raeburn 4261: my %loginhash;
1.9 raeburn 4262: ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
4263: \%domconfig,\%loginhash);
1.118 jms 4264: my @toggles = ('coursecatalog','adminmail','newuser');
1.42 raeburn 4265: foreach my $item (@toggles) {
4266: $loginhash{login}{$item} = $env{'form.'.$item};
4267: }
1.41 raeburn 4268: $loginhash{login}{loginheader} = $env{'form.loginheader'};
1.6 raeburn 4269: if (ref($colchanges{'login'}) eq 'HASH') {
4270: $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
4271: \%loginhash);
4272: }
1.110 raeburn 4273:
1.149 raeburn 4274: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.128 raeburn 4275: my @loginvia_attribs = ('serverpath','custompath','exempt');
1.110 raeburn 4276: if (keys(%servers) > 1) {
4277: foreach my $lonhost (keys(%servers)) {
1.128 raeburn 4278: next if ($env{'form.'.$lonhost.'_server'} eq $lonhost);
4279: if (ref($curr_loginvia{$lonhost}) eq 'HASH') {
4280: if ($env{'form.'.$lonhost.'_server'} eq $curr_loginvia{$lonhost}{'server'}) {
4281: $loginhash{login}{loginvia}{$lonhost}{'server'} = $curr_loginvia{$lonhost}{'server'};
4282: } elsif ($curr_loginvia{$lonhost}{'server'} ne '') {
4283: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
4284: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
4285: $changes{'loginvia'}{$lonhost} = 1;
4286: } else {
4287: $loginhash{login}{loginvia}{$lonhost}{'server'} = '';
4288: $changes{'loginvia'}{$lonhost} = 1;
4289: }
4290: } else {
4291: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
4292: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
4293: $changes{'loginvia'}{$lonhost} = 1;
4294: }
4295: }
4296: if ($loginhash{login}{loginvia}{$lonhost}{'server'} eq '') {
4297: foreach my $item (@loginvia_attribs) {
4298: $loginhash{login}{loginvia}{$lonhost}{$item} = '';
4299: }
4300: } else {
4301: foreach my $item (@loginvia_attribs) {
4302: my $new = $env{'form.'.$lonhost.'_'.$item};
4303: if (($item eq 'serverpath') && ($new eq 'custom')) {
4304: $env{'form.'.$lonhost.'_custompath'} =~ s/\s+//g;
4305: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
4306: $new = '/';
4307: }
4308: }
4309: if (($item eq 'custompath') &&
4310: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
4311: $new = '';
4312: }
4313: if ($new ne $curr_loginvia{$lonhost}{$item}) {
4314: $changes{'loginvia'}{$lonhost} = 1;
4315: }
4316: if ($item eq 'exempt') {
4317: $new =~ s/^\s+//;
4318: $new =~ s/\s+$//;
4319: my @poss_ips = split(/\s*[,:]\s*/,$new);
4320: my @okips;
4321: foreach my $ip (@poss_ips) {
4322: if ($ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
4323: if (($1 <= 255) && ($2 <= 255) && ($3 <= 255) && ($4 <= 255)) {
4324: push(@okips,$ip);
4325: }
4326: }
4327: }
4328: if (@okips > 0) {
4329: $new = join(',',@okips);
4330: } else {
4331: $new = '';
4332: }
4333: }
4334:
4335: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
4336: }
4337: }
1.112 raeburn 4338: } else {
1.128 raeburn 4339: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
4340: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
1.112 raeburn 4341: $changes{'loginvia'}{$lonhost} = 1;
1.128 raeburn 4342: foreach my $item (@loginvia_attribs) {
4343: my $new = $env{'form.'.$lonhost.'_'.$item};
4344: if (($item eq 'serverpath') && ($new eq 'custom')) {
4345: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
4346: $new = '/';
4347: }
4348: }
4349: if (($item eq 'custompath') &&
4350: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
4351: $new = '';
4352: }
4353: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
4354: }
1.110 raeburn 4355: }
4356: }
4357: }
4358: }
1.119 raeburn 4359:
1.1 raeburn 4360: my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
4361: $dom);
4362: if ($putresult eq 'ok') {
1.118 jms 4363: my @toggles = ('coursecatalog','adminmail','newuser');
1.42 raeburn 4364: my %defaultchecked = (
4365: 'coursecatalog' => 'on',
4366: 'adminmail' => 'off',
1.43 raeburn 4367: 'newuser' => 'off',
1.42 raeburn 4368: );
1.55 raeburn 4369: if (ref($domconfig{'login'}) eq 'HASH') {
4370: foreach my $item (@toggles) {
4371: if ($defaultchecked{$item} eq 'on') {
4372: if (($domconfig{'login'}{$item} eq '0') &&
4373: ($env{'form.'.$item} eq '1')) {
4374: $changes{$item} = 1;
4375: } elsif (($domconfig{'login'}{$item} eq '' ||
4376: $domconfig{'login'}{$item} eq '1') &&
4377: ($env{'form.'.$item} eq '0')) {
4378: $changes{$item} = 1;
4379: }
4380: } elsif ($defaultchecked{$item} eq 'off') {
4381: if (($domconfig{'login'}{$item} eq '1') &&
4382: ($env{'form.'.$item} eq '0')) {
4383: $changes{$item} = 1;
4384: } elsif (($domconfig{'login'}{$item} eq '' ||
4385: $domconfig{'login'}{$item} eq '0') &&
4386: ($env{'form.'.$item} eq '1')) {
4387: $changes{$item} = 1;
4388: }
1.42 raeburn 4389: }
4390: }
1.41 raeburn 4391: }
1.6 raeburn 4392: if (keys(%changes) > 0 || $colchgtext) {
1.41 raeburn 4393: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.1 raeburn 4394: $resulttext = &mt('Changes made:').'<ul>';
4395: foreach my $item (sort(keys(%changes))) {
1.135 bisitz 4396: if ($item eq 'loginvia') {
1.112 raeburn 4397: if (ref($changes{$item}) eq 'HASH') {
4398: $resulttext .= '<li>'.&mt('Log-in page availability:').'<ul>';
4399: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
1.128 raeburn 4400: if (defined($servers{$loginhash{login}{loginvia}{$lonhost}{'server'}})) {
4401: if (ref($loginhash{login}{loginvia}{$lonhost}) eq 'HASH') {
4402: my $protocol = $Apache::lonnet::protocol{$env{'form.'.$lonhost.'_server'}};
4403: $protocol = 'http' if ($protocol ne 'https');
4404: my $target = $protocol.'://'.$servers{$env{'form.'.$lonhost.'_server'}};
4405:
4406: if ($loginhash{login}{loginvia}{$lonhost}{'serverpath'} eq 'custom') {
4407: $target .= $loginhash{login}{loginvia}{$lonhost}{'custompath'};
4408: } else {
4409: $target .= $loginhash{login}{loginvia}{$lonhost}{'serverpath'};
4410: }
4411: $resulttext .= '<li>'.&mt('Server: [_1] log-in page redirects to [_2].',$servers{$lonhost},'<a href="'.$target.'">'.$target.'</a>');
4412: if ($loginhash{login}{loginvia}{$lonhost}{'exempt'} ne '') {
4413: $resulttext .= ' '.&mt('No redirection for clients from following IPs:').' '.$loginhash{login}{loginvia}{$lonhost}{'exempt'};
4414: }
4415: $resulttext .= '</li>';
4416: } else {
4417: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$lonhost).'</li>';
4418: }
1.112 raeburn 4419: } else {
1.128 raeburn 4420: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$servers{$lonhost}).'</li>';
1.112 raeburn 4421: }
4422: }
1.128 raeburn 4423: $resulttext .= '</ul></li>';
1.112 raeburn 4424: }
1.41 raeburn 4425: } else {
4426: $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
4427: }
1.1 raeburn 4428: }
1.6 raeburn 4429: $resulttext .= $colchgtext.'</ul>';
1.1 raeburn 4430: } else {
4431: $resulttext = &mt('No changes made to log-in page settings');
4432: }
4433: } else {
1.11 albertel 4434: $resulttext = '<span class="LC_error">'.
4435: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 4436: }
1.6 raeburn 4437: if ($errors) {
1.9 raeburn 4438: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.6 raeburn 4439: $errors.'</ul>';
4440: }
4441: return $resulttext;
4442: }
4443:
4444: sub color_font_choices {
4445: my %choices =
4446: &Apache::lonlocal::texthash (
4447: img => "Header",
4448: bgs => "Background colors",
4449: links => "Link colors",
1.55 raeburn 4450: images => "Images",
1.6 raeburn 4451: font => "Font color",
1.97 tempelho 4452: fontmenu => "Font Menu",
1.76 raeburn 4453: pgbg => "Page",
1.6 raeburn 4454: tabbg => "Header",
4455: sidebg => "Border",
4456: link => "Link",
4457: alink => "Active link",
4458: vlink => "Visited link",
4459: );
4460: return %choices;
4461: }
4462:
4463: sub modify_rolecolors {
1.9 raeburn 4464: my ($r,$dom,$confname,$roles,%domconfig) = @_;
1.6 raeburn 4465: my ($resulttext,%rolehash);
4466: $rolehash{'rolecolors'} = {};
1.55 raeburn 4467: if (ref($domconfig{'rolecolors'}) ne 'HASH') {
4468: if ($domconfig{'rolecolors'} eq '') {
4469: $domconfig{'rolecolors'} = {};
4470: }
4471: }
1.9 raeburn 4472: my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
1.6 raeburn 4473: $domconfig{'rolecolors'},$rolehash{'rolecolors'});
4474: my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
4475: $dom);
4476: if ($putresult eq 'ok') {
4477: if (keys(%changes) > 0) {
1.41 raeburn 4478: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.6 raeburn 4479: $resulttext = &display_colorchgs($dom,\%changes,$roles,
4480: $rolehash{'rolecolors'});
4481: } else {
4482: $resulttext = &mt('No changes made to default color schemes');
4483: }
4484: } else {
1.11 albertel 4485: $resulttext = '<span class="LC_error">'.
4486: &mt('An error occurred: [_1]',$putresult).'</span>';
1.6 raeburn 4487: }
4488: if ($errors) {
4489: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
4490: $errors.'</ul>';
4491: }
4492: return $resulttext;
4493: }
4494:
4495: sub modify_colors {
1.9 raeburn 4496: my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
1.12 raeburn 4497: my (%changes,%choices);
1.51 raeburn 4498: my @bgs;
1.6 raeburn 4499: my @links = ('link','alink','vlink');
1.41 raeburn 4500: my @logintext;
1.6 raeburn 4501: my @images;
4502: my $servadm = $r->dir_config('lonAdmEMail');
4503: my $errors;
4504: foreach my $role (@{$roles}) {
4505: if ($role eq 'login') {
1.12 raeburn 4506: %choices = &login_choices();
1.41 raeburn 4507: @logintext = ('textcol','bgcol');
1.12 raeburn 4508: } else {
4509: %choices = &color_font_choices();
1.107 raeburn 4510: $confhash->{$role}{'fontmenu'} = $env{'form.'.$role.'_fontmenu'};
1.12 raeburn 4511: }
4512: if ($role eq 'login') {
1.41 raeburn 4513: @images = ('img','logo','domlogo','login');
1.51 raeburn 4514: @bgs = ('pgbg','mainbg','sidebg');
1.6 raeburn 4515: } else {
4516: @images = ('img');
1.51 raeburn 4517: @bgs = ('pgbg','tabbg','sidebg');
1.6 raeburn 4518: }
4519: $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
1.41 raeburn 4520: foreach my $item (@bgs,@links,@logintext) {
1.6 raeburn 4521: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
4522: }
1.46 raeburn 4523: my ($configuserok,$author_ok,$switchserver) =
4524: &config_check($dom,$confname,$servadm);
1.9 raeburn 4525: my ($width,$height) = &thumb_dimensions();
1.40 raeburn 4526: if (ref($domconfig->{$role}) ne 'HASH') {
4527: $domconfig->{$role} = {};
4528: }
1.8 raeburn 4529: foreach my $img (@images) {
1.70 raeburn 4530: if (($role eq 'login') && (($img eq 'img') || ($img eq 'logo'))) {
4531: if (defined($env{'form.login_showlogo_'.$img})) {
4532: $confhash->{$role}{'showlogo'}{$img} = 1;
4533: } else {
4534: $confhash->{$role}{'showlogo'}{$img} = 0;
4535: }
4536: }
1.18 albertel 4537: if ( ! $env{'form.'.$role.'_'.$img.'.filename'}
4538: && !defined($domconfig->{$role}{$img})
4539: && !$env{'form.'.$role.'_del_'.$img}
4540: && $env{'form.'.$role.'_import_'.$img}) {
4541: # import the old configured image from the .tab setting
4542: # if they haven't provided a new one
4543: $domconfig->{$role}{$img} =
4544: $env{'form.'.$role.'_import_'.$img};
4545: }
1.6 raeburn 4546: if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
1.9 raeburn 4547: my $error;
1.6 raeburn 4548: if ($configuserok eq 'ok') {
1.9 raeburn 4549: if ($switchserver) {
1.12 raeburn 4550: $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
1.9 raeburn 4551: } else {
4552: if ($author_ok eq 'ok') {
4553: my ($result,$logourl) =
4554: &publishlogo($r,'upload',$role.'_'.$img,
4555: $dom,$confname,$img,$width,$height);
4556: if ($result eq 'ok') {
4557: $confhash->{$role}{$img} = $logourl;
1.12 raeburn 4558: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 4559: } else {
1.12 raeburn 4560: $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 4561: }
4562: } else {
1.46 raeburn 4563: $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 4564: }
4565: }
4566: } else {
1.46 raeburn 4567: $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 4568: }
4569: if ($error) {
1.8 raeburn 4570: &Apache::lonnet::logthis($error);
1.11 albertel 4571: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
1.8 raeburn 4572: }
4573: } elsif ($domconfig->{$role}{$img} ne '') {
1.9 raeburn 4574: if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
4575: my $error;
4576: if ($configuserok eq 'ok') {
4577: # is confname an author?
4578: if ($switchserver eq '') {
4579: if ($author_ok eq 'ok') {
4580: my ($result,$logourl) =
4581: &publishlogo($r,'copy',$domconfig->{$role}{$img},
4582: $dom,$confname,$img,$width,$height);
4583: if ($result eq 'ok') {
4584: $confhash->{$role}{$img} = $logourl;
1.18 albertel 4585: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 4586: }
4587: }
4588: }
4589: }
1.6 raeburn 4590: }
4591: }
4592: }
4593: if (ref($domconfig) eq 'HASH') {
4594: if (ref($domconfig->{$role}) eq 'HASH') {
4595: foreach my $img (@images) {
4596: if ($domconfig->{$role}{$img} ne '') {
4597: if ($env{'form.'.$role.'_del_'.$img}) {
4598: $confhash->{$role}{$img} = '';
1.12 raeburn 4599: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 4600: } else {
1.9 raeburn 4601: if ($confhash->{$role}{$img} eq '') {
4602: $confhash->{$role}{$img} = $domconfig->{$role}{$img};
4603: }
1.6 raeburn 4604: }
4605: } else {
4606: if ($env{'form.'.$role.'_del_'.$img}) {
4607: $confhash->{$role}{$img} = '';
1.12 raeburn 4608: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 4609: }
4610: }
1.70 raeburn 4611: if (($role eq 'login') && (($img eq 'logo') || ($img eq 'img'))) {
4612: if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') {
4613: if ($confhash->{$role}{'showlogo'}{$img} ne
4614: $domconfig->{$role}{'showlogo'}{$img}) {
4615: $changes{$role}{'showlogo'}{$img} = 1;
4616: }
4617: } else {
4618: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
4619: $changes{$role}{'showlogo'}{$img} = 1;
4620: }
4621: }
4622: }
4623: }
1.6 raeburn 4624: if ($domconfig->{$role}{'font'} ne '') {
4625: if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
4626: $changes{$role}{'font'} = 1;
4627: }
4628: } else {
4629: if ($confhash->{$role}{'font'}) {
4630: $changes{$role}{'font'} = 1;
4631: }
4632: }
1.107 raeburn 4633: if ($role ne 'login') {
4634: if ($domconfig->{$role}{'fontmenu'} ne '') {
4635: if ($confhash->{$role}{'fontmenu'} ne $domconfig->{$role}{'fontmenu'}) {
4636: $changes{$role}{'fontmenu'} = 1;
4637: }
4638: } else {
4639: if ($confhash->{$role}{'fontmenu'}) {
4640: $changes{$role}{'fontmenu'} = 1;
4641: }
1.97 tempelho 4642: }
4643: }
1.6 raeburn 4644: foreach my $item (@bgs) {
4645: if ($domconfig->{$role}{$item} ne '') {
4646: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
4647: $changes{$role}{'bgs'}{$item} = 1;
4648: }
4649: } else {
4650: if ($confhash->{$role}{$item}) {
4651: $changes{$role}{'bgs'}{$item} = 1;
4652: }
4653: }
4654: }
4655: foreach my $item (@links) {
4656: if ($domconfig->{$role}{$item} ne '') {
4657: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
4658: $changes{$role}{'links'}{$item} = 1;
4659: }
4660: } else {
4661: if ($confhash->{$role}{$item}) {
4662: $changes{$role}{'links'}{$item} = 1;
4663: }
4664: }
4665: }
1.41 raeburn 4666: foreach my $item (@logintext) {
4667: if ($domconfig->{$role}{$item} ne '') {
4668: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
4669: $changes{$role}{'logintext'}{$item} = 1;
4670: }
4671: } else {
4672: if ($confhash->{$role}{$item}) {
4673: $changes{$role}{'logintext'}{$item} = 1;
4674: }
4675: }
4676: }
1.6 raeburn 4677: } else {
4678: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 4679: \@logintext,$confhash,\%changes);
1.6 raeburn 4680: }
4681: } else {
4682: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 4683: \@logintext,$confhash,\%changes);
1.6 raeburn 4684: }
4685: }
4686: return ($errors,%changes);
4687: }
4688:
1.46 raeburn 4689: sub config_check {
4690: my ($dom,$confname,$servadm) = @_;
4691: my ($configuserok,$author_ok,$switchserver,%currroles);
4692: my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
4693: ($configuserok,%currroles) = &check_configuser($uhome,$dom,
4694: $confname,$servadm);
4695: if ($configuserok eq 'ok') {
4696: $switchserver = &check_switchserver($dom,$confname);
4697: if ($switchserver eq '') {
4698: $author_ok = &check_authorstatus($dom,$confname,%currroles);
4699: }
4700: }
4701: return ($configuserok,$author_ok,$switchserver);
4702: }
4703:
1.6 raeburn 4704: sub default_change_checker {
1.41 raeburn 4705: my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
1.6 raeburn 4706: foreach my $item (@{$links}) {
4707: if ($confhash->{$role}{$item}) {
4708: $changes->{$role}{'links'}{$item} = 1;
4709: }
4710: }
4711: foreach my $item (@{$bgs}) {
4712: if ($confhash->{$role}{$item}) {
4713: $changes->{$role}{'bgs'}{$item} = 1;
4714: }
4715: }
1.41 raeburn 4716: foreach my $item (@{$logintext}) {
4717: if ($confhash->{$role}{$item}) {
4718: $changes->{$role}{'logintext'}{$item} = 1;
4719: }
4720: }
1.6 raeburn 4721: foreach my $img (@{$images}) {
4722: if ($env{'form.'.$role.'_del_'.$img}) {
4723: $confhash->{$role}{$img} = '';
1.12 raeburn 4724: $changes->{$role}{'images'}{$img} = 1;
1.6 raeburn 4725: }
1.70 raeburn 4726: if ($role eq 'login') {
4727: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
4728: $changes->{$role}{'showlogo'}{$img} = 1;
4729: }
4730: }
1.6 raeburn 4731: }
4732: if ($confhash->{$role}{'font'}) {
4733: $changes->{$role}{'font'} = 1;
4734: }
1.48 raeburn 4735: }
1.6 raeburn 4736:
4737: sub display_colorchgs {
4738: my ($dom,$changes,$roles,$confhash) = @_;
4739: my (%choices,$resulttext);
4740: if (!grep(/^login$/,@{$roles})) {
4741: $resulttext = &mt('Changes made:').'<br />';
4742: }
4743: foreach my $role (@{$roles}) {
4744: if ($role eq 'login') {
4745: %choices = &login_choices();
4746: } else {
4747: %choices = &color_font_choices();
4748: }
4749: if (ref($changes->{$role}) eq 'HASH') {
4750: if ($role ne 'login') {
4751: $resulttext .= '<h4>'.&mt($role).'</h4>';
4752: }
4753: foreach my $key (sort(keys(%{$changes->{$role}}))) {
4754: if ($role ne 'login') {
4755: $resulttext .= '<ul>';
4756: }
4757: if (ref($changes->{$role}{$key}) eq 'HASH') {
4758: if ($role ne 'login') {
4759: $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
4760: }
4761: foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
1.70 raeburn 4762: if (($role eq 'login') && ($key eq 'showlogo')) {
4763: if ($confhash->{$role}{$key}{$item}) {
4764: $resulttext .= '<li>'.&mt("$choices{$item} set to be displayed").'</li>';
4765: } else {
4766: $resulttext .= '<li>'.&mt("$choices{$item} set to not be displayed").'</li>';
4767: }
4768: } elsif ($confhash->{$role}{$item} eq '') {
1.6 raeburn 4769: $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
4770: } else {
1.12 raeburn 4771: my $newitem = $confhash->{$role}{$item};
4772: if ($key eq 'images') {
4773: $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" valign="bottom" />';
4774: }
4775: $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
1.6 raeburn 4776: }
4777: }
4778: if ($role ne 'login') {
4779: $resulttext .= '</ul></li>';
4780: }
4781: } else {
4782: if ($confhash->{$role}{$key} eq '') {
4783: $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
4784: } else {
4785: $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
4786: }
4787: }
4788: if ($role ne 'login') {
4789: $resulttext .= '</ul>';
4790: }
4791: }
4792: }
4793: }
1.3 raeburn 4794: return $resulttext;
1.1 raeburn 4795: }
4796:
1.9 raeburn 4797: sub thumb_dimensions {
4798: return ('200','50');
4799: }
4800:
1.16 raeburn 4801: sub check_dimensions {
4802: my ($inputfile) = @_;
4803: my ($fullwidth,$fullheight);
4804: if ($inputfile =~ m|^[/\w.\-]+$|) {
4805: if (open(PIPE,"identify $inputfile 2>&1 |")) {
4806: my $imageinfo = <PIPE>;
4807: if (!close(PIPE)) {
4808: &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
4809: }
4810: chomp($imageinfo);
4811: my ($fullsize) =
1.21 raeburn 4812: ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
1.16 raeburn 4813: if ($fullsize) {
4814: ($fullwidth,$fullheight) = split(/x/,$fullsize);
4815: }
4816: }
4817: }
4818: return ($fullwidth,$fullheight);
4819: }
4820:
1.9 raeburn 4821: sub check_configuser {
4822: my ($uhome,$dom,$confname,$servadm) = @_;
4823: my ($configuserok,%currroles);
4824: if ($uhome eq 'no_host') {
4825: srand( time() ^ ($$ + ($$ << 15)) ); # Seed rand.
4826: my $configpass = &LONCAPA::Enrollment::create_password();
4827: $configuserok =
4828: &Apache::lonnet::modifyuser($dom,$confname,'','internal',
4829: $configpass,'','','','','',undef,$servadm);
4830: } else {
4831: $configuserok = 'ok';
4832: %currroles =
4833: &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
4834: }
4835: return ($configuserok,%currroles);
4836: }
4837:
4838: sub check_authorstatus {
4839: my ($dom,$confname,%currroles) = @_;
4840: my $author_ok;
1.40 raeburn 4841: if (!$currroles{':'.$dom.':au'}) {
1.9 raeburn 4842: my $start = time;
4843: my $end = 0;
4844: $author_ok =
4845: &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
1.47 raeburn 4846: 'au',$end,$start,'','','domconfig');
1.9 raeburn 4847: } else {
4848: $author_ok = 'ok';
4849: }
4850: return $author_ok;
4851: }
4852:
4853: sub publishlogo {
1.46 raeburn 4854: my ($r,$action,$formname,$dom,$confname,$subdir,$thumbwidth,$thumbheight,$savefileas) = @_;
1.9 raeburn 4855: my ($output,$fname,$logourl);
4856: if ($action eq 'upload') {
4857: $fname=$env{'form.'.$formname.'.filename'};
4858: chop($env{'form.'.$formname});
4859: } else {
4860: ($fname) = ($formname =~ /([^\/]+)$/);
4861: }
1.46 raeburn 4862: if ($savefileas ne '') {
4863: $fname = $savefileas;
4864: }
1.9 raeburn 4865: $fname=&Apache::lonnet::clean_filename($fname);
4866: # See if there is anything left
4867: unless ($fname) { return ('error: no uploaded file'); }
4868: $fname="$subdir/$fname";
4869: my $filepath='/home/'.$confname.'/public_html';
4870: my ($fnamepath,$file,$fetchthumb);
4871: $file=$fname;
4872: if ($fname=~m|/|) {
4873: ($fnamepath,$file) = ($fname =~ m|^(.*)/([^/]+)$|);
4874: }
4875: my @parts=split(/\//,$filepath.'/'.$fnamepath);
4876: my $count;
4877: for ($count=4;$count<=$#parts;$count++) {
4878: $filepath.="/$parts[$count]";
4879: if ((-e $filepath)!=1) {
4880: mkdir($filepath,02770);
4881: }
4882: }
4883: # Check for bad extension and disallow upload
4884: if ($file=~/\.(\w+)$/ &&
4885: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
4886: $output =
4887: &mt('Invalid file extension ([_1]) - reserved for LONCAPA use.',$1);
4888: } elsif ($file=~/\.(\w+)$/ &&
4889: !defined(&Apache::loncommon::fileembstyle($1))) {
4890: $output = &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
4891: } elsif ($file=~/\.(\d+)\.(\w+)$/) {
1.46 raeburn 4892: $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 4893: } elsif (-d "$filepath/$file") {
4894: $output = &mt('File name is a directory name - rename the file and re-upload');
4895: } else {
4896: my $source = $filepath.'/'.$file;
4897: my $logfile;
4898: if (!open($logfile,">>$source".'.log')) {
4899: return (&mt('No write permission to Construction Space'));
4900: }
4901: print $logfile
4902: "\n================= Publish ".localtime()." ================\n".
4903: $env{'user.name'}.':'.$env{'user.domain'}."\n";
4904: # Save the file
4905: if (!open(FH,'>'.$source)) {
4906: &Apache::lonnet::logthis('Failed to create '.$source);
4907: return (&mt('Failed to create file'));
4908: }
4909: if ($action eq 'upload') {
4910: if (!print FH ($env{'form.'.$formname})) {
4911: &Apache::lonnet::logthis('Failed to write to '.$source);
4912: return (&mt('Failed to write file'));
4913: }
4914: } else {
4915: my $original = &Apache::lonnet::filelocation('',$formname);
4916: if(!copy($original,$source)) {
4917: &Apache::lonnet::logthis('Failed to copy '.$original.' to '.$source);
4918: return (&mt('Failed to write file'));
4919: }
4920: }
4921: close(FH);
4922: chmod(0660, $source); # Permissions to rw-rw---.
4923:
4924: my $docroot=$r->dir_config('lonDocRoot');
4925: my $targetdir=$docroot.'/res/'.$dom.'/'.$confname .'/'.$fnamepath;
4926: my $copyfile=$targetdir.'/'.$file;
4927:
4928: my @parts=split(/\//,$targetdir);
4929: my $path="/$parts[1]/$parts[2]/$parts[3]/$parts[4]";
4930: for (my $count=5;$count<=$#parts;$count++) {
4931: $path.="/$parts[$count]";
4932: if (!-e $path) {
4933: print $logfile "\nCreating directory ".$path;
4934: mkdir($path,02770);
4935: }
4936: }
4937: my $versionresult;
4938: if (-e $copyfile) {
4939: $versionresult = &logo_versioning($targetdir,$file,$logfile);
4940: } else {
4941: $versionresult = 'ok';
4942: }
4943: if ($versionresult eq 'ok') {
4944: if (copy($source,$copyfile)) {
4945: print $logfile "\nCopied original source to ".$copyfile."\n";
4946: $output = 'ok';
4947: &write_metadata($dom,$confname,$formname,$targetdir,$file,$logfile);
4948: $logourl = '/res/'.$dom.'/'.$confname.'/'.$fname;
4949: } else {
4950: print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";
4951: $output = &mt('Failed to copy file to RES space').", $!";
4952: }
4953: if (($thumbwidth =~ /^\d+$/) && ($thumbheight =~ /^\d+$/)) {
4954: my $inputfile = $filepath.'/'.$file;
4955: my $outfile = $filepath.'/'.'tn-'.$file;
1.16 raeburn 4956: my ($fullwidth,$fullheight) = &check_dimensions($inputfile);
4957: if ($fullwidth ne '' && $fullheight ne '') {
4958: if ($fullwidth > $thumbwidth && $fullheight > $thumbheight) {
4959: my $thumbsize = $thumbwidth.'x'.$thumbheight;
4960: system("convert -sample $thumbsize $inputfile $outfile");
4961: chmod(0660, $filepath.'/tn-'.$file);
4962: if (-e $outfile) {
4963: my $copyfile=$targetdir.'/tn-'.$file;
4964: if (copy($outfile,$copyfile)) {
4965: print $logfile "\nCopied source to ".$copyfile."\n";
4966: &write_metadata($dom,$confname,$formname,
4967: $targetdir,'tn-'.$file,$logfile);
4968: } else {
4969: print $logfile "\nUnable to write ".$copyfile.
4970: ':'.$!."\n";
4971: }
4972: }
1.9 raeburn 4973: }
4974: }
4975: }
4976: } else {
4977: $output = $versionresult;
4978: }
4979: }
4980: return ($output,$logourl);
4981: }
4982:
4983: sub logo_versioning {
4984: my ($targetdir,$file,$logfile) = @_;
4985: my $target = $targetdir.'/'.$file;
4986: my ($maxversion,$fn,$extn,$output);
4987: $maxversion = 0;
4988: if ($file =~ /^(.+)\.(\w+)$/) {
4989: $fn=$1;
4990: $extn=$2;
4991: }
4992: opendir(DIR,$targetdir);
4993: while (my $filename=readdir(DIR)) {
4994: if ($filename=~/\Q$fn\E\.(\d+)\.\Q$extn\E$/) {
4995: $maxversion=($1>$maxversion)?$1:$maxversion;
4996: }
4997: }
4998: $maxversion++;
4999: print $logfile "\nCreating old version ".$maxversion."\n";
5000: my $copyfile=$targetdir.'/'.$fn.'.'.$maxversion.'.'.$extn;
5001: if (copy($target,$copyfile)) {
5002: print $logfile "Copied old target to ".$copyfile."\n";
5003: $copyfile=$copyfile.'.meta';
5004: if (copy($target.'.meta',$copyfile)) {
5005: print $logfile "Copied old target metadata to ".$copyfile."\n";
5006: $output = 'ok';
5007: } else {
5008: print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";
5009: $output = &mt('Failed to copy old meta').", $!, ";
5010: }
5011: } else {
5012: print $logfile "Unable to write ".$copyfile.':'.$!."\n";
5013: $output = &mt('Failed to copy old target').", $!, ";
5014: }
5015: return $output;
5016: }
5017:
5018: sub write_metadata {
5019: my ($dom,$confname,$formname,$targetdir,$file,$logfile) = @_;
5020: my (%metadatafields,%metadatakeys,$output);
5021: $metadatafields{'title'}=$formname;
5022: $metadatafields{'creationdate'}=time;
5023: $metadatafields{'lastrevisiondate'}=time;
5024: $metadatafields{'copyright'}='public';
5025: $metadatafields{'modifyinguser'}=$env{'user.name'}.':'.
5026: $env{'user.domain'};
5027: $metadatafields{'authorspace'}=$confname.':'.$dom;
5028: $metadatafields{'domain'}=$dom;
5029: {
5030: print $logfile "\nWrite metadata file for ".$targetdir.'/'.$file;
5031: my $mfh;
5032: unless (open($mfh,'>'.$targetdir.'/'.$file.'.meta')) {
5033: $output = &mt('Could not write metadata');
5034: }
5035: foreach (sort keys %metadatafields) {
5036: unless ($_=~/\./) {
5037: my $unikey=$_;
5038: $unikey=~/^([A-Za-z]+)/;
5039: my $tag=$1;
5040: $tag=~tr/A-Z/a-z/;
5041: print $mfh "\n\<$tag";
5042: foreach (split(/\,/,$metadatakeys{$unikey})) {
5043: my $value=$metadatafields{$unikey.'.'.$_};
5044: $value=~s/\"/\'\'/g;
5045: print $mfh ' '.$_.'="'.$value.'"';
5046: }
5047: print $mfh '>'.
5048: &HTML::Entities::encode($metadatafields{$unikey},'<>&"')
5049: .'</'.$tag.'>';
5050: }
5051: }
5052: $output = 'ok';
5053: print $logfile "\nWrote metadata";
5054: close($mfh);
5055: }
5056: }
5057:
5058: sub check_switchserver {
5059: my ($dom,$confname) = @_;
5060: my ($allowed,$switchserver);
5061: my $home = &Apache::lonnet::homeserver($confname,$dom);
5062: if ($home eq 'no_host') {
5063: $home = &Apache::lonnet::domain($dom,'primary');
5064: }
5065: my @ids=&Apache::lonnet::current_machine_ids();
1.10 albertel 5066: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
5067: if (!$allowed) {
5068: $switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role=dc./'.$dom.'/">'.&mt('Switch Server').'</a>';
1.9 raeburn 5069: }
5070: return $switchserver;
5071: }
5072:
1.1 raeburn 5073: sub modify_quotas {
1.86 raeburn 5074: my ($dom,$action,%domconfig) = @_;
1.101 raeburn 5075: my ($context,@usertools,@options,%validations,%titles,%confhash,%toolshash,
5076: %limithash,$toolregexp,%conditions,$resulttext,%changes);
1.86 raeburn 5077: if ($action eq 'quotas') {
5078: $context = 'tools';
5079: } else {
5080: $context = $action;
5081: }
5082: if ($context eq 'requestcourses') {
1.98 raeburn 5083: @usertools = ('official','unofficial','community');
1.106 raeburn 5084: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 5085: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
5086: %titles = &courserequest_titles();
5087: $toolregexp = join('|',@usertools);
5088: %conditions = &courserequest_conditions();
1.86 raeburn 5089: } else {
5090: @usertools = ('aboutme','blog','portfolio');
1.101 raeburn 5091: %titles = &tool_titles();
1.86 raeburn 5092: }
1.72 raeburn 5093: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.44 raeburn 5094: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 5095: foreach my $key (keys(%env)) {
1.101 raeburn 5096: if ($context eq 'requestcourses') {
5097: if ($key =~ /^form\.crsreq_($toolregexp)_(.+)$/) {
5098: my $item = $1;
5099: my $type = $2;
5100: if ($type =~ /^limit_(.+)/) {
5101: $limithash{$item}{$1} = $env{$key};
5102: } else {
5103: $confhash{$item}{$type} = $env{$key};
5104: }
5105: }
5106: } else {
1.86 raeburn 5107: if ($key =~ /^form\.quota_(.+)$/) {
5108: $confhash{'defaultquota'}{$1} = $env{$key};
5109: }
1.101 raeburn 5110: if ($key =~ /^form\.\Q$context\E_(.+)$/) {
5111: @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key);
5112: }
1.72 raeburn 5113: }
5114: }
1.102 raeburn 5115: if ($context eq 'requestcourses') {
5116: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.reqapprovalnotify');
5117: @approvalnotify = sort(@approvalnotify);
5118: $confhash{'notify'}{'approval'} = join(',',@approvalnotify);
5119: if (ref($domconfig{$action}) eq 'HASH') {
5120: if (ref($domconfig{$action}{'notify'}) eq 'HASH') {
5121: if ($domconfig{$action}{'notify'}{'approval'} ne $confhash{'notify'}{'approval'}) {
5122: $changes{'notify'}{'approval'} = 1;
5123: }
5124: } else {
1.144 raeburn 5125: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 5126: $changes{'notify'}{'approval'} = 1;
5127: }
5128: }
5129: } else {
1.144 raeburn 5130: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 5131: $changes{'notify'}{'approval'} = 1;
5132: }
5133: }
5134: } else {
1.86 raeburn 5135: $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
5136: }
1.72 raeburn 5137: foreach my $item (@usertools) {
5138: foreach my $type (@{$types},'default','_LC_adv') {
1.104 raeburn 5139: my $unset;
1.101 raeburn 5140: if ($context eq 'requestcourses') {
1.104 raeburn 5141: $unset = '0';
5142: if ($type eq '_LC_adv') {
5143: $unset = '';
5144: }
1.101 raeburn 5145: if ($confhash{$item}{$type} eq 'autolimit') {
5146: $confhash{$item}{$type} .= '=';
5147: unless ($limithash{$item}{$type} =~ /\D/) {
5148: $confhash{$item}{$type} .= $limithash{$item}{$type};
5149: }
5150: }
1.72 raeburn 5151: } else {
1.101 raeburn 5152: if (grep(/^\Q$type\E$/,@{$toolshash{$item}})) {
5153: $confhash{$item}{$type} = 1;
5154: } else {
5155: $confhash{$item}{$type} = 0;
5156: }
1.72 raeburn 5157: }
1.86 raeburn 5158: if (ref($domconfig{$action}) eq 'HASH') {
5159: if (ref($domconfig{$action}{$item}) eq 'HASH') {
5160: if ($domconfig{$action}{$item}{$type} ne $confhash{$item}{$type}) {
5161: $changes{$item}{$type} = 1;
5162: }
5163: } else {
5164: if ($context eq 'requestcourses') {
1.104 raeburn 5165: if ($confhash{$item}{$type} ne $unset) {
1.86 raeburn 5166: $changes{$item}{$type} = 1;
5167: }
5168: } else {
5169: if (!$confhash{$item}{$type}) {
5170: $changes{$item}{$type} = 1;
5171: }
5172: }
5173: }
5174: } else {
5175: if ($context eq 'requestcourses') {
1.104 raeburn 5176: if ($confhash{$item}{$type} ne $unset) {
1.72 raeburn 5177: $changes{$item}{$type} = 1;
5178: }
5179: } else {
5180: if (!$confhash{$item}{$type}) {
5181: $changes{$item}{$type} = 1;
5182: }
5183: }
5184: }
1.1 raeburn 5185: }
5186: }
1.86 raeburn 5187: unless ($context eq 'requestcourses') {
5188: if (ref($domconfig{'quotas'}) eq 'HASH') {
5189: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
5190: foreach my $key (keys(%{$domconfig{'quotas'}{'defaultquota'}})) {
5191: if (exists($confhash{'defaultquota'}{$key})) {
5192: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{'defaultquota'}{$key}) {
5193: $changes{'defaultquota'}{$key} = 1;
5194: }
5195: } else {
5196: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{'defaultquota'}{$key};
1.72 raeburn 5197: }
5198: }
1.86 raeburn 5199: } else {
5200: foreach my $key (keys(%{$domconfig{'quotas'}})) {
5201: if (exists($confhash{'defaultquota'}{$key})) {
5202: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{$key}) {
5203: $changes{'defaultquota'}{$key} = 1;
5204: }
5205: } else {
5206: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{$key};
1.72 raeburn 5207: }
1.1 raeburn 5208: }
5209: }
5210: }
1.86 raeburn 5211: if (ref($confhash{'defaultquota'}) eq 'HASH') {
5212: foreach my $key (keys(%{$confhash{'defaultquota'}})) {
5213: if (ref($domconfig{'quotas'}) eq 'HASH') {
5214: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
5215: if (!exists($domconfig{'quotas'}{'defaultquota'}{$key})) {
5216: $changes{'defaultquota'}{$key} = 1;
5217: }
5218: } else {
5219: if (!exists($domconfig{'quotas'}{$key})) {
5220: $changes{'defaultquota'}{$key} = 1;
5221: }
1.72 raeburn 5222: }
5223: } else {
1.86 raeburn 5224: $changes{'defaultquota'}{$key} = 1;
1.55 raeburn 5225: }
1.1 raeburn 5226: }
5227: }
5228: }
1.72 raeburn 5229:
5230: foreach my $key (keys(%confhash)) {
5231: $domdefaults{$key} = $confhash{$key};
5232: }
5233:
1.1 raeburn 5234: my %quotahash = (
1.86 raeburn 5235: $action => { %confhash }
1.1 raeburn 5236: );
5237: my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
5238: $dom);
5239: if ($putresult eq 'ok') {
5240: if (keys(%changes) > 0) {
1.72 raeburn 5241: my $cachetime = 24*60*60;
5242: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
5243:
1.1 raeburn 5244: $resulttext = &mt('Changes made:').'<ul>';
1.86 raeburn 5245: unless ($context eq 'requestcourses') {
5246: if (ref($changes{'defaultquota'}) eq 'HASH') {
5247: $resulttext .= '<li>'.&mt('Portfolio default quotas').'<ul>';
5248: foreach my $type (@{$types},'default') {
5249: if (defined($changes{'defaultquota'}{$type})) {
5250: my $typetitle = $usertypes->{$type};
5251: if ($type eq 'default') {
5252: $typetitle = $othertitle;
5253: }
5254: $resulttext .= '<li>'.&mt('[_1] set to [_2] Mb',$typetitle,$confhash{'defaultquota'}{$type}).'</li>';
1.72 raeburn 5255: }
5256: }
1.86 raeburn 5257: $resulttext .= '</ul></li>';
1.72 raeburn 5258: }
5259: }
1.80 raeburn 5260: my %newenv;
1.72 raeburn 5261: foreach my $item (@usertools) {
5262: if (ref($changes{$item}) eq 'HASH') {
1.80 raeburn 5263: my $newacc =
5264: &Apache::lonnet::usertools_access($env{'user.name'},
5265: $env{'user.domain'},
1.86 raeburn 5266: $item,'reload',$context);
5267: if ($context eq 'requestcourses') {
1.108 raeburn 5268: if ($env{'environment.canrequest.'.$item} ne $newacc) {
5269: $newenv{'environment.canrequest.'.$item} = $newacc;
1.86 raeburn 5270: }
5271: } else {
5272: if ($env{'environment.availabletools.'.$item} ne $newacc) {
5273: $newenv{'environment.availabletools.'.$item} = $newacc;
5274: }
1.80 raeburn 5275: }
1.72 raeburn 5276: $resulttext .= '<li>'.$titles{$item}.'<ul>';
5277: foreach my $type (@{$types},'default','_LC_adv') {
5278: if ($changes{$item}{$type}) {
5279: my $typetitle = $usertypes->{$type};
5280: if ($type eq 'default') {
5281: $typetitle = $othertitle;
5282: } elsif ($type eq '_LC_adv') {
5283: $typetitle = 'LON-CAPA Advanced Users';
5284: }
5285: if ($confhash{$item}{$type}) {
1.101 raeburn 5286: if ($context eq 'requestcourses') {
5287: my $cond;
5288: if ($confhash{$item}{$type} =~ /^autolimit=(\d*)$/) {
5289: if ($1 eq '') {
5290: $cond = &mt('(Automatic processing of any request).');
5291: } else {
5292: $cond = &mt('(Automatic processing of requests up to limit of [quant,_1,request] per user).',$1);
5293: }
5294: } else {
5295: $cond = $conditions{$confhash{$item}{$type}};
5296: }
5297: $resulttext .= '<li>'.&mt('Set to be available to [_1].',$typetitle).' '.$cond.'</li>';
5298: } else {
5299: $resulttext .= '<li>'.&mt('Set to be available to [_1]',$typetitle).'</li>';
5300: }
1.72 raeburn 5301: } else {
1.104 raeburn 5302: if ($type eq '_LC_adv') {
5303: if ($confhash{$item}{$type} eq '0') {
5304: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
5305: } else {
5306: $resulttext .= '<li>'.&mt('No override set for [_1]',$typetitle).'</li>';
5307: }
5308: } else {
5309: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
5310: }
1.72 raeburn 5311: }
5312: }
1.26 raeburn 5313: }
1.72 raeburn 5314: $resulttext .= '</ul></li>';
1.26 raeburn 5315: }
1.1 raeburn 5316: }
1.102 raeburn 5317: if ($action eq 'requestcourses') {
5318: if (ref($changes{'notify'}) eq 'HASH') {
5319: if ($changes{'notify'}{'approval'}) {
5320: if (ref($confhash{'notify'}) eq 'HASH') {
5321: if ($confhash{'notify'}{'approval'}) {
5322: $resulttext .= '<li>'.&mt('Notification of requests requiring approval will be sent to: ').$confhash{'notify'}{'approval'}.'</li>';
5323: } else {
5324: $resulttext .= '<li>'.&mt('No Domain Coordinators will receive notification of course requests requiring approval.').'</li>';
5325: }
5326: }
5327: }
5328: }
5329: }
1.1 raeburn 5330: $resulttext .= '</ul>';
1.80 raeburn 5331: if (keys(%newenv)) {
5332: &Apache::lonnet::appenv(\%newenv);
5333: }
1.1 raeburn 5334: } else {
1.86 raeburn 5335: if ($context eq 'requestcourses') {
5336: $resulttext = &mt('No changes made to rights to request creation of courses.');
5337: } else {
1.90 weissno 5338: $resulttext = &mt('No changes made to availability of personal information pages, blogs, portfolios or default quotas');
1.86 raeburn 5339: }
1.1 raeburn 5340: }
5341: } else {
1.11 albertel 5342: $resulttext = '<span class="LC_error">'.
5343: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 5344: }
1.3 raeburn 5345: return $resulttext;
1.1 raeburn 5346: }
5347:
1.3 raeburn 5348: sub modify_autoenroll {
5349: my ($dom,%domconfig) = @_;
1.1 raeburn 5350: my ($resulttext,%changes);
5351: my %currautoenroll;
5352: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
5353: foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
5354: $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
5355: }
5356: }
5357: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
5358: my %title = ( run => 'Auto-enrollment active',
1.129 raeburn 5359: sender => 'Sender for notification messages',
5360: coowners => 'Automatic assignment of co-ownership to instructors of record (institutional data)');
1.1 raeburn 5361: my @offon = ('off','on');
1.17 raeburn 5362: my $sender_uname = $env{'form.sender_uname'};
5363: my $sender_domain = $env{'form.sender_domain'};
5364: if ($sender_domain eq '') {
5365: $sender_uname = '';
5366: } elsif ($sender_uname eq '') {
5367: $sender_domain = '';
5368: }
1.129 raeburn 5369: my $coowners = $env{'form.autoassign_coowners'};
1.1 raeburn 5370: my %autoenrollhash = (
1.129 raeburn 5371: autoenroll => { 'run' => $env{'form.autoenroll_run'},
5372: 'sender_uname' => $sender_uname,
5373: 'sender_domain' => $sender_domain,
5374: 'co-owners' => $coowners,
1.1 raeburn 5375: }
5376: );
1.4 raeburn 5377: my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
5378: $dom);
1.1 raeburn 5379: if ($putresult eq 'ok') {
5380: if (exists($currautoenroll{'run'})) {
5381: if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
5382: $changes{'run'} = 1;
5383: }
5384: } elsif ($autorun) {
5385: if ($env{'form.autoenroll_run'} ne '1') {
1.23 raeburn 5386: $changes{'run'} = 1;
1.1 raeburn 5387: }
5388: }
1.17 raeburn 5389: if ($currautoenroll{'sender_uname'} ne $sender_uname) {
1.1 raeburn 5390: $changes{'sender'} = 1;
5391: }
1.17 raeburn 5392: if ($currautoenroll{'sender_domain'} ne $sender_domain) {
1.1 raeburn 5393: $changes{'sender'} = 1;
5394: }
1.129 raeburn 5395: if ($currautoenroll{'co-owners'} ne '') {
5396: if ($currautoenroll{'co-owners'} ne $coowners) {
5397: $changes{'coowners'} = 1;
5398: }
5399: } elsif ($coowners) {
5400: $changes{'coowners'} = 1;
5401: }
1.1 raeburn 5402: if (keys(%changes) > 0) {
5403: $resulttext = &mt('Changes made:').'<ul>';
1.3 raeburn 5404: if ($changes{'run'}) {
1.1 raeburn 5405: $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
5406: }
5407: if ($changes{'sender'}) {
1.17 raeburn 5408: if ($sender_uname eq '' || $sender_domain eq '') {
5409: $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
5410: } else {
5411: $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
5412: }
1.1 raeburn 5413: }
1.129 raeburn 5414: if ($changes{'coowners'}) {
5415: $resulttext .= '<li>'.&mt("$title{'coowners'} set to $offon[$env{'form.autoassign_coowners'}]").'</li>';
5416: &Apache::loncommon::devalidate_domconfig_cache($dom);
5417: }
1.1 raeburn 5418: $resulttext .= '</ul>';
5419: } else {
5420: $resulttext = &mt('No changes made to auto-enrollment settings');
5421: }
5422: } else {
1.11 albertel 5423: $resulttext = '<span class="LC_error">'.
5424: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 5425: }
1.3 raeburn 5426: return $resulttext;
1.1 raeburn 5427: }
5428:
5429: sub modify_autoupdate {
1.3 raeburn 5430: my ($dom,%domconfig) = @_;
1.1 raeburn 5431: my ($resulttext,%currautoupdate,%fields,%changes);
5432: if (ref($domconfig{'autoupdate'}) eq 'HASH') {
5433: foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
5434: $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
5435: }
5436: }
5437: my @offon = ('off','on');
5438: my %title = &Apache::lonlocal::texthash (
5439: run => 'Auto-update:',
5440: classlists => 'Updates to user information in classlists?'
5441: );
1.44 raeburn 5442: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 5443: my %fieldtitles = &Apache::lonlocal::texthash (
5444: id => 'Student/Employee ID',
1.20 raeburn 5445: permanentemail => 'E-mail address',
1.1 raeburn 5446: lastname => 'Last Name',
5447: firstname => 'First Name',
5448: middlename => 'Middle Name',
1.132 raeburn 5449: generation => 'Generation',
1.1 raeburn 5450: );
1.142 raeburn 5451: $othertitle = &mt('All users');
1.1 raeburn 5452: if (keys(%{$usertypes}) > 0) {
1.26 raeburn 5453: $othertitle = &mt('Other users');
1.1 raeburn 5454: }
5455: foreach my $key (keys(%env)) {
5456: if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
1.132 raeburn 5457: my ($usertype,$item) = ($1,$2);
5458: if (grep(/^\Q$item\E$/,keys(%fieldtitles))) {
5459: if ($usertype eq 'default') {
5460: push(@{$fields{$1}},$2);
5461: } elsif (ref($types) eq 'ARRAY') {
5462: if (grep(/^\Q$usertype\E$/,@{$types})) {
5463: push(@{$fields{$1}},$2);
5464: }
5465: }
5466: }
1.1 raeburn 5467: }
5468: }
1.131 raeburn 5469: my @lockablenames = &Apache::loncommon::get_env_multiple('form.lockablenames');
5470: @lockablenames = sort(@lockablenames);
5471: if (ref($currautoupdate{'lockablenames'}) eq 'ARRAY') {
5472: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
5473: if (@changed) {
5474: $changes{'lockablenames'} = 1;
5475: }
5476: } else {
5477: if (@lockablenames) {
5478: $changes{'lockablenames'} = 1;
5479: }
5480: }
1.1 raeburn 5481: my %updatehash = (
5482: autoupdate => { run => $env{'form.autoupdate_run'},
5483: classlists => $env{'form.classlists'},
5484: fields => {%fields},
1.131 raeburn 5485: lockablenames => \@lockablenames,
1.1 raeburn 5486: }
5487: );
5488: foreach my $key (keys(%currautoupdate)) {
5489: if (($key eq 'run') || ($key eq 'classlists')) {
5490: if (exists($updatehash{autoupdate}{$key})) {
5491: if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
5492: $changes{$key} = 1;
5493: }
5494: }
5495: } elsif ($key eq 'fields') {
5496: if (ref($currautoupdate{$key}) eq 'HASH') {
1.26 raeburn 5497: foreach my $item (@{$types},'default') {
1.1 raeburn 5498: if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
5499: my $change = 0;
5500: foreach my $type (@{$currautoupdate{$key}{$item}}) {
5501: if (!exists($fields{$item})) {
5502: $change = 1;
1.132 raeburn 5503: last;
1.1 raeburn 5504: } elsif (ref($fields{$item}) eq 'ARRAY') {
1.26 raeburn 5505: if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
1.1 raeburn 5506: $change = 1;
1.132 raeburn 5507: last;
1.1 raeburn 5508: }
5509: }
5510: }
5511: if ($change) {
5512: push(@{$changes{$key}},$item);
5513: }
1.26 raeburn 5514: }
1.1 raeburn 5515: }
5516: }
1.131 raeburn 5517: } elsif ($key eq 'lockablenames') {
5518: if (ref($currautoupdate{$key}) eq 'ARRAY') {
5519: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
5520: if (@changed) {
5521: $changes{'lockablenames'} = 1;
5522: }
5523: } else {
5524: if (@lockablenames) {
5525: $changes{'lockablenames'} = 1;
5526: }
5527: }
5528: }
5529: }
5530: unless (grep(/^\Qlockablenames\E$/,keys(%currautoupdate))) {
5531: if (@lockablenames) {
5532: $changes{'lockablenames'} = 1;
1.1 raeburn 5533: }
5534: }
1.26 raeburn 5535: foreach my $item (@{$types},'default') {
5536: if (defined($fields{$item})) {
5537: if (ref($currautoupdate{'fields'}) eq 'HASH') {
1.132 raeburn 5538: if (ref($currautoupdate{'fields'}{$item}) eq 'ARRAY') {
5539: my $change = 0;
5540: if (ref($fields{$item}) eq 'ARRAY') {
5541: foreach my $type (@{$fields{$item}}) {
5542: if (!grep(/^\Q$type\E$/,@{$currautoupdate{'fields'}{$item}})) {
5543: $change = 1;
5544: last;
5545: }
5546: }
5547: }
5548: if ($change) {
5549: push(@{$changes{'fields'}},$item);
5550: }
5551: } else {
1.26 raeburn 5552: push(@{$changes{'fields'}},$item);
5553: }
5554: } else {
5555: push(@{$changes{'fields'}},$item);
1.1 raeburn 5556: }
5557: }
5558: }
5559: my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
5560: $dom);
5561: if ($putresult eq 'ok') {
5562: if (keys(%changes) > 0) {
5563: $resulttext = &mt('Changes made:').'<ul>';
5564: foreach my $key (sort(keys(%changes))) {
1.131 raeburn 5565: if ($key eq 'lockablenames') {
5566: $resulttext .= '<li>';
5567: if (@lockablenames) {
5568: $usertypes->{'default'} = $othertitle;
5569: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update), available for the following affiliations:").' '.
5570: join(', ', map { $usertypes->{$_}; } @lockablenames).'</li>';
5571: } else {
5572: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update) is unavailable.");
5573: }
5574: $resulttext .= '</li>';
5575: } elsif (ref($changes{$key}) eq 'ARRAY') {
1.1 raeburn 5576: foreach my $item (@{$changes{$key}}) {
5577: my @newvalues;
5578: foreach my $type (@{$fields{$item}}) {
5579: push(@newvalues,$fieldtitles{$type});
5580: }
1.3 raeburn 5581: my $newvaluestr;
5582: if (@newvalues > 0) {
5583: $newvaluestr = join(', ',@newvalues);
5584: } else {
5585: $newvaluestr = &mt('none');
1.6 raeburn 5586: }
1.1 raeburn 5587: if ($item eq 'default') {
1.26 raeburn 5588: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
1.1 raeburn 5589: } else {
1.26 raeburn 5590: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
1.1 raeburn 5591: }
5592: }
5593: } else {
5594: my $newvalue;
5595: if ($key eq 'run') {
5596: $newvalue = $offon[$env{'form.autoupdate_run'}];
5597: } else {
5598: $newvalue = $offon[$env{'form.'.$key}];
1.3 raeburn 5599: }
1.1 raeburn 5600: $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
5601: }
5602: }
5603: $resulttext .= '</ul>';
5604: } else {
1.3 raeburn 5605: $resulttext = &mt('No changes made to autoupdates');
1.1 raeburn 5606: }
5607: } else {
1.11 albertel 5608: $resulttext = '<span class="LC_error">'.
5609: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 5610: }
1.3 raeburn 5611: return $resulttext;
1.1 raeburn 5612: }
5613:
1.125 raeburn 5614: sub modify_autocreate {
5615: my ($dom,%domconfig) = @_;
5616: my ($resulttext,%changes,%currautocreate,%newvals,%autocreatehash);
5617: if (ref($domconfig{'autocreate'}) eq 'HASH') {
5618: foreach my $key (keys(%{$domconfig{'autocreate'}})) {
5619: $currautocreate{$key} = $domconfig{'autocreate'}{$key};
5620: }
5621: }
5622: my %title= ( xml => 'Auto-creation of courses in XML course description files',
5623: req => 'Auto-creation of validated requests for official courses',
5624: xmldc => 'Identity of course creator of courses from XML files',
5625: );
5626: my @types = ('xml','req');
5627: foreach my $item (@types) {
5628: $newvals{$item} = $env{'form.autocreate_'.$item};
5629: $newvals{$item} =~ s/\D//g;
5630: $newvals{$item} = 0 if ($newvals{$item} eq '');
5631: }
5632: $newvals{'xmldc'} = $env{'form.autocreate_xmldc'};
5633: my %domcoords = &get_active_dcs($dom);
5634: unless (exists($domcoords{$newvals{'xmldc'}})) {
5635: $newvals{'xmldc'} = '';
5636: }
5637: %autocreatehash = (
5638: autocreate => { xml => $newvals{'xml'},
5639: req => $newvals{'req'},
5640: }
5641: );
5642: if ($newvals{'xmldc'} ne '') {
5643: $autocreatehash{'autocreate'}{'xmldc'} = $newvals{'xmldc'};
5644: }
5645: my $putresult = &Apache::lonnet::put_dom('configuration',\%autocreatehash,
5646: $dom);
5647: if ($putresult eq 'ok') {
5648: my @items = @types;
5649: if ($newvals{'xml'}) {
5650: push(@items,'xmldc');
5651: }
5652: foreach my $item (@items) {
5653: if (exists($currautocreate{$item})) {
5654: if ($currautocreate{$item} ne $newvals{$item}) {
5655: $changes{$item} = 1;
5656: }
5657: } elsif ($newvals{$item}) {
5658: $changes{$item} = 1;
5659: }
5660: }
5661: if (keys(%changes) > 0) {
5662: my @offon = ('off','on');
5663: $resulttext = &mt('Changes made:').'<ul>';
5664: foreach my $item (@types) {
5665: if ($changes{$item}) {
5666: my $newtxt = $offon[$newvals{$item}];
5667: $resulttext .= '<li>'.&mt("$title{$item} set to [_1]$newtxt [_2]",'<b>','</b>').'</li>';
5668: }
5669: }
5670: if ($changes{'xmldc'}) {
5671: my ($dcname,$dcdom) = split(':',$newvals{'xmldc'});
5672: my $newtxt = &Apache::loncommon::plainname($dcname,$dcdom);
5673: $resulttext .= '<li>'.&mt("$title{'xmldc'} set to [_1]$newtxt [_2]",'<b>','</b>').'</li>';
5674: }
5675: $resulttext .= '</ul>';
5676: } else {
5677: $resulttext = &mt('No changes made to auto-creation settings');
5678: }
5679: } else {
5680: $resulttext = '<span class="LC_error">'.
5681: &mt('An error occurred: [_1]',$putresult).'</span>';
5682: }
5683: return $resulttext;
5684: }
5685:
1.23 raeburn 5686: sub modify_directorysrch {
5687: my ($dom,%domconfig) = @_;
5688: my ($resulttext,%changes);
5689: my %currdirsrch;
5690: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
5691: foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
5692: $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
5693: }
5694: }
5695: my %title = ( available => 'Directory search available',
1.24 raeburn 5696: localonly => 'Other domains can search',
1.23 raeburn 5697: searchby => 'Search types',
5698: searchtypes => 'Search latitude');
5699: my @offon = ('off','on');
1.24 raeburn 5700: my @otherdoms = ('Yes','No');
1.23 raeburn 5701:
1.25 raeburn 5702: my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');
1.23 raeburn 5703: my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
5704: my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
5705:
1.44 raeburn 5706: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.26 raeburn 5707: if (keys(%{$usertypes}) == 0) {
5708: @cansearch = ('default');
5709: } else {
5710: if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
5711: foreach my $type (@{$currdirsrch{'cansearch'}}) {
5712: if (!grep(/^\Q$type\E$/,@cansearch)) {
5713: push(@{$changes{'cansearch'}},$type);
5714: }
1.23 raeburn 5715: }
1.26 raeburn 5716: foreach my $type (@cansearch) {
5717: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
5718: push(@{$changes{'cansearch'}},$type);
5719: }
1.23 raeburn 5720: }
1.26 raeburn 5721: } else {
5722: push(@{$changes{'cansearch'}},@cansearch);
1.23 raeburn 5723: }
5724: }
5725:
5726: if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
5727: foreach my $by (@{$currdirsrch{'searchby'}}) {
5728: if (!grep(/^\Q$by\E$/,@searchby)) {
5729: push(@{$changes{'searchby'}},$by);
5730: }
5731: }
5732: foreach my $by (@searchby) {
5733: if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
5734: push(@{$changes{'searchby'}},$by);
5735: }
5736: }
5737: } else {
5738: push(@{$changes{'searchby'}},@searchby);
5739: }
1.25 raeburn 5740:
5741: if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
5742: foreach my $type (@{$currdirsrch{'searchtypes'}}) {
5743: if (!grep(/^\Q$type\E$/,@searchtypes)) {
5744: push(@{$changes{'searchtypes'}},$type);
5745: }
5746: }
5747: foreach my $type (@searchtypes) {
5748: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
5749: push(@{$changes{'searchtypes'}},$type);
5750: }
5751: }
5752: } else {
5753: if (exists($currdirsrch{'searchtypes'})) {
5754: foreach my $type (@searchtypes) {
5755: if ($type ne $currdirsrch{'searchtypes'}) {
5756: push(@{$changes{'searchtypes'}},$type);
5757: }
5758: }
5759: if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
5760: push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
5761: }
5762: } else {
5763: push(@{$changes{'searchtypes'}},@searchtypes);
5764: }
5765: }
5766:
1.23 raeburn 5767: my %dirsrch_hash = (
5768: directorysrch => { available => $env{'form.dirsrch_available'},
5769: cansearch => \@cansearch,
1.24 raeburn 5770: localonly => $env{'form.dirsrch_localonly'},
1.23 raeburn 5771: searchby => \@searchby,
1.25 raeburn 5772: searchtypes => \@searchtypes,
1.23 raeburn 5773: }
5774: );
5775: my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
5776: $dom);
5777: if ($putresult eq 'ok') {
5778: if (exists($currdirsrch{'available'})) {
5779: if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
5780: $changes{'available'} = 1;
5781: }
5782: } else {
5783: if ($env{'form.dirsrch_available'} eq '1') {
5784: $changes{'available'} = 1;
5785: }
5786: }
1.24 raeburn 5787: if (exists($currdirsrch{'localonly'})) {
5788: if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_localonly'}) {
5789: $changes{'localonly'} = 1;
5790: }
5791: } else {
5792: if ($env{'form.dirsrch_localonly'} eq '1') {
5793: $changes{'localonly'} = 1;
5794: }
5795: }
1.23 raeburn 5796: if (keys(%changes) > 0) {
5797: $resulttext = &mt('Changes made:').'<ul>';
5798: if ($changes{'available'}) {
5799: $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
5800: }
1.24 raeburn 5801: if ($changes{'localonly'}) {
5802: $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_localonly'}]").'</li>';
5803: }
5804:
1.23 raeburn 5805: if (ref($changes{'cansearch'}) eq 'ARRAY') {
5806: my $chgtext;
1.26 raeburn 5807: if (ref($usertypes) eq 'HASH') {
5808: if (keys(%{$usertypes}) > 0) {
5809: foreach my $type (@{$types}) {
5810: if (grep(/^\Q$type\E$/,@cansearch)) {
5811: $chgtext .= $usertypes->{$type}.'; ';
5812: }
5813: }
5814: if (grep(/^default$/,@cansearch)) {
5815: $chgtext .= $othertitle;
5816: } else {
5817: $chgtext =~ s/\; $//;
5818: }
5819: $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 5820: }
5821: }
5822: }
5823: if (ref($changes{'searchby'}) eq 'ARRAY') {
5824: my ($searchtitles,$titleorder) = &sorted_searchtitles();
5825: my $chgtext;
5826: foreach my $type (@{$titleorder}) {
5827: if (grep(/^\Q$type\E$/,@searchby)) {
5828: if (defined($searchtitles->{$type})) {
5829: $chgtext .= $searchtitles->{$type}.'; ';
5830: }
5831: }
5832: }
5833: $chgtext =~ s/\; $//;
5834: $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
5835: }
1.25 raeburn 5836: if (ref($changes{'searchtypes'}) eq 'ARRAY') {
5837: my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes();
5838: my $chgtext;
5839: foreach my $type (@{$srchtypeorder}) {
5840: if (grep(/^\Q$type\E$/,@searchtypes)) {
5841: if (defined($srchtypes_desc->{$type})) {
5842: $chgtext .= $srchtypes_desc->{$type}.'; ';
5843: }
5844: }
5845: }
5846: $chgtext =~ s/\; $//;
5847: $resulttext .= '<li>'.&mt("$title{'searchtypes'} set to: \"[_1]\"",$chgtext).'</li>';
1.23 raeburn 5848: }
5849: $resulttext .= '</ul>';
5850: } else {
5851: $resulttext = &mt('No changes made to institution directory search settings');
5852: }
5853: } else {
5854: $resulttext = '<span class="LC_error">'.
1.27 raeburn 5855: &mt('An error occurred: [_1]',$putresult).'</span>';
5856: }
5857: return $resulttext;
5858: }
5859:
1.28 raeburn 5860: sub modify_contacts {
5861: my ($dom,%domconfig) = @_;
5862: my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
5863: if (ref($domconfig{'contacts'}) eq 'HASH') {
5864: foreach my $key (keys(%{$domconfig{'contacts'}})) {
5865: $currsetting{$key} = $domconfig{'contacts'}{$key};
5866: }
5867: }
1.134 raeburn 5868: my (%others,%to,%bcc);
1.28 raeburn 5869: my @contacts = ('supportemail','adminemail');
1.102 raeburn 5870: my @mailings = ('errormail','packagesmail','helpdeskmail','lonstatusmail',
5871: 'requestsmail');
1.28 raeburn 5872: foreach my $type (@mailings) {
5873: @{$newsetting{$type}} =
5874: &Apache::loncommon::get_env_multiple('form.'.$type);
5875: foreach my $item (@contacts) {
5876: if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
5877: $contacts_hash{contacts}{$type}{$item} = 1;
5878: } else {
5879: $contacts_hash{contacts}{$type}{$item} = 0;
5880: }
5881: }
5882: $others{$type} = $env{'form.'.$type.'_others'};
5883: $contacts_hash{contacts}{$type}{'others'} = $others{$type};
1.134 raeburn 5884: if ($type eq 'helpdeskmail') {
5885: $bcc{$type} = $env{'form.'.$type.'_bcc'};
5886: $contacts_hash{contacts}{$type}{'bcc'} = $bcc{$type};
5887: }
1.28 raeburn 5888: }
5889: foreach my $item (@contacts) {
5890: $to{$item} = $env{'form.'.$item};
5891: $contacts_hash{'contacts'}{$item} = $to{$item};
5892: }
5893: if (keys(%currsetting) > 0) {
5894: foreach my $item (@contacts) {
5895: if ($to{$item} ne $currsetting{$item}) {
5896: $changes{$item} = 1;
5897: }
5898: }
5899: foreach my $type (@mailings) {
5900: foreach my $item (@contacts) {
5901: if (ref($currsetting{$type}) eq 'HASH') {
5902: if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
5903: push(@{$changes{$type}},$item);
5904: }
5905: } else {
5906: push(@{$changes{$type}},@{$newsetting{$type}});
5907: }
5908: }
5909: if ($others{$type} ne $currsetting{$type}{'others'}) {
5910: push(@{$changes{$type}},'others');
5911: }
1.134 raeburn 5912: if ($type eq 'helpdeskmail') {
5913: if ($bcc{$type} ne $currsetting{$type}{'bcc'}) {
5914: push(@{$changes{$type}},'bcc');
5915: }
5916: }
1.28 raeburn 5917: }
5918: } else {
5919: my %default;
5920: $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
5921: $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
5922: $default{'errormail'} = 'adminemail';
5923: $default{'packagesmail'} = 'adminemail';
5924: $default{'helpdeskmail'} = 'supportemail';
1.89 raeburn 5925: $default{'lonstatusmail'} = 'adminemail';
1.102 raeburn 5926: $default{'requestsmail'} = 'adminemail';
1.28 raeburn 5927: foreach my $item (@contacts) {
5928: if ($to{$item} ne $default{$item}) {
5929: $changes{$item} = 1;
5930: }
5931: }
5932: foreach my $type (@mailings) {
5933: if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
5934:
5935: push(@{$changes{$type}},@{$newsetting{$type}});
5936: }
5937: if ($others{$type} ne '') {
5938: push(@{$changes{$type}},'others');
1.134 raeburn 5939: }
5940: if ($type eq 'helpdeskmail') {
5941: if ($bcc{$type} ne '') {
5942: push(@{$changes{$type}},'bcc');
5943: }
5944: }
1.28 raeburn 5945: }
5946: }
5947: my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
5948: $dom);
5949: if ($putresult eq 'ok') {
5950: if (keys(%changes) > 0) {
5951: my ($titles,$short_titles) = &contact_titles();
5952: $resulttext = &mt('Changes made:').'<ul>';
5953: foreach my $item (@contacts) {
5954: if ($changes{$item}) {
5955: $resulttext .= '<li>'.$titles->{$item}.
5956: &mt(' set to: ').
5957: '<span class="LC_cusr_emph">'.
5958: $to{$item}.'</span></li>';
5959: }
5960: }
5961: foreach my $type (@mailings) {
5962: if (ref($changes{$type}) eq 'ARRAY') {
5963: $resulttext .= '<li>'.$titles->{$type}.': ';
5964: my @text;
5965: foreach my $item (@{$newsetting{$type}}) {
5966: push(@text,$short_titles->{$item});
5967: }
5968: if ($others{$type} ne '') {
5969: push(@text,$others{$type});
5970: }
5971: $resulttext .= '<span class="LC_cusr_emph">'.
1.134 raeburn 5972: join(', ',@text).'</span>';
5973: if ($type eq 'helpdeskmail') {
5974: if ($bcc{$type} ne '') {
5975: $resulttext .= ' '.&mt('with Bcc to').': <span class="LC_cusr_emph">'.$bcc{$type}.'</span>';
5976: }
5977: }
5978: $resulttext .= '</li>';
1.28 raeburn 5979: }
5980: }
5981: $resulttext .= '</ul>';
5982: } else {
1.34 raeburn 5983: $resulttext = &mt('No changes made to contact information');
1.28 raeburn 5984: }
5985: } else {
5986: $resulttext = '<span class="LC_error">'.
5987: &mt('An error occurred: [_1].',$putresult).'</span>';
5988: }
5989: return $resulttext;
5990: }
5991:
5992: sub modify_usercreation {
1.27 raeburn 5993: my ($dom,%domconfig) = @_;
1.34 raeburn 5994: my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate);
1.43 raeburn 5995: my $warningmsg;
1.27 raeburn 5996: if (ref($domconfig{'usercreation'}) eq 'HASH') {
5997: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
5998: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
5999: }
6000: }
6001: my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
1.32 raeburn 6002: my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
1.43 raeburn 6003: my @email_rule = &Apache::loncommon::get_env_multiple('form.email_rule');
1.100 raeburn 6004: my @contexts = ('author','course','requestcrs','selfcreate');
1.34 raeburn 6005: foreach my $item(@contexts) {
1.45 raeburn 6006: if ($item eq 'selfcreate') {
1.50 raeburn 6007: @{$cancreate{$item}} = &Apache::loncommon::get_env_multiple('form.can_createuser_'.$item);
1.43 raeburn 6008: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
6009: if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) || ($domdefaults{'auth_def'} eq 'localauth'))) {
1.50 raeburn 6010: if (ref($cancreate{$item}) eq 'ARRAY') {
6011: if (grep(/^login$/,@{$cancreate{$item}})) {
6012: $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.');
6013: }
1.43 raeburn 6014: }
6015: }
1.50 raeburn 6016: } else {
6017: $cancreate{$item} = $env{'form.can_createuser_'.$item};
1.43 raeburn 6018: }
1.34 raeburn 6019: }
1.93 raeburn 6020: my ($othertitle,$usertypes,$types) =
6021: &Apache::loncommon::sorted_inst_types($dom);
6022: if (ref($types) eq 'ARRAY') {
6023: if (@{$types} > 0) {
6024: @{$cancreate{'statustocreate'}} =
6025: &Apache::loncommon::get_env_multiple('form.statustocreate');
1.103 raeburn 6026: } else {
6027: @{$cancreate{'statustocreate'}} = ();
1.93 raeburn 6028: }
6029: push(@contexts,'statustocreate');
6030: }
1.34 raeburn 6031: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
6032: foreach my $item (@contexts) {
1.93 raeburn 6033: if (($item eq 'selfcreate') || ($item eq 'statustocreate')) {
6034: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
1.50 raeburn 6035: foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
1.103 raeburn 6036: if (ref($cancreate{$item}) eq 'ARRAY') {
6037: if (!grep(/^$curr$/,@{$cancreate{$item}})) {
6038: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6039: push(@{$changes{'cancreate'}},$item);
6040: }
1.50 raeburn 6041: }
6042: }
6043: }
6044: } else {
6045: if ($curr_usercreation{'cancreate'}{$item} eq '') {
6046: if (@{$cancreate{$item}} > 0) {
6047: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6048: push(@{$changes{'cancreate'}},$item);
6049: }
6050: }
6051: } else {
6052: if ($curr_usercreation{'cancreate'}{$item} eq 'any') {
6053: if (@{$cancreate{$item}} < 3) {
6054: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6055: push(@{$changes{'cancreate'}},$item);
6056: }
6057: }
6058: } elsif ($curr_usercreation{'cancreate'}{$item} eq 'none') {
6059: if (@{$cancreate{$item}} > 0) {
6060: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6061: push(@{$changes{'cancreate'}},$item);
6062: }
6063: }
6064: } elsif (!grep(/^$curr_usercreation{'cancreate'}{$item}$/,@{$cancreate{$item}})) {
6065: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6066: push(@{$changes{'cancreate'}},$item);
6067: }
6068: }
6069: }
6070: }
6071: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6072: foreach my $type (@{$cancreate{$item}}) {
6073: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
6074: if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
6075: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6076: push(@{$changes{'cancreate'}},$item);
6077: }
6078: }
6079: } elsif (($curr_usercreation{'cancreate'}{$item} ne 'any') &&
6080: ($curr_usercreation{'cancreate'}{$item} ne 'none')) {
6081: if ($curr_usercreation{'cancreate'}{$item} ne $type) {
6082: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6083: push(@{$changes{'cancreate'}},$item);
6084: }
6085: }
6086: }
6087: }
6088: }
6089: } else {
6090: if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
6091: push(@{$changes{'cancreate'}},$item);
6092: }
6093: }
1.27 raeburn 6094: }
1.34 raeburn 6095: } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
6096: foreach my $item (@contexts) {
1.43 raeburn 6097: if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
1.34 raeburn 6098: if ($cancreate{$item} ne 'any') {
6099: push(@{$changes{'cancreate'}},$item);
6100: }
6101: } else {
6102: if ($cancreate{$item} ne 'none') {
6103: push(@{$changes{'cancreate'}},$item);
6104: }
1.27 raeburn 6105: }
6106: }
6107: } else {
1.43 raeburn 6108: foreach my $item (@contexts) {
1.34 raeburn 6109: push(@{$changes{'cancreate'}},$item);
6110: }
1.27 raeburn 6111: }
1.34 raeburn 6112:
1.27 raeburn 6113: if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
6114: foreach my $type (@{$curr_usercreation{'username_rule'}}) {
6115: if (!grep(/^\Q$type\E$/,@username_rule)) {
6116: push(@{$changes{'username_rule'}},$type);
6117: }
6118: }
6119: foreach my $type (@username_rule) {
6120: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
6121: push(@{$changes{'username_rule'}},$type);
6122: }
6123: }
6124: } else {
6125: push(@{$changes{'username_rule'}},@username_rule);
6126: }
6127:
1.32 raeburn 6128: if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
6129: foreach my $type (@{$curr_usercreation{'id_rule'}}) {
6130: if (!grep(/^\Q$type\E$/,@id_rule)) {
6131: push(@{$changes{'id_rule'}},$type);
6132: }
6133: }
6134: foreach my $type (@id_rule) {
6135: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
6136: push(@{$changes{'id_rule'}},$type);
6137: }
6138: }
6139: } else {
6140: push(@{$changes{'id_rule'}},@id_rule);
6141: }
6142:
1.43 raeburn 6143: if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
6144: foreach my $type (@{$curr_usercreation{'email_rule'}}) {
6145: if (!grep(/^\Q$type\E$/,@email_rule)) {
6146: push(@{$changes{'email_rule'}},$type);
6147: }
6148: }
6149: foreach my $type (@email_rule) {
6150: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'email_rule'}})) {
6151: push(@{$changes{'email_rule'}},$type);
6152: }
6153: }
6154: } else {
6155: push(@{$changes{'email_rule'}},@email_rule);
6156: }
6157:
6158: my @authen_contexts = ('author','course','domain');
1.28 raeburn 6159: my @authtypes = ('int','krb4','krb5','loc');
6160: my %authhash;
1.43 raeburn 6161: foreach my $item (@authen_contexts) {
1.28 raeburn 6162: my @authallowed = &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
6163: foreach my $auth (@authtypes) {
6164: if (grep(/^\Q$auth\E$/,@authallowed)) {
6165: $authhash{$item}{$auth} = 1;
6166: } else {
6167: $authhash{$item}{$auth} = 0;
6168: }
6169: }
6170: }
6171: if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
1.43 raeburn 6172: foreach my $item (@authen_contexts) {
1.28 raeburn 6173: if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
6174: foreach my $auth (@authtypes) {
6175: if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
6176: push(@{$changes{'authtypes'}},$item);
6177: last;
6178: }
6179: }
6180: }
6181: }
6182: } else {
1.43 raeburn 6183: foreach my $item (@authen_contexts) {
1.28 raeburn 6184: push(@{$changes{'authtypes'}},$item);
6185: }
6186: }
6187:
1.27 raeburn 6188: my %usercreation_hash = (
1.28 raeburn 6189: usercreation => {
1.34 raeburn 6190: cancreate => \%cancreate,
1.27 raeburn 6191: username_rule => \@username_rule,
1.32 raeburn 6192: id_rule => \@id_rule,
1.43 raeburn 6193: email_rule => \@email_rule,
1.32 raeburn 6194: authtypes => \%authhash,
1.27 raeburn 6195: }
6196: );
6197:
6198: my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
6199: $dom);
1.50 raeburn 6200:
6201: my %selfcreatetypes = (
6202: sso => 'users authenticated by institutional single sign on',
6203: login => 'users authenticated by institutional log-in',
6204: email => 'users who provide a valid e-mail address for use as the username',
6205: );
1.27 raeburn 6206: if ($putresult eq 'ok') {
6207: if (keys(%changes) > 0) {
6208: $resulttext = &mt('Changes made:').'<ul>';
6209: if (ref($changes{'cancreate'}) eq 'ARRAY') {
1.34 raeburn 6210: my %lt = &usercreation_types();
6211: foreach my $type (@{$changes{'cancreate'}}) {
1.100 raeburn 6212: my $chgtext;
6213: unless ($type eq 'statustocreate') {
6214: $chgtext = $lt{$type}.', ';
6215: }
1.45 raeburn 6216: if ($type eq 'selfcreate') {
1.50 raeburn 6217: if (@{$cancreate{$type}} == 0) {
1.43 raeburn 6218: $chgtext .= &mt('creation of a new user account is not permitted.');
1.50 raeburn 6219: } else {
1.100 raeburn 6220: $chgtext .= &mt('creation of a new account is permitted for:').'<ul>';
1.50 raeburn 6221: foreach my $case (@{$cancreate{$type}}) {
6222: $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
6223: }
6224: $chgtext .= '</ul>';
1.100 raeburn 6225: if (ref($cancreate{$type}) eq 'ARRAY') {
6226: if (grep(/^(login|sso)$/,@{$cancreate{$type}})) {
6227: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
6228: if (@{$cancreate{'statustocreate'}} == 0) {
6229: $chgtext .= '<br /><span class="LC_warning">'.&mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").'</span>';
6230: }
6231: }
6232: }
6233: }
1.43 raeburn 6234: }
1.93 raeburn 6235: } elsif ($type eq 'statustocreate') {
1.96 raeburn 6236: if ((ref($cancreate{'selfcreate'}) eq 'ARRAY') &&
6237: (ref($cancreate{'statustocreate'}) eq 'ARRAY')) {
6238: if (@{$cancreate{'selfcreate'}} > 0) {
6239: if (@{$cancreate{'statustocreate'}} == 0) {
1.100 raeburn 6240:
6241: $chgtext .= &mt("Institutional affiliations permitted to create accounts set to 'None'.");
1.96 raeburn 6242: if (!grep(/^email$/,@{$cancreate{'selfcreate'}})) {
1.100 raeburn 6243: $chgtext .= '<br /><span class="LC_warning">'.&mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").'</span>';
6244: }
1.96 raeburn 6245: } elsif (ref($usertypes) eq 'HASH') {
6246: if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.100 raeburn 6247: $chgtext .= &mt('Creation of a new account for an institutional user is restricted to the following institutional affiliation(s):');
6248: } else {
6249: $chgtext .= &mt('Institutional affiliations permitted to create accounts with institutional authentication were set as follows:');
6250: }
6251: $chgtext .= '<ul>';
6252: foreach my $case (@{$cancreate{$type}}) {
6253: if ($case eq 'default') {
6254: $chgtext .= '<li>'.$othertitle.'</li>';
6255: } else {
6256: $chgtext .= '<li>'.$usertypes->{$case}.'</li>';
1.93 raeburn 6257: }
6258: }
1.100 raeburn 6259: $chgtext .= '</ul>';
6260: if (!grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
6261: $chgtext .= '<br /><span class="LC_warning">'.&mt('However, users authenticated by institutional login/single sign on are not currently permitted to create accounts.').'</span>';
6262: }
6263: }
6264: } else {
6265: if (@{$cancreate{$type}} == 0) {
6266: $chgtext .= &mt("Institutional affiliations permitted to create accounts were set to 'none'.");
6267: } else {
6268: $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 6269: }
6270: }
6271: }
1.43 raeburn 6272: } else {
6273: if ($cancreate{$type} eq 'none') {
6274: $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
6275: } elsif ($cancreate{$type} eq 'any') {
6276: $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
6277: } elsif ($cancreate{$type} eq 'official') {
6278: $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
6279: } elsif ($cancreate{$type} eq 'unofficial') {
6280: $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
6281: }
1.34 raeburn 6282: }
6283: $resulttext .= '<li>'.$chgtext.'</li>';
1.27 raeburn 6284: }
6285: }
6286: if (ref($changes{'username_rule'}) eq 'ARRAY') {
1.32 raeburn 6287: my ($rules,$ruleorder) =
6288: &Apache::lonnet::inst_userrules($dom,'username');
1.27 raeburn 6289: my $chgtext = '<ul>';
6290: foreach my $type (@username_rule) {
6291: if (ref($rules->{$type}) eq 'HASH') {
6292: $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
6293: }
6294: }
6295: $chgtext .= '</ul>';
6296: if (@username_rule > 0) {
6297: $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
6298: } else {
1.28 raeburn 6299: $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>';
1.27 raeburn 6300: }
6301: }
1.32 raeburn 6302: if (ref($changes{'id_rule'}) eq 'ARRAY') {
6303: my ($idrules,$idruleorder) =
6304: &Apache::lonnet::inst_userrules($dom,'id');
6305: my $chgtext = '<ul>';
6306: foreach my $type (@id_rule) {
6307: if (ref($idrules->{$type}) eq 'HASH') {
6308: $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
6309: }
6310: }
6311: $chgtext .= '</ul>';
6312: if (@id_rule > 0) {
6313: $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
6314: } else {
6315: $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
6316: }
6317: }
1.43 raeburn 6318: if (ref($changes{'email_rule'}) eq 'ARRAY') {
6319: my ($emailrules,$emailruleorder) =
6320: &Apache::lonnet::inst_userrules($dom,'email');
6321: my $chgtext = '<ul>';
6322: foreach my $type (@email_rule) {
6323: if (ref($emailrules->{$type}) eq 'HASH') {
6324: $chgtext .= '<li>'.$emailrules->{$type}{'name'}.'</li>';
6325: }
6326: }
6327: $chgtext .= '</ul>';
6328: if (@email_rule > 0) {
6329: $resulttext .= '<li>'.&mt('Accounts may not be created by users self-enrolling with e-mail addresses of the following types: ').$chgtext.'</li>';
6330: } else {
6331: $resulttext .= '<li>'.&mt('There are now no restrictions on e-mail addresses which may be used as a username when self-enrolling.').'</li>';
6332: }
6333: }
6334:
1.28 raeburn 6335: my %authname = &authtype_names();
6336: my %context_title = &context_names();
6337: if (ref($changes{'authtypes'}) eq 'ARRAY') {
6338: my $chgtext = '<ul>';
6339: foreach my $type (@{$changes{'authtypes'}}) {
6340: my @allowed;
6341: $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
6342: foreach my $auth (@authtypes) {
6343: if ($authhash{$type}{$auth}) {
6344: push(@allowed,$authname{$auth});
6345: }
6346: }
1.43 raeburn 6347: if (@allowed > 0) {
6348: $chgtext .= join(', ',@allowed).'</li>';
6349: } else {
6350: $chgtext .= &mt('none').'</li>';
6351: }
1.28 raeburn 6352: }
6353: $chgtext .= '</ul>';
6354: $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
6355: $resulttext .= '</li>';
6356: }
1.27 raeburn 6357: $resulttext .= '</ul>';
6358: } else {
1.28 raeburn 6359: $resulttext = &mt('No changes made to user creation settings');
1.27 raeburn 6360: }
6361: } else {
6362: $resulttext = '<span class="LC_error">'.
1.23 raeburn 6363: &mt('An error occurred: [_1]',$putresult).'</span>';
6364: }
1.43 raeburn 6365: if ($warningmsg ne '') {
6366: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
6367: }
1.23 raeburn 6368: return $resulttext;
6369: }
6370:
1.33 raeburn 6371: sub modify_usermodification {
6372: my ($dom,%domconfig) = @_;
6373: my ($resulttext,%curr_usermodification,%changes);
6374: if (ref($domconfig{'usermodification'}) eq 'HASH') {
6375: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
6376: $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
6377: }
6378: }
1.63 raeburn 6379: my @contexts = ('author','course','selfcreate');
1.33 raeburn 6380: my %context_title = (
6381: author => 'In author context',
6382: course => 'In course context',
1.63 raeburn 6383: selfcreate => 'When self creating account',
1.33 raeburn 6384: );
6385: my @fields = ('lastname','firstname','middlename','generation',
6386: 'permanentemail','id');
6387: my %roles = (
6388: author => ['ca','aa'],
6389: course => ['st','ep','ta','in','cr'],
6390: );
1.63 raeburn 6391: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
6392: if (ref($types) eq 'ARRAY') {
6393: push(@{$types},'default');
6394: $usertypes->{'default'} = $othertitle;
6395: }
6396: $roles{'selfcreate'} = $types;
1.33 raeburn 6397: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
6398: my %modifyhash;
6399: foreach my $context (@contexts) {
6400: foreach my $role (@{$roles{$context}}) {
6401: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$role);
6402: foreach my $item (@fields) {
6403: if (grep(/^\Q$item\E$/,@modifiable)) {
6404: $modifyhash{$context}{$role}{$item} = 1;
6405: } else {
6406: $modifyhash{$context}{$role}{$item} = 0;
6407: }
6408: }
6409: }
6410: if (ref($curr_usermodification{$context}) eq 'HASH') {
6411: foreach my $role (@{$roles{$context}}) {
6412: if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
6413: foreach my $field (@fields) {
6414: if ($modifyhash{$context}{$role}{$field} ne
6415: $curr_usermodification{$context}{$role}{$field}) {
6416: push(@{$changes{$context}},$role);
6417: last;
6418: }
6419: }
6420: }
6421: }
6422: } else {
6423: foreach my $context (@contexts) {
6424: foreach my $role (@{$roles{$context}}) {
6425: push(@{$changes{$context}},$role);
6426: }
6427: }
6428: }
6429: }
6430: my %usermodification_hash = (
6431: usermodification => \%modifyhash,
6432: );
6433: my $putresult = &Apache::lonnet::put_dom('configuration',
6434: \%usermodification_hash,$dom);
6435: if ($putresult eq 'ok') {
6436: if (keys(%changes) > 0) {
6437: $resulttext = &mt('Changes made: ').'<ul>';
6438: foreach my $context (@contexts) {
6439: if (ref($changes{$context}) eq 'ARRAY') {
6440: $resulttext .= '<li>'.$context_title{$context}.':<ul>';
6441: if (ref($changes{$context}) eq 'ARRAY') {
6442: foreach my $role (@{$changes{$context}}) {
6443: my $rolename;
1.63 raeburn 6444: if ($context eq 'selfcreate') {
6445: $rolename = $role;
6446: if (ref($usertypes) eq 'HASH') {
6447: if ($usertypes->{$role} ne '') {
6448: $rolename = $usertypes->{$role};
6449: }
6450: }
1.33 raeburn 6451: } else {
1.63 raeburn 6452: if ($role eq 'cr') {
6453: $rolename = &mt('Custom');
6454: } else {
6455: $rolename = &Apache::lonnet::plaintext($role);
6456: }
1.33 raeburn 6457: }
6458: my @modifiable;
1.63 raeburn 6459: if ($context eq 'selfcreate') {
1.126 bisitz 6460: $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 6461: } else {
6462: $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
6463: }
1.33 raeburn 6464: foreach my $field (@fields) {
6465: if ($modifyhash{$context}{$role}{$field}) {
6466: push(@modifiable,$fieldtitles{$field});
6467: }
6468: }
6469: if (@modifiable > 0) {
6470: $resulttext .= join(', ',@modifiable);
6471: } else {
6472: $resulttext .= &mt('none');
6473: }
6474: $resulttext .= '</li>';
6475: }
6476: $resulttext .= '</ul></li>';
6477: }
6478: }
6479: }
6480: $resulttext .= '</ul>';
6481: } else {
6482: $resulttext = &mt('No changes made to user modification settings');
6483: }
6484: } else {
6485: $resulttext = '<span class="LC_error">'.
6486: &mt('An error occurred: [_1]',$putresult).'</span>';
6487: }
6488: return $resulttext;
6489: }
6490:
1.43 raeburn 6491: sub modify_defaults {
6492: my ($dom,$r) = @_;
6493: my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
6494: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.141 raeburn 6495: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def','portal_def');
1.43 raeburn 6496: my @authtypes = ('internal','krb4','krb5','localauth');
6497: foreach my $item (@items) {
6498: $newvalues{$item} = $env{'form.'.$item};
6499: if ($item eq 'auth_def') {
6500: if ($newvalues{$item} ne '') {
6501: if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
6502: push(@errors,$item);
6503: }
6504: }
6505: } elsif ($item eq 'lang_def') {
6506: if ($newvalues{$item} ne '') {
6507: if ($newvalues{$item} =~ /^(\w+)/) {
6508: my $langcode = $1;
1.103 raeburn 6509: if ($langcode ne 'x_chef') {
6510: if (code2language($langcode) eq '') {
6511: push(@errors,$item);
6512: }
1.43 raeburn 6513: }
6514: } else {
6515: push(@errors,$item);
6516: }
6517: }
1.54 raeburn 6518: } elsif ($item eq 'timezone_def') {
6519: if ($newvalues{$item} ne '') {
1.62 raeburn 6520: if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
1.54 raeburn 6521: push(@errors,$item);
6522: }
6523: }
1.68 raeburn 6524: } elsif ($item eq 'datelocale_def') {
6525: if ($newvalues{$item} ne '') {
6526: my @datelocale_ids = DateTime::Locale->ids();
6527: if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
6528: push(@errors,$item);
6529: }
6530: }
1.141 raeburn 6531: } elsif ($item eq 'portal_def') {
6532: if ($newvalues{$item} ne '') {
6533: 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])\/?$/) {
6534: push(@errors,$item);
6535: }
6536: }
1.43 raeburn 6537: }
6538: if (grep(/^\Q$item\E$/,@errors)) {
6539: $newvalues{$item} = $domdefaults{$item};
6540: } elsif ($domdefaults{$item} ne $newvalues{$item}) {
6541: $changes{$item} = 1;
6542: }
1.72 raeburn 6543: $domdefaults{$item} = $newvalues{$item};
1.43 raeburn 6544: }
6545: my %defaults_hash = (
1.72 raeburn 6546: defaults => \%newvalues,
6547: );
1.43 raeburn 6548: my $title = &defaults_titles();
6549: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
6550: $dom);
6551: if ($putresult eq 'ok') {
6552: if (keys(%changes) > 0) {
6553: $resulttext = &mt('Changes made:').'<ul>';
6554: my $version = $r->dir_config('lonVersion');
6555: 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";
6556: foreach my $item (sort(keys(%changes))) {
6557: my $value = $env{'form.'.$item};
6558: if ($value eq '') {
6559: $value = &mt('none');
6560: } elsif ($item eq 'auth_def') {
6561: my %authnames = &authtype_names();
6562: my %shortauth = (
6563: internal => 'int',
6564: krb4 => 'krb4',
6565: krb5 => 'krb5',
6566: localauth => 'loc',
6567: );
6568: $value = $authnames{$shortauth{$value}};
6569: }
6570: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
6571: $mailmsgtext .= "$title->{$item} set to $value\n";
6572: }
6573: $resulttext .= '</ul>';
6574: $mailmsgtext .= "\n";
6575: my $cachetime = 24*60*60;
1.72 raeburn 6576: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.68 raeburn 6577: if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
1.54 raeburn 6578: my $sysmail = $r->dir_config('lonSysEMail');
6579: &Apache::lonmsg::sendemail($sysmail,"LON-CAPA Domain Settings Change - $dom",$mailmsgtext);
6580: }
1.43 raeburn 6581: } else {
1.54 raeburn 6582: $resulttext = &mt('No changes made to default authentication/language/timezone settings');
1.43 raeburn 6583: }
6584: } else {
6585: $resulttext = '<span class="LC_error">'.
6586: &mt('An error occurred: [_1]',$putresult).'</span>';
6587: }
6588: if (@errors > 0) {
6589: $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
6590: foreach my $item (@errors) {
6591: $resulttext .= ' "'.$title->{$item}.'",';
6592: }
6593: $resulttext =~ s/,$//;
6594: }
6595: return $resulttext;
6596: }
6597:
1.46 raeburn 6598: sub modify_scantron {
1.48 raeburn 6599: my ($r,$dom,$confname,%domconfig) = @_;
1.46 raeburn 6600: my ($resulttext,%confhash,%changes,$errors);
6601: my $custom = 'custom.tab';
6602: my $default = 'default.tab';
6603: my $servadm = $r->dir_config('lonAdmEMail');
6604: my ($configuserok,$author_ok,$switchserver) =
6605: &config_check($dom,$confname,$servadm);
6606: if ($env{'form.scantronformat.filename'} ne '') {
6607: my $error;
6608: if ($configuserok eq 'ok') {
6609: if ($switchserver) {
1.130 raeburn 6610: $error = &mt("Upload of bubblesheet format file is not permitted to this server: [_1]",$switchserver);
1.46 raeburn 6611: } else {
6612: if ($author_ok eq 'ok') {
6613: my ($result,$scantronurl) =
6614: &publishlogo($r,'upload','scantronformat',$dom,
6615: $confname,'scantron','','',$custom);
6616: if ($result eq 'ok') {
6617: $confhash{'scantron'}{'scantronformat'} = $scantronurl;
1.48 raeburn 6618: $changes{'scantronformat'} = 1;
1.46 raeburn 6619: } else {
6620: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
6621: }
6622: } else {
6623: $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);
6624: }
6625: }
6626: } else {
6627: $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);
6628: }
6629: if ($error) {
6630: &Apache::lonnet::logthis($error);
6631: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
6632: }
6633: }
1.48 raeburn 6634: if (ref($domconfig{'scantron'}) eq 'HASH') {
6635: if ($domconfig{'scantron'}{'scantronformat'} ne '') {
6636: if ($env{'form.scantronformat_del'}) {
6637: $confhash{'scantron'}{'scantronformat'} = '';
6638: $changes{'scantronformat'} = 1;
1.46 raeburn 6639: }
6640: }
6641: }
6642: if (keys(%confhash) > 0) {
6643: my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
6644: $dom);
6645: if ($putresult eq 'ok') {
6646: if (keys(%changes) > 0) {
1.48 raeburn 6647: if (ref($confhash{'scantron'}) eq 'HASH') {
6648: $resulttext = &mt('Changes made:').'<ul>';
6649: if ($confhash{'scantron'}{'scantronformat'} eq '') {
1.130 raeburn 6650: $resulttext .= '<li>'.&mt('[_1] bubblesheet format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
1.48 raeburn 6651: } else {
1.130 raeburn 6652: $resulttext .= '<li>'.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
1.46 raeburn 6653: }
1.48 raeburn 6654: $resulttext .= '</ul>';
6655: } else {
1.130 raeburn 6656: $resulttext = &mt('Changes made to bubblesheet format file.');
1.46 raeburn 6657: }
6658: $resulttext .= '</ul>';
6659: &Apache::loncommon::devalidate_domconfig_cache($dom);
6660: } else {
1.130 raeburn 6661: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 6662: }
6663: } else {
6664: $resulttext = '<span class="LC_error">'.
6665: &mt('An error occurred: [_1]',$putresult).'</span>';
6666: }
6667: } else {
1.130 raeburn 6668: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 6669: }
6670: if ($errors) {
6671: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
6672: $errors.'</ul>';
6673: }
6674: return $resulttext;
6675: }
6676:
1.48 raeburn 6677: sub modify_coursecategories {
6678: my ($dom,%domconfig) = @_;
1.57 raeburn 6679: my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
6680: $cathash);
1.48 raeburn 6681: my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
1.55 raeburn 6682: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
1.57 raeburn 6683: $cathash = $domconfig{'coursecategories'}{'cats'};
6684: if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
6685: $changes{'togglecats'} = 1;
6686: $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
6687: }
6688: if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
6689: $changes{'categorize'} = 1;
6690: $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
6691: }
1.120 raeburn 6692: if ($domconfig{'coursecategories'}{'togglecatscomm'} ne $env{'form.togglecatscomm'}) {
6693: $changes{'togglecatscomm'} = 1;
6694: $domconfig{'coursecategories'}{'togglecatscomm'} = $env{'form.togglecatscomm'};
6695: }
6696: if ($domconfig{'coursecategories'}{'categorizecomm'} ne $env{'form.categorizecomm'}) {
6697: $changes{'categorizecomm'} = 1;
6698: $domconfig{'coursecategories'}{'categorizecomm'} = $env{'form.categorizecomm'};
6699: }
1.57 raeburn 6700: } else {
6701: $changes{'togglecats'} = 1;
6702: $changes{'categorize'} = 1;
1.124 raeburn 6703: $changes{'togglecatscomm'} = 1;
6704: $changes{'categorizecomm'} = 1;
1.87 raeburn 6705: $domconfig{'coursecategories'} = {
6706: togglecats => $env{'form.togglecats'},
6707: categorize => $env{'form.categorize'},
1.124 raeburn 6708: togglecatscomm => $env{'form.togglecatscomm'},
6709: categorizecomm => $env{'form.categorizecomm'},
1.120 raeburn 6710: };
1.57 raeburn 6711: }
6712: if (ref($cathash) eq 'HASH') {
6713: if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '') && ($env{'form.instcode'} == 0)) {
1.55 raeburn 6714: push (@deletecategory,'instcode::0');
6715: }
1.120 raeburn 6716: if (($domconfig{'coursecategories'}{'cats'}{'communities::0'} ne '') && ($env{'form.communities'} == 0)) {
6717: push(@deletecategory,'communities::0');
6718: }
1.48 raeburn 6719: }
1.57 raeburn 6720: my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
6721: if (ref($cathash) eq 'HASH') {
1.48 raeburn 6722: if (@deletecategory > 0) {
6723: #FIXME Need to remove category from all courses using a deleted category
1.57 raeburn 6724: &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
1.48 raeburn 6725: foreach my $item (@deletecategory) {
1.57 raeburn 6726: if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
6727: delete($domconfig{'coursecategories'}{'cats'}{$item});
1.48 raeburn 6728: $deletions{$item} = 1;
1.57 raeburn 6729: &recurse_cat_deletes($item,$cathash,\%deletions);
1.48 raeburn 6730: }
6731: }
6732: }
1.57 raeburn 6733: foreach my $item (keys(%{$cathash})) {
1.48 raeburn 6734: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
1.57 raeburn 6735: if ($cathash->{$item} ne $env{'form.'.$item}) {
1.48 raeburn 6736: $reorderings{$item} = 1;
1.57 raeburn 6737: $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
1.48 raeburn 6738: }
6739: if ($env{'form.addcategory_name_'.$item} ne '') {
6740: my $newcat = $env{'form.addcategory_name_'.$item};
6741: my $newdepth = $depth+1;
6742: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 6743: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
1.48 raeburn 6744: $adds{$newitem} = 1;
6745: }
6746: if ($env{'form.subcat_'.$item} ne '') {
6747: my $newcat = $env{'form.subcat_'.$item};
6748: my $newdepth = $depth+1;
6749: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 6750: $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
1.48 raeburn 6751: $adds{$newitem} = 1;
6752: }
6753: }
6754: }
6755: if ($env{'form.instcode'} eq '1') {
1.57 raeburn 6756: if (ref($cathash) eq 'HASH') {
1.48 raeburn 6757: my $newitem = 'instcode::0';
1.57 raeburn 6758: if ($cathash->{$newitem} eq '') {
6759: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 6760: $adds{$newitem} = 1;
6761: }
6762: } else {
6763: my $newitem = 'instcode::0';
1.57 raeburn 6764: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 6765: $adds{$newitem} = 1;
6766: }
6767: }
1.120 raeburn 6768: if ($env{'form.communities'} eq '1') {
6769: if (ref($cathash) eq 'HASH') {
6770: my $newitem = 'communities::0';
6771: if ($cathash->{$newitem} eq '') {
6772: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
6773: $adds{$newitem} = 1;
6774: }
6775: } else {
6776: my $newitem = 'communities::0';
6777: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
6778: $adds{$newitem} = 1;
6779: }
6780: }
1.48 raeburn 6781: if ($env{'form.addcategory_name'} ne '') {
1.120 raeburn 6782: if (($env{'form.addcategory_name'} ne 'instcode') &&
6783: ($env{'form.addcategory_name'} ne 'communities')) {
6784: my $newitem = &escape($env{'form.addcategory_name'}).'::0';
6785: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
6786: $adds{$newitem} = 1;
6787: }
1.48 raeburn 6788: }
1.57 raeburn 6789: my $putresult;
1.48 raeburn 6790: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
6791: if (keys(%deletions) > 0) {
6792: foreach my $key (keys(%deletions)) {
6793: if ($predelallitems{$key} ne '') {
6794: $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
6795: }
6796: }
6797: }
6798: my (@chkcats,@chktrails,%chkallitems);
1.57 raeburn 6799: &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
1.48 raeburn 6800: if (ref($chkcats[0]) eq 'ARRAY') {
6801: my $depth = 0;
6802: my $chg = 0;
6803: for (my $i=0; $i<@{$chkcats[0]}; $i++) {
6804: my $name = $chkcats[0][$i];
6805: my $item;
6806: if ($name eq '') {
6807: $chg ++;
6808: } else {
6809: $item = &escape($name).'::0';
6810: if ($chg) {
1.57 raeburn 6811: $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
1.48 raeburn 6812: }
6813: $depth ++;
1.57 raeburn 6814: &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
1.48 raeburn 6815: $depth --;
6816: }
6817: }
6818: }
1.57 raeburn 6819: }
6820: if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
6821: $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
1.48 raeburn 6822: if ($putresult eq 'ok') {
1.57 raeburn 6823: my %title = (
1.120 raeburn 6824: togglecats => 'Show/Hide a course in catalog',
6825: categorize => 'Assign a category to a course',
6826: togglecatscomm => 'Show/Hide a community in catalog',
6827: categorizecomm => 'Assign a category to a community',
1.57 raeburn 6828: );
6829: my %level = (
1.120 raeburn 6830: dom => 'set in Domain ("Modify Course/Community")',
6831: crs => 'set in Course ("Course Configuration")',
6832: comm => 'set in Community ("Community Configuration")',
1.57 raeburn 6833: );
1.48 raeburn 6834: $resulttext = &mt('Changes made:').'<ul>';
1.57 raeburn 6835: if ($changes{'togglecats'}) {
6836: $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>';
6837: }
6838: if ($changes{'categorize'}) {
6839: $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
1.48 raeburn 6840: }
1.120 raeburn 6841: if ($changes{'togglecatscomm'}) {
6842: $resulttext .= '<li>'.&mt("$title{'togglecatscomm'} $level{$env{'form.togglecatscomm'}}").'</li>';
6843: }
6844: if ($changes{'categorizecomm'}) {
6845: $resulttext .= '<li>'.&mt("$title{'categorizecomm'} $level{$env{'form.categorizecomm'}}").'</li>';
6846: }
1.57 raeburn 6847: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
6848: my $cathash;
6849: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
6850: $cathash = $domconfig{'coursecategories'}{'cats'};
6851: } else {
6852: $cathash = {};
6853: }
6854: my (@cats,@trails,%allitems);
6855: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
6856: if (keys(%deletions) > 0) {
6857: $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
6858: foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) {
6859: $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
6860: }
6861: $resulttext .= '</ul></li>';
6862: }
6863: if (keys(%reorderings) > 0) {
6864: my %sort_by_trail;
6865: $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
6866: foreach my $key (keys(%reorderings)) {
6867: if ($allitems{$key} ne '') {
6868: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
6869: }
1.48 raeburn 6870: }
1.57 raeburn 6871: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
6872: $resulttext .= '<li>'.$trails[$trail].'</li>';
6873: }
6874: $resulttext .= '</ul></li>';
1.48 raeburn 6875: }
1.57 raeburn 6876: if (keys(%adds) > 0) {
6877: my %sort_by_trail;
6878: $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
6879: foreach my $key (keys(%adds)) {
6880: if ($allitems{$key} ne '') {
6881: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
6882: }
6883: }
6884: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
6885: $resulttext .= '<li>'.$trails[$trail].'</li>';
1.48 raeburn 6886: }
1.57 raeburn 6887: $resulttext .= '</ul></li>';
1.48 raeburn 6888: }
6889: }
6890: $resulttext .= '</ul>';
6891: } else {
6892: $resulttext = '<span class="LC_error">'.
1.57 raeburn 6893: &mt('An error occurred: [_1]',$putresult).'</span>';
1.48 raeburn 6894: }
6895: } else {
1.120 raeburn 6896: $resulttext = &mt('No changes made to course and community categories');
1.48 raeburn 6897: }
6898: return $resulttext;
6899: }
6900:
1.69 raeburn 6901: sub modify_serverstatuses {
6902: my ($dom,%domconfig) = @_;
6903: my ($resulttext,%changes,%currserverstatus,%newserverstatus);
6904: if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
6905: %currserverstatus = %{$domconfig{'serverstatuses'}};
6906: }
6907: my @pages = &serverstatus_pages();
6908: foreach my $type (@pages) {
6909: $newserverstatus{$type}{'namedusers'} = '';
6910: $newserverstatus{$type}{'machines'} = '';
6911: if (defined($env{'form.'.$type.'_namedusers'})) {
6912: my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
6913: my @okusers;
6914: foreach my $user (@users) {
6915: my ($uname,$udom) = split(/:/,$user);
6916: if (($udom =~ /^$match_domain$/) &&
6917: (&Apache::lonnet::domain($udom)) &&
6918: ($uname =~ /^$match_username$/)) {
6919: if (!grep(/^\Q$user\E/,@okusers)) {
6920: push(@okusers,$user);
6921: }
6922: }
6923: }
6924: if (@okusers > 0) {
6925: @okusers = sort(@okusers);
6926: $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
6927: }
6928: }
6929: if (defined($env{'form.'.$type.'_machines'})) {
6930: my @machines = split(/,/,$env{'form.'.$type.'_machines'});
6931: my @okmachines;
6932: foreach my $ip (@machines) {
6933: my @parts = split(/\./,$ip);
6934: next if (@parts < 4);
6935: my $badip = 0;
6936: for (my $i=0; $i<4; $i++) {
6937: if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
6938: $badip = 1;
6939: last;
6940: }
6941: }
6942: if (!$badip) {
6943: push(@okmachines,$ip);
6944: }
6945: }
6946: @okmachines = sort(@okmachines);
6947: $newserverstatus{$type}{'machines'} = join(',',@okmachines);
6948: }
6949: }
6950: my %serverstatushash = (
6951: serverstatuses => \%newserverstatus,
6952: );
6953: foreach my $type (@pages) {
1.83 raeburn 6954: foreach my $setting ('namedusers','machines') {
1.84 raeburn 6955: my (@current,@new);
1.83 raeburn 6956: if (ref($currserverstatus{$type}) eq 'HASH') {
1.84 raeburn 6957: if ($currserverstatus{$type}{$setting} ne '') {
6958: @current = split(/,/,$currserverstatus{$type}{$setting});
6959: }
6960: }
6961: if ($newserverstatus{$type}{$setting} ne '') {
6962: @new = split(/,/,$newserverstatus{$type}{$setting});
1.83 raeburn 6963: }
6964: if (@current > 0) {
6965: if (@new > 0) {
6966: foreach my $item (@current) {
6967: if (!grep(/^\Q$item\E$/,@new)) {
6968: $changes{$type}{$setting} = 1;
1.82 raeburn 6969: last;
6970: }
6971: }
1.84 raeburn 6972: foreach my $item (@new) {
6973: if (!grep(/^\Q$item\E$/,@current)) {
6974: $changes{$type}{$setting} = 1;
6975: last;
1.82 raeburn 6976: }
6977: }
6978: } else {
1.83 raeburn 6979: $changes{$type}{$setting} = 1;
1.69 raeburn 6980: }
1.83 raeburn 6981: } elsif (@new > 0) {
6982: $changes{$type}{$setting} = 1;
1.69 raeburn 6983: }
6984: }
6985: }
6986: if (keys(%changes) > 0) {
1.81 raeburn 6987: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 6988: my $putresult = &Apache::lonnet::put_dom('configuration',
6989: \%serverstatushash,$dom);
6990: if ($putresult eq 'ok') {
6991: $resulttext .= &mt('Changes made:').'<ul>';
6992: foreach my $type (@pages) {
1.84 raeburn 6993: if (ref($changes{$type}) eq 'HASH') {
1.69 raeburn 6994: $resulttext .= '<li>'.$titles->{$type}.'<ul>';
1.84 raeburn 6995: if ($changes{$type}{'namedusers'}) {
1.69 raeburn 6996: if ($newserverstatus{$type}{'namedusers'} eq '') {
6997: $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n";
6998: } else {
6999: $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n";
7000: }
1.84 raeburn 7001: }
7002: if ($changes{$type}{'machines'}) {
1.69 raeburn 7003: if ($newserverstatus{$type}{'machines'} eq '') {
7004: $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n";
7005: } else {
7006: $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n";
7007: }
7008:
7009: }
7010: $resulttext .= '</ul></li>';
7011: }
7012: }
7013: $resulttext .= '</ul>';
7014: } else {
7015: $resulttext = '<span class="LC_error">'.
7016: &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>';
7017:
7018: }
7019: } else {
7020: $resulttext = &mt('No changes made to access to server status pages');
7021: }
7022: return $resulttext;
7023: }
7024:
1.118 jms 7025: sub modify_helpsettings {
1.122 jms 7026: my ($r,$dom,$confname,%domconfig) = @_;
1.118 jms 7027: my ($resulttext,$errors,%changes,%helphash);
7028:
1.122 jms 7029: my $customhelpfile = $env{'form.loginhelpurl.filename'};
7030: my $defaulthelpfile = 'defaulthelp.html';
7031: my $servadm = $r->dir_config('lonAdmEMail');
7032: my ($configuserok,$author_ok,$switchserver) =
7033: &config_check($dom,$confname,$servadm);
7034:
1.118 jms 7035: my %defaultchecked = ('submitbugs' => 'on');
7036: my @offon = ('off','on');
1.122 jms 7037: my %title = ( submitbugs => 'Display link for users to submit a bug',
7038: loginhelpurl => 'Unauthenticated login help page set to custom file');
7039:
1.118 jms 7040: my @toggles = ('submitbugs');
7041:
7042: $helphash{'helpsettings'} = {};
7043:
7044: if (ref($domconfig{'helpsettings'}) ne 'HASH') {
7045: if ($domconfig{'helpsettings'} eq '') {
7046: $domconfig{'helpsettings'} = {};
7047: }
7048: }
7049:
7050: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
7051:
7052: foreach my $item (@toggles) {
7053:
7054: if ($defaultchecked{$item} eq 'on') {
7055: if (($domconfig{'helpsettings'}{$item} eq '') &&
7056: ($env{'form.'.$item} eq '0')) {
7057: $changes{$item} = 1;
7058: } elsif ($domconfig{'helpsettings'}{$item} ne $env{'form.'.$item}) {
7059: $changes{$item} = 1;
7060: }
7061: } elsif ($defaultchecked{$item} eq 'off') {
7062: if (($domconfig{'helpsettings'}{$item} eq '') &&
7063: ($env{'form.'.$item} eq '1')) {
7064: $changes{$item} = 1;
7065: } elsif ($domconfig{'helpsettings'}{$item} ne $env{'form.'.$item}) {
7066: $changes{$item} = 1;
7067: }
7068: }
7069: $helphash{'helpsettings'}{$item} = $env{'form.'.$item};
1.122 jms 7070: }
7071:
7072: if ($customhelpfile ne '') {
7073: my $error;
7074: if ($configuserok eq 'ok') {
7075: if ($switchserver) {
7076: $error = &mt("Upload of custom help file is not permitted to this server: [_1]",$switchserver);
7077: } else {
7078: if ($author_ok eq 'ok') {
7079: my ($result,$loginhelpurl) =
7080: &publishlogo($r,'upload','loginhelpurl',$dom,
7081: $confname,'help','','',$customhelpfile);
7082: if ($result eq 'ok') {
7083: $helphash{'helpsettings'}{'loginhelpurl'} = $loginhelpurl;
7084: $changes{'loginhelpurl'} = 1;
7085: } else {
7086: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$customhelpfile,$result);
7087: }
7088: } else {
7089: $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);
7090: }
7091: }
7092: } else {
7093: $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);
7094: }
7095: if ($error) {
7096: &Apache::lonnet::logthis($error);
7097: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
7098: }
7099: }
7100:
7101: if ($domconfig{'helpsettings'}{'loginhelpurl'} ne '') {
7102: if ($env{'form.loginhelpurl_del'}) {
7103: $helphash{'helpsettings'}{'loginhelpurl'} = '';
7104: $changes{'loginhelpurl'} = 1;
7105: }
7106: }
1.118 jms 7107: }
7108:
1.123 jms 7109:
7110: my $putresult;
7111:
7112: if (keys(%changes) > 0) {
7113: $putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom);
7114: } else {
7115: $putresult = 'ok';
7116: }
1.118 jms 7117:
7118: if ($putresult eq 'ok') {
7119: if (keys(%changes) > 0) {
7120: $resulttext = &mt('Changes made:').'<ul>';
7121: foreach my $item (sort(keys(%changes))) {
7122: if ($item eq 'submitbugs') {
7123: $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
7124: }
1.122 jms 7125: if ($item eq 'loginhelpurl') {
7126: if ($helphash{'helpsettings'}{'loginhelpurl'} eq '') {
7127: $resulttext .= '<li>'.&mt('[_1] help file removed; [_2] file will be used for the unathorized help page in this domain.',$customhelpfile,$defaulthelpfile).'</li>';
7128: } else {
7129: $resulttext .= '<li>'.&mt("$title{$item} [_1]",$customhelpfile).'</li>';
7130: }
7131: }
1.118 jms 7132: }
7133: $resulttext .= '</ul>';
7134: } else {
7135: $resulttext = &mt('No changes made to help settings');
7136: }
7137: } else {
7138: $resulttext = '<span class="LC_error">'.
7139: &mt('An error occurred: [_1]',$putresult).'</span>';
7140: }
7141: if ($errors) {
7142: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
7143: $errors.'</ul>';
7144: }
7145: return $resulttext;
7146: }
7147:
1.121 raeburn 7148: sub modify_coursedefaults {
7149: my ($dom,%domconfig) = @_;
7150: my ($resulttext,$errors,%changes,%defaultshash);
7151: my %defaultchecked = ('canuse_pdfforms' => 'off');
7152: my @offon = ('off','on');
7153: my @toggles = ('canuse_pdfforms');
7154:
7155: $defaultshash{'coursedefaults'} = {};
7156:
7157: if (ref($domconfig{'coursedefaults'}) ne 'HASH') {
7158: if ($domconfig{'coursedefaults'} eq '') {
7159: $domconfig{'coursedefaults'} = {};
7160: }
7161: }
7162:
7163: if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
7164: foreach my $item (@toggles) {
7165: if ($defaultchecked{$item} eq 'on') {
7166: if (($domconfig{'coursedefaults'}{$item} eq '') &&
7167: ($env{'form.'.$item} eq '0')) {
7168: $changes{$item} = 1;
7169: } elsif ($domconfig{'coursdefaults'}{$item} ne $env{'form.'.$item}) {
7170: $changes{$item} = 1;
7171: }
7172: } elsif ($defaultchecked{$item} eq 'off') {
7173: if (($domconfig{'coursedefaults'}{$item} eq '') &&
7174: ($env{'form.'.$item} eq '1')) {
7175: $changes{$item} = 1;
7176: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
7177: $changes{$item} = 1;
7178: }
7179: }
7180: $defaultshash{'coursedefaults'}{$item} = $env{'form.'.$item};
7181: }
1.139 raeburn 7182: my $currdefresponder = $domconfig{'coursedefaults'}{'anonsurvey_threshold'};
7183: my $newdefresponder = $env{'form.anonsurvey_threshold'};
7184: $newdefresponder =~ s/\D//g;
7185: if ($newdefresponder eq '' || $newdefresponder < 1) {
7186: $newdefresponder = 1;
7187: }
7188: $defaultshash{'coursedefaults'}{'anonsurvey_threshold'} = $newdefresponder;
7189: if ($currdefresponder ne $newdefresponder) {
7190: unless ($currdefresponder eq '' && $newdefresponder == 10) {
7191: $changes{'anonsurvey_threshold'} = 1;
7192: }
7193: }
1.121 raeburn 7194: }
7195: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
7196: $dom);
7197: if ($putresult eq 'ok') {
7198: if (keys(%changes) > 0) {
7199: if ($changes{'canuse_pdfforms'}) {
7200: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
7201: $domdefaults{'canuse_pdfforms'}=$defaultshash{'coursedefaults'}{'canuse_pdfforms'};
7202: my $cachetime = 24*60*60;
7203: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
7204: }
7205: $resulttext = &mt('Changes made:').'<ul>';
7206: foreach my $item (sort(keys(%changes))) {
7207: if ($item eq 'canuse_pdfforms') {
7208: if ($env{'form.'.$item} eq '1') {
7209: $resulttext .= '<li>'.&mt("Course/Community users can create/upload PDF forms set to 'on'").'</li>';
7210: } else {
7211: $resulttext .= '<li>'.&mt('Course/Community users can create/upload PDF forms set to "off"').'</li>';
7212: }
1.139 raeburn 7213: } elsif ($item eq 'anonsurvey_threshold') {
7214: $resulttext .= '<li>'.&mt('Responder count required for display of anonymous survey submissions set to [_1].',$defaultshash{'coursedefaults'}{'anonsurvey_threshold'}).'</li>';
1.140 raeburn 7215: }
1.121 raeburn 7216: }
7217: $resulttext .= '</ul>';
7218: } else {
7219: $resulttext = &mt('No changes made to course defaults');
7220: }
7221: } else {
7222: $resulttext = '<span class="LC_error">'.
7223: &mt('An error occurred: [_1]',$putresult).'</span>';
7224: }
7225: return $resulttext;
7226: }
7227:
1.137 raeburn 7228: sub modify_usersessions {
7229: my ($dom,%domconfig) = @_;
1.145 raeburn 7230: my @hostingtypes = ('version','excludedomain','includedomain');
7231: my @offloadtypes = ('primary','default');
7232: my %types = (
7233: remote => \@hostingtypes,
7234: hosted => \@hostingtypes,
7235: spares => \@offloadtypes,
7236: );
7237: my @prefixes = ('remote','hosted','spares');
1.137 raeburn 7238: my @lcversions = &Apache::lonnet::all_loncaparevs();
1.138 raeburn 7239: my (%by_ip,%by_location,@intdoms);
7240: &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
7241: my @locations = sort(keys(%by_location));
1.137 raeburn 7242: my (%defaultshash,%changes);
7243: foreach my $prefix (@prefixes) {
7244: $defaultshash{'usersessions'}{$prefix} = {};
7245: }
7246: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
7247: my $resulttext;
1.138 raeburn 7248: my %iphost = &Apache::lonnet::get_iphost();
1.137 raeburn 7249: foreach my $prefix (@prefixes) {
1.145 raeburn 7250: next if ($prefix eq 'spares');
7251: foreach my $type (@{$types{$prefix}}) {
1.137 raeburn 7252: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
7253: if ($type eq 'version') {
7254: my $value = $env{'form.'.$prefix.'_'.$type};
7255: my $okvalue;
7256: if ($value ne '') {
7257: if (grep(/^\Q$value\E$/,@lcversions)) {
7258: $okvalue = $value;
7259: }
7260: }
7261: if (ref($domconfig{'usersessions'}) eq 'HASH') {
7262: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
7263: if ($domconfig{'usersessions'}{$prefix}{$type} ne '') {
7264: if ($inuse == 0) {
7265: $changes{$prefix}{$type} = 1;
7266: } else {
7267: if ($okvalue ne $domconfig{'usersessions'}{$prefix}{$type}) {
7268: $changes{$prefix}{$type} = 1;
7269: }
7270: if ($okvalue ne '') {
7271: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
7272: }
7273: }
7274: } else {
7275: if (($inuse == 1) && ($okvalue ne '')) {
7276: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
7277: $changes{$prefix}{$type} = 1;
7278: }
7279: }
7280: } else {
7281: if (($inuse == 1) && ($okvalue ne '')) {
7282: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
7283: $changes{$prefix}{$type} = 1;
7284: }
7285: }
7286: } else {
7287: if (($inuse == 1) && ($okvalue ne '')) {
7288: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
7289: $changes{$prefix}{$type} = 1;
7290: }
7291: }
7292: } else {
7293: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
7294: my @okvals;
7295: foreach my $val (@vals) {
1.138 raeburn 7296: if ($val =~ /:/) {
7297: my @items = split(/:/,$val);
7298: foreach my $item (@items) {
7299: if (ref($by_location{$item}) eq 'ARRAY') {
7300: push(@okvals,$item);
7301: }
7302: }
7303: } else {
7304: if (ref($by_location{$val}) eq 'ARRAY') {
7305: push(@okvals,$val);
7306: }
1.137 raeburn 7307: }
7308: }
7309: @okvals = sort(@okvals);
7310: if (ref($domconfig{'usersessions'}) eq 'HASH') {
7311: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
7312: if (ref($domconfig{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
7313: if ($inuse == 0) {
7314: $changes{$prefix}{$type} = 1;
7315: } else {
7316: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
7317: my @changed = &Apache::loncommon::compare_arrays($domconfig{'usersessions'}{$prefix}{$type},$defaultshash{'usersessions'}{$prefix}{$type});
7318: if (@changed > 0) {
7319: $changes{$prefix}{$type} = 1;
7320: }
7321: }
7322: } else {
7323: if ($inuse == 1) {
7324: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
7325: $changes{$prefix}{$type} = 1;
7326: }
7327: }
7328: } else {
7329: if ($inuse == 1) {
7330: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
7331: $changes{$prefix}{$type} = 1;
7332: }
7333: }
7334: } else {
7335: if ($inuse == 1) {
7336: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
7337: $changes{$prefix}{$type} = 1;
7338: }
7339: }
7340: }
7341: }
7342: }
1.145 raeburn 7343:
7344: my @alldoms = &Apache::lonnet::all_domains();
7345: my %uniques = &Apache::lonnet::get_unique_servers(\@alldoms);
1.149 raeburn 7346: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.145 raeburn 7347: my %spareid = ¤t_offloads_to($dom,$domconfig{'usersessions'},\%servers);
7348: my $savespares;
7349:
7350: foreach my $lonhost (sort(keys(%servers))) {
7351: my $serverhomeID =
7352: &Apache::lonnet::get_server_homeID($servers{$lonhost});
7353: $defaultshash{'usersessions'}{'spares'}{$lonhost} = {};
7354: my %spareschg;
7355: foreach my $type (@{$types{'spares'}}) {
7356: my @okspares;
7357: my @checked = &Apache::loncommon::get_env_multiple('form.spare_'.$type.'_'.$lonhost);
7358: foreach my $server (@checked) {
7359: unless (($server eq $lonhost) || ($server eq $serverhomeID)) {
7360: if ($uniques{$server}) {
7361: push(@okspares,$server);
7362: }
7363: }
7364: }
7365: my $new = $env{'form.newspare_'.$type.'_'.$lonhost};
7366: my $newspare;
7367: if (($new ne '') && ($uniques{$new})) {
7368: unless (($new eq $lonhost) || ($new eq $serverhomeID)) {
7369: $newspare = $new;
7370: $spareschg{$type} = 1;
7371: }
7372: }
7373: if (ref($spareid{$lonhost}) eq 'HASH') {
7374: if (ref($spareid{$lonhost}{$type}) eq 'ARRAY') {
7375: my @diffs = &Apache::loncommon::compare_arrays($domconfig{'usersessions'}{'spares'}{$lonhost}{$type},\@okspares);
7376: if (@diffs > 0) {
7377: $spareschg{$type} = 1;
7378: } elsif ($new ne '') {
7379: $spareschg{$type} = 1;
7380: }
7381: }
7382: }
1.146 raeburn 7383: my @spares;
7384: if (($newspare ne '') && (!grep(/^\Q$newspare\E$/,@okspares))) {
7385: @spares = sort(@okspares,$newspare);
7386: } else {
7387: @spares = sort(@okspares);
7388: }
1.145 raeburn 7389: $defaultshash{'usersessions'}{'spares'}{$lonhost}{$type} = \@spares;
7390: }
7391: if (keys(%spareschg) > 0) {
7392: $changes{'spares'}{$lonhost} = \%spareschg;
7393: }
7394: }
7395:
7396: if (ref($domconfig{'usersessions'}) eq 'HASH') {
7397: if (ref($domconfig{'usersessions'}{'spares'}) eq 'HASH') {
7398: if (ref($changes{'spares'}) eq 'HASH') {
7399: if (keys(%{$changes{'spares'}}) > 0) {
7400: $savespares = 1;
7401: }
7402: }
7403: } else {
7404: $savespares = 1;
7405: }
7406: }
7407:
1.147 raeburn 7408: my $nochgmsg = &mt('No changes made to settings for user session hosting/offloading.');
7409: if ((keys(%changes) > 0) || ($savespares)) {
1.137 raeburn 7410: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
7411: $dom);
7412: if ($putresult eq 'ok') {
7413: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
7414: if (ref($defaultshash{'usersessions'}{'remote'}) eq 'HASH') {
7415: $domdefaults{'remotesessions'} = $defaultshash{'usersessions'}{'remote'};
7416: }
7417: if (ref($defaultshash{'usersessions'}{'hosted'}) eq 'HASH') {
7418: $domdefaults{'hostedsessions'} = $defaultshash{'usersessions'}{'hosted'};
7419: }
7420: }
7421: my $cachetime = 24*60*60;
7422: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.147 raeburn 7423: if (keys(%changes) > 0) {
7424: my %lt = &usersession_titles();
7425: $resulttext = &mt('Changes made:').'<ul>';
7426: foreach my $prefix (@prefixes) {
7427: if (ref($changes{$prefix}) eq 'HASH') {
7428: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
7429: if ($prefix eq 'spares') {
7430: if (ref($changes{$prefix}) eq 'HASH') {
7431: foreach my $lonhost (sort(keys(%{$changes{$prefix}}))) {
7432: $resulttext .= '<li><b>'.$lonhost.'</b> ';
1.148 raeburn 7433: my $lonhostdom = &Apache::lonnet::host_domain($lonhost);
7434: &Apache::lonnet::remote_devalidate_cache($lonhost,'spares',$lonhostdom);
1.147 raeburn 7435: if (ref($changes{$prefix}{$lonhost}) eq 'HASH') {
7436: foreach my $type (@{$types{$prefix}}) {
7437: if ($changes{$prefix}{$lonhost}{$type}) {
7438: my $offloadto = &mt('None');
7439: if (ref($defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}) eq 'ARRAY') {
7440: if (@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}} > 0) {
7441: $offloadto = join(', ',@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}});
7442: }
1.145 raeburn 7443: }
1.147 raeburn 7444: $resulttext .= &mt('[_1] set to: [_2].','<i>'.$lt{$type}.'</i>',$offloadto).(' 'x3);
1.145 raeburn 7445: }
1.137 raeburn 7446: }
7447: }
1.147 raeburn 7448: $resulttext .= '</li>';
1.137 raeburn 7449: }
7450: }
1.147 raeburn 7451: } else {
7452: foreach my $type (@{$types{$prefix}}) {
7453: if (defined($changes{$prefix}{$type})) {
7454: my $newvalue;
7455: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
7456: if (ref($defaultshash{'usersessions'}{$prefix})) {
7457: if ($type eq 'version') {
7458: $newvalue = $defaultshash{'usersessions'}{$prefix}{$type};
7459: } elsif (ref($defaultshash{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
7460: if (@{$defaultshash{'usersessions'}{$prefix}{$type}} > 0) {
7461: $newvalue = join(', ',@{$defaultshash{'usersessions'}{$prefix}{$type}});
7462: }
1.145 raeburn 7463: }
7464: }
7465: }
1.147 raeburn 7466: if ($newvalue eq '') {
7467: if ($type eq 'version') {
7468: $resulttext .= '<li>'.&mt('[_1] set to: off',$lt{$type}).'</li>';
7469: } else {
7470: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
7471: }
1.145 raeburn 7472: } else {
1.147 raeburn 7473: if ($type eq 'version') {
7474: $newvalue .= ' '.&mt('(or later)');
7475: }
7476: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
1.145 raeburn 7477: }
1.137 raeburn 7478: }
7479: }
7480: }
1.147 raeburn 7481: $resulttext .= '</ul>';
1.137 raeburn 7482: }
7483: }
1.147 raeburn 7484: $resulttext .= '</ul>';
7485: } else {
7486: $resulttext = $nochgmsg;
1.137 raeburn 7487: }
7488: } else {
7489: $resulttext = '<span class="LC_error">'.
7490: &mt('An error occurred: [_1]',$putresult).'</span>';
7491: }
7492: } else {
1.147 raeburn 7493: $resulttext = $nochgmsg;
1.137 raeburn 7494: }
7495: return $resulttext;
7496: }
7497:
1.150 ! raeburn 7498: sub modify_loadbalancing {
! 7499: my ($dom,%domconfig) = @_;
! 7500: my $primary_id = &Apache::lonnet::domain($dom,'primary');
! 7501: my $intdom = &Apache::lonnet::internet_dom($primary_id);
! 7502: my ($othertitle,$usertypes,$types) =
! 7503: &Apache::loncommon::sorted_inst_types($dom);
! 7504: my %servers = &Apache::lonnet::internet_dom_servers($dom);
! 7505: my @sparestypes = ('primary','default');
! 7506: my %typetitles = &sparestype_titles();
! 7507: my $resulttext;
! 7508: if (keys(%servers) > 1) {
! 7509: my ($currbalancer,$currtargets,$currrules);
! 7510: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
! 7511: $currbalancer = $domconfig{'loadbalancing'}{'lonhost'};
! 7512: $currtargets = $domconfig{'loadbalancing'}{'targets'};
! 7513: $currrules = $domconfig{'loadbalancing'}{'rules'};
! 7514: } else {
! 7515: ($currbalancer,$currtargets) =
! 7516: &Apache::lonnet::get_lonbalancer_config(\%servers);
! 7517: }
! 7518: my ($saveloadbalancing,%defaultshash,%changes);
! 7519: my ($alltypes,$othertypes,$titles) =
! 7520: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
! 7521: my %ruletitles = &offloadtype_text();
! 7522: my $balancer = $env{'form.loadbalancing_lonhost'};
! 7523: if (!$servers{$balancer}) {
! 7524: undef($balancer);
! 7525: }
! 7526: if ($currbalancer ne $balancer) {
! 7527: $changes{'lonhost'} = 1;
! 7528: }
! 7529: $defaultshash{'loadbalancing'}{'lonhost'} = $balancer;
! 7530: if ($balancer ne '') {
! 7531: unless (ref($domconfig{'loadbalancing'}) eq 'HASH') {
! 7532: $saveloadbalancing = 1;
! 7533: }
! 7534: foreach my $sparetype (@sparestypes) {
! 7535: my @targets = &Apache::loncommon::get_env_multiple('form.loadbalancing_target_'.$sparetype);
! 7536: foreach my $target (@targets) {
! 7537: my @offloadto;
! 7538: if (($servers{$target}) && ($target ne $balancer)) {
! 7539: if ($sparetype eq 'default') {
! 7540: if (ref($defaultshash{'loadbalancing'}{'targets'}{'primary'}) eq 'ARRAY') {
! 7541: next if (grep(/^\Q$target\E$/,@{$defaultshash{'loadbalancing'}{'targets'}{'primary'}}));
! 7542: }
! 7543: }
! 7544: unless(grep(/^\Q$target\E$/,@offloadto)) {
! 7545: push(@offloadto,$target);
! 7546: }
! 7547: }
! 7548: $defaultshash{'loadbalancing'}{'targets'}{$sparetype} = \@offloadto;
! 7549: }
! 7550: }
! 7551: } else {
! 7552: foreach my $sparetype (@sparestypes) {
! 7553: $defaultshash{'loadbalancing'}{'targets'}{$sparetype} = [];
! 7554: }
! 7555: }
! 7556: if (ref($currtargets) eq 'HASH') {
! 7557: foreach my $sparetype (@sparestypes) {
! 7558: if (ref($currtargets->{$sparetype}) eq 'ARRAY') {
! 7559: my @targetdiffs = &Apache::loncommon::compare_arrays($currtargets->{$sparetype},$defaultshash{'loadbalancing'}{'targets'}{$sparetype});
! 7560: if (@targetdiffs > 0) {
! 7561: $changes{'targets'} = 1;
! 7562: }
! 7563: } elsif (ref($defaultshash{'loadbalancing'}{'targets'}{$sparetype}) eq 'ARRAY') {
! 7564: if (@{$defaultshash{'loadbalancing'}{'targets'}{$sparetype}} > 0) {
! 7565: $changes{'targets'} = 1;
! 7566: }
! 7567: }
! 7568: }
! 7569: } else {
! 7570: foreach my $sparetype (@sparestypes) {
! 7571: if (ref($defaultshash{'loadbalancing'}{'targets'}{$sparetype}) eq 'ARRAY') {
! 7572: if (@{$defaultshash{'loadbalancing'}{'targets'}{$sparetype}} > 0) {
! 7573: $changes{'targets'} = 1;
! 7574: }
! 7575: }
! 7576: }
! 7577: }
! 7578: my $ishomedom;
! 7579: if ($balancer ne '') {
! 7580: if (&Apache::lonnet::host_domain($balancer) eq $dom) {
! 7581: $ishomedom = 1;
! 7582: }
! 7583: }
! 7584: if (ref($alltypes) eq 'ARRAY') {
! 7585: foreach my $type (@{$alltypes}) {
! 7586: my $rule;
! 7587: if ($balancer ne '') {
! 7588: unless ((($type eq '_LC_external') || ($type eq '_LC_internetdom')) &&
! 7589: (!$ishomedom)) {
! 7590: $rule = $env{'form.loadbalancing_rules_'.$type};
! 7591: }
! 7592: if ($rule eq 'specific') {
! 7593: $rule = $env{'form.loadbalancing_singleserver_'.$type};
! 7594: }
! 7595: }
! 7596: $defaultshash{'loadbalancing'}{'rules'}{$type} = $rule;
! 7597: if (ref($currrules) eq 'HASH') {
! 7598: if ($rule ne $currrules->{$type}) {
! 7599: $changes{'rules'}{$type} = 1;
! 7600: }
! 7601: } elsif ($rule ne '') {
! 7602: $changes{'rules'}{$type} = 1;
! 7603: }
! 7604: }
! 7605: }
! 7606: my $nochgmsg = &mt('No changes made to Load Balancer settings.');
! 7607: if ((keys(%changes) > 0) || ($saveloadbalancing)) {
! 7608: my $putresult = &Apache::lonnet::put_dom('configuration',
! 7609: \%defaultshash,$dom);
! 7610: if ($putresult eq 'ok') {
! 7611: if (keys(%changes) > 0) {
! 7612: if ($changes{'lonhost'}) {
! 7613: if ($currbalancer ne '') {
! 7614: &Apache::lonnet::remote_devalidate_cache($currbalancer,'loadbalancing',$dom);
! 7615: }
! 7616: if ($balancer eq '') {
! 7617: $resulttext .= '<li>'.&mt('Load Balancing with dedicated server discontinued').'</li>';
! 7618: } else {
! 7619: &Apache::lonnet::remote_devalidate_cache($balancer,'loadbalancing',$dom);
! 7620: $resulttext .= '<li>'.&mt('Dedicated Load Balancer server set to [_1]',$balancer);
! 7621: }
! 7622: } else {
! 7623: &Apache::lonnet::remote_devalidate_cache($balancer,'loadbalancing',$dom);
! 7624: }
! 7625: if (($changes{'targets'}) && ($balancer ne '')) {
! 7626: my %offloadstr;
! 7627: foreach my $sparetype (@sparestypes) {
! 7628: if (ref($defaultshash{'loadbalancing'}{'targets'}{$sparetype}) eq 'ARRAY') {
! 7629: if (@{$defaultshash{'loadbalancing'}{'targets'}{$sparetype}} > 0) {
! 7630: $offloadstr{$sparetype} = join(', ',@{$defaultshash{'loadbalancing'}{'targets'}{$sparetype}});
! 7631: }
! 7632: }
! 7633: }
! 7634: if (keys(%offloadstr) == 0) {
! 7635: $resulttext .= '<li>'.&mt("Servers to which Load Balance server offloads set to 'None', by default").'</li>';
! 7636: } else {
! 7637: my $showoffload;
! 7638: foreach my $sparetype (@sparestypes) {
! 7639: $showoffload .= '<i>'.$typetitles{$sparetype}.'</i>: ';
! 7640: if (defined($offloadstr{$sparetype})) {
! 7641: $showoffload .= $offloadstr{$sparetype};
! 7642: } else {
! 7643: $showoffload .= &mt('None');
! 7644: }
! 7645: $showoffload .= (' 'x3);
! 7646: }
! 7647: $resulttext .= '<li>'.&mt('By default, Load Balancer server set to offload to: [_1]',$showoffload).'</li>';
! 7648: }
! 7649: }
! 7650: if ((ref($changes{'rules'}) eq 'HASH') && ($balancer ne '')) {
! 7651: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
! 7652: foreach my $type (@{$alltypes}) {
! 7653: if ($changes{'rules'}{$type}) {
! 7654: my $rule = $defaultshash{'loadbalancing'}{'rules'}{$type};
! 7655: my $balancetext;
! 7656: if ($rule eq '') {
! 7657: $balancetext = $ruletitles{'default'};
! 7658: } elsif (($rule eq 'homeserver') || ($rule eq 'externalbalancer')) {
! 7659: $balancetext = $ruletitles{$rule};
! 7660: } else {
! 7661: $balancetext = &mt('offload to [_1]',$defaultshash{'loadbalancing'}{'rules'}{$type});
! 7662: }
! 7663: $resulttext .= '<li>'.&mt('Load Balancing for [_1] set to: [_2]',$titles->{$type},$balancetext).'</li>';
! 7664: }
! 7665: }
! 7666: }
! 7667: }
! 7668: if ($resulttext ne '') {
! 7669: $resulttext = &mt('Changes made:').'<ul>'.$resulttext.'</ul>';
! 7670: } else {
! 7671: $resulttext = $nochgmsg;
! 7672: }
! 7673: } else {
! 7674: $resulttext = $nochgmsg;
! 7675: if ($balancer ne '') {
! 7676: &Apache::lonnet::remote_devalidate_cache($balancer,'loadbalancing',$dom);
! 7677: }
! 7678: }
! 7679: } else {
! 7680: $resulttext = '<span class="LC_error">'.
! 7681: &mt('An error occurred: [_1]',$putresult).'</span>';
! 7682: }
! 7683: } else {
! 7684: $resulttext = $nochgmsg;
! 7685: }
! 7686: } else {
! 7687: $resulttext = &mt('Load Balancing unavailable as this domain only has one server.');
! 7688: }
! 7689: return $resulttext;
! 7690: }
! 7691:
1.48 raeburn 7692: sub recurse_check {
7693: my ($chkcats,$categories,$depth,$name) = @_;
7694: if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
7695: my $chg = 0;
7696: for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
7697: my $category = $chkcats->[$depth]{$name}[$j];
7698: my $item;
7699: if ($category eq '') {
7700: $chg ++;
7701: } else {
7702: my $deeper = $depth + 1;
7703: $item = &escape($category).':'.&escape($name).':'.$depth;
7704: if ($chg) {
7705: $categories->{$item} -= $chg;
7706: }
7707: &recurse_check($chkcats,$categories,$deeper,$category);
7708: $deeper --;
7709: }
7710: }
7711: }
7712: return;
7713: }
7714:
7715: sub recurse_cat_deletes {
7716: my ($item,$coursecategories,$deletions) = @_;
7717: my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
7718: my $subdepth = $depth + 1;
7719: if (ref($coursecategories) eq 'HASH') {
7720: foreach my $subitem (keys(%{$coursecategories})) {
7721: my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
7722: if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
7723: delete($coursecategories->{$subitem});
7724: $deletions->{$subitem} = 1;
7725: &recurse_cat_deletes($subitem,$coursecategories,$deletions);
7726: }
7727: }
7728: }
7729: return;
7730: }
7731:
1.125 raeburn 7732: sub get_active_dcs {
7733: my ($dom) = @_;
7734: my %dompersonnel = &Apache::lonnet::get_domain_roles($dom,['dc']);
7735: my %domcoords;
7736: my $numdcs = 0;
7737: my $now = time;
7738: foreach my $server (keys(%dompersonnel)) {
7739: foreach my $user (sort(keys(%{$dompersonnel{$server}}))) {
7740: my ($trole,$uname,$udom,$runame,$rudom,$rsec) = split(/:/,$user);
7741: my ($end,$start) = split(':',$dompersonnel{$server}{$user});
7742: if (($end eq '') || ($end == 0) || ($end > $now)) {
7743: if ($start <= $now) {
7744: $domcoords{$uname.':'.$udom} = $dompersonnel{$server}{$user};
7745: }
7746: }
7747: }
7748: }
7749: return %domcoords;
7750: }
7751:
7752: sub active_dc_picker {
7753: my ($dom,$curr_dc) = @_;
7754: my %domcoords = &get_active_dcs($dom);
7755: my @dcs = sort(keys(%domcoords));
7756: my $numdcs = scalar(@dcs);
7757: my $datatable;
7758: my $numinrow = 2;
7759: if ($numdcs > 1) {
7760: $datatable = '<table>';
7761: for (my $i=0; $i<@dcs; $i++) {
7762: my $rem = $i%($numinrow);
7763: if ($rem == 0) {
7764: if ($i > 0) {
7765: $datatable .= '</tr>';
7766: }
7767: $datatable .= '<tr>';
7768: }
7769: my $check = ' ';
7770: if ($curr_dc eq '') {
7771: if (!$i) {
7772: $check = ' checked="checked" ';
7773: }
7774: } elsif ($dcs[$i] eq $curr_dc) {
7775: $check = ' checked="checked" ';
7776: }
7777: if ($i == @dcs - 1) {
7778: my $colsleft = $numinrow - $rem;
7779: if ($colsleft > 1) {
7780: $datatable .= '<td colspan="'.$colsleft.'">';
7781: } else {
7782: $datatable .= '<td>';
7783: }
7784: } else {
7785: $datatable .= '<td>';
7786: }
7787: my ($dcname,$dcdom) = split(':',$dcs[$i]);
7788: $datatable .= '<span class="LC_nobreak"><label>'.
7789: '<input type="radio" name="autocreate_xmldc"'.
7790: ' value="'.$dcs[$i].'"'.$check.'/>'.
7791: &Apache::loncommon::plainname($dcname,$dcdom).
7792: '</label></span></td>';
7793: }
7794: $datatable .= '</tr></table>';
7795: } elsif (@dcs) {
7796: $datatable .= '<input type="hidden" name="autocreate_dc" value="'.
7797: $dcs[0].'" />';
7798: }
7799: return ($numdcs,$datatable);
7800: }
7801:
1.137 raeburn 7802: sub usersession_titles {
7803: return &Apache::lonlocal::texthash(
7804: hosted => 'Hosting of sessions for users from other domains on servers in this domain',
7805:
7806: remote => 'Hosting of sessions for users in this domain on servers in other domains',
1.145 raeburn 7807: spares => 'Servers offloaded to, when busy',
1.137 raeburn 7808: version => 'LON-CAPA version requirement',
1.138 raeburn 7809: excludedomain => 'Allow all, but exclude specific domains',
7810: includedomain => 'Deny all, but include specific domains',
1.145 raeburn 7811: primary => 'Primary (checked first)',
7812: default => 'Default',
1.137 raeburn 7813: );
7814: }
7815:
1.150 ! raeburn 7816: sub count_servers {
! 7817: my ($currbalancer,%servers) = @_;
! 7818: my (@spares,$numspares);
! 7819: foreach my $lonhost (sort(keys(%servers))) {
! 7820: next if ($currbalancer eq $lonhost);
! 7821: push(@spares,$lonhost);
! 7822: }
! 7823: if ($currbalancer) {
! 7824: $numspares = scalar(@spares);
! 7825: } else {
! 7826: $numspares = scalar(@spares) - 1;
! 7827: }
! 7828: return ($numspares,@spares);
! 7829: }
! 7830:
! 7831: sub lonbalance_targets_js {
! 7832: my ($dom,$types,$servers) = @_;
! 7833: my $select = &mt('Select');
! 7834: my ($alltargets,$allishome,$allinsttypes,@alltypes);
! 7835: if (ref($servers) eq 'HASH') {
! 7836: $alltargets = join("','",sort(keys(%{$servers})));
! 7837: my @homedoms;
! 7838: foreach my $server (sort(keys(%{$servers}))) {
! 7839: if (&Apache::lonnet::host_domain($server) eq $dom) {
! 7840: push(@homedoms,'1');
! 7841: } else {
! 7842: push(@homedoms,'0');
! 7843: }
! 7844: }
! 7845: $allishome = join("','",@homedoms);
! 7846: }
! 7847: if (ref($types) eq 'ARRAY') {
! 7848: if (@{$types} > 0) {
! 7849: @alltypes = @{$types};
! 7850: }
! 7851: }
! 7852: push(@alltypes,'default','_LC_adv','_LC_author','_LC_internetdom','_LC_external');
! 7853: $allinsttypes = join("','",@alltypes);
! 7854: return <<"END";
! 7855:
! 7856: <script type="text/javascript">
! 7857: // <![CDATA[
! 7858:
! 7859: function toggleTargets() {
! 7860: var balancer = document.display.loadbalancing_lonhost.options[document.display.loadbalancing_lonhost.selectedIndex].value;
! 7861: if (balancer == '') {
! 7862: hideSpares();
! 7863: } else {
! 7864: var homedoms = new Array('$allishome');
! 7865: var ishomedom = homedoms[document.display.loadbalancing_lonhost.selectedIndex];
! 7866: showSpares(balancer,ishomedom);
! 7867: }
! 7868: return;
! 7869: }
! 7870:
! 7871: function showSpares(balancer,ishomedom) {
! 7872: var alltargets = new Array('$alltargets');
! 7873: var insttypes = new Array('$allinsttypes');
! 7874: document.getElementById('loadbalancing_targets').style.display='block';
! 7875: document.getElementById('loadbalancing_disabled').style.display='none';
! 7876: var count = 0;
! 7877: for (var i=0; i<alltargets.length; i++) {
! 7878: if (alltargets[i] != balancer) {
! 7879:
! 7880: document.getElementById('loadbalancing_target_'+count).value = alltargets[i];
! 7881: document.getElementById('loadbalancing_targettxt_'+count).style.textAlign='left';
! 7882: document.getElementById('loadbalancing_targettxt_'+count).style.textFace='normal';
! 7883: document.getElementById('loadbalancing_targettxt_'+count).innerHTML = alltargets[i];
! 7884:
! 7885: count ++;
! 7886: }
! 7887: }
! 7888: for (var j=0; j<insttypes.length; j++) {
! 7889: if ((insttypes[j] == '_LC_external') || (insttypes[j] == '_LC_internetdom')) {
! 7890: if (ishomedom == 1) {
! 7891: document.getElementById('balanceruletitle_'+insttypes[j]).style.display='block';
! 7892: document.getElementById('balancerule_'+insttypes[j]).style.display='block';
! 7893: } else {
! 7894: document.getElementById('balanceruletitle_'+insttypes[j]).style.display='none';
! 7895: document.getElementById('balancerule_'+insttypes[j]).style.display='none';
! 7896:
! 7897: }
! 7898: } else {
! 7899: document.getElementById('balanceruletitle_'+insttypes[j]).style.display='block';
! 7900: document.getElementById('balancerule_'+insttypes[j]).style.display='block';
! 7901: }
! 7902: if ((insttypes[j] != '_LC_external') &&
! 7903: ((insttypes[j] != '_LC_internetdom') ||
! 7904: ((insttypes[j] == '_LC_internetdom') && (homedom == 1)))) {
! 7905: document.getElementById('loadbalancing_singleserver_'+insttypes[j]).options[0] = new Option("","",true,true);
! 7906: for (var k=0; k<alltargets.length; k++) {
! 7907: var idx = k+1;
! 7908: if (alltargets[k] != balancer) {
! 7909: document.getElementById('loadbalancing_singleserver_'+insttypes[j]).options[idx] = new Option(alltargets[k],alltargets[k],false,false);
! 7910: }
! 7911: }
! 7912: }
! 7913: }
! 7914: return;
! 7915: }
! 7916:
! 7917: function hideSpares() {
! 7918: var alltargets = new Array('$alltargets');
! 7919: var insttypes = new Array('$allinsttypes');
! 7920: var offloadtypes = new Array('primary','default');
! 7921:
! 7922: document.getElementById('loadbalancing_targets').style.display='none';
! 7923: document.getElementById('loadbalancing_disabled').style.display='block';
! 7924:
! 7925: var total = alltargets.length - 1;
! 7926: for (var i=0; i<offloadtypes; i++) {
! 7927: for (var j=0; j<total; j++) {
! 7928: document.getElementById('loadbalancing_target_'+offloadtypes[i]+'_'+j).checked = false;
! 7929: document.getElementById('loadbalancing_target_'+offloadtypes[i]+'_'+j).value = '';
! 7930: document.getElementById('loadbalancing_targettxt_'+offloadtypes[i]+'_'+j).innerHTML = '';
! 7931: }
! 7932: for (var k=0; k<insttypes.length; k++) {
! 7933: document.getElementById('balanceruletitle_'+insttypes[j]).style.display='none';
! 7934: document.getElementById('balancerule_'+insttypes[j]).style.display='none';
! 7935: if (insttypes[j] != '_LC_external') {
! 7936: document.getElementById('loadbalancing_singleserver_'+insttypes[j]).length = 0;
! 7937: document.getElementById('loadbalancing_singleserver_'+insttypes[j]).options[0] = new Option("","",true,true);
! 7938: }
! 7939: }
! 7940: return;
! 7941: }
! 7942:
! 7943: function checkOffloads(item,type) {
! 7944: var alltargets = new Array('$alltargets');
! 7945: var offloadtypes = new Array('primary','default');
! 7946: if (item.checked) {
! 7947: var total = alltargets.length - 1;
! 7948: var other;
! 7949: if (type == offloadtypes[0]) {
! 7950: other = offoadtypes[1];
! 7951: } else {
! 7952: other = offoadtypes[0];
! 7953: }
! 7954: for (var i=0; i<total; i++) {
! 7955: var server = document.getElementById('loadbalancing_target_'+other+'_'+i).value;
! 7956: if (server == item.value) {
! 7957: if (document.getElementById('loadbalancing_target_'+other+'_'+i).checked) {
! 7958: document.getElementById('loadbalancing_target_'+other+'_'+i).checked = false;
! 7959: }
! 7960: }
! 7961: }
! 7962: }
! 7963: return;
! 7964: }
! 7965:
! 7966: function singleServerToggle(type) {
! 7967: var offloadtoSelIdx = document.getElementById('loadbalancing_singleserver_'+type).selectedIndex;
! 7968: if (offloadtoSelIdx == 0) {
! 7969: document.getElementById('loadbalancing_rules_'+type+'_0').checked = true;
! 7970: document.getElementById('loadbalancing_singleserver_'+type).options[0].text = '';
! 7971:
! 7972: } else {
! 7973: document.getElementById('loadbalancing_rules_'+type+'_2').checked = true;
! 7974: document.getElementById('loadbalancing_singleserver_'+type).options[0].text = '$select';
! 7975: }
! 7976: return;
! 7977: }
! 7978:
! 7979: function balanceruleChange(formname,type) {
! 7980: if (type == '_LC_external') {
! 7981: return;
! 7982: }
! 7983: var typesRules = getIndicesByName(formname,'loadbalancing_rules_'+type);
! 7984: for (var i=0; i<typesRules.length; i++) {
! 7985: if (formname.elements[typesRules[i]].checked) {
! 7986: if (formname.elements[typesRules[i]].value != 'specific') {
! 7987: document.getElementById('loadbalancing_singleserver_'+type).selectedIndex = 0;
! 7988: document.getElementById('loadbalancing_singleserver_'+type).options[0].text = '';
! 7989: } else {
! 7990: document.getElementById('loadbalancing_singleserver_'+type).options[0].text = '$select';
! 7991: }
! 7992: }
! 7993: }
! 7994: return;
! 7995: }
! 7996:
! 7997: function getIndicesByName(formname,item) {
! 7998: var radiogroup = new Array();
! 7999: for (var i=0;i<formname.elements.length;i++) {
! 8000: if (formname.elements[i].name == item) {
! 8001: radiogroup.push(formname.elements[i].id);
! 8002: }
! 8003: }
! 8004: return radiogroup;
! 8005: }
! 8006:
! 8007: // ]]>
! 8008: </script>
! 8009:
! 8010: END
! 8011: }
! 8012:
1.3 raeburn 8013: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>