1: # The LearningOnline Network with CAPA
2: # Handler to set domain-wide configuration settings
3: #
4: # $Id: domainprefs.pm,v 1.164 2012/08/21 21:12:08 raeburn Exp $
5: #
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:
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 (quotas,
90: requestcourses or requestauthor).
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:
108: 0, approval, validate, autolimit=N (where N is blank, or a positive integer).
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:
119: approval
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:
143: - course requests will be processed automatically up to a limit of
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:
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;
164: use Apache::lonmsg();
165: use Apache::lonconfigsettings;
166: use LONCAPA qw(:DEFAULT :match);
167: use LONCAPA::Enrollment;
168: use LONCAPA::lonauthcgi();
169: use File::Copy;
170: use Locale::Language;
171: use DateTime::TimeZone;
172: use DateTime::Locale;
173:
174: my $registered_cleanup;
175: my $modified_urls;
176:
177: sub handler {
178: my $r=shift;
179: if ($r->header_only) {
180: &Apache::loncommon::content_type($r,'text/html');
181: $r->send_http_header;
182: return OK;
183: }
184:
185: my $context = 'domain';
186: my $dom = $env{'request.role.domain'};
187: my $domdesc = &Apache::lonnet::domain($dom,'description');
188: if (&Apache::lonnet::allowed('mau',$dom)) {
189: &Apache::loncommon::content_type($r,'text/html');
190: $r->send_http_header;
191: } else {
192: $env{'user.error.msg'}=
193: "/adm/domainprefs:mau:0:0:Cannot modify domain settings";
194: return HTTP_NOT_ACCEPTABLE;
195: }
196:
197: $registered_cleanup=0;
198: @{$modified_urls}=();
199:
200: &Apache::lonhtmlcommon::clear_breadcrumbs();
201: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
202: ['phase','actions']);
203: my $phase = 'pickactions';
204: if ( exists($env{'form.phase'}) ) {
205: $phase = $env{'form.phase'};
206: }
207: my %servers = &Apache::lonnet::internet_dom_servers($dom);
208: my %domconfig =
209: &Apache::lonnet::get_dom('configuration',['login','rolecolors',
210: 'quotas','autoenroll','autoupdate','autocreate',
211: 'directorysrch','usercreation','usermodification',
212: 'contacts','defaults','scantron','coursecategories',
213: 'serverstatuses','requestcourses','helpsettings',
214: 'coursedefaults','usersessions','loadbalancing',
215: 'requestauthor'],$dom);
216: my @prefs_order = ('rolecolors','login','defaults','quotas','autoenroll',
217: 'autoupdate','autocreate','directorysrch','contacts',
218: 'usercreation','usermodification','scantron',
219: 'requestcourses','requestauthor','coursecategories',
220: 'serverstatuses','helpsettings',
221: 'coursedefaults','usersessions');
222: if (keys(%servers) > 1) {
223: push(@prefs_order,'loadbalancing');
224: }
225: my %prefs = (
226: 'rolecolors' =>
227: { text => 'Default color schemes',
228: help => 'Domain_Configuration_Color_Schemes',
229: header => [{col1 => 'Student Settings',
230: col2 => '',},
231: {col1 => 'Coordinator Settings',
232: col2 => '',},
233: {col1 => 'Author Settings',
234: col2 => '',},
235: {col1 => 'Administrator Settings',
236: col2 => '',}],
237: },
238: 'login' =>
239: { text => 'Log-in page options',
240: help => 'Domain_Configuration_Login_Page',
241: header => [{col1 => 'Item',
242: col2 => '',}],
243: },
244:
245: 'defaults' =>
246: { text => 'Default authentication/language/timezone/portal',
247: help => 'Domain_Configuration_LangTZAuth',
248: header => [{col1 => 'Setting',
249: col2 => 'Value'}],
250: },
251: 'quotas' =>
252: { text => 'Blogs, personal web pages, webDAV, portfolios',
253: help => 'Domain_Configuration_Quotas',
254: header => [{col1 => 'User affiliation',
255: col2 => 'Available tools',
256: col3 => 'Portfolio quota',}],
257: },
258: 'autoenroll' =>
259: { text => 'Auto-enrollment settings',
260: help => 'Domain_Configuration_Auto_Enrollment',
261: header => [{col1 => 'Configuration setting',
262: col2 => 'Value(s)'}],
263: },
264: 'autoupdate' =>
265: { text => 'Auto-update settings',
266: help => 'Domain_Configuration_Auto_Updates',
267: header => [{col1 => 'Setting',
268: col2 => 'Value',},
269: {col1 => 'Setting',
270: col2 => 'Affiliation'},
271: {col1 => 'User population',
272: col2 => 'Updateable user data'}],
273: },
274: 'autocreate' =>
275: { text => 'Auto-course creation settings',
276: help => 'Domain_Configuration_Auto_Creation',
277: header => [{col1 => 'Configuration Setting',
278: col2 => 'Value',}],
279: },
280: 'directorysrch' =>
281: { text => 'Institutional directory searches',
282: help => 'Domain_Configuration_InstDirectory_Search',
283: header => [{col1 => 'Setting',
284: col2 => 'Value',}],
285: },
286: 'contacts' =>
287: { text => 'Contact Information',
288: help => 'Domain_Configuration_Contact_Info',
289: header => [{col1 => 'Setting',
290: col2 => 'Value',}],
291: },
292:
293: 'usercreation' =>
294: { text => 'User creation',
295: help => 'Domain_Configuration_User_Creation',
296: header => [{col1 => 'Format rule type',
297: col2 => 'Format rules in force'},
298: {col1 => 'User account creation',
299: col2 => 'Usernames which may be created',},
300: {col1 => 'Context',
301: col2 => 'Assignable authentication types'}],
302: },
303: 'usermodification' =>
304: { text => 'User modification',
305: help => 'Domain_Configuration_User_Modification',
306: header => [{col1 => 'Target user has role',
307: col2 => 'User information updateable in author context'},
308: {col1 => 'Target user has role',
309: col2 => 'User information updateable in course context'},
310: {col1 => "Status of user",
311: col2 => 'Information settable when self-creating account (if directory data blank)'}],
312: },
313: 'scantron' =>
314: { text => 'Bubblesheet format file',
315: help => 'Domain_Configuration_Scantron_Format',
316: header => [ {col1 => 'Item',
317: col2 => '',
318: }],
319: },
320: 'requestcourses' =>
321: {text => 'Request creation of courses',
322: help => 'Domain_Configuration_Request_Courses',
323: header => [{col1 => 'User affiliation',
324: col2 => 'Availability/Processing of requests',},
325: {col1 => 'Setting',
326: col2 => 'Value'}],
327: },
328: 'requestauthor' =>
329: {text => 'Request authoring space',
330: help => 'Domain_Configuration_Request_Author',
331: header => [{col1 => 'User affiliation',
332: col2 => 'Availability/Processing of requests',},
333: {col1 => 'Setting',
334: col2 => 'Value'}],
335: },
336: 'coursecategories' =>
337: { text => 'Cataloging of courses/communities',
338: help => 'Domain_Configuration_Cataloging_Courses',
339: header => [{col1 => 'Category settings',
340: col2 => '',},
341: {col1 => 'Categories',
342: col2 => '',
343: }],
344: },
345: 'serverstatuses' =>
346: {text => 'Access to server status pages',
347: help => 'Domain_Configuration_Server_Status',
348: header => [{col1 => 'Status Page',
349: col2 => 'Other named users',
350: col3 => 'Specific IPs',
351: }],
352: },
353: 'helpsettings' =>
354: {text => 'Help page settings',
355: help => 'Domain_Configuration_Help_Settings',
356: header => [{col1 => 'Authenticated Help Settings',
357: col2 => ''},
358: {col1 => 'Unauthenticated Help Settings',
359: col2 => ''}],
360: },
361: 'coursedefaults' =>
362: {text => 'Course/Community defaults',
363: help => 'Domain_Configuration_Course_Defaults',
364: header => [{col1 => 'Defaults which can be overridden in each course by a CC',
365: col2 => 'Value',},
366: {col1 => 'Defaults which can be overridden for each course by a DC',
367: col2 => 'Value',},],
368: },
369: 'privacy' =>
370: {text => 'User Privacy',
371: help => 'Domain_Configuration_User_Privacy',
372: header => [{col1 => 'Setting',
373: col2 => 'Value',}],
374: },
375: 'usersessions' =>
376: {text => 'User session hosting/offloading',
377: help => 'Domain_Configuration_User_Sessions',
378: header => [{col1 => 'Domain server',
379: col2 => 'Servers to offload sessions to when busy'},
380: {col1 => 'Hosting of users from other domains',
381: col2 => 'Rules'},
382: {col1 => "Hosting domain's own users elsewhere",
383: col2 => 'Rules'}],
384: },
385: 'loadbalancing' =>
386: {text => 'Dedicated Load Balancer',
387: help => 'Domain_Configuration_Load_Balancing',
388: header => [{col1 => 'Server',
389: col2 => 'Default destinations',
390: col3 => 'User affliation',
391: col4 => 'Overrides'},
392: ],
393: },
394: );
395: if (keys(%servers) > 1) {
396: $prefs{'login'} = { text => 'Log-in page options',
397: help => 'Domain_Configuration_Login_Page',
398: header => [{col1 => 'Log-in Service',
399: col2 => 'Server Setting',},
400: {col1 => 'Log-in Page Items',
401: col2 => ''}],
402: };
403: }
404: my @roles = ('student','coordinator','author','admin');
405: my @actions = &Apache::loncommon::get_env_multiple('form.actions');
406: &Apache::lonhtmlcommon::add_breadcrumb
407: ({href=>"javascript:changePage(document.$phase,'pickactions')",
408: text=>"Settings to display/modify"});
409: my $confname = $dom.'-domainconfig';
410: if ($phase eq 'process') {
411: &Apache::lonconfigsettings::make_changes($r,$dom,$phase,$context,\@prefs_order,\%prefs,\%domconfig,$confname,\@roles);
412: } elsif ($phase eq 'display') {
413: my $js;
414: if (keys(%servers) > 1) {
415: my ($othertitle,$usertypes,$types) =
416: &Apache::loncommon::sorted_inst_types($dom);
417: $js = &lonbalance_targets_js($dom,$types,\%servers).
418: &new_spares_js().
419: &common_domprefs_js().
420: &Apache::loncommon::javascript_array_indexof();
421: }
422: &Apache::lonconfigsettings::display_settings($r,$dom,$phase,$context,\@prefs_order,\%prefs,\%domconfig,$confname,$js);
423: } else {
424: if (keys(%domconfig) == 0) {
425: my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
426: my @ids=&Apache::lonnet::current_machine_ids();
427: if (!grep(/^\Q$primarylibserv\E$/,@ids)) {
428: my %designhash = &Apache::loncommon::get_domainconf($dom);
429: my @loginimages = ('img','logo','domlogo','login');
430: my $custom_img_count = 0;
431: foreach my $img (@loginimages) {
432: if ($designhash{$dom.'.login.'.$img} ne '') {
433: $custom_img_count ++;
434: }
435: }
436: foreach my $role (@roles) {
437: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
438: $custom_img_count ++;
439: }
440: }
441: if ($custom_img_count > 0) {
442: &Apache::lonconfigsettings::print_header($r,$phase,$context);
443: my $switch_server = &check_switchserver($dom,$confname);
444: $r->print(
445: &mt('Domain configuration settings have yet to be saved for this domain via the web-based domain preferences interface.').'<br />'.
446: &mt("While this remains so, you must switch to the domain's primary library server in order to update settings.").'<br /><br />'.
447: &mt("Thereafter, (with a Domain Coordinator role selected in the domain) you will be able to update settings when logged in to any server in the LON-CAPA network.").'<br />'.
448: &mt("However, you will still need to switch to the domain's primary library server to upload new images or logos.").'<br /><br />');
449: if ($switch_server) {
450: $r->print($switch_server.' '.&mt('to primary library server for domain: [_1]',$dom));
451: }
452: $r->print(&Apache::loncommon::end_page());
453: return OK;
454: }
455: }
456: }
457: &Apache::lonconfigsettings::display_choices($r,$phase,$context,\@prefs_order,\%prefs);
458: }
459: return OK;
460: }
461:
462: sub process_changes {
463: my ($r,$dom,$confname,$action,$roles,$values) = @_;
464: my %domconfig;
465: if (ref($values) eq 'HASH') {
466: %domconfig = %{$values};
467: }
468: my $output;
469: if ($action eq 'login') {
470: $output = &modify_login($r,$dom,$confname,%domconfig);
471: } elsif ($action eq 'rolecolors') {
472: $output = &modify_rolecolors($r,$dom,$confname,$roles,
473: %domconfig);
474: } elsif ($action eq 'quotas') {
475: $output = &modify_quotas($dom,$action,%domconfig);
476: } elsif ($action eq 'autoenroll') {
477: $output = &modify_autoenroll($dom,%domconfig);
478: } elsif ($action eq 'autoupdate') {
479: $output = &modify_autoupdate($dom,%domconfig);
480: } elsif ($action eq 'autocreate') {
481: $output = &modify_autocreate($dom,%domconfig);
482: } elsif ($action eq 'directorysrch') {
483: $output = &modify_directorysrch($dom,%domconfig);
484: } elsif ($action eq 'usercreation') {
485: $output = &modify_usercreation($dom,%domconfig);
486: } elsif ($action eq 'usermodification') {
487: $output = &modify_usermodification($dom,%domconfig);
488: } elsif ($action eq 'contacts') {
489: $output = &modify_contacts($dom,%domconfig);
490: } elsif ($action eq 'defaults') {
491: $output = &modify_defaults($dom,$r);
492: } elsif ($action eq 'scantron') {
493: $output = &modify_scantron($r,$dom,$confname,%domconfig);
494: } elsif ($action eq 'coursecategories') {
495: $output = &modify_coursecategories($dom,%domconfig);
496: } elsif ($action eq 'serverstatuses') {
497: $output = &modify_serverstatuses($dom,%domconfig);
498: } elsif ($action eq 'requestcourses') {
499: $output = &modify_quotas($dom,$action,%domconfig);
500: } elsif ($action eq 'requestauthor') {
501: $output = &modify_quotas($dom,$action,%domconfig);
502: } elsif ($action eq 'helpsettings') {
503: $output = &modify_helpsettings($r,$dom,$confname,%domconfig);
504: } elsif ($action eq 'coursedefaults') {
505: $output = &modify_coursedefaults($dom,%domconfig);
506: } elsif ($action eq 'usersessions') {
507: $output = &modify_usersessions($dom,%domconfig);
508: } elsif ($action eq 'loadbalancing') {
509: $output = &modify_loadbalancing($dom,%domconfig);
510: }
511: return $output;
512: }
513:
514: sub print_config_box {
515: my ($r,$dom,$confname,$phase,$action,$item,$settings) = @_;
516: my $rowtotal = 0;
517: my $output;
518: if ($action eq 'coursecategories') {
519: $output = &coursecategories_javascript($settings);
520: }
521: $output .=
522: '<table class="LC_nested_outer">
523: <tr>
524: <th align="left" valign="middle"><span class="LC_nobreak">'.
525: &mt($item->{text}).' '.
526: &Apache::loncommon::help_open_topic($item->{'help'}).'</span></th>'."\n".
527: '</tr>';
528: $rowtotal ++;
529: my $numheaders = 1;
530: if (ref($item->{'header'}) eq 'ARRAY') {
531: $numheaders = scalar(@{$item->{'header'}});
532: }
533: if ($numheaders > 1) {
534: my $colspan = '';
535: my $rightcolspan = '';
536: if (($action eq 'rolecolors') || ($action eq 'coursecategories') || ($action eq 'helpsettings')) {
537: $colspan = ' colspan="2"';
538: }
539: if ($action eq 'usersessions') {
540: $rightcolspan = ' colspan="3"';
541: }
542: $output .= '
543: <tr>
544: <td>
545: <table class="LC_nested">
546: <tr class="LC_info_row">
547: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[0]->{'col1'}).'</td>
548: <td class="LC_right_item"'.$rightcolspan.'>'.&mt($item->{'header'}->[0]->{'col2'}).'</td>
549: </tr>';
550: $rowtotal ++;
551: if ($action eq 'autoupdate') {
552: $output .= &print_autoupdate('top',$dom,$settings,\$rowtotal);
553: } elsif ($action eq 'usercreation') {
554: $output .= &print_usercreation('top',$dom,$settings,\$rowtotal);
555: } elsif ($action eq 'usermodification') {
556: $output .= &print_usermodification('top',$dom,$settings,\$rowtotal);
557: } elsif ($action eq 'coursecategories') {
558: $output .= &print_coursecategories('top',$dom,$item,$settings,\$rowtotal);
559: } elsif ($action eq 'login') {
560: $output .= &print_login('top',$dom,$confname,$phase,$settings,\$rowtotal);
561: $colspan = ' colspan="2"';
562: } elsif ($action eq 'requestcourses') {
563: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
564: } elsif ($action eq 'requestauthor') {
565: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
566: } elsif ($action eq 'helpsettings') {
567: $output .= &print_helpsettings('top',$dom,$confname,$settings,\$rowtotal);
568: } elsif ($action eq 'usersessions') {
569: $output .= &print_usersessions('top',$dom,$settings,\$rowtotal);
570: } elsif ($action eq 'rolecolors') {
571: $output .= &print_rolecolors($phase,'student',$dom,$confname,$settings,\$rowtotal);
572: } elsif ($action eq 'coursedefaults') {
573: $output .= &print_coursedefaults('top',$dom,$settings,\$rowtotal);
574: }
575: $output .= '
576: </table>
577: </td>
578: </tr>
579: <tr>
580: <td>
581: <table class="LC_nested">
582: <tr class="LC_info_row">
583: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col1'}).'</td>';
584: $output .= '
585: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col2'}).'</td>
586: </tr>';
587: $rowtotal ++;
588: if ($action eq 'autoupdate') {
589: $output .= &print_autoupdate('middle',$dom,$settings,\$rowtotal).'
590: </table>
591: </td>
592: </tr>
593: <tr>
594: <td>
595: <table class="LC_nested">
596: <tr class="LC_info_row">
597: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
598: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
599: &print_autoupdate('bottom',$dom,$settings,\$rowtotal);
600: $rowtotal ++;
601: } elsif ($action eq 'usercreation') {
602: $output .= &print_usercreation('middle',$dom,$settings,\$rowtotal).'
603: </table>
604: </td>
605: </tr>
606: <tr>
607: <td>
608: <table class="LC_nested">
609: <tr class="LC_info_row">
610: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
611: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
612: &print_usercreation('bottom',$dom,$settings,\$rowtotal);
613: $rowtotal ++;
614: } elsif ($action eq 'usermodification') {
615: $output .= &print_usermodification('middle',$dom,$settings,\$rowtotal).'
616: </table>
617: </td>
618: </tr>
619: <tr>
620: <td>
621: <table class="LC_nested">
622: <tr class="LC_info_row">
623: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
624: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
625: &print_usermodification('bottom',$dom,$settings,\$rowtotal);
626: $rowtotal ++;
627: } elsif ($action eq 'coursecategories') {
628: $output .= &print_coursecategories('bottom',$dom,$item,$settings,\$rowtotal);
629: } elsif ($action eq 'login') {
630: $output .= &print_login('bottom',$dom,$confname,$phase,$settings,\$rowtotal);
631: } elsif ($action eq 'requestcourses') {
632: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
633: } elsif ($action eq 'requestauthor') {
634: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
635: } elsif ($action eq 'helpsettings') {
636: $output .= &print_helpsettings('bottom',$dom,$confname,$settings,\$rowtotal);
637: } elsif ($action eq 'usersessions') {
638: $output .= &print_usersessions('middle',$dom,$settings,\$rowtotal).'
639: </table>
640: </td>
641: </tr>
642: <tr>
643: <td>
644: <table class="LC_nested">
645: <tr class="LC_info_row">
646: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
647: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
648: &print_usersessions('bottom',$dom,$settings,\$rowtotal);
649: $rowtotal ++;
650: } elsif ($action eq 'coursedefaults') {
651: $output .= &print_coursedefaults('bottom',$dom,$settings,\$rowtotal);
652: } elsif ($action eq 'rolecolors') {
653: $output .= &print_rolecolors($phase,'coordinator',$dom,$confname,$settings,\$rowtotal).'
654: </table>
655: </td>
656: </tr>
657: <tr>
658: <td>
659: <table class="LC_nested">
660: <tr class="LC_info_row">
661: <td class="LC_left_item"'.$colspan.' valign="top">'.
662: &mt($item->{'header'}->[2]->{'col1'}).'</td>
663: <td class="LC_right_item" valign="top">'.
664: &mt($item->{'header'}->[2]->{'col2'}).'</td>
665: </tr>'.
666: &print_rolecolors($phase,'author',$dom,$confname,$settings,\$rowtotal).'
667: </table>
668: </td>
669: </tr>
670: <tr>
671: <td>
672: <table class="LC_nested">
673: <tr class="LC_info_row">
674: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
675: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
676: </tr>'.
677: &print_rolecolors($phase,'admin',$dom,$confname,$settings,\$rowtotal);
678: $rowtotal += 2;
679: }
680: } else {
681: $output .= '
682: <tr>
683: <td>
684: <table class="LC_nested">
685: <tr class="LC_info_row">';
686: if (($action eq 'login') || ($action eq 'directorysrch')) {
687: $output .= '
688: <td class="LC_left_item" colspan="2">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
689: } elsif ($action eq 'serverstatuses') {
690: $output .= '
691: <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).
692: '<br />('.&mt('Automatic access for Dom. Coords.').')</td>';
693:
694: } else {
695: $output .= '
696: <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
697: }
698: if (defined($item->{'header'}->[0]->{'col3'})) {
699: $output .= '<td class="LC_left_item" valign="top">'.
700: &mt($item->{'header'}->[0]->{'col2'});
701: if ($action eq 'serverstatuses') {
702: $output .= '<br />(<tt>'.&mt('user1:domain1,user2:domain2 etc.').'</tt>)';
703: }
704: } else {
705: $output .= '<td class="LC_right_item" valign="top">'.
706: &mt($item->{'header'}->[0]->{'col2'});
707: }
708: $output .= '</td>';
709: if ($item->{'header'}->[0]->{'col3'}) {
710: if (defined($item->{'header'}->[0]->{'col4'})) {
711: $output .= '<td class="LC_left_item" valign="top">'.
712: &mt($item->{'header'}->[0]->{'col3'});
713: } else {
714: $output .= '<td class="LC_right_item" valign="top">'.
715: &mt($item->{'header'}->[0]->{'col3'});
716: }
717: if ($action eq 'serverstatuses') {
718: $output .= '<br />(<tt>'.&mt('IP1,IP2 etc.').'</tt>)';
719: }
720: $output .= '</td>';
721: }
722: if ($item->{'header'}->[0]->{'col4'}) {
723: $output .= '<td class="LC_right_item" valign="top">'.
724: &mt($item->{'header'}->[0]->{'col4'});
725: }
726: $output .= '</tr>';
727: $rowtotal ++;
728: if ($action eq 'login') {
729: $output .= &print_login('bottom',$dom,$confname,$phase,$settings,
730: \$rowtotal);
731: } elsif ($action eq 'quotas') {
732: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
733: } elsif ($action eq 'autoenroll') {
734: $output .= &print_autoenroll($dom,$settings,\$rowtotal);
735: } elsif ($action eq 'autocreate') {
736: $output .= &print_autocreate($dom,$settings,\$rowtotal);
737: } elsif ($action eq 'directorysrch') {
738: $output .= &print_directorysrch($dom,$settings,\$rowtotal);
739: } elsif ($action eq 'contacts') {
740: $output .= &print_contacts($dom,$settings,\$rowtotal);
741: } elsif ($action eq 'defaults') {
742: $output .= &print_defaults($dom,\$rowtotal);
743: } elsif ($action eq 'scantron') {
744: $output .= &print_scantronformat($r,$dom,$confname,$settings,\$rowtotal);
745: } elsif ($action eq 'serverstatuses') {
746: $output .= &print_serverstatuses($dom,$settings,\$rowtotal);
747: } elsif ($action eq 'helpsettings') {
748: $output .= &print_helpsettings('top',$dom,$confname,$settings,\$rowtotal);
749: } elsif ($action eq 'loadbalancing') {
750: $output .= &print_loadbalancing($dom,$settings,\$rowtotal);
751: }
752: }
753: $output .= '
754: </table>
755: </td>
756: </tr>
757: </table><br />';
758: return ($output,$rowtotal);
759: }
760:
761: sub print_login {
762: my ($position,$dom,$confname,$phase,$settings,$rowtotal) = @_;
763: my ($css_class,$datatable);
764: my %choices = &login_choices();
765:
766: if ($position eq 'top') {
767: my %servers = &Apache::lonnet::internet_dom_servers($dom);
768: my $choice = $choices{'disallowlogin'};
769: $css_class = ' class="LC_odd_row"';
770: $datatable .= '<tr'.$css_class.'><td>'.$choice.'</td>'.
771: '<td align="right"><table><tr><th>'.$choices{'hostid'}.'</th>'.
772: '<th>'.$choices{'server'}.'</th>'.
773: '<th>'.$choices{'serverpath'}.'</th>'.
774: '<th>'.$choices{'custompath'}.'</th>'.
775: '<th><span class="LC_nobreak">'.$choices{'exempt'}.'</span></th></tr>'."\n";
776: my %disallowed;
777: if (ref($settings) eq 'HASH') {
778: if (ref($settings->{'loginvia'}) eq 'HASH') {
779: %disallowed = %{$settings->{'loginvia'}};
780: }
781: }
782: foreach my $lonhost (sort(keys(%servers))) {
783: my $direct = 'selected="selected"';
784: if (ref($disallowed{$lonhost}) eq 'HASH') {
785: if ($disallowed{$lonhost}{'server'} ne '') {
786: $direct = '';
787: }
788: }
789: $datatable .= '<tr><td>'.$servers{$lonhost}.'</td>'.
790: '<td><select name="'.$lonhost.'_server">'.
791: '<option value=""'.$direct.'>'.$choices{'directlogin'}.
792: '</option>';
793: foreach my $hostid (keys(%servers)) {
794: next if ($servers{$hostid} eq $servers{$lonhost});
795: my $selected = '';
796: if (ref($disallowed{$lonhost}) eq 'HASH') {
797: if ($hostid eq $disallowed{$lonhost}{'server'}) {
798: $selected = 'selected="selected"';
799: }
800: }
801: $datatable .= '<option value="'.$hostid.'"'.$selected.'>'.
802: $servers{$hostid}.'</option>';
803: }
804: $datatable .= '</select></td>'.
805: '<td><select name="'.$lonhost.'_serverpath">';
806: foreach my $path ('','/','/adm/login','/adm/roles','custom') {
807: my $pathname = $path;
808: if ($path eq 'custom') {
809: $pathname = &mt('Custom Path').' ->';
810: }
811: my $selected = '';
812: if (ref($disallowed{$lonhost}) eq 'HASH') {
813: if ($path eq $disallowed{$lonhost}{'serverpath'}) {
814: $selected = 'selected="selected"';
815: }
816: } elsif ($path eq '') {
817: $selected = 'selected="selected"';
818: }
819: $datatable .= '<option value="'.$path.'"'.$selected.'>'.$pathname.'</option>';
820: }
821: $datatable .= '</select></td>';
822: my ($custom,$exempt);
823: if (ref($disallowed{$lonhost}) eq 'HASH') {
824: $custom = $disallowed{$lonhost}{'custompath'};
825: $exempt = $disallowed{$lonhost}{'exempt'};
826: }
827: $datatable .= '<td><input type="text" name="'.$lonhost.'_custompath" size="6" value="'.$custom.'" /></td>'.
828: '<td><input type="text" name="'.$lonhost.'_exempt" size="8" value="'.$exempt.'" /></td>'.
829: '</tr>';
830: }
831: $datatable .= '</table></td></tr>';
832: return $datatable;
833: }
834:
835: my %defaultchecked = (
836: 'coursecatalog' => 'on',
837: 'adminmail' => 'off',
838: 'newuser' => 'off',
839: );
840: my @toggles = ('coursecatalog','adminmail','newuser');
841: my (%checkedon,%checkedoff);
842: foreach my $item (@toggles) {
843: if ($defaultchecked{$item} eq 'on') {
844: $checkedon{$item} = ' checked="checked" ';
845: $checkedoff{$item} = ' ';
846: } elsif ($defaultchecked{$item} eq 'off') {
847: $checkedoff{$item} = ' checked="checked" ';
848: $checkedon{$item} = ' ';
849: }
850: }
851: my @images = ('img','logo','domlogo','login');
852: my @logintext = ('textcol','bgcol');
853: my @bgs = ('pgbg','mainbg','sidebg');
854: my @links = ('link','alink','vlink');
855: my %designhash = &Apache::loncommon::get_domainconf($dom);
856: my %defaultdesign = %Apache::loncommon::defaultdesign;
857: my (%is_custom,%designs);
858: my %defaults = (
859: font => $defaultdesign{'login.font'},
860: );
861: foreach my $item (@images) {
862: $defaults{$item} = $defaultdesign{'login.'.$item};
863: $defaults{'showlogo'}{$item} = 1;
864: }
865: foreach my $item (@bgs) {
866: $defaults{'bgs'}{$item} = $defaultdesign{'login.'.$item};
867: }
868: foreach my $item (@logintext) {
869: $defaults{'logintext'}{$item} = $defaultdesign{'login.'.$item};
870: }
871: foreach my $item (@links) {
872: $defaults{'links'}{$item} = $defaultdesign{'login.'.$item};
873: }
874: if (ref($settings) eq 'HASH') {
875: foreach my $item (@toggles) {
876: if ($settings->{$item} eq '1') {
877: $checkedon{$item} = ' checked="checked" ';
878: $checkedoff{$item} = ' ';
879: } elsif ($settings->{$item} eq '0') {
880: $checkedoff{$item} = ' checked="checked" ';
881: $checkedon{$item} = ' ';
882: }
883: }
884: foreach my $item (@images) {
885: if (defined($settings->{$item})) {
886: $designs{$item} = $settings->{$item};
887: $is_custom{$item} = 1;
888: }
889: if (defined($settings->{'showlogo'}{$item})) {
890: $designs{'showlogo'}{$item} = $settings->{'showlogo'}{$item};
891: }
892: }
893: foreach my $item (@logintext) {
894: if ($settings->{$item} ne '') {
895: $designs{'logintext'}{$item} = $settings->{$item};
896: $is_custom{$item} = 1;
897: }
898: }
899: if ($settings->{'font'} ne '') {
900: $designs{'font'} = $settings->{'font'};
901: $is_custom{'font'} = 1;
902: }
903: foreach my $item (@bgs) {
904: if ($settings->{$item} ne '') {
905: $designs{'bgs'}{$item} = $settings->{$item};
906: $is_custom{$item} = 1;
907: }
908: }
909: foreach my $item (@links) {
910: if ($settings->{$item} ne '') {
911: $designs{'links'}{$item} = $settings->{$item};
912: $is_custom{$item} = 1;
913: }
914: }
915: } else {
916: if ($designhash{$dom.'.login.font'} ne '') {
917: $designs{'font'} = $designhash{$dom.'.login.font'};
918: $is_custom{'font'} = 1;
919: }
920: foreach my $item (@images) {
921: if ($designhash{$dom.'.login.'.$item} ne '') {
922: $designs{$item} = $designhash{$dom.'.login.'.$item};
923: $is_custom{$item} = 1;
924: }
925: }
926: foreach my $item (@bgs) {
927: if ($designhash{$dom.'.login.'.$item} ne '') {
928: $designs{'bgs'}{$item} = $designhash{$dom.'.login.'.$item};
929: $is_custom{$item} = 1;
930: }
931: }
932: foreach my $item (@links) {
933: if ($designhash{$dom.'.login.'.$item} ne '') {
934: $designs{'links'}{$item} = $designhash{$dom.'.login.'.$item};
935: $is_custom{$item} = 1;
936: }
937: }
938: }
939: my %alt_text = &Apache::lonlocal::texthash ( img => 'Log-in banner',
940: logo => 'Institution Logo',
941: domlogo => 'Domain Logo',
942: login => 'Login box');
943: my $itemcount = 1;
944: foreach my $item (@toggles) {
945: $css_class = $itemcount%2?' class="LC_odd_row"':'';
946: $datatable .=
947: '<tr'.$css_class.'><td colspan="2">'.$choices{$item}.
948: '</td><td>'.
949: '<span class="LC_nobreak"><label><input type="radio" name="'.
950: $item.'"'.$checkedon{$item}.' value="1" />'.&mt('Yes').
951: '</label> <label><input type="radio" name="'.$item.'"'.
952: $checkedoff{$item}.' value="0" />'.&mt('No').'</label></span></td>'.
953: '</tr>';
954: $itemcount ++;
955: }
956: $datatable .= &display_color_options($dom,$confname,$phase,'login',$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal,\@logintext);
957: $datatable .= '</tr></table></td></tr>';
958: return $datatable;
959: }
960:
961: sub login_choices {
962: my %choices =
963: &Apache::lonlocal::texthash (
964: coursecatalog => 'Display Course/Community Catalog link?',
965: adminmail => "Display Administrator's E-mail Address?",
966: disallowlogin => "Login page requests redirected",
967: hostid => "Server",
968: server => "Redirect to:",
969: serverpath => "Path",
970: custompath => "Custom",
971: exempt => "Exempt IP(s)",
972: directlogin => "No redirect",
973: newuser => "Link to create a user account",
974: img => "Header",
975: logo => "Main Logo",
976: domlogo => "Domain Logo",
977: login => "Log-in Header",
978: textcol => "Text color",
979: bgcol => "Box color",
980: bgs => "Background colors",
981: links => "Link colors",
982: font => "Font color",
983: pgbg => "Header",
984: mainbg => "Page",
985: sidebg => "Login box",
986: link => "Link",
987: alink => "Active link",
988: vlink => "Visited link",
989: );
990: return %choices;
991: }
992:
993: sub print_rolecolors {
994: my ($phase,$role,$dom,$confname,$settings,$rowtotal) = @_;
995: my %choices = &color_font_choices();
996: my @bgs = ('pgbg','tabbg','sidebg');
997: my @links = ('link','alink','vlink');
998: my @images = ('img');
999: my %alt_text = &Apache::lonlocal::texthash(img => "Banner for $role role");
1000: my %designhash = &Apache::loncommon::get_domainconf($dom);
1001: my %defaultdesign = %Apache::loncommon::defaultdesign;
1002: my (%is_custom,%designs);
1003: my %defaults = (
1004: img => $defaultdesign{$role.'.img'},
1005: font => $defaultdesign{$role.'.font'},
1006: fontmenu => $defaultdesign{$role.'.fontmenu'},
1007: );
1008: foreach my $item (@bgs) {
1009: $defaults{'bgs'}{$item} = $defaultdesign{$role.'.'.$item};
1010: }
1011: foreach my $item (@links) {
1012: $defaults{'links'}{$item} = $defaultdesign{$role.'.'.$item};
1013: }
1014: if (ref($settings) eq 'HASH') {
1015: if (ref($settings->{$role}) eq 'HASH') {
1016: if ($settings->{$role}->{'img'} ne '') {
1017: $designs{'img'} = $settings->{$role}->{'img'};
1018: $is_custom{'img'} = 1;
1019: }
1020: if ($settings->{$role}->{'font'} ne '') {
1021: $designs{'font'} = $settings->{$role}->{'font'};
1022: $is_custom{'font'} = 1;
1023: }
1024: if ($settings->{$role}->{'fontmenu'} ne '') {
1025: $designs{'fontmenu'} = $settings->{$role}->{'fontmenu'};
1026: $is_custom{'fontmenu'} = 1;
1027: }
1028: foreach my $item (@bgs) {
1029: if ($settings->{$role}->{$item} ne '') {
1030: $designs{'bgs'}{$item} = $settings->{$role}->{$item};
1031: $is_custom{$item} = 1;
1032: }
1033: }
1034: foreach my $item (@links) {
1035: if ($settings->{$role}->{$item} ne '') {
1036: $designs{'links'}{$item} = $settings->{$role}->{$item};
1037: $is_custom{$item} = 1;
1038: }
1039: }
1040: }
1041: } else {
1042: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
1043: $designs{img} = $designhash{$dom.'.'.$role.'.img'};
1044: $is_custom{'img'} = 1;
1045: }
1046: if ($designhash{$dom.'.'.$role.'.fontmenu'} ne '') {
1047: $designs{fontmenu} = $designhash{$dom.'.'.$role.'.fontmenu'};
1048: $is_custom{'fontmenu'} = 1;
1049: }
1050: if ($designhash{$dom.'.'.$role.'.font'} ne '') {
1051: $designs{font} = $designhash{$dom.'.'.$role.'.font'};
1052: $is_custom{'font'} = 1;
1053: }
1054: foreach my $item (@bgs) {
1055: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1056: $designs{'bgs'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1057: $is_custom{$item} = 1;
1058:
1059: }
1060: }
1061: foreach my $item (@links) {
1062: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1063: $designs{'links'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1064: $is_custom{$item} = 1;
1065: }
1066: }
1067: }
1068: my $itemcount = 1;
1069: my $datatable = &display_color_options($dom,$confname,$phase,$role,$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal);
1070: $datatable .= '</tr></table></td></tr>';
1071: return $datatable;
1072: }
1073:
1074: sub display_color_options {
1075: my ($dom,$confname,$phase,$role,$itemcount,$choices,$is_custom,$defaults,$designs,
1076: $images,$bgs,$links,$alt_text,$rowtotal,$logintext) = @_;
1077: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1078: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1079: my $datatable = '<tr'.$css_class.'>'.
1080: '<td>'.$choices->{'font'}.'</td>';
1081: if (!$is_custom->{'font'}) {
1082: $datatable .= '<td>'.&mt('Default in use:').' <span id="css_default_'.$role.'_font" style="color: '.$defaults->{'font'}.';">'.$defaults->{'font'}.'</span></td>';
1083: } else {
1084: $datatable .= '<td> </td>';
1085: }
1086: my $fontlink = &color_pick($phase,$role,'font',$choices->{'font'},$designs->{'font'});
1087: $datatable .= '<td><span class="LC_nobreak">'.
1088: '<input type="text" size="10" name="'.$role.'_font"'.
1089: ' value="'.$designs->{'font'}.'" /> '.$fontlink.
1090: ' <span id="css_'.$role.'_font" style="background-color: '.
1091: $designs->{'font'}.';"> </span>'.
1092: '</span></td></tr>';
1093: unless ($role eq 'login') {
1094: $datatable .= '<tr'.$css_class.'>'.
1095: '<td>'.$choices->{'fontmenu'}.'</td>';
1096: if (!$is_custom->{'fontmenu'}) {
1097: $datatable .= '<td>'.&mt('Default in use:').' <span id="css_default_'.$role.'_font" style="color: '.$defaults->{'fontmenu'}.';">'.$defaults->{'fontmenu'}.'</span></td>';
1098: } else {
1099: $datatable .= '<td> </td>';
1100: }
1101: $fontlink = &color_pick($phase,$role,'fontmenu',$choices->{'fontmenu'},$designs->{'fontmenu'});
1102: $datatable .= '<td><span class="LC_nobreak">'.
1103: '<input type="text" size="10" name="'.$role.'_fontmenu"'.
1104: ' value="'.$designs->{'fontmenu'}.'" /> '.$fontlink.
1105: ' <span id="css_'.$role.'_fontmenu" style="background-color: '.
1106: $designs->{'fontmenu'}.';"> </span>'.
1107: '</span></td></tr>';
1108: }
1109: my $switchserver = &check_switchserver($dom,$confname);
1110: foreach my $img (@{$images}) {
1111: $itemcount ++;
1112: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1113: $datatable .= '<tr'.$css_class.'>'.
1114: '<td>'.$choices->{$img};
1115: my ($imgfile,$img_import,$login_hdr_pick,$logincolors);
1116: if ($role eq 'login') {
1117: if ($img eq 'login') {
1118: $login_hdr_pick =
1119: &login_header_options($img,$role,$defaults,$is_custom,$choices);
1120: $logincolors =
1121: &login_text_colors($img,$role,$logintext,$phase,$choices,
1122: $designs);
1123: } elsif ($img ne 'domlogo') {
1124: $datatable.= &logo_display_options($img,$defaults,$designs);
1125: }
1126: }
1127: $datatable .= '</td>';
1128: if ($designs->{$img} ne '') {
1129: $imgfile = $designs->{$img};
1130: $img_import = ($imgfile =~ m{^/adm/});
1131: } else {
1132: $imgfile = $defaults->{$img};
1133: }
1134: if ($imgfile) {
1135: my ($showfile,$fullsize);
1136: if ($imgfile =~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
1137: my $urldir = $1;
1138: my $filename = $2;
1139: my @info = &Apache::lonnet::stat_file($designs->{$img});
1140: if (@info) {
1141: my $thumbfile = 'tn-'.$filename;
1142: my @thumb=&Apache::lonnet::stat_file($urldir.'/'.$thumbfile);
1143: if (@thumb) {
1144: $showfile = $urldir.'/'.$thumbfile;
1145: } else {
1146: $showfile = $imgfile;
1147: }
1148: } else {
1149: $showfile = '';
1150: }
1151: } elsif ($imgfile =~ m-^/(adm/[^/]+)/([^/]+)$-) {
1152: $showfile = $imgfile;
1153: my $imgdir = $1;
1154: my $filename = $2;
1155: if (-e "$londocroot/$imgdir/tn-".$filename) {
1156: $showfile = "/$imgdir/tn-".$filename;
1157: } else {
1158: my $input = $londocroot.$imgfile;
1159: my $output = "$londocroot/$imgdir/tn-".$filename;
1160: if (!-e $output) {
1161: my ($width,$height) = &thumb_dimensions();
1162: my ($fullwidth,$fullheight) = &check_dimensions($input);
1163: if ($fullwidth ne '' && $fullheight ne '') {
1164: if ($fullwidth > $width && $fullheight > $height) {
1165: my $size = $width.'x'.$height;
1166: system("convert -sample $size $input $output");
1167: $showfile = "/$imgdir/tn-".$filename;
1168: }
1169: }
1170: }
1171: }
1172: }
1173: if ($showfile) {
1174: if ($showfile =~ m{^/(adm|res)/}) {
1175: if ($showfile =~ m{^/res/}) {
1176: my $local_showfile =
1177: &Apache::lonnet::filelocation('',$showfile);
1178: &Apache::lonnet::repcopy($local_showfile);
1179: }
1180: $showfile = &Apache::loncommon::lonhttpdurl($showfile);
1181: }
1182: if ($imgfile) {
1183: if ($imgfile =~ m{^/(adm|res)/}) {
1184: if ($imgfile =~ m{^/res/}) {
1185: my $local_imgfile =
1186: &Apache::lonnet::filelocation('',$imgfile);
1187: &Apache::lonnet::repcopy($local_imgfile);
1188: }
1189: $fullsize = &Apache::loncommon::lonhttpdurl($imgfile);
1190: } else {
1191: $fullsize = $imgfile;
1192: }
1193: }
1194: $datatable .= '<td>';
1195: if ($img eq 'login') {
1196: $datatable .= $login_hdr_pick;
1197: }
1198: $datatable .= &image_changes($is_custom->{$img},$alt_text->{$img},$img_import,
1199: $showfile,$fullsize,$role,$img,$imgfile,$logincolors);
1200: } else {
1201: $datatable .= '<td colspan="2" class="LC_right_item"><br />'.
1202: &mt('Upload:');
1203: }
1204: } else {
1205: $datatable .= '<td colspan="2" class="LC_right_item"><br />'.
1206: &mt('Upload:');
1207: }
1208: if ($switchserver) {
1209: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1210: } else {
1211: if ($img ne 'login') { # suppress file selection for Log-in header
1212: $datatable .=' <input type="file" name="'.$role.'_'.$img.'" />';
1213: }
1214: }
1215: $datatable .= '</td></tr>';
1216: }
1217: $itemcount ++;
1218: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1219: $datatable .= '<tr'.$css_class.'>'.
1220: '<td>'.$choices->{'bgs'}.'</td>';
1221: my $bgs_def;
1222: foreach my $item (@{$bgs}) {
1223: if (!$is_custom->{$item}) {
1224: $bgs_def .= '<td><span class="LC_nobreak">'.$choices->{$item}.'</span> <span id="css_default_'.$role.'_'.$item.'" style="background-color: '.$defaults->{'bgs'}{$item}.';"> </span><br />'.$defaults->{'bgs'}{$item}.'</td>';
1225: }
1226: }
1227: if ($bgs_def) {
1228: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$bgs_def.'</tr></table></td>';
1229: } else {
1230: $datatable .= '<td> </td>';
1231: }
1232: $datatable .= '<td class="LC_right_item">'.
1233: '<table border="0"><tr>';
1234: foreach my $item (@{$bgs}) {
1235: my $link = &color_pick($phase,$role,$item,$choices->{$item},$designs->{'bgs'}{$item});
1236: $datatable .= '<td align="center">'.$link;
1237: if ($designs->{'bgs'}{$item}) {
1238: $datatable .= ' <span id="css_'.$role.'_'.$item.'" style="background-color: '.$designs->{'bgs'}{$item}.';"> </span>';
1239: }
1240: $datatable .= '<br /><input type="text" size="8" name="'.$role.'_'.$item.'" value="'.$designs->{'bgs'}{$item}.
1241: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1242: }
1243: $datatable .= '</tr></table></td></tr>';
1244: $itemcount ++;
1245: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1246: $datatable .= '<tr'.$css_class.'>'.
1247: '<td>'.$choices->{'links'}.'</td>';
1248: my $links_def;
1249: foreach my $item (@{$links}) {
1250: if (!$is_custom->{$item}) {
1251: $links_def .= '<td>'.$choices->{$item}.'<br /><span id="css_default_'.$role.'_'.$item.'" style="color: '.$defaults->{'links'}{$item}.';">'.$defaults->{'links'}{$item}.'</span></td>';
1252: }
1253: }
1254: if ($links_def) {
1255: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$links_def.'</tr></table></td>';
1256: } else {
1257: $datatable .= '<td> </td>';
1258: }
1259: $datatable .= '<td class="LC_right_item">'.
1260: '<table border="0"><tr>';
1261: foreach my $item (@{$links}) {
1262: $datatable .= '<td align="center">'."\n".
1263: &color_pick($phase,$role,$item,$choices->{$item},
1264: $designs->{'links'}{$item});
1265: if ($designs->{'links'}{$item}) {
1266: $datatable.=' <span id="css_'.$role.'_'.$item.'" style="background-color: '.$designs->{'links'}{$item}.';"> </span>';
1267: }
1268: $datatable .= '<br /><input type="text" size="8" name="'.$role.'_'.$item.'" value="'.$designs->{'links'}{$item}.
1269: '" /></td>';
1270: }
1271: $$rowtotal += $itemcount;
1272: return $datatable;
1273: }
1274:
1275: sub logo_display_options {
1276: my ($img,$defaults,$designs) = @_;
1277: my $checkedon;
1278: if (ref($defaults) eq 'HASH') {
1279: if (ref($defaults->{'showlogo'}) eq 'HASH') {
1280: if ($defaults->{'showlogo'}{$img}) {
1281: $checkedon = 'checked="checked" ';
1282: }
1283: }
1284: }
1285: if (ref($designs) eq 'HASH') {
1286: if (ref($designs->{'showlogo'}) eq 'HASH') {
1287: if (defined($designs->{'showlogo'}{$img})) {
1288: if ($designs->{'showlogo'}{$img} == 0) {
1289: $checkedon = '';
1290: } elsif ($designs->{'showlogo'}{$img} == 1) {
1291: $checkedon = 'checked="checked" ';
1292: }
1293: }
1294: }
1295: }
1296: return '<br /><label> <input type="checkbox" name="'.
1297: 'login_showlogo_'.$img.'" value="1" '.$checkedon.'/>'.
1298: &mt('show').'</label>'."\n";
1299: }
1300:
1301: sub login_header_options {
1302: my ($img,$role,$defaults,$is_custom,$choices) = @_;
1303: my $output = '';
1304: if ((!$is_custom->{'textcol'}) || (!$is_custom->{'bgcol'})) {
1305: $output .= &mt('Text default(s):').'<br />';
1306: if (!$is_custom->{'textcol'}) {
1307: $output .= $choices->{'textcol'}.': '.$defaults->{'logintext'}{'textcol'}.
1308: ' ';
1309: }
1310: if (!$is_custom->{'bgcol'}) {
1311: $output .= $choices->{'bgcol'}.': '.
1312: '<span id="css_'.$role.'_font" style="background-color: '.
1313: $defaults->{'logintext'}{'bgcol'}.';"> </span>';
1314: }
1315: $output .= '<br />';
1316: }
1317: $output .='<br />';
1318: return $output;
1319: }
1320:
1321: sub login_text_colors {
1322: my ($img,$role,$logintext,$phase,$choices,$designs) = @_;
1323: my $color_menu = '<table border="0"><tr>';
1324: foreach my $item (@{$logintext}) {
1325: my $link = &color_pick($phase,$role,$item,$choices->{$item},$designs->{'logintext'}{$item});
1326: $color_menu .= '<td align="center">'.$link;
1327: if ($designs->{'logintext'}{$item}) {
1328: $color_menu .= ' <span id="css_'.$role.'_'.$item.'" style="background-color: '.$designs->{'logintext'}{$item}.';"> </span>';
1329: }
1330: $color_menu .= '<br /><input type="text" size="8" name="'.$role.'_'.$item.'" value="'.
1331: $designs->{'logintext'}{$item}.'" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>'.
1332: '<td> </td>';
1333: }
1334: $color_menu .= '</tr></table><br />';
1335: return $color_menu;
1336: }
1337:
1338: sub image_changes {
1339: my ($is_custom,$alt_text,$img_import,$showfile,$fullsize,$role,$img,$imgfile,$logincolors) = @_;
1340: my $output;
1341: if ($img eq 'login') {
1342: # suppress image for Log-in header
1343: } elsif (!$is_custom) {
1344: if ($img ne 'domlogo') {
1345: $output .= &mt('Default image:').'<br />';
1346: } else {
1347: $output .= &mt('Default in use:').'<br />';
1348: }
1349: }
1350: if ($img eq 'login') { # suppress image for Log-in header
1351: $output .= '<td>'.$logincolors;
1352: } else {
1353: if ($img_import) {
1354: $output .= '<input type="hidden" name="'.$role.'_import_'.$img.'" value="'.$imgfile.'" />';
1355: }
1356: $output .= '<a href="'.$fullsize.'" target="_blank"><img src="'.
1357: $showfile.'" alt="'.$alt_text.'" border="0" /></a></td>';
1358: if ($is_custom) {
1359: $output .= '<td>'.$logincolors.'<span class="LC_nobreak"><label>'.
1360: '<input type="checkbox" name="'.
1361: $role.'_del_'.$img.'" value="1" />'.&mt('Delete?').
1362: '</label> '.&mt('Replace:').'</span><br />';
1363: } else {
1364: $output .= '<td valign="bottom">'.$logincolors.&mt('Upload:').'<br />';
1365: }
1366: }
1367: return $output;
1368: }
1369:
1370: sub color_pick {
1371: my ($phase,$role,$item,$desc,$curcol) = @_;
1372: my $link = '<a href="javascript:pjump('."'color_custom','".$desc.
1373: "','".$curcol."','".$role.'_'.$item."','parmform.pres','psub'".
1374: ');">'.$desc.'</a>';
1375: return $link;
1376: }
1377:
1378: sub print_quotas {
1379: my ($dom,$settings,$rowtotal,$action) = @_;
1380: my $context;
1381: if ($action eq 'quotas') {
1382: $context = 'tools';
1383: } else {
1384: $context = $action;
1385: }
1386: my ($datatable,$defaultquota,@usertools,@options,%validations);
1387: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1388: my $typecount = 0;
1389: my ($css_class,%titles);
1390: if ($context eq 'requestcourses') {
1391: @usertools = ('official','unofficial','community');
1392: @options =('norequest','approval','validate','autolimit');
1393: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
1394: %titles = &courserequest_titles();
1395: } elsif ($context eq 'requestauthor') {
1396: @usertools = ('author');
1397: @options = ('norequest','approval','automatic');
1398: %titles = &authorrequest_titles();
1399: } else {
1400: @usertools = ('aboutme','blog','webdav','portfolio');
1401: %titles = &tool_titles();
1402: }
1403: if (ref($types) eq 'ARRAY') {
1404: foreach my $type (@{$types}) {
1405: my $currdefquota;
1406: unless (($context eq 'requestcourses') ||
1407: ($context eq 'requestauthor')) {
1408: if (ref($settings) eq 'HASH') {
1409: if (ref($settings->{defaultquota}) eq 'HASH') {
1410: $currdefquota = $settings->{defaultquota}->{$type};
1411: } else {
1412: $currdefquota = $settings->{$type};
1413: }
1414: }
1415: }
1416: if (defined($usertypes->{$type})) {
1417: $typecount ++;
1418: $css_class = $typecount%2?' class="LC_odd_row"':'';
1419: $datatable .= '<tr'.$css_class.'>'.
1420: '<td>'.$usertypes->{$type}.'</td>'.
1421: '<td class="LC_left_item">';
1422: if ($context eq 'requestcourses') {
1423: $datatable .= '<table><tr>';
1424: }
1425: my %cell;
1426: foreach my $item (@usertools) {
1427: if ($context eq 'requestcourses') {
1428: my ($curroption,$currlimit);
1429: if (ref($settings) eq 'HASH') {
1430: if (ref($settings->{$item}) eq 'HASH') {
1431: $curroption = $settings->{$item}->{$type};
1432: if ($curroption =~ /^autolimit=(\d*)$/) {
1433: $currlimit = $1;
1434: }
1435: }
1436: }
1437: if (!$curroption) {
1438: $curroption = 'norequest';
1439: }
1440: $datatable .= '<th>'.$titles{$item}.'</th>';
1441: foreach my $option (@options) {
1442: my $val = $option;
1443: if ($option eq 'norequest') {
1444: $val = 0;
1445: }
1446: if ($option eq 'validate') {
1447: my $canvalidate = 0;
1448: if (ref($validations{$item}) eq 'HASH') {
1449: if ($validations{$item}{$type}) {
1450: $canvalidate = 1;
1451: }
1452: }
1453: next if (!$canvalidate);
1454: }
1455: my $checked = '';
1456: if ($option eq $curroption) {
1457: $checked = ' checked="checked"';
1458: } elsif ($option eq 'autolimit') {
1459: if ($curroption =~ /^autolimit/) {
1460: $checked = ' checked="checked"';
1461: }
1462: }
1463: $cell{$item} .= '<span class="LC_nobreak"><label>'.
1464: '<input type="radio" name="crsreq_'.$item.
1465: '_'.$type.'" value="'.$val.'"'.$checked.' />'.
1466: $titles{$option}.'</label>';
1467: if ($option eq 'autolimit') {
1468: $cell{$item} .= ' <input type="text" name="crsreq_'.
1469: $item.'_limit_'.$type.'" size="1" '.
1470: 'value="'.$currlimit.'" />';
1471: }
1472: $cell{$item} .= '</span> ';
1473: if ($option eq 'autolimit') {
1474: $cell{$item} .= $titles{'unlimited'};
1475: }
1476: }
1477: } elsif ($context eq 'requestauthor') {
1478: my $curroption;
1479: if (ref($settings) eq 'HASH') {
1480: $curroption = $settings->{$type};
1481: }
1482: if (!$curroption) {
1483: $curroption = 'norequest';
1484: }
1485: foreach my $option (@options) {
1486: my $val = $option;
1487: if ($option eq 'norequest') {
1488: $val = 0;
1489: }
1490: my $checked = '';
1491: if ($option eq $curroption) {
1492: $checked = ' checked="checked"';
1493: }
1494: $datatable .= '<span class="LC_nobreak"><label>'.
1495: '<input type="radio" name="authorreq_'.$type.
1496: '" value="'.$val.'"'.$checked.' />'.
1497: $titles{$option}.'</label></span> ';
1498: }
1499: } else {
1500: my $checked = 'checked="checked" ';
1501: if (ref($settings) eq 'HASH') {
1502: if (ref($settings->{$item}) eq 'HASH') {
1503: if ($settings->{$item}->{$type} == 0) {
1504: $checked = '';
1505: } elsif ($settings->{$item}->{$type} == 1) {
1506: $checked = 'checked="checked" ';
1507: }
1508: }
1509: }
1510: $datatable .= '<span class="LC_nobreak"><label>'.
1511: '<input type="checkbox" name="'.$context.'_'.$item.
1512: '" value="'.$type.'" '.$checked.'/>'.$titles{$item}.
1513: '</label></span> ';
1514: }
1515: }
1516: if ($context eq 'requestcourses') {
1517: $datatable .= '</tr><tr>';
1518: foreach my $item (@usertools) {
1519: $datatable .= '<td style="vertical-align: top">'.$cell{$item}.'</td>';
1520: }
1521: $datatable .= '</tr></table>';
1522: }
1523: $datatable .= '</td>';
1524: unless (($context eq 'requestcourses') ||
1525: ($context eq 'requestauthor')) {
1526: $datatable .=
1527: '<td class="LC_right_item"><span class="LC_nobreak">'.
1528: '<input type="text" name="quota_'.$type.
1529: '" value="'.$currdefquota.
1530: '" size="5" /> Mb</span></td>';
1531: }
1532: $datatable .= '</tr>';
1533: }
1534: }
1535: }
1536: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1537: $defaultquota = '20';
1538: if (ref($settings) eq 'HASH') {
1539: if (ref($settings->{'defaultquota'}) eq 'HASH') {
1540: $defaultquota = $settings->{'defaultquota'}->{'default'};
1541: } elsif (defined($settings->{'default'})) {
1542: $defaultquota = $settings->{'default'};
1543: }
1544: }
1545: }
1546: $typecount ++;
1547: $css_class = $typecount%2?' class="LC_odd_row"':'';
1548: $datatable .= '<tr'.$css_class.'>'.
1549: '<td>'.$othertitle.'</td>'.
1550: '<td class="LC_left_item">';
1551: if ($context eq 'requestcourses') {
1552: $datatable .= '<table><tr>';
1553: }
1554: my %defcell;
1555: foreach my $item (@usertools) {
1556: if ($context eq 'requestcourses') {
1557: my ($curroption,$currlimit);
1558: if (ref($settings) eq 'HASH') {
1559: if (ref($settings->{$item}) eq 'HASH') {
1560: $curroption = $settings->{$item}->{'default'};
1561: if ($curroption =~ /^autolimit=(\d*)$/) {
1562: $currlimit = $1;
1563: }
1564: }
1565: }
1566: if (!$curroption) {
1567: $curroption = 'norequest';
1568: }
1569: $datatable .= '<th>'.$titles{$item}.'</th>';
1570: foreach my $option (@options) {
1571: my $val = $option;
1572: if ($option eq 'norequest') {
1573: $val = 0;
1574: }
1575: if ($option eq 'validate') {
1576: my $canvalidate = 0;
1577: if (ref($validations{$item}) eq 'HASH') {
1578: if ($validations{$item}{'default'}) {
1579: $canvalidate = 1;
1580: }
1581: }
1582: next if (!$canvalidate);
1583: }
1584: my $checked = '';
1585: if ($option eq $curroption) {
1586: $checked = ' checked="checked"';
1587: } elsif ($option eq 'autolimit') {
1588: if ($curroption =~ /^autolimit/) {
1589: $checked = ' checked="checked"';
1590: }
1591: }
1592: $defcell{$item} .= '<span class="LC_nobreak"><label>'.
1593: '<input type="radio" name="crsreq_'.$item.
1594: '_default" value="'.$val.'"'.$checked.' />'.
1595: $titles{$option}.'</label>';
1596: if ($option eq 'autolimit') {
1597: $defcell{$item} .= ' <input type="text" name="crsreq_'.
1598: $item.'_limit_default" size="1" '.
1599: 'value="'.$currlimit.'" />';
1600: }
1601: $defcell{$item} .= '</span> ';
1602: if ($option eq 'autolimit') {
1603: $defcell{$item} .= $titles{'unlimited'};
1604: }
1605: }
1606: } elsif ($context eq 'requestauthor') {
1607: my $curroption;
1608: if (ref($settings) eq 'HASH') {
1609: if (ref($settings->{'requestauthor'}) eq 'HASH') {
1610: $curroption = $settings->{'requestauthor'};
1611: }
1612: }
1613: if (!$curroption) {
1614: $curroption = 'norequest';
1615: }
1616: foreach my $option (@options) {
1617: my $val = $option;
1618: if ($option eq 'norequest') {
1619: $val = 0;
1620: }
1621: my $checked = '';
1622: if ($option eq $curroption) {
1623: $checked = ' checked="checked"';
1624: }
1625: $datatable .= '<span class="LC_nobreak"><label>'.
1626: '<input type="radio" name="authorreq_default"'.
1627: ' value="'.$val.'"'.$checked.' />'.
1628: $titles{$option}.'</label></span> ';
1629: }
1630: } else {
1631: my $checked = 'checked="checked" ';
1632: if (ref($settings) eq 'HASH') {
1633: if (ref($settings->{$item}) eq 'HASH') {
1634: if ($settings->{$item}->{'default'} == 0) {
1635: $checked = '';
1636: } elsif ($settings->{$item}->{'default'} == 1) {
1637: $checked = 'checked="checked" ';
1638: }
1639: }
1640: }
1641: $datatable .= '<span class="LC_nobreak"><label>'.
1642: '<input type="checkbox" name="'.$context.'_'.$item.
1643: '" value="default" '.$checked.'/>'.$titles{$item}.
1644: '</label></span> ';
1645: }
1646: }
1647: if ($context eq 'requestcourses') {
1648: $datatable .= '</tr><tr>';
1649: foreach my $item (@usertools) {
1650: $datatable .= '<td style="vertical-align: top">'.$defcell{$item}.'</td>';
1651: }
1652: $datatable .= '</tr></table>';
1653: }
1654: $datatable .= '</td>';
1655: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1656: $datatable .= '<td class="LC_right_item"><span class="LC_nobreak">'.
1657: '<input type="text" name="defaultquota" value="'.
1658: $defaultquota.'" size="5" /> Mb</span></td>';
1659: }
1660: $datatable .= '</tr>';
1661: $typecount ++;
1662: $css_class = $typecount%2?' class="LC_odd_row"':'';
1663: $datatable .= '<tr'.$css_class.'>'.
1664: '<td>'.&mt('LON-CAPA Advanced Users').' ';
1665: if ($context eq 'requestcourses') {
1666: $datatable .= &mt('(overrides affiliation, if set)').
1667: '</td>'.
1668: '<td class="LC_left_item">'.
1669: '<table><tr>';
1670: } else {
1671: $datatable .= &mt('(overrides affiliation, if checked)').
1672: '</td>'.
1673: '<td class="LC_left_item" colspan="2">'.
1674: '<br />';
1675: }
1676: my %advcell;
1677: foreach my $item (@usertools) {
1678: if ($context eq 'requestcourses') {
1679: my ($curroption,$currlimit);
1680: if (ref($settings) eq 'HASH') {
1681: if (ref($settings->{$item}) eq 'HASH') {
1682: $curroption = $settings->{$item}->{'_LC_adv'};
1683: if ($curroption =~ /^autolimit=(\d*)$/) {
1684: $currlimit = $1;
1685: }
1686: }
1687: }
1688: $datatable .= '<th>'.$titles{$item}.'</th>';
1689: my $checked = '';
1690: if ($curroption eq '') {
1691: $checked = ' checked="checked"';
1692: }
1693: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
1694: '<input type="radio" name="crsreq_'.$item.
1695: '__LC_adv" value=""'.$checked.' />'.
1696: &mt('No override set').'</label></span> ';
1697: foreach my $option (@options) {
1698: my $val = $option;
1699: if ($option eq 'norequest') {
1700: $val = 0;
1701: }
1702: if ($option eq 'validate') {
1703: my $canvalidate = 0;
1704: if (ref($validations{$item}) eq 'HASH') {
1705: if ($validations{$item}{'_LC_adv'}) {
1706: $canvalidate = 1;
1707: }
1708: }
1709: next if (!$canvalidate);
1710: }
1711: my $checked = '';
1712: if ($val eq $curroption) {
1713: $checked = ' checked="checked"';
1714: } elsif ($option eq 'autolimit') {
1715: if ($curroption =~ /^autolimit/) {
1716: $checked = ' checked="checked"';
1717: }
1718: }
1719: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
1720: '<input type="radio" name="crsreq_'.$item.
1721: '__LC_adv" value="'.$val.'"'.$checked.' />'.
1722: $titles{$option}.'</label>';
1723: if ($option eq 'autolimit') {
1724: $advcell{$item} .= ' <input type="text" name="crsreq_'.
1725: $item.'_limit__LC_adv" size="1" '.
1726: 'value="'.$currlimit.'" />';
1727: }
1728: $advcell{$item} .= '</span> ';
1729: if ($option eq 'autolimit') {
1730: $advcell{$item} .= $titles{'unlimited'};
1731: }
1732: }
1733: } elsif ($context eq 'requestauthor') {
1734: my $curroption;
1735: if (ref($settings) eq 'HASH') {
1736: $curroption = $settings->{'_LC_adv'};
1737: }
1738: my $checked = '';
1739: if ($curroption eq '') {
1740: $checked = ' checked="checked"';
1741: }
1742: $datatable .= '<span class="LC_nobreak"><label>'.
1743: '<input type="radio" name="authorreq__LC_adv"'.
1744: ' value=""'.$checked.' />'.
1745: &mt('No override set').'</label></span> ';
1746: foreach my $option (@options) {
1747: my $val = $option;
1748: if ($option eq 'norequest') {
1749: $val = 0;
1750: }
1751: my $checked = '';
1752: if ($val eq $curroption) {
1753: $checked = ' checked="checked"';
1754: }
1755: $datatable .= '<span class="LC_nobreak"><label>'.
1756: '<input type="radio" name="crsreq_'.$item.
1757: '__LC_adv" value="'.$val.'"'.$checked.' />'.
1758: $titles{$option}.'</label></span> ';
1759: }
1760: } else {
1761: my $checked = 'checked="checked" ';
1762: if (ref($settings) eq 'HASH') {
1763: if (ref($settings->{$item}) eq 'HASH') {
1764: if ($settings->{$item}->{'_LC_adv'} == 0) {
1765: $checked = '';
1766: } elsif ($settings->{$item}->{'_LC_adv'} == 1) {
1767: $checked = 'checked="checked" ';
1768: }
1769: }
1770: }
1771: $datatable .= '<span class="LC_nobreak"><label>'.
1772: '<input type="checkbox" name="'.$context.'_'.$item.
1773: '" value="_LC_adv" '.$checked.'/>'.$titles{$item}.
1774: '</label></span> ';
1775: }
1776: }
1777: if ($context eq 'requestcourses') {
1778: $datatable .= '</tr><tr>';
1779: foreach my $item (@usertools) {
1780: $datatable .= '<td style="vertical-align: top">'.$advcell{$item}.'</td>';
1781: }
1782: $datatable .= '</tr></table>';
1783: }
1784: $datatable .= '</td></tr>';
1785: $$rowtotal += $typecount;
1786: return $datatable;
1787: }
1788:
1789: sub print_requestmail {
1790: my ($dom,$action,$settings,$rowtotal) = @_;
1791: my ($now,$datatable,%dompersonnel,@domcoord,@currapproval,$rows);
1792: $now = time;
1793: $rows = 0;
1794: %dompersonnel = &Apache::lonnet::get_domain_roles($dom,['dc'],$now,$now);
1795: foreach my $server (keys(%dompersonnel)) {
1796: foreach my $user (sort(keys(%{$dompersonnel{$server}}))) {
1797: my ($trole,$uname,$udom,$runame,$rudom,$rsec) = split(/:/,$user);
1798: if (!grep(/^$uname:$udom$/,@domcoord)) {
1799: push(@domcoord,$uname.':'.$udom);
1800: }
1801: }
1802: }
1803: if (ref($settings) eq 'HASH') {
1804: if (ref($settings->{'notify'}) eq 'HASH') {
1805: if ($settings->{'notify'}{'approval'} ne '') {
1806: @currapproval = split(',',$settings->{'notify'}{'approval'});
1807: }
1808: }
1809: }
1810: if (@currapproval) {
1811: foreach my $dc (@currapproval) {
1812: unless (grep(/^\Q$dc\E$/,@domcoord)) {
1813: push(@domcoord,$dc);
1814: }
1815: }
1816: }
1817: @domcoord = sort(@domcoord);
1818: my $numinrow = 4;
1819: my $numdc = @domcoord;
1820: my $css_class = 'class="LC_odd_row"';
1821: my $text;
1822: if ($action eq 'requestcourses') {
1823: $text = &mt('Receive notification of course requests requiring approval');
1824: } else {
1825: $text = &mt('Receive notification of authoring space requests requiring approval')
1826: }
1827: $datatable = '<tr '.$css_class.'>'.
1828: ' <td>'.$text.'</td>'.
1829: ' <td class="LC_left_item">';
1830: if (@domcoord > 0) {
1831: $datatable .= '<table>';
1832: for (my $i=0; $i<$numdc; $i++) {
1833: my $rem = $i%($numinrow);
1834: if ($rem == 0) {
1835: if ($i > 0) {
1836: $datatable .= '</tr>';
1837: }
1838: $datatable .= '<tr>';
1839: $rows ++;
1840: }
1841: my $check = ' ';
1842: if (grep(/^\Q$domcoord[$i]\E$/,@currapproval)) {
1843: $check = ' checked="checked" ';
1844: }
1845: my ($uname,$udom) = split(':',$domcoord[$i]);
1846: my $fullname = &Apache::loncommon::plainname($uname,$udom);
1847: if ($i == $numdc-1) {
1848: my $colsleft = $numinrow-$rem;
1849: if ($colsleft > 1) {
1850: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
1851: } else {
1852: $datatable .= '<td class="LC_left_item">';
1853: }
1854: } else {
1855: $datatable .= '<td class="LC_left_item">';
1856: }
1857: $datatable .= '<span class="LC_nobreak"><label>'.
1858: '<input type="checkbox" name="reqapprovalnotify" '.
1859: 'value="'.$domcoord[$i].'"'.$check.'/>'.
1860: $fullname.'</label></span></td>';
1861: }
1862: $datatable .= '</tr></table>';
1863: } else {
1864: $datatable .= &mt('There are no active Domain Coordinators');
1865: $rows ++;
1866: }
1867: $datatable .='</td></tr>';
1868: $$rowtotal += $rows;
1869: return $datatable;
1870: }
1871:
1872: sub print_autoenroll {
1873: my ($dom,$settings,$rowtotal) = @_;
1874: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
1875: my ($defdom,$runon,$runoff,$coownerson,$coownersoff);
1876: if (ref($settings) eq 'HASH') {
1877: if (exists($settings->{'run'})) {
1878: if ($settings->{'run'} eq '0') {
1879: $runoff = ' checked="checked" ';
1880: $runon = ' ';
1881: } else {
1882: $runon = ' checked="checked" ';
1883: $runoff = ' ';
1884: }
1885: } else {
1886: if ($autorun) {
1887: $runon = ' checked="checked" ';
1888: $runoff = ' ';
1889: } else {
1890: $runoff = ' checked="checked" ';
1891: $runon = ' ';
1892: }
1893: }
1894: if (exists($settings->{'co-owners'})) {
1895: if ($settings->{'co-owners'} eq '0') {
1896: $coownersoff = ' checked="checked" ';
1897: $coownerson = ' ';
1898: } else {
1899: $coownerson = ' checked="checked" ';
1900: $coownersoff = ' ';
1901: }
1902: } else {
1903: $coownersoff = ' checked="checked" ';
1904: $coownerson = ' ';
1905: }
1906: if (exists($settings->{'sender_domain'})) {
1907: $defdom = $settings->{'sender_domain'};
1908: }
1909: } else {
1910: if ($autorun) {
1911: $runon = ' checked="checked" ';
1912: $runoff = ' ';
1913: } else {
1914: $runoff = ' checked="checked" ';
1915: $runon = ' ';
1916: }
1917: }
1918: my $domform = &Apache::loncommon::select_dom_form($defdom,'sender_domain',1);
1919: my $notif_sender;
1920: if (ref($settings) eq 'HASH') {
1921: $notif_sender = $settings->{'sender_uname'};
1922: }
1923: my $datatable='<tr class="LC_odd_row">'.
1924: '<td>'.&mt('Auto-enrollment active?').'</td>'.
1925: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1926: '<input type="radio" name="autoenroll_run"'.
1927: $runon.' value="1" />'.&mt('Yes').'</label> '.
1928: '<label><input type="radio" name="autoenroll_run"'.
1929: $runoff.' value="0" />'.&mt('No').'</label></span></td>'.
1930: '</tr><tr>'.
1931: '<td>'.&mt('Notification messages - sender').
1932: '</td><td class="LC_right_item"><span class="LC_nobreak">'.
1933: &mt('username').': '.
1934: '<input type="text" name="sender_uname" value="'.
1935: $notif_sender.'" size="10" /> '.&mt('domain').
1936: ': '.$domform.'</span></td></tr>'.
1937: '<tr class="LC_odd_row">'.
1938: '<td>'.&mt('Automatically assign co-ownership').'</td>'.
1939: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1940: '<input type="radio" name="autoassign_coowners"'.
1941: $coownerson.' value="1" />'.&mt('Yes').'</label> '.
1942: '<label><input type="radio" name="autoassign_coowners"'.
1943: $coownersoff.' value="0" />'.&mt('No').'</label></span></td>'.
1944: '</tr>';
1945: $$rowtotal += 3;
1946: return $datatable;
1947: }
1948:
1949: sub print_autoupdate {
1950: my ($position,$dom,$settings,$rowtotal) = @_;
1951: my $datatable;
1952: if ($position eq 'top') {
1953: my $updateon = ' ';
1954: my $updateoff = ' checked="checked" ';
1955: my $classlistson = ' ';
1956: my $classlistsoff = ' checked="checked" ';
1957: if (ref($settings) eq 'HASH') {
1958: if ($settings->{'run'} eq '1') {
1959: $updateon = $updateoff;
1960: $updateoff = ' ';
1961: }
1962: if ($settings->{'classlists'} eq '1') {
1963: $classlistson = $classlistsoff;
1964: $classlistsoff = ' ';
1965: }
1966: }
1967: my %title = (
1968: run => 'Auto-update active?',
1969: classlists => 'Update information in classlists?',
1970: );
1971: $datatable = '<tr class="LC_odd_row">'.
1972: '<td>'.&mt($title{'run'}).'</td>'.
1973: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1974: '<input type="radio" name="autoupdate_run"'.
1975: $updateon.' value="1" />'.&mt('Yes').'</label> '.
1976: '<label><input type="radio" name="autoupdate_run"'.
1977: $updateoff.'value="0" />'.&mt('No').'</label></span></td>'.
1978: '</tr><tr>'.
1979: '<td>'.&mt($title{'classlists'}).'</td>'.
1980: '<td class="LC_right_item"><span class="LC_nobreak">'.
1981: '<label><input type="radio" name="classlists"'.
1982: $classlistson.' value="1" />'.&mt('Yes').'</label> '.
1983: '<label><input type="radio" name="classlists"'.
1984: $classlistsoff.'value="0" />'.&mt('No').'</label></span></td>'.
1985: '</tr>';
1986: $$rowtotal += 2;
1987: } elsif ($position eq 'middle') {
1988: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1989: my $numinrow = 3;
1990: my $locknamesettings;
1991: $datatable .= &insttypes_row($settings,$types,$usertypes,
1992: $dom,$numinrow,$othertitle,
1993: 'lockablenames');
1994: $$rowtotal ++;
1995: } else {
1996: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1997: my @fields = ('lastname','firstname','middlename','generation',
1998: 'permanentemail','id');
1999: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
2000: my $numrows = 0;
2001: if (ref($types) eq 'ARRAY') {
2002: if (@{$types} > 0) {
2003: $datatable =
2004: &usertype_update_row($settings,$usertypes,\%fieldtitles,
2005: \@fields,$types,\$numrows);
2006: $$rowtotal += @{$types};
2007: }
2008: }
2009: $datatable .=
2010: &usertype_update_row($settings,{'default' => $othertitle},
2011: \%fieldtitles,\@fields,['default'],
2012: \$numrows);
2013: $$rowtotal ++;
2014: }
2015: return $datatable;
2016: }
2017:
2018: sub print_autocreate {
2019: my ($dom,$settings,$rowtotal) = @_;
2020: my (%createon,%createoff);
2021: my $curr_dc;
2022: my @types = ('xml','req');
2023: if (ref($settings) eq 'HASH') {
2024: foreach my $item (@types) {
2025: $createoff{$item} = ' checked="checked" ';
2026: $createon{$item} = ' ';
2027: if (exists($settings->{$item})) {
2028: if ($settings->{$item}) {
2029: $createon{$item} = ' checked="checked" ';
2030: $createoff{$item} = ' ';
2031: }
2032: }
2033: }
2034: $curr_dc = $settings->{'xmldc'};
2035: } else {
2036: foreach my $item (@types) {
2037: $createoff{$item} = ' checked="checked" ';
2038: $createon{$item} = ' ';
2039: }
2040: }
2041: $$rowtotal += 2;
2042: my $datatable='<tr class="LC_odd_row">'.
2043: '<td>'.&mt('Create pending official courses from XML files').'</td>'.
2044: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2045: '<input type="radio" name="autocreate_xml"'.
2046: $createon{'xml'}.' value="1" />'.&mt('Yes').'</label> '.
2047: '<label><input type="radio" name="autocreate_xml"'.
2048: $createoff{'xml'}.' value="0" />'.&mt('No').'</label></span>'.
2049: '</td></tr><tr>'.
2050: '<td>'.&mt('Create pending requests for official courses (if validated)').'</td>'.
2051: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2052: '<input type="radio" name="autocreate_req"'.
2053: $createon{'req'}.' value="1" />'.&mt('Yes').'</label> '.
2054: '<label><input type="radio" name="autocreate_req"'.
2055: $createoff{'req'}.' value="0" />'.&mt('No').'</label></span>';
2056: my ($numdc,$dctable) = &active_dc_picker($dom,$curr_dc);
2057: if ($numdc > 1) {
2058: $datatable .= '</td></tr><tr class="LC_odd_row"><td>'.
2059: &mt('Course creation processed as: (choose Dom. Coord.)').
2060: '</td><td class="LC_left_item">'.$dctable.'</td></tr>';
2061: $$rowtotal ++ ;
2062: } else {
2063: $datatable .= $dctable.'</td></tr>';
2064: }
2065: return $datatable;
2066: }
2067:
2068: sub print_directorysrch {
2069: my ($dom,$settings,$rowtotal) = @_;
2070: my $srchon = ' ';
2071: my $srchoff = ' checked="checked" ';
2072: my ($exacton,$containson,$beginson);
2073: my $localon = ' ';
2074: my $localoff = ' checked="checked" ';
2075: if (ref($settings) eq 'HASH') {
2076: if ($settings->{'available'} eq '1') {
2077: $srchon = $srchoff;
2078: $srchoff = ' ';
2079: }
2080: if ($settings->{'localonly'} eq '1') {
2081: $localon = $localoff;
2082: $localoff = ' ';
2083: }
2084: if (ref($settings->{'searchtypes'}) eq 'ARRAY') {
2085: foreach my $type (@{$settings->{'searchtypes'}}) {
2086: if ($type eq 'exact') {
2087: $exacton = ' checked="checked" ';
2088: } elsif ($type eq 'contains') {
2089: $containson = ' checked="checked" ';
2090: } elsif ($type eq 'begins') {
2091: $beginson = ' checked="checked" ';
2092: }
2093: }
2094: } else {
2095: if ($settings->{'searchtypes'} eq 'exact') {
2096: $exacton = ' checked="checked" ';
2097: } elsif ($settings->{'searchtypes'} eq 'contains') {
2098: $containson = ' checked="checked" ';
2099: } elsif ($settings->{'searchtypes'} eq 'specify') {
2100: $exacton = ' checked="checked" ';
2101: $containson = ' checked="checked" ';
2102: }
2103: }
2104: }
2105: my ($searchtitles,$titleorder) = &sorted_searchtitles();
2106: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
2107:
2108: my $numinrow = 4;
2109: my $cansrchrow = 0;
2110: my $datatable='<tr class="LC_odd_row">'.
2111: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Directory search available?').'</span></td>'.
2112: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2113: '<input type="radio" name="dirsrch_available"'.
2114: $srchon.' value="1" />'.&mt('Yes').'</label> '.
2115: '<label><input type="radio" name="dirsrch_available"'.
2116: $srchoff.' value="0" />'.&mt('No').'</label></span></td>'.
2117: '</tr><tr>'.
2118: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search?').'</span></td>'.
2119: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2120: '<input type="radio" name="dirsrch_localonly"'.
2121: $localoff.' value="0" />'.&mt('Yes').'</label> '.
2122: '<label><input type="radio" name="dirsrch_localonly"'.
2123: $localon.' value="1" />'.&mt('No').'</label></span></td>'.
2124: '</tr>';
2125: $$rowtotal += 2;
2126: if (ref($usertypes) eq 'HASH') {
2127: if (keys(%{$usertypes}) > 0) {
2128: $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
2129: $numinrow,$othertitle,'cansearch');
2130: $cansrchrow = 1;
2131: }
2132: }
2133: if ($cansrchrow) {
2134: $$rowtotal ++;
2135: $datatable .= '<tr>';
2136: } else {
2137: $datatable .= '<tr class="LC_odd_row">';
2138: }
2139: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Supported search methods').
2140: '</span></td><td class="LC_left_item" colspan="2"><table><tr>';
2141: foreach my $title (@{$titleorder}) {
2142: if (defined($searchtitles->{$title})) {
2143: my $check = ' ';
2144: if (ref($settings) eq 'HASH') {
2145: if (ref($settings->{'searchby'}) eq 'ARRAY') {
2146: if (grep(/^\Q$title\E$/,@{$settings->{'searchby'}})) {
2147: $check = ' checked="checked" ';
2148: }
2149: }
2150: }
2151: $datatable .= '<td class="LC_left_item">'.
2152: '<span class="LC_nobreak"><label>'.
2153: '<input type="checkbox" name="searchby" '.
2154: 'value="'.$title.'"'.$check.'/>'.
2155: $searchtitles->{$title}.'</label></span></td>';
2156: }
2157: }
2158: $datatable .= '</tr></table></td></tr>';
2159: $$rowtotal ++;
2160: if ($cansrchrow) {
2161: $datatable .= '<tr class="LC_odd_row">';
2162: } else {
2163: $datatable .= '<tr>';
2164: }
2165: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Search latitude').'</span></td>'.
2166: '<td class="LC_left_item" colspan="2">'.
2167: '<span class="LC_nobreak"><label>'.
2168: '<input type="checkbox" name="searchtypes" '.
2169: $exacton.' value="exact" />'.&mt('Exact match').
2170: '</label> '.
2171: '<label><input type="checkbox" name="searchtypes" '.
2172: $beginson.' value="begins" />'.&mt('Begins with').
2173: '</label> '.
2174: '<label><input type="checkbox" name="searchtypes" '.
2175: $containson.' value="contains" />'.&mt('Contains').
2176: '</label></span></td></tr>';
2177: $$rowtotal ++;
2178: return $datatable;
2179: }
2180:
2181: sub print_contacts {
2182: my ($dom,$settings,$rowtotal) = @_;
2183: my $datatable;
2184: my @contacts = ('adminemail','supportemail');
2185: my (%checked,%to,%otheremails,%bccemails);
2186: my @mailings = ('errormail','packagesmail','lonstatusmail','helpdeskmail',
2187: 'requestsmail');
2188: foreach my $type (@mailings) {
2189: $otheremails{$type} = '';
2190: }
2191: $bccemails{'helpdeskmail'} = '';
2192: if (ref($settings) eq 'HASH') {
2193: foreach my $item (@contacts) {
2194: if (exists($settings->{$item})) {
2195: $to{$item} = $settings->{$item};
2196: }
2197: }
2198: foreach my $type (@mailings) {
2199: if (exists($settings->{$type})) {
2200: if (ref($settings->{$type}) eq 'HASH') {
2201: foreach my $item (@contacts) {
2202: if ($settings->{$type}{$item}) {
2203: $checked{$type}{$item} = ' checked="checked" ';
2204: }
2205: }
2206: $otheremails{$type} = $settings->{$type}{'others'};
2207: if ($type eq 'helpdeskmail') {
2208: $bccemails{$type} = $settings->{$type}{'bcc'};
2209: }
2210: }
2211: } elsif ($type eq 'lonstatusmail') {
2212: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
2213: }
2214: }
2215: } else {
2216: $to{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
2217: $to{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
2218: $checked{'errormail'}{'adminemail'} = ' checked="checked" ';
2219: $checked{'packagesmail'}{'adminemail'} = ' checked="checked" ';
2220: $checked{'helpdeskmail'}{'supportemail'} = ' checked="checked" ';
2221: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
2222: $checked{'requestsmail'}{'adminemail'} = ' checked="checked" ';
2223: }
2224: my ($titles,$short_titles) = &contact_titles();
2225: my $rownum = 0;
2226: my $css_class;
2227: foreach my $item (@contacts) {
2228: $rownum ++;
2229: $css_class = $rownum%2?' class="LC_odd_row"':'';
2230: $datatable .= '<tr'.$css_class.'>'.
2231: '<td><span class="LC_nobreak">'.$titles->{$item}.
2232: '</span></td><td class="LC_right_item">'.
2233: '<input type="text" name="'.$item.'" value="'.
2234: $to{$item}.'" /></td></tr>';
2235: }
2236: foreach my $type (@mailings) {
2237: $rownum ++;
2238: $css_class = $rownum%2?' class="LC_odd_row"':'';
2239: $datatable .= '<tr'.$css_class.'>'.
2240: '<td><span class="LC_nobreak">'.
2241: $titles->{$type}.': </span></td>'.
2242: '<td class="LC_left_item">'.
2243: '<span class="LC_nobreak">';
2244: foreach my $item (@contacts) {
2245: $datatable .= '<label>'.
2246: '<input type="checkbox" name="'.$type.'"'.
2247: $checked{$type}{$item}.
2248: ' value="'.$item.'" />'.$short_titles->{$item}.
2249: '</label> ';
2250: }
2251: $datatable .= '</span><br />'.&mt('Others').': '.
2252: '<input type="text" name="'.$type.'_others" '.
2253: 'value="'.$otheremails{$type}.'" />';
2254: if ($type eq 'helpdeskmail') {
2255: $datatable .= '<br />'.&mt('Bcc:').(' 'x6).
2256: '<input type="text" name="'.$type.'_bcc" '.
2257: 'value="'.$bccemails{$type}.'" />';
2258: }
2259: $datatable .= '</td></tr>'."\n";
2260: }
2261: $$rowtotal += $rownum;
2262: return $datatable;
2263: }
2264:
2265: sub print_helpsettings {
2266:
2267: my ($position,$dom,$confname,$settings,$rowtotal) = @_;
2268: my ($css_class,$datatable);
2269:
2270: my $switchserver = &check_switchserver($dom,$confname);
2271:
2272: my $itemcount = 1;
2273:
2274: if ($position eq 'top') {
2275:
2276: my (%checkedon,%checkedoff,%choices,%defaultchecked,@toggles);
2277:
2278: %choices =
2279: &Apache::lonlocal::texthash (
2280: submitbugs => 'Display "Submit a bug" link?',
2281: );
2282:
2283: %defaultchecked = ('submitbugs' => 'on');
2284:
2285: @toggles = ('submitbugs',);
2286:
2287: foreach my $item (@toggles) {
2288: if ($defaultchecked{$item} eq 'on') {
2289: $checkedon{$item} = ' checked="checked" ';
2290: $checkedoff{$item} = ' ';
2291: } elsif ($defaultchecked{$item} eq 'off') {
2292: $checkedoff{$item} = ' checked="checked" ';
2293: $checkedon{$item} = ' ';
2294: }
2295: }
2296:
2297: if (ref($settings) eq 'HASH') {
2298: foreach my $item (@toggles) {
2299: if ($settings->{$item} eq '1') {
2300: $checkedon{$item} = ' checked="checked" ';
2301: $checkedoff{$item} = ' ';
2302: } elsif ($settings->{$item} eq '0') {
2303: $checkedoff{$item} = ' checked="checked" ';
2304: $checkedon{$item} = ' ';
2305: }
2306: }
2307: }
2308:
2309: foreach my $item (@toggles) {
2310: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
2311: $datatable .=
2312: '<tr'.$css_class.'>
2313: <td><span class="LC_nobreak">'.$choices{$item}.'</span></td>
2314: <td><span class="LC_nobreak"> </span></td>
2315: <td class="LC_right_item"><span class="LC_nobreak">
2316: <label><input type="radio" name="'.$item.'" '.$checkedon{$item}.' value="1" />'.&mt('Yes').'</label>
2317: <label><input type="radio" name="'.$item.'" '.$checkedoff{$item}.' value="0" />'.&mt('No').'</label>'.
2318: '</span></td>'.
2319: '</tr>';
2320: $itemcount ++;
2321: }
2322:
2323: } else {
2324:
2325: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
2326:
2327: $datatable .= '<tr'.$css_class.'>';
2328:
2329: if (ref($settings) eq 'HASH') {
2330: if ($settings->{'loginhelpurl'} ne '') {
2331: my($directory, $filename) = $settings->{'loginhelpurl'} =~ m/(.*\/)(.*)$/;
2332: $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>';
2333: $datatable .= '<td width="33%"><span class="LC_right_item"><label><input type="checkbox" name="loginhelpurl_del" value="1" />'.&mt('Delete?').'</label></span></td>'
2334: } else {
2335: $datatable .= '<td width="33%"><span class="LC_left_item"><label>'.&mt('Default Login Page Help File In Use').'</label></span></td>';
2336: $datatable .= '<td width="33%"><span class="LC_right_item"> </span></td>';
2337: }
2338: } else {
2339: $datatable .= '<td><span class="LC_left_item"> </span></td>';
2340: $datatable .= '<td><span class="LC_right_item"> </span></td>';
2341: }
2342:
2343: $datatable .= '<td width="33%"><span class="LC_right_item">';
2344: if ($switchserver) {
2345: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2346: } else {
2347: $datatable .= &mt('Upload Custom Login Page Help File:');
2348: $datatable .='<input type="file" name="loginhelpurl" />';
2349: }
2350: $datatable .= '</span></td></tr>';
2351:
2352: }
2353:
2354: return $datatable;
2355:
2356: }
2357:
2358:
2359: sub radiobutton_prefs {
2360: my ($settings,$toggles,$defaultchecked,$choices,$itemcount) = @_;
2361: return unless ((ref($toggles) eq 'ARRAY') && (ref($defaultchecked) eq 'HASH') &&
2362: (ref($choices) eq 'HASH'));
2363:
2364: my (%checkedon,%checkedoff,$datatable,$css_class);
2365:
2366: foreach my $item (@{$toggles}) {
2367: if ($defaultchecked->{$item} eq 'on') {
2368: $checkedon{$item} = ' checked="checked" ';
2369: $checkedoff{$item} = ' ';
2370: } elsif ($defaultchecked->{$item} eq 'off') {
2371: $checkedoff{$item} = ' checked="checked" ';
2372: $checkedon{$item} = ' ';
2373: }
2374: }
2375: if (ref($settings) eq 'HASH') {
2376: foreach my $item (@{$toggles}) {
2377: if ($settings->{$item} eq '1') {
2378: $checkedon{$item} = ' checked="checked" ';
2379: $checkedoff{$item} = ' ';
2380: } elsif ($settings->{$item} eq '0') {
2381: $checkedoff{$item} = ' checked="checked" ';
2382: $checkedon{$item} = ' ';
2383: }
2384: }
2385: }
2386: foreach my $item (@{$toggles}) {
2387: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2388: $datatable .=
2389: '<tr'.$css_class.'><td><span class="LC_nobreak">'.$choices->{$item}.
2390: '</span></td>'.
2391: '<td class="LC_right_item"><span class="LC_nobreak">'.
2392: '<label><input type="radio" name="'.
2393: $item.'" '.$checkedon{$item}.' value="1" />'.&mt('Yes').
2394: '</label> <label><input type="radio" name="'.$item.'" '.
2395: $checkedoff{$item}.' value="0" />'.&mt('No').'</label>'.
2396: '</span></td>'.
2397: '</tr>';
2398: $itemcount ++;
2399: }
2400: return ($datatable,$itemcount);
2401: }
2402:
2403: sub print_coursedefaults {
2404: my ($position,$dom,$settings,$rowtotal) = @_;
2405: my ($css_class,$datatable);
2406: my $itemcount = 1;
2407: if ($position eq 'top') {
2408: my (%checkedon,%checkedoff,%choices,%defaultchecked,@toggles);
2409: %choices =
2410: &Apache::lonlocal::texthash (
2411: canuse_pdfforms => 'Course/Community users can create/upload PDF forms',
2412: );
2413: %defaultchecked = ('canuse_pdfforms' => 'off');
2414: @toggles = ('canuse_pdfforms',);
2415: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
2416: \%choices,$itemcount);
2417: $$rowtotal += $itemcount;
2418: } else {
2419: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
2420: my %choices =
2421: &Apache::lonlocal::texthash (
2422: anonsurvey_threshold => 'Responder count needed before showing submissions for anonymous surveys',
2423: );
2424: my $currdefresponder;
2425: if (ref($settings) eq 'HASH') {
2426: $currdefresponder = $settings->{'anonsurvey_threshold'};
2427: }
2428: if (!$currdefresponder) {
2429: $currdefresponder = 10;
2430: } elsif ($currdefresponder < 1) {
2431: $currdefresponder = 1;
2432: }
2433: $datatable .=
2434: '<tr'.$css_class.'><td><span class="LC_nobreak">'.$choices{'anonsurvey_threshold'}.
2435: '</span></td>'.
2436: '<td class="LC_right_item"><span class="LC_nobreak">'.
2437: '<input type="text" name="anonsurvey_threshold"'.
2438: ' value="'.$currdefresponder.'" size="5" /></span>'.
2439: '</td></tr>';
2440: }
2441: return $datatable;
2442: }
2443:
2444: sub print_usersessions {
2445: my ($position,$dom,$settings,$rowtotal) = @_;
2446: my ($css_class,$datatable,%checked,%choices);
2447: my (%by_ip,%by_location,@intdoms);
2448: &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
2449:
2450: my @alldoms = &Apache::lonnet::all_domains();
2451: my %serverhomes = %Apache::lonnet::serverhomeIDs;
2452: my %servers = &Apache::lonnet::internet_dom_servers($dom);
2453: my %altids = &id_for_thisdom(%servers);
2454: my $itemcount = 1;
2455: if ($position eq 'top') {
2456: if (keys(%serverhomes) > 1) {
2457: my %spareid = ¤t_offloads_to($dom,$settings,\%servers);
2458: $datatable .= &spares_row($dom,\%servers,\%spareid,\%serverhomes,\%altids,$rowtotal);
2459: } else {
2460: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
2461: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one server.');
2462: }
2463: } else {
2464: if (keys(%by_location) == 0) {
2465: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
2466: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one institution.');
2467: } else {
2468: my %lt = &usersession_titles();
2469: my $numinrow = 5;
2470: my $prefix;
2471: my @types;
2472: if ($position eq 'bottom') {
2473: $prefix = 'remote';
2474: @types = ('version','excludedomain','includedomain');
2475: } else {
2476: $prefix = 'hosted';
2477: @types = ('excludedomain','includedomain');
2478: }
2479: my (%current,%checkedon,%checkedoff);
2480: my @lcversions = &Apache::lonnet::all_loncaparevs();
2481: my @locations = sort(keys(%by_location));
2482: foreach my $type (@types) {
2483: $checkedon{$type} = '';
2484: $checkedoff{$type} = ' checked="checked"';
2485: }
2486: if (ref($settings) eq 'HASH') {
2487: if (ref($settings->{$prefix}) eq 'HASH') {
2488: foreach my $key (keys(%{$settings->{$prefix}})) {
2489: $current{$key} = $settings->{$prefix}{$key};
2490: if ($key eq 'version') {
2491: if ($current{$key} ne '') {
2492: $checkedon{$key} = ' checked="checked"';
2493: $checkedoff{$key} = '';
2494: }
2495: } elsif (ref($current{$key}) eq 'ARRAY') {
2496: $checkedon{$key} = ' checked="checked"';
2497: $checkedoff{$key} = '';
2498: }
2499: }
2500: }
2501: }
2502: foreach my $type (@types) {
2503: next if ($type ne 'version' && !@locations);
2504: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
2505: $datatable .= '<tr'.$css_class.'>
2506: <td><span class="LC_nobreak">'.$lt{$type}.'</span><br />
2507: <span class="LC_nobreak">
2508: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedoff{$type}.' value="0" />'.&mt('Not in use').'</label>
2509: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedon{$type}.' value="1" />'.&mt('In use').'</label></span></td><td>';
2510: if ($type eq 'version') {
2511: my $selector = '<select name="'.$prefix.'_version">';
2512: foreach my $version (@lcversions) {
2513: my $selected = '';
2514: if ($current{'version'} eq $version) {
2515: $selected = ' selected="selected"';
2516: }
2517: $selector .= ' <option value="'.$version.'"'.
2518: $selected.'>'.$version.'</option>';
2519: }
2520: $selector .= '</select> ';
2521: $datatable .= &mt('remote server must be version: [_1] or later',$selector);
2522: } else {
2523: $datatable.= '<div><input type="button" value="'.&mt('check all').'" '.
2524: 'onclick="javascript:checkAll(document.display.'.$prefix.'_'.$type.')"'.
2525: ' />'.(' 'x2).
2526: '<input type="button" value="'.&mt('uncheck all').'" '.
2527: 'onclick="javascript:uncheckAll(document.display.'.$prefix.'_'.$type.')" />'.
2528: "\n".
2529: '</div><div><table>';
2530: my $rem;
2531: for (my $i=0; $i<@locations; $i++) {
2532: my ($showloc,$value,$checkedtype);
2533: if (ref($by_location{$locations[$i]}) eq 'ARRAY') {
2534: my $ip = $by_location{$locations[$i]}->[0];
2535: if (ref($by_ip{$ip}) eq 'ARRAY') {
2536: $value = join(':',@{$by_ip{$ip}});
2537: $showloc = join(', ',@{$by_ip{$ip}});
2538: if (ref($current{$type}) eq 'ARRAY') {
2539: foreach my $loc (@{$by_ip{$ip}}) {
2540: if (grep(/^\Q$loc\E$/,@{$current{$type}})) {
2541: $checkedtype = ' checked="checked"';
2542: last;
2543: }
2544: }
2545: }
2546: }
2547: }
2548: $rem = $i%($numinrow);
2549: if ($rem == 0) {
2550: if ($i > 0) {
2551: $datatable .= '</tr>';
2552: }
2553: $datatable .= '<tr>';
2554: }
2555: $datatable .= '<td class="LC_left_item">'.
2556: '<span class="LC_nobreak"><label>'.
2557: '<input type="checkbox" name="'.$prefix.'_'.$type.
2558: '" value="'.$value.'"'.$checkedtype.' />'.$showloc.
2559: '</label></span></td>';
2560: }
2561: $rem = @locations%($numinrow);
2562: my $colsleft = $numinrow - $rem;
2563: if ($colsleft > 1 ) {
2564: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
2565: ' </td>';
2566: } elsif ($colsleft == 1) {
2567: $datatable .= '<td class="LC_left_item"> </td>';
2568: }
2569: $datatable .= '</tr></table>';
2570: }
2571: $datatable .= '</td></tr>';
2572: $itemcount ++;
2573: }
2574: }
2575: }
2576: $$rowtotal += $itemcount;
2577: return $datatable;
2578: }
2579:
2580: sub build_location_hashes {
2581: my ($intdoms,$by_ip,$by_location) = @_;
2582: return unless((ref($intdoms) eq 'ARRAY') && (ref($by_ip) eq 'HASH') &&
2583: (ref($by_location) eq 'HASH'));
2584: my %iphost = &Apache::lonnet::get_iphost();
2585: my $primary_id = &Apache::lonnet::domain($env{'request.role.domain'},'primary');
2586: my $primary_ip = &Apache::lonnet::get_host_ip($primary_id);
2587: if (ref($iphost{$primary_ip}) eq 'ARRAY') {
2588: foreach my $id (@{$iphost{$primary_ip}}) {
2589: my $intdom = &Apache::lonnet::internet_dom($id);
2590: unless(grep(/^\Q$intdom\E$/,@{$intdoms})) {
2591: push(@{$intdoms},$intdom);
2592: }
2593: }
2594: }
2595: foreach my $ip (keys(%iphost)) {
2596: if (ref($iphost{$ip}) eq 'ARRAY') {
2597: foreach my $id (@{$iphost{$ip}}) {
2598: my $location = &Apache::lonnet::internet_dom($id);
2599: if ($location) {
2600: next if (grep(/^\Q$location\E$/,@{$intdoms}));
2601: if (ref($by_ip->{$ip}) eq 'ARRAY') {
2602: unless(grep(/^\Q$location\E$/,@{$by_ip->{$ip}})) {
2603: push(@{$by_ip->{$ip}},$location);
2604: }
2605: } else {
2606: $by_ip->{$ip} = [$location];
2607: }
2608: }
2609: }
2610: }
2611: }
2612: foreach my $ip (sort(keys(%{$by_ip}))) {
2613: if (ref($by_ip->{$ip}) eq 'ARRAY') {
2614: @{$by_ip->{$ip}} = sort(@{$by_ip->{$ip}});
2615: my $first = $by_ip->{$ip}->[0];
2616: if (ref($by_location->{$first}) eq 'ARRAY') {
2617: unless (grep(/^\Q$ip\E$/,@{$by_location->{$first}})) {
2618: push(@{$by_location->{$first}},$ip);
2619: }
2620: } else {
2621: $by_location->{$first} = [$ip];
2622: }
2623: }
2624: }
2625: return;
2626: }
2627:
2628: sub current_offloads_to {
2629: my ($dom,$settings,$servers) = @_;
2630: my (%spareid,%otherdomconfigs);
2631: if (ref($servers) eq 'HASH') {
2632: foreach my $lonhost (sort(keys(%{$servers}))) {
2633: my $gotspares;
2634: if (ref($settings) eq 'HASH') {
2635: if (ref($settings->{'spares'}) eq 'HASH') {
2636: if (ref($settings->{'spares'}{$lonhost}) eq 'HASH') {
2637: $spareid{$lonhost}{'primary'} = $settings->{'spares'}{$lonhost}{'primary'};
2638: $spareid{$lonhost}{'default'} = $settings->{'spares'}{$lonhost}{'default'};
2639: $gotspares = 1;
2640: }
2641: }
2642: }
2643: unless ($gotspares) {
2644: my $gotspares;
2645: my $serverhomeID =
2646: &Apache::lonnet::get_server_homeID($servers->{$lonhost});
2647: my $serverhomedom =
2648: &Apache::lonnet::host_domain($serverhomeID);
2649: if ($serverhomedom ne $dom) {
2650: if (ref($otherdomconfigs{$serverhomedom} eq 'HASH')) {
2651: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
2652: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
2653: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
2654: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
2655: $gotspares = 1;
2656: }
2657: }
2658: } else {
2659: $otherdomconfigs{$serverhomedom} =
2660: &Apache::lonnet::get_dom('configuration',['usersessions'],$serverhomedom);
2661: if (ref($otherdomconfigs{$serverhomedom}) eq 'HASH') {
2662: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
2663: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
2664: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{$lonhost}) eq 'HASH') {
2665: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
2666: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
2667: $gotspares = 1;
2668: }
2669: }
2670: }
2671: }
2672: }
2673: }
2674: }
2675: unless ($gotspares) {
2676: if ($lonhost eq $Apache::lonnet::perlvar{'lonHostID'}) {
2677: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
2678: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
2679: } else {
2680: my $server_hostname = &Apache::lonnet::hostname($lonhost);
2681: my $server_homeID = &Apache::lonnet::get_server_homeID($server_hostname);
2682: if ($server_homeID eq $Apache::lonnet::perlvar{'lonHostID'}) {
2683: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
2684: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
2685: } else {
2686: my %what = (
2687: spareid => 1,
2688: );
2689: my ($result,$returnhash) =
2690: &Apache::lonnet::get_remote_globals($lonhost,\%what);
2691: if ($result eq 'ok') {
2692: if (ref($returnhash) eq 'HASH') {
2693: if (ref($returnhash->{'spareid'}) eq 'HASH') {
2694: $spareid{$lonhost}{'primary'} = $returnhash->{'spareid'}->{'primary'};
2695: $spareid{$lonhost}{'default'} = $returnhash->{'spareid'}->{'default'};
2696: }
2697: }
2698: }
2699: }
2700: }
2701: }
2702: }
2703: }
2704: return %spareid;
2705: }
2706:
2707: sub spares_row {
2708: my ($dom,$servers,$spareid,$serverhomes,$altids,$rowtotal) = @_;
2709: my $css_class;
2710: my $numinrow = 4;
2711: my $itemcount = 1;
2712: my $datatable;
2713: my %typetitles = &sparestype_titles();
2714: if ((ref($servers) eq 'HASH') && (ref($spareid) eq 'HASH') && (ref($altids) eq 'HASH')) {
2715: foreach my $server (sort(keys(%{$servers}))) {
2716: my $serverhome = &Apache::lonnet::get_server_homeID($servers->{$server});
2717: my ($othercontrol,$serverdom);
2718: if ($serverhome ne $server) {
2719: $serverdom = &Apache::lonnet::host_domain($serverhome);
2720: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
2721: } else {
2722: $serverdom = &Apache::lonnet::host_domain($server);
2723: if ($serverdom ne $dom) {
2724: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
2725: }
2726: }
2727: next unless (ref($spareid->{$server}) eq 'HASH');
2728: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
2729: $datatable .= '<tr'.$css_class.'>
2730: <td rowspan="2">
2731: <span class="LC_nobreak"><b>'.$server.'</b> when busy, offloads to:</span></td>'."\n";
2732: my (%current,%canselect);
2733: my @choices =
2734: &possible_newspares($server,$spareid->{$server},$serverhomes,$altids);
2735: foreach my $type ('primary','default') {
2736: if (ref($spareid->{$server}) eq 'HASH') {
2737: if (ref($spareid->{$server}{$type}) eq 'ARRAY') {
2738: my @spares = @{$spareid->{$server}{$type}};
2739: if (@spares > 0) {
2740: if ($othercontrol) {
2741: $current{$type} = join(', ',@spares);
2742: } else {
2743: $current{$type} .= '<table>';
2744: my $numspares = scalar(@spares);
2745: for (my $i=0; $i<@spares; $i++) {
2746: my $rem = $i%($numinrow);
2747: if ($rem == 0) {
2748: if ($i > 0) {
2749: $current{$type} .= '</tr>';
2750: }
2751: $current{$type} .= '<tr>';
2752: }
2753: $current{$type} .= '<td><label><input type="checkbox" name="spare_'.$type.'_'.$server.'" id="spare_'.$type.'_'.$server.'_'.$i.'" checked="checked" value="'.$spareid->{$server}{$type}[$i].'" onclick="updateNewSpares(this.form,'."'$server'".');" /> '.
2754: $spareid->{$server}{$type}[$i].
2755: '</label></td>'."\n";
2756: }
2757: my $rem = @spares%($numinrow);
2758: my $colsleft = $numinrow - $rem;
2759: if ($colsleft > 1 ) {
2760: $current{$type} .= '<td colspan="'.$colsleft.
2761: '" class="LC_left_item">'.
2762: ' </td>';
2763: } elsif ($colsleft == 1) {
2764: $current{$type} .= '<td class="LC_left_item"> </td>'."\n";
2765: }
2766: $current{$type} .= '</tr></table>';
2767: }
2768: }
2769: }
2770: if ($current{$type} eq '') {
2771: $current{$type} = &mt('None specified');
2772: }
2773: if ($othercontrol) {
2774: if ($type eq 'primary') {
2775: $canselect{$type} = $othercontrol;
2776: }
2777: } else {
2778: $canselect{$type} =
2779: &mt('Add new [_1]'.$type.'[_2]:','<i>','</i>').' '.
2780: '<select name="newspare_'.$type.'_'.$server.'" '.
2781: 'id="newspare_'.$type.'_'.$server.'" onchange="checkNewSpares('."'$server','$type'".');">'."\n".
2782: '<option value="" selected ="selected">'.&mt('Select').'</option>'."\n";
2783: if (@choices > 0) {
2784: foreach my $lonhost (@choices) {
2785: $canselect{$type} .= '<option value="'.$lonhost.'">'.$lonhost.'</option>'."\n";
2786: }
2787: }
2788: $canselect{$type} .= '</select>'."\n";
2789: }
2790: } else {
2791: $current{$type} = &mt('Could not be determined');
2792: if ($type eq 'primary') {
2793: $canselect{$type} = $othercontrol;
2794: }
2795: }
2796: if ($type eq 'default') {
2797: $datatable .= '<tr'.$css_class.'>';
2798: }
2799: $datatable .= '<td><i>'.$typetitles{$type}.'</i></td>'."\n".
2800: '<td>'.$current{$type}.'</td>'."\n".
2801: '<td>'.$canselect{$type}.'</td></tr>'."\n";
2802: }
2803: $itemcount ++;
2804: }
2805: }
2806: $$rowtotal += $itemcount;
2807: return $datatable;
2808: }
2809:
2810: sub possible_newspares {
2811: my ($server,$currspares,$serverhomes,$altids) = @_;
2812: my $serverhostname = &Apache::lonnet::hostname($server);
2813: my %excluded;
2814: if ($serverhostname ne '') {
2815: %excluded = (
2816: $serverhostname => 1,
2817: );
2818: }
2819: if (ref($currspares) eq 'HASH') {
2820: foreach my $type (keys(%{$currspares})) {
2821: if (ref($currspares->{$type}) eq 'ARRAY') {
2822: if (@{$currspares->{$type}} > 0) {
2823: foreach my $curr (@{$currspares->{$type}}) {
2824: my $hostname = &Apache::lonnet::hostname($curr);
2825: $excluded{$hostname} = 1;
2826: }
2827: }
2828: }
2829: }
2830: }
2831: my @choices;
2832: if ((ref($serverhomes) eq 'HASH') && (ref($altids) eq 'HASH')) {
2833: if (keys(%{$serverhomes}) > 1) {
2834: foreach my $name (sort(keys(%{$serverhomes}))) {
2835: unless ($excluded{$name}) {
2836: if (exists($altids->{$serverhomes->{$name}})) {
2837: push(@choices,$altids->{$serverhomes->{$name}});
2838: } else {
2839: push(@choices,$serverhomes->{$name});
2840: }
2841: }
2842: }
2843: }
2844: }
2845: return sort(@choices);
2846: }
2847:
2848: sub print_loadbalancing {
2849: my ($dom,$settings,$rowtotal) = @_;
2850: my $primary_id = &Apache::lonnet::domain($dom,'primary');
2851: my $intdom = &Apache::lonnet::internet_dom($primary_id);
2852: my $numinrow = 1;
2853: my $datatable;
2854: my %servers = &Apache::lonnet::internet_dom_servers($dom);
2855: my ($currbalancer,$currtargets,$currrules);
2856: if (keys(%servers) > 1) {
2857: if (ref($settings) eq 'HASH') {
2858: $currbalancer = $settings->{'lonhost'};
2859: $currtargets = $settings->{'targets'};
2860: $currrules = $settings->{'rules'};
2861: } else {
2862: ($currbalancer,$currtargets) =
2863: &Apache::lonnet::get_lonbalancer_config(\%servers);
2864: }
2865: } else {
2866: return;
2867: }
2868: my ($othertitle,$usertypes,$types) =
2869: &Apache::loncommon::sorted_inst_types($dom);
2870: my $rownum = 6;
2871: if (ref($types) eq 'ARRAY') {
2872: $rownum += scalar(@{$types});
2873: }
2874: my $css_class = ' class="LC_odd_row"';
2875: my $targets_div_style = 'display: none';
2876: my $disabled_div_style = 'display: block';
2877: my $homedom_div_style = 'display: none';
2878: $datatable = '<tr'.$css_class.'>'.
2879: '<td rowspan="'.$rownum.'" valign="top">'.
2880: '<p><select name="loadbalancing_lonhost" onchange="toggleTargets();">'."\n".
2881: '<option value=""';
2882: if (($currbalancer eq '') || (!grep(/^\Q$currbalancer\E$/,keys(%servers)))) {
2883: $datatable .= ' selected="selected"';
2884: } else {
2885: $targets_div_style = 'display: block';
2886: $disabled_div_style = 'display: none';
2887: if ($dom eq &Apache::lonnet::host_domain($currbalancer)) {
2888: $homedom_div_style = 'display: block';
2889: }
2890: }
2891: $datatable .= '>'.&mt('None').'</option>'."\n";
2892: foreach my $lonhost (sort(keys(%servers))) {
2893: my $selected;
2894: if ($lonhost eq $currbalancer) {
2895: $selected .= ' selected="selected"';
2896: }
2897: $datatable .= '<option value="'.$lonhost.'"'.$selected.'>'.$lonhost.'</option>'."\n";
2898: }
2899: $datatable .= '</select></p></td><td rowspan="'.$rownum.'" valign="top">'.
2900: '<div id="loadbalancing_disabled" style="'.$disabled_div_style.'">'.&mt('No dedicated Load Balancer').'</div>'."\n".
2901: '<div id="loadbalancing_targets" style="'.$targets_div_style.'">'.&mt('Offloads to:').'<br />';
2902: my ($numspares,@spares) = &count_servers($currbalancer,%servers);
2903: my @sparestypes = ('primary','default');
2904: my %typetitles = &sparestype_titles();
2905: foreach my $sparetype (@sparestypes) {
2906: my $targettable;
2907: for (my $i=0; $i<$numspares; $i++) {
2908: my $checked;
2909: if (ref($currtargets) eq 'HASH') {
2910: if (ref($currtargets->{$sparetype}) eq 'ARRAY') {
2911: if (grep(/^\Q$spares[$i]\E$/,@{$currtargets->{$sparetype}})) {
2912: $checked = ' checked="checked"';
2913: }
2914: }
2915: }
2916: my $chkboxval;
2917: if (($currbalancer ne '') && (grep((/^\Q$currbalancer\E$/,keys(%servers))))) {
2918: $chkboxval = $spares[$i];
2919: }
2920: $targettable .= '<td><label><input type="checkbox" name="loadbalancing_target_'.$sparetype.'"'.
2921: $checked.' value="'.$chkboxval.'" id="loadbalancing_target_'.$sparetype.'_'.$i.'" onclick="checkOffloads('."this,'$sparetype'".');" /><span id="loadbalancing_targettxt_'.$sparetype.'_'.$i.'"> '.$chkboxval.
2922: '</span></label></td>';
2923: my $rem = $i%($numinrow);
2924: if ($rem == 0) {
2925: if ($i > 0) {
2926: $targettable .= '</tr>';
2927: }
2928: $targettable .= '<tr>';
2929: }
2930: }
2931: if ($targettable ne '') {
2932: my $rem = $numspares%($numinrow);
2933: my $colsleft = $numinrow - $rem;
2934: if ($colsleft > 1 ) {
2935: $targettable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
2936: ' </td>';
2937: } elsif ($colsleft == 1) {
2938: $targettable .= '<td class="LC_left_item"> </td>';
2939: }
2940: $datatable .= '<i>'.$typetitles{$sparetype}.'</i><br />'.
2941: '<table><tr>'.$targettable.'</table><br />';
2942: }
2943: }
2944: $datatable .= '</div></td></tr>'.
2945: &loadbalancing_rules($dom,$intdom,$currrules,$othertitle,
2946: $usertypes,$types,\%servers,$currbalancer,
2947: $targets_div_style,$homedom_div_style,$css_class);
2948: $$rowtotal += $rownum;
2949: return $datatable;
2950: }
2951:
2952: sub loadbalancing_rules {
2953: my ($dom,$intdom,$currrules,$othertitle,$usertypes,$types,$servers,
2954: $currbalancer,$targets_div_style,$homedom_div_style,$css_class) = @_;
2955: my $output;
2956: my ($alltypes,$othertypes,$titles) =
2957: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
2958: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
2959: foreach my $type (@{$alltypes}) {
2960: my $current;
2961: if (ref($currrules) eq 'HASH') {
2962: $current = $currrules->{$type};
2963: }
2964: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
2965: if ($dom ne &Apache::lonnet::host_domain($currbalancer)) {
2966: $current = '';
2967: }
2968: }
2969: $output .= &loadbalance_rule_row($type,$titles->{$type},$current,
2970: $servers,$currbalancer,$dom,
2971: $targets_div_style,$homedom_div_style,$css_class);
2972: }
2973: }
2974: return $output;
2975: }
2976:
2977: sub loadbalancing_titles {
2978: my ($dom,$intdom,$usertypes,$types) = @_;
2979: my %othertypes = (
2980: '_LC_adv' => &mt('Advanced users from [_1]',$dom),
2981: '_LC_author' => &mt('Users from [_1] with author role',$dom),
2982: '_LC_internetdom' => &mt('Users not from [_1], but from [_2]',$dom,$intdom),
2983: '_LC_external' => &mt('Users not from [_1]',$intdom),
2984: );
2985: my @alltypes = ('_LC_adv','_LC_author','_LC_internetdom','_LC_external');
2986: if (ref($types) eq 'ARRAY') {
2987: unshift(@alltypes,@{$types},'default');
2988: }
2989: my %titles;
2990: foreach my $type (@alltypes) {
2991: if ($type =~ /^_LC_/) {
2992: $titles{$type} = $othertypes{$type};
2993: } elsif ($type eq 'default') {
2994: $titles{$type} = &mt('All users from [_1]',$dom);
2995: if (ref($types) eq 'ARRAY') {
2996: if (@{$types} > 0) {
2997: $titles{$type} = &mt('Other users from [_1]',$dom);
2998: }
2999: }
3000: } elsif (ref($usertypes) eq 'HASH') {
3001: $titles{$type} = $usertypes->{$type};
3002: }
3003: }
3004: return (\@alltypes,\%othertypes,\%titles);
3005: }
3006:
3007: sub loadbalance_rule_row {
3008: my ($type,$title,$current,$servers,$currbalancer,$dom,$targets_div_style,
3009: $homedom_div_style,$css_class) = @_;
3010: my @rulenames = ('default','homeserver');
3011: my %ruletitles = &offloadtype_text();
3012: if ($type eq '_LC_external') {
3013: push(@rulenames,'externalbalancer');
3014: } else {
3015: push(@rulenames,'specific');
3016: }
3017: push(@rulenames,'none');
3018: my $style = $targets_div_style;
3019: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
3020: $style = $homedom_div_style;
3021: }
3022: my $output =
3023: '<tr'.$css_class.'><td valign="top"><div id="balanceruletitle_'.$type.'" style="'.$style.'">'.$title.'</div></td>'."\n".
3024: '<td><div id="balancerule_'.$type.'" style="'.$style.'">'."\n";
3025: for (my $i=0; $i<@rulenames; $i++) {
3026: my $rule = $rulenames[$i];
3027: my ($checked,$extra);
3028: if ($rulenames[$i] eq 'default') {
3029: $rule = '';
3030: }
3031: if ($rulenames[$i] eq 'specific') {
3032: if (ref($servers) eq 'HASH') {
3033: my $default;
3034: if (($current ne '') && (exists($servers->{$current}))) {
3035: $checked = ' checked="checked"';
3036: }
3037: unless ($checked) {
3038: $default = ' selected="selected"';
3039: }
3040: $extra = ': <select name="loadbalancing_singleserver_'.$type.
3041: '" id="loadbalancing_singleserver_'.$type.
3042: '" onchange="singleServerToggle('."'$type'".')">'."\n".
3043: '<option value=""'.$default.'></option>'."\n";
3044: foreach my $lonhost (sort(keys(%{$servers}))) {
3045: next if ($lonhost eq $currbalancer);
3046: my $selected;
3047: if ($lonhost eq $current) {
3048: $selected = ' selected="selected"';
3049: }
3050: $extra .= '<option value="'.$lonhost.'"'.$selected.'>'.$lonhost.'</option>';
3051: }
3052: $extra .= '</select>';
3053: }
3054: } elsif ($rule eq $current) {
3055: $checked = ' checked="checked"';
3056: }
3057: $output .= '<span class="LC_nobreak"><label>'.
3058: '<input type="radio" name="loadbalancing_rules_'.$type.
3059: '" id="loadbalancing_rules_'.$type.'_'.$i.'" value="'.
3060: $rule.'" onclick="balanceruleChange('."this.form,'$type'".
3061: ')"'.$checked.' /> '.$ruletitles{$rulenames[$i]}.
3062: '</label>'.$extra.'</span><br />'."\n";
3063: }
3064: $output .= '</div></td></tr>'."\n";
3065: return $output;
3066: }
3067:
3068: sub offloadtype_text {
3069: my %ruletitles = &Apache::lonlocal::texthash (
3070: 'default' => 'Offloads to default destinations',
3071: 'homeserver' => "Offloads to user's home server",
3072: 'externalbalancer' => "Offloads to Load Balancer in user's domain",
3073: 'specific' => 'Offloads to specific server',
3074: 'none' => 'No offload',
3075: );
3076: return %ruletitles;
3077: }
3078:
3079: sub sparestype_titles {
3080: my %typestitles = &Apache::lonlocal::texthash (
3081: 'primary' => 'primary',
3082: 'default' => 'default',
3083: );
3084: return %typestitles;
3085: }
3086:
3087: sub contact_titles {
3088: my %titles = &Apache::lonlocal::texthash (
3089: 'supportemail' => 'Support E-mail address',
3090: 'adminemail' => 'Default Server Admin E-mail address',
3091: 'errormail' => 'Error reports to be e-mailed to',
3092: 'packagesmail' => 'Package update alerts to be e-mailed to',
3093: 'helpdeskmail' => 'Helpdesk requests to be e-mailed to',
3094: 'lonstatusmail' => 'E-mail from nightly status check (warnings/errors)',
3095: 'requestsmail' => 'E-mail from course requests requiring approval',
3096: );
3097: my %short_titles = &Apache::lonlocal::texthash (
3098: adminemail => 'Admin E-mail address',
3099: supportemail => 'Support E-mail',
3100: );
3101: return (\%titles,\%short_titles);
3102: }
3103:
3104: sub tool_titles {
3105: my %titles = &Apache::lonlocal::texthash (
3106: aboutme => 'Personal web page',
3107: blog => 'Blog',
3108: webdav => 'WebDAV',
3109: portfolio => 'Portfolio',
3110: official => 'Official courses (with institutional codes)',
3111: unofficial => 'Unofficial courses',
3112: community => 'Communities',
3113: );
3114: return %titles;
3115: }
3116:
3117: sub courserequest_titles {
3118: my %titles = &Apache::lonlocal::texthash (
3119: official => 'Official',
3120: unofficial => 'Unofficial',
3121: community => 'Communities',
3122: norequest => 'Not allowed',
3123: approval => 'Approval by Dom. Coord.',
3124: validate => 'With validation',
3125: autolimit => 'Numerical limit',
3126: unlimited => '(blank for unlimited)',
3127: );
3128: return %titles;
3129: }
3130:
3131: sub authorrequest_titles {
3132: my %titles = &Apache::lonlocal::texthash (
3133: norequest => 'Not allowed',
3134: approval => 'Approval by Dom. Coord.',
3135: automatic => 'Automatic approval',
3136: );
3137: return %titles;
3138: }
3139:
3140: sub courserequest_conditions {
3141: my %conditions = &Apache::lonlocal::texthash (
3142: approval => '(Processing of request subject to approval by Domain Coordinator).',
3143: validate => '(Processing of request subject to instittutional validation).',
3144: );
3145: return %conditions;
3146: }
3147:
3148:
3149: sub print_usercreation {
3150: my ($position,$dom,$settings,$rowtotal) = @_;
3151: my $numinrow = 4;
3152: my $datatable;
3153: if ($position eq 'top') {
3154: $$rowtotal ++;
3155: my $rowcount = 0;
3156: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username');
3157: if (ref($rules) eq 'HASH') {
3158: if (keys(%{$rules}) > 0) {
3159: $datatable .= &user_formats_row('username',$settings,$rules,
3160: $ruleorder,$numinrow,$rowcount);
3161: $$rowtotal ++;
3162: $rowcount ++;
3163: }
3164: }
3165: my ($idrules,$idruleorder) = &Apache::lonnet::inst_userrules($dom,'id');
3166: if (ref($idrules) eq 'HASH') {
3167: if (keys(%{$idrules}) > 0) {
3168: $datatable .= &user_formats_row('id',$settings,$idrules,
3169: $idruleorder,$numinrow,$rowcount);
3170: $$rowtotal ++;
3171: $rowcount ++;
3172: }
3173: }
3174: my ($emailrules,$emailruleorder) =
3175: &Apache::lonnet::inst_userrules($dom,'email');
3176: if (ref($emailrules) eq 'HASH') {
3177: if (keys(%{$emailrules}) > 0) {
3178: $datatable .= &user_formats_row('email',$settings,$emailrules,
3179: $emailruleorder,$numinrow,$rowcount);
3180: $$rowtotal ++;
3181: $rowcount ++;
3182: }
3183: }
3184: if ($rowcount == 0) {
3185: $datatable .= '<tr><td colspan="2">'.&mt('No format rules have been defined for usernames or IDs in this domain.').'</td></tr>';
3186: $$rowtotal ++;
3187: $rowcount ++;
3188: }
3189: } elsif ($position eq 'middle') {
3190: my @creators = ('author','course','requestcrs','selfcreate');
3191: my ($rules,$ruleorder) =
3192: &Apache::lonnet::inst_userrules($dom,'username');
3193: my %lt = &usercreation_types();
3194: my %checked;
3195: my @selfcreate;
3196: if (ref($settings) eq 'HASH') {
3197: if (ref($settings->{'cancreate'}) eq 'HASH') {
3198: foreach my $item (@creators) {
3199: $checked{$item} = $settings->{'cancreate'}{$item};
3200: }
3201: if (ref($settings->{'cancreate'}{'selfcreate'}) eq 'ARRAY') {
3202: @selfcreate = @{$settings->{'cancreate'}{'selfcreate'}};
3203: } elsif ($settings->{'cancreate'}{'selfcreate'} ne '') {
3204: if ($settings->{'cancreate'}{'selfcreate'} eq 'any') {
3205: @selfcreate = ('email','login','sso');
3206: } elsif ($settings->{'cancreate'}{'selfcreate'} ne 'none') {
3207: @selfcreate = ($settings->{'cancreate'}{'selfcreate'});
3208: }
3209: }
3210: } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {
3211: foreach my $item (@creators) {
3212: if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {
3213: $checked{$item} = 'none';
3214: }
3215: }
3216: }
3217: }
3218: my $rownum = 0;
3219: foreach my $item (@creators) {
3220: $rownum ++;
3221: if ($item ne 'selfcreate') {
3222: if ($checked{$item} eq '') {
3223: $checked{$item} = 'any';
3224: }
3225: }
3226: my $css_class;
3227: if ($rownum%2) {
3228: $css_class = '';
3229: } else {
3230: $css_class = ' class="LC_odd_row" ';
3231: }
3232: $datatable .= '<tr'.$css_class.'>'.
3233: '<td><span class="LC_nobreak">'.$lt{$item}.
3234: '</span></td><td align="right">';
3235: my @options;
3236: if ($item eq 'selfcreate') {
3237: push(@options,('email','login','sso'));
3238: } else {
3239: @options = ('any');
3240: if (ref($rules) eq 'HASH') {
3241: if (keys(%{$rules}) > 0) {
3242: push(@options,('official','unofficial'));
3243: }
3244: }
3245: push(@options,'none');
3246: }
3247: foreach my $option (@options) {
3248: my $type = 'radio';
3249: my $check = ' ';
3250: if ($item eq 'selfcreate') {
3251: $type = 'checkbox';
3252: if (grep(/^\Q$option\E$/,@selfcreate)) {
3253: $check = ' checked="checked" ';
3254: }
3255: } else {
3256: if ($checked{$item} eq $option) {
3257: $check = ' checked="checked" ';
3258: }
3259: }
3260: $datatable .= '<span class="LC_nobreak"><label>'.
3261: '<input type="'.$type.'" name="can_createuser_'.
3262: $item.'" value="'.$option.'"'.$check.'/> '.
3263: $lt{$option}.'</label> </span>';
3264: }
3265: $datatable .= '</td></tr>';
3266: }
3267: my ($othertitle,$usertypes,$types) =
3268: &Apache::loncommon::sorted_inst_types($dom);
3269: if (ref($usertypes) eq 'HASH') {
3270: if (keys(%{$usertypes}) > 0) {
3271: my $createsettings;
3272: if (ref($settings) eq 'HASH') {
3273: $createsettings = $settings->{cancreate};
3274: }
3275: $datatable .= &insttypes_row($createsettings,$types,$usertypes,
3276: $dom,$numinrow,$othertitle,
3277: 'statustocreate');
3278: $$rowtotal ++;
3279: }
3280: }
3281: } else {
3282: my @contexts = ('author','course','domain');
3283: my @authtypes = ('int','krb4','krb5','loc');
3284: my %checked;
3285: if (ref($settings) eq 'HASH') {
3286: if (ref($settings->{'authtypes'}) eq 'HASH') {
3287: foreach my $item (@contexts) {
3288: if (ref($settings->{'authtypes'}{$item}) eq 'HASH') {
3289: foreach my $auth (@authtypes) {
3290: if ($settings->{'authtypes'}{$item}{$auth}) {
3291: $checked{$item}{$auth} = ' checked="checked" ';
3292: }
3293: }
3294: }
3295: }
3296: }
3297: } else {
3298: foreach my $item (@contexts) {
3299: foreach my $auth (@authtypes) {
3300: $checked{$item}{$auth} = ' checked="checked" ';
3301: }
3302: }
3303: }
3304: my %title = &context_names();
3305: my %authname = &authtype_names();
3306: my $rownum = 0;
3307: my $css_class;
3308: foreach my $item (@contexts) {
3309: if ($rownum%2) {
3310: $css_class = '';
3311: } else {
3312: $css_class = ' class="LC_odd_row" ';
3313: }
3314: $datatable .= '<tr'.$css_class.'>'.
3315: '<td>'.$title{$item}.
3316: '</td><td class="LC_left_item">'.
3317: '<span class="LC_nobreak">';
3318: foreach my $auth (@authtypes) {
3319: $datatable .= '<label>'.
3320: '<input type="checkbox" name="'.$item.'_auth" '.
3321: $checked{$item}{$auth}.' value="'.$auth.'" />'.
3322: $authname{$auth}.'</label> ';
3323: }
3324: $datatable .= '</span></td></tr>';
3325: $rownum ++;
3326: }
3327: $$rowtotal += $rownum;
3328: }
3329: return $datatable;
3330: }
3331:
3332: sub user_formats_row {
3333: my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount) = @_;
3334: my $output;
3335: my %text = (
3336: 'username' => 'new usernames',
3337: 'id' => 'IDs',
3338: 'email' => 'self-created accounts (e-mail)',
3339: );
3340: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
3341: $output = '<tr '.$css_class.'>'.
3342: '<td><span class="LC_nobreak">';
3343: if ($type eq 'email') {
3344: $output .= &mt("Formats disallowed for $text{$type}: ");
3345: } else {
3346: $output .= &mt("Format rules to check for $text{$type}: ");
3347: }
3348: $output .= '</span></td>'.
3349: '<td class="LC_left_item" colspan="2"><table>';
3350: my $rem;
3351: if (ref($ruleorder) eq 'ARRAY') {
3352: for (my $i=0; $i<@{$ruleorder}; $i++) {
3353: if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
3354: my $rem = $i%($numinrow);
3355: if ($rem == 0) {
3356: if ($i > 0) {
3357: $output .= '</tr>';
3358: }
3359: $output .= '<tr>';
3360: }
3361: my $check = ' ';
3362: if (ref($settings) eq 'HASH') {
3363: if (ref($settings->{$type.'_rule'}) eq 'ARRAY') {
3364: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) {
3365: $check = ' checked="checked" ';
3366: }
3367: }
3368: }
3369: $output .= '<td class="LC_left_item">'.
3370: '<span class="LC_nobreak"><label>'.
3371: '<input type="checkbox" name="'.$type.'_rule" '.
3372: 'value="'.$ruleorder->[$i].'"'.$check.'/>'.
3373: $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
3374: }
3375: }
3376: $rem = @{$ruleorder}%($numinrow);
3377: }
3378: my $colsleft = $numinrow - $rem;
3379: if ($colsleft > 1 ) {
3380: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
3381: ' </td>';
3382: } elsif ($colsleft == 1) {
3383: $output .= '<td class="LC_left_item"> </td>';
3384: }
3385: $output .= '</tr></table></td></tr>';
3386: return $output;
3387: }
3388:
3389: sub usercreation_types {
3390: my %lt = &Apache::lonlocal::texthash (
3391: author => 'When adding a co-author',
3392: course => 'When adding a user to a course',
3393: requestcrs => 'When requesting a course',
3394: selfcreate => 'User creates own account',
3395: any => 'Any',
3396: official => 'Institutional only ',
3397: unofficial => 'Non-institutional only',
3398: email => 'E-mail address',
3399: login => 'Institutional Login',
3400: sso => 'SSO',
3401: none => 'None',
3402: );
3403: return %lt;
3404: }
3405:
3406: sub authtype_names {
3407: my %lt = &Apache::lonlocal::texthash(
3408: int => 'Internal',
3409: krb4 => 'Kerberos 4',
3410: krb5 => 'Kerberos 5',
3411: loc => 'Local',
3412: );
3413: return %lt;
3414: }
3415:
3416: sub context_names {
3417: my %context_title = &Apache::lonlocal::texthash(
3418: author => 'Creating users when an Author',
3419: course => 'Creating users when in a course',
3420: domain => 'Creating users when a Domain Coordinator',
3421: );
3422: return %context_title;
3423: }
3424:
3425: sub print_usermodification {
3426: my ($position,$dom,$settings,$rowtotal) = @_;
3427: my $numinrow = 4;
3428: my ($context,$datatable,$rowcount);
3429: if ($position eq 'top') {
3430: $rowcount = 0;
3431: $context = 'author';
3432: foreach my $role ('ca','aa') {
3433: $datatable .= &modifiable_userdata_row($context,$role,$settings,
3434: $numinrow,$rowcount);
3435: $$rowtotal ++;
3436: $rowcount ++;
3437: }
3438: } elsif ($position eq 'middle') {
3439: $context = 'course';
3440: $rowcount = 0;
3441: foreach my $role ('st','ep','ta','in','cr') {
3442: $datatable .= &modifiable_userdata_row($context,$role,$settings,
3443: $numinrow,$rowcount);
3444: $$rowtotal ++;
3445: $rowcount ++;
3446: }
3447: } elsif ($position eq 'bottom') {
3448: $context = 'selfcreate';
3449: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
3450: $usertypes->{'default'} = $othertitle;
3451: if (ref($types) eq 'ARRAY') {
3452: push(@{$types},'default');
3453: $usertypes->{'default'} = $othertitle;
3454: foreach my $status (@{$types}) {
3455: $datatable .= &modifiable_userdata_row($context,$status,$settings,
3456: $numinrow,$rowcount,$usertypes);
3457: $$rowtotal ++;
3458: $rowcount ++;
3459: }
3460: }
3461: }
3462: return $datatable;
3463: }
3464:
3465: sub print_defaults {
3466: my ($dom,$rowtotal) = @_;
3467: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def',
3468: 'datelocale_def','portal_def');
3469: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
3470: my $titles = &defaults_titles($dom);
3471: my $rownum = 0;
3472: my ($datatable,$css_class);
3473: foreach my $item (@items) {
3474: if ($rownum%2) {
3475: $css_class = '';
3476: } else {
3477: $css_class = ' class="LC_odd_row" ';
3478: }
3479: $datatable .= '<tr'.$css_class.'>'.
3480: '<td><span class="LC_nobreak">'.$titles->{$item}.
3481: '</span></td><td class="LC_right_item">';
3482: if ($item eq 'auth_def') {
3483: my @authtypes = ('internal','krb4','krb5','localauth');
3484: my %shortauth = (
3485: internal => 'int',
3486: krb4 => 'krb4',
3487: krb5 => 'krb5',
3488: localauth => 'loc'
3489: );
3490: my %authnames = &authtype_names();
3491: foreach my $auth (@authtypes) {
3492: my $checked = ' ';
3493: if ($domdefaults{$item} eq $auth) {
3494: $checked = ' checked="checked" ';
3495: }
3496: $datatable .= '<label><input type="radio" name="'.$item.
3497: '" value="'.$auth.'"'.$checked.'/>'.
3498: $authnames{$shortauth{$auth}}.'</label> ';
3499: }
3500: } elsif ($item eq 'timezone_def') {
3501: my $includeempty = 1;
3502: $datatable .= &Apache::loncommon::select_timezone($item,$domdefaults{$item},undef,$includeempty);
3503: } elsif ($item eq 'datelocale_def') {
3504: my $includeempty = 1;
3505: $datatable .= &Apache::loncommon::select_datelocale($item,$domdefaults{$item},undef,$includeempty);
3506: } else {
3507: my $size;
3508: if ($item eq 'portal_def') {
3509: $size = ' size="25"';
3510: }
3511: $datatable .= '<input type="text" name="'.$item.'" value="'.
3512: $domdefaults{$item}.'"'.$size.' />';
3513: }
3514: $datatable .= '</td></tr>';
3515: $rownum ++;
3516: }
3517: $$rowtotal += $rownum;
3518: return $datatable;
3519: }
3520:
3521: sub defaults_titles {
3522: my ($dom) = @_;
3523: my %titles = &Apache::lonlocal::texthash (
3524: 'auth_def' => 'Default authentication type',
3525: 'auth_arg_def' => 'Default authentication argument',
3526: 'lang_def' => 'Default language',
3527: 'timezone_def' => 'Default timezone',
3528: 'datelocale_def' => 'Default locale for dates',
3529: 'portal_def' => 'Portal/Default URL',
3530: );
3531: if ($dom) {
3532: my $uprimary_id = &Apache::lonnet::domain($dom,'primary');
3533: my $uint_dom = &Apache::lonnet::internet_dom($uprimary_id);
3534: my $protocol = $Apache::lonnet::protocol{$uprimary_id};
3535: $protocol = 'http' if ($protocol ne 'https');
3536: if ($uint_dom) {
3537: $titles{'portal_def'} .= ' '.&mt('(for example: [_1])',$protocol.'://loncapa.'.
3538: $uint_dom);
3539: }
3540: }
3541: return (\%titles);
3542: }
3543:
3544: sub print_scantronformat {
3545: my ($r,$dom,$confname,$settings,$rowtotal) = @_;
3546: my $itemcount = 1;
3547: my ($datatable,$css_class,$scantronurl,$is_custom,%error,%scantronurls,
3548: %confhash);
3549: my $switchserver = &check_switchserver($dom,$confname);
3550: my %lt = &Apache::lonlocal::texthash (
3551: default => 'Default bubblesheet format file error',
3552: custom => 'Custom bubblesheet format file error',
3553: );
3554: my %scantronfiles = (
3555: default => 'default.tab',
3556: custom => 'custom.tab',
3557: );
3558: foreach my $key (keys(%scantronfiles)) {
3559: $scantronurls{$key} = '/res/'.$dom.'/'.$confname.'/scantron/'
3560: .$scantronfiles{$key};
3561: }
3562: my @defaultinfo = &Apache::lonnet::stat_file($scantronurls{'default'});
3563: if ((!@defaultinfo) || ($defaultinfo[0] eq 'no_such_dir')) {
3564: if (!$switchserver) {
3565: my $servadm = $r->dir_config('lonAdmEMail');
3566: my ($configuserok,$author_ok) = &config_check($dom,$confname,$servadm);
3567: if ($configuserok eq 'ok') {
3568: if ($author_ok eq 'ok') {
3569: my %legacyfile = (
3570: default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab',
3571: custom => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab',
3572: );
3573: my %md5chk;
3574: foreach my $type (keys(%legacyfile)) {
3575: ($md5chk{$type}) = split(/ /,`md5sum $legacyfile{$type}`);
3576: chomp($md5chk{$type});
3577: }
3578: if ($md5chk{'default'} ne $md5chk{'custom'}) {
3579: foreach my $type (keys(%legacyfile)) {
3580: ($scantronurls{$type},my $error) =
3581: &legacy_scantronformat($r,$dom,$confname,
3582: $type,$legacyfile{$type},
3583: $scantronurls{$type},
3584: $scantronfiles{$type});
3585: if ($error ne '') {
3586: $error{$type} = $error;
3587: }
3588: }
3589: if (keys(%error) == 0) {
3590: $is_custom = 1;
3591: $confhash{'scantron'}{'scantronformat'} =
3592: $scantronurls{'custom'};
3593: my $putresult =
3594: &Apache::lonnet::put_dom('configuration',
3595: \%confhash,$dom);
3596: if ($putresult ne 'ok') {
3597: $error{'custom'} =
3598: '<span class="LC_error">'.
3599: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
3600: }
3601: }
3602: } else {
3603: ($scantronurls{'default'},my $error) =
3604: &legacy_scantronformat($r,$dom,$confname,
3605: 'default',$legacyfile{'default'},
3606: $scantronurls{'default'},
3607: $scantronfiles{'default'});
3608: if ($error eq '') {
3609: $confhash{'scantron'}{'scantronformat'} = '';
3610: my $putresult =
3611: &Apache::lonnet::put_dom('configuration',
3612: \%confhash,$dom);
3613: if ($putresult ne 'ok') {
3614: $error{'default'} =
3615: '<span class="LC_error">'.
3616: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
3617: }
3618: } else {
3619: $error{'default'} = $error;
3620: }
3621: }
3622: }
3623: }
3624: } else {
3625: $error{'default'} = &mt("Unable to copy default bubblesheet formatfile to domain's RES space: [_1]",$switchserver);
3626: }
3627: }
3628: if (ref($settings) eq 'HASH') {
3629: if ($settings->{'scantronformat'} eq "/res/$dom/$confname/scantron/custom.tab") {
3630: my @info = &Apache::lonnet::stat_file($settings->{'scantronformat'});
3631: if ((!@info) || ($info[0] eq 'no_such_dir')) {
3632: $scantronurl = '';
3633: } else {
3634: $scantronurl = $settings->{'scantronformat'};
3635: }
3636: $is_custom = 1;
3637: } else {
3638: $scantronurl = $scantronurls{'default'};
3639: }
3640: } else {
3641: if ($is_custom) {
3642: $scantronurl = $scantronurls{'custom'};
3643: } else {
3644: $scantronurl = $scantronurls{'default'};
3645: }
3646: }
3647: $css_class = $itemcount%2?' class="LC_odd_row"':'';
3648: $datatable .= '<tr'.$css_class.'>';
3649: if (!$is_custom) {
3650: $datatable .= '<td>'.&mt('Default in use:').'<br />'.
3651: '<span class="LC_nobreak">';
3652: if ($scantronurl) {
3653: $datatable .= '<a href="'.$scantronurl.'" target="_blank">'.
3654: &mt('Default bubblesheet format file').'</a>';
3655: } else {
3656: $datatable = &mt('File unavailable for display');
3657: }
3658: $datatable .= '</span></td>';
3659: if (keys(%error) == 0) {
3660: $datatable .= '<td valign="bottom">';
3661: if (!$switchserver) {
3662: $datatable .= &mt('Upload:').'<br />';
3663: }
3664: } else {
3665: my $errorstr;
3666: foreach my $key (sort(keys(%error))) {
3667: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
3668: }
3669: $datatable .= '<td>'.$errorstr;
3670: }
3671: } else {
3672: if (keys(%error) > 0) {
3673: my $errorstr;
3674: foreach my $key (sort(keys(%error))) {
3675: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
3676: }
3677: $datatable .= '<td>'.$errorstr.'</td><td> ';
3678: } elsif ($scantronurl) {
3679: $datatable .= '<td><span class="LC_nobreak">'.
3680: '<a href="'.$scantronurl.'" target="_blank">'.
3681: &mt('Custom bubblesheet format file').'</a><label>'.
3682: '<input type="checkbox" name="scantronformat_del"'.
3683: '" value="1" />'.&mt('Delete?').'</label></span></td>'.
3684: '<td><span class="LC_nobreak"> '.
3685: &mt('Replace:').'</span><br />';
3686: }
3687: }
3688: if (keys(%error) == 0) {
3689: if ($switchserver) {
3690: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
3691: } else {
3692: $datatable .='<span class="LC_nobreak"> '.
3693: '<input type="file" name="scantronformat" /></span>';
3694: }
3695: }
3696: $datatable .= '</td></tr>';
3697: $$rowtotal ++;
3698: return $datatable;
3699: }
3700:
3701: sub legacy_scantronformat {
3702: my ($r,$dom,$confname,$file,$legacyfile,$newurl,$newfile) = @_;
3703: my ($url,$error);
3704: my @statinfo = &Apache::lonnet::stat_file($newurl);
3705: if ((!@statinfo) || ($statinfo[0] eq 'no_such_dir')) {
3706: (my $result,$url) =
3707: &publishlogo($r,'copy',$legacyfile,$dom,$confname,'scantron',
3708: '','',$newfile);
3709: if ($result ne 'ok') {
3710: $error = &mt("An error occurred publishing the [_1] bubblesheet format file in RES space. Error was: [_2].",$newfile,$result);
3711: }
3712: }
3713: return ($url,$error);
3714: }
3715:
3716: sub print_coursecategories {
3717: my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;
3718: my $datatable;
3719: if ($position eq 'top') {
3720: my $toggle_cats_crs = ' ';
3721: my $toggle_cats_dom = ' checked="checked" ';
3722: my $can_cat_crs = ' ';
3723: my $can_cat_dom = ' checked="checked" ';
3724: my $toggle_catscomm_comm = ' ';
3725: my $toggle_catscomm_dom = ' checked="checked" ';
3726: my $can_catcomm_comm = ' ';
3727: my $can_catcomm_dom = ' checked="checked" ';
3728:
3729: if (ref($settings) eq 'HASH') {
3730: if ($settings->{'togglecats'} eq 'crs') {
3731: $toggle_cats_crs = $toggle_cats_dom;
3732: $toggle_cats_dom = ' ';
3733: }
3734: if ($settings->{'categorize'} eq 'crs') {
3735: $can_cat_crs = $can_cat_dom;
3736: $can_cat_dom = ' ';
3737: }
3738: if ($settings->{'togglecatscomm'} eq 'comm') {
3739: $toggle_catscomm_comm = $toggle_catscomm_dom;
3740: $toggle_catscomm_dom = ' ';
3741: }
3742: if ($settings->{'categorizecomm'} eq 'comm') {
3743: $can_catcomm_comm = $can_catcomm_dom;
3744: $can_catcomm_dom = ' ';
3745: }
3746: }
3747: my %title = &Apache::lonlocal::texthash (
3748: togglecats => 'Show/Hide a course in catalog',
3749: togglecatscomm => 'Show/Hide a community in catalog',
3750: categorize => 'Assign a category to a course',
3751: categorizecomm => 'Assign a category to a community',
3752: );
3753: my %level = &Apache::lonlocal::texthash (
3754: dom => 'Set in Domain',
3755: crs => 'Set in Course',
3756: comm => 'Set in Community',
3757: );
3758: $datatable = '<tr class="LC_odd_row">'.
3759: '<td>'.$title{'togglecats'}.'</td>'.
3760: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3761: '<input type="radio" name="togglecats"'.
3762: $toggle_cats_dom.' value="dom" />'.$level{'dom'}.'</label> '.
3763: '<label><input type="radio" name="togglecats"'.
3764: $toggle_cats_crs.' value="crs" />'.$level{'crs'}.'</label></span></td>'.
3765: '</tr><tr>'.
3766: '<td>'.$title{'categorize'}.'</td>'.
3767: '<td class="LC_right_item"><span class="LC_nobreak">'.
3768: '<label><input type="radio" name="categorize"'.
3769: $can_cat_dom.' value="dom" />'.$level{'dom'}.'</label> '.
3770: '<label><input type="radio" name="categorize"'.
3771: $can_cat_crs.'value="crs" />'.$level{'crs'}.'</label></span></td>'.
3772: '</tr><tr class="LC_odd_row">'.
3773: '<td>'.$title{'togglecatscomm'}.'</td>'.
3774: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3775: '<input type="radio" name="togglecatscomm"'.
3776: $toggle_catscomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
3777: '<label><input type="radio" name="togglecatscomm"'.
3778: $toggle_catscomm_comm.' value="comm" />'.$level{'comm'}.'</label></span></td>'.
3779: '</tr><tr>'.
3780: '<td>'.$title{'categorizecomm'}.'</td>'.
3781: '<td class="LC_right_item"><span class="LC_nobreak">'.
3782: '<label><input type="radio" name="categorizecomm"'.
3783: $can_catcomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
3784: '<label><input type="radio" name="categorizecomm"'.
3785: $can_catcomm_comm.'value="comm" />'.$level{'comm'}.'</label></span></td>'.
3786: '</tr>';
3787: $$rowtotal += 4;
3788: } else {
3789: my $css_class;
3790: my $itemcount = 1;
3791: my $cathash;
3792: if (ref($settings) eq 'HASH') {
3793: $cathash = $settings->{'cats'};
3794: }
3795: if (ref($cathash) eq 'HASH') {
3796: my (@cats,@trails,%allitems,%idx,@jsarray);
3797: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
3798: \%allitems,\%idx,\@jsarray);
3799: my $maxdepth = scalar(@cats);
3800: my $colattrib = '';
3801: if ($maxdepth > 2) {
3802: $colattrib = ' colspan="2" ';
3803: }
3804: my @path;
3805: if (@cats > 0) {
3806: if (ref($cats[0]) eq 'ARRAY') {
3807: my $numtop = @{$cats[0]};
3808: my $maxnum = $numtop;
3809: my %default_names = (
3810: instcode => &mt('Official courses'),
3811: communities => &mt('Communities'),
3812: );
3813:
3814: if ((!grep(/^instcode$/,@{$cats[0]})) ||
3815: ($cathash->{'instcode::0'} eq '') ||
3816: (!grep(/^communities$/,@{$cats[0]})) ||
3817: ($cathash->{'communities::0'} eq '')) {
3818: $maxnum ++;
3819: }
3820: my $lastidx;
3821: for (my $i=0; $i<$numtop; $i++) {
3822: my $parent = $cats[0][$i];
3823: $css_class = $itemcount%2?' class="LC_odd_row"':'';
3824: my $item = &escape($parent).'::0';
3825: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$item','$idx{$item}'".');"';
3826: $lastidx = $idx{$item};
3827: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
3828: .'<select name="'.$item.'"'.$chgstr.'>';
3829: for (my $k=0; $k<=$maxnum; $k++) {
3830: my $vpos = $k+1;
3831: my $selstr;
3832: if ($k == $i) {
3833: $selstr = ' selected="selected" ';
3834: }
3835: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
3836: }
3837: $datatable .= '</select></td><td>';
3838: if ($parent eq 'instcode' || $parent eq 'communities') {
3839: $datatable .= '<span class="LC_nobreak">'
3840: .$default_names{$parent}.'</span>';
3841: if ($parent eq 'instcode') {
3842: $datatable .= '<br /><span class="LC_nobreak">('
3843: .&mt('with institutional codes')
3844: .')</span></td><td'.$colattrib.'>';
3845: } else {
3846: $datatable .= '<table><tr><td>';
3847: }
3848: $datatable .= '<span class="LC_nobreak">'
3849: .'<label><input type="radio" name="'
3850: .$parent.'" value="1" checked="checked" />'
3851: .&mt('Display').'</label>';
3852: if ($parent eq 'instcode') {
3853: $datatable .= ' ';
3854: } else {
3855: $datatable .= '</span></td></tr><tr><td>'
3856: .'<span class="LC_nobreak">';
3857: }
3858: $datatable .= '<label><input type="radio" name="'
3859: .$parent.'" value="0" />'
3860: .&mt('Do not display').'</label></span>';
3861: if ($parent eq 'communities') {
3862: $datatable .= '</td></tr></table>';
3863: }
3864: $datatable .= '</td>';
3865: } else {
3866: $datatable .= $parent
3867: .' <label><input type="checkbox" name="deletecategory" '
3868: .'value="'.$item.'" />'.&mt('Delete').'</label></span></td>';
3869: }
3870: my $depth = 1;
3871: push(@path,$parent);
3872: $datatable .= &build_category_rows($itemcount,\@cats,$depth,$parent,\@path,\%idx);
3873: pop(@path);
3874: $datatable .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
3875: $itemcount ++;
3876: }
3877: $css_class = $itemcount%2?' class="LC_odd_row"':'';
3878: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','$lastidx'".');"';
3879: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="addcategory_pos"'.$chgstr.'>';
3880: for (my $k=0; $k<=$maxnum; $k++) {
3881: my $vpos = $k+1;
3882: my $selstr;
3883: if ($k == $numtop) {
3884: $selstr = ' selected="selected" ';
3885: }
3886: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
3887: }
3888: $datatable .= '</select></span></td><td colspan="2">'.&mt('Add category:').' '
3889: .'<input type="text" size="20" name="addcategory_name" value="" /></td>'
3890: .'</tr>'."\n";
3891: $itemcount ++;
3892: foreach my $default ('instcode','communities') {
3893: if ((!grep(/^\Q$default\E$/,@{$cats[0]})) || ($cathash->{$default.'::0'} eq '')) {
3894: $css_class = $itemcount%2?' class="LC_odd_row"':'';
3895: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','$lastidx'".');"';
3896: $datatable .= '<tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr><tr '.$css_class.'><td>'.
3897: '<span class="LC_nobreak"><select name="'.$default.'_pos"'.$chgstr.'>';
3898: for (my $k=0; $k<=$maxnum; $k++) {
3899: my $vpos = $k+1;
3900: my $selstr;
3901: if ($k == $maxnum) {
3902: $selstr = ' selected="selected" ';
3903: }
3904: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
3905: }
3906: $datatable .= '</select></span></td>'.
3907: '<td><span class="LC_nobreak">'.
3908: $default_names{$default}.'</span>';
3909: if ($default eq 'instcode') {
3910: $datatable .= '<br /><span class="LC_nobreak">('
3911: .&mt('with institutional codes').')</span>';
3912: }
3913: $datatable .= '</td>'
3914: .'<td><span class="LC_nobreak"><label><input type="radio" name="'.$default.'" value="1" />'
3915: .&mt('Display').'</label> '
3916: .'<label><input type="radio" name="'.$default.'" value="0" checked="checked"/>'
3917: .&mt('Do not display').'</label></span></td></tr>';
3918: }
3919: }
3920: }
3921: } else {
3922: $datatable .= &initialize_categories($itemcount);
3923: }
3924: } else {
3925: $datatable .= '<td class="LC_right_item">'.$hdritem->{'header'}->[0]->{'col2'}.'</td>'
3926: .&initialize_categories($itemcount);
3927: }
3928: $$rowtotal += $itemcount;
3929: }
3930: return $datatable;
3931: }
3932:
3933: sub print_serverstatuses {
3934: my ($dom,$settings,$rowtotal) = @_;
3935: my $datatable;
3936: my @pages = &serverstatus_pages();
3937: my (%namedaccess,%machineaccess);
3938: foreach my $type (@pages) {
3939: $namedaccess{$type} = '';
3940: $machineaccess{$type}= '';
3941: }
3942: if (ref($settings) eq 'HASH') {
3943: foreach my $type (@pages) {
3944: if (exists($settings->{$type})) {
3945: if (ref($settings->{$type}) eq 'HASH') {
3946: foreach my $key (keys(%{$settings->{$type}})) {
3947: if ($key eq 'namedusers') {
3948: $namedaccess{$type} = $settings->{$type}->{$key};
3949: } elsif ($key eq 'machines') {
3950: $machineaccess{$type} = $settings->{$type}->{$key};
3951: }
3952: }
3953: }
3954: }
3955: }
3956: }
3957: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
3958: my $rownum = 0;
3959: my $css_class;
3960: foreach my $type (@pages) {
3961: $rownum ++;
3962: $css_class = $rownum%2?' class="LC_odd_row"':'';
3963: $datatable .= '<tr'.$css_class.'>'.
3964: '<td><span class="LC_nobreak">'.
3965: $titles->{$type}.'</span></td>'.
3966: '<td class="LC_left_item">'.
3967: '<input type="text" name="'.$type.'_namedusers" '.
3968: 'value="'.$namedaccess{$type}.'" size="30" /></td>'.
3969: '<td class="LC_right_item">'.
3970: '<span class="LC_nobreak">'.
3971: '<input type="text" name="'.$type.'_machines" '.
3972: 'value="'.$machineaccess{$type}.'" size="10" />'.
3973: '</td></tr>'."\n";
3974: }
3975: $$rowtotal += $rownum;
3976: return $datatable;
3977: }
3978:
3979: sub serverstatus_pages {
3980: return ('userstatus','lonstatus','loncron','server-status','codeversions',
3981: 'clusterstatus','metadata_keywords','metadata_harvest',
3982: 'takeoffline','takeonline','showenv','toggledebug','ping','domconf');
3983: }
3984:
3985: sub coursecategories_javascript {
3986: my ($settings) = @_;
3987: my ($output,$jstext,$cathash);
3988: if (ref($settings) eq 'HASH') {
3989: $cathash = $settings->{'cats'};
3990: }
3991: if (ref($cathash) eq 'HASH') {
3992: my (@cats,@jsarray,%idx);
3993: &Apache::loncommon::gather_categories($cathash,\@cats,\%idx,\@jsarray);
3994: if (@jsarray > 0) {
3995: $jstext = ' var categories = Array('.scalar(@jsarray).');'."\n";
3996: for (my $i=0; $i<@jsarray; $i++) {
3997: if (ref($jsarray[$i]) eq 'ARRAY') {
3998: my $catstr = join('","',@{$jsarray[$i]});
3999: $jstext .= ' categories['.$i.'] = Array("'.$catstr.'");'."\n";
4000: }
4001: }
4002: }
4003: } else {
4004: $jstext = ' var categories = Array(1);'."\n".
4005: ' categories[0] = Array("instcode_pos");'."\n";
4006: }
4007: my $instcode_reserved = &mt('The name: "instcode" is a reserved category');
4008: my $communities_reserved = &mt('The name: "communities" is a reserved category');
4009: my $choose_again = '\\n'.&mt('Please use a different name for the new top level category');
4010: $output = <<"ENDSCRIPT";
4011: <script type="text/javascript">
4012: // <![CDATA[
4013: function reorderCats(form,parent,item,idx) {
4014: var changedVal;
4015: $jstext
4016: var newpos = 'addcategory_pos';
4017: var current = new Array;
4018: if (parent == '') {
4019: var has_instcode = 0;
4020: var maxtop = categories[idx].length;
4021: for (var j=0; j<maxtop; j++) {
4022: if (categories[idx][j] == 'instcode::0') {
4023: has_instcode == 1;
4024: }
4025: }
4026: if (has_instcode == 0) {
4027: categories[idx][maxtop] = 'instcode_pos';
4028: }
4029: } else {
4030: newpos += '_'+parent;
4031: }
4032: var maxh = 1 + categories[idx].length;
4033: var current = new Array;
4034: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
4035: if (item == newpos) {
4036: changedVal = newitemVal;
4037: } else {
4038: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
4039: current[newitemVal] = newpos;
4040: }
4041: for (var i=0; i<categories[idx].length; i++) {
4042: var elementName = categories[idx][i];
4043: if (elementName != item) {
4044: if (form.elements[elementName]) {
4045: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
4046: current[currVal] = elementName;
4047: }
4048: }
4049: }
4050: var oldVal;
4051: for (var j=0; j<maxh; j++) {
4052: if (current[j] == undefined) {
4053: oldVal = j;
4054: }
4055: }
4056: if (oldVal < changedVal) {
4057: for (var k=oldVal+1; k<=changedVal ; k++) {
4058: var elementName = current[k];
4059: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
4060: }
4061: } else {
4062: for (var k=changedVal; k<oldVal; k++) {
4063: var elementName = current[k];
4064: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
4065: }
4066: }
4067: return;
4068: }
4069:
4070: function categoryCheck(form) {
4071: if (form.elements['addcategory_name'].value == 'instcode') {
4072: alert('$instcode_reserved\\n$choose_again');
4073: return false;
4074: }
4075: if (form.elements['addcategory_name'].value == 'communities') {
4076: alert('$communities_reserved\\n$choose_again');
4077: return false;
4078: }
4079: return true;
4080: }
4081:
4082: // ]]>
4083: </script>
4084:
4085: ENDSCRIPT
4086: return $output;
4087: }
4088:
4089: sub initialize_categories {
4090: my ($itemcount) = @_;
4091: my ($datatable,$css_class,$chgstr);
4092: my %default_names = (
4093: instcode => 'Official courses (with institutional codes)',
4094: communities => 'Communities',
4095: );
4096: my $select0 = ' selected="selected"';
4097: my $select1 = '';
4098: foreach my $default ('instcode','communities') {
4099: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4100: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'',$default"."_pos','0'".');"';
4101: if ($default eq 'communities') {
4102: $select1 = $select0;
4103: $select0 = '';
4104: }
4105: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
4106: .'<select name="'.$default.'_pos">'
4107: .'<option value="0"'.$select0.'>1</option>'
4108: .'<option value="1"'.$select1.'>2</option>'
4109: .'<option value="2">3</option></select> '
4110: .$default_names{$default}
4111: .'</span></td><td><span class="LC_nobreak">'
4112: .'<label><input type="radio" name="'.$default.'" value="1" checked="checked" />'
4113: .&mt('Display').'</label> <label>'
4114: .'<input type="radio" name="'.$default.'" value="0" />'.&mt('Do not display')
4115: .'</label></span></td></tr>';
4116: $itemcount ++;
4117: }
4118: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4119: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','0'".');"';
4120: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
4121: .'<select name="addcategory_pos"'.$chgstr.'>'
4122: .'<option value="0">1</option>'
4123: .'<option value="1">2</option>'
4124: .'<option value="2" selected="selected">3</option></select> '
4125: .&mt('Add category').'</td><td>'.&mt('Name:')
4126: .' <input type="text" size="20" name="addcategory_name" value="" /></td></tr>';
4127: return $datatable;
4128: }
4129:
4130: sub build_category_rows {
4131: my ($itemcount,$cats,$depth,$parent,$path,$idx) = @_;
4132: my ($text,$name,$item,$chgstr);
4133: if (ref($cats) eq 'ARRAY') {
4134: my $maxdepth = scalar(@{$cats});
4135: if (ref($cats->[$depth]) eq 'HASH') {
4136: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
4137: my $numchildren = @{$cats->[$depth]{$parent}};
4138: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
4139: $text .= '<td><table class="LC_datatable">';
4140: my ($idxnum,$parent_name,$parent_item);
4141: my $higher = $depth - 1;
4142: if ($higher == 0) {
4143: $parent_name = &escape($parent).'::'.$higher;
4144: } else {
4145: if (ref($path) eq 'ARRAY') {
4146: $parent_name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
4147: }
4148: }
4149: $parent_item = 'addcategory_pos_'.$parent_name;
4150: for (my $j=0; $j<=$numchildren; $j++) {
4151: if ($j < $numchildren) {
4152: $name = $cats->[$depth]{$parent}[$j];
4153: $item = &escape($name).':'.&escape($parent).':'.$depth;
4154: $idxnum = $idx->{$item};
4155: } else {
4156: $name = $parent_name;
4157: $item = $parent_item;
4158: }
4159: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'$parent_name','$item','$idxnum'".');"';
4160: $text .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="'.$item.'"'.$chgstr.'>';
4161: for (my $i=0; $i<=$numchildren; $i++) {
4162: my $vpos = $i+1;
4163: my $selstr;
4164: if ($j == $i) {
4165: $selstr = ' selected="selected" ';
4166: }
4167: $text .= '<option value="'.$i.'"'.$selstr.'>'.$vpos.'</option>';
4168: }
4169: $text .= '</select> ';
4170: if ($j < $numchildren) {
4171: my $deeper = $depth+1;
4172: $text .= $name.' '
4173: .'<label><input type="checkbox" name="deletecategory" value="'
4174: .$item.'" />'.&mt('Delete').'</label></span></td><td>';
4175: if(ref($path) eq 'ARRAY') {
4176: push(@{$path},$name);
4177: $text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path,$idx);
4178: pop(@{$path});
4179: }
4180: } else {
4181: $text .= &mt('Add subcategory:').' </span><input type="textbox" size="20" name="addcategory_name_';
4182: if ($j == $numchildren) {
4183: $text .= $name;
4184: } else {
4185: $text .= $item;
4186: }
4187: $text .= '" value="" />';
4188: }
4189: $text .= '</td></tr>';
4190: }
4191: $text .= '</table></td>';
4192: } else {
4193: my $higher = $depth-1;
4194: if ($higher == 0) {
4195: $name = &escape($parent).'::'.$higher;
4196: } else {
4197: if (ref($path) eq 'ARRAY') {
4198: $name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
4199: }
4200: }
4201: my $colspan;
4202: if ($parent ne 'instcode') {
4203: $colspan = $maxdepth - $depth - 1;
4204: $text .= '<td colspan="'.$colspan.'">'.&mt('Add subcategory:').'<input type="textbox" size="20" name="subcat_'.$name.'" value="" /></td>';
4205: }
4206: }
4207: }
4208: }
4209: return $text;
4210: }
4211:
4212: sub modifiable_userdata_row {
4213: my ($context,$role,$settings,$numinrow,$rowcount,$usertypes) = @_;
4214: my $rolename;
4215: if ($context eq 'selfcreate') {
4216: if (ref($usertypes) eq 'HASH') {
4217: $rolename = $usertypes->{$role};
4218: } else {
4219: $rolename = $role;
4220: }
4221: } else {
4222: if ($role eq 'cr') {
4223: $rolename = &mt('Custom role');
4224: } else {
4225: $rolename = &Apache::lonnet::plaintext($role);
4226: }
4227: }
4228: my @fields = ('lastname','firstname','middlename','generation',
4229: 'permanentemail','id');
4230: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
4231: my $output;
4232: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
4233: $output = '<tr '.$css_class.'>'.
4234: '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
4235: '<td class="LC_left_item" colspan="2"><table>';
4236: my $rem;
4237: my %checks;
4238: if (ref($settings) eq 'HASH') {
4239: if (ref($settings->{$context}) eq 'HASH') {
4240: if (ref($settings->{$context}->{$role}) eq 'HASH') {
4241: foreach my $field (@fields) {
4242: if ($settings->{$context}->{$role}->{$field}) {
4243: $checks{$field} = ' checked="checked" ';
4244: }
4245: }
4246: }
4247: }
4248: }
4249: for (my $i=0; $i<@fields; $i++) {
4250: my $rem = $i%($numinrow);
4251: if ($rem == 0) {
4252: if ($i > 0) {
4253: $output .= '</tr>';
4254: }
4255: $output .= '<tr>';
4256: }
4257: my $check = ' ';
4258: if (exists($checks{$fields[$i]})) {
4259: $check = $checks{$fields[$i]}
4260: } else {
4261: if ($role eq 'st') {
4262: if (ref($settings) ne 'HASH') {
4263: $check = ' checked="checked" ';
4264: }
4265: }
4266: }
4267: $output .= '<td class="LC_left_item">'.
4268: '<span class="LC_nobreak"><label>'.
4269: '<input type="checkbox" name="canmodify_'.$role.'" '.
4270: 'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
4271: '</label></span></td>';
4272: $rem = @fields%($numinrow);
4273: }
4274: my $colsleft = $numinrow - $rem;
4275: if ($colsleft > 1 ) {
4276: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
4277: ' </td>';
4278: } elsif ($colsleft == 1) {
4279: $output .= '<td class="LC_left_item"> </td>';
4280: }
4281: $output .= '</tr></table></td></tr>';
4282: return $output;
4283: }
4284:
4285: sub insttypes_row {
4286: my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle,$context) = @_;
4287: my %lt = &Apache::lonlocal::texthash (
4288: cansearch => 'Users allowed to search',
4289: statustocreate => 'Institutional affiliation(s) able to create own account (login/SSO)',
4290: lockablenames => 'User preference to lock name',
4291: );
4292: my $showdom;
4293: if ($context eq 'cansearch') {
4294: $showdom = ' ('.$dom.')';
4295: }
4296: my $output = '<tr class="LC_odd_row">'.
4297: '<td>'.$lt{$context}.$showdom.
4298: '</td><td class="LC_left_item" colspan="2"><table>';
4299: my $rem;
4300: if (ref($types) eq 'ARRAY') {
4301: for (my $i=0; $i<@{$types}; $i++) {
4302: if (defined($usertypes->{$types->[$i]})) {
4303: my $rem = $i%($numinrow);
4304: if ($rem == 0) {
4305: if ($i > 0) {
4306: $output .= '</tr>';
4307: }
4308: $output .= '<tr>';
4309: }
4310: my $check = ' ';
4311: if (ref($settings) eq 'HASH') {
4312: if (ref($settings->{$context}) eq 'ARRAY') {
4313: if (grep(/^\Q$types->[$i]\E$/,@{$settings->{$context}})) {
4314: $check = ' checked="checked" ';
4315: }
4316: } elsif ($context eq 'statustocreate') {
4317: $check = ' checked="checked" ';
4318: }
4319: }
4320: $output .= '<td class="LC_left_item">'.
4321: '<span class="LC_nobreak"><label>'.
4322: '<input type="checkbox" name="'.$context.'" '.
4323: 'value="'.$types->[$i].'"'.$check.'/>'.
4324: $usertypes->{$types->[$i]}.'</label></span></td>';
4325: }
4326: }
4327: $rem = @{$types}%($numinrow);
4328: }
4329: my $colsleft = $numinrow - $rem;
4330: if (($rem == 0) && (@{$types} > 0)) {
4331: $output .= '<tr>';
4332: }
4333: if ($colsleft > 1) {
4334: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
4335: } else {
4336: $output .= '<td class="LC_left_item">';
4337: }
4338: my $defcheck = ' ';
4339: if (ref($settings) eq 'HASH') {
4340: if (ref($settings->{$context}) eq 'ARRAY') {
4341: if (grep(/^default$/,@{$settings->{$context}})) {
4342: $defcheck = ' checked="checked" ';
4343: }
4344: } elsif ($context eq 'statustocreate') {
4345: $defcheck = ' checked="checked" ';
4346: }
4347: }
4348: $output .= '<span class="LC_nobreak"><label>'.
4349: '<input type="checkbox" name="'.$context.'" '.
4350: 'value="default"'.$defcheck.'/>'.
4351: $othertitle.'</label></span></td>'.
4352: '</tr></table></td></tr>';
4353: return $output;
4354: }
4355:
4356: sub sorted_searchtitles {
4357: my %searchtitles = &Apache::lonlocal::texthash(
4358: 'uname' => 'username',
4359: 'lastname' => 'last name',
4360: 'lastfirst' => 'last name, first name',
4361: );
4362: my @titleorder = ('uname','lastname','lastfirst');
4363: return (\%searchtitles,\@titleorder);
4364: }
4365:
4366: sub sorted_searchtypes {
4367: my %srchtypes_desc = (
4368: exact => 'is exact match',
4369: contains => 'contains ..',
4370: begins => 'begins with ..',
4371: );
4372: my @srchtypeorder = ('exact','begins','contains');
4373: return (\%srchtypes_desc,\@srchtypeorder);
4374: }
4375:
4376: sub usertype_update_row {
4377: my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
4378: my $datatable;
4379: my $numinrow = 4;
4380: foreach my $type (@{$types}) {
4381: if (defined($usertypes->{$type})) {
4382: $$rownums ++;
4383: my $css_class = $$rownums%2?' class="LC_odd_row"':'';
4384: $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
4385: '</td><td class="LC_left_item"><table>';
4386: for (my $i=0; $i<@{$fields}; $i++) {
4387: my $rem = $i%($numinrow);
4388: if ($rem == 0) {
4389: if ($i > 0) {
4390: $datatable .= '</tr>';
4391: }
4392: $datatable .= '<tr>';
4393: }
4394: my $check = ' ';
4395: if (ref($settings) eq 'HASH') {
4396: if (ref($settings->{'fields'}) eq 'HASH') {
4397: if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
4398: if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
4399: $check = ' checked="checked" ';
4400: }
4401: }
4402: }
4403: }
4404:
4405: if ($i == @{$fields}-1) {
4406: my $colsleft = $numinrow - $rem;
4407: if ($colsleft > 1) {
4408: $datatable .= '<td colspan="'.$colsleft.'">';
4409: } else {
4410: $datatable .= '<td>';
4411: }
4412: } else {
4413: $datatable .= '<td>';
4414: }
4415: $datatable .= '<span class="LC_nobreak"><label>'.
4416: '<input type="checkbox" name="updateable_'.$type.
4417: '_'.$fields->[$i].'" value="1"'.$check.'/>'.
4418: $fieldtitles->{$fields->[$i]}.'</label></span></td>';
4419: }
4420: $datatable .= '</tr></table></td></tr>';
4421: }
4422: }
4423: return $datatable;
4424: }
4425:
4426: sub modify_login {
4427: my ($r,$dom,$confname,%domconfig) = @_;
4428: my ($resulttext,$errors,$colchgtext,%changes,%colchanges);
4429: my %title = ( coursecatalog => 'Display course catalog',
4430: adminmail => 'Display administrator E-mail address',
4431: newuser => 'Link for visitors to create a user account',
4432: loginheader => 'Log-in box header');
4433: my @offon = ('off','on');
4434: my %curr_loginvia;
4435: if (ref($domconfig{login}) eq 'HASH') {
4436: if (ref($domconfig{login}{loginvia}) eq 'HASH') {
4437: foreach my $lonhost (keys(%{$domconfig{login}{loginvia}})) {
4438: $curr_loginvia{$lonhost} = $domconfig{login}{loginvia}{$lonhost};
4439: }
4440: }
4441: }
4442: my %loginhash;
4443: ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
4444: \%domconfig,\%loginhash);
4445: my @toggles = ('coursecatalog','adminmail','newuser');
4446: foreach my $item (@toggles) {
4447: $loginhash{login}{$item} = $env{'form.'.$item};
4448: }
4449: $loginhash{login}{loginheader} = $env{'form.loginheader'};
4450: if (ref($colchanges{'login'}) eq 'HASH') {
4451: $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
4452: \%loginhash);
4453: }
4454:
4455: my %servers = &Apache::lonnet::internet_dom_servers($dom);
4456: my @loginvia_attribs = ('serverpath','custompath','exempt');
4457: if (keys(%servers) > 1) {
4458: foreach my $lonhost (keys(%servers)) {
4459: next if ($env{'form.'.$lonhost.'_server'} eq $lonhost);
4460: if (ref($curr_loginvia{$lonhost}) eq 'HASH') {
4461: if ($env{'form.'.$lonhost.'_server'} eq $curr_loginvia{$lonhost}{'server'}) {
4462: $loginhash{login}{loginvia}{$lonhost}{'server'} = $curr_loginvia{$lonhost}{'server'};
4463: } elsif ($curr_loginvia{$lonhost}{'server'} ne '') {
4464: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
4465: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
4466: $changes{'loginvia'}{$lonhost} = 1;
4467: } else {
4468: $loginhash{login}{loginvia}{$lonhost}{'server'} = '';
4469: $changes{'loginvia'}{$lonhost} = 1;
4470: }
4471: } else {
4472: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
4473: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
4474: $changes{'loginvia'}{$lonhost} = 1;
4475: }
4476: }
4477: if ($loginhash{login}{loginvia}{$lonhost}{'server'} eq '') {
4478: foreach my $item (@loginvia_attribs) {
4479: $loginhash{login}{loginvia}{$lonhost}{$item} = '';
4480: }
4481: } else {
4482: foreach my $item (@loginvia_attribs) {
4483: my $new = $env{'form.'.$lonhost.'_'.$item};
4484: if (($item eq 'serverpath') && ($new eq 'custom')) {
4485: $env{'form.'.$lonhost.'_custompath'} =~ s/\s+//g;
4486: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
4487: $new = '/';
4488: }
4489: }
4490: if (($item eq 'custompath') &&
4491: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
4492: $new = '';
4493: }
4494: if ($new ne $curr_loginvia{$lonhost}{$item}) {
4495: $changes{'loginvia'}{$lonhost} = 1;
4496: }
4497: if ($item eq 'exempt') {
4498: $new =~ s/^\s+//;
4499: $new =~ s/\s+$//;
4500: my @poss_ips = split(/\s*[,:]\s*/,$new);
4501: my @okips;
4502: foreach my $ip (@poss_ips) {
4503: if ($ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
4504: if (($1 <= 255) && ($2 <= 255) && ($3 <= 255) && ($4 <= 255)) {
4505: push(@okips,$ip);
4506: }
4507: }
4508: }
4509: if (@okips > 0) {
4510: $new = join(',',@okips);
4511: } else {
4512: $new = '';
4513: }
4514: }
4515:
4516: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
4517: }
4518: }
4519: } else {
4520: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
4521: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
4522: $changes{'loginvia'}{$lonhost} = 1;
4523: foreach my $item (@loginvia_attribs) {
4524: my $new = $env{'form.'.$lonhost.'_'.$item};
4525: if (($item eq 'serverpath') && ($new eq 'custom')) {
4526: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
4527: $new = '/';
4528: }
4529: }
4530: if (($item eq 'custompath') &&
4531: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
4532: $new = '';
4533: }
4534: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
4535: }
4536: }
4537: }
4538: }
4539: }
4540:
4541: my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
4542: $dom);
4543: if ($putresult eq 'ok') {
4544: my @toggles = ('coursecatalog','adminmail','newuser');
4545: my %defaultchecked = (
4546: 'coursecatalog' => 'on',
4547: 'adminmail' => 'off',
4548: 'newuser' => 'off',
4549: );
4550: if (ref($domconfig{'login'}) eq 'HASH') {
4551: foreach my $item (@toggles) {
4552: if ($defaultchecked{$item} eq 'on') {
4553: if (($domconfig{'login'}{$item} eq '0') &&
4554: ($env{'form.'.$item} eq '1')) {
4555: $changes{$item} = 1;
4556: } elsif (($domconfig{'login'}{$item} eq '' ||
4557: $domconfig{'login'}{$item} eq '1') &&
4558: ($env{'form.'.$item} eq '0')) {
4559: $changes{$item} = 1;
4560: }
4561: } elsif ($defaultchecked{$item} eq 'off') {
4562: if (($domconfig{'login'}{$item} eq '1') &&
4563: ($env{'form.'.$item} eq '0')) {
4564: $changes{$item} = 1;
4565: } elsif (($domconfig{'login'}{$item} eq '' ||
4566: $domconfig{'login'}{$item} eq '0') &&
4567: ($env{'form.'.$item} eq '1')) {
4568: $changes{$item} = 1;
4569: }
4570: }
4571: }
4572: }
4573: if (keys(%changes) > 0 || $colchgtext) {
4574: &Apache::loncommon::devalidate_domconfig_cache($dom);
4575: $resulttext = &mt('Changes made:').'<ul>';
4576: foreach my $item (sort(keys(%changes))) {
4577: if ($item eq 'loginvia') {
4578: if (ref($changes{$item}) eq 'HASH') {
4579: $resulttext .= '<li>'.&mt('Log-in page availability:').'<ul>';
4580: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
4581: if (defined($servers{$loginhash{login}{loginvia}{$lonhost}{'server'}})) {
4582: if (ref($loginhash{login}{loginvia}{$lonhost}) eq 'HASH') {
4583: my $protocol = $Apache::lonnet::protocol{$env{'form.'.$lonhost.'_server'}};
4584: $protocol = 'http' if ($protocol ne 'https');
4585: my $target = $protocol.'://'.$servers{$env{'form.'.$lonhost.'_server'}};
4586:
4587: if ($loginhash{login}{loginvia}{$lonhost}{'serverpath'} eq 'custom') {
4588: $target .= $loginhash{login}{loginvia}{$lonhost}{'custompath'};
4589: } else {
4590: $target .= $loginhash{login}{loginvia}{$lonhost}{'serverpath'};
4591: }
4592: $resulttext .= '<li>'.&mt('Server: [_1] log-in page redirects to [_2].',$servers{$lonhost},'<a href="'.$target.'">'.$target.'</a>');
4593: if ($loginhash{login}{loginvia}{$lonhost}{'exempt'} ne '') {
4594: $resulttext .= ' '.&mt('No redirection for clients from following IPs:').' '.$loginhash{login}{loginvia}{$lonhost}{'exempt'};
4595: }
4596: $resulttext .= '</li>';
4597: } else {
4598: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$lonhost).'</li>';
4599: }
4600: } else {
4601: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$servers{$lonhost}).'</li>';
4602: }
4603: }
4604: $resulttext .= '</ul></li>';
4605: }
4606: } else {
4607: $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
4608: }
4609: }
4610: $resulttext .= $colchgtext.'</ul>';
4611: } else {
4612: $resulttext = &mt('No changes made to log-in page settings');
4613: }
4614: } else {
4615: $resulttext = '<span class="LC_error">'.
4616: &mt('An error occurred: [_1]',$putresult).'</span>';
4617: }
4618: if ($errors) {
4619: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
4620: $errors.'</ul>';
4621: }
4622: return $resulttext;
4623: }
4624:
4625: sub color_font_choices {
4626: my %choices =
4627: &Apache::lonlocal::texthash (
4628: img => "Header",
4629: bgs => "Background colors",
4630: links => "Link colors",
4631: images => "Images",
4632: font => "Font color",
4633: fontmenu => "Font Menu",
4634: pgbg => "Page",
4635: tabbg => "Header",
4636: sidebg => "Border",
4637: link => "Link",
4638: alink => "Active link",
4639: vlink => "Visited link",
4640: );
4641: return %choices;
4642: }
4643:
4644: sub modify_rolecolors {
4645: my ($r,$dom,$confname,$roles,%domconfig) = @_;
4646: my ($resulttext,%rolehash);
4647: $rolehash{'rolecolors'} = {};
4648: if (ref($domconfig{'rolecolors'}) ne 'HASH') {
4649: if ($domconfig{'rolecolors'} eq '') {
4650: $domconfig{'rolecolors'} = {};
4651: }
4652: }
4653: my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
4654: $domconfig{'rolecolors'},$rolehash{'rolecolors'});
4655: my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
4656: $dom);
4657: if ($putresult eq 'ok') {
4658: if (keys(%changes) > 0) {
4659: &Apache::loncommon::devalidate_domconfig_cache($dom);
4660: $resulttext = &display_colorchgs($dom,\%changes,$roles,
4661: $rolehash{'rolecolors'});
4662: } else {
4663: $resulttext = &mt('No changes made to default color schemes');
4664: }
4665: } else {
4666: $resulttext = '<span class="LC_error">'.
4667: &mt('An error occurred: [_1]',$putresult).'</span>';
4668: }
4669: if ($errors) {
4670: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
4671: $errors.'</ul>';
4672: }
4673: return $resulttext;
4674: }
4675:
4676: sub modify_colors {
4677: my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
4678: my (%changes,%choices);
4679: my @bgs;
4680: my @links = ('link','alink','vlink');
4681: my @logintext;
4682: my @images;
4683: my $servadm = $r->dir_config('lonAdmEMail');
4684: my $errors;
4685: foreach my $role (@{$roles}) {
4686: if ($role eq 'login') {
4687: %choices = &login_choices();
4688: @logintext = ('textcol','bgcol');
4689: } else {
4690: %choices = &color_font_choices();
4691: $confhash->{$role}{'fontmenu'} = $env{'form.'.$role.'_fontmenu'};
4692: }
4693: if ($role eq 'login') {
4694: @images = ('img','logo','domlogo','login');
4695: @bgs = ('pgbg','mainbg','sidebg');
4696: } else {
4697: @images = ('img');
4698: @bgs = ('pgbg','tabbg','sidebg');
4699: }
4700: $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
4701: foreach my $item (@bgs,@links,@logintext) {
4702: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
4703: }
4704: my ($configuserok,$author_ok,$switchserver) =
4705: &config_check($dom,$confname,$servadm);
4706: my ($width,$height) = &thumb_dimensions();
4707: if (ref($domconfig->{$role}) ne 'HASH') {
4708: $domconfig->{$role} = {};
4709: }
4710: foreach my $img (@images) {
4711: if (($role eq 'login') && (($img eq 'img') || ($img eq 'logo'))) {
4712: if (defined($env{'form.login_showlogo_'.$img})) {
4713: $confhash->{$role}{'showlogo'}{$img} = 1;
4714: } else {
4715: $confhash->{$role}{'showlogo'}{$img} = 0;
4716: }
4717: }
4718: if ( ! $env{'form.'.$role.'_'.$img.'.filename'}
4719: && !defined($domconfig->{$role}{$img})
4720: && !$env{'form.'.$role.'_del_'.$img}
4721: && $env{'form.'.$role.'_import_'.$img}) {
4722: # import the old configured image from the .tab setting
4723: # if they haven't provided a new one
4724: $domconfig->{$role}{$img} =
4725: $env{'form.'.$role.'_import_'.$img};
4726: }
4727: if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
4728: my $error;
4729: if ($configuserok eq 'ok') {
4730: if ($switchserver) {
4731: $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
4732: } else {
4733: if ($author_ok eq 'ok') {
4734: my ($result,$logourl) =
4735: &publishlogo($r,'upload',$role.'_'.$img,
4736: $dom,$confname,$img,$width,$height);
4737: if ($result eq 'ok') {
4738: $confhash->{$role}{$img} = $logourl;
4739: $changes{$role}{'images'}{$img} = 1;
4740: } else {
4741: $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);
4742: }
4743: } else {
4744: $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);
4745: }
4746: }
4747: } else {
4748: $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);
4749: }
4750: if ($error) {
4751: &Apache::lonnet::logthis($error);
4752: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
4753: }
4754: } elsif ($domconfig->{$role}{$img} ne '') {
4755: if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
4756: my $error;
4757: if ($configuserok eq 'ok') {
4758: # is confname an author?
4759: if ($switchserver eq '') {
4760: if ($author_ok eq 'ok') {
4761: my ($result,$logourl) =
4762: &publishlogo($r,'copy',$domconfig->{$role}{$img},
4763: $dom,$confname,$img,$width,$height);
4764: if ($result eq 'ok') {
4765: $confhash->{$role}{$img} = $logourl;
4766: $changes{$role}{'images'}{$img} = 1;
4767: }
4768: }
4769: }
4770: }
4771: }
4772: }
4773: }
4774: if (ref($domconfig) eq 'HASH') {
4775: if (ref($domconfig->{$role}) eq 'HASH') {
4776: foreach my $img (@images) {
4777: if ($domconfig->{$role}{$img} ne '') {
4778: if ($env{'form.'.$role.'_del_'.$img}) {
4779: $confhash->{$role}{$img} = '';
4780: $changes{$role}{'images'}{$img} = 1;
4781: } else {
4782: if ($confhash->{$role}{$img} eq '') {
4783: $confhash->{$role}{$img} = $domconfig->{$role}{$img};
4784: }
4785: }
4786: } else {
4787: if ($env{'form.'.$role.'_del_'.$img}) {
4788: $confhash->{$role}{$img} = '';
4789: $changes{$role}{'images'}{$img} = 1;
4790: }
4791: }
4792: if (($role eq 'login') && (($img eq 'logo') || ($img eq 'img'))) {
4793: if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') {
4794: if ($confhash->{$role}{'showlogo'}{$img} ne
4795: $domconfig->{$role}{'showlogo'}{$img}) {
4796: $changes{$role}{'showlogo'}{$img} = 1;
4797: }
4798: } else {
4799: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
4800: $changes{$role}{'showlogo'}{$img} = 1;
4801: }
4802: }
4803: }
4804: }
4805: if ($domconfig->{$role}{'font'} ne '') {
4806: if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
4807: $changes{$role}{'font'} = 1;
4808: }
4809: } else {
4810: if ($confhash->{$role}{'font'}) {
4811: $changes{$role}{'font'} = 1;
4812: }
4813: }
4814: if ($role ne 'login') {
4815: if ($domconfig->{$role}{'fontmenu'} ne '') {
4816: if ($confhash->{$role}{'fontmenu'} ne $domconfig->{$role}{'fontmenu'}) {
4817: $changes{$role}{'fontmenu'} = 1;
4818: }
4819: } else {
4820: if ($confhash->{$role}{'fontmenu'}) {
4821: $changes{$role}{'fontmenu'} = 1;
4822: }
4823: }
4824: }
4825: foreach my $item (@bgs) {
4826: if ($domconfig->{$role}{$item} ne '') {
4827: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
4828: $changes{$role}{'bgs'}{$item} = 1;
4829: }
4830: } else {
4831: if ($confhash->{$role}{$item}) {
4832: $changes{$role}{'bgs'}{$item} = 1;
4833: }
4834: }
4835: }
4836: foreach my $item (@links) {
4837: if ($domconfig->{$role}{$item} ne '') {
4838: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
4839: $changes{$role}{'links'}{$item} = 1;
4840: }
4841: } else {
4842: if ($confhash->{$role}{$item}) {
4843: $changes{$role}{'links'}{$item} = 1;
4844: }
4845: }
4846: }
4847: foreach my $item (@logintext) {
4848: if ($domconfig->{$role}{$item} ne '') {
4849: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
4850: $changes{$role}{'logintext'}{$item} = 1;
4851: }
4852: } else {
4853: if ($confhash->{$role}{$item}) {
4854: $changes{$role}{'logintext'}{$item} = 1;
4855: }
4856: }
4857: }
4858: } else {
4859: &default_change_checker($role,\@images,\@links,\@bgs,
4860: \@logintext,$confhash,\%changes);
4861: }
4862: } else {
4863: &default_change_checker($role,\@images,\@links,\@bgs,
4864: \@logintext,$confhash,\%changes);
4865: }
4866: }
4867: return ($errors,%changes);
4868: }
4869:
4870: sub config_check {
4871: my ($dom,$confname,$servadm) = @_;
4872: my ($configuserok,$author_ok,$switchserver,%currroles);
4873: my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
4874: ($configuserok,%currroles) = &check_configuser($uhome,$dom,
4875: $confname,$servadm);
4876: if ($configuserok eq 'ok') {
4877: $switchserver = &check_switchserver($dom,$confname);
4878: if ($switchserver eq '') {
4879: $author_ok = &check_authorstatus($dom,$confname,%currroles);
4880: }
4881: }
4882: return ($configuserok,$author_ok,$switchserver);
4883: }
4884:
4885: sub default_change_checker {
4886: my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
4887: foreach my $item (@{$links}) {
4888: if ($confhash->{$role}{$item}) {
4889: $changes->{$role}{'links'}{$item} = 1;
4890: }
4891: }
4892: foreach my $item (@{$bgs}) {
4893: if ($confhash->{$role}{$item}) {
4894: $changes->{$role}{'bgs'}{$item} = 1;
4895: }
4896: }
4897: foreach my $item (@{$logintext}) {
4898: if ($confhash->{$role}{$item}) {
4899: $changes->{$role}{'logintext'}{$item} = 1;
4900: }
4901: }
4902: foreach my $img (@{$images}) {
4903: if ($env{'form.'.$role.'_del_'.$img}) {
4904: $confhash->{$role}{$img} = '';
4905: $changes->{$role}{'images'}{$img} = 1;
4906: }
4907: if ($role eq 'login') {
4908: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
4909: $changes->{$role}{'showlogo'}{$img} = 1;
4910: }
4911: }
4912: }
4913: if ($confhash->{$role}{'font'}) {
4914: $changes->{$role}{'font'} = 1;
4915: }
4916: }
4917:
4918: sub display_colorchgs {
4919: my ($dom,$changes,$roles,$confhash) = @_;
4920: my (%choices,$resulttext);
4921: if (!grep(/^login$/,@{$roles})) {
4922: $resulttext = &mt('Changes made:').'<br />';
4923: }
4924: foreach my $role (@{$roles}) {
4925: if ($role eq 'login') {
4926: %choices = &login_choices();
4927: } else {
4928: %choices = &color_font_choices();
4929: }
4930: if (ref($changes->{$role}) eq 'HASH') {
4931: if ($role ne 'login') {
4932: $resulttext .= '<h4>'.&mt($role).'</h4>';
4933: }
4934: foreach my $key (sort(keys(%{$changes->{$role}}))) {
4935: if ($role ne 'login') {
4936: $resulttext .= '<ul>';
4937: }
4938: if (ref($changes->{$role}{$key}) eq 'HASH') {
4939: if ($role ne 'login') {
4940: $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
4941: }
4942: foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
4943: if (($role eq 'login') && ($key eq 'showlogo')) {
4944: if ($confhash->{$role}{$key}{$item}) {
4945: $resulttext .= '<li>'.&mt("$choices{$item} set to be displayed").'</li>';
4946: } else {
4947: $resulttext .= '<li>'.&mt("$choices{$item} set to not be displayed").'</li>';
4948: }
4949: } elsif ($confhash->{$role}{$item} eq '') {
4950: $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
4951: } else {
4952: my $newitem = $confhash->{$role}{$item};
4953: if ($key eq 'images') {
4954: $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" valign="bottom" />';
4955: }
4956: $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
4957: }
4958: }
4959: if ($role ne 'login') {
4960: $resulttext .= '</ul></li>';
4961: }
4962: } else {
4963: if ($confhash->{$role}{$key} eq '') {
4964: $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
4965: } else {
4966: $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
4967: }
4968: }
4969: if ($role ne 'login') {
4970: $resulttext .= '</ul>';
4971: }
4972: }
4973: }
4974: }
4975: return $resulttext;
4976: }
4977:
4978: sub thumb_dimensions {
4979: return ('200','50');
4980: }
4981:
4982: sub check_dimensions {
4983: my ($inputfile) = @_;
4984: my ($fullwidth,$fullheight);
4985: if ($inputfile =~ m|^[/\w.\-]+$|) {
4986: if (open(PIPE,"identify $inputfile 2>&1 |")) {
4987: my $imageinfo = <PIPE>;
4988: if (!close(PIPE)) {
4989: &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
4990: }
4991: chomp($imageinfo);
4992: my ($fullsize) =
4993: ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
4994: if ($fullsize) {
4995: ($fullwidth,$fullheight) = split(/x/,$fullsize);
4996: }
4997: }
4998: }
4999: return ($fullwidth,$fullheight);
5000: }
5001:
5002: sub check_configuser {
5003: my ($uhome,$dom,$confname,$servadm) = @_;
5004: my ($configuserok,%currroles);
5005: if ($uhome eq 'no_host') {
5006: srand( time() ^ ($$ + ($$ << 15)) ); # Seed rand.
5007: my $configpass = &LONCAPA::Enrollment::create_password();
5008: $configuserok =
5009: &Apache::lonnet::modifyuser($dom,$confname,'','internal',
5010: $configpass,'','','','','',undef,$servadm);
5011: } else {
5012: $configuserok = 'ok';
5013: %currroles =
5014: &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
5015: }
5016: return ($configuserok,%currroles);
5017: }
5018:
5019: sub check_authorstatus {
5020: my ($dom,$confname,%currroles) = @_;
5021: my $author_ok;
5022: if (!$currroles{':'.$dom.':au'}) {
5023: my $start = time;
5024: my $end = 0;
5025: $author_ok =
5026: &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
5027: 'au',$end,$start,'','','domconfig');
5028: } else {
5029: $author_ok = 'ok';
5030: }
5031: return $author_ok;
5032: }
5033:
5034: sub publishlogo {
5035: my ($r,$action,$formname,$dom,$confname,$subdir,$thumbwidth,$thumbheight,$savefileas) = @_;
5036: my ($output,$fname,$logourl);
5037: if ($action eq 'upload') {
5038: $fname=$env{'form.'.$formname.'.filename'};
5039: chop($env{'form.'.$formname});
5040: } else {
5041: ($fname) = ($formname =~ /([^\/]+)$/);
5042: }
5043: if ($savefileas ne '') {
5044: $fname = $savefileas;
5045: }
5046: $fname=&Apache::lonnet::clean_filename($fname);
5047: # See if there is anything left
5048: unless ($fname) { return ('error: no uploaded file'); }
5049: $fname="$subdir/$fname";
5050: my $docroot=$r->dir_config('lonDocRoot');
5051: my $filepath="$docroot/priv";
5052: my $relpath = "$dom/$confname";
5053: my ($fnamepath,$file,$fetchthumb);
5054: $file=$fname;
5055: if ($fname=~m|/|) {
5056: ($fnamepath,$file) = ($fname =~ m|^(.*)/([^/]+)$|);
5057: }
5058: my @parts=split(/\//,"$filepath/$relpath/$fnamepath");
5059: my $count;
5060: for ($count=5;$count<=$#parts;$count++) {
5061: $filepath.="/$parts[$count]";
5062: if ((-e $filepath)!=1) {
5063: mkdir($filepath,02770);
5064: }
5065: }
5066: # Check for bad extension and disallow upload
5067: if ($file=~/\.(\w+)$/ &&
5068: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
5069: $output =
5070: &mt('Invalid file extension ([_1]) - reserved for LONCAPA use.',$1);
5071: } elsif ($file=~/\.(\w+)$/ &&
5072: !defined(&Apache::loncommon::fileembstyle($1))) {
5073: $output = &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
5074: } elsif ($file=~/\.(\d+)\.(\w+)$/) {
5075: $output = &mt('File name not allowed - rename the file to remove the number immediately before the file extension([_1]) and re-upload.',$2);
5076: } elsif (-d "$filepath/$file") {
5077: $output = &mt('File name is a directory name - rename the file and re-upload');
5078: } else {
5079: my $source = $filepath.'/'.$file;
5080: my $logfile;
5081: if (!open($logfile,">>$source".'.log')) {
5082: return (&mt('No write permission to Construction Space'));
5083: }
5084: print $logfile
5085: "\n================= Publish ".localtime()." ================\n".
5086: $env{'user.name'}.':'.$env{'user.domain'}."\n";
5087: # Save the file
5088: if (!open(FH,'>'.$source)) {
5089: &Apache::lonnet::logthis('Failed to create '.$source);
5090: return (&mt('Failed to create file'));
5091: }
5092: if ($action eq 'upload') {
5093: if (!print FH ($env{'form.'.$formname})) {
5094: &Apache::lonnet::logthis('Failed to write to '.$source);
5095: return (&mt('Failed to write file'));
5096: }
5097: } else {
5098: my $original = &Apache::lonnet::filelocation('',$formname);
5099: if(!copy($original,$source)) {
5100: &Apache::lonnet::logthis('Failed to copy '.$original.' to '.$source);
5101: return (&mt('Failed to write file'));
5102: }
5103: }
5104: close(FH);
5105: chmod(0660, $source); # Permissions to rw-rw---.
5106:
5107: my $targetdir=$docroot.'/res/'.$dom.'/'.$confname .'/'.$fnamepath;
5108: my $copyfile=$targetdir.'/'.$file;
5109:
5110: my @parts=split(/\//,$targetdir);
5111: my $path="/$parts[1]/$parts[2]/$parts[3]/$parts[4]";
5112: for (my $count=5;$count<=$#parts;$count++) {
5113: $path.="/$parts[$count]";
5114: if (!-e $path) {
5115: print $logfile "\nCreating directory ".$path;
5116: mkdir($path,02770);
5117: }
5118: }
5119: my $versionresult;
5120: if (-e $copyfile) {
5121: $versionresult = &logo_versioning($targetdir,$file,$logfile);
5122: } else {
5123: $versionresult = 'ok';
5124: }
5125: if ($versionresult eq 'ok') {
5126: if (copy($source,$copyfile)) {
5127: print $logfile "\nCopied original source to ".$copyfile."\n";
5128: $output = 'ok';
5129: $logourl = '/res/'.$dom.'/'.$confname.'/'.$fname;
5130: push(@{$modified_urls},[$copyfile,$source]);
5131: my $metaoutput =
5132: &write_metadata($dom,$confname,$formname,$targetdir,$file,$logfile);
5133: unless ($registered_cleanup) {
5134: my $handlers = $r->get_handlers('PerlCleanupHandler');
5135: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
5136: $registered_cleanup=1;
5137: }
5138: } else {
5139: print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";
5140: $output = &mt('Failed to copy file to RES space').", $!";
5141: }
5142: if (($thumbwidth =~ /^\d+$/) && ($thumbheight =~ /^\d+$/)) {
5143: my $inputfile = $filepath.'/'.$file;
5144: my $outfile = $filepath.'/'.'tn-'.$file;
5145: my ($fullwidth,$fullheight) = &check_dimensions($inputfile);
5146: if ($fullwidth ne '' && $fullheight ne '') {
5147: if ($fullwidth > $thumbwidth && $fullheight > $thumbheight) {
5148: my $thumbsize = $thumbwidth.'x'.$thumbheight;
5149: system("convert -sample $thumbsize $inputfile $outfile");
5150: chmod(0660, $filepath.'/tn-'.$file);
5151: if (-e $outfile) {
5152: my $copyfile=$targetdir.'/tn-'.$file;
5153: if (copy($outfile,$copyfile)) {
5154: print $logfile "\nCopied source to ".$copyfile."\n";
5155: my $thumb_metaoutput =
5156: &write_metadata($dom,$confname,$formname,
5157: $targetdir,'tn-'.$file,$logfile);
5158: push(@{$modified_urls},[$copyfile,$outfile]);
5159: unless ($registered_cleanup) {
5160: my $handlers = $r->get_handlers('PerlCleanupHandler');
5161: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
5162: $registered_cleanup=1;
5163: }
5164: } else {
5165: print $logfile "\nUnable to write ".$copyfile.
5166: ':'.$!."\n";
5167: }
5168: }
5169: }
5170: }
5171: }
5172: } else {
5173: $output = $versionresult;
5174: }
5175: }
5176: return ($output,$logourl);
5177: }
5178:
5179: sub logo_versioning {
5180: my ($targetdir,$file,$logfile) = @_;
5181: my $target = $targetdir.'/'.$file;
5182: my ($maxversion,$fn,$extn,$output);
5183: $maxversion = 0;
5184: if ($file =~ /^(.+)\.(\w+)$/) {
5185: $fn=$1;
5186: $extn=$2;
5187: }
5188: opendir(DIR,$targetdir);
5189: while (my $filename=readdir(DIR)) {
5190: if ($filename=~/\Q$fn\E\.(\d+)\.\Q$extn\E$/) {
5191: $maxversion=($1>$maxversion)?$1:$maxversion;
5192: }
5193: }
5194: $maxversion++;
5195: print $logfile "\nCreating old version ".$maxversion."\n";
5196: my $copyfile=$targetdir.'/'.$fn.'.'.$maxversion.'.'.$extn;
5197: if (copy($target,$copyfile)) {
5198: print $logfile "Copied old target to ".$copyfile."\n";
5199: $copyfile=$copyfile.'.meta';
5200: if (copy($target.'.meta',$copyfile)) {
5201: print $logfile "Copied old target metadata to ".$copyfile."\n";
5202: $output = 'ok';
5203: } else {
5204: print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";
5205: $output = &mt('Failed to copy old meta').", $!, ";
5206: }
5207: } else {
5208: print $logfile "Unable to write ".$copyfile.':'.$!."\n";
5209: $output = &mt('Failed to copy old target').", $!, ";
5210: }
5211: return $output;
5212: }
5213:
5214: sub write_metadata {
5215: my ($dom,$confname,$formname,$targetdir,$file,$logfile) = @_;
5216: my (%metadatafields,%metadatakeys,$output);
5217: $metadatafields{'title'}=$formname;
5218: $metadatafields{'creationdate'}=time;
5219: $metadatafields{'lastrevisiondate'}=time;
5220: $metadatafields{'copyright'}='public';
5221: $metadatafields{'modifyinguser'}=$env{'user.name'}.':'.
5222: $env{'user.domain'};
5223: $metadatafields{'authorspace'}=$confname.':'.$dom;
5224: $metadatafields{'domain'}=$dom;
5225: {
5226: print $logfile "\nWrite metadata file for ".$targetdir.'/'.$file;
5227: my $mfh;
5228: if (open($mfh,'>'.$targetdir.'/'.$file.'.meta')) {
5229: foreach (sort keys %metadatafields) {
5230: unless ($_=~/\./) {
5231: my $unikey=$_;
5232: $unikey=~/^([A-Za-z]+)/;
5233: my $tag=$1;
5234: $tag=~tr/A-Z/a-z/;
5235: print $mfh "\n\<$tag";
5236: foreach (split(/\,/,$metadatakeys{$unikey})) {
5237: my $value=$metadatafields{$unikey.'.'.$_};
5238: $value=~s/\"/\'\'/g;
5239: print $mfh ' '.$_.'="'.$value.'"';
5240: }
5241: print $mfh '>'.
5242: &HTML::Entities::encode($metadatafields{$unikey},'<>&"')
5243: .'</'.$tag.'>';
5244: }
5245: }
5246: $output = 'ok';
5247: print $logfile "\nWrote metadata";
5248: close($mfh);
5249: } else {
5250: print $logfile "\nFailed to open metadata file";
5251: $output = &mt('Could not write metadata');
5252: }
5253: }
5254: return $output;
5255: }
5256:
5257: sub notifysubscribed {
5258: foreach my $targetsource (@{$modified_urls}){
5259: next unless (ref($targetsource) eq 'ARRAY');
5260: my ($target,$source)=@{$targetsource};
5261: if ($source ne '') {
5262: if (open(my $logfh,'>>'.$source.'.log')) {
5263: print $logfh "\nCleanup phase: Notifications\n";
5264: my @subscribed=&subscribed_hosts($target);
5265: foreach my $subhost (@subscribed) {
5266: print $logfh "\nNotifying host ".$subhost.':';
5267: my $reply=&Apache::lonnet::critical('update:'.$target,$subhost);
5268: print $logfh $reply;
5269: }
5270: my @subscribedmeta=&subscribed_hosts("$target.meta");
5271: foreach my $subhost (@subscribedmeta) {
5272: print $logfh "\nNotifying host for metadata only ".$subhost.':';
5273: my $reply=&Apache::lonnet::critical('update:'.$target.'.meta',
5274: $subhost);
5275: print $logfh $reply;
5276: }
5277: print $logfh "\n============ Done ============\n";
5278: close($logfh);
5279: }
5280: }
5281: }
5282: return OK;
5283: }
5284:
5285: sub subscribed_hosts {
5286: my ($target) = @_;
5287: my @subscribed;
5288: if (open(my $fh,"<$target.subscription")) {
5289: while (my $subline=<$fh>) {
5290: if ($subline =~ /^($match_lonid):/) {
5291: my $host = $1;
5292: if ($host ne $Apache::lonnet::perlvar{'lonHostID'}) {
5293: unless (grep(/^\Q$host\E$/,@subscribed)) {
5294: push(@subscribed,$host);
5295: }
5296: }
5297: }
5298: }
5299: }
5300: return @subscribed;
5301: }
5302:
5303: sub check_switchserver {
5304: my ($dom,$confname) = @_;
5305: my ($allowed,$switchserver);
5306: my $home = &Apache::lonnet::homeserver($confname,$dom);
5307: if ($home eq 'no_host') {
5308: $home = &Apache::lonnet::domain($dom,'primary');
5309: }
5310: my @ids=&Apache::lonnet::current_machine_ids();
5311: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
5312: if (!$allowed) {
5313: $switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role=dc./'.$dom.'/">'.&mt('Switch Server').'</a>';
5314: }
5315: return $switchserver;
5316: }
5317:
5318: sub modify_quotas {
5319: my ($dom,$action,%domconfig) = @_;
5320: my ($context,@usertools,@options,%validations,%titles,%confhash,%toolshash,
5321: %limithash,$toolregexp,%conditions,$resulttext,%changes);
5322: if ($action eq 'quotas') {
5323: $context = 'tools';
5324: } else {
5325: $context = $action;
5326: }
5327: if ($context eq 'requestcourses') {
5328: @usertools = ('official','unofficial','community');
5329: @options =('norequest','approval','validate','autolimit');
5330: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
5331: %titles = &courserequest_titles();
5332: $toolregexp = join('|',@usertools);
5333: %conditions = &courserequest_conditions();
5334: } elsif ($context eq 'requestauthor') {
5335: @usertools = ('author');
5336: %titles = &authorrequest_titles();
5337: } else {
5338: @usertools = ('aboutme','blog','webdav','portfolio');
5339: %titles = &tool_titles();
5340: }
5341: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
5342: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
5343: foreach my $key (keys(%env)) {
5344: if ($context eq 'requestcourses') {
5345: if ($key =~ /^form\.crsreq_($toolregexp)_(.+)$/) {
5346: my $item = $1;
5347: my $type = $2;
5348: if ($type =~ /^limit_(.+)/) {
5349: $limithash{$item}{$1} = $env{$key};
5350: } else {
5351: $confhash{$item}{$type} = $env{$key};
5352: }
5353: }
5354: } elsif ($context eq 'requestauthor') {
5355: if ($key =~ /^\Qform.authorreq_\E(.+)$/) {
5356: $confhash{$1} = $env{$key};
5357: }
5358: } else {
5359: if ($key =~ /^form\.quota_(.+)$/) {
5360: $confhash{'defaultquota'}{$1} = $env{$key};
5361: }
5362: if ($key =~ /^form\.\Q$context\E_(.+)$/) {
5363: @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key);
5364: }
5365: }
5366: }
5367: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
5368: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.reqapprovalnotify');
5369: @approvalnotify = sort(@approvalnotify);
5370: $confhash{'notify'}{'approval'} = join(',',@approvalnotify);
5371: if (ref($domconfig{$action}) eq 'HASH') {
5372: if (ref($domconfig{$action}{'notify'}) eq 'HASH') {
5373: if ($domconfig{$action}{'notify'}{'approval'} ne $confhash{'notify'}{'approval'}) {
5374: $changes{'notify'}{'approval'} = 1;
5375: }
5376: } else {
5377: if ($confhash{'notify'}{'approval'}) {
5378: $changes{'notify'}{'approval'} = 1;
5379: }
5380: }
5381: } else {
5382: if ($confhash{'notify'}{'approval'}) {
5383: $changes{'notify'}{'approval'} = 1;
5384: }
5385: }
5386: } else {
5387: $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
5388: }
5389: foreach my $item (@usertools) {
5390: foreach my $type (@{$types},'default','_LC_adv') {
5391: my $unset;
5392: if ($context eq 'requestcourses') {
5393: $unset = '0';
5394: if ($type eq '_LC_adv') {
5395: $unset = '';
5396: }
5397: if ($confhash{$item}{$type} eq 'autolimit') {
5398: $confhash{$item}{$type} .= '=';
5399: unless ($limithash{$item}{$type} =~ /\D/) {
5400: $confhash{$item}{$type} .= $limithash{$item}{$type};
5401: }
5402: }
5403: } elsif ($context eq 'requestauthor') {
5404: $unset = '0';
5405: if ($type eq '_LC_adv') {
5406: $unset = '';
5407: }
5408: } else {
5409: if (grep(/^\Q$type\E$/,@{$toolshash{$item}})) {
5410: $confhash{$item}{$type} = 1;
5411: } else {
5412: $confhash{$item}{$type} = 0;
5413: }
5414: }
5415: if (ref($domconfig{$action}) eq 'HASH') {
5416: if ($action eq 'requestauthor') {
5417: if ($domconfig{$action}{$type} ne $confhash{$type}) {
5418: $changes{$type} = 1;
5419: }
5420: } elsif (ref($domconfig{$action}{$item}) eq 'HASH') {
5421: if ($domconfig{$action}{$item}{$type} ne $confhash{$item}{$type}) {
5422: $changes{$item}{$type} = 1;
5423: }
5424: } else {
5425: if ($context eq 'requestcourses') {
5426: if ($confhash{$item}{$type} ne $unset) {
5427: $changes{$item}{$type} = 1;
5428: }
5429: } else {
5430: if (!$confhash{$item}{$type}) {
5431: $changes{$item}{$type} = 1;
5432: }
5433: }
5434: }
5435: } else {
5436: if ($context eq 'requestcourses') {
5437: if ($confhash{$item}{$type} ne $unset) {
5438: $changes{$item}{$type} = 1;
5439: }
5440: } elsif ($context eq 'requestauthor') {
5441: if ($confhash{$type} ne $unset) {
5442: $changes{$type} = 1;
5443: }
5444: } else {
5445: if (!$confhash{$item}{$type}) {
5446: $changes{$item}{$type} = 1;
5447: }
5448: }
5449: }
5450: }
5451: }
5452: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
5453: if (ref($domconfig{'quotas'}) eq 'HASH') {
5454: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
5455: foreach my $key (keys(%{$domconfig{'quotas'}{'defaultquota'}})) {
5456: if (exists($confhash{'defaultquota'}{$key})) {
5457: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{'defaultquota'}{$key}) {
5458: $changes{'defaultquota'}{$key} = 1;
5459: }
5460: } else {
5461: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{'defaultquota'}{$key};
5462: }
5463: }
5464: } else {
5465: foreach my $key (keys(%{$domconfig{'quotas'}})) {
5466: if (exists($confhash{'defaultquota'}{$key})) {
5467: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{$key}) {
5468: $changes{'defaultquota'}{$key} = 1;
5469: }
5470: } else {
5471: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{$key};
5472: }
5473: }
5474: }
5475: }
5476: if (ref($confhash{'defaultquota'}) eq 'HASH') {
5477: foreach my $key (keys(%{$confhash{'defaultquota'}})) {
5478: if (ref($domconfig{'quotas'}) eq 'HASH') {
5479: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
5480: if (!exists($domconfig{'quotas'}{'defaultquota'}{$key})) {
5481: $changes{'defaultquota'}{$key} = 1;
5482: }
5483: } else {
5484: if (!exists($domconfig{'quotas'}{$key})) {
5485: $changes{'defaultquota'}{$key} = 1;
5486: }
5487: }
5488: } else {
5489: $changes{'defaultquota'}{$key} = 1;
5490: }
5491: }
5492: }
5493: }
5494:
5495: if ($context eq 'requestauthor') {
5496: $domdefaults{'requestauthor'} = \%confhash;
5497: } else {
5498: foreach my $key (keys(%confhash)) {
5499: $domdefaults{$key} = $confhash{$key};
5500: }
5501: }
5502:
5503: my %quotahash = (
5504: $action => { %confhash }
5505: );
5506: my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
5507: $dom);
5508: if ($putresult eq 'ok') {
5509: if (keys(%changes) > 0) {
5510: my $cachetime = 24*60*60;
5511: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
5512:
5513: $resulttext = &mt('Changes made:').'<ul>';
5514: unless (($context eq 'requestcourses') ||
5515: ($context eq 'requestauthor')) {
5516: if (ref($changes{'defaultquota'}) eq 'HASH') {
5517: $resulttext .= '<li>'.&mt('Portfolio default quotas').'<ul>';
5518: foreach my $type (@{$types},'default') {
5519: if (defined($changes{'defaultquota'}{$type})) {
5520: my $typetitle = $usertypes->{$type};
5521: if ($type eq 'default') {
5522: $typetitle = $othertitle;
5523: }
5524: $resulttext .= '<li>'.&mt('[_1] set to [_2] Mb',$typetitle,$confhash{'defaultquota'}{$type}).'</li>';
5525: }
5526: }
5527: $resulttext .= '</ul></li>';
5528: }
5529: }
5530: my %newenv;
5531: foreach my $item (@usertools) {
5532: my (%haschgs,%inconf);
5533: if ($context eq 'requestauthor') {
5534: %haschgs = %changes;
5535: %inconf = %confhash;
5536: } else {
5537: if (ref($changes{$item}) eq 'HASH') {
5538: %haschgs = %{$changes{$item}};
5539: }
5540: if (ref($confhash{$item}) eq 'HASH') {
5541: %inconf = %{$confhash{$item}};
5542: }
5543: }
5544: if (keys(%haschgs) > 0) {
5545: my $newacc =
5546: &Apache::lonnet::usertools_access($env{'user.name'},
5547: $env{'user.domain'},
5548: $item,'reload',$context);
5549: if (($context eq 'requestcourses') ||
5550: ($context eq 'requestauthor')) {
5551: if ($env{'environment.canrequest.'.$item} ne $newacc) {
5552: $newenv{'environment.canrequest.'.$item} = $newacc;
5553: }
5554: } else {
5555: if ($env{'environment.availabletools.'.$item} ne $newacc) {
5556: $newenv{'environment.availabletools.'.$item} = $newacc;
5557: }
5558: }
5559: unless ($context eq 'requestauthor') {
5560: $resulttext .= '<li>'.$titles{$item}.'<ul>';
5561: }
5562: foreach my $type (@{$types},'default','_LC_adv') {
5563: if ($haschgs{$type}) {
5564: my $typetitle = $usertypes->{$type};
5565: if ($type eq 'default') {
5566: $typetitle = $othertitle;
5567: } elsif ($type eq '_LC_adv') {
5568: $typetitle = 'LON-CAPA Advanced Users';
5569: }
5570: if ($inconf{$type}) {
5571: if ($context eq 'requestcourses') {
5572: my $cond;
5573: if ($inconf{$type} =~ /^autolimit=(\d*)$/) {
5574: if ($1 eq '') {
5575: $cond = &mt('(Automatic processing of any request).');
5576: } else {
5577: $cond = &mt('(Automatic processing of requests up to limit of [quant,_1,request] per user).',$1);
5578: }
5579: } else {
5580: $cond = $conditions{$inconf{$type}};
5581: }
5582: $resulttext .= '<li>'.&mt('Set to be available to [_1].',$typetitle).' '.$cond.'</li>';
5583: } else {
5584: $resulttext .= '<li>'.&mt('Set to be available to [_1]',$typetitle).'</li>';
5585: }
5586: } else {
5587: if ($type eq '_LC_adv') {
5588: if ($inconf{$type} eq '0') {
5589: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
5590: } else {
5591: $resulttext .= '<li>'.&mt('No override set for [_1]',$typetitle).'</li>';
5592: }
5593: } else {
5594: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
5595: }
5596: }
5597: }
5598: }
5599: unless ($context eq 'requestauthor') {
5600: $resulttext .= '</ul></li>';
5601: }
5602: }
5603: }
5604: if (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
5605: if (ref($changes{'notify'}) eq 'HASH') {
5606: if ($changes{'notify'}{'approval'}) {
5607: if (ref($confhash{'notify'}) eq 'HASH') {
5608: if ($confhash{'notify'}{'approval'}) {
5609: $resulttext .= '<li>'.&mt('Notification of requests requiring approval will be sent to: ').$confhash{'notify'}{'approval'}.'</li>';
5610: } else {
5611: $resulttext .= '<li>'.&mt('No Domain Coordinators will receive notification of requests requiring approval.').'</li>';
5612: }
5613: }
5614: }
5615: }
5616: }
5617: $resulttext .= '</ul>';
5618: if (keys(%newenv)) {
5619: &Apache::lonnet::appenv(\%newenv);
5620: }
5621: } else {
5622: if ($context eq 'requestcourses') {
5623: $resulttext = &mt('No changes made to rights to request creation of courses.');
5624: } elsif ($context eq 'requestauthor') {
5625: $resulttext = &mt('No changes made to rights to request author space.');
5626: } else {
5627: $resulttext = &mt('No changes made to availability of personal information pages, blogs, portfolios or default quotas');
5628: }
5629: }
5630: } else {
5631: $resulttext = '<span class="LC_error">'.
5632: &mt('An error occurred: [_1]',$putresult).'</span>';
5633: }
5634: return $resulttext;
5635: }
5636:
5637: sub modify_autoenroll {
5638: my ($dom,%domconfig) = @_;
5639: my ($resulttext,%changes);
5640: my %currautoenroll;
5641: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
5642: foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
5643: $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
5644: }
5645: }
5646: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
5647: my %title = ( run => 'Auto-enrollment active',
5648: sender => 'Sender for notification messages',
5649: coowners => 'Automatic assignment of co-ownership to instructors of record (institutional data)');
5650: my @offon = ('off','on');
5651: my $sender_uname = $env{'form.sender_uname'};
5652: my $sender_domain = $env{'form.sender_domain'};
5653: if ($sender_domain eq '') {
5654: $sender_uname = '';
5655: } elsif ($sender_uname eq '') {
5656: $sender_domain = '';
5657: }
5658: my $coowners = $env{'form.autoassign_coowners'};
5659: my %autoenrollhash = (
5660: autoenroll => { 'run' => $env{'form.autoenroll_run'},
5661: 'sender_uname' => $sender_uname,
5662: 'sender_domain' => $sender_domain,
5663: 'co-owners' => $coowners,
5664: }
5665: );
5666: my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
5667: $dom);
5668: if ($putresult eq 'ok') {
5669: if (exists($currautoenroll{'run'})) {
5670: if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
5671: $changes{'run'} = 1;
5672: }
5673: } elsif ($autorun) {
5674: if ($env{'form.autoenroll_run'} ne '1') {
5675: $changes{'run'} = 1;
5676: }
5677: }
5678: if ($currautoenroll{'sender_uname'} ne $sender_uname) {
5679: $changes{'sender'} = 1;
5680: }
5681: if ($currautoenroll{'sender_domain'} ne $sender_domain) {
5682: $changes{'sender'} = 1;
5683: }
5684: if ($currautoenroll{'co-owners'} ne '') {
5685: if ($currautoenroll{'co-owners'} ne $coowners) {
5686: $changes{'coowners'} = 1;
5687: }
5688: } elsif ($coowners) {
5689: $changes{'coowners'} = 1;
5690: }
5691: if (keys(%changes) > 0) {
5692: $resulttext = &mt('Changes made:').'<ul>';
5693: if ($changes{'run'}) {
5694: $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
5695: }
5696: if ($changes{'sender'}) {
5697: if ($sender_uname eq '' || $sender_domain eq '') {
5698: $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
5699: } else {
5700: $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
5701: }
5702: }
5703: if ($changes{'coowners'}) {
5704: $resulttext .= '<li>'.&mt("$title{'coowners'} set to $offon[$env{'form.autoassign_coowners'}]").'</li>';
5705: &Apache::loncommon::devalidate_domconfig_cache($dom);
5706: }
5707: $resulttext .= '</ul>';
5708: } else {
5709: $resulttext = &mt('No changes made to auto-enrollment settings');
5710: }
5711: } else {
5712: $resulttext = '<span class="LC_error">'.
5713: &mt('An error occurred: [_1]',$putresult).'</span>';
5714: }
5715: return $resulttext;
5716: }
5717:
5718: sub modify_autoupdate {
5719: my ($dom,%domconfig) = @_;
5720: my ($resulttext,%currautoupdate,%fields,%changes);
5721: if (ref($domconfig{'autoupdate'}) eq 'HASH') {
5722: foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
5723: $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
5724: }
5725: }
5726: my @offon = ('off','on');
5727: my %title = &Apache::lonlocal::texthash (
5728: run => 'Auto-update:',
5729: classlists => 'Updates to user information in classlists?'
5730: );
5731: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
5732: my %fieldtitles = &Apache::lonlocal::texthash (
5733: id => 'Student/Employee ID',
5734: permanentemail => 'E-mail address',
5735: lastname => 'Last Name',
5736: firstname => 'First Name',
5737: middlename => 'Middle Name',
5738: generation => 'Generation',
5739: );
5740: $othertitle = &mt('All users');
5741: if (keys(%{$usertypes}) > 0) {
5742: $othertitle = &mt('Other users');
5743: }
5744: foreach my $key (keys(%env)) {
5745: if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
5746: my ($usertype,$item) = ($1,$2);
5747: if (grep(/^\Q$item\E$/,keys(%fieldtitles))) {
5748: if ($usertype eq 'default') {
5749: push(@{$fields{$1}},$2);
5750: } elsif (ref($types) eq 'ARRAY') {
5751: if (grep(/^\Q$usertype\E$/,@{$types})) {
5752: push(@{$fields{$1}},$2);
5753: }
5754: }
5755: }
5756: }
5757: }
5758: my @lockablenames = &Apache::loncommon::get_env_multiple('form.lockablenames');
5759: @lockablenames = sort(@lockablenames);
5760: if (ref($currautoupdate{'lockablenames'}) eq 'ARRAY') {
5761: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
5762: if (@changed) {
5763: $changes{'lockablenames'} = 1;
5764: }
5765: } else {
5766: if (@lockablenames) {
5767: $changes{'lockablenames'} = 1;
5768: }
5769: }
5770: my %updatehash = (
5771: autoupdate => { run => $env{'form.autoupdate_run'},
5772: classlists => $env{'form.classlists'},
5773: fields => {%fields},
5774: lockablenames => \@lockablenames,
5775: }
5776: );
5777: foreach my $key (keys(%currautoupdate)) {
5778: if (($key eq 'run') || ($key eq 'classlists')) {
5779: if (exists($updatehash{autoupdate}{$key})) {
5780: if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
5781: $changes{$key} = 1;
5782: }
5783: }
5784: } elsif ($key eq 'fields') {
5785: if (ref($currautoupdate{$key}) eq 'HASH') {
5786: foreach my $item (@{$types},'default') {
5787: if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
5788: my $change = 0;
5789: foreach my $type (@{$currautoupdate{$key}{$item}}) {
5790: if (!exists($fields{$item})) {
5791: $change = 1;
5792: last;
5793: } elsif (ref($fields{$item}) eq 'ARRAY') {
5794: if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
5795: $change = 1;
5796: last;
5797: }
5798: }
5799: }
5800: if ($change) {
5801: push(@{$changes{$key}},$item);
5802: }
5803: }
5804: }
5805: }
5806: } elsif ($key eq 'lockablenames') {
5807: if (ref($currautoupdate{$key}) eq 'ARRAY') {
5808: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
5809: if (@changed) {
5810: $changes{'lockablenames'} = 1;
5811: }
5812: } else {
5813: if (@lockablenames) {
5814: $changes{'lockablenames'} = 1;
5815: }
5816: }
5817: }
5818: }
5819: unless (grep(/^\Qlockablenames\E$/,keys(%currautoupdate))) {
5820: if (@lockablenames) {
5821: $changes{'lockablenames'} = 1;
5822: }
5823: }
5824: foreach my $item (@{$types},'default') {
5825: if (defined($fields{$item})) {
5826: if (ref($currautoupdate{'fields'}) eq 'HASH') {
5827: if (ref($currautoupdate{'fields'}{$item}) eq 'ARRAY') {
5828: my $change = 0;
5829: if (ref($fields{$item}) eq 'ARRAY') {
5830: foreach my $type (@{$fields{$item}}) {
5831: if (!grep(/^\Q$type\E$/,@{$currautoupdate{'fields'}{$item}})) {
5832: $change = 1;
5833: last;
5834: }
5835: }
5836: }
5837: if ($change) {
5838: push(@{$changes{'fields'}},$item);
5839: }
5840: } else {
5841: push(@{$changes{'fields'}},$item);
5842: }
5843: } else {
5844: push(@{$changes{'fields'}},$item);
5845: }
5846: }
5847: }
5848: my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
5849: $dom);
5850: if ($putresult eq 'ok') {
5851: if (keys(%changes) > 0) {
5852: $resulttext = &mt('Changes made:').'<ul>';
5853: foreach my $key (sort(keys(%changes))) {
5854: if ($key eq 'lockablenames') {
5855: $resulttext .= '<li>';
5856: if (@lockablenames) {
5857: $usertypes->{'default'} = $othertitle;
5858: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update), available for the following affiliations:").' '.
5859: join(', ', map { $usertypes->{$_}; } @lockablenames).'</li>';
5860: } else {
5861: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update) is unavailable.");
5862: }
5863: $resulttext .= '</li>';
5864: } elsif (ref($changes{$key}) eq 'ARRAY') {
5865: foreach my $item (@{$changes{$key}}) {
5866: my @newvalues;
5867: foreach my $type (@{$fields{$item}}) {
5868: push(@newvalues,$fieldtitles{$type});
5869: }
5870: my $newvaluestr;
5871: if (@newvalues > 0) {
5872: $newvaluestr = join(', ',@newvalues);
5873: } else {
5874: $newvaluestr = &mt('none');
5875: }
5876: if ($item eq 'default') {
5877: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
5878: } else {
5879: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
5880: }
5881: }
5882: } else {
5883: my $newvalue;
5884: if ($key eq 'run') {
5885: $newvalue = $offon[$env{'form.autoupdate_run'}];
5886: } else {
5887: $newvalue = $offon[$env{'form.'.$key}];
5888: }
5889: $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
5890: }
5891: }
5892: $resulttext .= '</ul>';
5893: } else {
5894: $resulttext = &mt('No changes made to autoupdates');
5895: }
5896: } else {
5897: $resulttext = '<span class="LC_error">'.
5898: &mt('An error occurred: [_1]',$putresult).'</span>';
5899: }
5900: return $resulttext;
5901: }
5902:
5903: sub modify_autocreate {
5904: my ($dom,%domconfig) = @_;
5905: my ($resulttext,%changes,%currautocreate,%newvals,%autocreatehash);
5906: if (ref($domconfig{'autocreate'}) eq 'HASH') {
5907: foreach my $key (keys(%{$domconfig{'autocreate'}})) {
5908: $currautocreate{$key} = $domconfig{'autocreate'}{$key};
5909: }
5910: }
5911: my %title= ( xml => 'Auto-creation of courses in XML course description files',
5912: req => 'Auto-creation of validated requests for official courses',
5913: xmldc => 'Identity of course creator of courses from XML files',
5914: );
5915: my @types = ('xml','req');
5916: foreach my $item (@types) {
5917: $newvals{$item} = $env{'form.autocreate_'.$item};
5918: $newvals{$item} =~ s/\D//g;
5919: $newvals{$item} = 0 if ($newvals{$item} eq '');
5920: }
5921: $newvals{'xmldc'} = $env{'form.autocreate_xmldc'};
5922: my %domcoords = &get_active_dcs($dom);
5923: unless (exists($domcoords{$newvals{'xmldc'}})) {
5924: $newvals{'xmldc'} = '';
5925: }
5926: %autocreatehash = (
5927: autocreate => { xml => $newvals{'xml'},
5928: req => $newvals{'req'},
5929: }
5930: );
5931: if ($newvals{'xmldc'} ne '') {
5932: $autocreatehash{'autocreate'}{'xmldc'} = $newvals{'xmldc'};
5933: }
5934: my $putresult = &Apache::lonnet::put_dom('configuration',\%autocreatehash,
5935: $dom);
5936: if ($putresult eq 'ok') {
5937: my @items = @types;
5938: if ($newvals{'xml'}) {
5939: push(@items,'xmldc');
5940: }
5941: foreach my $item (@items) {
5942: if (exists($currautocreate{$item})) {
5943: if ($currautocreate{$item} ne $newvals{$item}) {
5944: $changes{$item} = 1;
5945: }
5946: } elsif ($newvals{$item}) {
5947: $changes{$item} = 1;
5948: }
5949: }
5950: if (keys(%changes) > 0) {
5951: my @offon = ('off','on');
5952: $resulttext = &mt('Changes made:').'<ul>';
5953: foreach my $item (@types) {
5954: if ($changes{$item}) {
5955: my $newtxt = $offon[$newvals{$item}];
5956: $resulttext .= '<li>'.&mt("$title{$item} set to [_1]$newtxt [_2]",'<b>','</b>').'</li>';
5957: }
5958: }
5959: if ($changes{'xmldc'}) {
5960: my ($dcname,$dcdom) = split(':',$newvals{'xmldc'});
5961: my $newtxt = &Apache::loncommon::plainname($dcname,$dcdom);
5962: $resulttext .= '<li>'.&mt("$title{'xmldc'} set to [_1]$newtxt [_2]",'<b>','</b>').'</li>';
5963: }
5964: $resulttext .= '</ul>';
5965: } else {
5966: $resulttext = &mt('No changes made to auto-creation settings');
5967: }
5968: } else {
5969: $resulttext = '<span class="LC_error">'.
5970: &mt('An error occurred: [_1]',$putresult).'</span>';
5971: }
5972: return $resulttext;
5973: }
5974:
5975: sub modify_directorysrch {
5976: my ($dom,%domconfig) = @_;
5977: my ($resulttext,%changes);
5978: my %currdirsrch;
5979: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
5980: foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
5981: $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
5982: }
5983: }
5984: my %title = ( available => 'Directory search available',
5985: localonly => 'Other domains can search',
5986: searchby => 'Search types',
5987: searchtypes => 'Search latitude');
5988: my @offon = ('off','on');
5989: my @otherdoms = ('Yes','No');
5990:
5991: my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');
5992: my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
5993: my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
5994:
5995: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
5996: if (keys(%{$usertypes}) == 0) {
5997: @cansearch = ('default');
5998: } else {
5999: if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
6000: foreach my $type (@{$currdirsrch{'cansearch'}}) {
6001: if (!grep(/^\Q$type\E$/,@cansearch)) {
6002: push(@{$changes{'cansearch'}},$type);
6003: }
6004: }
6005: foreach my $type (@cansearch) {
6006: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
6007: push(@{$changes{'cansearch'}},$type);
6008: }
6009: }
6010: } else {
6011: push(@{$changes{'cansearch'}},@cansearch);
6012: }
6013: }
6014:
6015: if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
6016: foreach my $by (@{$currdirsrch{'searchby'}}) {
6017: if (!grep(/^\Q$by\E$/,@searchby)) {
6018: push(@{$changes{'searchby'}},$by);
6019: }
6020: }
6021: foreach my $by (@searchby) {
6022: if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
6023: push(@{$changes{'searchby'}},$by);
6024: }
6025: }
6026: } else {
6027: push(@{$changes{'searchby'}},@searchby);
6028: }
6029:
6030: if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
6031: foreach my $type (@{$currdirsrch{'searchtypes'}}) {
6032: if (!grep(/^\Q$type\E$/,@searchtypes)) {
6033: push(@{$changes{'searchtypes'}},$type);
6034: }
6035: }
6036: foreach my $type (@searchtypes) {
6037: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
6038: push(@{$changes{'searchtypes'}},$type);
6039: }
6040: }
6041: } else {
6042: if (exists($currdirsrch{'searchtypes'})) {
6043: foreach my $type (@searchtypes) {
6044: if ($type ne $currdirsrch{'searchtypes'}) {
6045: push(@{$changes{'searchtypes'}},$type);
6046: }
6047: }
6048: if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
6049: push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
6050: }
6051: } else {
6052: push(@{$changes{'searchtypes'}},@searchtypes);
6053: }
6054: }
6055:
6056: my %dirsrch_hash = (
6057: directorysrch => { available => $env{'form.dirsrch_available'},
6058: cansearch => \@cansearch,
6059: localonly => $env{'form.dirsrch_localonly'},
6060: searchby => \@searchby,
6061: searchtypes => \@searchtypes,
6062: }
6063: );
6064: my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
6065: $dom);
6066: if ($putresult eq 'ok') {
6067: if (exists($currdirsrch{'available'})) {
6068: if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
6069: $changes{'available'} = 1;
6070: }
6071: } else {
6072: if ($env{'form.dirsrch_available'} eq '1') {
6073: $changes{'available'} = 1;
6074: }
6075: }
6076: if (exists($currdirsrch{'localonly'})) {
6077: if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_localonly'}) {
6078: $changes{'localonly'} = 1;
6079: }
6080: } else {
6081: if ($env{'form.dirsrch_localonly'} eq '1') {
6082: $changes{'localonly'} = 1;
6083: }
6084: }
6085: if (keys(%changes) > 0) {
6086: $resulttext = &mt('Changes made:').'<ul>';
6087: if ($changes{'available'}) {
6088: $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
6089: }
6090: if ($changes{'localonly'}) {
6091: $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_localonly'}]").'</li>';
6092: }
6093:
6094: if (ref($changes{'cansearch'}) eq 'ARRAY') {
6095: my $chgtext;
6096: if (ref($usertypes) eq 'HASH') {
6097: if (keys(%{$usertypes}) > 0) {
6098: foreach my $type (@{$types}) {
6099: if (grep(/^\Q$type\E$/,@cansearch)) {
6100: $chgtext .= $usertypes->{$type}.'; ';
6101: }
6102: }
6103: if (grep(/^default$/,@cansearch)) {
6104: $chgtext .= $othertitle;
6105: } else {
6106: $chgtext =~ s/\; $//;
6107: }
6108: $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>';
6109: }
6110: }
6111: }
6112: if (ref($changes{'searchby'}) eq 'ARRAY') {
6113: my ($searchtitles,$titleorder) = &sorted_searchtitles();
6114: my $chgtext;
6115: foreach my $type (@{$titleorder}) {
6116: if (grep(/^\Q$type\E$/,@searchby)) {
6117: if (defined($searchtitles->{$type})) {
6118: $chgtext .= $searchtitles->{$type}.'; ';
6119: }
6120: }
6121: }
6122: $chgtext =~ s/\; $//;
6123: $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
6124: }
6125: if (ref($changes{'searchtypes'}) eq 'ARRAY') {
6126: my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes();
6127: my $chgtext;
6128: foreach my $type (@{$srchtypeorder}) {
6129: if (grep(/^\Q$type\E$/,@searchtypes)) {
6130: if (defined($srchtypes_desc->{$type})) {
6131: $chgtext .= $srchtypes_desc->{$type}.'; ';
6132: }
6133: }
6134: }
6135: $chgtext =~ s/\; $//;
6136: $resulttext .= '<li>'.&mt("$title{'searchtypes'} set to: \"[_1]\"",$chgtext).'</li>';
6137: }
6138: $resulttext .= '</ul>';
6139: } else {
6140: $resulttext = &mt('No changes made to institution directory search settings');
6141: }
6142: } else {
6143: $resulttext = '<span class="LC_error">'.
6144: &mt('An error occurred: [_1]',$putresult).'</span>';
6145: }
6146: return $resulttext;
6147: }
6148:
6149: sub modify_contacts {
6150: my ($dom,%domconfig) = @_;
6151: my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
6152: if (ref($domconfig{'contacts'}) eq 'HASH') {
6153: foreach my $key (keys(%{$domconfig{'contacts'}})) {
6154: $currsetting{$key} = $domconfig{'contacts'}{$key};
6155: }
6156: }
6157: my (%others,%to,%bcc);
6158: my @contacts = ('supportemail','adminemail');
6159: my @mailings = ('errormail','packagesmail','helpdeskmail','lonstatusmail',
6160: 'requestsmail');
6161: foreach my $type (@mailings) {
6162: @{$newsetting{$type}} =
6163: &Apache::loncommon::get_env_multiple('form.'.$type);
6164: foreach my $item (@contacts) {
6165: if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
6166: $contacts_hash{contacts}{$type}{$item} = 1;
6167: } else {
6168: $contacts_hash{contacts}{$type}{$item} = 0;
6169: }
6170: }
6171: $others{$type} = $env{'form.'.$type.'_others'};
6172: $contacts_hash{contacts}{$type}{'others'} = $others{$type};
6173: if ($type eq 'helpdeskmail') {
6174: $bcc{$type} = $env{'form.'.$type.'_bcc'};
6175: $contacts_hash{contacts}{$type}{'bcc'} = $bcc{$type};
6176: }
6177: }
6178: foreach my $item (@contacts) {
6179: $to{$item} = $env{'form.'.$item};
6180: $contacts_hash{'contacts'}{$item} = $to{$item};
6181: }
6182: if (keys(%currsetting) > 0) {
6183: foreach my $item (@contacts) {
6184: if ($to{$item} ne $currsetting{$item}) {
6185: $changes{$item} = 1;
6186: }
6187: }
6188: foreach my $type (@mailings) {
6189: foreach my $item (@contacts) {
6190: if (ref($currsetting{$type}) eq 'HASH') {
6191: if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
6192: push(@{$changes{$type}},$item);
6193: }
6194: } else {
6195: push(@{$changes{$type}},@{$newsetting{$type}});
6196: }
6197: }
6198: if ($others{$type} ne $currsetting{$type}{'others'}) {
6199: push(@{$changes{$type}},'others');
6200: }
6201: if ($type eq 'helpdeskmail') {
6202: if ($bcc{$type} ne $currsetting{$type}{'bcc'}) {
6203: push(@{$changes{$type}},'bcc');
6204: }
6205: }
6206: }
6207: } else {
6208: my %default;
6209: $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
6210: $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
6211: $default{'errormail'} = 'adminemail';
6212: $default{'packagesmail'} = 'adminemail';
6213: $default{'helpdeskmail'} = 'supportemail';
6214: $default{'lonstatusmail'} = 'adminemail';
6215: $default{'requestsmail'} = 'adminemail';
6216: foreach my $item (@contacts) {
6217: if ($to{$item} ne $default{$item}) {
6218: $changes{$item} = 1;
6219: }
6220: }
6221: foreach my $type (@mailings) {
6222: if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
6223:
6224: push(@{$changes{$type}},@{$newsetting{$type}});
6225: }
6226: if ($others{$type} ne '') {
6227: push(@{$changes{$type}},'others');
6228: }
6229: if ($type eq 'helpdeskmail') {
6230: if ($bcc{$type} ne '') {
6231: push(@{$changes{$type}},'bcc');
6232: }
6233: }
6234: }
6235: }
6236: my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
6237: $dom);
6238: if ($putresult eq 'ok') {
6239: if (keys(%changes) > 0) {
6240: my ($titles,$short_titles) = &contact_titles();
6241: $resulttext = &mt('Changes made:').'<ul>';
6242: foreach my $item (@contacts) {
6243: if ($changes{$item}) {
6244: $resulttext .= '<li>'.$titles->{$item}.
6245: &mt(' set to: ').
6246: '<span class="LC_cusr_emph">'.
6247: $to{$item}.'</span></li>';
6248: }
6249: }
6250: foreach my $type (@mailings) {
6251: if (ref($changes{$type}) eq 'ARRAY') {
6252: $resulttext .= '<li>'.$titles->{$type}.': ';
6253: my @text;
6254: foreach my $item (@{$newsetting{$type}}) {
6255: push(@text,$short_titles->{$item});
6256: }
6257: if ($others{$type} ne '') {
6258: push(@text,$others{$type});
6259: }
6260: $resulttext .= '<span class="LC_cusr_emph">'.
6261: join(', ',@text).'</span>';
6262: if ($type eq 'helpdeskmail') {
6263: if ($bcc{$type} ne '') {
6264: $resulttext .= ' '.&mt('with Bcc to').': <span class="LC_cusr_emph">'.$bcc{$type}.'</span>';
6265: }
6266: }
6267: $resulttext .= '</li>';
6268: }
6269: }
6270: $resulttext .= '</ul>';
6271: } else {
6272: $resulttext = &mt('No changes made to contact information');
6273: }
6274: } else {
6275: $resulttext = '<span class="LC_error">'.
6276: &mt('An error occurred: [_1].',$putresult).'</span>';
6277: }
6278: return $resulttext;
6279: }
6280:
6281: sub modify_usercreation {
6282: my ($dom,%domconfig) = @_;
6283: my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate);
6284: my $warningmsg;
6285: if (ref($domconfig{'usercreation'}) eq 'HASH') {
6286: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
6287: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
6288: }
6289: }
6290: my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
6291: my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
6292: my @email_rule = &Apache::loncommon::get_env_multiple('form.email_rule');
6293: my @contexts = ('author','course','requestcrs','selfcreate');
6294: foreach my $item(@contexts) {
6295: if ($item eq 'selfcreate') {
6296: @{$cancreate{$item}} = &Apache::loncommon::get_env_multiple('form.can_createuser_'.$item);
6297: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
6298: if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) || ($domdefaults{'auth_def'} eq 'localauth'))) {
6299: if (ref($cancreate{$item}) eq 'ARRAY') {
6300: if (grep(/^login$/,@{$cancreate{$item}})) {
6301: $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.');
6302: }
6303: }
6304: }
6305: } else {
6306: $cancreate{$item} = $env{'form.can_createuser_'.$item};
6307: }
6308: }
6309: my ($othertitle,$usertypes,$types) =
6310: &Apache::loncommon::sorted_inst_types($dom);
6311: if (ref($types) eq 'ARRAY') {
6312: if (@{$types} > 0) {
6313: @{$cancreate{'statustocreate'}} =
6314: &Apache::loncommon::get_env_multiple('form.statustocreate');
6315: } else {
6316: @{$cancreate{'statustocreate'}} = ();
6317: }
6318: push(@contexts,'statustocreate');
6319: }
6320: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
6321: foreach my $item (@contexts) {
6322: if (($item eq 'selfcreate') || ($item eq 'statustocreate')) {
6323: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
6324: foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
6325: if (ref($cancreate{$item}) eq 'ARRAY') {
6326: if (!grep(/^$curr$/,@{$cancreate{$item}})) {
6327: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6328: push(@{$changes{'cancreate'}},$item);
6329: }
6330: }
6331: }
6332: }
6333: } else {
6334: if ($curr_usercreation{'cancreate'}{$item} eq '') {
6335: if (@{$cancreate{$item}} > 0) {
6336: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6337: push(@{$changes{'cancreate'}},$item);
6338: }
6339: }
6340: } else {
6341: if ($curr_usercreation{'cancreate'}{$item} eq 'any') {
6342: if (@{$cancreate{$item}} < 3) {
6343: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6344: push(@{$changes{'cancreate'}},$item);
6345: }
6346: }
6347: } elsif ($curr_usercreation{'cancreate'}{$item} eq 'none') {
6348: if (@{$cancreate{$item}} > 0) {
6349: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6350: push(@{$changes{'cancreate'}},$item);
6351: }
6352: }
6353: } elsif (!grep(/^$curr_usercreation{'cancreate'}{$item}$/,@{$cancreate{$item}})) {
6354: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6355: push(@{$changes{'cancreate'}},$item);
6356: }
6357: }
6358: }
6359: }
6360: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6361: foreach my $type (@{$cancreate{$item}}) {
6362: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
6363: if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
6364: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6365: push(@{$changes{'cancreate'}},$item);
6366: }
6367: }
6368: } elsif (($curr_usercreation{'cancreate'}{$item} ne 'any') &&
6369: ($curr_usercreation{'cancreate'}{$item} ne 'none')) {
6370: if ($curr_usercreation{'cancreate'}{$item} ne $type) {
6371: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6372: push(@{$changes{'cancreate'}},$item);
6373: }
6374: }
6375: }
6376: }
6377: }
6378: } else {
6379: if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
6380: push(@{$changes{'cancreate'}},$item);
6381: }
6382: }
6383: }
6384: } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
6385: foreach my $item (@contexts) {
6386: if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
6387: if ($cancreate{$item} ne 'any') {
6388: push(@{$changes{'cancreate'}},$item);
6389: }
6390: } else {
6391: if ($cancreate{$item} ne 'none') {
6392: push(@{$changes{'cancreate'}},$item);
6393: }
6394: }
6395: }
6396: } else {
6397: foreach my $item (@contexts) {
6398: push(@{$changes{'cancreate'}},$item);
6399: }
6400: }
6401:
6402: if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
6403: foreach my $type (@{$curr_usercreation{'username_rule'}}) {
6404: if (!grep(/^\Q$type\E$/,@username_rule)) {
6405: push(@{$changes{'username_rule'}},$type);
6406: }
6407: }
6408: foreach my $type (@username_rule) {
6409: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
6410: push(@{$changes{'username_rule'}},$type);
6411: }
6412: }
6413: } else {
6414: push(@{$changes{'username_rule'}},@username_rule);
6415: }
6416:
6417: if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
6418: foreach my $type (@{$curr_usercreation{'id_rule'}}) {
6419: if (!grep(/^\Q$type\E$/,@id_rule)) {
6420: push(@{$changes{'id_rule'}},$type);
6421: }
6422: }
6423: foreach my $type (@id_rule) {
6424: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
6425: push(@{$changes{'id_rule'}},$type);
6426: }
6427: }
6428: } else {
6429: push(@{$changes{'id_rule'}},@id_rule);
6430: }
6431:
6432: if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
6433: foreach my $type (@{$curr_usercreation{'email_rule'}}) {
6434: if (!grep(/^\Q$type\E$/,@email_rule)) {
6435: push(@{$changes{'email_rule'}},$type);
6436: }
6437: }
6438: foreach my $type (@email_rule) {
6439: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'email_rule'}})) {
6440: push(@{$changes{'email_rule'}},$type);
6441: }
6442: }
6443: } else {
6444: push(@{$changes{'email_rule'}},@email_rule);
6445: }
6446:
6447: my @authen_contexts = ('author','course','domain');
6448: my @authtypes = ('int','krb4','krb5','loc');
6449: my %authhash;
6450: foreach my $item (@authen_contexts) {
6451: my @authallowed = &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
6452: foreach my $auth (@authtypes) {
6453: if (grep(/^\Q$auth\E$/,@authallowed)) {
6454: $authhash{$item}{$auth} = 1;
6455: } else {
6456: $authhash{$item}{$auth} = 0;
6457: }
6458: }
6459: }
6460: if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
6461: foreach my $item (@authen_contexts) {
6462: if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
6463: foreach my $auth (@authtypes) {
6464: if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
6465: push(@{$changes{'authtypes'}},$item);
6466: last;
6467: }
6468: }
6469: }
6470: }
6471: } else {
6472: foreach my $item (@authen_contexts) {
6473: push(@{$changes{'authtypes'}},$item);
6474: }
6475: }
6476:
6477: my %usercreation_hash = (
6478: usercreation => {
6479: cancreate => \%cancreate,
6480: username_rule => \@username_rule,
6481: id_rule => \@id_rule,
6482: email_rule => \@email_rule,
6483: authtypes => \%authhash,
6484: }
6485: );
6486:
6487: my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
6488: $dom);
6489:
6490: my %selfcreatetypes = (
6491: sso => 'users authenticated by institutional single sign on',
6492: login => 'users authenticated by institutional log-in',
6493: email => 'users who provide a valid e-mail address for use as the username',
6494: );
6495: if ($putresult eq 'ok') {
6496: if (keys(%changes) > 0) {
6497: $resulttext = &mt('Changes made:').'<ul>';
6498: if (ref($changes{'cancreate'}) eq 'ARRAY') {
6499: my %lt = &usercreation_types();
6500: foreach my $type (@{$changes{'cancreate'}}) {
6501: my $chgtext;
6502: unless ($type eq 'statustocreate') {
6503: $chgtext = $lt{$type}.', ';
6504: }
6505: if ($type eq 'selfcreate') {
6506: if (@{$cancreate{$type}} == 0) {
6507: $chgtext .= &mt('creation of a new user account is not permitted.');
6508: } else {
6509: $chgtext .= &mt('creation of a new account is permitted for:').'<ul>';
6510: foreach my $case (@{$cancreate{$type}}) {
6511: $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
6512: }
6513: $chgtext .= '</ul>';
6514: if (ref($cancreate{$type}) eq 'ARRAY') {
6515: if (grep(/^(login|sso)$/,@{$cancreate{$type}})) {
6516: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
6517: if (@{$cancreate{'statustocreate'}} == 0) {
6518: $chgtext .= '<br /><span class="LC_warning">'.&mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").'</span>';
6519: }
6520: }
6521: }
6522: }
6523: }
6524: } elsif ($type eq 'statustocreate') {
6525: if ((ref($cancreate{'selfcreate'}) eq 'ARRAY') &&
6526: (ref($cancreate{'statustocreate'}) eq 'ARRAY')) {
6527: if (@{$cancreate{'selfcreate'}} > 0) {
6528: if (@{$cancreate{'statustocreate'}} == 0) {
6529:
6530: $chgtext .= &mt("Institutional affiliations permitted to create accounts set to 'None'.");
6531: if (!grep(/^email$/,@{$cancreate{'selfcreate'}})) {
6532: $chgtext .= '<br /><span class="LC_warning">'.&mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").'</span>';
6533: }
6534: } elsif (ref($usertypes) eq 'HASH') {
6535: if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
6536: $chgtext .= &mt('Creation of a new account for an institutional user is restricted to the following institutional affiliation(s):');
6537: } else {
6538: $chgtext .= &mt('Institutional affiliations permitted to create accounts with institutional authentication were set as follows:');
6539: }
6540: $chgtext .= '<ul>';
6541: foreach my $case (@{$cancreate{$type}}) {
6542: if ($case eq 'default') {
6543: $chgtext .= '<li>'.$othertitle.'</li>';
6544: } else {
6545: $chgtext .= '<li>'.$usertypes->{$case}.'</li>';
6546: }
6547: }
6548: $chgtext .= '</ul>';
6549: if (!grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
6550: $chgtext .= '<br /><span class="LC_warning">'.&mt('However, users authenticated by institutional login/single sign on are not currently permitted to create accounts.').'</span>';
6551: }
6552: }
6553: } else {
6554: if (@{$cancreate{$type}} == 0) {
6555: $chgtext .= &mt("Institutional affiliations permitted to create accounts were set to 'none'.");
6556: } else {
6557: $chgtext .= &mt('Although institutional affiliations permitted to create accounts were changed, self creation of accounts is not currently permitted for any authentication types.');
6558: }
6559: }
6560: }
6561: } else {
6562: if ($cancreate{$type} eq 'none') {
6563: $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
6564: } elsif ($cancreate{$type} eq 'any') {
6565: $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
6566: } elsif ($cancreate{$type} eq 'official') {
6567: $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
6568: } elsif ($cancreate{$type} eq 'unofficial') {
6569: $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
6570: }
6571: }
6572: $resulttext .= '<li>'.$chgtext.'</li>';
6573: }
6574: }
6575: if (ref($changes{'username_rule'}) eq 'ARRAY') {
6576: my ($rules,$ruleorder) =
6577: &Apache::lonnet::inst_userrules($dom,'username');
6578: my $chgtext = '<ul>';
6579: foreach my $type (@username_rule) {
6580: if (ref($rules->{$type}) eq 'HASH') {
6581: $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
6582: }
6583: }
6584: $chgtext .= '</ul>';
6585: if (@username_rule > 0) {
6586: $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
6587: } else {
6588: $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>';
6589: }
6590: }
6591: if (ref($changes{'id_rule'}) eq 'ARRAY') {
6592: my ($idrules,$idruleorder) =
6593: &Apache::lonnet::inst_userrules($dom,'id');
6594: my $chgtext = '<ul>';
6595: foreach my $type (@id_rule) {
6596: if (ref($idrules->{$type}) eq 'HASH') {
6597: $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
6598: }
6599: }
6600: $chgtext .= '</ul>';
6601: if (@id_rule > 0) {
6602: $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
6603: } else {
6604: $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
6605: }
6606: }
6607: if (ref($changes{'email_rule'}) eq 'ARRAY') {
6608: my ($emailrules,$emailruleorder) =
6609: &Apache::lonnet::inst_userrules($dom,'email');
6610: my $chgtext = '<ul>';
6611: foreach my $type (@email_rule) {
6612: if (ref($emailrules->{$type}) eq 'HASH') {
6613: $chgtext .= '<li>'.$emailrules->{$type}{'name'}.'</li>';
6614: }
6615: }
6616: $chgtext .= '</ul>';
6617: if (@email_rule > 0) {
6618: $resulttext .= '<li>'.&mt('Accounts may not be created by users self-enrolling with e-mail addresses of the following types: ').$chgtext.'</li>';
6619: } else {
6620: $resulttext .= '<li>'.&mt('There are now no restrictions on e-mail addresses which may be used as a username when self-enrolling.').'</li>';
6621: }
6622: }
6623:
6624: my %authname = &authtype_names();
6625: my %context_title = &context_names();
6626: if (ref($changes{'authtypes'}) eq 'ARRAY') {
6627: my $chgtext = '<ul>';
6628: foreach my $type (@{$changes{'authtypes'}}) {
6629: my @allowed;
6630: $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
6631: foreach my $auth (@authtypes) {
6632: if ($authhash{$type}{$auth}) {
6633: push(@allowed,$authname{$auth});
6634: }
6635: }
6636: if (@allowed > 0) {
6637: $chgtext .= join(', ',@allowed).'</li>';
6638: } else {
6639: $chgtext .= &mt('none').'</li>';
6640: }
6641: }
6642: $chgtext .= '</ul>';
6643: $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
6644: $resulttext .= '</li>';
6645: }
6646: $resulttext .= '</ul>';
6647: } else {
6648: $resulttext = &mt('No changes made to user creation settings');
6649: }
6650: } else {
6651: $resulttext = '<span class="LC_error">'.
6652: &mt('An error occurred: [_1]',$putresult).'</span>';
6653: }
6654: if ($warningmsg ne '') {
6655: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
6656: }
6657: return $resulttext;
6658: }
6659:
6660: sub modify_usermodification {
6661: my ($dom,%domconfig) = @_;
6662: my ($resulttext,%curr_usermodification,%changes);
6663: if (ref($domconfig{'usermodification'}) eq 'HASH') {
6664: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
6665: $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
6666: }
6667: }
6668: my @contexts = ('author','course','selfcreate');
6669: my %context_title = (
6670: author => 'In author context',
6671: course => 'In course context',
6672: selfcreate => 'When self creating account',
6673: );
6674: my @fields = ('lastname','firstname','middlename','generation',
6675: 'permanentemail','id');
6676: my %roles = (
6677: author => ['ca','aa'],
6678: course => ['st','ep','ta','in','cr'],
6679: );
6680: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
6681: if (ref($types) eq 'ARRAY') {
6682: push(@{$types},'default');
6683: $usertypes->{'default'} = $othertitle;
6684: }
6685: $roles{'selfcreate'} = $types;
6686: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
6687: my %modifyhash;
6688: foreach my $context (@contexts) {
6689: foreach my $role (@{$roles{$context}}) {
6690: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$role);
6691: foreach my $item (@fields) {
6692: if (grep(/^\Q$item\E$/,@modifiable)) {
6693: $modifyhash{$context}{$role}{$item} = 1;
6694: } else {
6695: $modifyhash{$context}{$role}{$item} = 0;
6696: }
6697: }
6698: }
6699: if (ref($curr_usermodification{$context}) eq 'HASH') {
6700: foreach my $role (@{$roles{$context}}) {
6701: if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
6702: foreach my $field (@fields) {
6703: if ($modifyhash{$context}{$role}{$field} ne
6704: $curr_usermodification{$context}{$role}{$field}) {
6705: push(@{$changes{$context}},$role);
6706: last;
6707: }
6708: }
6709: }
6710: }
6711: } else {
6712: foreach my $context (@contexts) {
6713: foreach my $role (@{$roles{$context}}) {
6714: push(@{$changes{$context}},$role);
6715: }
6716: }
6717: }
6718: }
6719: my %usermodification_hash = (
6720: usermodification => \%modifyhash,
6721: );
6722: my $putresult = &Apache::lonnet::put_dom('configuration',
6723: \%usermodification_hash,$dom);
6724: if ($putresult eq 'ok') {
6725: if (keys(%changes) > 0) {
6726: $resulttext = &mt('Changes made: ').'<ul>';
6727: foreach my $context (@contexts) {
6728: if (ref($changes{$context}) eq 'ARRAY') {
6729: $resulttext .= '<li>'.$context_title{$context}.':<ul>';
6730: if (ref($changes{$context}) eq 'ARRAY') {
6731: foreach my $role (@{$changes{$context}}) {
6732: my $rolename;
6733: if ($context eq 'selfcreate') {
6734: $rolename = $role;
6735: if (ref($usertypes) eq 'HASH') {
6736: if ($usertypes->{$role} ne '') {
6737: $rolename = $usertypes->{$role};
6738: }
6739: }
6740: } else {
6741: if ($role eq 'cr') {
6742: $rolename = &mt('Custom');
6743: } else {
6744: $rolename = &Apache::lonnet::plaintext($role);
6745: }
6746: }
6747: my @modifiable;
6748: if ($context eq 'selfcreate') {
6749: $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): ');
6750: } else {
6751: $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
6752: }
6753: foreach my $field (@fields) {
6754: if ($modifyhash{$context}{$role}{$field}) {
6755: push(@modifiable,$fieldtitles{$field});
6756: }
6757: }
6758: if (@modifiable > 0) {
6759: $resulttext .= join(', ',@modifiable);
6760: } else {
6761: $resulttext .= &mt('none');
6762: }
6763: $resulttext .= '</li>';
6764: }
6765: $resulttext .= '</ul></li>';
6766: }
6767: }
6768: }
6769: $resulttext .= '</ul>';
6770: } else {
6771: $resulttext = &mt('No changes made to user modification settings');
6772: }
6773: } else {
6774: $resulttext = '<span class="LC_error">'.
6775: &mt('An error occurred: [_1]',$putresult).'</span>';
6776: }
6777: return $resulttext;
6778: }
6779:
6780: sub modify_defaults {
6781: my ($dom,$r) = @_;
6782: my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
6783: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
6784: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def','portal_def');
6785: my @authtypes = ('internal','krb4','krb5','localauth');
6786: foreach my $item (@items) {
6787: $newvalues{$item} = $env{'form.'.$item};
6788: if ($item eq 'auth_def') {
6789: if ($newvalues{$item} ne '') {
6790: if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
6791: push(@errors,$item);
6792: }
6793: }
6794: } elsif ($item eq 'lang_def') {
6795: if ($newvalues{$item} ne '') {
6796: if ($newvalues{$item} =~ /^(\w+)/) {
6797: my $langcode = $1;
6798: if ($langcode ne 'x_chef') {
6799: if (code2language($langcode) eq '') {
6800: push(@errors,$item);
6801: }
6802: }
6803: } else {
6804: push(@errors,$item);
6805: }
6806: }
6807: } elsif ($item eq 'timezone_def') {
6808: if ($newvalues{$item} ne '') {
6809: if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
6810: push(@errors,$item);
6811: }
6812: }
6813: } elsif ($item eq 'datelocale_def') {
6814: if ($newvalues{$item} ne '') {
6815: my @datelocale_ids = DateTime::Locale->ids();
6816: if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
6817: push(@errors,$item);
6818: }
6819: }
6820: } elsif ($item eq 'portal_def') {
6821: if ($newvalues{$item} ne '') {
6822: 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])\/?$/) {
6823: push(@errors,$item);
6824: }
6825: }
6826: }
6827: if (grep(/^\Q$item\E$/,@errors)) {
6828: $newvalues{$item} = $domdefaults{$item};
6829: } elsif ($domdefaults{$item} ne $newvalues{$item}) {
6830: $changes{$item} = 1;
6831: }
6832: $domdefaults{$item} = $newvalues{$item};
6833: }
6834: my %defaults_hash = (
6835: defaults => \%newvalues,
6836: );
6837: my $title = &defaults_titles();
6838: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
6839: $dom);
6840: if ($putresult eq 'ok') {
6841: if (keys(%changes) > 0) {
6842: $resulttext = &mt('Changes made:').'<ul>';
6843: my $version = $r->dir_config('lonVersion');
6844: 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";
6845: foreach my $item (sort(keys(%changes))) {
6846: my $value = $env{'form.'.$item};
6847: if ($value eq '') {
6848: $value = &mt('none');
6849: } elsif ($item eq 'auth_def') {
6850: my %authnames = &authtype_names();
6851: my %shortauth = (
6852: internal => 'int',
6853: krb4 => 'krb4',
6854: krb5 => 'krb5',
6855: localauth => 'loc',
6856: );
6857: $value = $authnames{$shortauth{$value}};
6858: }
6859: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
6860: $mailmsgtext .= "$title->{$item} set to $value\n";
6861: }
6862: $resulttext .= '</ul>';
6863: $mailmsgtext .= "\n";
6864: my $cachetime = 24*60*60;
6865: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
6866: if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
6867: my $sysmail = $r->dir_config('lonSysEMail');
6868: &Apache::lonmsg::sendemail($sysmail,"LON-CAPA Domain Settings Change - $dom",$mailmsgtext);
6869: }
6870: } else {
6871: $resulttext = &mt('No changes made to default authentication/language/timezone settings');
6872: }
6873: } else {
6874: $resulttext = '<span class="LC_error">'.
6875: &mt('An error occurred: [_1]',$putresult).'</span>';
6876: }
6877: if (@errors > 0) {
6878: $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
6879: foreach my $item (@errors) {
6880: $resulttext .= ' "'.$title->{$item}.'",';
6881: }
6882: $resulttext =~ s/,$//;
6883: }
6884: return $resulttext;
6885: }
6886:
6887: sub modify_scantron {
6888: my ($r,$dom,$confname,%domconfig) = @_;
6889: my ($resulttext,%confhash,%changes,$errors);
6890: my $custom = 'custom.tab';
6891: my $default = 'default.tab';
6892: my $servadm = $r->dir_config('lonAdmEMail');
6893: my ($configuserok,$author_ok,$switchserver) =
6894: &config_check($dom,$confname,$servadm);
6895: if ($env{'form.scantronformat.filename'} ne '') {
6896: my $error;
6897: if ($configuserok eq 'ok') {
6898: if ($switchserver) {
6899: $error = &mt("Upload of bubblesheet format file is not permitted to this server: [_1]",$switchserver);
6900: } else {
6901: if ($author_ok eq 'ok') {
6902: my ($result,$scantronurl) =
6903: &publishlogo($r,'upload','scantronformat',$dom,
6904: $confname,'scantron','','',$custom);
6905: if ($result eq 'ok') {
6906: $confhash{'scantron'}{'scantronformat'} = $scantronurl;
6907: $changes{'scantronformat'} = 1;
6908: } else {
6909: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
6910: }
6911: } else {
6912: $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);
6913: }
6914: }
6915: } else {
6916: $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);
6917: }
6918: if ($error) {
6919: &Apache::lonnet::logthis($error);
6920: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
6921: }
6922: }
6923: if (ref($domconfig{'scantron'}) eq 'HASH') {
6924: if ($domconfig{'scantron'}{'scantronformat'} ne '') {
6925: if ($env{'form.scantronformat_del'}) {
6926: $confhash{'scantron'}{'scantronformat'} = '';
6927: $changes{'scantronformat'} = 1;
6928: }
6929: }
6930: }
6931: if (keys(%confhash) > 0) {
6932: my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
6933: $dom);
6934: if ($putresult eq 'ok') {
6935: if (keys(%changes) > 0) {
6936: if (ref($confhash{'scantron'}) eq 'HASH') {
6937: $resulttext = &mt('Changes made:').'<ul>';
6938: if ($confhash{'scantron'}{'scantronformat'} eq '') {
6939: $resulttext .= '<li>'.&mt('[_1] bubblesheet format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
6940: } else {
6941: $resulttext .= '<li>'.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
6942: }
6943: $resulttext .= '</ul>';
6944: } else {
6945: $resulttext = &mt('Changes made to bubblesheet format file.');
6946: }
6947: $resulttext .= '</ul>';
6948: &Apache::loncommon::devalidate_domconfig_cache($dom);
6949: } else {
6950: $resulttext = &mt('No changes made to bubblesheet format file');
6951: }
6952: } else {
6953: $resulttext = '<span class="LC_error">'.
6954: &mt('An error occurred: [_1]',$putresult).'</span>';
6955: }
6956: } else {
6957: $resulttext = &mt('No changes made to bubblesheet format file');
6958: }
6959: if ($errors) {
6960: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
6961: $errors.'</ul>';
6962: }
6963: return $resulttext;
6964: }
6965:
6966: sub modify_coursecategories {
6967: my ($dom,%domconfig) = @_;
6968: my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
6969: $cathash);
6970: my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
6971: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
6972: $cathash = $domconfig{'coursecategories'}{'cats'};
6973: if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
6974: $changes{'togglecats'} = 1;
6975: $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
6976: }
6977: if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
6978: $changes{'categorize'} = 1;
6979: $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
6980: }
6981: if ($domconfig{'coursecategories'}{'togglecatscomm'} ne $env{'form.togglecatscomm'}) {
6982: $changes{'togglecatscomm'} = 1;
6983: $domconfig{'coursecategories'}{'togglecatscomm'} = $env{'form.togglecatscomm'};
6984: }
6985: if ($domconfig{'coursecategories'}{'categorizecomm'} ne $env{'form.categorizecomm'}) {
6986: $changes{'categorizecomm'} = 1;
6987: $domconfig{'coursecategories'}{'categorizecomm'} = $env{'form.categorizecomm'};
6988: }
6989: } else {
6990: $changes{'togglecats'} = 1;
6991: $changes{'categorize'} = 1;
6992: $changes{'togglecatscomm'} = 1;
6993: $changes{'categorizecomm'} = 1;
6994: $domconfig{'coursecategories'} = {
6995: togglecats => $env{'form.togglecats'},
6996: categorize => $env{'form.categorize'},
6997: togglecatscomm => $env{'form.togglecatscomm'},
6998: categorizecomm => $env{'form.categorizecomm'},
6999: };
7000: }
7001: if (ref($cathash) eq 'HASH') {
7002: if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '') && ($env{'form.instcode'} == 0)) {
7003: push (@deletecategory,'instcode::0');
7004: }
7005: if (($domconfig{'coursecategories'}{'cats'}{'communities::0'} ne '') && ($env{'form.communities'} == 0)) {
7006: push(@deletecategory,'communities::0');
7007: }
7008: }
7009: my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
7010: if (ref($cathash) eq 'HASH') {
7011: if (@deletecategory > 0) {
7012: #FIXME Need to remove category from all courses using a deleted category
7013: &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
7014: foreach my $item (@deletecategory) {
7015: if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
7016: delete($domconfig{'coursecategories'}{'cats'}{$item});
7017: $deletions{$item} = 1;
7018: &recurse_cat_deletes($item,$cathash,\%deletions);
7019: }
7020: }
7021: }
7022: foreach my $item (keys(%{$cathash})) {
7023: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
7024: if ($cathash->{$item} ne $env{'form.'.$item}) {
7025: $reorderings{$item} = 1;
7026: $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
7027: }
7028: if ($env{'form.addcategory_name_'.$item} ne '') {
7029: my $newcat = $env{'form.addcategory_name_'.$item};
7030: my $newdepth = $depth+1;
7031: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
7032: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
7033: $adds{$newitem} = 1;
7034: }
7035: if ($env{'form.subcat_'.$item} ne '') {
7036: my $newcat = $env{'form.subcat_'.$item};
7037: my $newdepth = $depth+1;
7038: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
7039: $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
7040: $adds{$newitem} = 1;
7041: }
7042: }
7043: }
7044: if ($env{'form.instcode'} eq '1') {
7045: if (ref($cathash) eq 'HASH') {
7046: my $newitem = 'instcode::0';
7047: if ($cathash->{$newitem} eq '') {
7048: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
7049: $adds{$newitem} = 1;
7050: }
7051: } else {
7052: my $newitem = 'instcode::0';
7053: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
7054: $adds{$newitem} = 1;
7055: }
7056: }
7057: if ($env{'form.communities'} eq '1') {
7058: if (ref($cathash) eq 'HASH') {
7059: my $newitem = 'communities::0';
7060: if ($cathash->{$newitem} eq '') {
7061: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
7062: $adds{$newitem} = 1;
7063: }
7064: } else {
7065: my $newitem = 'communities::0';
7066: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
7067: $adds{$newitem} = 1;
7068: }
7069: }
7070: if ($env{'form.addcategory_name'} ne '') {
7071: if (($env{'form.addcategory_name'} ne 'instcode') &&
7072: ($env{'form.addcategory_name'} ne 'communities')) {
7073: my $newitem = &escape($env{'form.addcategory_name'}).'::0';
7074: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
7075: $adds{$newitem} = 1;
7076: }
7077: }
7078: my $putresult;
7079: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
7080: if (keys(%deletions) > 0) {
7081: foreach my $key (keys(%deletions)) {
7082: if ($predelallitems{$key} ne '') {
7083: $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
7084: }
7085: }
7086: }
7087: my (@chkcats,@chktrails,%chkallitems);
7088: &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
7089: if (ref($chkcats[0]) eq 'ARRAY') {
7090: my $depth = 0;
7091: my $chg = 0;
7092: for (my $i=0; $i<@{$chkcats[0]}; $i++) {
7093: my $name = $chkcats[0][$i];
7094: my $item;
7095: if ($name eq '') {
7096: $chg ++;
7097: } else {
7098: $item = &escape($name).'::0';
7099: if ($chg) {
7100: $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
7101: }
7102: $depth ++;
7103: &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
7104: $depth --;
7105: }
7106: }
7107: }
7108: }
7109: if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
7110: $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
7111: if ($putresult eq 'ok') {
7112: my %title = (
7113: togglecats => 'Show/Hide a course in catalog',
7114: categorize => 'Assign a category to a course',
7115: togglecatscomm => 'Show/Hide a community in catalog',
7116: categorizecomm => 'Assign a category to a community',
7117: );
7118: my %level = (
7119: dom => 'set in Domain ("Modify Course/Community")',
7120: crs => 'set in Course ("Course Configuration")',
7121: comm => 'set in Community ("Community Configuration")',
7122: );
7123: $resulttext = &mt('Changes made:').'<ul>';
7124: if ($changes{'togglecats'}) {
7125: $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>';
7126: }
7127: if ($changes{'categorize'}) {
7128: $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
7129: }
7130: if ($changes{'togglecatscomm'}) {
7131: $resulttext .= '<li>'.&mt("$title{'togglecatscomm'} $level{$env{'form.togglecatscomm'}}").'</li>';
7132: }
7133: if ($changes{'categorizecomm'}) {
7134: $resulttext .= '<li>'.&mt("$title{'categorizecomm'} $level{$env{'form.categorizecomm'}}").'</li>';
7135: }
7136: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
7137: my $cathash;
7138: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
7139: $cathash = $domconfig{'coursecategories'}{'cats'};
7140: } else {
7141: $cathash = {};
7142: }
7143: my (@cats,@trails,%allitems);
7144: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
7145: if (keys(%deletions) > 0) {
7146: $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
7147: foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) {
7148: $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
7149: }
7150: $resulttext .= '</ul></li>';
7151: }
7152: if (keys(%reorderings) > 0) {
7153: my %sort_by_trail;
7154: $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
7155: foreach my $key (keys(%reorderings)) {
7156: if ($allitems{$key} ne '') {
7157: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
7158: }
7159: }
7160: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
7161: $resulttext .= '<li>'.$trails[$trail].'</li>';
7162: }
7163: $resulttext .= '</ul></li>';
7164: }
7165: if (keys(%adds) > 0) {
7166: my %sort_by_trail;
7167: $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
7168: foreach my $key (keys(%adds)) {
7169: if ($allitems{$key} ne '') {
7170: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
7171: }
7172: }
7173: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
7174: $resulttext .= '<li>'.$trails[$trail].'</li>';
7175: }
7176: $resulttext .= '</ul></li>';
7177: }
7178: }
7179: $resulttext .= '</ul>';
7180: } else {
7181: $resulttext = '<span class="LC_error">'.
7182: &mt('An error occurred: [_1]',$putresult).'</span>';
7183: }
7184: } else {
7185: $resulttext = &mt('No changes made to course and community categories');
7186: }
7187: return $resulttext;
7188: }
7189:
7190: sub modify_serverstatuses {
7191: my ($dom,%domconfig) = @_;
7192: my ($resulttext,%changes,%currserverstatus,%newserverstatus);
7193: if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
7194: %currserverstatus = %{$domconfig{'serverstatuses'}};
7195: }
7196: my @pages = &serverstatus_pages();
7197: foreach my $type (@pages) {
7198: $newserverstatus{$type}{'namedusers'} = '';
7199: $newserverstatus{$type}{'machines'} = '';
7200: if (defined($env{'form.'.$type.'_namedusers'})) {
7201: my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
7202: my @okusers;
7203: foreach my $user (@users) {
7204: my ($uname,$udom) = split(/:/,$user);
7205: if (($udom =~ /^$match_domain$/) &&
7206: (&Apache::lonnet::domain($udom)) &&
7207: ($uname =~ /^$match_username$/)) {
7208: if (!grep(/^\Q$user\E/,@okusers)) {
7209: push(@okusers,$user);
7210: }
7211: }
7212: }
7213: if (@okusers > 0) {
7214: @okusers = sort(@okusers);
7215: $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
7216: }
7217: }
7218: if (defined($env{'form.'.$type.'_machines'})) {
7219: my @machines = split(/,/,$env{'form.'.$type.'_machines'});
7220: my @okmachines;
7221: foreach my $ip (@machines) {
7222: my @parts = split(/\./,$ip);
7223: next if (@parts < 4);
7224: my $badip = 0;
7225: for (my $i=0; $i<4; $i++) {
7226: if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
7227: $badip = 1;
7228: last;
7229: }
7230: }
7231: if (!$badip) {
7232: push(@okmachines,$ip);
7233: }
7234: }
7235: @okmachines = sort(@okmachines);
7236: $newserverstatus{$type}{'machines'} = join(',',@okmachines);
7237: }
7238: }
7239: my %serverstatushash = (
7240: serverstatuses => \%newserverstatus,
7241: );
7242: foreach my $type (@pages) {
7243: foreach my $setting ('namedusers','machines') {
7244: my (@current,@new);
7245: if (ref($currserverstatus{$type}) eq 'HASH') {
7246: if ($currserverstatus{$type}{$setting} ne '') {
7247: @current = split(/,/,$currserverstatus{$type}{$setting});
7248: }
7249: }
7250: if ($newserverstatus{$type}{$setting} ne '') {
7251: @new = split(/,/,$newserverstatus{$type}{$setting});
7252: }
7253: if (@current > 0) {
7254: if (@new > 0) {
7255: foreach my $item (@current) {
7256: if (!grep(/^\Q$item\E$/,@new)) {
7257: $changes{$type}{$setting} = 1;
7258: last;
7259: }
7260: }
7261: foreach my $item (@new) {
7262: if (!grep(/^\Q$item\E$/,@current)) {
7263: $changes{$type}{$setting} = 1;
7264: last;
7265: }
7266: }
7267: } else {
7268: $changes{$type}{$setting} = 1;
7269: }
7270: } elsif (@new > 0) {
7271: $changes{$type}{$setting} = 1;
7272: }
7273: }
7274: }
7275: if (keys(%changes) > 0) {
7276: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
7277: my $putresult = &Apache::lonnet::put_dom('configuration',
7278: \%serverstatushash,$dom);
7279: if ($putresult eq 'ok') {
7280: $resulttext .= &mt('Changes made:').'<ul>';
7281: foreach my $type (@pages) {
7282: if (ref($changes{$type}) eq 'HASH') {
7283: $resulttext .= '<li>'.$titles->{$type}.'<ul>';
7284: if ($changes{$type}{'namedusers'}) {
7285: if ($newserverstatus{$type}{'namedusers'} eq '') {
7286: $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n";
7287: } else {
7288: $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n";
7289: }
7290: }
7291: if ($changes{$type}{'machines'}) {
7292: if ($newserverstatus{$type}{'machines'} eq '') {
7293: $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n";
7294: } else {
7295: $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n";
7296: }
7297:
7298: }
7299: $resulttext .= '</ul></li>';
7300: }
7301: }
7302: $resulttext .= '</ul>';
7303: } else {
7304: $resulttext = '<span class="LC_error">'.
7305: &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>';
7306:
7307: }
7308: } else {
7309: $resulttext = &mt('No changes made to access to server status pages');
7310: }
7311: return $resulttext;
7312: }
7313:
7314: sub modify_helpsettings {
7315: my ($r,$dom,$confname,%domconfig) = @_;
7316: my ($resulttext,$errors,%changes,%helphash);
7317:
7318: my $customhelpfile = $env{'form.loginhelpurl.filename'};
7319: my $defaulthelpfile = 'defaulthelp.html';
7320: my $servadm = $r->dir_config('lonAdmEMail');
7321: my ($configuserok,$author_ok,$switchserver) =
7322: &config_check($dom,$confname,$servadm);
7323:
7324: my %defaultchecked = ('submitbugs' => 'on');
7325: my @offon = ('off','on');
7326: my %title = ( submitbugs => 'Display link for users to submit a bug',
7327: loginhelpurl => 'Unauthenticated login help page set to custom file');
7328:
7329: my @toggles = ('submitbugs');
7330:
7331: $helphash{'helpsettings'} = {};
7332:
7333: if (ref($domconfig{'helpsettings'}) ne 'HASH') {
7334: if ($domconfig{'helpsettings'} eq '') {
7335: $domconfig{'helpsettings'} = {};
7336: }
7337: }
7338:
7339: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
7340:
7341: foreach my $item (@toggles) {
7342:
7343: if ($defaultchecked{$item} eq 'on') {
7344: if (($domconfig{'helpsettings'}{$item} eq '') &&
7345: ($env{'form.'.$item} eq '0')) {
7346: $changes{$item} = 1;
7347: } elsif ($domconfig{'helpsettings'}{$item} ne $env{'form.'.$item}) {
7348: $changes{$item} = 1;
7349: }
7350: } elsif ($defaultchecked{$item} eq 'off') {
7351: if (($domconfig{'helpsettings'}{$item} eq '') &&
7352: ($env{'form.'.$item} eq '1')) {
7353: $changes{$item} = 1;
7354: } elsif ($domconfig{'helpsettings'}{$item} ne $env{'form.'.$item}) {
7355: $changes{$item} = 1;
7356: }
7357: }
7358: $helphash{'helpsettings'}{$item} = $env{'form.'.$item};
7359: }
7360:
7361: if ($customhelpfile ne '') {
7362: my $error;
7363: if ($configuserok eq 'ok') {
7364: if ($switchserver) {
7365: $error = &mt("Upload of custom help file is not permitted to this server: [_1]",$switchserver);
7366: } else {
7367: if ($author_ok eq 'ok') {
7368: my ($result,$loginhelpurl) =
7369: &publishlogo($r,'upload','loginhelpurl',$dom,
7370: $confname,'help','','',$customhelpfile);
7371: if ($result eq 'ok') {
7372: $helphash{'helpsettings'}{'loginhelpurl'} = $loginhelpurl;
7373: $changes{'loginhelpurl'} = 1;
7374: } else {
7375: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$customhelpfile,$result);
7376: }
7377: } else {
7378: $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);
7379: }
7380: }
7381: } else {
7382: $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);
7383: }
7384: if ($error) {
7385: &Apache::lonnet::logthis($error);
7386: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
7387: }
7388: }
7389:
7390: if ($domconfig{'helpsettings'}{'loginhelpurl'} ne '') {
7391: if ($env{'form.loginhelpurl_del'}) {
7392: $helphash{'helpsettings'}{'loginhelpurl'} = '';
7393: $changes{'loginhelpurl'} = 1;
7394: }
7395: }
7396: }
7397:
7398:
7399: my $putresult;
7400:
7401: if (keys(%changes) > 0) {
7402: $putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom);
7403: } else {
7404: $putresult = 'ok';
7405: }
7406:
7407: if ($putresult eq 'ok') {
7408: if (keys(%changes) > 0) {
7409: $resulttext = &mt('Changes made:').'<ul>';
7410: foreach my $item (sort(keys(%changes))) {
7411: if ($item eq 'submitbugs') {
7412: $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
7413: }
7414: if ($item eq 'loginhelpurl') {
7415: if ($helphash{'helpsettings'}{'loginhelpurl'} eq '') {
7416: $resulttext .= '<li>'.&mt('[_1] help file removed; [_2] file will be used for the unathorized help page in this domain.',$customhelpfile,$defaulthelpfile).'</li>';
7417: } else {
7418: $resulttext .= '<li>'.&mt("$title{$item} [_1]",$customhelpfile).'</li>';
7419: }
7420: }
7421: }
7422: $resulttext .= '</ul>';
7423: } else {
7424: $resulttext = &mt('No changes made to help settings');
7425: }
7426: } else {
7427: $resulttext = '<span class="LC_error">'.
7428: &mt('An error occurred: [_1]',$putresult).'</span>';
7429: }
7430: if ($errors) {
7431: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
7432: $errors.'</ul>';
7433: }
7434: return $resulttext;
7435: }
7436:
7437: sub modify_coursedefaults {
7438: my ($dom,%domconfig) = @_;
7439: my ($resulttext,$errors,%changes,%defaultshash);
7440: my %defaultchecked = ('canuse_pdfforms' => 'off');
7441: my @offon = ('off','on');
7442: my @toggles = ('canuse_pdfforms');
7443:
7444: $defaultshash{'coursedefaults'} = {};
7445:
7446: if (ref($domconfig{'coursedefaults'}) ne 'HASH') {
7447: if ($domconfig{'coursedefaults'} eq '') {
7448: $domconfig{'coursedefaults'} = {};
7449: }
7450: }
7451:
7452: if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
7453: foreach my $item (@toggles) {
7454: if ($defaultchecked{$item} eq 'on') {
7455: if (($domconfig{'coursedefaults'}{$item} eq '') &&
7456: ($env{'form.'.$item} eq '0')) {
7457: $changes{$item} = 1;
7458: } elsif ($domconfig{'coursdefaults'}{$item} ne $env{'form.'.$item}) {
7459: $changes{$item} = 1;
7460: }
7461: } elsif ($defaultchecked{$item} eq 'off') {
7462: if (($domconfig{'coursedefaults'}{$item} eq '') &&
7463: ($env{'form.'.$item} eq '1')) {
7464: $changes{$item} = 1;
7465: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
7466: $changes{$item} = 1;
7467: }
7468: }
7469: $defaultshash{'coursedefaults'}{$item} = $env{'form.'.$item};
7470: }
7471: my $currdefresponder = $domconfig{'coursedefaults'}{'anonsurvey_threshold'};
7472: my $newdefresponder = $env{'form.anonsurvey_threshold'};
7473: $newdefresponder =~ s/\D//g;
7474: if ($newdefresponder eq '' || $newdefresponder < 1) {
7475: $newdefresponder = 1;
7476: }
7477: $defaultshash{'coursedefaults'}{'anonsurvey_threshold'} = $newdefresponder;
7478: if ($currdefresponder ne $newdefresponder) {
7479: unless ($currdefresponder eq '' && $newdefresponder == 10) {
7480: $changes{'anonsurvey_threshold'} = 1;
7481: }
7482: }
7483: }
7484: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
7485: $dom);
7486: if ($putresult eq 'ok') {
7487: if (keys(%changes) > 0) {
7488: if ($changes{'canuse_pdfforms'}) {
7489: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
7490: $domdefaults{'canuse_pdfforms'}=$defaultshash{'coursedefaults'}{'canuse_pdfforms'};
7491: my $cachetime = 24*60*60;
7492: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
7493: }
7494: $resulttext = &mt('Changes made:').'<ul>';
7495: foreach my $item (sort(keys(%changes))) {
7496: if ($item eq 'canuse_pdfforms') {
7497: if ($env{'form.'.$item} eq '1') {
7498: $resulttext .= '<li>'.&mt("Course/Community users can create/upload PDF forms set to 'on'").'</li>';
7499: } else {
7500: $resulttext .= '<li>'.&mt('Course/Community users can create/upload PDF forms set to "off"').'</li>';
7501: }
7502: } elsif ($item eq 'anonsurvey_threshold') {
7503: $resulttext .= '<li>'.&mt('Responder count required for display of anonymous survey submissions set to [_1].',$defaultshash{'coursedefaults'}{'anonsurvey_threshold'}).'</li>';
7504: }
7505: }
7506: $resulttext .= '</ul>';
7507: } else {
7508: $resulttext = &mt('No changes made to course defaults');
7509: }
7510: } else {
7511: $resulttext = '<span class="LC_error">'.
7512: &mt('An error occurred: [_1]',$putresult).'</span>';
7513: }
7514: return $resulttext;
7515: }
7516:
7517: sub modify_usersessions {
7518: my ($dom,%domconfig) = @_;
7519: my @hostingtypes = ('version','excludedomain','includedomain');
7520: my @offloadtypes = ('primary','default');
7521: my %types = (
7522: remote => \@hostingtypes,
7523: hosted => \@hostingtypes,
7524: spares => \@offloadtypes,
7525: );
7526: my @prefixes = ('remote','hosted','spares');
7527: my @lcversions = &Apache::lonnet::all_loncaparevs();
7528: my (%by_ip,%by_location,@intdoms);
7529: &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
7530: my @locations = sort(keys(%by_location));
7531: my (%defaultshash,%changes);
7532: foreach my $prefix (@prefixes) {
7533: $defaultshash{'usersessions'}{$prefix} = {};
7534: }
7535: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
7536: my $resulttext;
7537: my %iphost = &Apache::lonnet::get_iphost();
7538: foreach my $prefix (@prefixes) {
7539: next if ($prefix eq 'spares');
7540: foreach my $type (@{$types{$prefix}}) {
7541: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
7542: if ($type eq 'version') {
7543: my $value = $env{'form.'.$prefix.'_'.$type};
7544: my $okvalue;
7545: if ($value ne '') {
7546: if (grep(/^\Q$value\E$/,@lcversions)) {
7547: $okvalue = $value;
7548: }
7549: }
7550: if (ref($domconfig{'usersessions'}) eq 'HASH') {
7551: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
7552: if ($domconfig{'usersessions'}{$prefix}{$type} ne '') {
7553: if ($inuse == 0) {
7554: $changes{$prefix}{$type} = 1;
7555: } else {
7556: if ($okvalue ne $domconfig{'usersessions'}{$prefix}{$type}) {
7557: $changes{$prefix}{$type} = 1;
7558: }
7559: if ($okvalue ne '') {
7560: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
7561: }
7562: }
7563: } else {
7564: if (($inuse == 1) && ($okvalue ne '')) {
7565: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
7566: $changes{$prefix}{$type} = 1;
7567: }
7568: }
7569: } else {
7570: if (($inuse == 1) && ($okvalue ne '')) {
7571: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
7572: $changes{$prefix}{$type} = 1;
7573: }
7574: }
7575: } else {
7576: if (($inuse == 1) && ($okvalue ne '')) {
7577: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
7578: $changes{$prefix}{$type} = 1;
7579: }
7580: }
7581: } else {
7582: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
7583: my @okvals;
7584: foreach my $val (@vals) {
7585: if ($val =~ /:/) {
7586: my @items = split(/:/,$val);
7587: foreach my $item (@items) {
7588: if (ref($by_location{$item}) eq 'ARRAY') {
7589: push(@okvals,$item);
7590: }
7591: }
7592: } else {
7593: if (ref($by_location{$val}) eq 'ARRAY') {
7594: push(@okvals,$val);
7595: }
7596: }
7597: }
7598: @okvals = sort(@okvals);
7599: if (ref($domconfig{'usersessions'}) eq 'HASH') {
7600: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
7601: if (ref($domconfig{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
7602: if ($inuse == 0) {
7603: $changes{$prefix}{$type} = 1;
7604: } else {
7605: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
7606: my @changed = &Apache::loncommon::compare_arrays($domconfig{'usersessions'}{$prefix}{$type},$defaultshash{'usersessions'}{$prefix}{$type});
7607: if (@changed > 0) {
7608: $changes{$prefix}{$type} = 1;
7609: }
7610: }
7611: } else {
7612: if ($inuse == 1) {
7613: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
7614: $changes{$prefix}{$type} = 1;
7615: }
7616: }
7617: } else {
7618: if ($inuse == 1) {
7619: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
7620: $changes{$prefix}{$type} = 1;
7621: }
7622: }
7623: } else {
7624: if ($inuse == 1) {
7625: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
7626: $changes{$prefix}{$type} = 1;
7627: }
7628: }
7629: }
7630: }
7631: }
7632:
7633: my @alldoms = &Apache::lonnet::all_domains();
7634: my %servers = &Apache::lonnet::internet_dom_servers($dom);
7635: my %spareid = ¤t_offloads_to($dom,$domconfig{'usersessions'},\%servers);
7636: my $savespares;
7637:
7638: foreach my $lonhost (sort(keys(%servers))) {
7639: my $serverhomeID =
7640: &Apache::lonnet::get_server_homeID($servers{$lonhost});
7641: my $serverhostname = &Apache::lonnet::hostname($lonhost);
7642: $defaultshash{'usersessions'}{'spares'}{$lonhost} = {};
7643: my %spareschg;
7644: foreach my $type (@{$types{'spares'}}) {
7645: my @okspares;
7646: my @checked = &Apache::loncommon::get_env_multiple('form.spare_'.$type.'_'.$lonhost);
7647: foreach my $server (@checked) {
7648: if (&Apache::lonnet::hostname($server) ne '') {
7649: unless (&Apache::lonnet::hostname($server) eq $serverhostname) {
7650: unless (grep(/^\Q$server\E$/,@okspares)) {
7651: push(@okspares,$server);
7652: }
7653: }
7654: }
7655: }
7656: my $new = $env{'form.newspare_'.$type.'_'.$lonhost};
7657: my $newspare;
7658: if (($new ne '') && (&Apache::lonnet::hostname($new))) {
7659: unless (&Apache::lonnet::hostname($new) eq $serverhostname) {
7660: $newspare = $new;
7661: }
7662: }
7663: my @spares;
7664: if (($newspare ne '') && (!grep(/^\Q$newspare\E$/,@okspares))) {
7665: @spares = sort(@okspares,$newspare);
7666: } else {
7667: @spares = sort(@okspares);
7668: }
7669: $defaultshash{'usersessions'}{'spares'}{$lonhost}{$type} = \@spares;
7670: if (ref($spareid{$lonhost}) eq 'HASH') {
7671: if (ref($spareid{$lonhost}{$type}) eq 'ARRAY') {
7672: my @diffs = &Apache::loncommon::compare_arrays($spareid{$lonhost}{$type},\@spares);
7673: if (@diffs > 0) {
7674: $spareschg{$type} = 1;
7675: }
7676: }
7677: }
7678: }
7679: if (keys(%spareschg) > 0) {
7680: $changes{'spares'}{$lonhost} = \%spareschg;
7681: }
7682: }
7683:
7684: if (ref($domconfig{'usersessions'}) eq 'HASH') {
7685: if (ref($domconfig{'usersessions'}{'spares'}) eq 'HASH') {
7686: if (ref($changes{'spares'}) eq 'HASH') {
7687: if (keys(%{$changes{'spares'}}) > 0) {
7688: $savespares = 1;
7689: }
7690: }
7691: } else {
7692: $savespares = 1;
7693: }
7694: }
7695:
7696: my $nochgmsg = &mt('No changes made to settings for user session hosting/offloading.');
7697: if ((keys(%changes) > 0) || ($savespares)) {
7698: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
7699: $dom);
7700: if ($putresult eq 'ok') {
7701: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
7702: if (ref($defaultshash{'usersessions'}{'remote'}) eq 'HASH') {
7703: $domdefaults{'remotesessions'} = $defaultshash{'usersessions'}{'remote'};
7704: }
7705: if (ref($defaultshash{'usersessions'}{'hosted'}) eq 'HASH') {
7706: $domdefaults{'hostedsessions'} = $defaultshash{'usersessions'}{'hosted'};
7707: }
7708: }
7709: my $cachetime = 24*60*60;
7710: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
7711: if (keys(%changes) > 0) {
7712: my %lt = &usersession_titles();
7713: $resulttext = &mt('Changes made:').'<ul>';
7714: foreach my $prefix (@prefixes) {
7715: if (ref($changes{$prefix}) eq 'HASH') {
7716: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
7717: if ($prefix eq 'spares') {
7718: if (ref($changes{$prefix}) eq 'HASH') {
7719: foreach my $lonhost (sort(keys(%{$changes{$prefix}}))) {
7720: $resulttext .= '<li><b>'.$lonhost.'</b> ';
7721: my $lonhostdom = &Apache::lonnet::host_domain($lonhost);
7722: &Apache::lonnet::remote_devalidate_cache($lonhost,'spares',$lonhostdom);
7723: if (ref($changes{$prefix}{$lonhost}) eq 'HASH') {
7724: foreach my $type (@{$types{$prefix}}) {
7725: if ($changes{$prefix}{$lonhost}{$type}) {
7726: my $offloadto = &mt('None');
7727: if (ref($defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}) eq 'ARRAY') {
7728: if (@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}} > 0) {
7729: $offloadto = join(', ',@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}});
7730: }
7731: }
7732: $resulttext .= &mt('[_1] set to: [_2].','<i>'.$lt{$type}.'</i>',$offloadto).(' 'x3);
7733: }
7734: }
7735: }
7736: $resulttext .= '</li>';
7737: }
7738: }
7739: } else {
7740: foreach my $type (@{$types{$prefix}}) {
7741: if (defined($changes{$prefix}{$type})) {
7742: my $newvalue;
7743: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
7744: if (ref($defaultshash{'usersessions'}{$prefix})) {
7745: if ($type eq 'version') {
7746: $newvalue = $defaultshash{'usersessions'}{$prefix}{$type};
7747: } elsif (ref($defaultshash{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
7748: if (@{$defaultshash{'usersessions'}{$prefix}{$type}} > 0) {
7749: $newvalue = join(', ',@{$defaultshash{'usersessions'}{$prefix}{$type}});
7750: }
7751: }
7752: }
7753: }
7754: if ($newvalue eq '') {
7755: if ($type eq 'version') {
7756: $resulttext .= '<li>'.&mt('[_1] set to: off',$lt{$type}).'</li>';
7757: } else {
7758: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
7759: }
7760: } else {
7761: if ($type eq 'version') {
7762: $newvalue .= ' '.&mt('(or later)');
7763: }
7764: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
7765: }
7766: }
7767: }
7768: }
7769: $resulttext .= '</ul>';
7770: }
7771: }
7772: $resulttext .= '</ul>';
7773: } else {
7774: $resulttext = $nochgmsg;
7775: }
7776: } else {
7777: $resulttext = '<span class="LC_error">'.
7778: &mt('An error occurred: [_1]',$putresult).'</span>';
7779: }
7780: } else {
7781: $resulttext = $nochgmsg;
7782: }
7783: return $resulttext;
7784: }
7785:
7786: sub modify_loadbalancing {
7787: my ($dom,%domconfig) = @_;
7788: my $primary_id = &Apache::lonnet::domain($dom,'primary');
7789: my $intdom = &Apache::lonnet::internet_dom($primary_id);
7790: my ($othertitle,$usertypes,$types) =
7791: &Apache::loncommon::sorted_inst_types($dom);
7792: my %servers = &Apache::lonnet::internet_dom_servers($dom);
7793: my @sparestypes = ('primary','default');
7794: my %typetitles = &sparestype_titles();
7795: my $resulttext;
7796: if (keys(%servers) > 1) {
7797: my ($currbalancer,$currtargets,$currrules);
7798: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
7799: $currbalancer = $domconfig{'loadbalancing'}{'lonhost'};
7800: $currtargets = $domconfig{'loadbalancing'}{'targets'};
7801: $currrules = $domconfig{'loadbalancing'}{'rules'};
7802: } else {
7803: ($currbalancer,$currtargets) =
7804: &Apache::lonnet::get_lonbalancer_config(\%servers);
7805: }
7806: my ($saveloadbalancing,%defaultshash,%changes);
7807: my ($alltypes,$othertypes,$titles) =
7808: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
7809: my %ruletitles = &offloadtype_text();
7810: my $balancer = $env{'form.loadbalancing_lonhost'};
7811: if (!$servers{$balancer}) {
7812: undef($balancer);
7813: }
7814: if ($currbalancer ne $balancer) {
7815: $changes{'lonhost'} = 1;
7816: }
7817: $defaultshash{'loadbalancing'}{'lonhost'} = $balancer;
7818: if ($balancer ne '') {
7819: unless (ref($domconfig{'loadbalancing'}) eq 'HASH') {
7820: $saveloadbalancing = 1;
7821: }
7822: foreach my $sparetype (@sparestypes) {
7823: my @targets = &Apache::loncommon::get_env_multiple('form.loadbalancing_target_'.$sparetype);
7824: my @offloadto;
7825: foreach my $target (@targets) {
7826: if (($servers{$target}) && ($target ne $balancer)) {
7827: if ($sparetype eq 'default') {
7828: if (ref($defaultshash{'loadbalancing'}{'targets'}{'primary'}) eq 'ARRAY') {
7829: next if (grep(/^\Q$target\E$/,@{$defaultshash{'loadbalancing'}{'targets'}{'primary'}}));
7830: }
7831: }
7832: unless(grep(/^\Q$target\E$/,@offloadto)) {
7833: push(@offloadto,$target);
7834: }
7835: }
7836: $defaultshash{'loadbalancing'}{'targets'}{$sparetype} = \@offloadto;
7837: }
7838: }
7839: } else {
7840: foreach my $sparetype (@sparestypes) {
7841: $defaultshash{'loadbalancing'}{'targets'}{$sparetype} = [];
7842: }
7843: }
7844: if (ref($currtargets) eq 'HASH') {
7845: foreach my $sparetype (@sparestypes) {
7846: if (ref($currtargets->{$sparetype}) eq 'ARRAY') {
7847: my @targetdiffs = &Apache::loncommon::compare_arrays($currtargets->{$sparetype},$defaultshash{'loadbalancing'}{'targets'}{$sparetype});
7848: if (@targetdiffs > 0) {
7849: $changes{'targets'} = 1;
7850: }
7851: } elsif (ref($defaultshash{'loadbalancing'}{'targets'}{$sparetype}) eq 'ARRAY') {
7852: if (@{$defaultshash{'loadbalancing'}{'targets'}{$sparetype}} > 0) {
7853: $changes{'targets'} = 1;
7854: }
7855: }
7856: }
7857: } else {
7858: foreach my $sparetype (@sparestypes) {
7859: if (ref($defaultshash{'loadbalancing'}{'targets'}{$sparetype}) eq 'ARRAY') {
7860: if (@{$defaultshash{'loadbalancing'}{'targets'}{$sparetype}} > 0) {
7861: $changes{'targets'} = 1;
7862: }
7863: }
7864: }
7865: }
7866: my $ishomedom;
7867: if ($balancer ne '') {
7868: if (&Apache::lonnet::host_domain($balancer) eq $dom) {
7869: $ishomedom = 1;
7870: }
7871: }
7872: if (ref($alltypes) eq 'ARRAY') {
7873: foreach my $type (@{$alltypes}) {
7874: my $rule;
7875: if ($balancer ne '') {
7876: unless ((($type eq '_LC_external') || ($type eq '_LC_internetdom')) &&
7877: (!$ishomedom)) {
7878: $rule = $env{'form.loadbalancing_rules_'.$type};
7879: }
7880: if ($rule eq 'specific') {
7881: $rule = $env{'form.loadbalancing_singleserver_'.$type};
7882: }
7883: }
7884: $defaultshash{'loadbalancing'}{'rules'}{$type} = $rule;
7885: if (ref($currrules) eq 'HASH') {
7886: if ($rule ne $currrules->{$type}) {
7887: $changes{'rules'}{$type} = 1;
7888: }
7889: } elsif ($rule ne '') {
7890: $changes{'rules'}{$type} = 1;
7891: }
7892: }
7893: }
7894: my $nochgmsg = &mt('No changes made to Load Balancer settings.');
7895: if ((keys(%changes) > 0) || ($saveloadbalancing)) {
7896: my $putresult = &Apache::lonnet::put_dom('configuration',
7897: \%defaultshash,$dom);
7898: if ($putresult eq 'ok') {
7899: if (keys(%changes) > 0) {
7900: if ($changes{'lonhost'}) {
7901: if ($currbalancer ne '') {
7902: &Apache::lonnet::remote_devalidate_cache($currbalancer,'loadbalancing',$dom);
7903: }
7904: if ($balancer eq '') {
7905: $resulttext .= '<li>'.&mt('Load Balancing with dedicated server discontinued').'</li>';
7906: } else {
7907: &Apache::lonnet::remote_devalidate_cache($balancer,'loadbalancing',$dom);
7908: $resulttext .= '<li>'.&mt('Dedicated Load Balancer server set to [_1]',$balancer);
7909: }
7910: } else {
7911: &Apache::lonnet::remote_devalidate_cache($balancer,'loadbalancing',$dom);
7912: }
7913: if (($changes{'targets'}) && ($balancer ne '')) {
7914: my %offloadstr;
7915: foreach my $sparetype (@sparestypes) {
7916: if (ref($defaultshash{'loadbalancing'}{'targets'}{$sparetype}) eq 'ARRAY') {
7917: if (@{$defaultshash{'loadbalancing'}{'targets'}{$sparetype}} > 0) {
7918: $offloadstr{$sparetype} = join(', ',@{$defaultshash{'loadbalancing'}{'targets'}{$sparetype}});
7919: }
7920: }
7921: }
7922: if (keys(%offloadstr) == 0) {
7923: $resulttext .= '<li>'.&mt("Servers to which Load Balance server offloads set to 'None', by default").'</li>';
7924: } else {
7925: my $showoffload;
7926: foreach my $sparetype (@sparestypes) {
7927: $showoffload .= '<i>'.$typetitles{$sparetype}.'</i>: ';
7928: if (defined($offloadstr{$sparetype})) {
7929: $showoffload .= $offloadstr{$sparetype};
7930: } else {
7931: $showoffload .= &mt('None');
7932: }
7933: $showoffload .= (' 'x3);
7934: }
7935: $resulttext .= '<li>'.&mt('By default, Load Balancer server set to offload to: [_1]',$showoffload).'</li>';
7936: }
7937: }
7938: if ((ref($changes{'rules'}) eq 'HASH') && ($balancer ne '')) {
7939: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
7940: foreach my $type (@{$alltypes}) {
7941: if ($changes{'rules'}{$type}) {
7942: my $rule = $defaultshash{'loadbalancing'}{'rules'}{$type};
7943: my $balancetext;
7944: if ($rule eq '') {
7945: $balancetext = $ruletitles{'default'};
7946: } elsif (($rule eq 'homeserver') || ($rule eq 'externalbalancer')) {
7947: $balancetext = $ruletitles{$rule};
7948: } else {
7949: $balancetext = &mt('offload to [_1]',$defaultshash{'loadbalancing'}{'rules'}{$type});
7950: }
7951: $resulttext .= '<li>'.&mt('Load Balancing for [_1] set to: [_2]',$titles->{$type},$balancetext).'</li>';
7952: }
7953: }
7954: }
7955: }
7956: if ($resulttext ne '') {
7957: $resulttext = &mt('Changes made:').'<ul>'.$resulttext.'</ul>';
7958: } else {
7959: $resulttext = $nochgmsg;
7960: }
7961: } else {
7962: $resulttext = $nochgmsg;
7963: if ($balancer ne '') {
7964: &Apache::lonnet::remote_devalidate_cache($balancer,'loadbalancing',$dom);
7965: }
7966: }
7967: } else {
7968: $resulttext = '<span class="LC_error">'.
7969: &mt('An error occurred: [_1]',$putresult).'</span>';
7970: }
7971: } else {
7972: $resulttext = $nochgmsg;
7973: }
7974: } else {
7975: $resulttext = &mt('Load Balancing unavailable as this domain only has one server.');
7976: }
7977: return $resulttext;
7978: }
7979:
7980: sub recurse_check {
7981: my ($chkcats,$categories,$depth,$name) = @_;
7982: if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
7983: my $chg = 0;
7984: for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
7985: my $category = $chkcats->[$depth]{$name}[$j];
7986: my $item;
7987: if ($category eq '') {
7988: $chg ++;
7989: } else {
7990: my $deeper = $depth + 1;
7991: $item = &escape($category).':'.&escape($name).':'.$depth;
7992: if ($chg) {
7993: $categories->{$item} -= $chg;
7994: }
7995: &recurse_check($chkcats,$categories,$deeper,$category);
7996: $deeper --;
7997: }
7998: }
7999: }
8000: return;
8001: }
8002:
8003: sub recurse_cat_deletes {
8004: my ($item,$coursecategories,$deletions) = @_;
8005: my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
8006: my $subdepth = $depth + 1;
8007: if (ref($coursecategories) eq 'HASH') {
8008: foreach my $subitem (keys(%{$coursecategories})) {
8009: my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
8010: if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
8011: delete($coursecategories->{$subitem});
8012: $deletions->{$subitem} = 1;
8013: &recurse_cat_deletes($subitem,$coursecategories,$deletions);
8014: }
8015: }
8016: }
8017: return;
8018: }
8019:
8020: sub get_active_dcs {
8021: my ($dom) = @_;
8022: my %dompersonnel = &Apache::lonnet::get_domain_roles($dom,['dc']);
8023: my %domcoords;
8024: my $numdcs = 0;
8025: my $now = time;
8026: foreach my $server (keys(%dompersonnel)) {
8027: foreach my $user (sort(keys(%{$dompersonnel{$server}}))) {
8028: my ($trole,$uname,$udom,$runame,$rudom,$rsec) = split(/:/,$user);
8029: my ($end,$start) = split(':',$dompersonnel{$server}{$user});
8030: if (($end eq '') || ($end == 0) || ($end > $now)) {
8031: if ($start <= $now) {
8032: $domcoords{$uname.':'.$udom} = $dompersonnel{$server}{$user};
8033: }
8034: }
8035: }
8036: }
8037: return %domcoords;
8038: }
8039:
8040: sub active_dc_picker {
8041: my ($dom,$curr_dc) = @_;
8042: my %domcoords = &get_active_dcs($dom);
8043: my @dcs = sort(keys(%domcoords));
8044: my $numdcs = scalar(@dcs);
8045: my $datatable;
8046: my $numinrow = 2;
8047: if ($numdcs > 1) {
8048: $datatable = '<table>';
8049: for (my $i=0; $i<@dcs; $i++) {
8050: my $rem = $i%($numinrow);
8051: if ($rem == 0) {
8052: if ($i > 0) {
8053: $datatable .= '</tr>';
8054: }
8055: $datatable .= '<tr>';
8056: }
8057: my $check = ' ';
8058: if ($curr_dc eq '') {
8059: if (!$i) {
8060: $check = ' checked="checked" ';
8061: }
8062: } elsif ($dcs[$i] eq $curr_dc) {
8063: $check = ' checked="checked" ';
8064: }
8065: if ($i == @dcs - 1) {
8066: my $colsleft = $numinrow - $rem;
8067: if ($colsleft > 1) {
8068: $datatable .= '<td colspan="'.$colsleft.'">';
8069: } else {
8070: $datatable .= '<td>';
8071: }
8072: } else {
8073: $datatable .= '<td>';
8074: }
8075: my ($dcname,$dcdom) = split(':',$dcs[$i]);
8076: $datatable .= '<span class="LC_nobreak"><label>'.
8077: '<input type="radio" name="autocreate_xmldc"'.
8078: ' value="'.$dcs[$i].'"'.$check.'/>'.
8079: &Apache::loncommon::plainname($dcname,$dcdom).
8080: '</label></span></td>';
8081: }
8082: $datatable .= '</tr></table>';
8083: } elsif (@dcs) {
8084: $datatable .= '<input type="hidden" name="autocreate_dc" value="'.
8085: $dcs[0].'" />';
8086: }
8087: return ($numdcs,$datatable);
8088: }
8089:
8090: sub usersession_titles {
8091: return &Apache::lonlocal::texthash(
8092: hosted => 'Hosting of sessions for users from other domains on servers in this domain',
8093: remote => 'Hosting of sessions for users in this domain on servers in other domains',
8094: spares => 'Servers offloaded to, when busy',
8095: version => 'LON-CAPA version requirement',
8096: excludedomain => 'Allow all, but exclude specific domains',
8097: includedomain => 'Deny all, but include specific domains',
8098: primary => 'Primary (checked first)',
8099: default => 'Default',
8100: );
8101: }
8102:
8103: sub id_for_thisdom {
8104: my (%servers) = @_;
8105: my %altids;
8106: foreach my $server (keys(%servers)) {
8107: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
8108: if ($serverhome ne $server) {
8109: $altids{$serverhome} = $server;
8110: }
8111: }
8112: return %altids;
8113: }
8114:
8115: sub count_servers {
8116: my ($currbalancer,%servers) = @_;
8117: my (@spares,$numspares);
8118: foreach my $lonhost (sort(keys(%servers))) {
8119: next if ($currbalancer eq $lonhost);
8120: push(@spares,$lonhost);
8121: }
8122: if ($currbalancer) {
8123: $numspares = scalar(@spares);
8124: } else {
8125: $numspares = scalar(@spares) - 1;
8126: }
8127: return ($numspares,@spares);
8128: }
8129:
8130: sub lonbalance_targets_js {
8131: my ($dom,$types,$servers) = @_;
8132: my $select = &mt('Select');
8133: my ($alltargets,$allishome,$allinsttypes,@alltypes);
8134: if (ref($servers) eq 'HASH') {
8135: $alltargets = join("','",sort(keys(%{$servers})));
8136: my @homedoms;
8137: foreach my $server (sort(keys(%{$servers}))) {
8138: if (&Apache::lonnet::host_domain($server) eq $dom) {
8139: push(@homedoms,'1');
8140: } else {
8141: push(@homedoms,'0');
8142: }
8143: }
8144: $allishome = join("','",@homedoms);
8145: }
8146: if (ref($types) eq 'ARRAY') {
8147: if (@{$types} > 0) {
8148: @alltypes = @{$types};
8149: }
8150: }
8151: push(@alltypes,'default','_LC_adv','_LC_author','_LC_internetdom','_LC_external');
8152: $allinsttypes = join("','",@alltypes);
8153: return <<"END";
8154:
8155: <script type="text/javascript">
8156: // <![CDATA[
8157:
8158: function toggleTargets() {
8159: var balancer = document.display.loadbalancing_lonhost.options[document.display.loadbalancing_lonhost.selectedIndex].value;
8160: if (balancer == '') {
8161: hideSpares();
8162: } else {
8163: var homedoms = new Array('$allishome');
8164: var ishomedom = homedoms[document.display.loadbalancing_lonhost.selectedIndex];
8165: showSpares(balancer,ishomedom);
8166: }
8167: return;
8168: }
8169:
8170: function showSpares(balancer,ishomedom) {
8171: var alltargets = new Array('$alltargets');
8172: var insttypes = new Array('$allinsttypes');
8173: var offloadtypes = new Array('primary','default');
8174:
8175: document.getElementById('loadbalancing_targets').style.display='block';
8176: document.getElementById('loadbalancing_disabled').style.display='none';
8177:
8178: for (var i=0; i<offloadtypes.length; i++) {
8179: var count = 0;
8180: for (var j=0; j<alltargets.length; j++) {
8181: if (alltargets[j] != balancer) {
8182: document.getElementById('loadbalancing_target_'+offloadtypes[i]+'_'+count).value = alltargets[j];
8183: document.getElementById('loadbalancing_targettxt_'+offloadtypes[i]+'_'+count).style.textAlign='left';
8184: document.getElementById('loadbalancing_targettxt_'+offloadtypes[i]+'_'+count).style.textFace='normal';
8185: document.getElementById('loadbalancing_targettxt_'+offloadtypes[i]+'_'+count).innerHTML = alltargets[j];
8186: count ++;
8187: }
8188: }
8189: }
8190: for (var k=0; k<insttypes.length; k++) {
8191: if ((insttypes[k] == '_LC_external') || (insttypes[k] == '_LC_internetdom')) {
8192: if (ishomedom == 1) {
8193: document.getElementById('balanceruletitle_'+insttypes[k]).style.display='block';
8194: document.getElementById('balancerule_'+insttypes[k]).style.display='block';
8195: } else {
8196: document.getElementById('balanceruletitle_'+insttypes[k]).style.display='none';
8197: document.getElementById('balancerule_'+insttypes[k]).style.display='none';
8198:
8199: }
8200: } else {
8201: document.getElementById('balanceruletitle_'+insttypes[k]).style.display='block';
8202: document.getElementById('balancerule_'+insttypes[k]).style.display='block';
8203: }
8204: if ((insttypes[k] != '_LC_external') &&
8205: ((insttypes[k] != '_LC_internetdom') ||
8206: ((insttypes[k] == '_LC_internetdom') && (ishomedom == 1)))) {
8207: document.getElementById('loadbalancing_singleserver_'+insttypes[k]).options[0] = new Option("","",true,true);
8208: for (var m=0; m<alltargets.length; m++) {
8209: var idx = m+1;
8210: if (alltargets[m] != balancer) {
8211: document.getElementById('loadbalancing_singleserver_'+insttypes[k]).options[idx] = new Option(alltargets[m],alltargets[m],false,false);
8212: }
8213: }
8214: }
8215: }
8216: return;
8217: }
8218:
8219: function hideSpares() {
8220: var alltargets = new Array('$alltargets');
8221: var insttypes = new Array('$allinsttypes');
8222: var offloadtypes = new Array('primary','default');
8223:
8224: document.getElementById('loadbalancing_targets').style.display='none';
8225: document.getElementById('loadbalancing_disabled').style.display='block';
8226:
8227: var total = alltargets.length - 1;
8228: for (var i=0; i<offloadtypes; i++) {
8229: for (var j=0; j<total; j++) {
8230: document.getElementById('loadbalancing_target_'+offloadtypes[i]+'_'+j).checked = false;
8231: document.getElementById('loadbalancing_target_'+offloadtypes[i]+'_'+j).value = '';
8232: document.getElementById('loadbalancing_targettxt_'+offloadtypes[i]+'_'+j).innerHTML = '';
8233: }
8234: }
8235: for (var k=0; k<insttypes.length; k++) {
8236: document.getElementById('balanceruletitle_'+insttypes[k]).style.display='none';
8237: document.getElementById('balancerule_'+insttypes[k]).style.display='none';
8238: if (insttypes[k] != '_LC_external') {
8239: document.getElementById('loadbalancing_singleserver_'+insttypes[k]).length = 0;
8240: document.getElementById('loadbalancing_singleserver_'+insttypes[k]).options[0] = new Option("","",true,true);
8241: }
8242: }
8243: return;
8244: }
8245:
8246: function checkOffloads(item,type) {
8247: var alltargets = new Array('$alltargets');
8248: var offloadtypes = new Array('primary','default');
8249: if (item.checked) {
8250: var total = alltargets.length - 1;
8251: var other;
8252: if (type == offloadtypes[0]) {
8253: other = offloadtypes[1];
8254: } else {
8255: other = offloadtypes[0];
8256: }
8257: for (var i=0; i<total; i++) {
8258: var server = document.getElementById('loadbalancing_target_'+other+'_'+i).value;
8259: if (server == item.value) {
8260: if (document.getElementById('loadbalancing_target_'+other+'_'+i).checked) {
8261: document.getElementById('loadbalancing_target_'+other+'_'+i).checked = false;
8262: }
8263: }
8264: }
8265: }
8266: return;
8267: }
8268:
8269: function singleServerToggle(type) {
8270: var offloadtoSelIdx = document.getElementById('loadbalancing_singleserver_'+type).selectedIndex;
8271: if (offloadtoSelIdx == 0) {
8272: document.getElementById('loadbalancing_rules_'+type+'_0').checked = true;
8273: document.getElementById('loadbalancing_singleserver_'+type).options[0].text = '';
8274:
8275: } else {
8276: document.getElementById('loadbalancing_rules_'+type+'_2').checked = true;
8277: document.getElementById('loadbalancing_singleserver_'+type).options[0].text = '$select';
8278: }
8279: return;
8280: }
8281:
8282: function balanceruleChange(formname,type) {
8283: if (type == '_LC_external') {
8284: return;
8285: }
8286: var typesRules = getIndicesByName(formname,'loadbalancing_rules_'+type);
8287: for (var i=0; i<typesRules.length; i++) {
8288: if (formname.elements[typesRules[i]].checked) {
8289: if (formname.elements[typesRules[i]].value != 'specific') {
8290: document.getElementById('loadbalancing_singleserver_'+type).selectedIndex = 0;
8291: document.getElementById('loadbalancing_singleserver_'+type).options[0].text = '';
8292: } else {
8293: document.getElementById('loadbalancing_singleserver_'+type).options[0].text = '$select';
8294: }
8295: }
8296: }
8297: return;
8298: }
8299:
8300: // ]]>
8301: </script>
8302:
8303: END
8304: }
8305:
8306: sub new_spares_js {
8307: my @sparestypes = ('primary','default');
8308: my $types = join("','",@sparestypes);
8309: my $select = &mt('Select');
8310: return <<"END";
8311:
8312: <script type="text/javascript">
8313: // <![CDATA[
8314:
8315: function updateNewSpares(formname,lonhost) {
8316: var types = new Array('$types');
8317: var include = new Array();
8318: var exclude = new Array();
8319: for (var i=0; i<types.length; i++) {
8320: var spareboxes = getIndicesByName(formname,'spare_'+types[i]+'_'+lonhost);
8321: for (var j=0; j<spareboxes.length; j++) {
8322: if (formname.elements[spareboxes[j]].checked) {
8323: exclude.push(formname.elements[spareboxes[j]].value);
8324: } else {
8325: include.push(formname.elements[spareboxes[j]].value);
8326: }
8327: }
8328: }
8329: for (var i=0; i<types.length; i++) {
8330: var newSpare = document.getElementById('newspare_'+types[i]+'_'+lonhost);
8331: var selIdx = newSpare.selectedIndex;
8332: var currnew = newSpare.options[selIdx].value;
8333: var okSpares = new Array();
8334: for (var j=0; j<newSpare.options.length; j++) {
8335: var possible = newSpare.options[j].value;
8336: if (possible != '') {
8337: if (exclude.indexOf(possible) == -1) {
8338: okSpares.push(possible);
8339: } else {
8340: if (currnew == possible) {
8341: selIdx = 0;
8342: }
8343: }
8344: }
8345: }
8346: for (var k=0; k<include.length; k++) {
8347: if (okSpares.indexOf(include[k]) == -1) {
8348: okSpares.push(include[k]);
8349: }
8350: }
8351: okSpares.sort();
8352: newSpare.options.length = 0;
8353: if (selIdx == 0) {
8354: newSpare.options[0] = new Option("$select","",true,true);
8355: } else {
8356: newSpare.options[0] = new Option("$select","",false,false);
8357: }
8358: for (var m=0; m<okSpares.length; m++) {
8359: var idx = m+1;
8360: var selThis = 0;
8361: if (selIdx != 0) {
8362: if (okSpares[m] == currnew) {
8363: selThis = 1;
8364: }
8365: }
8366: if (selThis == 1) {
8367: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],true,true);
8368: } else {
8369: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],false,false);
8370: }
8371: }
8372: }
8373: return;
8374: }
8375:
8376: function checkNewSpares(lonhost,type) {
8377: var newSpare = document.getElementById('newspare_'+type+'_'+lonhost);
8378: var chosen = newSpare.options[newSpare.selectedIndex].value;
8379: if (chosen != '') {
8380: var othertype;
8381: var othernewSpare;
8382: if (type == 'primary') {
8383: othernewSpare = document.getElementById('newspare_default_'+lonhost);
8384: }
8385: if (type == 'default') {
8386: othernewSpare = document.getElementById('newspare_primary_'+lonhost);
8387: }
8388: if (othernewSpare.options[othernewSpare.selectedIndex].value == chosen) {
8389: othernewSpare.selectedIndex = 0;
8390: }
8391: }
8392: return;
8393: }
8394:
8395: // ]]>
8396: </script>
8397:
8398: END
8399:
8400: }
8401:
8402: sub common_domprefs_js {
8403: return <<"END";
8404:
8405: <script type="text/javascript">
8406: // <![CDATA[
8407:
8408: function getIndicesByName(formname,item) {
8409: var group = new Array();
8410: for (var i=0;i<formname.elements.length;i++) {
8411: if (formname.elements[i].name == item) {
8412: group.push(formname.elements[i].id);
8413: }
8414: }
8415: return group;
8416: }
8417:
8418: // ]]>
8419: </script>
8420:
8421: END
8422:
8423: }
8424:
8425: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>