1: # The LearningOnline Network with CAPA
2: # Handler to set domain-wide configuration settings
3: #
4: # $Id: domainprefs.pm,v 1.160.6.3 2012/05/30 16:51:34 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 (either quotas
90: or requestcourses).
91:
92: The print_quotas routine was orginally created to display/store information
93: about default quota sizes for portfolio spaces for the different types of
94: institutional affiliation in the domain (e.g., Faculty, Staff, Student etc.),
95: but is now also used to manage availability of user tools:
96: i.e., blogs, aboutme page, and portfolios, and the course request tool,
97: used by course owners to request creation of a course.
98:
99: Outputs: 1
100:
101: $datatable - HTML containing form elements which allow settings to be changed.
102:
103: In the case of course requests, radio buttons are displayed for each institutional
104: affiliate type (and also default, and _LC_adv) for each of the course types
105: (official, unofficial and community). In each case the radio buttons allow the
106: selection of one of four values:
107:
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','usersessions',
214: 'loadbalancing'],$dom);
215: my @prefs_order = ('rolecolors','login','defaults','quotas','autoenroll',
216: 'autoupdate','autocreate','directorysrch','contacts',
217: 'usercreation','usermodification','scantron',
218: 'requestcourses','coursecategories','serverstatuses',
219: 'usersessions');
220: if (keys(%servers) > 1) {
221: push(@prefs_order,'loadbalancing');
222: }
223: my %prefs = (
224: 'rolecolors' =>
225: { text => 'Default color schemes',
226: help => 'Domain_Configuration_Color_Schemes',
227: header => [{col1 => 'Student Settings',
228: col2 => '',},
229: {col1 => 'Coordinator Settings',
230: col2 => '',},
231: {col1 => 'Author Settings',
232: col2 => '',},
233: {col1 => 'Administrator Settings',
234: col2 => '',}],
235: },
236: 'login' =>
237: { text => 'Log-in page options',
238: help => 'Domain_Configuration_Login_Page',
239: header => [{col1 => 'Item',
240: col2 => '',}],
241: },
242:
243: 'defaults' =>
244: { text => 'Default authentication/language/timezone/portal',
245: help => 'Domain_Configuration_LangTZAuth',
246: header => [{col1 => 'Setting',
247: col2 => 'Value'}],
248: },
249: 'quotas' =>
250: { text => 'User blogs, personal information pages, portfolios',
251: help => 'Domain_Configuration_Quotas',
252: header => [{col1 => 'User affiliation',
253: col2 => 'Available tools',
254: col3 => 'Portfolio quota',}],
255: },
256: 'autoenroll' =>
257: { text => 'Auto-enrollment settings',
258: help => 'Domain_Configuration_Auto_Enrollment',
259: header => [{col1 => 'Configuration setting',
260: col2 => 'Value(s)'}],
261: },
262: 'autoupdate' =>
263: { text => 'Auto-update settings',
264: help => 'Domain_Configuration_Auto_Updates',
265: header => [{col1 => 'Setting',
266: col2 => 'Value',},
267: {col1 => 'Setting',
268: col2 => 'Affiliation'},
269: {col1 => 'User population',
270: col2 => 'Updateable user data'}],
271: },
272: 'autocreate' =>
273: { text => 'Auto-course creation settings',
274: help => 'Domain_Configuration_Auto_Creation',
275: header => [{col1 => 'Configuration Setting',
276: col2 => 'Value',}],
277: },
278: 'directorysrch' =>
279: { text => 'Institutional directory searches',
280: help => 'Domain_Configuration_InstDirectory_Search',
281: header => [{col1 => 'Setting',
282: col2 => 'Value',}],
283: },
284: 'contacts' =>
285: { text => 'Contact Information',
286: help => 'Domain_Configuration_Contact_Info',
287: header => [{col1 => 'Setting',
288: col2 => 'Value',}],
289: },
290:
291: 'usercreation' =>
292: { text => 'User creation',
293: help => 'Domain_Configuration_User_Creation',
294: header => [{col1 => 'Format rule type',
295: col2 => 'Format rules in force'},
296: {col1 => 'User account creation',
297: col2 => 'Usernames which may be created',},
298: {col1 => 'Context',
299: col2 => 'Assignable authentication types'}],
300: },
301: 'usermodification' =>
302: { text => 'User modification',
303: help => 'Domain_Configuration_User_Modification',
304: header => [{col1 => 'Target user has role',
305: col2 => 'User information updateable in author context'},
306: {col1 => 'Target user has role',
307: col2 => 'User information updateable in course context'},
308: {col1 => "Status of user",
309: col2 => 'Information settable when self-creating account (if directory data blank)'}],
310: },
311: 'scantron' =>
312: { text => 'Bubblesheet format file',
313: help => 'Domain_Configuration_Scantron_Format',
314: header => [ {col1 => 'Item',
315: col2 => '',
316: }],
317: },
318: 'requestcourses' =>
319: {text => 'Request creation of courses',
320: help => 'Domain_Configuration_Request_Courses',
321: header => [{col1 => 'User affiliation',
322: col2 => 'Availability/Processing of requests',},
323: {col1 => 'Setting',
324: col2 => 'Value'}],
325: },
326: 'coursecategories' =>
327: { text => 'Cataloging of courses/communities',
328: help => 'Domain_Configuration_Cataloging_Courses',
329: header => [{col1 => 'Category settings',
330: col2 => '',},
331: {col1 => 'Categories',
332: col2 => '',
333: }],
334: },
335: 'serverstatuses' =>
336: {text => 'Access to server status pages',
337: help => 'Domain_Configuration_Server_Status',
338: header => [{col1 => 'Status Page',
339: col2 => 'Other named users',
340: col3 => 'Specific IPs',
341: }],
342: },
343: 'usersessions' =>
344: {text => 'User session hosting/offloading',
345: help => 'Domain_Configuration_User_Sessions',
346: header => [{col1 => 'Domain server',
347: col2 => 'Servers to offload sessions to when busy'},
348: {col1 => 'Hosting of users from other domains',
349: col2 => 'Rules'},
350: {col1 => "Hosting domain's own users elsewhere",
351: col2 => 'Rules'}],
352: },
353: 'loadbalancing' =>
354: {text => 'Dedicated Load Balancer',
355: help => 'Domain_Configuration_Load_Balancing',
356: header => [{col1 => 'Server',
357: col2 => 'Default destinations',
358: col3 => 'User affliation',
359: col4 => 'Overrides'},
360: ],
361: },
362: );
363: if (keys(%servers) > 1) {
364: $prefs{'login'} = { text => 'Log-in page options',
365: help => 'Domain_Configuration_Login_Page',
366: header => [{col1 => 'Log-in Service',
367: col2 => 'Server Setting',},
368: {col1 => 'Log-in Page Items',
369: col2 => ''}],
370: };
371: }
372: my @roles = ('student','coordinator','author','admin');
373: my @actions = &Apache::loncommon::get_env_multiple('form.actions');
374: &Apache::lonhtmlcommon::add_breadcrumb
375: ({href=>"javascript:changePage(document.$phase,'pickactions')",
376: text=>"Settings to display/modify"});
377: my $confname = $dom.'-domainconfig';
378: if ($phase eq 'process') {
379: &Apache::lonconfigsettings::make_changes($r,$dom,$phase,$context,\@prefs_order,\%prefs,\%domconfig,$confname,\@roles);
380: } elsif ($phase eq 'display') {
381: my $js;
382: if (keys(%servers) > 1) {
383: my ($othertitle,$usertypes,$types) =
384: &Apache::loncommon::sorted_inst_types($dom);
385: $js = &lonbalance_targets_js($dom,$types,\%servers).
386: &new_spares_js().
387: &common_domprefs_js().
388: &Apache::loncommon::javascript_array_indexof();
389: }
390: &Apache::lonconfigsettings::display_settings($r,$dom,$phase,$context,\@prefs_order,\%prefs,\%domconfig,$confname,$js);
391: } else {
392: if (keys(%domconfig) == 0) {
393: my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
394: my @ids=&Apache::lonnet::current_machine_ids();
395: if (!grep(/^\Q$primarylibserv\E$/,@ids)) {
396: my %designhash = &Apache::loncommon::get_domainconf($dom);
397: my @loginimages = ('img','logo','domlogo','login');
398: my $custom_img_count = 0;
399: foreach my $img (@loginimages) {
400: if ($designhash{$dom.'.login.'.$img} ne '') {
401: $custom_img_count ++;
402: }
403: }
404: foreach my $role (@roles) {
405: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
406: $custom_img_count ++;
407: }
408: }
409: if ($custom_img_count > 0) {
410: &Apache::lonconfigsettings::print_header($r,$phase,$context);
411: my $switch_server = &check_switchserver($dom,$confname);
412: $r->print(
413: &mt('Domain configuration settings have yet to be saved for this domain via the web-based domain preferences interface.').'<br />'.
414: &mt("While this remains so, you must switch to the domain's primary library server in order to update settings.").'<br /><br />'.
415: &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 />'.
416: &mt("However, you will still need to switch to the domain's primary library server to upload new images or logos.").'<br /><br />');
417: if ($switch_server) {
418: $r->print($switch_server.' '.&mt('to primary library server for domain: [_1]',$dom));
419: }
420: $r->print(&Apache::loncommon::end_page());
421: return OK;
422: }
423: }
424: }
425: &Apache::lonconfigsettings::display_choices($r,$phase,$context,\@prefs_order,\%prefs);
426: }
427: return OK;
428: }
429:
430: sub process_changes {
431: my ($r,$dom,$confname,$action,$roles,$values) = @_;
432: my %domconfig;
433: if (ref($values) eq 'HASH') {
434: %domconfig = %{$values};
435: }
436: my $output;
437: if ($action eq 'login') {
438: $output = &modify_login($r,$dom,$confname,%domconfig);
439: } elsif ($action eq 'rolecolors') {
440: $output = &modify_rolecolors($r,$dom,$confname,$roles,
441: %domconfig);
442: } elsif ($action eq 'quotas') {
443: $output = &modify_quotas($dom,$action,%domconfig);
444: } elsif ($action eq 'autoenroll') {
445: $output = &modify_autoenroll($dom,%domconfig);
446: } elsif ($action eq 'autoupdate') {
447: $output = &modify_autoupdate($dom,%domconfig);
448: } elsif ($action eq 'autocreate') {
449: $output = &modify_autocreate($dom,%domconfig);
450: } elsif ($action eq 'directorysrch') {
451: $output = &modify_directorysrch($dom,%domconfig);
452: } elsif ($action eq 'usercreation') {
453: $output = &modify_usercreation($dom,%domconfig);
454: } elsif ($action eq 'usermodification') {
455: $output = &modify_usermodification($dom,%domconfig);
456: } elsif ($action eq 'contacts') {
457: $output = &modify_contacts($dom,%domconfig);
458: } elsif ($action eq 'defaults') {
459: $output = &modify_defaults($dom,$r);
460: } elsif ($action eq 'scantron') {
461: $output = &modify_scantron($r,$dom,$confname,%domconfig);
462: } elsif ($action eq 'coursecategories') {
463: $output = &modify_coursecategories($dom,%domconfig);
464: } elsif ($action eq 'serverstatuses') {
465: $output = &modify_serverstatuses($dom,%domconfig);
466: } elsif ($action eq 'requestcourses') {
467: $output = &modify_quotas($dom,$action,%domconfig);
468: } elsif ($action eq 'usersessions') {
469: $output = &modify_usersessions($dom,%domconfig);
470: } elsif ($action eq 'loadbalancing') {
471: $output = &modify_loadbalancing($dom,%domconfig);
472: }
473: return $output;
474: }
475:
476: sub print_config_box {
477: my ($r,$dom,$confname,$phase,$action,$item,$settings) = @_;
478: my $rowtotal = 0;
479: my $output;
480: if ($action eq 'coursecategories') {
481: $output = &coursecategories_javascript($settings);
482: }
483: $output .=
484: '<table class="LC_nested_outer">
485: <tr>
486: <th align="left" valign="middle"><span class="LC_nobreak">'.
487: &mt($item->{text}).' '.
488: &Apache::loncommon::help_open_topic($item->{'help'}).'</span></th>'."\n".
489: '</tr>';
490: $rowtotal ++;
491: my $numheaders = 1;
492: if (ref($item->{'header'}) eq 'ARRAY') {
493: $numheaders = scalar(@{$item->{'header'}});
494: }
495: if ($numheaders > 1) {
496: my $colspan = '';
497: my $rightcolspan = '';
498: if (($action eq 'rolecolors') || ($action eq 'coursecategories') || ($action eq 'helpsettings')) {
499: $colspan = ' colspan="2"';
500: }
501: if ($action eq 'usersessions') {
502: $rightcolspan = ' colspan="3"';
503: }
504: $output .= '
505: <tr>
506: <td>
507: <table class="LC_nested">
508: <tr class="LC_info_row">
509: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[0]->{'col1'}).'</td>
510: <td class="LC_right_item"'.$rightcolspan.'>'.&mt($item->{'header'}->[0]->{'col2'}).'</td>
511: </tr>';
512: $rowtotal ++;
513: if ($action eq 'autoupdate') {
514: $output .= &print_autoupdate('top',$dom,$settings,\$rowtotal);
515: } elsif ($action eq 'usercreation') {
516: $output .= &print_usercreation('top',$dom,$settings,\$rowtotal);
517: } elsif ($action eq 'usermodification') {
518: $output .= &print_usermodification('top',$dom,$settings,\$rowtotal);
519: } elsif ($action eq 'coursecategories') {
520: $output .= &print_coursecategories('top',$dom,$item,$settings,\$rowtotal);
521: } elsif ($action eq 'login') {
522: $output .= &print_login('top',$dom,$confname,$phase,$settings,\$rowtotal);
523: $colspan = ' colspan="2"';
524: } elsif ($action eq 'requestcourses') {
525: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
526: } elsif ($action eq 'usersessions') {
527: $output .= &print_usersessions('top',$dom,$settings,\$rowtotal);
528: } elsif ($action eq 'rolecolors') {
529: $output .= &print_rolecolors($phase,'student',$dom,$confname,$settings,\$rowtotal);
530: }
531: $output .= '
532: </table>
533: </td>
534: </tr>
535: <tr>
536: <td>
537: <table class="LC_nested">
538: <tr class="LC_info_row">
539: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col1'}).'</td>';
540: $output .= '
541: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col2'}).'</td>
542: </tr>';
543: $rowtotal ++;
544: if ($action eq 'autoupdate') {
545: $output .= &print_autoupdate('middle',$dom,$settings,\$rowtotal).'
546: </table>
547: </td>
548: </tr>
549: <tr>
550: <td>
551: <table class="LC_nested">
552: <tr class="LC_info_row">
553: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
554: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
555: &print_autoupdate('bottom',$dom,$settings,\$rowtotal);
556: $rowtotal ++;
557: } elsif ($action eq 'usercreation') {
558: $output .= &print_usercreation('middle',$dom,$settings,\$rowtotal).'
559: </table>
560: </td>
561: </tr>
562: <tr>
563: <td>
564: <table class="LC_nested">
565: <tr class="LC_info_row">
566: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
567: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
568: &print_usercreation('bottom',$dom,$settings,\$rowtotal);
569: $rowtotal ++;
570: } elsif ($action eq 'usermodification') {
571: $output .= &print_usermodification('middle',$dom,$settings,\$rowtotal).'
572: </table>
573: </td>
574: </tr>
575: <tr>
576: <td>
577: <table class="LC_nested">
578: <tr class="LC_info_row">
579: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
580: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
581: &print_usermodification('bottom',$dom,$settings,\$rowtotal);
582: $rowtotal ++;
583: } elsif ($action eq 'coursecategories') {
584: $output .= &print_coursecategories('bottom',$dom,$item,$settings,\$rowtotal);
585: } elsif ($action eq 'login') {
586: $output .= &print_login('bottom',$dom,$confname,$phase,$settings,\$rowtotal);
587: } elsif ($action eq 'requestcourses') {
588: $output .= &print_courserequestmail($dom,$settings,\$rowtotal);
589: } elsif ($action eq 'helpsettings') {
590: $output .= &print_helpsettings('bottom',$dom,$confname,$settings,\$rowtotal);
591: } elsif ($action eq 'usersessions') {
592: $output .= &print_usersessions('middle',$dom,$settings,\$rowtotal).'
593: </table>
594: </td>
595: </tr>
596: <tr>
597: <td>
598: <table class="LC_nested">
599: <tr class="LC_info_row">
600: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
601: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
602: &print_usersessions('bottom',$dom,$settings,\$rowtotal);
603: $rowtotal ++;
604: } elsif ($action eq 'coursedefaults') {
605: $output .= &print_coursedefaults('bottom',$dom,$settings,\$rowtotal);
606: } elsif ($action eq 'rolecolors') {
607: $output .= &print_rolecolors($phase,'coordinator',$dom,$confname,$settings,\$rowtotal).'
608: </table>
609: </td>
610: </tr>
611: <tr>
612: <td>
613: <table class="LC_nested">
614: <tr class="LC_info_row">
615: <td class="LC_left_item"'.$colspan.' valign="top">'.
616: &mt($item->{'header'}->[2]->{'col1'}).'</td>
617: <td class="LC_right_item" valign="top">'.
618: &mt($item->{'header'}->[2]->{'col2'}).'</td>
619: </tr>'.
620: &print_rolecolors($phase,'author',$dom,$confname,$settings,\$rowtotal).'
621: </table>
622: </td>
623: </tr>
624: <tr>
625: <td>
626: <table class="LC_nested">
627: <tr class="LC_info_row">
628: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
629: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
630: </tr>'.
631: &print_rolecolors($phase,'admin',$dom,$confname,$settings,\$rowtotal);
632: $rowtotal += 2;
633: }
634: } else {
635: $output .= '
636: <tr>
637: <td>
638: <table class="LC_nested">
639: <tr class="LC_info_row">';
640: if (($action eq 'login') || ($action eq 'directorysrch')) {
641: $output .= '
642: <td class="LC_left_item" colspan="2">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
643: } elsif ($action eq 'serverstatuses') {
644: $output .= '
645: <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).
646: '<br />('.&mt('Automatic access for Dom. Coords.').')</td>';
647:
648: } else {
649: $output .= '
650: <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
651: }
652: if (defined($item->{'header'}->[0]->{'col3'})) {
653: $output .= '<td class="LC_left_item" valign="top">'.
654: &mt($item->{'header'}->[0]->{'col2'});
655: if ($action eq 'serverstatuses') {
656: $output .= '<br />(<tt>'.&mt('user1:domain1,user2:domain2 etc.').'</tt>)';
657: }
658: } else {
659: $output .= '<td class="LC_right_item" valign="top">'.
660: &mt($item->{'header'}->[0]->{'col2'});
661: }
662: $output .= '</td>';
663: if ($item->{'header'}->[0]->{'col3'}) {
664: if (defined($item->{'header'}->[0]->{'col4'})) {
665: $output .= '<td class="LC_left_item" valign="top">'.
666: &mt($item->{'header'}->[0]->{'col3'});
667: } else {
668: $output .= '<td class="LC_right_item" valign="top">'.
669: &mt($item->{'header'}->[0]->{'col3'});
670: }
671: if ($action eq 'serverstatuses') {
672: $output .= '<br />(<tt>'.&mt('IP1,IP2 etc.').'</tt>)';
673: }
674: $output .= '</td>';
675: }
676: if ($item->{'header'}->[0]->{'col4'}) {
677: $output .= '<td class="LC_right_item" valign="top">'.
678: &mt($item->{'header'}->[0]->{'col4'});
679: }
680: $output .= '</tr>';
681: $rowtotal ++;
682: if ($action eq 'login') {
683: $output .= &print_login('bottom',$dom,$confname,$phase,$settings,
684: \$rowtotal);
685: } elsif ($action eq 'quotas') {
686: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
687: } elsif ($action eq 'autoenroll') {
688: $output .= &print_autoenroll($dom,$settings,\$rowtotal);
689: } elsif ($action eq 'autocreate') {
690: $output .= &print_autocreate($dom,$settings,\$rowtotal);
691: } elsif ($action eq 'directorysrch') {
692: $output .= &print_directorysrch($dom,$settings,\$rowtotal);
693: } elsif ($action eq 'contacts') {
694: $output .= &print_contacts($dom,$settings,\$rowtotal);
695: } elsif ($action eq 'defaults') {
696: $output .= &print_defaults($dom,\$rowtotal);
697: } elsif ($action eq 'scantron') {
698: $output .= &print_scantronformat($r,$dom,$confname,$settings,\$rowtotal);
699: } elsif ($action eq 'serverstatuses') {
700: $output .= &print_serverstatuses($dom,$settings,\$rowtotal);
701: } elsif ($action eq 'helpsettings') {
702: $output .= &print_helpsettings('top',$dom,$confname,$settings,\$rowtotal);
703: } elsif ($action eq 'loadbalancing') {
704: $output .= &print_loadbalancing($dom,$settings,\$rowtotal);
705: }
706: }
707: $output .= '
708: </table>
709: </td>
710: </tr>
711: </table><br />';
712: return ($output,$rowtotal);
713: }
714:
715: sub print_login {
716: my ($position,$dom,$confname,$phase,$settings,$rowtotal) = @_;
717: my ($css_class,$datatable);
718: my %choices = &login_choices();
719:
720: if ($position eq 'top') {
721: my %servers = &Apache::lonnet::internet_dom_servers($dom);
722: my $choice = $choices{'disallowlogin'};
723: $css_class = ' class="LC_odd_row"';
724: $datatable .= '<tr'.$css_class.'><td>'.$choice.'</td>'.
725: '<td align="right"><table><tr><th>'.$choices{'hostid'}.'</th>'.
726: '<th>'.$choices{'server'}.'</th>'.
727: '<th>'.$choices{'serverpath'}.'</th>'.
728: '<th>'.$choices{'custompath'}.'</th>'.
729: '<th><span class="LC_nobreak">'.$choices{'exempt'}.'</span></th></tr>'."\n";
730: my %disallowed;
731: if (ref($settings) eq 'HASH') {
732: if (ref($settings->{'loginvia'}) eq 'HASH') {
733: %disallowed = %{$settings->{'loginvia'}};
734: }
735: }
736: foreach my $lonhost (sort(keys(%servers))) {
737: my $direct = 'selected="selected"';
738: if (ref($disallowed{$lonhost}) eq 'HASH') {
739: if ($disallowed{$lonhost}{'server'} ne '') {
740: $direct = '';
741: }
742: }
743: $datatable .= '<tr><td>'.$servers{$lonhost}.'</td>'.
744: '<td><select name="'.$lonhost.'_server">'.
745: '<option value=""'.$direct.'>'.$choices{'directlogin'}.
746: '</option>';
747: foreach my $hostid (keys(%servers)) {
748: next if ($servers{$hostid} eq $servers{$lonhost});
749: my $selected = '';
750: if (ref($disallowed{$lonhost}) eq 'HASH') {
751: if ($hostid eq $disallowed{$lonhost}{'server'}) {
752: $selected = 'selected="selected"';
753: }
754: }
755: $datatable .= '<option value="'.$hostid.'"'.$selected.'>'.
756: $servers{$hostid}.'</option>';
757: }
758: $datatable .= '</select></td>'.
759: '<td><select name="'.$lonhost.'_serverpath">';
760: foreach my $path ('','/','/adm/login','/adm/roles','custom') {
761: my $pathname = $path;
762: if ($path eq 'custom') {
763: $pathname = &mt('Custom Path').' ->';
764: }
765: my $selected = '';
766: if (ref($disallowed{$lonhost}) eq 'HASH') {
767: if ($path eq $disallowed{$lonhost}{'serverpath'}) {
768: $selected = 'selected="selected"';
769: }
770: } elsif ($path eq '') {
771: $selected = 'selected="selected"';
772: }
773: $datatable .= '<option value="'.$path.'"'.$selected.'>'.$pathname.'</option>';
774: }
775: $datatable .= '</select></td>';
776: my ($custom,$exempt);
777: if (ref($disallowed{$lonhost}) eq 'HASH') {
778: $custom = $disallowed{$lonhost}{'custompath'};
779: $exempt = $disallowed{$lonhost}{'exempt'};
780: }
781: $datatable .= '<td><input type="text" name="'.$lonhost.'_custompath" size="6" value="'.$custom.'" /></td>'.
782: '<td><input type="text" name="'.$lonhost.'_exempt" size="8" value="'.$exempt.'" /></td>'.
783: '</tr>';
784: }
785: $datatable .= '</table></td></tr>';
786: return $datatable;
787: }
788:
789: my %defaultchecked = (
790: 'coursecatalog' => 'on',
791: 'adminmail' => 'off',
792: 'newuser' => 'off',
793: );
794: my @toggles = ('coursecatalog','adminmail','newuser');
795: my (%checkedon,%checkedoff);
796: foreach my $item (@toggles) {
797: if ($defaultchecked{$item} eq 'on') {
798: $checkedon{$item} = ' checked="checked" ';
799: $checkedoff{$item} = ' ';
800: } elsif ($defaultchecked{$item} eq 'off') {
801: $checkedoff{$item} = ' checked="checked" ';
802: $checkedon{$item} = ' ';
803: }
804: }
805: my @images = ('img','logo','domlogo','login');
806: my @logintext = ('textcol','bgcol');
807: my @bgs = ('pgbg','mainbg','sidebg');
808: my @links = ('link','alink','vlink');
809: my %designhash = &Apache::loncommon::get_domainconf($dom);
810: my %defaultdesign = %Apache::loncommon::defaultdesign;
811: my (%is_custom,%designs);
812: my %defaults = (
813: font => $defaultdesign{'login.font'},
814: );
815: foreach my $item (@images) {
816: $defaults{$item} = $defaultdesign{'login.'.$item};
817: $defaults{'showlogo'}{$item} = 1;
818: }
819: foreach my $item (@bgs) {
820: $defaults{'bgs'}{$item} = $defaultdesign{'login.'.$item};
821: }
822: foreach my $item (@logintext) {
823: $defaults{'logintext'}{$item} = $defaultdesign{'login.'.$item};
824: }
825: foreach my $item (@links) {
826: $defaults{'links'}{$item} = $defaultdesign{'login.'.$item};
827: }
828: if (ref($settings) eq 'HASH') {
829: foreach my $item (@toggles) {
830: if ($settings->{$item} eq '1') {
831: $checkedon{$item} = ' checked="checked" ';
832: $checkedoff{$item} = ' ';
833: } elsif ($settings->{$item} eq '0') {
834: $checkedoff{$item} = ' checked="checked" ';
835: $checkedon{$item} = ' ';
836: }
837: }
838: foreach my $item (@images) {
839: if (defined($settings->{$item})) {
840: $designs{$item} = $settings->{$item};
841: $is_custom{$item} = 1;
842: }
843: if (defined($settings->{'showlogo'}{$item})) {
844: $designs{'showlogo'}{$item} = $settings->{'showlogo'}{$item};
845: }
846: }
847: foreach my $item (@logintext) {
848: if ($settings->{$item} ne '') {
849: $designs{'logintext'}{$item} = $settings->{$item};
850: $is_custom{$item} = 1;
851: }
852: }
853: if ($settings->{'font'} ne '') {
854: $designs{'font'} = $settings->{'font'};
855: $is_custom{'font'} = 1;
856: }
857: foreach my $item (@bgs) {
858: if ($settings->{$item} ne '') {
859: $designs{'bgs'}{$item} = $settings->{$item};
860: $is_custom{$item} = 1;
861: }
862: }
863: foreach my $item (@links) {
864: if ($settings->{$item} ne '') {
865: $designs{'links'}{$item} = $settings->{$item};
866: $is_custom{$item} = 1;
867: }
868: }
869: } else {
870: if ($designhash{$dom.'.login.font'} ne '') {
871: $designs{'font'} = $designhash{$dom.'.login.font'};
872: $is_custom{'font'} = 1;
873: }
874: foreach my $item (@images) {
875: if ($designhash{$dom.'.login.'.$item} ne '') {
876: $designs{$item} = $designhash{$dom.'.login.'.$item};
877: $is_custom{$item} = 1;
878: }
879: }
880: foreach my $item (@bgs) {
881: if ($designhash{$dom.'.login.'.$item} ne '') {
882: $designs{'bgs'}{$item} = $designhash{$dom.'.login.'.$item};
883: $is_custom{$item} = 1;
884: }
885: }
886: foreach my $item (@links) {
887: if ($designhash{$dom.'.login.'.$item} ne '') {
888: $designs{'links'}{$item} = $designhash{$dom.'.login.'.$item};
889: $is_custom{$item} = 1;
890: }
891: }
892: }
893: my %alt_text = &Apache::lonlocal::texthash ( img => 'Log-in banner',
894: logo => 'Institution Logo',
895: domlogo => 'Domain Logo',
896: login => 'Login box');
897: my $itemcount = 1;
898: foreach my $item (@toggles) {
899: $css_class = $itemcount%2?' class="LC_odd_row"':'';
900: $datatable .=
901: '<tr'.$css_class.'><td colspan="2">'.$choices{$item}.
902: '</td><td>'.
903: '<span class="LC_nobreak"><label><input type="radio" name="'.
904: $item.'"'.$checkedon{$item}.' value="1" />'.&mt('Yes').
905: '</label> <label><input type="radio" name="'.$item.'"'.
906: $checkedoff{$item}.' value="0" />'.&mt('No').'</label></span></td>'.
907: '</tr>';
908: $itemcount ++;
909: }
910: $datatable .= &display_color_options($dom,$confname,$phase,'login',$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal,\@logintext);
911: $datatable .= '</tr></table></td></tr>';
912: return $datatable;
913: }
914:
915: sub login_choices {
916: my %choices =
917: &Apache::lonlocal::texthash (
918: coursecatalog => 'Display Course/Community Catalog link?',
919: adminmail => "Display Administrator's E-mail Address?",
920: disallowlogin => "Login page requests redirected",
921: hostid => "Server",
922: server => "Redirect to:",
923: serverpath => "Path",
924: custompath => "Custom",
925: exempt => "Exempt IP(s)",
926: directlogin => "No redirect",
927: newuser => "Link to create a user account",
928: img => "Header",
929: logo => "Main Logo",
930: domlogo => "Domain Logo",
931: login => "Log-in Header",
932: textcol => "Text color",
933: bgcol => "Box color",
934: bgs => "Background colors",
935: links => "Link colors",
936: font => "Font color",
937: pgbg => "Header",
938: mainbg => "Page",
939: sidebg => "Login box",
940: link => "Link",
941: alink => "Active link",
942: vlink => "Visited link",
943: );
944: return %choices;
945: }
946:
947: sub print_rolecolors {
948: my ($phase,$role,$dom,$confname,$settings,$rowtotal) = @_;
949: my %choices = &color_font_choices();
950: my @bgs = ('pgbg','tabbg','sidebg');
951: my @links = ('link','alink','vlink');
952: my @images = ('img');
953: my %alt_text = &Apache::lonlocal::texthash(img => "Banner for $role role");
954: my %designhash = &Apache::loncommon::get_domainconf($dom);
955: my %defaultdesign = %Apache::loncommon::defaultdesign;
956: my (%is_custom,%designs);
957: my %defaults = (
958: img => $defaultdesign{$role.'.img'},
959: font => $defaultdesign{$role.'.font'},
960: fontmenu => $defaultdesign{$role.'.fontmenu'},
961: );
962: foreach my $item (@bgs) {
963: $defaults{'bgs'}{$item} = $defaultdesign{$role.'.'.$item};
964: }
965: foreach my $item (@links) {
966: $defaults{'links'}{$item} = $defaultdesign{$role.'.'.$item};
967: }
968: if (ref($settings) eq 'HASH') {
969: if (ref($settings->{$role}) eq 'HASH') {
970: if ($settings->{$role}->{'img'} ne '') {
971: $designs{'img'} = $settings->{$role}->{'img'};
972: $is_custom{'img'} = 1;
973: }
974: if ($settings->{$role}->{'font'} ne '') {
975: $designs{'font'} = $settings->{$role}->{'font'};
976: $is_custom{'font'} = 1;
977: }
978: if ($settings->{$role}->{'fontmenu'} ne '') {
979: $designs{'fontmenu'} = $settings->{$role}->{'fontmenu'};
980: $is_custom{'fontmenu'} = 1;
981: }
982: foreach my $item (@bgs) {
983: if ($settings->{$role}->{$item} ne '') {
984: $designs{'bgs'}{$item} = $settings->{$role}->{$item};
985: $is_custom{$item} = 1;
986: }
987: }
988: foreach my $item (@links) {
989: if ($settings->{$role}->{$item} ne '') {
990: $designs{'links'}{$item} = $settings->{$role}->{$item};
991: $is_custom{$item} = 1;
992: }
993: }
994: }
995: } else {
996: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
997: $designs{img} = $designhash{$dom.'.'.$role.'.img'};
998: $is_custom{'img'} = 1;
999: }
1000: if ($designhash{$dom.'.'.$role.'.fontmenu'} ne '') {
1001: $designs{fontmenu} = $designhash{$dom.'.'.$role.'.fontmenu'};
1002: $is_custom{'fontmenu'} = 1;
1003: }
1004: if ($designhash{$dom.'.'.$role.'.font'} ne '') {
1005: $designs{font} = $designhash{$dom.'.'.$role.'.font'};
1006: $is_custom{'font'} = 1;
1007: }
1008: foreach my $item (@bgs) {
1009: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1010: $designs{'bgs'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1011: $is_custom{$item} = 1;
1012:
1013: }
1014: }
1015: foreach my $item (@links) {
1016: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1017: $designs{'links'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1018: $is_custom{$item} = 1;
1019: }
1020: }
1021: }
1022: my $itemcount = 1;
1023: my $datatable = &display_color_options($dom,$confname,$phase,$role,$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal);
1024: $datatable .= '</tr></table></td></tr>';
1025: return $datatable;
1026: }
1027:
1028: sub display_color_options {
1029: my ($dom,$confname,$phase,$role,$itemcount,$choices,$is_custom,$defaults,$designs,
1030: $images,$bgs,$links,$alt_text,$rowtotal,$logintext) = @_;
1031: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1032: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1033: my $datatable = '<tr'.$css_class.'>'.
1034: '<td>'.$choices->{'font'}.'</td>';
1035: if (!$is_custom->{'font'}) {
1036: $datatable .= '<td>'.&mt('Default in use:').' <span id="css_default_'.$role.'_font" style="color: '.$defaults->{'font'}.';">'.$defaults->{'font'}.'</span></td>';
1037: } else {
1038: $datatable .= '<td> </td>';
1039: }
1040: my $fontlink = &color_pick($phase,$role,'font',$choices->{'font'},$designs->{'font'});
1041: $datatable .= '<td><span class="LC_nobreak">'.
1042: '<input type="text" size="10" name="'.$role.'_font"'.
1043: ' value="'.$designs->{'font'}.'" /> '.$fontlink.
1044: ' <span id="css_'.$role.'_font" style="background-color: '.
1045: $designs->{'font'}.';"> </span>'.
1046: '</span></td></tr>';
1047: unless ($role eq 'login') {
1048: $datatable .= '<tr'.$css_class.'>'.
1049: '<td>'.$choices->{'fontmenu'}.'</td>';
1050: if (!$is_custom->{'fontmenu'}) {
1051: $datatable .= '<td>'.&mt('Default in use:').' <span id="css_default_'.$role.'_font" style="color: '.$defaults->{'fontmenu'}.';">'.$defaults->{'fontmenu'}.'</span></td>';
1052: } else {
1053: $datatable .= '<td> </td>';
1054: }
1055: $fontlink = &color_pick($phase,$role,'fontmenu',$choices->{'fontmenu'},$designs->{'fontmenu'});
1056: $datatable .= '<td><span class="LC_nobreak">'.
1057: '<input type="text" size="10" name="'.$role.'_fontmenu"'.
1058: ' value="'.$designs->{'fontmenu'}.'" /> '.$fontlink.
1059: ' <span id="css_'.$role.'_fontmenu" style="background-color: '.
1060: $designs->{'fontmenu'}.';"> </span>'.
1061: '</span></td></tr>';
1062: }
1063: my $switchserver = &check_switchserver($dom,$confname);
1064: foreach my $img (@{$images}) {
1065: $itemcount ++;
1066: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1067: $datatable .= '<tr'.$css_class.'>'.
1068: '<td>'.$choices->{$img};
1069: my ($imgfile,$img_import,$login_hdr_pick,$logincolors);
1070: if ($role eq 'login') {
1071: if ($img eq 'login') {
1072: $login_hdr_pick =
1073: &login_header_options($img,$role,$defaults,$is_custom,$choices);
1074: $logincolors =
1075: &login_text_colors($img,$role,$logintext,$phase,$choices,
1076: $designs);
1077: } elsif ($img ne 'domlogo') {
1078: $datatable.= &logo_display_options($img,$defaults,$designs);
1079: }
1080: }
1081: $datatable .= '</td>';
1082: if ($designs->{$img} ne '') {
1083: $imgfile = $designs->{$img};
1084: $img_import = ($imgfile =~ m{^/adm/});
1085: } else {
1086: $imgfile = $defaults->{$img};
1087: }
1088: if ($imgfile) {
1089: my ($showfile,$fullsize);
1090: if ($imgfile =~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
1091: my $urldir = $1;
1092: my $filename = $2;
1093: my @info = &Apache::lonnet::stat_file($designs->{$img});
1094: if (@info) {
1095: my $thumbfile = 'tn-'.$filename;
1096: my @thumb=&Apache::lonnet::stat_file($urldir.'/'.$thumbfile);
1097: if (@thumb) {
1098: $showfile = $urldir.'/'.$thumbfile;
1099: } else {
1100: $showfile = $imgfile;
1101: }
1102: } else {
1103: $showfile = '';
1104: }
1105: } elsif ($imgfile =~ m-^/(adm/[^/]+)/([^/]+)$-) {
1106: $showfile = $imgfile;
1107: my $imgdir = $1;
1108: my $filename = $2;
1109: if (-e "$londocroot/$imgdir/tn-".$filename) {
1110: $showfile = "/$imgdir/tn-".$filename;
1111: } else {
1112: my $input = $londocroot.$imgfile;
1113: my $output = "$londocroot/$imgdir/tn-".$filename;
1114: if (!-e $output) {
1115: my ($width,$height) = &thumb_dimensions();
1116: my ($fullwidth,$fullheight) = &check_dimensions($input);
1117: if ($fullwidth ne '' && $fullheight ne '') {
1118: if ($fullwidth > $width && $fullheight > $height) {
1119: my $size = $width.'x'.$height;
1120: system("convert -sample $size $input $output");
1121: $showfile = "/$imgdir/tn-".$filename;
1122: }
1123: }
1124: }
1125: }
1126: }
1127: if ($showfile) {
1128: if ($showfile =~ m{^/(adm|res)/}) {
1129: if ($showfile =~ m{^/res/}) {
1130: my $local_showfile =
1131: &Apache::lonnet::filelocation('',$showfile);
1132: &Apache::lonnet::repcopy($local_showfile);
1133: }
1134: $showfile = &Apache::loncommon::lonhttpdurl($showfile);
1135: }
1136: if ($imgfile) {
1137: if ($imgfile =~ m{^/(adm|res)/}) {
1138: if ($imgfile =~ m{^/res/}) {
1139: my $local_imgfile =
1140: &Apache::lonnet::filelocation('',$imgfile);
1141: &Apache::lonnet::repcopy($local_imgfile);
1142: }
1143: $fullsize = &Apache::loncommon::lonhttpdurl($imgfile);
1144: } else {
1145: $fullsize = $imgfile;
1146: }
1147: }
1148: $datatable .= '<td>';
1149: if ($img eq 'login') {
1150: $datatable .= $login_hdr_pick;
1151: }
1152: $datatable .= &image_changes($is_custom->{$img},$alt_text->{$img},$img_import,
1153: $showfile,$fullsize,$role,$img,$imgfile,$logincolors);
1154: } else {
1155: $datatable .= '<td colspan="2" class="LC_right_item"><br />'.
1156: &mt('Upload:');
1157: }
1158: } else {
1159: $datatable .= '<td colspan="2" class="LC_right_item"><br />'.
1160: &mt('Upload:');
1161: }
1162: if ($switchserver) {
1163: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1164: } else {
1165: if ($img ne 'login') { # suppress file selection for Log-in header
1166: $datatable .=' <input type="file" name="'.$role.'_'.$img.'" />';
1167: }
1168: }
1169: $datatable .= '</td></tr>';
1170: }
1171: $itemcount ++;
1172: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1173: $datatable .= '<tr'.$css_class.'>'.
1174: '<td>'.$choices->{'bgs'}.'</td>';
1175: my $bgs_def;
1176: foreach my $item (@{$bgs}) {
1177: if (!$is_custom->{$item}) {
1178: $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>';
1179: }
1180: }
1181: if ($bgs_def) {
1182: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$bgs_def.'</tr></table></td>';
1183: } else {
1184: $datatable .= '<td> </td>';
1185: }
1186: $datatable .= '<td class="LC_right_item">'.
1187: '<table border="0"><tr>';
1188: foreach my $item (@{$bgs}) {
1189: my $link = &color_pick($phase,$role,$item,$choices->{$item},$designs->{'bgs'}{$item});
1190: $datatable .= '<td align="center">'.$link;
1191: if ($designs->{'bgs'}{$item}) {
1192: $datatable .= ' <span id="css_'.$role.'_'.$item.'" style="background-color: '.$designs->{'bgs'}{$item}.';"> </span>';
1193: }
1194: $datatable .= '<br /><input type="text" size="8" name="'.$role.'_'.$item.'" value="'.$designs->{'bgs'}{$item}.
1195: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1196: }
1197: $datatable .= '</tr></table></td></tr>';
1198: $itemcount ++;
1199: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1200: $datatable .= '<tr'.$css_class.'>'.
1201: '<td>'.$choices->{'links'}.'</td>';
1202: my $links_def;
1203: foreach my $item (@{$links}) {
1204: if (!$is_custom->{$item}) {
1205: $links_def .= '<td>'.$choices->{$item}.'<br /><span id="css_default_'.$role.'_'.$item.'" style="color: '.$defaults->{'links'}{$item}.';">'.$defaults->{'links'}{$item}.'</span></td>';
1206: }
1207: }
1208: if ($links_def) {
1209: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$links_def.'</tr></table></td>';
1210: } else {
1211: $datatable .= '<td> </td>';
1212: }
1213: $datatable .= '<td class="LC_right_item">'.
1214: '<table border="0"><tr>';
1215: foreach my $item (@{$links}) {
1216: $datatable .= '<td align="center">'."\n".
1217: &color_pick($phase,$role,$item,$choices->{$item},
1218: $designs->{'links'}{$item});
1219: if ($designs->{'links'}{$item}) {
1220: $datatable.=' <span id="css_'.$role.'_'.$item.'" style="background-color: '.$designs->{'links'}{$item}.';"> </span>';
1221: }
1222: $datatable .= '<br /><input type="text" size="8" name="'.$role.'_'.$item.'" value="'.$designs->{'links'}{$item}.
1223: '" /></td>';
1224: }
1225: $$rowtotal += $itemcount;
1226: return $datatable;
1227: }
1228:
1229: sub logo_display_options {
1230: my ($img,$defaults,$designs) = @_;
1231: my $checkedon;
1232: if (ref($defaults) eq 'HASH') {
1233: if (ref($defaults->{'showlogo'}) eq 'HASH') {
1234: if ($defaults->{'showlogo'}{$img}) {
1235: $checkedon = 'checked="checked" ';
1236: }
1237: }
1238: }
1239: if (ref($designs) eq 'HASH') {
1240: if (ref($designs->{'showlogo'}) eq 'HASH') {
1241: if (defined($designs->{'showlogo'}{$img})) {
1242: if ($designs->{'showlogo'}{$img} == 0) {
1243: $checkedon = '';
1244: } elsif ($designs->{'showlogo'}{$img} == 1) {
1245: $checkedon = 'checked="checked" ';
1246: }
1247: }
1248: }
1249: }
1250: return '<br /><label> <input type="checkbox" name="'.
1251: 'login_showlogo_'.$img.'" value="1" '.$checkedon.'/>'.
1252: &mt('show').'</label>'."\n";
1253: }
1254:
1255: sub login_header_options {
1256: my ($img,$role,$defaults,$is_custom,$choices) = @_;
1257: my $output = '';
1258: if ((!$is_custom->{'textcol'}) || (!$is_custom->{'bgcol'})) {
1259: $output .= &mt('Text default(s):').'<br />';
1260: if (!$is_custom->{'textcol'}) {
1261: $output .= $choices->{'textcol'}.': '.$defaults->{'logintext'}{'textcol'}.
1262: ' ';
1263: }
1264: if (!$is_custom->{'bgcol'}) {
1265: $output .= $choices->{'bgcol'}.': '.
1266: '<span id="css_'.$role.'_font" style="background-color: '.
1267: $defaults->{'logintext'}{'bgcol'}.';"> </span>';
1268: }
1269: $output .= '<br />';
1270: }
1271: $output .='<br />';
1272: return $output;
1273: }
1274:
1275: sub login_text_colors {
1276: my ($img,$role,$logintext,$phase,$choices,$designs) = @_;
1277: my $color_menu = '<table border="0"><tr>';
1278: foreach my $item (@{$logintext}) {
1279: my $link = &color_pick($phase,$role,$item,$choices->{$item},$designs->{'logintext'}{$item});
1280: $color_menu .= '<td align="center">'.$link;
1281: if ($designs->{'logintext'}{$item}) {
1282: $color_menu .= ' <span id="css_'.$role.'_'.$item.'" style="background-color: '.$designs->{'logintext'}{$item}.';"> </span>';
1283: }
1284: $color_menu .= '<br /><input type="text" size="8" name="'.$role.'_'.$item.'" value="'.
1285: $designs->{'logintext'}{$item}.'" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>'.
1286: '<td> </td>';
1287: }
1288: $color_menu .= '</tr></table><br />';
1289: return $color_menu;
1290: }
1291:
1292: sub image_changes {
1293: my ($is_custom,$alt_text,$img_import,$showfile,$fullsize,$role,$img,$imgfile,$logincolors) = @_;
1294: my $output;
1295: if ($img eq 'login') {
1296: # suppress image for Log-in header
1297: } elsif (!$is_custom) {
1298: if ($img ne 'domlogo') {
1299: $output .= &mt('Default image:').'<br />';
1300: } else {
1301: $output .= &mt('Default in use:').'<br />';
1302: }
1303: }
1304: if ($img eq 'login') { # suppress image for Log-in header
1305: $output .= '<td>'.$logincolors;
1306: } else {
1307: if ($img_import) {
1308: $output .= '<input type="hidden" name="'.$role.'_import_'.$img.'" value="'.$imgfile.'" />';
1309: }
1310: $output .= '<a href="'.$fullsize.'" target="_blank"><img src="'.
1311: $showfile.'" alt="'.$alt_text.'" border="0" /></a></td>';
1312: if ($is_custom) {
1313: $output .= '<td>'.$logincolors.'<span class="LC_nobreak"><label>'.
1314: '<input type="checkbox" name="'.
1315: $role.'_del_'.$img.'" value="1" />'.&mt('Delete?').
1316: '</label> '.&mt('Replace:').'</span><br />';
1317: } else {
1318: $output .= '<td valign="bottom">'.$logincolors.&mt('Upload:').'<br />';
1319: }
1320: }
1321: return $output;
1322: }
1323:
1324: sub color_pick {
1325: my ($phase,$role,$item,$desc,$curcol) = @_;
1326: my $link = '<a href="javascript:pjump('."'color_custom','".$desc.
1327: "','".$curcol."','".$role.'_'.$item."','parmform.pres','psub'".
1328: ');">'.$desc.'</a>';
1329: return $link;
1330: }
1331:
1332: sub print_quotas {
1333: my ($dom,$settings,$rowtotal,$action) = @_;
1334: my $context;
1335: if ($action eq 'quotas') {
1336: $context = 'tools';
1337: } else {
1338: $context = $action;
1339: }
1340: my ($datatable,$defaultquota,@usertools,@options,%validations);
1341: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1342: my $typecount = 0;
1343: my ($css_class,%titles);
1344: if ($context eq 'requestcourses') {
1345: @usertools = ('official','unofficial','community');
1346: @options =('norequest','approval','validate','autolimit');
1347: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
1348: %titles = &courserequest_titles();
1349: } else {
1350: @usertools = ('aboutme','blog','portfolio');
1351: %titles = &tool_titles();
1352: }
1353: if (ref($types) eq 'ARRAY') {
1354: foreach my $type (@{$types}) {
1355: my $currdefquota;
1356: unless ($context eq 'requestcourses') {
1357: if (ref($settings) eq 'HASH') {
1358: if (ref($settings->{defaultquota}) eq 'HASH') {
1359: $currdefquota = $settings->{defaultquota}->{$type};
1360: } else {
1361: $currdefquota = $settings->{$type};
1362: }
1363: }
1364: }
1365: if (defined($usertypes->{$type})) {
1366: $typecount ++;
1367: $css_class = $typecount%2?' class="LC_odd_row"':'';
1368: $datatable .= '<tr'.$css_class.'>'.
1369: '<td>'.$usertypes->{$type}.'</td>'.
1370: '<td class="LC_left_item">';
1371: if ($context eq 'requestcourses') {
1372: $datatable .= '<table><tr>';
1373: }
1374: my %cell;
1375: foreach my $item (@usertools) {
1376: if ($context eq 'requestcourses') {
1377: my ($curroption,$currlimit);
1378: if (ref($settings) eq 'HASH') {
1379: if (ref($settings->{$item}) eq 'HASH') {
1380: $curroption = $settings->{$item}->{$type};
1381: if ($curroption =~ /^autolimit=(\d*)$/) {
1382: $currlimit = $1;
1383: }
1384: }
1385: }
1386: if (!$curroption) {
1387: $curroption = 'norequest';
1388: }
1389: $datatable .= '<th>'.$titles{$item}.'</th>';
1390: foreach my $option (@options) {
1391: my $val = $option;
1392: if ($option eq 'norequest') {
1393: $val = 0;
1394: }
1395: if ($option eq 'validate') {
1396: my $canvalidate = 0;
1397: if (ref($validations{$item}) eq 'HASH') {
1398: if ($validations{$item}{$type}) {
1399: $canvalidate = 1;
1400: }
1401: }
1402: next if (!$canvalidate);
1403: }
1404: my $checked = '';
1405: if ($option eq $curroption) {
1406: $checked = ' checked="checked"';
1407: } elsif ($option eq 'autolimit') {
1408: if ($curroption =~ /^autolimit/) {
1409: $checked = ' checked="checked"';
1410: }
1411: }
1412: $cell{$item} .= '<span class="LC_nobreak"><label>'.
1413: '<input type="radio" name="crsreq_'.$item.
1414: '_'.$type.'" value="'.$val.'"'.$checked.' />'.
1415: $titles{$option}.'</label>';
1416: if ($option eq 'autolimit') {
1417: $cell{$item} .= ' <input type="text" name="crsreq_'.
1418: $item.'_limit_'.$type.'" size="1" '.
1419: 'value="'.$currlimit.'" />';
1420: }
1421: $cell{$item} .= '</span> ';
1422: if ($option eq 'autolimit') {
1423: $cell{$item} .= $titles{'unlimited'};
1424: }
1425: }
1426: } else {
1427: my $checked = 'checked="checked" ';
1428: if (ref($settings) eq 'HASH') {
1429: if (ref($settings->{$item}) eq 'HASH') {
1430: if ($settings->{$item}->{$type} == 0) {
1431: $checked = '';
1432: } elsif ($settings->{$item}->{$type} == 1) {
1433: $checked = 'checked="checked" ';
1434: }
1435: }
1436: }
1437: $datatable .= '<span class="LC_nobreak"><label>'.
1438: '<input type="checkbox" name="'.$context.'_'.$item.
1439: '" value="'.$type.'" '.$checked.'/>'.$titles{$item}.
1440: '</label></span> ';
1441: }
1442: }
1443: if ($context eq 'requestcourses') {
1444: $datatable .= '</tr><tr>';
1445: foreach my $item (@usertools) {
1446: $datatable .= '<td style="vertical-align: top">'.$cell{$item}.'</td>';
1447: }
1448: $datatable .= '</tr></table>';
1449: }
1450: $datatable .= '</td>';
1451: unless ($context eq 'requestcourses') {
1452: $datatable .=
1453: '<td class="LC_right_item"><span class="LC_nobreak">'.
1454: '<input type="text" name="quota_'.$type.
1455: '" value="'.$currdefquota.
1456: '" size="5" /> Mb</span></td>';
1457: }
1458: $datatable .= '</tr>';
1459: }
1460: }
1461: }
1462: unless ($context eq 'requestcourses') {
1463: $defaultquota = '20';
1464: if (ref($settings) eq 'HASH') {
1465: if (ref($settings->{'defaultquota'}) eq 'HASH') {
1466: $defaultquota = $settings->{'defaultquota'}->{'default'};
1467: } elsif (defined($settings->{'default'})) {
1468: $defaultquota = $settings->{'default'};
1469: }
1470: }
1471: }
1472: $typecount ++;
1473: $css_class = $typecount%2?' class="LC_odd_row"':'';
1474: $datatable .= '<tr'.$css_class.'>'.
1475: '<td>'.$othertitle.'</td>'.
1476: '<td class="LC_left_item">';
1477: if ($context eq 'requestcourses') {
1478: $datatable .= '<table><tr>';
1479: }
1480: my %defcell;
1481: foreach my $item (@usertools) {
1482: if ($context eq 'requestcourses') {
1483: my ($curroption,$currlimit);
1484: if (ref($settings) eq 'HASH') {
1485: if (ref($settings->{$item}) eq 'HASH') {
1486: $curroption = $settings->{$item}->{'default'};
1487: if ($curroption =~ /^autolimit=(\d*)$/) {
1488: $currlimit = $1;
1489: }
1490: }
1491: }
1492: if (!$curroption) {
1493: $curroption = 'norequest';
1494: }
1495: $datatable .= '<th>'.$titles{$item}.'</th>';
1496: foreach my $option (@options) {
1497: my $val = $option;
1498: if ($option eq 'norequest') {
1499: $val = 0;
1500: }
1501: if ($option eq 'validate') {
1502: my $canvalidate = 0;
1503: if (ref($validations{$item}) eq 'HASH') {
1504: if ($validations{$item}{'default'}) {
1505: $canvalidate = 1;
1506: }
1507: }
1508: next if (!$canvalidate);
1509: }
1510: my $checked = '';
1511: if ($option eq $curroption) {
1512: $checked = ' checked="checked"';
1513: } elsif ($option eq 'autolimit') {
1514: if ($curroption =~ /^autolimit/) {
1515: $checked = ' checked="checked"';
1516: }
1517: }
1518: $defcell{$item} .= '<span class="LC_nobreak"><label>'.
1519: '<input type="radio" name="crsreq_'.$item.
1520: '_default" value="'.$val.'"'.$checked.' />'.
1521: $titles{$option}.'</label>';
1522: if ($option eq 'autolimit') {
1523: $defcell{$item} .= ' <input type="text" name="crsreq_'.
1524: $item.'_limit_default" size="1" '.
1525: 'value="'.$currlimit.'" />';
1526: }
1527: $defcell{$item} .= '</span> ';
1528: if ($option eq 'autolimit') {
1529: $defcell{$item} .= $titles{'unlimited'};
1530: }
1531: }
1532: } else {
1533: my $checked = 'checked="checked" ';
1534: if (ref($settings) eq 'HASH') {
1535: if (ref($settings->{$item}) eq 'HASH') {
1536: if ($settings->{$item}->{'default'} == 0) {
1537: $checked = '';
1538: } elsif ($settings->{$item}->{'default'} == 1) {
1539: $checked = 'checked="checked" ';
1540: }
1541: }
1542: }
1543: $datatable .= '<span class="LC_nobreak"><label>'.
1544: '<input type="checkbox" name="'.$context.'_'.$item.
1545: '" value="default" '.$checked.'/>'.$titles{$item}.
1546: '</label></span> ';
1547: }
1548: }
1549: if ($context eq 'requestcourses') {
1550: $datatable .= '</tr><tr>';
1551: foreach my $item (@usertools) {
1552: $datatable .= '<td style="vertical-align: top">'.$defcell{$item}.'</td>';
1553: }
1554: $datatable .= '</tr></table>';
1555: }
1556: $datatable .= '</td>';
1557: unless ($context eq 'requestcourses') {
1558: $datatable .= '<td class="LC_right_item"><span class="LC_nobreak">'.
1559: '<input type="text" name="defaultquota" value="'.
1560: $defaultquota.'" size="5" /> Mb</span></td>';
1561: }
1562: $datatable .= '</tr>';
1563: $typecount ++;
1564: $css_class = $typecount%2?' class="LC_odd_row"':'';
1565: $datatable .= '<tr'.$css_class.'>'.
1566: '<td>'.&mt('LON-CAPA Advanced Users').' ';
1567: if ($context eq 'requestcourses') {
1568: $datatable .= &mt('(overrides affiliation, if set)').
1569: '</td>'.
1570: '<td class="LC_left_item">'.
1571: '<table><tr>';
1572: } else {
1573: $datatable .= &mt('(overrides affiliation, if checked)').
1574: '</td>'.
1575: '<td class="LC_left_item" colspan="2">'.
1576: '<br />';
1577: }
1578: my %advcell;
1579: foreach my $item (@usertools) {
1580: if ($context eq 'requestcourses') {
1581: my ($curroption,$currlimit);
1582: if (ref($settings) eq 'HASH') {
1583: if (ref($settings->{$item}) eq 'HASH') {
1584: $curroption = $settings->{$item}->{'_LC_adv'};
1585: if ($curroption =~ /^autolimit=(\d*)$/) {
1586: $currlimit = $1;
1587: }
1588: }
1589: }
1590: $datatable .= '<th>'.$titles{$item}.'</th>';
1591: my $checked = '';
1592: if ($curroption eq '') {
1593: $checked = ' checked="checked"';
1594: }
1595: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
1596: '<input type="radio" name="crsreq_'.$item.
1597: '__LC_adv" value=""'.$checked.' />'.
1598: &mt('No override set').'</label></span> ';
1599: foreach my $option (@options) {
1600: my $val = $option;
1601: if ($option eq 'norequest') {
1602: $val = 0;
1603: }
1604: if ($option eq 'validate') {
1605: my $canvalidate = 0;
1606: if (ref($validations{$item}) eq 'HASH') {
1607: if ($validations{$item}{'_LC_adv'}) {
1608: $canvalidate = 1;
1609: }
1610: }
1611: next if (!$canvalidate);
1612: }
1613: my $checked = '';
1614: if ($val eq $curroption) {
1615: $checked = ' checked="checked"';
1616: } elsif ($option eq 'autolimit') {
1617: if ($curroption =~ /^autolimit/) {
1618: $checked = ' checked="checked"';
1619: }
1620: }
1621: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
1622: '<input type="radio" name="crsreq_'.$item.
1623: '__LC_adv" value="'.$val.'"'.$checked.' />'.
1624: $titles{$option}.'</label>';
1625: if ($option eq 'autolimit') {
1626: $advcell{$item} .= ' <input type="text" name="crsreq_'.
1627: $item.'_limit__LC_adv" size="1" '.
1628: 'value="'.$currlimit.'" />';
1629: }
1630: $advcell{$item} .= '</span> ';
1631: if ($option eq 'autolimit') {
1632: $advcell{$item} .= $titles{'unlimited'};
1633: }
1634: }
1635: } else {
1636: my $checked = 'checked="checked" ';
1637: if (ref($settings) eq 'HASH') {
1638: if (ref($settings->{$item}) eq 'HASH') {
1639: if ($settings->{$item}->{'_LC_adv'} == 0) {
1640: $checked = '';
1641: } elsif ($settings->{$item}->{'_LC_adv'} == 1) {
1642: $checked = 'checked="checked" ';
1643: }
1644: }
1645: }
1646: $datatable .= '<span class="LC_nobreak"><label>'.
1647: '<input type="checkbox" name="'.$context.'_'.$item.
1648: '" value="_LC_adv" '.$checked.'/>'.$titles{$item}.
1649: '</label></span> ';
1650: }
1651: }
1652: if ($context eq 'requestcourses') {
1653: $datatable .= '</tr><tr>';
1654: foreach my $item (@usertools) {
1655: $datatable .= '<td style="vertical-align: top">'.$advcell{$item}.'</td>';
1656: }
1657: $datatable .= '</tr></table>';
1658: }
1659: $datatable .= '</td></tr>';
1660: $$rowtotal += $typecount;
1661: return $datatable;
1662: }
1663:
1664: sub print_courserequestmail {
1665: my ($dom,$settings,$rowtotal) = @_;
1666: my ($now,$datatable,%dompersonnel,@domcoord,@currapproval,$rows);
1667: $now = time;
1668: $rows = 0;
1669: %dompersonnel = &Apache::lonnet::get_domain_roles($dom,['dc'],$now,$now);
1670: foreach my $server (keys(%dompersonnel)) {
1671: foreach my $user (sort(keys(%{$dompersonnel{$server}}))) {
1672: my ($trole,$uname,$udom,$runame,$rudom,$rsec) = split(/:/,$user);
1673: if (!grep(/^$uname:$udom$/,@domcoord)) {
1674: push(@domcoord,$uname.':'.$udom);
1675: }
1676: }
1677: }
1678: if (ref($settings) eq 'HASH') {
1679: if (ref($settings->{'notify'}) eq 'HASH') {
1680: if ($settings->{'notify'}{'approval'} ne '') {
1681: @currapproval = split(',',$settings->{'notify'}{'approval'});
1682: }
1683: }
1684: }
1685: if (@currapproval) {
1686: foreach my $dc (@currapproval) {
1687: unless (grep(/^\Q$dc\E$/,@domcoord)) {
1688: push(@domcoord,$dc);
1689: }
1690: }
1691: }
1692: @domcoord = sort(@domcoord);
1693: my $numinrow = 4;
1694: my $numdc = @domcoord;
1695: my $css_class = 'class="LC_odd_row"';
1696: $datatable = '<tr'.$css_class.'>'.
1697: ' <td>'.&mt('Receive notification of course requests requiring approval.').
1698: ' </td>'.
1699: ' <td class="LC_left_item">';
1700: if (@domcoord > 0) {
1701: $datatable .= '<table>';
1702: for (my $i=0; $i<$numdc; $i++) {
1703: my $rem = $i%($numinrow);
1704: if ($rem == 0) {
1705: if ($i > 0) {
1706: $datatable .= '</tr>';
1707: }
1708: $datatable .= '<tr>';
1709: $rows ++;
1710: }
1711: my $check = ' ';
1712: if (grep(/^\Q$domcoord[$i]\E$/,@currapproval)) {
1713: $check = ' checked="checked" ';
1714: }
1715: my ($uname,$udom) = split(':',$domcoord[$i]);
1716: my $fullname = &Apache::loncommon::plainname($uname,$udom);
1717: if ($i == $numdc-1) {
1718: my $colsleft = $numinrow-$rem;
1719: if ($colsleft > 1) {
1720: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
1721: } else {
1722: $datatable .= '<td class="LC_left_item">';
1723: }
1724: } else {
1725: $datatable .= '<td class="LC_left_item">';
1726: }
1727: $datatable .= '<span class="LC_nobreak"><label>'.
1728: '<input type="checkbox" name="reqapprovalnotify" '.
1729: 'value="'.$domcoord[$i].'"'.$check.'/>'.
1730: $fullname.'</label></span></td>';
1731: }
1732: $datatable .= '</tr></table>';
1733: } else {
1734: $datatable .= &mt('There are no active Domain Coordinators');
1735: $rows ++;
1736: }
1737: $datatable .='</td></tr>';
1738: $$rowtotal += $rows;
1739: return $datatable;
1740: }
1741:
1742: sub print_autoenroll {
1743: my ($dom,$settings,$rowtotal) = @_;
1744: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
1745: my ($defdom,$runon,$runoff,$coownerson,$coownersoff);
1746: if (ref($settings) eq 'HASH') {
1747: if (exists($settings->{'run'})) {
1748: if ($settings->{'run'} eq '0') {
1749: $runoff = ' checked="checked" ';
1750: $runon = ' ';
1751: } else {
1752: $runon = ' checked="checked" ';
1753: $runoff = ' ';
1754: }
1755: } else {
1756: if ($autorun) {
1757: $runon = ' checked="checked" ';
1758: $runoff = ' ';
1759: } else {
1760: $runoff = ' checked="checked" ';
1761: $runon = ' ';
1762: }
1763: }
1764: if (exists($settings->{'co-owners'})) {
1765: if ($settings->{'co-owners'} eq '0') {
1766: $coownersoff = ' checked="checked" ';
1767: $coownerson = ' ';
1768: } else {
1769: $coownerson = ' checked="checked" ';
1770: $coownersoff = ' ';
1771: }
1772: } else {
1773: $coownersoff = ' checked="checked" ';
1774: $coownerson = ' ';
1775: }
1776: if (exists($settings->{'sender_domain'})) {
1777: $defdom = $settings->{'sender_domain'};
1778: }
1779: } else {
1780: if ($autorun) {
1781: $runon = ' checked="checked" ';
1782: $runoff = ' ';
1783: } else {
1784: $runoff = ' checked="checked" ';
1785: $runon = ' ';
1786: }
1787: }
1788: my $domform = &Apache::loncommon::select_dom_form($defdom,'sender_domain',1);
1789: my $notif_sender;
1790: if (ref($settings) eq 'HASH') {
1791: $notif_sender = $settings->{'sender_uname'};
1792: }
1793: my $datatable='<tr class="LC_odd_row">'.
1794: '<td>'.&mt('Auto-enrollment active?').'</td>'.
1795: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1796: '<input type="radio" name="autoenroll_run"'.
1797: $runon.' value="1" />'.&mt('Yes').'</label> '.
1798: '<label><input type="radio" name="autoenroll_run"'.
1799: $runoff.' value="0" />'.&mt('No').'</label></span></td>'.
1800: '</tr><tr>'.
1801: '<td>'.&mt('Notification messages - sender').
1802: '</td><td class="LC_right_item"><span class="LC_nobreak">'.
1803: &mt('username').': '.
1804: '<input type="text" name="sender_uname" value="'.
1805: $notif_sender.'" size="10" /> '.&mt('domain').
1806: ': '.$domform.'</span></td></tr>'.
1807: '<tr class="LC_odd_row">'.
1808: '<td>'.&mt('Automatically assign co-ownership').'</td>'.
1809: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1810: '<input type="radio" name="autoassign_coowners"'.
1811: $coownerson.' value="1" />'.&mt('Yes').'</label> '.
1812: '<label><input type="radio" name="autoassign_coowners"'.
1813: $coownersoff.' value="0" />'.&mt('No').'</label></span></td>'.
1814: '</tr>';
1815: $$rowtotal += 3;
1816: return $datatable;
1817: }
1818:
1819: sub print_autoupdate {
1820: my ($position,$dom,$settings,$rowtotal) = @_;
1821: my $datatable;
1822: if ($position eq 'top') {
1823: my $updateon = ' ';
1824: my $updateoff = ' checked="checked" ';
1825: my $classlistson = ' ';
1826: my $classlistsoff = ' checked="checked" ';
1827: if (ref($settings) eq 'HASH') {
1828: if ($settings->{'run'} eq '1') {
1829: $updateon = $updateoff;
1830: $updateoff = ' ';
1831: }
1832: if ($settings->{'classlists'} eq '1') {
1833: $classlistson = $classlistsoff;
1834: $classlistsoff = ' ';
1835: }
1836: }
1837: my %title = (
1838: run => 'Auto-update active?',
1839: classlists => 'Update information in classlists?',
1840: );
1841: $datatable = '<tr class="LC_odd_row">'.
1842: '<td>'.&mt($title{'run'}).'</td>'.
1843: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1844: '<input type="radio" name="autoupdate_run"'.
1845: $updateon.' value="1" />'.&mt('Yes').'</label> '.
1846: '<label><input type="radio" name="autoupdate_run"'.
1847: $updateoff.'value="0" />'.&mt('No').'</label></span></td>'.
1848: '</tr><tr>'.
1849: '<td>'.&mt($title{'classlists'}).'</td>'.
1850: '<td class="LC_right_item"><span class="LC_nobreak">'.
1851: '<label><input type="radio" name="classlists"'.
1852: $classlistson.' value="1" />'.&mt('Yes').'</label> '.
1853: '<label><input type="radio" name="classlists"'.
1854: $classlistsoff.'value="0" />'.&mt('No').'</label></span></td>'.
1855: '</tr>';
1856: $$rowtotal += 2;
1857: } elsif ($position eq 'middle') {
1858: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1859: my $numinrow = 3;
1860: my $locknamesettings;
1861: $datatable .= &insttypes_row($settings,$types,$usertypes,
1862: $dom,$numinrow,$othertitle,
1863: 'lockablenames');
1864: $$rowtotal ++;
1865: } else {
1866: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1867: my @fields = ('lastname','firstname','middlename','generation',
1868: 'permanentemail','id');
1869: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1870: my $numrows = 0;
1871: if (ref($types) eq 'ARRAY') {
1872: if (@{$types} > 0) {
1873: $datatable =
1874: &usertype_update_row($settings,$usertypes,\%fieldtitles,
1875: \@fields,$types,\$numrows);
1876: $$rowtotal += @{$types};
1877: }
1878: }
1879: $datatable .=
1880: &usertype_update_row($settings,{'default' => $othertitle},
1881: \%fieldtitles,\@fields,['default'],
1882: \$numrows);
1883: $$rowtotal ++;
1884: }
1885: return $datatable;
1886: }
1887:
1888: sub print_autocreate {
1889: my ($dom,$settings,$rowtotal) = @_;
1890: my (%createon,%createoff);
1891: my $curr_dc;
1892: my @types = ('xml','req');
1893: if (ref($settings) eq 'HASH') {
1894: foreach my $item (@types) {
1895: $createoff{$item} = ' checked="checked" ';
1896: $createon{$item} = ' ';
1897: if (exists($settings->{$item})) {
1898: if ($settings->{$item}) {
1899: $createon{$item} = ' checked="checked" ';
1900: $createoff{$item} = ' ';
1901: }
1902: }
1903: }
1904: $curr_dc = $settings->{'xmldc'};
1905: } else {
1906: foreach my $item (@types) {
1907: $createoff{$item} = ' checked="checked" ';
1908: $createon{$item} = ' ';
1909: }
1910: }
1911: $$rowtotal += 2;
1912: my $datatable='<tr class="LC_odd_row">'.
1913: '<td>'.&mt('Create pending official courses from XML files').'</td>'.
1914: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1915: '<input type="radio" name="autocreate_xml"'.
1916: $createon{'xml'}.' value="1" />'.&mt('Yes').'</label> '.
1917: '<label><input type="radio" name="autocreate_xml"'.
1918: $createoff{'xml'}.' value="0" />'.&mt('No').'</label></span>'.
1919: '</td></tr><tr>'.
1920: '<td>'.&mt('Create pending requests for official courses (if validated)').'</td>'.
1921: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1922: '<input type="radio" name="autocreate_req"'.
1923: $createon{'req'}.' value="1" />'.&mt('Yes').'</label> '.
1924: '<label><input type="radio" name="autocreate_req"'.
1925: $createoff{'req'}.' value="0" />'.&mt('No').'</label></span>';
1926: my ($numdc,$dctable) = &active_dc_picker($dom,$curr_dc);
1927: if ($numdc > 1) {
1928: $datatable .= '</td></tr><tr class="LC_odd_row"><td>'.
1929: &mt('Course creation processed as: (choose Dom. Coord.)').
1930: '</td><td class="LC_left_item">'.$dctable.'</td></tr>';
1931: $$rowtotal ++ ;
1932: } else {
1933: $datatable .= $dctable.'</td></tr>';
1934: }
1935: return $datatable;
1936: }
1937:
1938: sub print_directorysrch {
1939: my ($dom,$settings,$rowtotal) = @_;
1940: my $srchon = ' ';
1941: my $srchoff = ' checked="checked" ';
1942: my ($exacton,$containson,$beginson);
1943: my $localon = ' ';
1944: my $localoff = ' checked="checked" ';
1945: if (ref($settings) eq 'HASH') {
1946: if ($settings->{'available'} eq '1') {
1947: $srchon = $srchoff;
1948: $srchoff = ' ';
1949: }
1950: if ($settings->{'localonly'} eq '1') {
1951: $localon = $localoff;
1952: $localoff = ' ';
1953: }
1954: if (ref($settings->{'searchtypes'}) eq 'ARRAY') {
1955: foreach my $type (@{$settings->{'searchtypes'}}) {
1956: if ($type eq 'exact') {
1957: $exacton = ' checked="checked" ';
1958: } elsif ($type eq 'contains') {
1959: $containson = ' checked="checked" ';
1960: } elsif ($type eq 'begins') {
1961: $beginson = ' checked="checked" ';
1962: }
1963: }
1964: } else {
1965: if ($settings->{'searchtypes'} eq 'exact') {
1966: $exacton = ' checked="checked" ';
1967: } elsif ($settings->{'searchtypes'} eq 'contains') {
1968: $containson = ' checked="checked" ';
1969: } elsif ($settings->{'searchtypes'} eq 'specify') {
1970: $exacton = ' checked="checked" ';
1971: $containson = ' checked="checked" ';
1972: }
1973: }
1974: }
1975: my ($searchtitles,$titleorder) = &sorted_searchtitles();
1976: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1977:
1978: my $numinrow = 4;
1979: my $cansrchrow = 0;
1980: my $datatable='<tr class="LC_odd_row">'.
1981: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Directory search available?').'</span></td>'.
1982: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1983: '<input type="radio" name="dirsrch_available"'.
1984: $srchon.' value="1" />'.&mt('Yes').'</label> '.
1985: '<label><input type="radio" name="dirsrch_available"'.
1986: $srchoff.' value="0" />'.&mt('No').'</label></span></td>'.
1987: '</tr><tr>'.
1988: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search?').'</span></td>'.
1989: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1990: '<input type="radio" name="dirsrch_localonly"'.
1991: $localoff.' value="0" />'.&mt('Yes').'</label> '.
1992: '<label><input type="radio" name="dirsrch_localonly"'.
1993: $localon.' value="1" />'.&mt('No').'</label></span></td>'.
1994: '</tr>';
1995: $$rowtotal += 2;
1996: if (ref($usertypes) eq 'HASH') {
1997: if (keys(%{$usertypes}) > 0) {
1998: $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
1999: $numinrow,$othertitle,'cansearch');
2000: $cansrchrow = 1;
2001: }
2002: }
2003: if ($cansrchrow) {
2004: $$rowtotal ++;
2005: $datatable .= '<tr>';
2006: } else {
2007: $datatable .= '<tr class="LC_odd_row">';
2008: }
2009: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Supported search methods').
2010: '</span></td><td class="LC_left_item" colspan="2"><table><tr>';
2011: foreach my $title (@{$titleorder}) {
2012: if (defined($searchtitles->{$title})) {
2013: my $check = ' ';
2014: if (ref($settings) eq 'HASH') {
2015: if (ref($settings->{'searchby'}) eq 'ARRAY') {
2016: if (grep(/^\Q$title\E$/,@{$settings->{'searchby'}})) {
2017: $check = ' checked="checked" ';
2018: }
2019: }
2020: }
2021: $datatable .= '<td class="LC_left_item">'.
2022: '<span class="LC_nobreak"><label>'.
2023: '<input type="checkbox" name="searchby" '.
2024: 'value="'.$title.'"'.$check.'/>'.
2025: $searchtitles->{$title}.'</label></span></td>';
2026: }
2027: }
2028: $datatable .= '</tr></table></td></tr>';
2029: $$rowtotal ++;
2030: if ($cansrchrow) {
2031: $datatable .= '<tr class="LC_odd_row">';
2032: } else {
2033: $datatable .= '<tr>';
2034: }
2035: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Search latitude').'</span></td>'.
2036: '<td class="LC_left_item" colspan="2">'.
2037: '<span class="LC_nobreak"><label>'.
2038: '<input type="checkbox" name="searchtypes" '.
2039: $exacton.' value="exact" />'.&mt('Exact match').
2040: '</label> '.
2041: '<label><input type="checkbox" name="searchtypes" '.
2042: $beginson.' value="begins" />'.&mt('Begins with').
2043: '</label> '.
2044: '<label><input type="checkbox" name="searchtypes" '.
2045: $containson.' value="contains" />'.&mt('Contains').
2046: '</label></span></td></tr>';
2047: $$rowtotal ++;
2048: return $datatable;
2049: }
2050:
2051: sub print_contacts {
2052: my ($dom,$settings,$rowtotal) = @_;
2053: my $datatable;
2054: my @contacts = ('adminemail','supportemail');
2055: my (%checked,%to,%otheremails,%bccemails);
2056: my @mailings = ('errormail','packagesmail','lonstatusmail','helpdeskmail',
2057: 'requestsmail');
2058: foreach my $type (@mailings) {
2059: $otheremails{$type} = '';
2060: }
2061: $bccemails{'helpdeskmail'} = '';
2062: if (ref($settings) eq 'HASH') {
2063: foreach my $item (@contacts) {
2064: if (exists($settings->{$item})) {
2065: $to{$item} = $settings->{$item};
2066: }
2067: }
2068: foreach my $type (@mailings) {
2069: if (exists($settings->{$type})) {
2070: if (ref($settings->{$type}) eq 'HASH') {
2071: foreach my $item (@contacts) {
2072: if ($settings->{$type}{$item}) {
2073: $checked{$type}{$item} = ' checked="checked" ';
2074: }
2075: }
2076: $otheremails{$type} = $settings->{$type}{'others'};
2077: if ($type eq 'helpdeskmail') {
2078: $bccemails{$type} = $settings->{$type}{'bcc'};
2079: }
2080: }
2081: } elsif ($type eq 'lonstatusmail') {
2082: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
2083: }
2084: }
2085: } else {
2086: $to{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
2087: $to{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
2088: $checked{'errormail'}{'adminemail'} = ' checked="checked" ';
2089: $checked{'packagesmail'}{'adminemail'} = ' checked="checked" ';
2090: $checked{'helpdeskmail'}{'supportemail'} = ' checked="checked" ';
2091: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
2092: $checked{'requestsmail'}{'adminemail'} = ' checked="checked" ';
2093: }
2094: my ($titles,$short_titles) = &contact_titles();
2095: my $rownum = 0;
2096: my $css_class;
2097: foreach my $item (@contacts) {
2098: $rownum ++;
2099: $css_class = $rownum%2?' class="LC_odd_row"':'';
2100: $datatable .= '<tr'.$css_class.'>'.
2101: '<td><span class="LC_nobreak">'.$titles->{$item}.
2102: '</span></td><td class="LC_right_item">'.
2103: '<input type="text" name="'.$item.'" value="'.
2104: $to{$item}.'" /></td></tr>';
2105: }
2106: foreach my $type (@mailings) {
2107: $rownum ++;
2108: $css_class = $rownum%2?' class="LC_odd_row"':'';
2109: $datatable .= '<tr'.$css_class.'>'.
2110: '<td><span class="LC_nobreak">'.
2111: $titles->{$type}.': </span></td>'.
2112: '<td class="LC_left_item">'.
2113: '<span class="LC_nobreak">';
2114: foreach my $item (@contacts) {
2115: $datatable .= '<label>'.
2116: '<input type="checkbox" name="'.$type.'"'.
2117: $checked{$type}{$item}.
2118: ' value="'.$item.'" />'.$short_titles->{$item}.
2119: '</label> ';
2120: }
2121: $datatable .= '</span><br />'.&mt('Others').': '.
2122: '<input type="text" name="'.$type.'_others" '.
2123: 'value="'.$otheremails{$type}.'" />';
2124: if ($type eq 'helpdeskmail') {
2125: $datatable .= '<br />'.&mt('Bcc:').(' 'x6).
2126: '<input type="text" name="'.$type.'_bcc" '.
2127: 'value="'.$bccemails{$type}.'" />';
2128: }
2129: $datatable .= '</td></tr>'."\n";
2130: }
2131: $$rowtotal += $rownum;
2132: return $datatable;
2133: }
2134:
2135: sub print_helpsettings {
2136:
2137: my ($position,$dom,$confname,$settings,$rowtotal) = @_;
2138: my ($css_class,$datatable);
2139:
2140: my $switchserver = &check_switchserver($dom,$confname);
2141:
2142: my $itemcount = 1;
2143:
2144: if ($position eq 'top') {
2145:
2146: my (%checkedon,%checkedoff,%choices,%defaultchecked,@toggles);
2147:
2148: %choices =
2149: &Apache::lonlocal::texthash (
2150: submitbugs => 'Display "Submit a bug" link?',
2151: );
2152:
2153: %defaultchecked = ('submitbugs' => 'on');
2154:
2155: @toggles = ('submitbugs',);
2156:
2157: foreach my $item (@toggles) {
2158: if ($defaultchecked{$item} eq 'on') {
2159: $checkedon{$item} = ' checked="checked" ';
2160: $checkedoff{$item} = ' ';
2161: } elsif ($defaultchecked{$item} eq 'off') {
2162: $checkedoff{$item} = ' checked="checked" ';
2163: $checkedon{$item} = ' ';
2164: }
2165: }
2166:
2167: if (ref($settings) eq 'HASH') {
2168: foreach my $item (@toggles) {
2169: if ($settings->{$item} eq '1') {
2170: $checkedon{$item} = ' checked="checked" ';
2171: $checkedoff{$item} = ' ';
2172: } elsif ($settings->{$item} eq '0') {
2173: $checkedoff{$item} = ' checked="checked" ';
2174: $checkedon{$item} = ' ';
2175: }
2176: }
2177: }
2178:
2179: foreach my $item (@toggles) {
2180: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
2181: $datatable .=
2182: '<tr'.$css_class.'>
2183: <td><span class="LC_nobreak">'.$choices{$item}.'</span></td>
2184: <td><span class="LC_nobreak"> </span></td>
2185: <td class="LC_right_item"><span class="LC_nobreak">
2186: <label><input type="radio" name="'.$item.'" '.$checkedon{$item}.' value="1" />'.&mt('Yes').'</label>
2187: <label><input type="radio" name="'.$item.'" '.$checkedoff{$item}.' value="0" />'.&mt('No').'</label>'.
2188: '</span></td>'.
2189: '</tr>';
2190: $itemcount ++;
2191: }
2192:
2193: } else {
2194:
2195: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
2196:
2197: $datatable .= '<tr'.$css_class.'>';
2198:
2199: if (ref($settings) eq 'HASH') {
2200: if ($settings->{'loginhelpurl'} ne '') {
2201: my($directory, $filename) = $settings->{'loginhelpurl'} =~ m/(.*\/)(.*)$/;
2202: $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>';
2203: $datatable .= '<td width="33%"><span class="LC_right_item"><label><input type="checkbox" name="loginhelpurl_del" value="1" />'.&mt('Delete?').'</label></span></td>'
2204: } else {
2205: $datatable .= '<td width="33%"><span class="LC_left_item"><label>'.&mt('Default Login Page Help File In Use').'</label></span></td>';
2206: $datatable .= '<td width="33%"><span class="LC_right_item"> </span></td>';
2207: }
2208: } else {
2209: $datatable .= '<td><span class="LC_left_item"> </span></td>';
2210: $datatable .= '<td><span class="LC_right_item"> </span></td>';
2211: }
2212:
2213: $datatable .= '<td width="33%"><span class="LC_right_item">';
2214: if ($switchserver) {
2215: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2216: } else {
2217: $datatable .= &mt('Upload Custom Login Page Help File:');
2218: $datatable .='<input type="file" name="loginhelpurl" />';
2219: }
2220: $datatable .= '</span></td></tr>';
2221:
2222: }
2223:
2224: return $datatable;
2225:
2226: }
2227:
2228:
2229: sub radiobutton_prefs {
2230: my ($settings,$toggles,$defaultchecked,$choices,$itemcount) = @_;
2231: return unless ((ref($toggles) eq 'ARRAY') && (ref($defaultchecked) eq 'HASH') &&
2232: (ref($choices) eq 'HASH'));
2233:
2234: my (%checkedon,%checkedoff,$datatable,$css_class);
2235:
2236: foreach my $item (@{$toggles}) {
2237: if ($defaultchecked->{$item} eq 'on') {
2238: $checkedon{$item} = ' checked="checked" ';
2239: $checkedoff{$item} = ' ';
2240: } elsif ($defaultchecked->{$item} eq 'off') {
2241: $checkedoff{$item} = ' checked="checked" ';
2242: $checkedon{$item} = ' ';
2243: }
2244: }
2245: if (ref($settings) eq 'HASH') {
2246: foreach my $item (@{$toggles}) {
2247: if ($settings->{$item} eq '1') {
2248: $checkedon{$item} = ' checked="checked" ';
2249: $checkedoff{$item} = ' ';
2250: } elsif ($settings->{$item} eq '0') {
2251: $checkedoff{$item} = ' checked="checked" ';
2252: $checkedon{$item} = ' ';
2253: }
2254: }
2255: }
2256: foreach my $item (@{$toggles}) {
2257: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2258: $datatable .=
2259: '<tr'.$css_class.'><td><span class="LC_nobreak">'.$choices->{$item}.
2260: '</span></td>'.
2261: '<td class="LC_right_item"><span class="LC_nobreak">'.
2262: '<label><input type="radio" name="'.
2263: $item.'" '.$checkedon{$item}.' value="1" />'.&mt('Yes').
2264: '</label> <label><input type="radio" name="'.$item.'" '.
2265: $checkedoff{$item}.' value="0" />'.&mt('No').'</label>'.
2266: '</span></td>'.
2267: '</tr>';
2268: $itemcount ++;
2269: }
2270: return ($datatable,$itemcount);
2271: }
2272:
2273: sub print_coursedefaults {
2274: my ($position,$dom,$settings,$rowtotal) = @_;
2275: my ($css_class,$datatable);
2276: my $itemcount = 1;
2277: if ($position eq 'top') {
2278: my (%checkedon,%checkedoff,%choices,%defaultchecked,@toggles);
2279: %choices =
2280: &Apache::lonlocal::texthash (
2281: canuse_pdfforms => 'Course/Community users can create/upload PDF forms',
2282: );
2283: %defaultchecked = ('canuse_pdfforms' => 'off');
2284: @toggles = ('canuse_pdfforms',);
2285: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
2286: \%choices,$itemcount);
2287: $$rowtotal += $itemcount;
2288: } else {
2289: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
2290: my %choices =
2291: &Apache::lonlocal::texthash (
2292: anonsurvey_threshold => 'Responder count needed before showing submissions for anonymous surveys',
2293: );
2294: my $currdefresponder;
2295: if (ref($settings) eq 'HASH') {
2296: $currdefresponder = $settings->{'anonsurvey_threshold'};
2297: }
2298: if (!$currdefresponder) {
2299: $currdefresponder = 10;
2300: } elsif ($currdefresponder < 1) {
2301: $currdefresponder = 1;
2302: }
2303: $datatable .=
2304: '<tr'.$css_class.'><td><span class="LC_nobreak">'.$choices{'anonsurvey_threshold'}.
2305: '</span></td>'.
2306: '<td class="LC_right_item"><span class="LC_nobreak">'.
2307: '<input type="text" name="anonsurvey_threshold"'.
2308: ' value="'.$currdefresponder.'" size="5" /></span>'.
2309: '</td></tr>';
2310: }
2311: return $datatable;
2312: }
2313:
2314: sub print_usersessions {
2315: my ($position,$dom,$settings,$rowtotal) = @_;
2316: my ($css_class,$datatable,%checked,%choices);
2317: my (%by_ip,%by_location,@intdoms);
2318: &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
2319:
2320: my @alldoms = &Apache::lonnet::all_domains();
2321: my %serverhomes = %Apache::lonnet::serverhomeIDs;
2322: my %servers = &Apache::lonnet::internet_dom_servers($dom);
2323: my %altids = &id_for_thisdom(%servers);
2324: my $itemcount = 1;
2325: if ($position eq 'top') {
2326: if (keys(%serverhomes) > 1) {
2327: my %spareid = ¤t_offloads_to($dom,$settings,\%servers);
2328: $datatable .= &spares_row($dom,\%servers,\%spareid,\%serverhomes,\%altids,$rowtotal);
2329: } else {
2330: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
2331: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one server.');
2332: }
2333: } else {
2334: if (keys(%by_location) == 0) {
2335: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
2336: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one institution.');
2337: } else {
2338: my %lt = &usersession_titles();
2339: my $numinrow = 5;
2340: my $prefix;
2341: my @types;
2342: if ($position eq 'bottom') {
2343: $prefix = 'remote';
2344: @types = ('version','excludedomain','includedomain');
2345: } else {
2346: $prefix = 'hosted';
2347: @types = ('excludedomain','includedomain');
2348: }
2349: my (%current,%checkedon,%checkedoff);
2350: my @lcversions = &Apache::lonnet::all_loncaparevs();
2351: my @locations = sort(keys(%by_location));
2352: foreach my $type (@types) {
2353: $checkedon{$type} = '';
2354: $checkedoff{$type} = ' checked="checked"';
2355: }
2356: if (ref($settings) eq 'HASH') {
2357: if (ref($settings->{$prefix}) eq 'HASH') {
2358: foreach my $key (keys(%{$settings->{$prefix}})) {
2359: $current{$key} = $settings->{$prefix}{$key};
2360: if ($key eq 'version') {
2361: if ($current{$key} ne '') {
2362: $checkedon{$key} = ' checked="checked"';
2363: $checkedoff{$key} = '';
2364: }
2365: } elsif (ref($current{$key}) eq 'ARRAY') {
2366: $checkedon{$key} = ' checked="checked"';
2367: $checkedoff{$key} = '';
2368: }
2369: }
2370: }
2371: }
2372: foreach my $type (@types) {
2373: next if ($type ne 'version' && !@locations);
2374: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
2375: $datatable .= '<tr'.$css_class.'>
2376: <td><span class="LC_nobreak">'.$lt{$type}.'</span><br />
2377: <span class="LC_nobreak">
2378: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedoff{$type}.' value="0" />'.&mt('Not in use').'</label>
2379: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedon{$type}.' value="1" />'.&mt('In use').'</label></span></td><td>';
2380: if ($type eq 'version') {
2381: my $selector = '<select name="'.$prefix.'_version">';
2382: foreach my $version (@lcversions) {
2383: my $selected = '';
2384: if ($current{'version'} eq $version) {
2385: $selected = ' selected="selected"';
2386: }
2387: $selector .= ' <option value="'.$version.'"'.
2388: $selected.'>'.$version.'</option>';
2389: }
2390: $selector .= '</select> ';
2391: $datatable .= &mt('remote server must be version: [_1] or later',$selector);
2392: } else {
2393: $datatable.= '<div><input type="button" value="'.&mt('check all').'" '.
2394: 'onclick="javascript:checkAll(document.display.'.$prefix.'_'.$type.')"'.
2395: ' />'.(' 'x2).
2396: '<input type="button" value="'.&mt('uncheck all').'" '.
2397: 'onclick="javascript:uncheckAll(document.display.'.$prefix.'_'.$type.')" />'.
2398: "\n".
2399: '</div><div><table>';
2400: my $rem;
2401: for (my $i=0; $i<@locations; $i++) {
2402: my ($showloc,$value,$checkedtype);
2403: if (ref($by_location{$locations[$i]}) eq 'ARRAY') {
2404: my $ip = $by_location{$locations[$i]}->[0];
2405: if (ref($by_ip{$ip}) eq 'ARRAY') {
2406: $value = join(':',@{$by_ip{$ip}});
2407: $showloc = join(', ',@{$by_ip{$ip}});
2408: if (ref($current{$type}) eq 'ARRAY') {
2409: foreach my $loc (@{$by_ip{$ip}}) {
2410: if (grep(/^\Q$loc\E$/,@{$current{$type}})) {
2411: $checkedtype = ' checked="checked"';
2412: last;
2413: }
2414: }
2415: }
2416: }
2417: }
2418: $rem = $i%($numinrow);
2419: if ($rem == 0) {
2420: if ($i > 0) {
2421: $datatable .= '</tr>';
2422: }
2423: $datatable .= '<tr>';
2424: }
2425: $datatable .= '<td class="LC_left_item">'.
2426: '<span class="LC_nobreak"><label>'.
2427: '<input type="checkbox" name="'.$prefix.'_'.$type.
2428: '" value="'.$value.'"'.$checkedtype.' />'.$showloc.
2429: '</label></span></td>';
2430: }
2431: $rem = @locations%($numinrow);
2432: my $colsleft = $numinrow - $rem;
2433: if ($colsleft > 1 ) {
2434: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
2435: ' </td>';
2436: } elsif ($colsleft == 1) {
2437: $datatable .= '<td class="LC_left_item"> </td>';
2438: }
2439: $datatable .= '</tr></table>';
2440: }
2441: $datatable .= '</td></tr>';
2442: $itemcount ++;
2443: }
2444: }
2445: }
2446: $$rowtotal += $itemcount;
2447: return $datatable;
2448: }
2449:
2450: sub build_location_hashes {
2451: my ($intdoms,$by_ip,$by_location) = @_;
2452: return unless((ref($intdoms) eq 'ARRAY') && (ref($by_ip) eq 'HASH') &&
2453: (ref($by_location) eq 'HASH'));
2454: my %iphost = &Apache::lonnet::get_iphost();
2455: my $primary_id = &Apache::lonnet::domain($env{'request.role.domain'},'primary');
2456: my $primary_ip = &Apache::lonnet::get_host_ip($primary_id);
2457: if (ref($iphost{$primary_ip}) eq 'ARRAY') {
2458: foreach my $id (@{$iphost{$primary_ip}}) {
2459: my $intdom = &Apache::lonnet::internet_dom($id);
2460: unless(grep(/^\Q$intdom\E$/,@{$intdoms})) {
2461: push(@{$intdoms},$intdom);
2462: }
2463: }
2464: }
2465: foreach my $ip (keys(%iphost)) {
2466: if (ref($iphost{$ip}) eq 'ARRAY') {
2467: foreach my $id (@{$iphost{$ip}}) {
2468: my $location = &Apache::lonnet::internet_dom($id);
2469: if ($location) {
2470: next if (grep(/^\Q$location\E$/,@{$intdoms}));
2471: if (ref($by_ip->{$ip}) eq 'ARRAY') {
2472: unless(grep(/^\Q$location\E$/,@{$by_ip->{$ip}})) {
2473: push(@{$by_ip->{$ip}},$location);
2474: }
2475: } else {
2476: $by_ip->{$ip} = [$location];
2477: }
2478: }
2479: }
2480: }
2481: }
2482: foreach my $ip (sort(keys(%{$by_ip}))) {
2483: if (ref($by_ip->{$ip}) eq 'ARRAY') {
2484: @{$by_ip->{$ip}} = sort(@{$by_ip->{$ip}});
2485: my $first = $by_ip->{$ip}->[0];
2486: if (ref($by_location->{$first}) eq 'ARRAY') {
2487: unless (grep(/^\Q$ip\E$/,@{$by_location->{$first}})) {
2488: push(@{$by_location->{$first}},$ip);
2489: }
2490: } else {
2491: $by_location->{$first} = [$ip];
2492: }
2493: }
2494: }
2495: return;
2496: }
2497:
2498: sub current_offloads_to {
2499: my ($dom,$settings,$servers) = @_;
2500: my (%spareid,%otherdomconfigs);
2501: if (ref($servers) eq 'HASH') {
2502: foreach my $lonhost (sort(keys(%{$servers}))) {
2503: my $gotspares;
2504: if (ref($settings) eq 'HASH') {
2505: if (ref($settings->{'spares'}) eq 'HASH') {
2506: if (ref($settings->{'spares'}{$lonhost}) eq 'HASH') {
2507: $spareid{$lonhost}{'primary'} = $settings->{'spares'}{$lonhost}{'primary'};
2508: $spareid{$lonhost}{'default'} = $settings->{'spares'}{$lonhost}{'default'};
2509: $gotspares = 1;
2510: }
2511: }
2512: }
2513: unless ($gotspares) {
2514: my $gotspares;
2515: my $serverhomeID =
2516: &Apache::lonnet::get_server_homeID($servers->{$lonhost});
2517: my $serverhomedom =
2518: &Apache::lonnet::host_domain($serverhomeID);
2519: if ($serverhomedom ne $dom) {
2520: if (ref($otherdomconfigs{$serverhomedom} eq 'HASH')) {
2521: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
2522: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
2523: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
2524: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
2525: $gotspares = 1;
2526: }
2527: }
2528: } else {
2529: $otherdomconfigs{$serverhomedom} =
2530: &Apache::lonnet::get_dom('configuration',['usersessions'],$serverhomedom);
2531: if (ref($otherdomconfigs{$serverhomedom}) eq 'HASH') {
2532: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
2533: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
2534: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{$lonhost}) eq 'HASH') {
2535: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
2536: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
2537: $gotspares = 1;
2538: }
2539: }
2540: }
2541: }
2542: }
2543: }
2544: }
2545: unless ($gotspares) {
2546: if ($lonhost eq $Apache::lonnet::perlvar{'lonHostID'}) {
2547: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
2548: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
2549: } else {
2550: my $server_hostname = &Apache::lonnet::hostname($lonhost);
2551: my $server_homeID = &Apache::lonnet::get_server_homeID($server_hostname);
2552: if ($server_homeID eq $Apache::lonnet::perlvar{'lonHostID'}) {
2553: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
2554: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
2555: } else {
2556: my %what = (
2557: spareid => 1,
2558: );
2559: my ($result,$returnhash) =
2560: &Apache::lonnet::get_remote_globals($lonhost,\%what);
2561: if ($result eq 'ok') {
2562: if (ref($returnhash) eq 'HASH') {
2563: if (ref($returnhash->{'spareid'}) eq 'HASH') {
2564: $spareid{$lonhost}{'primary'} = $returnhash->{'spareid'}->{'primary'};
2565: $spareid{$lonhost}{'default'} = $returnhash->{'spareid'}->{'default'};
2566: }
2567: }
2568: }
2569: }
2570: }
2571: }
2572: }
2573: }
2574: return %spareid;
2575: }
2576:
2577: sub spares_row {
2578: my ($dom,$servers,$spareid,$serverhomes,$altids,$rowtotal) = @_;
2579: my $css_class;
2580: my $numinrow = 4;
2581: my $itemcount = 1;
2582: my $datatable;
2583: my %typetitles = &sparestype_titles();
2584: if ((ref($servers) eq 'HASH') && (ref($spareid) eq 'HASH') && (ref($altids) eq 'HASH')) {
2585: foreach my $server (sort(keys(%{$servers}))) {
2586: my $serverhome = &Apache::lonnet::get_server_homeID($servers->{$server});
2587: my ($othercontrol,$serverdom);
2588: if ($serverhome ne $server) {
2589: $serverdom = &Apache::lonnet::host_domain($serverhome);
2590: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
2591: } else {
2592: $serverdom = &Apache::lonnet::host_domain($server);
2593: if ($serverdom ne $dom) {
2594: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
2595: }
2596: }
2597: next unless (ref($spareid->{$server}) eq 'HASH');
2598: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
2599: $datatable .= '<tr'.$css_class.'>
2600: <td rowspan="2">
2601: <span class="LC_nobreak"><b>'.$server.'</b> when busy, offloads to:</span></td>'."\n";
2602: my (%current,%canselect);
2603: my @choices =
2604: &possible_newspares($server,$spareid->{$server},$serverhomes,$altids);
2605: foreach my $type ('primary','default') {
2606: if (ref($spareid->{$server}) eq 'HASH') {
2607: if (ref($spareid->{$server}{$type}) eq 'ARRAY') {
2608: my @spares = @{$spareid->{$server}{$type}};
2609: if (@spares > 0) {
2610: if ($othercontrol) {
2611: $current{$type} = join(', ',@spares);
2612: } else {
2613: $current{$type} .= '<table>';
2614: my $numspares = scalar(@spares);
2615: for (my $i=0; $i<@spares; $i++) {
2616: my $rem = $i%($numinrow);
2617: if ($rem == 0) {
2618: if ($i > 0) {
2619: $current{$type} .= '</tr>';
2620: }
2621: $current{$type} .= '<tr>';
2622: }
2623: $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'".');" /> '.
2624: $spareid->{$server}{$type}[$i].
2625: '</label></td>'."\n";
2626: }
2627: my $rem = @spares%($numinrow);
2628: my $colsleft = $numinrow - $rem;
2629: if ($colsleft > 1 ) {
2630: $current{$type} .= '<td colspan="'.$colsleft.
2631: '" class="LC_left_item">'.
2632: ' </td>';
2633: } elsif ($colsleft == 1) {
2634: $current{$type} .= '<td class="LC_left_item"> </td>'."\n";
2635: }
2636: $current{$type} .= '</tr></table>';
2637: }
2638: }
2639: }
2640: if ($current{$type} eq '') {
2641: $current{$type} = &mt('None specified');
2642: }
2643: if ($othercontrol) {
2644: if ($type eq 'primary') {
2645: $canselect{$type} = $othercontrol;
2646: }
2647: } else {
2648: $canselect{$type} =
2649: &mt('Add new [_1]'.$type.'[_2]:','<i>','</i>').' '.
2650: '<select name="newspare_'.$type.'_'.$server.'" '.
2651: 'id="newspare_'.$type.'_'.$server.'" onchange="checkNewSpares('."'$server','$type'".');">'."\n".
2652: '<option value="" selected ="selected">'.&mt('Select').'</option>'."\n";
2653: if (@choices > 0) {
2654: foreach my $lonhost (@choices) {
2655: $canselect{$type} .= '<option value="'.$lonhost.'">'.$lonhost.'</option>'."\n";
2656: }
2657: }
2658: $canselect{$type} .= '</select>'."\n";
2659: }
2660: } else {
2661: $current{$type} = &mt('Could not be determined');
2662: if ($type eq 'primary') {
2663: $canselect{$type} = $othercontrol;
2664: }
2665: }
2666: if ($type eq 'default') {
2667: $datatable .= '<tr'.$css_class.'>';
2668: }
2669: $datatable .= '<td><i>'.$typetitles{$type}.'</i></td>'."\n".
2670: '<td>'.$current{$type}.'</td>'."\n".
2671: '<td>'.$canselect{$type}.'</td></tr>'."\n";
2672: }
2673: $itemcount ++;
2674: }
2675: }
2676: $$rowtotal += $itemcount;
2677: return $datatable;
2678: }
2679:
2680: sub possible_newspares {
2681: my ($server,$currspares,$serverhomes,$altids) = @_;
2682: my $serverhostname = &Apache::lonnet::hostname($server);
2683: my %excluded;
2684: if ($serverhostname ne '') {
2685: %excluded = (
2686: $serverhostname => 1,
2687: );
2688: }
2689: if (ref($currspares) eq 'HASH') {
2690: foreach my $type (keys(%{$currspares})) {
2691: if (ref($currspares->{$type}) eq 'ARRAY') {
2692: if (@{$currspares->{$type}} > 0) {
2693: foreach my $curr (@{$currspares->{$type}}) {
2694: my $hostname = &Apache::lonnet::hostname($curr);
2695: $excluded{$hostname} = 1;
2696: }
2697: }
2698: }
2699: }
2700: }
2701: my @choices;
2702: if ((ref($serverhomes) eq 'HASH') && (ref($altids) eq 'HASH')) {
2703: if (keys(%{$serverhomes}) > 1) {
2704: foreach my $name (sort(keys(%{$serverhomes}))) {
2705: unless ($excluded{$name}) {
2706: if (exists($altids->{$serverhomes->{$name}})) {
2707: push(@choices,$altids->{$serverhomes->{$name}});
2708: } else {
2709: push(@choices,$serverhomes->{$name});
2710: }
2711: }
2712: }
2713: }
2714: }
2715: return sort(@choices);
2716: }
2717:
2718: sub print_loadbalancing {
2719: my ($dom,$settings,$rowtotal) = @_;
2720: my $primary_id = &Apache::lonnet::domain($dom,'primary');
2721: my $intdom = &Apache::lonnet::internet_dom($primary_id);
2722: my $numinrow = 1;
2723: my $datatable;
2724: my %servers = &Apache::lonnet::internet_dom_servers($dom);
2725: my ($currbalancer,$currtargets,$currrules);
2726: if (keys(%servers) > 1) {
2727: if (ref($settings) eq 'HASH') {
2728: $currbalancer = $settings->{'lonhost'};
2729: $currtargets = $settings->{'targets'};
2730: $currrules = $settings->{'rules'};
2731: } else {
2732: ($currbalancer,$currtargets) =
2733: &Apache::lonnet::get_lonbalancer_config(\%servers);
2734: }
2735: } else {
2736: return;
2737: }
2738: my ($othertitle,$usertypes,$types) =
2739: &Apache::loncommon::sorted_inst_types($dom);
2740: my $rownum = 6;
2741: if (ref($types) eq 'ARRAY') {
2742: $rownum += scalar(@{$types});
2743: }
2744: my $css_class = ' class="LC_odd_row"';
2745: my $targets_div_style = 'display: none';
2746: my $disabled_div_style = 'display: block';
2747: my $homedom_div_style = 'display: none';
2748: $datatable = '<tr'.$css_class.'>'.
2749: '<td rowspan="'.$rownum.'" valign="top">'.
2750: '<p><select name="loadbalancing_lonhost" onchange="toggleTargets();">'."\n".
2751: '<option value=""';
2752: if (($currbalancer eq '') || (!grep(/^\Q$currbalancer\E$/,keys(%servers)))) {
2753: $datatable .= ' selected="selected"';
2754: } else {
2755: $targets_div_style = 'display: block';
2756: $disabled_div_style = 'display: none';
2757: if ($dom eq &Apache::lonnet::host_domain($currbalancer)) {
2758: $homedom_div_style = 'display: block';
2759: }
2760: }
2761: $datatable .= '>'.&mt('None').'</option>'."\n";
2762: foreach my $lonhost (sort(keys(%servers))) {
2763: my $selected;
2764: if ($lonhost eq $currbalancer) {
2765: $selected .= ' selected="selected"';
2766: }
2767: $datatable .= '<option value="'.$lonhost.'"'.$selected.'>'.$lonhost.'</option>'."\n";
2768: }
2769: $datatable .= '</select></p></td><td rowspan="'.$rownum.'" valign="top">'.
2770: '<div id="loadbalancing_disabled" style="'.$disabled_div_style.'">'.&mt('No dedicated Load Balancer').'</div>'."\n".
2771: '<div id="loadbalancing_targets" style="'.$targets_div_style.'">'.&mt('Offloads to:').'<br />';
2772: my ($numspares,@spares) = &count_servers($currbalancer,%servers);
2773: my @sparestypes = ('primary','default');
2774: my %typetitles = &sparestype_titles();
2775: foreach my $sparetype (@sparestypes) {
2776: my $targettable;
2777: for (my $i=0; $i<$numspares; $i++) {
2778: my $checked;
2779: if (ref($currtargets) eq 'HASH') {
2780: if (ref($currtargets->{$sparetype}) eq 'ARRAY') {
2781: if (grep(/^\Q$spares[$i]\E$/,@{$currtargets->{$sparetype}})) {
2782: $checked = ' checked="checked"';
2783: }
2784: }
2785: }
2786: my $chkboxval;
2787: if (($currbalancer ne '') && (grep((/^\Q$currbalancer\E$/,keys(%servers))))) {
2788: $chkboxval = $spares[$i];
2789: }
2790: $targettable .= '<td><label><input type="checkbox" name="loadbalancing_target_'.$sparetype.'"'.
2791: $checked.' value="'.$chkboxval.'" id="loadbalancing_target_'.$sparetype.'_'.$i.'" onclick="checkOffloads('."this,'$sparetype'".');" /><span id="loadbalancing_targettxt_'.$sparetype.'_'.$i.'"> '.$chkboxval.
2792: '</span></label></td>';
2793: my $rem = $i%($numinrow);
2794: if ($rem == 0) {
2795: if ($i > 0) {
2796: $targettable .= '</tr>';
2797: }
2798: $targettable .= '<tr>';
2799: }
2800: }
2801: if ($targettable ne '') {
2802: my $rem = $numspares%($numinrow);
2803: my $colsleft = $numinrow - $rem;
2804: if ($colsleft > 1 ) {
2805: $targettable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
2806: ' </td>';
2807: } elsif ($colsleft == 1) {
2808: $targettable .= '<td class="LC_left_item"> </td>';
2809: }
2810: $datatable .= '<i>'.$typetitles{$sparetype}.'</i><br />'.
2811: '<table><tr>'.$targettable.'</table><br />';
2812: }
2813: }
2814: $datatable .= '</div></td></tr>'.
2815: &loadbalancing_rules($dom,$intdom,$currrules,$othertitle,
2816: $usertypes,$types,\%servers,$currbalancer,
2817: $targets_div_style,$homedom_div_style,$css_class);
2818: $$rowtotal += $rownum;
2819: return $datatable;
2820: }
2821:
2822: sub loadbalancing_rules {
2823: my ($dom,$intdom,$currrules,$othertitle,$usertypes,$types,$servers,
2824: $currbalancer,$targets_div_style,$homedom_div_style,$css_class) = @_;
2825: my $output;
2826: my ($alltypes,$othertypes,$titles) =
2827: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
2828: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
2829: foreach my $type (@{$alltypes}) {
2830: my $current;
2831: if (ref($currrules) eq 'HASH') {
2832: $current = $currrules->{$type};
2833: }
2834: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
2835: if ($dom ne &Apache::lonnet::host_domain($currbalancer)) {
2836: $current = '';
2837: }
2838: }
2839: $output .= &loadbalance_rule_row($type,$titles->{$type},$current,
2840: $servers,$currbalancer,$dom,
2841: $targets_div_style,$homedom_div_style,$css_class);
2842: }
2843: }
2844: return $output;
2845: }
2846:
2847: sub loadbalancing_titles {
2848: my ($dom,$intdom,$usertypes,$types) = @_;
2849: my %othertypes = (
2850: '_LC_adv' => &mt('Advanced users from [_1]',$dom),
2851: '_LC_author' => &mt('Users from [_1] with author role',$dom),
2852: '_LC_internetdom' => &mt('Users not from [_1], but from [_2]',$dom,$intdom),
2853: '_LC_external' => &mt('Users not from [_1]',$intdom),
2854: );
2855: my @alltypes = ('_LC_adv','_LC_author','_LC_internetdom','_LC_external');
2856: if (ref($types) eq 'ARRAY') {
2857: unshift(@alltypes,@{$types},'default');
2858: }
2859: my %titles;
2860: foreach my $type (@alltypes) {
2861: if ($type =~ /^_LC_/) {
2862: $titles{$type} = $othertypes{$type};
2863: } elsif ($type eq 'default') {
2864: $titles{$type} = &mt('All users from [_1]',$dom);
2865: if (ref($types) eq 'ARRAY') {
2866: if (@{$types} > 0) {
2867: $titles{$type} = &mt('Other users from [_1]',$dom);
2868: }
2869: }
2870: } elsif (ref($usertypes) eq 'HASH') {
2871: $titles{$type} = $usertypes->{$type};
2872: }
2873: }
2874: return (\@alltypes,\%othertypes,\%titles);
2875: }
2876:
2877: sub loadbalance_rule_row {
2878: my ($type,$title,$current,$servers,$currbalancer,$dom,$targets_div_style,
2879: $homedom_div_style,$css_class) = @_;
2880: my @rulenames = ('default','homeserver');
2881: my %ruletitles = &offloadtype_text();
2882: if ($type eq '_LC_external') {
2883: push(@rulenames,'externalbalancer');
2884: } else {
2885: push(@rulenames,'specific');
2886: }
2887: push(@rulenames,'none');
2888: my $style = $targets_div_style;
2889: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
2890: $style = $homedom_div_style;
2891: }
2892: my $output =
2893: '<tr'.$css_class.'><td valign="top"><div id="balanceruletitle_'.$type.'" style="'.$style.'">'.$title.'</div></td>'."\n".
2894: '<td><div id="balancerule_'.$type.'" style="'.$style.'">'."\n";
2895: for (my $i=0; $i<@rulenames; $i++) {
2896: my $rule = $rulenames[$i];
2897: my ($checked,$extra);
2898: if ($rulenames[$i] eq 'default') {
2899: $rule = '';
2900: }
2901: if ($rulenames[$i] eq 'specific') {
2902: if (ref($servers) eq 'HASH') {
2903: my $default;
2904: if (($current ne '') && (exists($servers->{$current}))) {
2905: $checked = ' checked="checked"';
2906: }
2907: unless ($checked) {
2908: $default = ' selected="selected"';
2909: }
2910: $extra = ': <select name="loadbalancing_singleserver_'.$type.
2911: '" id="loadbalancing_singleserver_'.$type.
2912: '" onchange="singleServerToggle('."'$type'".')">'."\n".
2913: '<option value=""'.$default.'></option>'."\n";
2914: foreach my $lonhost (sort(keys(%{$servers}))) {
2915: next if ($lonhost eq $currbalancer);
2916: my $selected;
2917: if ($lonhost eq $current) {
2918: $selected = ' selected="selected"';
2919: }
2920: $extra .= '<option value="'.$lonhost.'"'.$selected.'>'.$lonhost.'</option>';
2921: }
2922: $extra .= '</select>';
2923: }
2924: } elsif ($rule eq $current) {
2925: $checked = ' checked="checked"';
2926: }
2927: $output .= '<span class="LC_nobreak"><label>'.
2928: '<input type="radio" name="loadbalancing_rules_'.$type.
2929: '" id="loadbalancing_rules_'.$type.'_'.$i.'" value="'.
2930: $rule.'" onclick="balanceruleChange('."this.form,'$type'".
2931: ')"'.$checked.' /> '.$ruletitles{$rulenames[$i]}.
2932: '</label>'.$extra.'</span><br />'."\n";
2933: }
2934: $output .= '</div></td></tr>'."\n";
2935: return $output;
2936: }
2937:
2938: sub offloadtype_text {
2939: my %ruletitles = &Apache::lonlocal::texthash (
2940: 'default' => 'Offloads to default destinations',
2941: 'homeserver' => "Offloads to user's home server",
2942: 'externalbalancer' => "Offloads to Load Balancer in user's domain",
2943: 'specific' => 'Offloads to specific server',
2944: 'none' => 'No offload',
2945: );
2946: return %ruletitles;
2947: }
2948:
2949: sub sparestype_titles {
2950: my %typestitles = &Apache::lonlocal::texthash (
2951: 'primary' => 'primary',
2952: 'default' => 'default',
2953: );
2954: return %typestitles;
2955: }
2956:
2957: sub contact_titles {
2958: my %titles = &Apache::lonlocal::texthash (
2959: 'supportemail' => 'Support E-mail address',
2960: 'adminemail' => 'Default Server Admin E-mail address',
2961: 'errormail' => 'Error reports to be e-mailed to',
2962: 'packagesmail' => 'Package update alerts to be e-mailed to',
2963: 'helpdeskmail' => 'Helpdesk requests to be e-mailed to',
2964: 'lonstatusmail' => 'E-mail from nightly status check (warnings/errors)',
2965: 'requestsmail' => 'E-mail from course requests requiring approval',
2966: );
2967: my %short_titles = &Apache::lonlocal::texthash (
2968: adminemail => 'Admin E-mail address',
2969: supportemail => 'Support E-mail',
2970: );
2971: return (\%titles,\%short_titles);
2972: }
2973:
2974: sub tool_titles {
2975: my %titles = &Apache::lonlocal::texthash (
2976: aboutme => 'Personal Information Page',
2977: blog => 'Blog',
2978: portfolio => 'Portfolio',
2979: official => 'Official courses (with institutional codes)',
2980: unofficial => 'Unofficial courses',
2981: community => 'Communities',
2982: );
2983: return %titles;
2984: }
2985:
2986: sub courserequest_titles {
2987: my %titles = &Apache::lonlocal::texthash (
2988: official => 'Official',
2989: unofficial => 'Unofficial',
2990: community => 'Communities',
2991: norequest => 'Not allowed',
2992: approval => 'Approval by Dom. Coord.',
2993: validate => 'With validation',
2994: autolimit => 'Numerical limit',
2995: unlimited => '(blank for unlimited)',
2996: );
2997: return %titles;
2998: }
2999:
3000: sub courserequest_conditions {
3001: my %conditions = &Apache::lonlocal::texthash (
3002: approval => '(Processing of request subject to approval by Domain Coordinator).',
3003: validate => '(Processing of request subject to instittutional validation).',
3004: );
3005: return %conditions;
3006: }
3007:
3008:
3009: sub print_usercreation {
3010: my ($position,$dom,$settings,$rowtotal) = @_;
3011: my $numinrow = 4;
3012: my $datatable;
3013: if ($position eq 'top') {
3014: $$rowtotal ++;
3015: my $rowcount = 0;
3016: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username');
3017: if (ref($rules) eq 'HASH') {
3018: if (keys(%{$rules}) > 0) {
3019: $datatable .= &user_formats_row('username',$settings,$rules,
3020: $ruleorder,$numinrow,$rowcount);
3021: $$rowtotal ++;
3022: $rowcount ++;
3023: }
3024: }
3025: my ($idrules,$idruleorder) = &Apache::lonnet::inst_userrules($dom,'id');
3026: if (ref($idrules) eq 'HASH') {
3027: if (keys(%{$idrules}) > 0) {
3028: $datatable .= &user_formats_row('id',$settings,$idrules,
3029: $idruleorder,$numinrow,$rowcount);
3030: $$rowtotal ++;
3031: $rowcount ++;
3032: }
3033: }
3034: my ($emailrules,$emailruleorder) =
3035: &Apache::lonnet::inst_userrules($dom,'email');
3036: if (ref($emailrules) eq 'HASH') {
3037: if (keys(%{$emailrules}) > 0) {
3038: $datatable .= &user_formats_row('email',$settings,$emailrules,
3039: $emailruleorder,$numinrow,$rowcount);
3040: $$rowtotal ++;
3041: $rowcount ++;
3042: }
3043: }
3044: if ($rowcount == 0) {
3045: $datatable .= '<tr><td colspan="2">'.&mt('No format rules have been defined for usernames or IDs in this domain.').'</td></tr>';
3046: $$rowtotal ++;
3047: $rowcount ++;
3048: }
3049: } elsif ($position eq 'middle') {
3050: my @creators = ('author','course','requestcrs','selfcreate');
3051: my ($rules,$ruleorder) =
3052: &Apache::lonnet::inst_userrules($dom,'username');
3053: my %lt = &usercreation_types();
3054: my %checked;
3055: my @selfcreate;
3056: if (ref($settings) eq 'HASH') {
3057: if (ref($settings->{'cancreate'}) eq 'HASH') {
3058: foreach my $item (@creators) {
3059: $checked{$item} = $settings->{'cancreate'}{$item};
3060: }
3061: if (ref($settings->{'cancreate'}{'selfcreate'}) eq 'ARRAY') {
3062: @selfcreate = @{$settings->{'cancreate'}{'selfcreate'}};
3063: } elsif ($settings->{'cancreate'}{'selfcreate'} ne '') {
3064: if ($settings->{'cancreate'}{'selfcreate'} eq 'any') {
3065: @selfcreate = ('email','login','sso');
3066: } elsif ($settings->{'cancreate'}{'selfcreate'} ne 'none') {
3067: @selfcreate = ($settings->{'cancreate'}{'selfcreate'});
3068: }
3069: }
3070: } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {
3071: foreach my $item (@creators) {
3072: if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {
3073: $checked{$item} = 'none';
3074: }
3075: }
3076: }
3077: }
3078: my $rownum = 0;
3079: foreach my $item (@creators) {
3080: $rownum ++;
3081: if ($item ne 'selfcreate') {
3082: if ($checked{$item} eq '') {
3083: $checked{$item} = 'any';
3084: }
3085: }
3086: my $css_class;
3087: if ($rownum%2) {
3088: $css_class = '';
3089: } else {
3090: $css_class = ' class="LC_odd_row" ';
3091: }
3092: $datatable .= '<tr'.$css_class.'>'.
3093: '<td><span class="LC_nobreak">'.$lt{$item}.
3094: '</span></td><td align="right">';
3095: my @options;
3096: if ($item eq 'selfcreate') {
3097: push(@options,('email','login','sso'));
3098: } else {
3099: @options = ('any');
3100: if (ref($rules) eq 'HASH') {
3101: if (keys(%{$rules}) > 0) {
3102: push(@options,('official','unofficial'));
3103: }
3104: }
3105: push(@options,'none');
3106: }
3107: foreach my $option (@options) {
3108: my $type = 'radio';
3109: my $check = ' ';
3110: if ($item eq 'selfcreate') {
3111: $type = 'checkbox';
3112: if (grep(/^\Q$option\E$/,@selfcreate)) {
3113: $check = ' checked="checked" ';
3114: }
3115: } else {
3116: if ($checked{$item} eq $option) {
3117: $check = ' checked="checked" ';
3118: }
3119: }
3120: $datatable .= '<span class="LC_nobreak"><label>'.
3121: '<input type="'.$type.'" name="can_createuser_'.
3122: $item.'" value="'.$option.'"'.$check.'/> '.
3123: $lt{$option}.'</label> </span>';
3124: }
3125: $datatable .= '</td></tr>';
3126: }
3127: my ($othertitle,$usertypes,$types) =
3128: &Apache::loncommon::sorted_inst_types($dom);
3129: if (ref($usertypes) eq 'HASH') {
3130: if (keys(%{$usertypes}) > 0) {
3131: my $createsettings;
3132: if (ref($settings) eq 'HASH') {
3133: $createsettings = $settings->{cancreate};
3134: }
3135: $datatable .= &insttypes_row($createsettings,$types,$usertypes,
3136: $dom,$numinrow,$othertitle,
3137: 'statustocreate');
3138: $$rowtotal ++;
3139: }
3140: }
3141: } else {
3142: my @contexts = ('author','course','domain');
3143: my @authtypes = ('int','krb4','krb5','loc');
3144: my %checked;
3145: if (ref($settings) eq 'HASH') {
3146: if (ref($settings->{'authtypes'}) eq 'HASH') {
3147: foreach my $item (@contexts) {
3148: if (ref($settings->{'authtypes'}{$item}) eq 'HASH') {
3149: foreach my $auth (@authtypes) {
3150: if ($settings->{'authtypes'}{$item}{$auth}) {
3151: $checked{$item}{$auth} = ' checked="checked" ';
3152: }
3153: }
3154: }
3155: }
3156: }
3157: } else {
3158: foreach my $item (@contexts) {
3159: foreach my $auth (@authtypes) {
3160: $checked{$item}{$auth} = ' checked="checked" ';
3161: }
3162: }
3163: }
3164: my %title = &context_names();
3165: my %authname = &authtype_names();
3166: my $rownum = 0;
3167: my $css_class;
3168: foreach my $item (@contexts) {
3169: if ($rownum%2) {
3170: $css_class = '';
3171: } else {
3172: $css_class = ' class="LC_odd_row" ';
3173: }
3174: $datatable .= '<tr'.$css_class.'>'.
3175: '<td>'.$title{$item}.
3176: '</td><td class="LC_left_item">'.
3177: '<span class="LC_nobreak">';
3178: foreach my $auth (@authtypes) {
3179: $datatable .= '<label>'.
3180: '<input type="checkbox" name="'.$item.'_auth" '.
3181: $checked{$item}{$auth}.' value="'.$auth.'" />'.
3182: $authname{$auth}.'</label> ';
3183: }
3184: $datatable .= '</span></td></tr>';
3185: $rownum ++;
3186: }
3187: $$rowtotal += $rownum;
3188: }
3189: return $datatable;
3190: }
3191:
3192: sub user_formats_row {
3193: my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount) = @_;
3194: my $output;
3195: my %text = (
3196: 'username' => 'new usernames',
3197: 'id' => 'IDs',
3198: 'email' => 'self-created accounts (e-mail)',
3199: );
3200: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
3201: $output = '<tr '.$css_class.'>'.
3202: '<td><span class="LC_nobreak">';
3203: if ($type eq 'email') {
3204: $output .= &mt("Formats disallowed for $text{$type}: ");
3205: } else {
3206: $output .= &mt("Format rules to check for $text{$type}: ");
3207: }
3208: $output .= '</span></td>'.
3209: '<td class="LC_left_item" colspan="2"><table>';
3210: my $rem;
3211: if (ref($ruleorder) eq 'ARRAY') {
3212: for (my $i=0; $i<@{$ruleorder}; $i++) {
3213: if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
3214: my $rem = $i%($numinrow);
3215: if ($rem == 0) {
3216: if ($i > 0) {
3217: $output .= '</tr>';
3218: }
3219: $output .= '<tr>';
3220: }
3221: my $check = ' ';
3222: if (ref($settings) eq 'HASH') {
3223: if (ref($settings->{$type.'_rule'}) eq 'ARRAY') {
3224: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) {
3225: $check = ' checked="checked" ';
3226: }
3227: }
3228: }
3229: $output .= '<td class="LC_left_item">'.
3230: '<span class="LC_nobreak"><label>'.
3231: '<input type="checkbox" name="'.$type.'_rule" '.
3232: 'value="'.$ruleorder->[$i].'"'.$check.'/>'.
3233: $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
3234: }
3235: }
3236: $rem = @{$ruleorder}%($numinrow);
3237: }
3238: my $colsleft = $numinrow - $rem;
3239: if ($colsleft > 1 ) {
3240: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
3241: ' </td>';
3242: } elsif ($colsleft == 1) {
3243: $output .= '<td class="LC_left_item"> </td>';
3244: }
3245: $output .= '</tr></table></td></tr>';
3246: return $output;
3247: }
3248:
3249: sub usercreation_types {
3250: my %lt = &Apache::lonlocal::texthash (
3251: author => 'When adding a co-author',
3252: course => 'When adding a user to a course',
3253: requestcrs => 'When requesting a course',
3254: selfcreate => 'User creates own account',
3255: any => 'Any',
3256: official => 'Institutional only ',
3257: unofficial => 'Non-institutional only',
3258: email => 'E-mail address',
3259: login => 'Institutional Login',
3260: sso => 'SSO',
3261: none => 'None',
3262: );
3263: return %lt;
3264: }
3265:
3266: sub authtype_names {
3267: my %lt = &Apache::lonlocal::texthash(
3268: int => 'Internal',
3269: krb4 => 'Kerberos 4',
3270: krb5 => 'Kerberos 5',
3271: loc => 'Local',
3272: );
3273: return %lt;
3274: }
3275:
3276: sub context_names {
3277: my %context_title = &Apache::lonlocal::texthash(
3278: author => 'Creating users when an Author',
3279: course => 'Creating users when in a course',
3280: domain => 'Creating users when a Domain Coordinator',
3281: );
3282: return %context_title;
3283: }
3284:
3285: sub print_usermodification {
3286: my ($position,$dom,$settings,$rowtotal) = @_;
3287: my $numinrow = 4;
3288: my ($context,$datatable,$rowcount);
3289: if ($position eq 'top') {
3290: $rowcount = 0;
3291: $context = 'author';
3292: foreach my $role ('ca','aa') {
3293: $datatable .= &modifiable_userdata_row($context,$role,$settings,
3294: $numinrow,$rowcount);
3295: $$rowtotal ++;
3296: $rowcount ++;
3297: }
3298: } elsif ($position eq 'middle') {
3299: $context = 'course';
3300: $rowcount = 0;
3301: foreach my $role ('st','ep','ta','in','cr') {
3302: $datatable .= &modifiable_userdata_row($context,$role,$settings,
3303: $numinrow,$rowcount);
3304: $$rowtotal ++;
3305: $rowcount ++;
3306: }
3307: } elsif ($position eq 'bottom') {
3308: $context = 'selfcreate';
3309: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
3310: $usertypes->{'default'} = $othertitle;
3311: if (ref($types) eq 'ARRAY') {
3312: push(@{$types},'default');
3313: $usertypes->{'default'} = $othertitle;
3314: foreach my $status (@{$types}) {
3315: $datatable .= &modifiable_userdata_row($context,$status,$settings,
3316: $numinrow,$rowcount,$usertypes);
3317: $$rowtotal ++;
3318: $rowcount ++;
3319: }
3320: }
3321: }
3322: return $datatable;
3323: }
3324:
3325: sub print_defaults {
3326: my ($dom,$rowtotal) = @_;
3327: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def',
3328: 'datelocale_def','portal_def');
3329: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
3330: my $titles = &defaults_titles($dom);
3331: my $rownum = 0;
3332: my ($datatable,$css_class);
3333: foreach my $item (@items) {
3334: if ($rownum%2) {
3335: $css_class = '';
3336: } else {
3337: $css_class = ' class="LC_odd_row" ';
3338: }
3339: $datatable .= '<tr'.$css_class.'>'.
3340: '<td><span class="LC_nobreak">'.$titles->{$item}.
3341: '</span></td><td class="LC_right_item">';
3342: if ($item eq 'auth_def') {
3343: my @authtypes = ('internal','krb4','krb5','localauth');
3344: my %shortauth = (
3345: internal => 'int',
3346: krb4 => 'krb4',
3347: krb5 => 'krb5',
3348: localauth => 'loc'
3349: );
3350: my %authnames = &authtype_names();
3351: foreach my $auth (@authtypes) {
3352: my $checked = ' ';
3353: if ($domdefaults{$item} eq $auth) {
3354: $checked = ' checked="checked" ';
3355: }
3356: $datatable .= '<label><input type="radio" name="'.$item.
3357: '" value="'.$auth.'"'.$checked.'/>'.
3358: $authnames{$shortauth{$auth}}.'</label> ';
3359: }
3360: } elsif ($item eq 'timezone_def') {
3361: my $includeempty = 1;
3362: $datatable .= &Apache::loncommon::select_timezone($item,$domdefaults{$item},undef,$includeempty);
3363: } elsif ($item eq 'datelocale_def') {
3364: my $includeempty = 1;
3365: $datatable .= &Apache::loncommon::select_datelocale($item,$domdefaults{$item},undef,$includeempty);
3366: } else {
3367: my $size;
3368: if ($item eq 'portal_def') {
3369: $size = ' size="25"';
3370: }
3371: $datatable .= '<input type="text" name="'.$item.'" value="'.
3372: $domdefaults{$item}.'"'.$size.' />';
3373: }
3374: $datatable .= '</td></tr>';
3375: $rownum ++;
3376: }
3377: $$rowtotal += $rownum;
3378: return $datatable;
3379: }
3380:
3381: sub defaults_titles {
3382: my ($dom) = @_;
3383: my %titles = &Apache::lonlocal::texthash (
3384: 'auth_def' => 'Default authentication type',
3385: 'auth_arg_def' => 'Default authentication argument',
3386: 'lang_def' => 'Default language',
3387: 'timezone_def' => 'Default timezone',
3388: 'datelocale_def' => 'Default locale for dates',
3389: 'portal_def' => 'Portal/Default URL',
3390: );
3391: if ($dom) {
3392: my $uprimary_id = &Apache::lonnet::domain($dom,'primary');
3393: my $uint_dom = &Apache::lonnet::internet_dom($uprimary_id);
3394: my $protocol = $Apache::lonnet::protocol{$uprimary_id};
3395: $protocol = 'http' if ($protocol ne 'https');
3396: if ($uint_dom) {
3397: $titles{'portal_def'} .= ' '.&mt('(for example: [_1])',$protocol.'://loncapa.'.
3398: $uint_dom);
3399: }
3400: }
3401: return (\%titles);
3402: }
3403:
3404: sub print_scantronformat {
3405: my ($r,$dom,$confname,$settings,$rowtotal) = @_;
3406: my $itemcount = 1;
3407: my ($datatable,$css_class,$scantronurl,$is_custom,%error,%scantronurls,
3408: %confhash);
3409: my $switchserver = &check_switchserver($dom,$confname);
3410: my %lt = &Apache::lonlocal::texthash (
3411: default => 'Default bubblesheet format file error',
3412: custom => 'Custom bubblesheet format file error',
3413: );
3414: my %scantronfiles = (
3415: default => 'default.tab',
3416: custom => 'custom.tab',
3417: );
3418: foreach my $key (keys(%scantronfiles)) {
3419: $scantronurls{$key} = '/res/'.$dom.'/'.$confname.'/scantron/'
3420: .$scantronfiles{$key};
3421: }
3422: my @defaultinfo = &Apache::lonnet::stat_file($scantronurls{'default'});
3423: if ((!@defaultinfo) || ($defaultinfo[0] eq 'no_such_dir')) {
3424: if (!$switchserver) {
3425: my $servadm = $r->dir_config('lonAdmEMail');
3426: my ($configuserok,$author_ok) = &config_check($dom,$confname,$servadm);
3427: if ($configuserok eq 'ok') {
3428: if ($author_ok eq 'ok') {
3429: my %legacyfile = (
3430: default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab',
3431: custom => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab',
3432: );
3433: my %md5chk;
3434: foreach my $type (keys(%legacyfile)) {
3435: ($md5chk{$type}) = split(/ /,`md5sum $legacyfile{$type}`);
3436: chomp($md5chk{$type});
3437: }
3438: if ($md5chk{'default'} ne $md5chk{'custom'}) {
3439: foreach my $type (keys(%legacyfile)) {
3440: ($scantronurls{$type},my $error) =
3441: &legacy_scantronformat($r,$dom,$confname,
3442: $type,$legacyfile{$type},
3443: $scantronurls{$type},
3444: $scantronfiles{$type});
3445: if ($error ne '') {
3446: $error{$type} = $error;
3447: }
3448: }
3449: if (keys(%error) == 0) {
3450: $is_custom = 1;
3451: $confhash{'scantron'}{'scantronformat'} =
3452: $scantronurls{'custom'};
3453: my $putresult =
3454: &Apache::lonnet::put_dom('configuration',
3455: \%confhash,$dom);
3456: if ($putresult ne 'ok') {
3457: $error{'custom'} =
3458: '<span class="LC_error">'.
3459: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
3460: }
3461: }
3462: } else {
3463: ($scantronurls{'default'},my $error) =
3464: &legacy_scantronformat($r,$dom,$confname,
3465: 'default',$legacyfile{'default'},
3466: $scantronurls{'default'},
3467: $scantronfiles{'default'});
3468: if ($error eq '') {
3469: $confhash{'scantron'}{'scantronformat'} = '';
3470: my $putresult =
3471: &Apache::lonnet::put_dom('configuration',
3472: \%confhash,$dom);
3473: if ($putresult ne 'ok') {
3474: $error{'default'} =
3475: '<span class="LC_error">'.
3476: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
3477: }
3478: } else {
3479: $error{'default'} = $error;
3480: }
3481: }
3482: }
3483: }
3484: } else {
3485: $error{'default'} = &mt("Unable to copy default bubblesheet formatfile to domain's RES space: [_1]",$switchserver);
3486: }
3487: }
3488: if (ref($settings) eq 'HASH') {
3489: if ($settings->{'scantronformat'} eq "/res/$dom/$confname/scantron/custom.tab") {
3490: my @info = &Apache::lonnet::stat_file($settings->{'scantronformat'});
3491: if ((!@info) || ($info[0] eq 'no_such_dir')) {
3492: $scantronurl = '';
3493: } else {
3494: $scantronurl = $settings->{'scantronformat'};
3495: }
3496: $is_custom = 1;
3497: } else {
3498: $scantronurl = $scantronurls{'default'};
3499: }
3500: } else {
3501: if ($is_custom) {
3502: $scantronurl = $scantronurls{'custom'};
3503: } else {
3504: $scantronurl = $scantronurls{'default'};
3505: }
3506: }
3507: $css_class = $itemcount%2?' class="LC_odd_row"':'';
3508: $datatable .= '<tr'.$css_class.'>';
3509: if (!$is_custom) {
3510: $datatable .= '<td>'.&mt('Default in use:').'<br />'.
3511: '<span class="LC_nobreak">';
3512: if ($scantronurl) {
3513: $datatable .= '<a href="'.$scantronurl.'" target="_blank">'.
3514: &mt('Default bubblesheet format file').'</a>';
3515: } else {
3516: $datatable = &mt('File unavailable for display');
3517: }
3518: $datatable .= '</span></td>';
3519: if (keys(%error) == 0) {
3520: $datatable .= '<td valign="bottom">';
3521: if (!$switchserver) {
3522: $datatable .= &mt('Upload:').'<br />';
3523: }
3524: } else {
3525: my $errorstr;
3526: foreach my $key (sort(keys(%error))) {
3527: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
3528: }
3529: $datatable .= '<td>'.$errorstr;
3530: }
3531: } else {
3532: if (keys(%error) > 0) {
3533: my $errorstr;
3534: foreach my $key (sort(keys(%error))) {
3535: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
3536: }
3537: $datatable .= '<td>'.$errorstr.'</td><td> ';
3538: } elsif ($scantronurl) {
3539: $datatable .= '<td><span class="LC_nobreak">'.
3540: '<a href="'.$scantronurl.'" target="_blank">'.
3541: &mt('Custom bubblesheet format file').'</a><label>'.
3542: '<input type="checkbox" name="scantronformat_del"'.
3543: '" value="1" />'.&mt('Delete?').'</label></span></td>'.
3544: '<td><span class="LC_nobreak"> '.
3545: &mt('Replace:').'</span><br />';
3546: }
3547: }
3548: if (keys(%error) == 0) {
3549: if ($switchserver) {
3550: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
3551: } else {
3552: $datatable .='<span class="LC_nobreak"> '.
3553: '<input type="file" name="scantronformat" /></span>';
3554: }
3555: }
3556: $datatable .= '</td></tr>';
3557: $$rowtotal ++;
3558: return $datatable;
3559: }
3560:
3561: sub legacy_scantronformat {
3562: my ($r,$dom,$confname,$file,$legacyfile,$newurl,$newfile) = @_;
3563: my ($url,$error);
3564: my @statinfo = &Apache::lonnet::stat_file($newurl);
3565: if ((!@statinfo) || ($statinfo[0] eq 'no_such_dir')) {
3566: (my $result,$url) =
3567: &publishlogo($r,'copy',$legacyfile,$dom,$confname,'scantron',
3568: '','',$newfile);
3569: if ($result ne 'ok') {
3570: $error = &mt("An error occurred publishing the [_1] bubblesheet format file in RES space. Error was: [_2].",$newfile,$result);
3571: }
3572: }
3573: return ($url,$error);
3574: }
3575:
3576: sub print_coursecategories {
3577: my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;
3578: my $datatable;
3579: if ($position eq 'top') {
3580: my $toggle_cats_crs = ' ';
3581: my $toggle_cats_dom = ' checked="checked" ';
3582: my $can_cat_crs = ' ';
3583: my $can_cat_dom = ' checked="checked" ';
3584: my $toggle_catscomm_comm = ' ';
3585: my $toggle_catscomm_dom = ' checked="checked" ';
3586: my $can_catcomm_comm = ' ';
3587: my $can_catcomm_dom = ' checked="checked" ';
3588:
3589: if (ref($settings) eq 'HASH') {
3590: if ($settings->{'togglecats'} eq 'crs') {
3591: $toggle_cats_crs = $toggle_cats_dom;
3592: $toggle_cats_dom = ' ';
3593: }
3594: if ($settings->{'categorize'} eq 'crs') {
3595: $can_cat_crs = $can_cat_dom;
3596: $can_cat_dom = ' ';
3597: }
3598: if ($settings->{'togglecatscomm'} eq 'comm') {
3599: $toggle_catscomm_comm = $toggle_catscomm_dom;
3600: $toggle_catscomm_dom = ' ';
3601: }
3602: if ($settings->{'categorizecomm'} eq 'comm') {
3603: $can_catcomm_comm = $can_catcomm_dom;
3604: $can_catcomm_dom = ' ';
3605: }
3606: }
3607: my %title = &Apache::lonlocal::texthash (
3608: togglecats => 'Show/Hide a course in catalog',
3609: togglecatscomm => 'Show/Hide a community in catalog',
3610: categorize => 'Assign a category to a course',
3611: categorizecomm => 'Assign a category to a community',
3612: );
3613: my %level = &Apache::lonlocal::texthash (
3614: dom => 'Set in Domain',
3615: crs => 'Set in Course',
3616: comm => 'Set in Community',
3617: );
3618: $datatable = '<tr class="LC_odd_row">'.
3619: '<td>'.$title{'togglecats'}.'</td>'.
3620: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3621: '<input type="radio" name="togglecats"'.
3622: $toggle_cats_dom.' value="dom" />'.$level{'dom'}.'</label> '.
3623: '<label><input type="radio" name="togglecats"'.
3624: $toggle_cats_crs.' value="crs" />'.$level{'crs'}.'</label></span></td>'.
3625: '</tr><tr>'.
3626: '<td>'.$title{'categorize'}.'</td>'.
3627: '<td class="LC_right_item"><span class="LC_nobreak">'.
3628: '<label><input type="radio" name="categorize"'.
3629: $can_cat_dom.' value="dom" />'.$level{'dom'}.'</label> '.
3630: '<label><input type="radio" name="categorize"'.
3631: $can_cat_crs.'value="crs" />'.$level{'crs'}.'</label></span></td>'.
3632: '</tr><tr class="LC_odd_row">'.
3633: '<td>'.$title{'togglecatscomm'}.'</td>'.
3634: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3635: '<input type="radio" name="togglecatscomm"'.
3636: $toggle_catscomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
3637: '<label><input type="radio" name="togglecatscomm"'.
3638: $toggle_catscomm_comm.' value="comm" />'.$level{'comm'}.'</label></span></td>'.
3639: '</tr><tr>'.
3640: '<td>'.$title{'categorizecomm'}.'</td>'.
3641: '<td class="LC_right_item"><span class="LC_nobreak">'.
3642: '<label><input type="radio" name="categorizecomm"'.
3643: $can_catcomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
3644: '<label><input type="radio" name="categorizecomm"'.
3645: $can_catcomm_comm.'value="comm" />'.$level{'comm'}.'</label></span></td>'.
3646: '</tr>';
3647: $$rowtotal += 4;
3648: } else {
3649: my $css_class;
3650: my $itemcount = 1;
3651: my $cathash;
3652: if (ref($settings) eq 'HASH') {
3653: $cathash = $settings->{'cats'};
3654: }
3655: if (ref($cathash) eq 'HASH') {
3656: my (@cats,@trails,%allitems,%idx,@jsarray);
3657: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
3658: \%allitems,\%idx,\@jsarray);
3659: my $maxdepth = scalar(@cats);
3660: my $colattrib = '';
3661: if ($maxdepth > 2) {
3662: $colattrib = ' colspan="2" ';
3663: }
3664: my @path;
3665: if (@cats > 0) {
3666: if (ref($cats[0]) eq 'ARRAY') {
3667: my $numtop = @{$cats[0]};
3668: my $maxnum = $numtop;
3669: my %default_names = (
3670: instcode => &mt('Official courses'),
3671: communities => &mt('Communities'),
3672: );
3673:
3674: if ((!grep(/^instcode$/,@{$cats[0]})) ||
3675: ($cathash->{'instcode::0'} eq '') ||
3676: (!grep(/^communities$/,@{$cats[0]})) ||
3677: ($cathash->{'communities::0'} eq '')) {
3678: $maxnum ++;
3679: }
3680: my $lastidx;
3681: for (my $i=0; $i<$numtop; $i++) {
3682: my $parent = $cats[0][$i];
3683: $css_class = $itemcount%2?' class="LC_odd_row"':'';
3684: my $item = &escape($parent).'::0';
3685: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$item','$idx{$item}'".');"';
3686: $lastidx = $idx{$item};
3687: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
3688: .'<select name="'.$item.'"'.$chgstr.'>';
3689: for (my $k=0; $k<=$maxnum; $k++) {
3690: my $vpos = $k+1;
3691: my $selstr;
3692: if ($k == $i) {
3693: $selstr = ' selected="selected" ';
3694: }
3695: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
3696: }
3697: $datatable .= '</select></td><td>';
3698: if ($parent eq 'instcode' || $parent eq 'communities') {
3699: $datatable .= '<span class="LC_nobreak">'
3700: .$default_names{$parent}.'</span>';
3701: if ($parent eq 'instcode') {
3702: $datatable .= '<br /><span class="LC_nobreak">('
3703: .&mt('with institutional codes')
3704: .')</span></td><td'.$colattrib.'>';
3705: } else {
3706: $datatable .= '<table><tr><td>';
3707: }
3708: $datatable .= '<span class="LC_nobreak">'
3709: .'<label><input type="radio" name="'
3710: .$parent.'" value="1" checked="checked" />'
3711: .&mt('Display').'</label>';
3712: if ($parent eq 'instcode') {
3713: $datatable .= ' ';
3714: } else {
3715: $datatable .= '</span></td></tr><tr><td>'
3716: .'<span class="LC_nobreak">';
3717: }
3718: $datatable .= '<label><input type="radio" name="'
3719: .$parent.'" value="0" />'
3720: .&mt('Do not display').'</label></span>';
3721: if ($parent eq 'communities') {
3722: $datatable .= '</td></tr></table>';
3723: }
3724: $datatable .= '</td>';
3725: } else {
3726: $datatable .= $parent
3727: .' <label><input type="checkbox" name="deletecategory" '
3728: .'value="'.$item.'" />'.&mt('Delete').'</label></span></td>';
3729: }
3730: my $depth = 1;
3731: push(@path,$parent);
3732: $datatable .= &build_category_rows($itemcount,\@cats,$depth,$parent,\@path,\%idx);
3733: pop(@path);
3734: $datatable .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
3735: $itemcount ++;
3736: }
3737: $css_class = $itemcount%2?' class="LC_odd_row"':'';
3738: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','$lastidx'".');"';
3739: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="addcategory_pos"'.$chgstr.'>';
3740: for (my $k=0; $k<=$maxnum; $k++) {
3741: my $vpos = $k+1;
3742: my $selstr;
3743: if ($k == $numtop) {
3744: $selstr = ' selected="selected" ';
3745: }
3746: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
3747: }
3748: $datatable .= '</select></span></td><td colspan="2">'.&mt('Add category:').' '
3749: .'<input type="text" size="20" name="addcategory_name" value="" /></td>'
3750: .'</tr>'."\n";
3751: $itemcount ++;
3752: foreach my $default ('instcode','communities') {
3753: if ((!grep(/^\Q$default\E$/,@{$cats[0]})) || ($cathash->{$default.'::0'} eq '')) {
3754: $css_class = $itemcount%2?' class="LC_odd_row"':'';
3755: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','$lastidx'".');"';
3756: $datatable .= '<tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr><tr '.$css_class.'><td>'.
3757: '<span class="LC_nobreak"><select name="'.$default.'_pos"'.$chgstr.'>';
3758: for (my $k=0; $k<=$maxnum; $k++) {
3759: my $vpos = $k+1;
3760: my $selstr;
3761: if ($k == $maxnum) {
3762: $selstr = ' selected="selected" ';
3763: }
3764: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
3765: }
3766: $datatable .= '</select></span></td>'.
3767: '<td><span class="LC_nobreak">'.
3768: $default_names{$default}.'</span>';
3769: if ($default eq 'instcode') {
3770: $datatable .= '<br /><span class="LC_nobreak">('
3771: .&mt('with institutional codes').')</span>';
3772: }
3773: $datatable .= '</td>'
3774: .'<td><span class="LC_nobreak"><label><input type="radio" name="'.$default.'" value="1" />'
3775: .&mt('Display').'</label> '
3776: .'<label><input type="radio" name="'.$default.'" value="0" checked="checked"/>'
3777: .&mt('Do not display').'</label></span></td></tr>';
3778: }
3779: }
3780: }
3781: } else {
3782: $datatable .= &initialize_categories($itemcount);
3783: }
3784: } else {
3785: $datatable .= '<td class="LC_right_item">'.$hdritem->{'header'}->[0]->{'col2'}.'</td>'
3786: .&initialize_categories($itemcount);
3787: }
3788: $$rowtotal += $itemcount;
3789: }
3790: return $datatable;
3791: }
3792:
3793: sub print_serverstatuses {
3794: my ($dom,$settings,$rowtotal) = @_;
3795: my $datatable;
3796: my @pages = &serverstatus_pages();
3797: my (%namedaccess,%machineaccess);
3798: foreach my $type (@pages) {
3799: $namedaccess{$type} = '';
3800: $machineaccess{$type}= '';
3801: }
3802: if (ref($settings) eq 'HASH') {
3803: foreach my $type (@pages) {
3804: if (exists($settings->{$type})) {
3805: if (ref($settings->{$type}) eq 'HASH') {
3806: foreach my $key (keys(%{$settings->{$type}})) {
3807: if ($key eq 'namedusers') {
3808: $namedaccess{$type} = $settings->{$type}->{$key};
3809: } elsif ($key eq 'machines') {
3810: $machineaccess{$type} = $settings->{$type}->{$key};
3811: }
3812: }
3813: }
3814: }
3815: }
3816: }
3817: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
3818: my $rownum = 0;
3819: my $css_class;
3820: foreach my $type (@pages) {
3821: $rownum ++;
3822: $css_class = $rownum%2?' class="LC_odd_row"':'';
3823: $datatable .= '<tr'.$css_class.'>'.
3824: '<td><span class="LC_nobreak">'.
3825: $titles->{$type}.'</span></td>'.
3826: '<td class="LC_left_item">'.
3827: '<input type="text" name="'.$type.'_namedusers" '.
3828: 'value="'.$namedaccess{$type}.'" size="30" /></td>'.
3829: '<td class="LC_right_item">'.
3830: '<span class="LC_nobreak">'.
3831: '<input type="text" name="'.$type.'_machines" '.
3832: 'value="'.$machineaccess{$type}.'" size="10" />'.
3833: '</td></tr>'."\n";
3834: }
3835: $$rowtotal += $rownum;
3836: return $datatable;
3837: }
3838:
3839: sub serverstatus_pages {
3840: return ('userstatus','lonstatus','loncron','server-status','codeversions',
3841: 'clusterstatus','metadata_keywords','metadata_harvest',
3842: 'takeoffline','takeonline','showenv','toggledebug','ping','domconf');
3843: }
3844:
3845: sub coursecategories_javascript {
3846: my ($settings) = @_;
3847: my ($output,$jstext,$cathash);
3848: if (ref($settings) eq 'HASH') {
3849: $cathash = $settings->{'cats'};
3850: }
3851: if (ref($cathash) eq 'HASH') {
3852: my (@cats,@jsarray,%idx);
3853: &Apache::loncommon::gather_categories($cathash,\@cats,\%idx,\@jsarray);
3854: if (@jsarray > 0) {
3855: $jstext = ' var categories = Array('.scalar(@jsarray).');'."\n";
3856: for (my $i=0; $i<@jsarray; $i++) {
3857: if (ref($jsarray[$i]) eq 'ARRAY') {
3858: my $catstr = join('","',@{$jsarray[$i]});
3859: $jstext .= ' categories['.$i.'] = Array("'.$catstr.'");'."\n";
3860: }
3861: }
3862: }
3863: } else {
3864: $jstext = ' var categories = Array(1);'."\n".
3865: ' categories[0] = Array("instcode_pos");'."\n";
3866: }
3867: my $instcode_reserved = &mt('The name: "instcode" is a reserved category');
3868: my $communities_reserved = &mt('The name: "communities" is a reserved category');
3869: my $choose_again = '\\n'.&mt('Please use a different name for the new top level category');
3870: $output = <<"ENDSCRIPT";
3871: <script type="text/javascript">
3872: // <![CDATA[
3873: function reorderCats(form,parent,item,idx) {
3874: var changedVal;
3875: $jstext
3876: var newpos = 'addcategory_pos';
3877: var current = new Array;
3878: if (parent == '') {
3879: var has_instcode = 0;
3880: var maxtop = categories[idx].length;
3881: for (var j=0; j<maxtop; j++) {
3882: if (categories[idx][j] == 'instcode::0') {
3883: has_instcode == 1;
3884: }
3885: }
3886: if (has_instcode == 0) {
3887: categories[idx][maxtop] = 'instcode_pos';
3888: }
3889: } else {
3890: newpos += '_'+parent;
3891: }
3892: var maxh = 1 + categories[idx].length;
3893: var current = new Array;
3894: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
3895: if (item == newpos) {
3896: changedVal = newitemVal;
3897: } else {
3898: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
3899: current[newitemVal] = newpos;
3900: }
3901: for (var i=0; i<categories[idx].length; i++) {
3902: var elementName = categories[idx][i];
3903: if (elementName != item) {
3904: if (form.elements[elementName]) {
3905: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
3906: current[currVal] = elementName;
3907: }
3908: }
3909: }
3910: var oldVal;
3911: for (var j=0; j<maxh; j++) {
3912: if (current[j] == undefined) {
3913: oldVal = j;
3914: }
3915: }
3916: if (oldVal < changedVal) {
3917: for (var k=oldVal+1; k<=changedVal ; k++) {
3918: var elementName = current[k];
3919: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
3920: }
3921: } else {
3922: for (var k=changedVal; k<oldVal; k++) {
3923: var elementName = current[k];
3924: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
3925: }
3926: }
3927: return;
3928: }
3929:
3930: function categoryCheck(form) {
3931: if (form.elements['addcategory_name'].value == 'instcode') {
3932: alert('$instcode_reserved\\n$choose_again');
3933: return false;
3934: }
3935: if (form.elements['addcategory_name'].value == 'communities') {
3936: alert('$communities_reserved\\n$choose_again');
3937: return false;
3938: }
3939: return true;
3940: }
3941:
3942: // ]]>
3943: </script>
3944:
3945: ENDSCRIPT
3946: return $output;
3947: }
3948:
3949: sub initialize_categories {
3950: my ($itemcount) = @_;
3951: my ($datatable,$css_class,$chgstr);
3952: my %default_names = (
3953: instcode => 'Official courses (with institutional codes)',
3954: communities => 'Communities',
3955: );
3956: my $select0 = ' selected="selected"';
3957: my $select1 = '';
3958: foreach my $default ('instcode','communities') {
3959: $css_class = $itemcount%2?' class="LC_odd_row"':'';
3960: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'',$default"."_pos','0'".');"';
3961: if ($default eq 'communities') {
3962: $select1 = $select0;
3963: $select0 = '';
3964: }
3965: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
3966: .'<select name="'.$default.'_pos">'
3967: .'<option value="0"'.$select0.'>1</option>'
3968: .'<option value="1"'.$select1.'>2</option>'
3969: .'<option value="2">3</option></select> '
3970: .$default_names{$default}
3971: .'</span></td><td><span class="LC_nobreak">'
3972: .'<label><input type="radio" name="'.$default.'" value="1" checked="checked" />'
3973: .&mt('Display').'</label> <label>'
3974: .'<input type="radio" name="'.$default.'" value="0" />'.&mt('Do not display')
3975: .'</label></span></td></tr>';
3976: $itemcount ++;
3977: }
3978: $css_class = $itemcount%2?' class="LC_odd_row"':'';
3979: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','0'".');"';
3980: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
3981: .'<select name="addcategory_pos"'.$chgstr.'>'
3982: .'<option value="0">1</option>'
3983: .'<option value="1">2</option>'
3984: .'<option value="2" selected="selected">3</option></select> '
3985: .&mt('Add category').'</td><td>'.&mt('Name:')
3986: .' <input type="text" size="20" name="addcategory_name" value="" /></td></tr>';
3987: return $datatable;
3988: }
3989:
3990: sub build_category_rows {
3991: my ($itemcount,$cats,$depth,$parent,$path,$idx) = @_;
3992: my ($text,$name,$item,$chgstr);
3993: if (ref($cats) eq 'ARRAY') {
3994: my $maxdepth = scalar(@{$cats});
3995: if (ref($cats->[$depth]) eq 'HASH') {
3996: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
3997: my $numchildren = @{$cats->[$depth]{$parent}};
3998: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
3999: $text .= '<td><table class="LC_datatable">';
4000: my ($idxnum,$parent_name,$parent_item);
4001: my $higher = $depth - 1;
4002: if ($higher == 0) {
4003: $parent_name = &escape($parent).'::'.$higher;
4004: } else {
4005: if (ref($path) eq 'ARRAY') {
4006: $parent_name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
4007: }
4008: }
4009: $parent_item = 'addcategory_pos_'.$parent_name;
4010: for (my $j=0; $j<=$numchildren; $j++) {
4011: if ($j < $numchildren) {
4012: $name = $cats->[$depth]{$parent}[$j];
4013: $item = &escape($name).':'.&escape($parent).':'.$depth;
4014: $idxnum = $idx->{$item};
4015: } else {
4016: $name = $parent_name;
4017: $item = $parent_item;
4018: }
4019: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'$parent_name','$item','$idxnum'".');"';
4020: $text .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="'.$item.'"'.$chgstr.'>';
4021: for (my $i=0; $i<=$numchildren; $i++) {
4022: my $vpos = $i+1;
4023: my $selstr;
4024: if ($j == $i) {
4025: $selstr = ' selected="selected" ';
4026: }
4027: $text .= '<option value="'.$i.'"'.$selstr.'>'.$vpos.'</option>';
4028: }
4029: $text .= '</select> ';
4030: if ($j < $numchildren) {
4031: my $deeper = $depth+1;
4032: $text .= $name.' '
4033: .'<label><input type="checkbox" name="deletecategory" value="'
4034: .$item.'" />'.&mt('Delete').'</label></span></td><td>';
4035: if(ref($path) eq 'ARRAY') {
4036: push(@{$path},$name);
4037: $text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path,$idx);
4038: pop(@{$path});
4039: }
4040: } else {
4041: $text .= &mt('Add subcategory:').' </span><input type="textbox" size="20" name="addcategory_name_';
4042: if ($j == $numchildren) {
4043: $text .= $name;
4044: } else {
4045: $text .= $item;
4046: }
4047: $text .= '" value="" />';
4048: }
4049: $text .= '</td></tr>';
4050: }
4051: $text .= '</table></td>';
4052: } else {
4053: my $higher = $depth-1;
4054: if ($higher == 0) {
4055: $name = &escape($parent).'::'.$higher;
4056: } else {
4057: if (ref($path) eq 'ARRAY') {
4058: $name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
4059: }
4060: }
4061: my $colspan;
4062: if ($parent ne 'instcode') {
4063: $colspan = $maxdepth - $depth - 1;
4064: $text .= '<td colspan="'.$colspan.'">'.&mt('Add subcategory:').'<input type="textbox" size="20" name="subcat_'.$name.'" value="" /></td>';
4065: }
4066: }
4067: }
4068: }
4069: return $text;
4070: }
4071:
4072: sub modifiable_userdata_row {
4073: my ($context,$role,$settings,$numinrow,$rowcount,$usertypes) = @_;
4074: my $rolename;
4075: if ($context eq 'selfcreate') {
4076: if (ref($usertypes) eq 'HASH') {
4077: $rolename = $usertypes->{$role};
4078: } else {
4079: $rolename = $role;
4080: }
4081: } else {
4082: if ($role eq 'cr') {
4083: $rolename = &mt('Custom role');
4084: } else {
4085: $rolename = &Apache::lonnet::plaintext($role);
4086: }
4087: }
4088: my @fields = ('lastname','firstname','middlename','generation',
4089: 'permanentemail','id');
4090: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
4091: my $output;
4092: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
4093: $output = '<tr '.$css_class.'>'.
4094: '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
4095: '<td class="LC_left_item" colspan="2"><table>';
4096: my $rem;
4097: my %checks;
4098: if (ref($settings) eq 'HASH') {
4099: if (ref($settings->{$context}) eq 'HASH') {
4100: if (ref($settings->{$context}->{$role}) eq 'HASH') {
4101: foreach my $field (@fields) {
4102: if ($settings->{$context}->{$role}->{$field}) {
4103: $checks{$field} = ' checked="checked" ';
4104: }
4105: }
4106: }
4107: }
4108: }
4109: for (my $i=0; $i<@fields; $i++) {
4110: my $rem = $i%($numinrow);
4111: if ($rem == 0) {
4112: if ($i > 0) {
4113: $output .= '</tr>';
4114: }
4115: $output .= '<tr>';
4116: }
4117: my $check = ' ';
4118: if (exists($checks{$fields[$i]})) {
4119: $check = $checks{$fields[$i]}
4120: } else {
4121: if ($role eq 'st') {
4122: if (ref($settings) ne 'HASH') {
4123: $check = ' checked="checked" ';
4124: }
4125: }
4126: }
4127: $output .= '<td class="LC_left_item">'.
4128: '<span class="LC_nobreak"><label>'.
4129: '<input type="checkbox" name="canmodify_'.$role.'" '.
4130: 'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
4131: '</label></span></td>';
4132: $rem = @fields%($numinrow);
4133: }
4134: my $colsleft = $numinrow - $rem;
4135: if ($colsleft > 1 ) {
4136: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
4137: ' </td>';
4138: } elsif ($colsleft == 1) {
4139: $output .= '<td class="LC_left_item"> </td>';
4140: }
4141: $output .= '</tr></table></td></tr>';
4142: return $output;
4143: }
4144:
4145: sub insttypes_row {
4146: my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle,$context) = @_;
4147: my %lt = &Apache::lonlocal::texthash (
4148: cansearch => 'Users allowed to search',
4149: statustocreate => 'Institutional affiliation(s) able to create own account (login/SSO)',
4150: lockablenames => 'User preference to lock name',
4151: );
4152: my $showdom;
4153: if ($context eq 'cansearch') {
4154: $showdom = ' ('.$dom.')';
4155: }
4156: my $output = '<tr class="LC_odd_row">'.
4157: '<td>'.$lt{$context}.$showdom.
4158: '</td><td class="LC_left_item" colspan="2"><table>';
4159: my $rem;
4160: if (ref($types) eq 'ARRAY') {
4161: for (my $i=0; $i<@{$types}; $i++) {
4162: if (defined($usertypes->{$types->[$i]})) {
4163: my $rem = $i%($numinrow);
4164: if ($rem == 0) {
4165: if ($i > 0) {
4166: $output .= '</tr>';
4167: }
4168: $output .= '<tr>';
4169: }
4170: my $check = ' ';
4171: if (ref($settings) eq 'HASH') {
4172: if (ref($settings->{$context}) eq 'ARRAY') {
4173: if (grep(/^\Q$types->[$i]\E$/,@{$settings->{$context}})) {
4174: $check = ' checked="checked" ';
4175: }
4176: } elsif ($context eq 'statustocreate') {
4177: $check = ' checked="checked" ';
4178: }
4179: }
4180: $output .= '<td class="LC_left_item">'.
4181: '<span class="LC_nobreak"><label>'.
4182: '<input type="checkbox" name="'.$context.'" '.
4183: 'value="'.$types->[$i].'"'.$check.'/>'.
4184: $usertypes->{$types->[$i]}.'</label></span></td>';
4185: }
4186: }
4187: $rem = @{$types}%($numinrow);
4188: }
4189: my $colsleft = $numinrow - $rem;
4190: if (($rem == 0) && (@{$types} > 0)) {
4191: $output .= '<tr>';
4192: }
4193: if ($colsleft > 1) {
4194: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
4195: } else {
4196: $output .= '<td class="LC_left_item">';
4197: }
4198: my $defcheck = ' ';
4199: if (ref($settings) eq 'HASH') {
4200: if (ref($settings->{$context}) eq 'ARRAY') {
4201: if (grep(/^default$/,@{$settings->{$context}})) {
4202: $defcheck = ' checked="checked" ';
4203: }
4204: } elsif ($context eq 'statustocreate') {
4205: $defcheck = ' checked="checked" ';
4206: }
4207: }
4208: $output .= '<span class="LC_nobreak"><label>'.
4209: '<input type="checkbox" name="'.$context.'" '.
4210: 'value="default"'.$defcheck.'/>'.
4211: $othertitle.'</label></span></td>'.
4212: '</tr></table></td></tr>';
4213: return $output;
4214: }
4215:
4216: sub sorted_searchtitles {
4217: my %searchtitles = &Apache::lonlocal::texthash(
4218: 'uname' => 'username',
4219: 'lastname' => 'last name',
4220: 'lastfirst' => 'last name, first name',
4221: );
4222: my @titleorder = ('uname','lastname','lastfirst');
4223: return (\%searchtitles,\@titleorder);
4224: }
4225:
4226: sub sorted_searchtypes {
4227: my %srchtypes_desc = (
4228: exact => 'is exact match',
4229: contains => 'contains ..',
4230: begins => 'begins with ..',
4231: );
4232: my @srchtypeorder = ('exact','begins','contains');
4233: return (\%srchtypes_desc,\@srchtypeorder);
4234: }
4235:
4236: sub usertype_update_row {
4237: my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
4238: my $datatable;
4239: my $numinrow = 4;
4240: foreach my $type (@{$types}) {
4241: if (defined($usertypes->{$type})) {
4242: $$rownums ++;
4243: my $css_class = $$rownums%2?' class="LC_odd_row"':'';
4244: $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
4245: '</td><td class="LC_left_item"><table>';
4246: for (my $i=0; $i<@{$fields}; $i++) {
4247: my $rem = $i%($numinrow);
4248: if ($rem == 0) {
4249: if ($i > 0) {
4250: $datatable .= '</tr>';
4251: }
4252: $datatable .= '<tr>';
4253: }
4254: my $check = ' ';
4255: if (ref($settings) eq 'HASH') {
4256: if (ref($settings->{'fields'}) eq 'HASH') {
4257: if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
4258: if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
4259: $check = ' checked="checked" ';
4260: }
4261: }
4262: }
4263: }
4264:
4265: if ($i == @{$fields}-1) {
4266: my $colsleft = $numinrow - $rem;
4267: if ($colsleft > 1) {
4268: $datatable .= '<td colspan="'.$colsleft.'">';
4269: } else {
4270: $datatable .= '<td>';
4271: }
4272: } else {
4273: $datatable .= '<td>';
4274: }
4275: $datatable .= '<span class="LC_nobreak"><label>'.
4276: '<input type="checkbox" name="updateable_'.$type.
4277: '_'.$fields->[$i].'" value="1"'.$check.'/>'.
4278: $fieldtitles->{$fields->[$i]}.'</label></span></td>';
4279: }
4280: $datatable .= '</tr></table></td></tr>';
4281: }
4282: }
4283: return $datatable;
4284: }
4285:
4286: sub modify_login {
4287: my ($r,$dom,$confname,%domconfig) = @_;
4288: my ($resulttext,$errors,$colchgtext,%changes,%colchanges);
4289: my %title = ( coursecatalog => 'Display course catalog',
4290: adminmail => 'Display administrator E-mail address',
4291: newuser => 'Link for visitors to create a user account',
4292: loginheader => 'Log-in box header');
4293: my @offon = ('off','on');
4294: my %curr_loginvia;
4295: if (ref($domconfig{login}) eq 'HASH') {
4296: if (ref($domconfig{login}{loginvia}) eq 'HASH') {
4297: foreach my $lonhost (keys(%{$domconfig{login}{loginvia}})) {
4298: $curr_loginvia{$lonhost} = $domconfig{login}{loginvia}{$lonhost};
4299: }
4300: }
4301: }
4302: my %loginhash;
4303: ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
4304: \%domconfig,\%loginhash);
4305: my @toggles = ('coursecatalog','adminmail','newuser');
4306: foreach my $item (@toggles) {
4307: $loginhash{login}{$item} = $env{'form.'.$item};
4308: }
4309: $loginhash{login}{loginheader} = $env{'form.loginheader'};
4310: if (ref($colchanges{'login'}) eq 'HASH') {
4311: $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
4312: \%loginhash);
4313: }
4314:
4315: my %servers = &Apache::lonnet::internet_dom_servers($dom);
4316: my @loginvia_attribs = ('serverpath','custompath','exempt');
4317: if (keys(%servers) > 1) {
4318: foreach my $lonhost (keys(%servers)) {
4319: next if ($env{'form.'.$lonhost.'_server'} eq $lonhost);
4320: if (ref($curr_loginvia{$lonhost}) eq 'HASH') {
4321: if ($env{'form.'.$lonhost.'_server'} eq $curr_loginvia{$lonhost}{'server'}) {
4322: $loginhash{login}{loginvia}{$lonhost}{'server'} = $curr_loginvia{$lonhost}{'server'};
4323: } elsif ($curr_loginvia{$lonhost}{'server'} ne '') {
4324: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
4325: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
4326: $changes{'loginvia'}{$lonhost} = 1;
4327: } else {
4328: $loginhash{login}{loginvia}{$lonhost}{'server'} = '';
4329: $changes{'loginvia'}{$lonhost} = 1;
4330: }
4331: } else {
4332: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
4333: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
4334: $changes{'loginvia'}{$lonhost} = 1;
4335: }
4336: }
4337: if ($loginhash{login}{loginvia}{$lonhost}{'server'} eq '') {
4338: foreach my $item (@loginvia_attribs) {
4339: $loginhash{login}{loginvia}{$lonhost}{$item} = '';
4340: }
4341: } else {
4342: foreach my $item (@loginvia_attribs) {
4343: my $new = $env{'form.'.$lonhost.'_'.$item};
4344: if (($item eq 'serverpath') && ($new eq 'custom')) {
4345: $env{'form.'.$lonhost.'_custompath'} =~ s/\s+//g;
4346: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
4347: $new = '/';
4348: }
4349: }
4350: if (($item eq 'custompath') &&
4351: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
4352: $new = '';
4353: }
4354: if ($new ne $curr_loginvia{$lonhost}{$item}) {
4355: $changes{'loginvia'}{$lonhost} = 1;
4356: }
4357: if ($item eq 'exempt') {
4358: $new =~ s/^\s+//;
4359: $new =~ s/\s+$//;
4360: my @poss_ips = split(/\s*[,:]\s*/,$new);
4361: my @okips;
4362: foreach my $ip (@poss_ips) {
4363: if ($ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
4364: if (($1 <= 255) && ($2 <= 255) && ($3 <= 255) && ($4 <= 255)) {
4365: push(@okips,$ip);
4366: }
4367: }
4368: }
4369: if (@okips > 0) {
4370: $new = join(',',@okips);
4371: } else {
4372: $new = '';
4373: }
4374: }
4375:
4376: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
4377: }
4378: }
4379: } else {
4380: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
4381: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
4382: $changes{'loginvia'}{$lonhost} = 1;
4383: foreach my $item (@loginvia_attribs) {
4384: my $new = $env{'form.'.$lonhost.'_'.$item};
4385: if (($item eq 'serverpath') && ($new eq 'custom')) {
4386: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
4387: $new = '/';
4388: }
4389: }
4390: if (($item eq 'custompath') &&
4391: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
4392: $new = '';
4393: }
4394: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
4395: }
4396: }
4397: }
4398: }
4399: }
4400:
4401: my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
4402: $dom);
4403: if ($putresult eq 'ok') {
4404: my @toggles = ('coursecatalog','adminmail','newuser');
4405: my %defaultchecked = (
4406: 'coursecatalog' => 'on',
4407: 'adminmail' => 'off',
4408: 'newuser' => 'off',
4409: );
4410: if (ref($domconfig{'login'}) eq 'HASH') {
4411: foreach my $item (@toggles) {
4412: if ($defaultchecked{$item} eq 'on') {
4413: if (($domconfig{'login'}{$item} eq '0') &&
4414: ($env{'form.'.$item} eq '1')) {
4415: $changes{$item} = 1;
4416: } elsif (($domconfig{'login'}{$item} eq '' ||
4417: $domconfig{'login'}{$item} eq '1') &&
4418: ($env{'form.'.$item} eq '0')) {
4419: $changes{$item} = 1;
4420: }
4421: } elsif ($defaultchecked{$item} eq 'off') {
4422: if (($domconfig{'login'}{$item} eq '1') &&
4423: ($env{'form.'.$item} eq '0')) {
4424: $changes{$item} = 1;
4425: } elsif (($domconfig{'login'}{$item} eq '' ||
4426: $domconfig{'login'}{$item} eq '0') &&
4427: ($env{'form.'.$item} eq '1')) {
4428: $changes{$item} = 1;
4429: }
4430: }
4431: }
4432: }
4433: if (keys(%changes) > 0 || $colchgtext) {
4434: &Apache::loncommon::devalidate_domconfig_cache($dom);
4435: $resulttext = &mt('Changes made:').'<ul>';
4436: foreach my $item (sort(keys(%changes))) {
4437: if ($item eq 'loginvia') {
4438: if (ref($changes{$item}) eq 'HASH') {
4439: $resulttext .= '<li>'.&mt('Log-in page availability:').'<ul>';
4440: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
4441: if (defined($servers{$loginhash{login}{loginvia}{$lonhost}{'server'}})) {
4442: if (ref($loginhash{login}{loginvia}{$lonhost}) eq 'HASH') {
4443: my $protocol = $Apache::lonnet::protocol{$env{'form.'.$lonhost.'_server'}};
4444: $protocol = 'http' if ($protocol ne 'https');
4445: my $target = $protocol.'://'.$servers{$env{'form.'.$lonhost.'_server'}};
4446:
4447: if ($loginhash{login}{loginvia}{$lonhost}{'serverpath'} eq 'custom') {
4448: $target .= $loginhash{login}{loginvia}{$lonhost}{'custompath'};
4449: } else {
4450: $target .= $loginhash{login}{loginvia}{$lonhost}{'serverpath'};
4451: }
4452: $resulttext .= '<li>'.&mt('Server: [_1] log-in page redirects to [_2].',$servers{$lonhost},'<a href="'.$target.'">'.$target.'</a>');
4453: if ($loginhash{login}{loginvia}{$lonhost}{'exempt'} ne '') {
4454: $resulttext .= ' '.&mt('No redirection for clients from following IPs:').' '.$loginhash{login}{loginvia}{$lonhost}{'exempt'};
4455: }
4456: $resulttext .= '</li>';
4457: } else {
4458: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$lonhost).'</li>';
4459: }
4460: } else {
4461: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$servers{$lonhost}).'</li>';
4462: }
4463: }
4464: $resulttext .= '</ul></li>';
4465: }
4466: } else {
4467: $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
4468: }
4469: }
4470: $resulttext .= $colchgtext.'</ul>';
4471: } else {
4472: $resulttext = &mt('No changes made to log-in page settings');
4473: }
4474: } else {
4475: $resulttext = '<span class="LC_error">'.
4476: &mt('An error occurred: [_1]',$putresult).'</span>';
4477: }
4478: if ($errors) {
4479: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
4480: $errors.'</ul>';
4481: }
4482: return $resulttext;
4483: }
4484:
4485: sub color_font_choices {
4486: my %choices =
4487: &Apache::lonlocal::texthash (
4488: img => "Header",
4489: bgs => "Background colors",
4490: links => "Link colors",
4491: images => "Images",
4492: font => "Font color",
4493: fontmenu => "Font Menu",
4494: pgbg => "Page",
4495: tabbg => "Header",
4496: sidebg => "Border",
4497: link => "Link",
4498: alink => "Active link",
4499: vlink => "Visited link",
4500: );
4501: return %choices;
4502: }
4503:
4504: sub modify_rolecolors {
4505: my ($r,$dom,$confname,$roles,%domconfig) = @_;
4506: my ($resulttext,%rolehash);
4507: $rolehash{'rolecolors'} = {};
4508: if (ref($domconfig{'rolecolors'}) ne 'HASH') {
4509: if ($domconfig{'rolecolors'} eq '') {
4510: $domconfig{'rolecolors'} = {};
4511: }
4512: }
4513: my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
4514: $domconfig{'rolecolors'},$rolehash{'rolecolors'});
4515: my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
4516: $dom);
4517: if ($putresult eq 'ok') {
4518: if (keys(%changes) > 0) {
4519: &Apache::loncommon::devalidate_domconfig_cache($dom);
4520: $resulttext = &display_colorchgs($dom,\%changes,$roles,
4521: $rolehash{'rolecolors'});
4522: } else {
4523: $resulttext = &mt('No changes made to default color schemes');
4524: }
4525: } else {
4526: $resulttext = '<span class="LC_error">'.
4527: &mt('An error occurred: [_1]',$putresult).'</span>';
4528: }
4529: if ($errors) {
4530: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
4531: $errors.'</ul>';
4532: }
4533: return $resulttext;
4534: }
4535:
4536: sub modify_colors {
4537: my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
4538: my (%changes,%choices);
4539: my @bgs;
4540: my @links = ('link','alink','vlink');
4541: my @logintext;
4542: my @images;
4543: my $servadm = $r->dir_config('lonAdmEMail');
4544: my $errors;
4545: foreach my $role (@{$roles}) {
4546: if ($role eq 'login') {
4547: %choices = &login_choices();
4548: @logintext = ('textcol','bgcol');
4549: } else {
4550: %choices = &color_font_choices();
4551: $confhash->{$role}{'fontmenu'} = $env{'form.'.$role.'_fontmenu'};
4552: }
4553: if ($role eq 'login') {
4554: @images = ('img','logo','domlogo','login');
4555: @bgs = ('pgbg','mainbg','sidebg');
4556: } else {
4557: @images = ('img');
4558: @bgs = ('pgbg','tabbg','sidebg');
4559: }
4560: $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
4561: foreach my $item (@bgs,@links,@logintext) {
4562: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
4563: }
4564: my ($configuserok,$author_ok,$switchserver) =
4565: &config_check($dom,$confname,$servadm);
4566: my ($width,$height) = &thumb_dimensions();
4567: if (ref($domconfig->{$role}) ne 'HASH') {
4568: $domconfig->{$role} = {};
4569: }
4570: foreach my $img (@images) {
4571: if (($role eq 'login') && (($img eq 'img') || ($img eq 'logo'))) {
4572: if (defined($env{'form.login_showlogo_'.$img})) {
4573: $confhash->{$role}{'showlogo'}{$img} = 1;
4574: } else {
4575: $confhash->{$role}{'showlogo'}{$img} = 0;
4576: }
4577: }
4578: if ( ! $env{'form.'.$role.'_'.$img.'.filename'}
4579: && !defined($domconfig->{$role}{$img})
4580: && !$env{'form.'.$role.'_del_'.$img}
4581: && $env{'form.'.$role.'_import_'.$img}) {
4582: # import the old configured image from the .tab setting
4583: # if they haven't provided a new one
4584: $domconfig->{$role}{$img} =
4585: $env{'form.'.$role.'_import_'.$img};
4586: }
4587: if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
4588: my $error;
4589: if ($configuserok eq 'ok') {
4590: if ($switchserver) {
4591: $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
4592: } else {
4593: if ($author_ok eq 'ok') {
4594: my ($result,$logourl) =
4595: &publishlogo($r,'upload',$role.'_'.$img,
4596: $dom,$confname,$img,$width,$height);
4597: if ($result eq 'ok') {
4598: $confhash->{$role}{$img} = $logourl;
4599: $changes{$role}{'images'}{$img} = 1;
4600: } else {
4601: $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);
4602: }
4603: } else {
4604: $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);
4605: }
4606: }
4607: } else {
4608: $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);
4609: }
4610: if ($error) {
4611: &Apache::lonnet::logthis($error);
4612: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
4613: }
4614: } elsif ($domconfig->{$role}{$img} ne '') {
4615: if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
4616: my $error;
4617: if ($configuserok eq 'ok') {
4618: # is confname an author?
4619: if ($switchserver eq '') {
4620: if ($author_ok eq 'ok') {
4621: my ($result,$logourl) =
4622: &publishlogo($r,'copy',$domconfig->{$role}{$img},
4623: $dom,$confname,$img,$width,$height);
4624: if ($result eq 'ok') {
4625: $confhash->{$role}{$img} = $logourl;
4626: $changes{$role}{'images'}{$img} = 1;
4627: }
4628: }
4629: }
4630: }
4631: }
4632: }
4633: }
4634: if (ref($domconfig) eq 'HASH') {
4635: if (ref($domconfig->{$role}) eq 'HASH') {
4636: foreach my $img (@images) {
4637: if ($domconfig->{$role}{$img} ne '') {
4638: if ($env{'form.'.$role.'_del_'.$img}) {
4639: $confhash->{$role}{$img} = '';
4640: $changes{$role}{'images'}{$img} = 1;
4641: } else {
4642: if ($confhash->{$role}{$img} eq '') {
4643: $confhash->{$role}{$img} = $domconfig->{$role}{$img};
4644: }
4645: }
4646: } else {
4647: if ($env{'form.'.$role.'_del_'.$img}) {
4648: $confhash->{$role}{$img} = '';
4649: $changes{$role}{'images'}{$img} = 1;
4650: }
4651: }
4652: if (($role eq 'login') && (($img eq 'logo') || ($img eq 'img'))) {
4653: if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') {
4654: if ($confhash->{$role}{'showlogo'}{$img} ne
4655: $domconfig->{$role}{'showlogo'}{$img}) {
4656: $changes{$role}{'showlogo'}{$img} = 1;
4657: }
4658: } else {
4659: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
4660: $changes{$role}{'showlogo'}{$img} = 1;
4661: }
4662: }
4663: }
4664: }
4665: if ($domconfig->{$role}{'font'} ne '') {
4666: if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
4667: $changes{$role}{'font'} = 1;
4668: }
4669: } else {
4670: if ($confhash->{$role}{'font'}) {
4671: $changes{$role}{'font'} = 1;
4672: }
4673: }
4674: if ($role ne 'login') {
4675: if ($domconfig->{$role}{'fontmenu'} ne '') {
4676: if ($confhash->{$role}{'fontmenu'} ne $domconfig->{$role}{'fontmenu'}) {
4677: $changes{$role}{'fontmenu'} = 1;
4678: }
4679: } else {
4680: if ($confhash->{$role}{'fontmenu'}) {
4681: $changes{$role}{'fontmenu'} = 1;
4682: }
4683: }
4684: }
4685: foreach my $item (@bgs) {
4686: if ($domconfig->{$role}{$item} ne '') {
4687: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
4688: $changes{$role}{'bgs'}{$item} = 1;
4689: }
4690: } else {
4691: if ($confhash->{$role}{$item}) {
4692: $changes{$role}{'bgs'}{$item} = 1;
4693: }
4694: }
4695: }
4696: foreach my $item (@links) {
4697: if ($domconfig->{$role}{$item} ne '') {
4698: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
4699: $changes{$role}{'links'}{$item} = 1;
4700: }
4701: } else {
4702: if ($confhash->{$role}{$item}) {
4703: $changes{$role}{'links'}{$item} = 1;
4704: }
4705: }
4706: }
4707: foreach my $item (@logintext) {
4708: if ($domconfig->{$role}{$item} ne '') {
4709: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
4710: $changes{$role}{'logintext'}{$item} = 1;
4711: }
4712: } else {
4713: if ($confhash->{$role}{$item}) {
4714: $changes{$role}{'logintext'}{$item} = 1;
4715: }
4716: }
4717: }
4718: } else {
4719: &default_change_checker($role,\@images,\@links,\@bgs,
4720: \@logintext,$confhash,\%changes);
4721: }
4722: } else {
4723: &default_change_checker($role,\@images,\@links,\@bgs,
4724: \@logintext,$confhash,\%changes);
4725: }
4726: }
4727: return ($errors,%changes);
4728: }
4729:
4730: sub config_check {
4731: my ($dom,$confname,$servadm) = @_;
4732: my ($configuserok,$author_ok,$switchserver,%currroles);
4733: my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
4734: ($configuserok,%currroles) = &check_configuser($uhome,$dom,
4735: $confname,$servadm);
4736: if ($configuserok eq 'ok') {
4737: $switchserver = &check_switchserver($dom,$confname);
4738: if ($switchserver eq '') {
4739: $author_ok = &check_authorstatus($dom,$confname,%currroles);
4740: }
4741: }
4742: return ($configuserok,$author_ok,$switchserver);
4743: }
4744:
4745: sub default_change_checker {
4746: my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
4747: foreach my $item (@{$links}) {
4748: if ($confhash->{$role}{$item}) {
4749: $changes->{$role}{'links'}{$item} = 1;
4750: }
4751: }
4752: foreach my $item (@{$bgs}) {
4753: if ($confhash->{$role}{$item}) {
4754: $changes->{$role}{'bgs'}{$item} = 1;
4755: }
4756: }
4757: foreach my $item (@{$logintext}) {
4758: if ($confhash->{$role}{$item}) {
4759: $changes->{$role}{'logintext'}{$item} = 1;
4760: }
4761: }
4762: foreach my $img (@{$images}) {
4763: if ($env{'form.'.$role.'_del_'.$img}) {
4764: $confhash->{$role}{$img} = '';
4765: $changes->{$role}{'images'}{$img} = 1;
4766: }
4767: if ($role eq 'login') {
4768: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
4769: $changes->{$role}{'showlogo'}{$img} = 1;
4770: }
4771: }
4772: }
4773: if ($confhash->{$role}{'font'}) {
4774: $changes->{$role}{'font'} = 1;
4775: }
4776: }
4777:
4778: sub display_colorchgs {
4779: my ($dom,$changes,$roles,$confhash) = @_;
4780: my (%choices,$resulttext);
4781: if (!grep(/^login$/,@{$roles})) {
4782: $resulttext = &mt('Changes made:').'<br />';
4783: }
4784: foreach my $role (@{$roles}) {
4785: if ($role eq 'login') {
4786: %choices = &login_choices();
4787: } else {
4788: %choices = &color_font_choices();
4789: }
4790: if (ref($changes->{$role}) eq 'HASH') {
4791: if ($role ne 'login') {
4792: $resulttext .= '<h4>'.&mt($role).'</h4>';
4793: }
4794: foreach my $key (sort(keys(%{$changes->{$role}}))) {
4795: if ($role ne 'login') {
4796: $resulttext .= '<ul>';
4797: }
4798: if (ref($changes->{$role}{$key}) eq 'HASH') {
4799: if ($role ne 'login') {
4800: $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
4801: }
4802: foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
4803: if (($role eq 'login') && ($key eq 'showlogo')) {
4804: if ($confhash->{$role}{$key}{$item}) {
4805: $resulttext .= '<li>'.&mt("$choices{$item} set to be displayed").'</li>';
4806: } else {
4807: $resulttext .= '<li>'.&mt("$choices{$item} set to not be displayed").'</li>';
4808: }
4809: } elsif ($confhash->{$role}{$item} eq '') {
4810: $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
4811: } else {
4812: my $newitem = $confhash->{$role}{$item};
4813: if ($key eq 'images') {
4814: $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" valign="bottom" />';
4815: }
4816: $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
4817: }
4818: }
4819: if ($role ne 'login') {
4820: $resulttext .= '</ul></li>';
4821: }
4822: } else {
4823: if ($confhash->{$role}{$key} eq '') {
4824: $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
4825: } else {
4826: $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
4827: }
4828: }
4829: if ($role ne 'login') {
4830: $resulttext .= '</ul>';
4831: }
4832: }
4833: }
4834: }
4835: return $resulttext;
4836: }
4837:
4838: sub thumb_dimensions {
4839: return ('200','50');
4840: }
4841:
4842: sub check_dimensions {
4843: my ($inputfile) = @_;
4844: my ($fullwidth,$fullheight);
4845: if ($inputfile =~ m|^[/\w.\-]+$|) {
4846: if (open(PIPE,"identify $inputfile 2>&1 |")) {
4847: my $imageinfo = <PIPE>;
4848: if (!close(PIPE)) {
4849: &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
4850: }
4851: chomp($imageinfo);
4852: my ($fullsize) =
4853: ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
4854: if ($fullsize) {
4855: ($fullwidth,$fullheight) = split(/x/,$fullsize);
4856: }
4857: }
4858: }
4859: return ($fullwidth,$fullheight);
4860: }
4861:
4862: sub check_configuser {
4863: my ($uhome,$dom,$confname,$servadm) = @_;
4864: my ($configuserok,%currroles);
4865: if ($uhome eq 'no_host') {
4866: srand( time() ^ ($$ + ($$ << 15)) ); # Seed rand.
4867: my $configpass = &LONCAPA::Enrollment::create_password();
4868: $configuserok =
4869: &Apache::lonnet::modifyuser($dom,$confname,'','internal',
4870: $configpass,'','','','','',undef,$servadm);
4871: } else {
4872: $configuserok = 'ok';
4873: %currroles =
4874: &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
4875: }
4876: return ($configuserok,%currroles);
4877: }
4878:
4879: sub check_authorstatus {
4880: my ($dom,$confname,%currroles) = @_;
4881: my $author_ok;
4882: if (!$currroles{':'.$dom.':au'}) {
4883: my $start = time;
4884: my $end = 0;
4885: $author_ok =
4886: &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
4887: 'au',$end,$start,'','','domconfig');
4888: } else {
4889: $author_ok = 'ok';
4890: }
4891: return $author_ok;
4892: }
4893:
4894: sub publishlogo {
4895: my ($r,$action,$formname,$dom,$confname,$subdir,$thumbwidth,$thumbheight,$savefileas) = @_;
4896: my ($output,$fname,$logourl);
4897: if ($action eq 'upload') {
4898: $fname=$env{'form.'.$formname.'.filename'};
4899: chop($env{'form.'.$formname});
4900: } else {
4901: ($fname) = ($formname =~ /([^\/]+)$/);
4902: }
4903: if ($savefileas ne '') {
4904: $fname = $savefileas;
4905: }
4906: $fname=&Apache::lonnet::clean_filename($fname);
4907: # See if there is anything left
4908: unless ($fname) { return ('error: no uploaded file'); }
4909: $fname="$subdir/$fname";
4910: my $filepath=$r->dir_config('lonDocRoot')."/priv/$dom/$confname";
4911: my ($fnamepath,$file,$fetchthumb);
4912: $file=$fname;
4913: if ($fname=~m|/|) {
4914: ($fnamepath,$file) = ($fname =~ m|^(.*)/([^/]+)$|);
4915: }
4916: my @parts=split(/\//,$filepath.'/'.$fnamepath);
4917: my $count;
4918: for ($count=4;$count<=$#parts;$count++) {
4919: $filepath.="/$parts[$count]";
4920: if ((-e $filepath)!=1) {
4921: mkdir($filepath,02770);
4922: }
4923: }
4924: # Check for bad extension and disallow upload
4925: if ($file=~/\.(\w+)$/ &&
4926: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
4927: $output =
4928: &mt('Invalid file extension ([_1]) - reserved for LONCAPA use.',$1);
4929: } elsif ($file=~/\.(\w+)$/ &&
4930: !defined(&Apache::loncommon::fileembstyle($1))) {
4931: $output = &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
4932: } elsif ($file=~/\.(\d+)\.(\w+)$/) {
4933: $output = &mt('File name not allowed - rename the file to remove the number immediately before the file extension([_1]) and re-upload.',$2);
4934: } elsif (-d "$filepath/$file") {
4935: $output = &mt('File name is a directory name - rename the file and re-upload');
4936: } else {
4937: my $source = $filepath.'/'.$file;
4938: my $logfile;
4939: if (!open($logfile,">>$source".'.log')) {
4940: return (&mt('No write permission to Construction Space'));
4941: }
4942: print $logfile
4943: "\n================= Publish ".localtime()." ================\n".
4944: $env{'user.name'}.':'.$env{'user.domain'}."\n";
4945: # Save the file
4946: if (!open(FH,'>'.$source)) {
4947: &Apache::lonnet::logthis('Failed to create '.$source);
4948: return (&mt('Failed to create file'));
4949: }
4950: if ($action eq 'upload') {
4951: if (!print FH ($env{'form.'.$formname})) {
4952: &Apache::lonnet::logthis('Failed to write to '.$source);
4953: return (&mt('Failed to write file'));
4954: }
4955: } else {
4956: my $original = &Apache::lonnet::filelocation('',$formname);
4957: if(!copy($original,$source)) {
4958: &Apache::lonnet::logthis('Failed to copy '.$original.' to '.$source);
4959: return (&mt('Failed to write file'));
4960: }
4961: }
4962: close(FH);
4963: chmod(0660, $source); # Permissions to rw-rw---.
4964:
4965: my $docroot=$r->dir_config('lonDocRoot');
4966: my $targetdir=$docroot.'/res/'.$dom.'/'.$confname .'/'.$fnamepath;
4967: my $copyfile=$targetdir.'/'.$file;
4968:
4969: my @parts=split(/\//,$targetdir);
4970: my $path="/$parts[1]/$parts[2]/$parts[3]/$parts[4]";
4971: for (my $count=5;$count<=$#parts;$count++) {
4972: $path.="/$parts[$count]";
4973: if (!-e $path) {
4974: print $logfile "\nCreating directory ".$path;
4975: mkdir($path,02770);
4976: }
4977: }
4978: my $versionresult;
4979: if (-e $copyfile) {
4980: $versionresult = &logo_versioning($targetdir,$file,$logfile);
4981: } else {
4982: $versionresult = 'ok';
4983: }
4984: if ($versionresult eq 'ok') {
4985: if (copy($source,$copyfile)) {
4986: print $logfile "\nCopied original source to ".$copyfile."\n";
4987: $output = 'ok';
4988: $logourl = '/res/'.$dom.'/'.$confname.'/'.$fname;
4989: push(@{$modified_urls},[$copyfile,$source]);
4990: my $metaoutput =
4991: &write_metadata($dom,$confname,$formname,$targetdir,$file,$logfile);
4992: unless ($registered_cleanup) {
4993: my $handlers = $r->get_handlers('PerlCleanupHandler');
4994: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
4995: $registered_cleanup=1;
4996: }
4997: } else {
4998: print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";
4999: $output = &mt('Failed to copy file to RES space').", $!";
5000: }
5001: if (($thumbwidth =~ /^\d+$/) && ($thumbheight =~ /^\d+$/)) {
5002: my $inputfile = $filepath.'/'.$file;
5003: my $outfile = $filepath.'/'.'tn-'.$file;
5004: my ($fullwidth,$fullheight) = &check_dimensions($inputfile);
5005: if ($fullwidth ne '' && $fullheight ne '') {
5006: if ($fullwidth > $thumbwidth && $fullheight > $thumbheight) {
5007: my $thumbsize = $thumbwidth.'x'.$thumbheight;
5008: system("convert -sample $thumbsize $inputfile $outfile");
5009: chmod(0660, $filepath.'/tn-'.$file);
5010: if (-e $outfile) {
5011: my $copyfile=$targetdir.'/tn-'.$file;
5012: if (copy($outfile,$copyfile)) {
5013: print $logfile "\nCopied source to ".$copyfile."\n";
5014: my $thumb_metaoutput =
5015: &write_metadata($dom,$confname,$formname,
5016: $targetdir,'tn-'.$file,$logfile);
5017: push(@{$modified_urls},[$copyfile,$outfile]);
5018: unless ($registered_cleanup) {
5019: my $handlers = $r->get_handlers('PerlCleanupHandler');
5020: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
5021: $registered_cleanup=1;
5022: }
5023: } else {
5024: print $logfile "\nUnable to write ".$copyfile.
5025: ':'.$!."\n";
5026: }
5027: }
5028: }
5029: }
5030: }
5031: } else {
5032: $output = $versionresult;
5033: }
5034: }
5035: return ($output,$logourl);
5036: }
5037:
5038: sub logo_versioning {
5039: my ($targetdir,$file,$logfile) = @_;
5040: my $target = $targetdir.'/'.$file;
5041: my ($maxversion,$fn,$extn,$output);
5042: $maxversion = 0;
5043: if ($file =~ /^(.+)\.(\w+)$/) {
5044: $fn=$1;
5045: $extn=$2;
5046: }
5047: opendir(DIR,$targetdir);
5048: while (my $filename=readdir(DIR)) {
5049: if ($filename=~/\Q$fn\E\.(\d+)\.\Q$extn\E$/) {
5050: $maxversion=($1>$maxversion)?$1:$maxversion;
5051: }
5052: }
5053: $maxversion++;
5054: print $logfile "\nCreating old version ".$maxversion."\n";
5055: my $copyfile=$targetdir.'/'.$fn.'.'.$maxversion.'.'.$extn;
5056: if (copy($target,$copyfile)) {
5057: print $logfile "Copied old target to ".$copyfile."\n";
5058: $copyfile=$copyfile.'.meta';
5059: if (copy($target.'.meta',$copyfile)) {
5060: print $logfile "Copied old target metadata to ".$copyfile."\n";
5061: $output = 'ok';
5062: } else {
5063: print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";
5064: $output = &mt('Failed to copy old meta').", $!, ";
5065: }
5066: } else {
5067: print $logfile "Unable to write ".$copyfile.':'.$!."\n";
5068: $output = &mt('Failed to copy old target').", $!, ";
5069: }
5070: return $output;
5071: }
5072:
5073: sub write_metadata {
5074: my ($dom,$confname,$formname,$targetdir,$file,$logfile) = @_;
5075: my (%metadatafields,%metadatakeys,$output);
5076: $metadatafields{'title'}=$formname;
5077: $metadatafields{'creationdate'}=time;
5078: $metadatafields{'lastrevisiondate'}=time;
5079: $metadatafields{'copyright'}='public';
5080: $metadatafields{'modifyinguser'}=$env{'user.name'}.':'.
5081: $env{'user.domain'};
5082: $metadatafields{'authorspace'}=$confname.':'.$dom;
5083: $metadatafields{'domain'}=$dom;
5084: {
5085: print $logfile "\nWrite metadata file for ".$targetdir.'/'.$file;
5086: my $mfh;
5087: if (open($mfh,'>'.$targetdir.'/'.$file.'.meta')) {
5088: foreach (sort keys %metadatafields) {
5089: unless ($_=~/\./) {
5090: my $unikey=$_;
5091: $unikey=~/^([A-Za-z]+)/;
5092: my $tag=$1;
5093: $tag=~tr/A-Z/a-z/;
5094: print $mfh "\n\<$tag";
5095: foreach (split(/\,/,$metadatakeys{$unikey})) {
5096: my $value=$metadatafields{$unikey.'.'.$_};
5097: $value=~s/\"/\'\'/g;
5098: print $mfh ' '.$_.'="'.$value.'"';
5099: }
5100: print $mfh '>'.
5101: &HTML::Entities::encode($metadatafields{$unikey},'<>&"')
5102: .'</'.$tag.'>';
5103: }
5104: }
5105: $output = 'ok';
5106: print $logfile "\nWrote metadata";
5107: close($mfh);
5108: } else {
5109: print $logfile "\nFailed to open metadata file";
5110: $output = &mt('Could not write metadata');
5111: }
5112: }
5113: return $output;
5114: }
5115:
5116: sub notifysubscribed {
5117: foreach my $targetsource (@{$modified_urls}){
5118: next unless (ref($targetsource) eq 'ARRAY');
5119: my ($target,$source)=@{$targetsource};
5120: if ($source ne '') {
5121: if (open(my $logfh,'>>'.$source.'.log')) {
5122: print $logfh "\nCleanup phase: Notifications\n";
5123: my @subscribed=&subscribed_hosts($target);
5124: foreach my $subhost (@subscribed) {
5125: print $logfh "\nNotifying host ".$subhost.':';
5126: my $reply=&Apache::lonnet::critical('update:'.$target,$subhost);
5127: print $logfh $reply;
5128: }
5129: my @subscribedmeta=&subscribed_hosts("$target.meta");
5130: foreach my $subhost (@subscribedmeta) {
5131: print $logfh "\nNotifying host for metadata only ".$subhost.':';
5132: my $reply=&Apache::lonnet::critical('update:'.$target.'.meta',
5133: $subhost);
5134: print $logfh $reply;
5135: }
5136: print $logfh "\n============ Done ============\n";
5137: close($logfh);
5138: }
5139: }
5140: }
5141: return OK;
5142: }
5143:
5144: sub subscribed_hosts {
5145: my ($target) = @_;
5146: my @subscribed;
5147: if (open(my $fh,"<$target.subscription")) {
5148: while (my $subline=<$fh>) {
5149: if ($subline =~ /^($match_lonid):/) {
5150: my $host = $1;
5151: if ($host ne $Apache::lonnet::perlvar{'lonHostID'}) {
5152: unless (grep(/^\Q$host\E$/,@subscribed)) {
5153: push(@subscribed,$host);
5154: }
5155: }
5156: }
5157: }
5158: }
5159: return @subscribed;
5160: }
5161:
5162: sub check_switchserver {
5163: my ($dom,$confname) = @_;
5164: my ($allowed,$switchserver);
5165: my $home = &Apache::lonnet::homeserver($confname,$dom);
5166: if ($home eq 'no_host') {
5167: $home = &Apache::lonnet::domain($dom,'primary');
5168: }
5169: my @ids=&Apache::lonnet::current_machine_ids();
5170: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
5171: if (!$allowed) {
5172: $switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role=dc./'.$dom.'/">'.&mt('Switch Server').'</a>';
5173: }
5174: return $switchserver;
5175: }
5176:
5177: sub modify_quotas {
5178: my ($dom,$action,%domconfig) = @_;
5179: my ($context,@usertools,@options,%validations,%titles,%confhash,%toolshash,
5180: %limithash,$toolregexp,%conditions,$resulttext,%changes);
5181: if ($action eq 'quotas') {
5182: $context = 'tools';
5183: } else {
5184: $context = $action;
5185: }
5186: if ($context eq 'requestcourses') {
5187: @usertools = ('official','unofficial','community');
5188: @options =('norequest','approval','validate','autolimit');
5189: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
5190: %titles = &courserequest_titles();
5191: $toolregexp = join('|',@usertools);
5192: %conditions = &courserequest_conditions();
5193: } else {
5194: @usertools = ('aboutme','blog','portfolio');
5195: %titles = &tool_titles();
5196: }
5197: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
5198: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
5199: foreach my $key (keys(%env)) {
5200: if ($context eq 'requestcourses') {
5201: if ($key =~ /^form\.crsreq_($toolregexp)_(.+)$/) {
5202: my $item = $1;
5203: my $type = $2;
5204: if ($type =~ /^limit_(.+)/) {
5205: $limithash{$item}{$1} = $env{$key};
5206: } else {
5207: $confhash{$item}{$type} = $env{$key};
5208: }
5209: }
5210: } else {
5211: if ($key =~ /^form\.quota_(.+)$/) {
5212: $confhash{'defaultquota'}{$1} = $env{$key};
5213: }
5214: if ($key =~ /^form\.\Q$context\E_(.+)$/) {
5215: @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key);
5216: }
5217: }
5218: }
5219: if ($context eq 'requestcourses') {
5220: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.reqapprovalnotify');
5221: @approvalnotify = sort(@approvalnotify);
5222: $confhash{'notify'}{'approval'} = join(',',@approvalnotify);
5223: if (ref($domconfig{$action}) eq 'HASH') {
5224: if (ref($domconfig{$action}{'notify'}) eq 'HASH') {
5225: if ($domconfig{$action}{'notify'}{'approval'} ne $confhash{'notify'}{'approval'}) {
5226: $changes{'notify'}{'approval'} = 1;
5227: }
5228: } else {
5229: if ($confhash{'notify'}{'approval'}) {
5230: $changes{'notify'}{'approval'} = 1;
5231: }
5232: }
5233: } else {
5234: if ($confhash{'notify'}{'approval'}) {
5235: $changes{'notify'}{'approval'} = 1;
5236: }
5237: }
5238: } else {
5239: $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
5240: }
5241: foreach my $item (@usertools) {
5242: foreach my $type (@{$types},'default','_LC_adv') {
5243: my $unset;
5244: if ($context eq 'requestcourses') {
5245: $unset = '0';
5246: if ($type eq '_LC_adv') {
5247: $unset = '';
5248: }
5249: if ($confhash{$item}{$type} eq 'autolimit') {
5250: $confhash{$item}{$type} .= '=';
5251: unless ($limithash{$item}{$type} =~ /\D/) {
5252: $confhash{$item}{$type} .= $limithash{$item}{$type};
5253: }
5254: }
5255: } else {
5256: if (grep(/^\Q$type\E$/,@{$toolshash{$item}})) {
5257: $confhash{$item}{$type} = 1;
5258: } else {
5259: $confhash{$item}{$type} = 0;
5260: }
5261: }
5262: if (ref($domconfig{$action}) eq 'HASH') {
5263: if (ref($domconfig{$action}{$item}) eq 'HASH') {
5264: if ($domconfig{$action}{$item}{$type} ne $confhash{$item}{$type}) {
5265: $changes{$item}{$type} = 1;
5266: }
5267: } else {
5268: if ($context eq 'requestcourses') {
5269: if ($confhash{$item}{$type} ne $unset) {
5270: $changes{$item}{$type} = 1;
5271: }
5272: } else {
5273: if (!$confhash{$item}{$type}) {
5274: $changes{$item}{$type} = 1;
5275: }
5276: }
5277: }
5278: } else {
5279: if ($context eq 'requestcourses') {
5280: if ($confhash{$item}{$type} ne $unset) {
5281: $changes{$item}{$type} = 1;
5282: }
5283: } else {
5284: if (!$confhash{$item}{$type}) {
5285: $changes{$item}{$type} = 1;
5286: }
5287: }
5288: }
5289: }
5290: }
5291: unless ($context eq 'requestcourses') {
5292: if (ref($domconfig{'quotas'}) eq 'HASH') {
5293: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
5294: foreach my $key (keys(%{$domconfig{'quotas'}{'defaultquota'}})) {
5295: if (exists($confhash{'defaultquota'}{$key})) {
5296: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{'defaultquota'}{$key}) {
5297: $changes{'defaultquota'}{$key} = 1;
5298: }
5299: } else {
5300: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{'defaultquota'}{$key};
5301: }
5302: }
5303: } else {
5304: foreach my $key (keys(%{$domconfig{'quotas'}})) {
5305: if (exists($confhash{'defaultquota'}{$key})) {
5306: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{$key}) {
5307: $changes{'defaultquota'}{$key} = 1;
5308: }
5309: } else {
5310: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{$key};
5311: }
5312: }
5313: }
5314: }
5315: if (ref($confhash{'defaultquota'}) eq 'HASH') {
5316: foreach my $key (keys(%{$confhash{'defaultquota'}})) {
5317: if (ref($domconfig{'quotas'}) eq 'HASH') {
5318: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
5319: if (!exists($domconfig{'quotas'}{'defaultquota'}{$key})) {
5320: $changes{'defaultquota'}{$key} = 1;
5321: }
5322: } else {
5323: if (!exists($domconfig{'quotas'}{$key})) {
5324: $changes{'defaultquota'}{$key} = 1;
5325: }
5326: }
5327: } else {
5328: $changes{'defaultquota'}{$key} = 1;
5329: }
5330: }
5331: }
5332: }
5333:
5334: foreach my $key (keys(%confhash)) {
5335: $domdefaults{$key} = $confhash{$key};
5336: }
5337:
5338: my %quotahash = (
5339: $action => { %confhash }
5340: );
5341: my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
5342: $dom);
5343: if ($putresult eq 'ok') {
5344: if (keys(%changes) > 0) {
5345: my $cachetime = 24*60*60;
5346: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
5347:
5348: $resulttext = &mt('Changes made:').'<ul>';
5349: unless ($context eq 'requestcourses') {
5350: if (ref($changes{'defaultquota'}) eq 'HASH') {
5351: $resulttext .= '<li>'.&mt('Portfolio default quotas').'<ul>';
5352: foreach my $type (@{$types},'default') {
5353: if (defined($changes{'defaultquota'}{$type})) {
5354: my $typetitle = $usertypes->{$type};
5355: if ($type eq 'default') {
5356: $typetitle = $othertitle;
5357: }
5358: $resulttext .= '<li>'.&mt('[_1] set to [_2] Mb',$typetitle,$confhash{'defaultquota'}{$type}).'</li>';
5359: }
5360: }
5361: $resulttext .= '</ul></li>';
5362: }
5363: }
5364: my %newenv;
5365: foreach my $item (@usertools) {
5366: if (ref($changes{$item}) eq 'HASH') {
5367: my $newacc =
5368: &Apache::lonnet::usertools_access($env{'user.name'},
5369: $env{'user.domain'},
5370: $item,'reload',$context);
5371: if ($context eq 'requestcourses') {
5372: if ($env{'environment.canrequest.'.$item} ne $newacc) {
5373: $newenv{'environment.canrequest.'.$item} = $newacc;
5374: }
5375: } else {
5376: if ($env{'environment.availabletools.'.$item} ne $newacc) {
5377: $newenv{'environment.availabletools.'.$item} = $newacc;
5378: }
5379: }
5380: $resulttext .= '<li>'.$titles{$item}.'<ul>';
5381: foreach my $type (@{$types},'default','_LC_adv') {
5382: if ($changes{$item}{$type}) {
5383: my $typetitle = $usertypes->{$type};
5384: if ($type eq 'default') {
5385: $typetitle = $othertitle;
5386: } elsif ($type eq '_LC_adv') {
5387: $typetitle = 'LON-CAPA Advanced Users';
5388: }
5389: if ($confhash{$item}{$type}) {
5390: if ($context eq 'requestcourses') {
5391: my $cond;
5392: if ($confhash{$item}{$type} =~ /^autolimit=(\d*)$/) {
5393: if ($1 eq '') {
5394: $cond = &mt('(Automatic processing of any request).');
5395: } else {
5396: $cond = &mt('(Automatic processing of requests up to limit of [quant,_1,request] per user).',$1);
5397: }
5398: } else {
5399: $cond = $conditions{$confhash{$item}{$type}};
5400: }
5401: $resulttext .= '<li>'.&mt('Set to be available to [_1].',$typetitle).' '.$cond.'</li>';
5402: } else {
5403: $resulttext .= '<li>'.&mt('Set to be available to [_1]',$typetitle).'</li>';
5404: }
5405: } else {
5406: if ($type eq '_LC_adv') {
5407: if ($confhash{$item}{$type} eq '0') {
5408: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
5409: } else {
5410: $resulttext .= '<li>'.&mt('No override set for [_1]',$typetitle).'</li>';
5411: }
5412: } else {
5413: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
5414: }
5415: }
5416: }
5417: }
5418: $resulttext .= '</ul></li>';
5419: }
5420: }
5421: if ($action eq 'requestcourses') {
5422: if (ref($changes{'notify'}) eq 'HASH') {
5423: if ($changes{'notify'}{'approval'}) {
5424: if (ref($confhash{'notify'}) eq 'HASH') {
5425: if ($confhash{'notify'}{'approval'}) {
5426: $resulttext .= '<li>'.&mt('Notification of requests requiring approval will be sent to: ').$confhash{'notify'}{'approval'}.'</li>';
5427: } else {
5428: $resulttext .= '<li>'.&mt('No Domain Coordinators will receive notification of course requests requiring approval.').'</li>';
5429: }
5430: }
5431: }
5432: }
5433: }
5434: $resulttext .= '</ul>';
5435: if (keys(%newenv)) {
5436: &Apache::lonnet::appenv(\%newenv);
5437: }
5438: } else {
5439: if ($context eq 'requestcourses') {
5440: $resulttext = &mt('No changes made to rights to request creation of courses.');
5441: } else {
5442: $resulttext = &mt('No changes made to availability of personal information pages, blogs, portfolios or default quotas');
5443: }
5444: }
5445: } else {
5446: $resulttext = '<span class="LC_error">'.
5447: &mt('An error occurred: [_1]',$putresult).'</span>';
5448: }
5449: return $resulttext;
5450: }
5451:
5452: sub modify_autoenroll {
5453: my ($dom,%domconfig) = @_;
5454: my ($resulttext,%changes);
5455: my %currautoenroll;
5456: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
5457: foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
5458: $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
5459: }
5460: }
5461: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
5462: my %title = ( run => 'Auto-enrollment active',
5463: sender => 'Sender for notification messages',
5464: coowners => 'Automatic assignment of co-ownership to instructors of record (institutional data)');
5465: my @offon = ('off','on');
5466: my $sender_uname = $env{'form.sender_uname'};
5467: my $sender_domain = $env{'form.sender_domain'};
5468: if ($sender_domain eq '') {
5469: $sender_uname = '';
5470: } elsif ($sender_uname eq '') {
5471: $sender_domain = '';
5472: }
5473: my $coowners = $env{'form.autoassign_coowners'};
5474: my %autoenrollhash = (
5475: autoenroll => { 'run' => $env{'form.autoenroll_run'},
5476: 'sender_uname' => $sender_uname,
5477: 'sender_domain' => $sender_domain,
5478: 'co-owners' => $coowners,
5479: }
5480: );
5481: my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
5482: $dom);
5483: if ($putresult eq 'ok') {
5484: if (exists($currautoenroll{'run'})) {
5485: if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
5486: $changes{'run'} = 1;
5487: }
5488: } elsif ($autorun) {
5489: if ($env{'form.autoenroll_run'} ne '1') {
5490: $changes{'run'} = 1;
5491: }
5492: }
5493: if ($currautoenroll{'sender_uname'} ne $sender_uname) {
5494: $changes{'sender'} = 1;
5495: }
5496: if ($currautoenroll{'sender_domain'} ne $sender_domain) {
5497: $changes{'sender'} = 1;
5498: }
5499: if ($currautoenroll{'co-owners'} ne '') {
5500: if ($currautoenroll{'co-owners'} ne $coowners) {
5501: $changes{'coowners'} = 1;
5502: }
5503: } elsif ($coowners) {
5504: $changes{'coowners'} = 1;
5505: }
5506: if (keys(%changes) > 0) {
5507: $resulttext = &mt('Changes made:').'<ul>';
5508: if ($changes{'run'}) {
5509: $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
5510: }
5511: if ($changes{'sender'}) {
5512: if ($sender_uname eq '' || $sender_domain eq '') {
5513: $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
5514: } else {
5515: $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
5516: }
5517: }
5518: if ($changes{'coowners'}) {
5519: $resulttext .= '<li>'.&mt("$title{'coowners'} set to $offon[$env{'form.autoassign_coowners'}]").'</li>';
5520: &Apache::loncommon::devalidate_domconfig_cache($dom);
5521: }
5522: $resulttext .= '</ul>';
5523: } else {
5524: $resulttext = &mt('No changes made to auto-enrollment settings');
5525: }
5526: } else {
5527: $resulttext = '<span class="LC_error">'.
5528: &mt('An error occurred: [_1]',$putresult).'</span>';
5529: }
5530: return $resulttext;
5531: }
5532:
5533: sub modify_autoupdate {
5534: my ($dom,%domconfig) = @_;
5535: my ($resulttext,%currautoupdate,%fields,%changes);
5536: if (ref($domconfig{'autoupdate'}) eq 'HASH') {
5537: foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
5538: $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
5539: }
5540: }
5541: my @offon = ('off','on');
5542: my %title = &Apache::lonlocal::texthash (
5543: run => 'Auto-update:',
5544: classlists => 'Updates to user information in classlists?'
5545: );
5546: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
5547: my %fieldtitles = &Apache::lonlocal::texthash (
5548: id => 'Student/Employee ID',
5549: permanentemail => 'E-mail address',
5550: lastname => 'Last Name',
5551: firstname => 'First Name',
5552: middlename => 'Middle Name',
5553: generation => 'Generation',
5554: );
5555: $othertitle = &mt('All users');
5556: if (keys(%{$usertypes}) > 0) {
5557: $othertitle = &mt('Other users');
5558: }
5559: foreach my $key (keys(%env)) {
5560: if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
5561: my ($usertype,$item) = ($1,$2);
5562: if (grep(/^\Q$item\E$/,keys(%fieldtitles))) {
5563: if ($usertype eq 'default') {
5564: push(@{$fields{$1}},$2);
5565: } elsif (ref($types) eq 'ARRAY') {
5566: if (grep(/^\Q$usertype\E$/,@{$types})) {
5567: push(@{$fields{$1}},$2);
5568: }
5569: }
5570: }
5571: }
5572: }
5573: my @lockablenames = &Apache::loncommon::get_env_multiple('form.lockablenames');
5574: @lockablenames = sort(@lockablenames);
5575: if (ref($currautoupdate{'lockablenames'}) eq 'ARRAY') {
5576: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
5577: if (@changed) {
5578: $changes{'lockablenames'} = 1;
5579: }
5580: } else {
5581: if (@lockablenames) {
5582: $changes{'lockablenames'} = 1;
5583: }
5584: }
5585: my %updatehash = (
5586: autoupdate => { run => $env{'form.autoupdate_run'},
5587: classlists => $env{'form.classlists'},
5588: fields => {%fields},
5589: lockablenames => \@lockablenames,
5590: }
5591: );
5592: foreach my $key (keys(%currautoupdate)) {
5593: if (($key eq 'run') || ($key eq 'classlists')) {
5594: if (exists($updatehash{autoupdate}{$key})) {
5595: if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
5596: $changes{$key} = 1;
5597: }
5598: }
5599: } elsif ($key eq 'fields') {
5600: if (ref($currautoupdate{$key}) eq 'HASH') {
5601: foreach my $item (@{$types},'default') {
5602: if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
5603: my $change = 0;
5604: foreach my $type (@{$currautoupdate{$key}{$item}}) {
5605: if (!exists($fields{$item})) {
5606: $change = 1;
5607: last;
5608: } elsif (ref($fields{$item}) eq 'ARRAY') {
5609: if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
5610: $change = 1;
5611: last;
5612: }
5613: }
5614: }
5615: if ($change) {
5616: push(@{$changes{$key}},$item);
5617: }
5618: }
5619: }
5620: }
5621: } elsif ($key eq 'lockablenames') {
5622: if (ref($currautoupdate{$key}) eq 'ARRAY') {
5623: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
5624: if (@changed) {
5625: $changes{'lockablenames'} = 1;
5626: }
5627: } else {
5628: if (@lockablenames) {
5629: $changes{'lockablenames'} = 1;
5630: }
5631: }
5632: }
5633: }
5634: unless (grep(/^\Qlockablenames\E$/,keys(%currautoupdate))) {
5635: if (@lockablenames) {
5636: $changes{'lockablenames'} = 1;
5637: }
5638: }
5639: foreach my $item (@{$types},'default') {
5640: if (defined($fields{$item})) {
5641: if (ref($currautoupdate{'fields'}) eq 'HASH') {
5642: if (ref($currautoupdate{'fields'}{$item}) eq 'ARRAY') {
5643: my $change = 0;
5644: if (ref($fields{$item}) eq 'ARRAY') {
5645: foreach my $type (@{$fields{$item}}) {
5646: if (!grep(/^\Q$type\E$/,@{$currautoupdate{'fields'}{$item}})) {
5647: $change = 1;
5648: last;
5649: }
5650: }
5651: }
5652: if ($change) {
5653: push(@{$changes{'fields'}},$item);
5654: }
5655: } else {
5656: push(@{$changes{'fields'}},$item);
5657: }
5658: } else {
5659: push(@{$changes{'fields'}},$item);
5660: }
5661: }
5662: }
5663: my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
5664: $dom);
5665: if ($putresult eq 'ok') {
5666: if (keys(%changes) > 0) {
5667: $resulttext = &mt('Changes made:').'<ul>';
5668: foreach my $key (sort(keys(%changes))) {
5669: if ($key eq 'lockablenames') {
5670: $resulttext .= '<li>';
5671: if (@lockablenames) {
5672: $usertypes->{'default'} = $othertitle;
5673: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update), available for the following affiliations:").' '.
5674: join(', ', map { $usertypes->{$_}; } @lockablenames).'</li>';
5675: } else {
5676: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update) is unavailable.");
5677: }
5678: $resulttext .= '</li>';
5679: } elsif (ref($changes{$key}) eq 'ARRAY') {
5680: foreach my $item (@{$changes{$key}}) {
5681: my @newvalues;
5682: foreach my $type (@{$fields{$item}}) {
5683: push(@newvalues,$fieldtitles{$type});
5684: }
5685: my $newvaluestr;
5686: if (@newvalues > 0) {
5687: $newvaluestr = join(', ',@newvalues);
5688: } else {
5689: $newvaluestr = &mt('none');
5690: }
5691: if ($item eq 'default') {
5692: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
5693: } else {
5694: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
5695: }
5696: }
5697: } else {
5698: my $newvalue;
5699: if ($key eq 'run') {
5700: $newvalue = $offon[$env{'form.autoupdate_run'}];
5701: } else {
5702: $newvalue = $offon[$env{'form.'.$key}];
5703: }
5704: $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
5705: }
5706: }
5707: $resulttext .= '</ul>';
5708: } else {
5709: $resulttext = &mt('No changes made to autoupdates');
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_autocreate {
5719: my ($dom,%domconfig) = @_;
5720: my ($resulttext,%changes,%currautocreate,%newvals,%autocreatehash);
5721: if (ref($domconfig{'autocreate'}) eq 'HASH') {
5722: foreach my $key (keys(%{$domconfig{'autocreate'}})) {
5723: $currautocreate{$key} = $domconfig{'autocreate'}{$key};
5724: }
5725: }
5726: my %title= ( xml => 'Auto-creation of courses in XML course description files',
5727: req => 'Auto-creation of validated requests for official courses',
5728: xmldc => 'Identity of course creator of courses from XML files',
5729: );
5730: my @types = ('xml','req');
5731: foreach my $item (@types) {
5732: $newvals{$item} = $env{'form.autocreate_'.$item};
5733: $newvals{$item} =~ s/\D//g;
5734: $newvals{$item} = 0 if ($newvals{$item} eq '');
5735: }
5736: $newvals{'xmldc'} = $env{'form.autocreate_xmldc'};
5737: my %domcoords = &get_active_dcs($dom);
5738: unless (exists($domcoords{$newvals{'xmldc'}})) {
5739: $newvals{'xmldc'} = '';
5740: }
5741: %autocreatehash = (
5742: autocreate => { xml => $newvals{'xml'},
5743: req => $newvals{'req'},
5744: }
5745: );
5746: if ($newvals{'xmldc'} ne '') {
5747: $autocreatehash{'autocreate'}{'xmldc'} = $newvals{'xmldc'};
5748: }
5749: my $putresult = &Apache::lonnet::put_dom('configuration',\%autocreatehash,
5750: $dom);
5751: if ($putresult eq 'ok') {
5752: my @items = @types;
5753: if ($newvals{'xml'}) {
5754: push(@items,'xmldc');
5755: }
5756: foreach my $item (@items) {
5757: if (exists($currautocreate{$item})) {
5758: if ($currautocreate{$item} ne $newvals{$item}) {
5759: $changes{$item} = 1;
5760: }
5761: } elsif ($newvals{$item}) {
5762: $changes{$item} = 1;
5763: }
5764: }
5765: if (keys(%changes) > 0) {
5766: my @offon = ('off','on');
5767: $resulttext = &mt('Changes made:').'<ul>';
5768: foreach my $item (@types) {
5769: if ($changes{$item}) {
5770: my $newtxt = $offon[$newvals{$item}];
5771: $resulttext .= '<li>'.&mt("$title{$item} set to [_1]$newtxt [_2]",'<b>','</b>').'</li>';
5772: }
5773: }
5774: if ($changes{'xmldc'}) {
5775: my ($dcname,$dcdom) = split(':',$newvals{'xmldc'});
5776: my $newtxt = &Apache::loncommon::plainname($dcname,$dcdom);
5777: $resulttext .= '<li>'.&mt("$title{'xmldc'} set to [_1]$newtxt [_2]",'<b>','</b>').'</li>';
5778: }
5779: $resulttext .= '</ul>';
5780: } else {
5781: $resulttext = &mt('No changes made to auto-creation settings');
5782: }
5783: } else {
5784: $resulttext = '<span class="LC_error">'.
5785: &mt('An error occurred: [_1]',$putresult).'</span>';
5786: }
5787: return $resulttext;
5788: }
5789:
5790: sub modify_directorysrch {
5791: my ($dom,%domconfig) = @_;
5792: my ($resulttext,%changes);
5793: my %currdirsrch;
5794: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
5795: foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
5796: $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
5797: }
5798: }
5799: my %title = ( available => 'Directory search available',
5800: localonly => 'Other domains can search',
5801: searchby => 'Search types',
5802: searchtypes => 'Search latitude');
5803: my @offon = ('off','on');
5804: my @otherdoms = ('Yes','No');
5805:
5806: my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');
5807: my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
5808: my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
5809:
5810: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
5811: if (keys(%{$usertypes}) == 0) {
5812: @cansearch = ('default');
5813: } else {
5814: if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
5815: foreach my $type (@{$currdirsrch{'cansearch'}}) {
5816: if (!grep(/^\Q$type\E$/,@cansearch)) {
5817: push(@{$changes{'cansearch'}},$type);
5818: }
5819: }
5820: foreach my $type (@cansearch) {
5821: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
5822: push(@{$changes{'cansearch'}},$type);
5823: }
5824: }
5825: } else {
5826: push(@{$changes{'cansearch'}},@cansearch);
5827: }
5828: }
5829:
5830: if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
5831: foreach my $by (@{$currdirsrch{'searchby'}}) {
5832: if (!grep(/^\Q$by\E$/,@searchby)) {
5833: push(@{$changes{'searchby'}},$by);
5834: }
5835: }
5836: foreach my $by (@searchby) {
5837: if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
5838: push(@{$changes{'searchby'}},$by);
5839: }
5840: }
5841: } else {
5842: push(@{$changes{'searchby'}},@searchby);
5843: }
5844:
5845: if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
5846: foreach my $type (@{$currdirsrch{'searchtypes'}}) {
5847: if (!grep(/^\Q$type\E$/,@searchtypes)) {
5848: push(@{$changes{'searchtypes'}},$type);
5849: }
5850: }
5851: foreach my $type (@searchtypes) {
5852: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
5853: push(@{$changes{'searchtypes'}},$type);
5854: }
5855: }
5856: } else {
5857: if (exists($currdirsrch{'searchtypes'})) {
5858: foreach my $type (@searchtypes) {
5859: if ($type ne $currdirsrch{'searchtypes'}) {
5860: push(@{$changes{'searchtypes'}},$type);
5861: }
5862: }
5863: if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
5864: push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
5865: }
5866: } else {
5867: push(@{$changes{'searchtypes'}},@searchtypes);
5868: }
5869: }
5870:
5871: my %dirsrch_hash = (
5872: directorysrch => { available => $env{'form.dirsrch_available'},
5873: cansearch => \@cansearch,
5874: localonly => $env{'form.dirsrch_localonly'},
5875: searchby => \@searchby,
5876: searchtypes => \@searchtypes,
5877: }
5878: );
5879: my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
5880: $dom);
5881: if ($putresult eq 'ok') {
5882: if (exists($currdirsrch{'available'})) {
5883: if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
5884: $changes{'available'} = 1;
5885: }
5886: } else {
5887: if ($env{'form.dirsrch_available'} eq '1') {
5888: $changes{'available'} = 1;
5889: }
5890: }
5891: if (exists($currdirsrch{'localonly'})) {
5892: if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_localonly'}) {
5893: $changes{'localonly'} = 1;
5894: }
5895: } else {
5896: if ($env{'form.dirsrch_localonly'} eq '1') {
5897: $changes{'localonly'} = 1;
5898: }
5899: }
5900: if (keys(%changes) > 0) {
5901: $resulttext = &mt('Changes made:').'<ul>';
5902: if ($changes{'available'}) {
5903: $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
5904: }
5905: if ($changes{'localonly'}) {
5906: $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_localonly'}]").'</li>';
5907: }
5908:
5909: if (ref($changes{'cansearch'}) eq 'ARRAY') {
5910: my $chgtext;
5911: if (ref($usertypes) eq 'HASH') {
5912: if (keys(%{$usertypes}) > 0) {
5913: foreach my $type (@{$types}) {
5914: if (grep(/^\Q$type\E$/,@cansearch)) {
5915: $chgtext .= $usertypes->{$type}.'; ';
5916: }
5917: }
5918: if (grep(/^default$/,@cansearch)) {
5919: $chgtext .= $othertitle;
5920: } else {
5921: $chgtext =~ s/\; $//;
5922: }
5923: $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>';
5924: }
5925: }
5926: }
5927: if (ref($changes{'searchby'}) eq 'ARRAY') {
5928: my ($searchtitles,$titleorder) = &sorted_searchtitles();
5929: my $chgtext;
5930: foreach my $type (@{$titleorder}) {
5931: if (grep(/^\Q$type\E$/,@searchby)) {
5932: if (defined($searchtitles->{$type})) {
5933: $chgtext .= $searchtitles->{$type}.'; ';
5934: }
5935: }
5936: }
5937: $chgtext =~ s/\; $//;
5938: $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
5939: }
5940: if (ref($changes{'searchtypes'}) eq 'ARRAY') {
5941: my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes();
5942: my $chgtext;
5943: foreach my $type (@{$srchtypeorder}) {
5944: if (grep(/^\Q$type\E$/,@searchtypes)) {
5945: if (defined($srchtypes_desc->{$type})) {
5946: $chgtext .= $srchtypes_desc->{$type}.'; ';
5947: }
5948: }
5949: }
5950: $chgtext =~ s/\; $//;
5951: $resulttext .= '<li>'.&mt("$title{'searchtypes'} set to: \"[_1]\"",$chgtext).'</li>';
5952: }
5953: $resulttext .= '</ul>';
5954: } else {
5955: $resulttext = &mt('No changes made to institution directory search settings');
5956: }
5957: } else {
5958: $resulttext = '<span class="LC_error">'.
5959: &mt('An error occurred: [_1]',$putresult).'</span>';
5960: }
5961: return $resulttext;
5962: }
5963:
5964: sub modify_contacts {
5965: my ($dom,%domconfig) = @_;
5966: my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
5967: if (ref($domconfig{'contacts'}) eq 'HASH') {
5968: foreach my $key (keys(%{$domconfig{'contacts'}})) {
5969: $currsetting{$key} = $domconfig{'contacts'}{$key};
5970: }
5971: }
5972: my (%others,%to,%bcc);
5973: my @contacts = ('supportemail','adminemail');
5974: my @mailings = ('errormail','packagesmail','helpdeskmail','lonstatusmail',
5975: 'requestsmail');
5976: foreach my $type (@mailings) {
5977: @{$newsetting{$type}} =
5978: &Apache::loncommon::get_env_multiple('form.'.$type);
5979: foreach my $item (@contacts) {
5980: if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
5981: $contacts_hash{contacts}{$type}{$item} = 1;
5982: } else {
5983: $contacts_hash{contacts}{$type}{$item} = 0;
5984: }
5985: }
5986: $others{$type} = $env{'form.'.$type.'_others'};
5987: $contacts_hash{contacts}{$type}{'others'} = $others{$type};
5988: if ($type eq 'helpdeskmail') {
5989: $bcc{$type} = $env{'form.'.$type.'_bcc'};
5990: $contacts_hash{contacts}{$type}{'bcc'} = $bcc{$type};
5991: }
5992: }
5993: foreach my $item (@contacts) {
5994: $to{$item} = $env{'form.'.$item};
5995: $contacts_hash{'contacts'}{$item} = $to{$item};
5996: }
5997: if (keys(%currsetting) > 0) {
5998: foreach my $item (@contacts) {
5999: if ($to{$item} ne $currsetting{$item}) {
6000: $changes{$item} = 1;
6001: }
6002: }
6003: foreach my $type (@mailings) {
6004: foreach my $item (@contacts) {
6005: if (ref($currsetting{$type}) eq 'HASH') {
6006: if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
6007: push(@{$changes{$type}},$item);
6008: }
6009: } else {
6010: push(@{$changes{$type}},@{$newsetting{$type}});
6011: }
6012: }
6013: if ($others{$type} ne $currsetting{$type}{'others'}) {
6014: push(@{$changes{$type}},'others');
6015: }
6016: if ($type eq 'helpdeskmail') {
6017: if ($bcc{$type} ne $currsetting{$type}{'bcc'}) {
6018: push(@{$changes{$type}},'bcc');
6019: }
6020: }
6021: }
6022: } else {
6023: my %default;
6024: $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
6025: $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
6026: $default{'errormail'} = 'adminemail';
6027: $default{'packagesmail'} = 'adminemail';
6028: $default{'helpdeskmail'} = 'supportemail';
6029: $default{'lonstatusmail'} = 'adminemail';
6030: $default{'requestsmail'} = 'adminemail';
6031: foreach my $item (@contacts) {
6032: if ($to{$item} ne $default{$item}) {
6033: $changes{$item} = 1;
6034: }
6035: }
6036: foreach my $type (@mailings) {
6037: if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
6038:
6039: push(@{$changes{$type}},@{$newsetting{$type}});
6040: }
6041: if ($others{$type} ne '') {
6042: push(@{$changes{$type}},'others');
6043: }
6044: if ($type eq 'helpdeskmail') {
6045: if ($bcc{$type} ne '') {
6046: push(@{$changes{$type}},'bcc');
6047: }
6048: }
6049: }
6050: }
6051: my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
6052: $dom);
6053: if ($putresult eq 'ok') {
6054: if (keys(%changes) > 0) {
6055: my ($titles,$short_titles) = &contact_titles();
6056: $resulttext = &mt('Changes made:').'<ul>';
6057: foreach my $item (@contacts) {
6058: if ($changes{$item}) {
6059: $resulttext .= '<li>'.$titles->{$item}.
6060: &mt(' set to: ').
6061: '<span class="LC_cusr_emph">'.
6062: $to{$item}.'</span></li>';
6063: }
6064: }
6065: foreach my $type (@mailings) {
6066: if (ref($changes{$type}) eq 'ARRAY') {
6067: $resulttext .= '<li>'.$titles->{$type}.': ';
6068: my @text;
6069: foreach my $item (@{$newsetting{$type}}) {
6070: push(@text,$short_titles->{$item});
6071: }
6072: if ($others{$type} ne '') {
6073: push(@text,$others{$type});
6074: }
6075: $resulttext .= '<span class="LC_cusr_emph">'.
6076: join(', ',@text).'</span>';
6077: if ($type eq 'helpdeskmail') {
6078: if ($bcc{$type} ne '') {
6079: $resulttext .= ' '.&mt('with Bcc to').': <span class="LC_cusr_emph">'.$bcc{$type}.'</span>';
6080: }
6081: }
6082: $resulttext .= '</li>';
6083: }
6084: }
6085: $resulttext .= '</ul>';
6086: } else {
6087: $resulttext = &mt('No changes made to contact information');
6088: }
6089: } else {
6090: $resulttext = '<span class="LC_error">'.
6091: &mt('An error occurred: [_1].',$putresult).'</span>';
6092: }
6093: return $resulttext;
6094: }
6095:
6096: sub modify_usercreation {
6097: my ($dom,%domconfig) = @_;
6098: my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate);
6099: my $warningmsg;
6100: if (ref($domconfig{'usercreation'}) eq 'HASH') {
6101: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
6102: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
6103: }
6104: }
6105: my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
6106: my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
6107: my @email_rule = &Apache::loncommon::get_env_multiple('form.email_rule');
6108: my @contexts = ('author','course','requestcrs','selfcreate');
6109: foreach my $item(@contexts) {
6110: if ($item eq 'selfcreate') {
6111: @{$cancreate{$item}} = &Apache::loncommon::get_env_multiple('form.can_createuser_'.$item);
6112: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
6113: if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) || ($domdefaults{'auth_def'} eq 'localauth'))) {
6114: if (ref($cancreate{$item}) eq 'ARRAY') {
6115: if (grep(/^login$/,@{$cancreate{$item}})) {
6116: $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.');
6117: }
6118: }
6119: }
6120: } else {
6121: $cancreate{$item} = $env{'form.can_createuser_'.$item};
6122: }
6123: }
6124: my ($othertitle,$usertypes,$types) =
6125: &Apache::loncommon::sorted_inst_types($dom);
6126: if (ref($types) eq 'ARRAY') {
6127: if (@{$types} > 0) {
6128: @{$cancreate{'statustocreate'}} =
6129: &Apache::loncommon::get_env_multiple('form.statustocreate');
6130: } else {
6131: @{$cancreate{'statustocreate'}} = ();
6132: }
6133: push(@contexts,'statustocreate');
6134: }
6135: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
6136: foreach my $item (@contexts) {
6137: if (($item eq 'selfcreate') || ($item eq 'statustocreate')) {
6138: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
6139: foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
6140: if (ref($cancreate{$item}) eq 'ARRAY') {
6141: if (!grep(/^$curr$/,@{$cancreate{$item}})) {
6142: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6143: push(@{$changes{'cancreate'}},$item);
6144: }
6145: }
6146: }
6147: }
6148: } else {
6149: if ($curr_usercreation{'cancreate'}{$item} eq '') {
6150: if (@{$cancreate{$item}} > 0) {
6151: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6152: push(@{$changes{'cancreate'}},$item);
6153: }
6154: }
6155: } else {
6156: if ($curr_usercreation{'cancreate'}{$item} eq 'any') {
6157: if (@{$cancreate{$item}} < 3) {
6158: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6159: push(@{$changes{'cancreate'}},$item);
6160: }
6161: }
6162: } elsif ($curr_usercreation{'cancreate'}{$item} eq 'none') {
6163: if (@{$cancreate{$item}} > 0) {
6164: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6165: push(@{$changes{'cancreate'}},$item);
6166: }
6167: }
6168: } elsif (!grep(/^$curr_usercreation{'cancreate'}{$item}$/,@{$cancreate{$item}})) {
6169: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6170: push(@{$changes{'cancreate'}},$item);
6171: }
6172: }
6173: }
6174: }
6175: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6176: foreach my $type (@{$cancreate{$item}}) {
6177: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
6178: if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
6179: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6180: push(@{$changes{'cancreate'}},$item);
6181: }
6182: }
6183: } elsif (($curr_usercreation{'cancreate'}{$item} ne 'any') &&
6184: ($curr_usercreation{'cancreate'}{$item} ne 'none')) {
6185: if ($curr_usercreation{'cancreate'}{$item} ne $type) {
6186: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6187: push(@{$changes{'cancreate'}},$item);
6188: }
6189: }
6190: }
6191: }
6192: }
6193: } else {
6194: if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
6195: push(@{$changes{'cancreate'}},$item);
6196: }
6197: }
6198: }
6199: } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
6200: foreach my $item (@contexts) {
6201: if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
6202: if ($cancreate{$item} ne 'any') {
6203: push(@{$changes{'cancreate'}},$item);
6204: }
6205: } else {
6206: if ($cancreate{$item} ne 'none') {
6207: push(@{$changes{'cancreate'}},$item);
6208: }
6209: }
6210: }
6211: } else {
6212: foreach my $item (@contexts) {
6213: push(@{$changes{'cancreate'}},$item);
6214: }
6215: }
6216:
6217: if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
6218: foreach my $type (@{$curr_usercreation{'username_rule'}}) {
6219: if (!grep(/^\Q$type\E$/,@username_rule)) {
6220: push(@{$changes{'username_rule'}},$type);
6221: }
6222: }
6223: foreach my $type (@username_rule) {
6224: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
6225: push(@{$changes{'username_rule'}},$type);
6226: }
6227: }
6228: } else {
6229: push(@{$changes{'username_rule'}},@username_rule);
6230: }
6231:
6232: if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
6233: foreach my $type (@{$curr_usercreation{'id_rule'}}) {
6234: if (!grep(/^\Q$type\E$/,@id_rule)) {
6235: push(@{$changes{'id_rule'}},$type);
6236: }
6237: }
6238: foreach my $type (@id_rule) {
6239: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
6240: push(@{$changes{'id_rule'}},$type);
6241: }
6242: }
6243: } else {
6244: push(@{$changes{'id_rule'}},@id_rule);
6245: }
6246:
6247: if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
6248: foreach my $type (@{$curr_usercreation{'email_rule'}}) {
6249: if (!grep(/^\Q$type\E$/,@email_rule)) {
6250: push(@{$changes{'email_rule'}},$type);
6251: }
6252: }
6253: foreach my $type (@email_rule) {
6254: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'email_rule'}})) {
6255: push(@{$changes{'email_rule'}},$type);
6256: }
6257: }
6258: } else {
6259: push(@{$changes{'email_rule'}},@email_rule);
6260: }
6261:
6262: my @authen_contexts = ('author','course','domain');
6263: my @authtypes = ('int','krb4','krb5','loc');
6264: my %authhash;
6265: foreach my $item (@authen_contexts) {
6266: my @authallowed = &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
6267: foreach my $auth (@authtypes) {
6268: if (grep(/^\Q$auth\E$/,@authallowed)) {
6269: $authhash{$item}{$auth} = 1;
6270: } else {
6271: $authhash{$item}{$auth} = 0;
6272: }
6273: }
6274: }
6275: if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
6276: foreach my $item (@authen_contexts) {
6277: if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
6278: foreach my $auth (@authtypes) {
6279: if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
6280: push(@{$changes{'authtypes'}},$item);
6281: last;
6282: }
6283: }
6284: }
6285: }
6286: } else {
6287: foreach my $item (@authen_contexts) {
6288: push(@{$changes{'authtypes'}},$item);
6289: }
6290: }
6291:
6292: my %usercreation_hash = (
6293: usercreation => {
6294: cancreate => \%cancreate,
6295: username_rule => \@username_rule,
6296: id_rule => \@id_rule,
6297: email_rule => \@email_rule,
6298: authtypes => \%authhash,
6299: }
6300: );
6301:
6302: my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
6303: $dom);
6304:
6305: my %selfcreatetypes = (
6306: sso => 'users authenticated by institutional single sign on',
6307: login => 'users authenticated by institutional log-in',
6308: email => 'users who provide a valid e-mail address for use as the username',
6309: );
6310: if ($putresult eq 'ok') {
6311: if (keys(%changes) > 0) {
6312: $resulttext = &mt('Changes made:').'<ul>';
6313: if (ref($changes{'cancreate'}) eq 'ARRAY') {
6314: my %lt = &usercreation_types();
6315: foreach my $type (@{$changes{'cancreate'}}) {
6316: my $chgtext;
6317: unless ($type eq 'statustocreate') {
6318: $chgtext = $lt{$type}.', ';
6319: }
6320: if ($type eq 'selfcreate') {
6321: if (@{$cancreate{$type}} == 0) {
6322: $chgtext .= &mt('creation of a new user account is not permitted.');
6323: } else {
6324: $chgtext .= &mt('creation of a new account is permitted for:').'<ul>';
6325: foreach my $case (@{$cancreate{$type}}) {
6326: $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
6327: }
6328: $chgtext .= '</ul>';
6329: if (ref($cancreate{$type}) eq 'ARRAY') {
6330: if (grep(/^(login|sso)$/,@{$cancreate{$type}})) {
6331: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
6332: if (@{$cancreate{'statustocreate'}} == 0) {
6333: $chgtext .= '<br /><span class="LC_warning">'.&mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").'</span>';
6334: }
6335: }
6336: }
6337: }
6338: }
6339: } elsif ($type eq 'statustocreate') {
6340: if ((ref($cancreate{'selfcreate'}) eq 'ARRAY') &&
6341: (ref($cancreate{'statustocreate'}) eq 'ARRAY')) {
6342: if (@{$cancreate{'selfcreate'}} > 0) {
6343: if (@{$cancreate{'statustocreate'}} == 0) {
6344:
6345: $chgtext .= &mt("Institutional affiliations permitted to create accounts set to 'None'.");
6346: if (!grep(/^email$/,@{$cancreate{'selfcreate'}})) {
6347: $chgtext .= '<br /><span class="LC_warning">'.&mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").'</span>';
6348: }
6349: } elsif (ref($usertypes) eq 'HASH') {
6350: if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
6351: $chgtext .= &mt('Creation of a new account for an institutional user is restricted to the following institutional affiliation(s):');
6352: } else {
6353: $chgtext .= &mt('Institutional affiliations permitted to create accounts with institutional authentication were set as follows:');
6354: }
6355: $chgtext .= '<ul>';
6356: foreach my $case (@{$cancreate{$type}}) {
6357: if ($case eq 'default') {
6358: $chgtext .= '<li>'.$othertitle.'</li>';
6359: } else {
6360: $chgtext .= '<li>'.$usertypes->{$case}.'</li>';
6361: }
6362: }
6363: $chgtext .= '</ul>';
6364: if (!grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
6365: $chgtext .= '<br /><span class="LC_warning">'.&mt('However, users authenticated by institutional login/single sign on are not currently permitted to create accounts.').'</span>';
6366: }
6367: }
6368: } else {
6369: if (@{$cancreate{$type}} == 0) {
6370: $chgtext .= &mt("Institutional affiliations permitted to create accounts were set to 'none'.");
6371: } else {
6372: $chgtext .= &mt('Although institutional affiliations permitted to create accounts were changed, self creation of accounts is not currently permitted for any authentication types.');
6373: }
6374: }
6375: }
6376: } else {
6377: if ($cancreate{$type} eq 'none') {
6378: $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
6379: } elsif ($cancreate{$type} eq 'any') {
6380: $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
6381: } elsif ($cancreate{$type} eq 'official') {
6382: $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
6383: } elsif ($cancreate{$type} eq 'unofficial') {
6384: $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
6385: }
6386: }
6387: $resulttext .= '<li>'.$chgtext.'</li>';
6388: }
6389: }
6390: if (ref($changes{'username_rule'}) eq 'ARRAY') {
6391: my ($rules,$ruleorder) =
6392: &Apache::lonnet::inst_userrules($dom,'username');
6393: my $chgtext = '<ul>';
6394: foreach my $type (@username_rule) {
6395: if (ref($rules->{$type}) eq 'HASH') {
6396: $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
6397: }
6398: }
6399: $chgtext .= '</ul>';
6400: if (@username_rule > 0) {
6401: $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
6402: } else {
6403: $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>';
6404: }
6405: }
6406: if (ref($changes{'id_rule'}) eq 'ARRAY') {
6407: my ($idrules,$idruleorder) =
6408: &Apache::lonnet::inst_userrules($dom,'id');
6409: my $chgtext = '<ul>';
6410: foreach my $type (@id_rule) {
6411: if (ref($idrules->{$type}) eq 'HASH') {
6412: $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
6413: }
6414: }
6415: $chgtext .= '</ul>';
6416: if (@id_rule > 0) {
6417: $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
6418: } else {
6419: $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
6420: }
6421: }
6422: if (ref($changes{'email_rule'}) eq 'ARRAY') {
6423: my ($emailrules,$emailruleorder) =
6424: &Apache::lonnet::inst_userrules($dom,'email');
6425: my $chgtext = '<ul>';
6426: foreach my $type (@email_rule) {
6427: if (ref($emailrules->{$type}) eq 'HASH') {
6428: $chgtext .= '<li>'.$emailrules->{$type}{'name'}.'</li>';
6429: }
6430: }
6431: $chgtext .= '</ul>';
6432: if (@email_rule > 0) {
6433: $resulttext .= '<li>'.&mt('Accounts may not be created by users self-enrolling with e-mail addresses of the following types: ').$chgtext.'</li>';
6434: } else {
6435: $resulttext .= '<li>'.&mt('There are now no restrictions on e-mail addresses which may be used as a username when self-enrolling.').'</li>';
6436: }
6437: }
6438:
6439: my %authname = &authtype_names();
6440: my %context_title = &context_names();
6441: if (ref($changes{'authtypes'}) eq 'ARRAY') {
6442: my $chgtext = '<ul>';
6443: foreach my $type (@{$changes{'authtypes'}}) {
6444: my @allowed;
6445: $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
6446: foreach my $auth (@authtypes) {
6447: if ($authhash{$type}{$auth}) {
6448: push(@allowed,$authname{$auth});
6449: }
6450: }
6451: if (@allowed > 0) {
6452: $chgtext .= join(', ',@allowed).'</li>';
6453: } else {
6454: $chgtext .= &mt('none').'</li>';
6455: }
6456: }
6457: $chgtext .= '</ul>';
6458: $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
6459: $resulttext .= '</li>';
6460: }
6461: $resulttext .= '</ul>';
6462: } else {
6463: $resulttext = &mt('No changes made to user creation settings');
6464: }
6465: } else {
6466: $resulttext = '<span class="LC_error">'.
6467: &mt('An error occurred: [_1]',$putresult).'</span>';
6468: }
6469: if ($warningmsg ne '') {
6470: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
6471: }
6472: return $resulttext;
6473: }
6474:
6475: sub modify_usermodification {
6476: my ($dom,%domconfig) = @_;
6477: my ($resulttext,%curr_usermodification,%changes);
6478: if (ref($domconfig{'usermodification'}) eq 'HASH') {
6479: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
6480: $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
6481: }
6482: }
6483: my @contexts = ('author','course','selfcreate');
6484: my %context_title = (
6485: author => 'In author context',
6486: course => 'In course context',
6487: selfcreate => 'When self creating account',
6488: );
6489: my @fields = ('lastname','firstname','middlename','generation',
6490: 'permanentemail','id');
6491: my %roles = (
6492: author => ['ca','aa'],
6493: course => ['st','ep','ta','in','cr'],
6494: );
6495: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
6496: if (ref($types) eq 'ARRAY') {
6497: push(@{$types},'default');
6498: $usertypes->{'default'} = $othertitle;
6499: }
6500: $roles{'selfcreate'} = $types;
6501: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
6502: my %modifyhash;
6503: foreach my $context (@contexts) {
6504: foreach my $role (@{$roles{$context}}) {
6505: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$role);
6506: foreach my $item (@fields) {
6507: if (grep(/^\Q$item\E$/,@modifiable)) {
6508: $modifyhash{$context}{$role}{$item} = 1;
6509: } else {
6510: $modifyhash{$context}{$role}{$item} = 0;
6511: }
6512: }
6513: }
6514: if (ref($curr_usermodification{$context}) eq 'HASH') {
6515: foreach my $role (@{$roles{$context}}) {
6516: if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
6517: foreach my $field (@fields) {
6518: if ($modifyhash{$context}{$role}{$field} ne
6519: $curr_usermodification{$context}{$role}{$field}) {
6520: push(@{$changes{$context}},$role);
6521: last;
6522: }
6523: }
6524: }
6525: }
6526: } else {
6527: foreach my $context (@contexts) {
6528: foreach my $role (@{$roles{$context}}) {
6529: push(@{$changes{$context}},$role);
6530: }
6531: }
6532: }
6533: }
6534: my %usermodification_hash = (
6535: usermodification => \%modifyhash,
6536: );
6537: my $putresult = &Apache::lonnet::put_dom('configuration',
6538: \%usermodification_hash,$dom);
6539: if ($putresult eq 'ok') {
6540: if (keys(%changes) > 0) {
6541: $resulttext = &mt('Changes made: ').'<ul>';
6542: foreach my $context (@contexts) {
6543: if (ref($changes{$context}) eq 'ARRAY') {
6544: $resulttext .= '<li>'.$context_title{$context}.':<ul>';
6545: if (ref($changes{$context}) eq 'ARRAY') {
6546: foreach my $role (@{$changes{$context}}) {
6547: my $rolename;
6548: if ($context eq 'selfcreate') {
6549: $rolename = $role;
6550: if (ref($usertypes) eq 'HASH') {
6551: if ($usertypes->{$role} ne '') {
6552: $rolename = $usertypes->{$role};
6553: }
6554: }
6555: } else {
6556: if ($role eq 'cr') {
6557: $rolename = &mt('Custom');
6558: } else {
6559: $rolename = &Apache::lonnet::plaintext($role);
6560: }
6561: }
6562: my @modifiable;
6563: if ($context eq 'selfcreate') {
6564: $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): ');
6565: } else {
6566: $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
6567: }
6568: foreach my $field (@fields) {
6569: if ($modifyhash{$context}{$role}{$field}) {
6570: push(@modifiable,$fieldtitles{$field});
6571: }
6572: }
6573: if (@modifiable > 0) {
6574: $resulttext .= join(', ',@modifiable);
6575: } else {
6576: $resulttext .= &mt('none');
6577: }
6578: $resulttext .= '</li>';
6579: }
6580: $resulttext .= '</ul></li>';
6581: }
6582: }
6583: }
6584: $resulttext .= '</ul>';
6585: } else {
6586: $resulttext = &mt('No changes made to user modification settings');
6587: }
6588: } else {
6589: $resulttext = '<span class="LC_error">'.
6590: &mt('An error occurred: [_1]',$putresult).'</span>';
6591: }
6592: return $resulttext;
6593: }
6594:
6595: sub modify_defaults {
6596: my ($dom,$r) = @_;
6597: my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
6598: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
6599: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def','portal_def');
6600: my @authtypes = ('internal','krb4','krb5','localauth');
6601: foreach my $item (@items) {
6602: $newvalues{$item} = $env{'form.'.$item};
6603: if ($item eq 'auth_def') {
6604: if ($newvalues{$item} ne '') {
6605: if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
6606: push(@errors,$item);
6607: }
6608: }
6609: } elsif ($item eq 'lang_def') {
6610: if ($newvalues{$item} ne '') {
6611: if ($newvalues{$item} =~ /^(\w+)/) {
6612: my $langcode = $1;
6613: if ($langcode ne 'x_chef') {
6614: if (code2language($langcode) eq '') {
6615: push(@errors,$item);
6616: }
6617: }
6618: } else {
6619: push(@errors,$item);
6620: }
6621: }
6622: } elsif ($item eq 'timezone_def') {
6623: if ($newvalues{$item} ne '') {
6624: if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
6625: push(@errors,$item);
6626: }
6627: }
6628: } elsif ($item eq 'datelocale_def') {
6629: if ($newvalues{$item} ne '') {
6630: my @datelocale_ids = DateTime::Locale->ids();
6631: if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
6632: push(@errors,$item);
6633: }
6634: }
6635: } elsif ($item eq 'portal_def') {
6636: if ($newvalues{$item} ne '') {
6637: 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])\/?$/) {
6638: push(@errors,$item);
6639: }
6640: }
6641: }
6642: if (grep(/^\Q$item\E$/,@errors)) {
6643: $newvalues{$item} = $domdefaults{$item};
6644: } elsif ($domdefaults{$item} ne $newvalues{$item}) {
6645: $changes{$item} = 1;
6646: }
6647: $domdefaults{$item} = $newvalues{$item};
6648: }
6649: my %defaults_hash = (
6650: defaults => \%newvalues,
6651: );
6652: my $title = &defaults_titles();
6653: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
6654: $dom);
6655: if ($putresult eq 'ok') {
6656: if (keys(%changes) > 0) {
6657: $resulttext = &mt('Changes made:').'<ul>';
6658: my $version = $r->dir_config('lonVersion');
6659: 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";
6660: foreach my $item (sort(keys(%changes))) {
6661: my $value = $env{'form.'.$item};
6662: if ($value eq '') {
6663: $value = &mt('none');
6664: } elsif ($item eq 'auth_def') {
6665: my %authnames = &authtype_names();
6666: my %shortauth = (
6667: internal => 'int',
6668: krb4 => 'krb4',
6669: krb5 => 'krb5',
6670: localauth => 'loc',
6671: );
6672: $value = $authnames{$shortauth{$value}};
6673: }
6674: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
6675: $mailmsgtext .= "$title->{$item} set to $value\n";
6676: }
6677: $resulttext .= '</ul>';
6678: $mailmsgtext .= "\n";
6679: my $cachetime = 24*60*60;
6680: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
6681: if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
6682: my $sysmail = $r->dir_config('lonSysEMail');
6683: &Apache::lonmsg::sendemail($sysmail,"LON-CAPA Domain Settings Change - $dom",$mailmsgtext);
6684: }
6685: } else {
6686: $resulttext = &mt('No changes made to default authentication/language/timezone settings');
6687: }
6688: } else {
6689: $resulttext = '<span class="LC_error">'.
6690: &mt('An error occurred: [_1]',$putresult).'</span>';
6691: }
6692: if (@errors > 0) {
6693: $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
6694: foreach my $item (@errors) {
6695: $resulttext .= ' "'.$title->{$item}.'",';
6696: }
6697: $resulttext =~ s/,$//;
6698: }
6699: return $resulttext;
6700: }
6701:
6702: sub modify_scantron {
6703: my ($r,$dom,$confname,%domconfig) = @_;
6704: my ($resulttext,%confhash,%changes,$errors);
6705: my $custom = 'custom.tab';
6706: my $default = 'default.tab';
6707: my $servadm = $r->dir_config('lonAdmEMail');
6708: my ($configuserok,$author_ok,$switchserver) =
6709: &config_check($dom,$confname,$servadm);
6710: if ($env{'form.scantronformat.filename'} ne '') {
6711: my $error;
6712: if ($configuserok eq 'ok') {
6713: if ($switchserver) {
6714: $error = &mt("Upload of bubblesheet format file is not permitted to this server: [_1]",$switchserver);
6715: } else {
6716: if ($author_ok eq 'ok') {
6717: my ($result,$scantronurl) =
6718: &publishlogo($r,'upload','scantronformat',$dom,
6719: $confname,'scantron','','',$custom);
6720: if ($result eq 'ok') {
6721: $confhash{'scantron'}{'scantronformat'} = $scantronurl;
6722: $changes{'scantronformat'} = 1;
6723: } else {
6724: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
6725: }
6726: } else {
6727: $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);
6728: }
6729: }
6730: } else {
6731: $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);
6732: }
6733: if ($error) {
6734: &Apache::lonnet::logthis($error);
6735: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
6736: }
6737: }
6738: if (ref($domconfig{'scantron'}) eq 'HASH') {
6739: if ($domconfig{'scantron'}{'scantronformat'} ne '') {
6740: if ($env{'form.scantronformat_del'}) {
6741: $confhash{'scantron'}{'scantronformat'} = '';
6742: $changes{'scantronformat'} = 1;
6743: }
6744: }
6745: }
6746: if (keys(%confhash) > 0) {
6747: my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
6748: $dom);
6749: if ($putresult eq 'ok') {
6750: if (keys(%changes) > 0) {
6751: if (ref($confhash{'scantron'}) eq 'HASH') {
6752: $resulttext = &mt('Changes made:').'<ul>';
6753: if ($confhash{'scantron'}{'scantronformat'} eq '') {
6754: $resulttext .= '<li>'.&mt('[_1] bubblesheet format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
6755: } else {
6756: $resulttext .= '<li>'.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
6757: }
6758: $resulttext .= '</ul>';
6759: } else {
6760: $resulttext = &mt('Changes made to bubblesheet format file.');
6761: }
6762: $resulttext .= '</ul>';
6763: &Apache::loncommon::devalidate_domconfig_cache($dom);
6764: } else {
6765: $resulttext = &mt('No changes made to bubblesheet format file');
6766: }
6767: } else {
6768: $resulttext = '<span class="LC_error">'.
6769: &mt('An error occurred: [_1]',$putresult).'</span>';
6770: }
6771: } else {
6772: $resulttext = &mt('No changes made to bubblesheet format file');
6773: }
6774: if ($errors) {
6775: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
6776: $errors.'</ul>';
6777: }
6778: return $resulttext;
6779: }
6780:
6781: sub modify_coursecategories {
6782: my ($dom,%domconfig) = @_;
6783: my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
6784: $cathash);
6785: my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
6786: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
6787: $cathash = $domconfig{'coursecategories'}{'cats'};
6788: if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
6789: $changes{'togglecats'} = 1;
6790: $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
6791: }
6792: if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
6793: $changes{'categorize'} = 1;
6794: $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
6795: }
6796: if ($domconfig{'coursecategories'}{'togglecatscomm'} ne $env{'form.togglecatscomm'}) {
6797: $changes{'togglecatscomm'} = 1;
6798: $domconfig{'coursecategories'}{'togglecatscomm'} = $env{'form.togglecatscomm'};
6799: }
6800: if ($domconfig{'coursecategories'}{'categorizecomm'} ne $env{'form.categorizecomm'}) {
6801: $changes{'categorizecomm'} = 1;
6802: $domconfig{'coursecategories'}{'categorizecomm'} = $env{'form.categorizecomm'};
6803: }
6804: } else {
6805: $changes{'togglecats'} = 1;
6806: $changes{'categorize'} = 1;
6807: $changes{'togglecatscomm'} = 1;
6808: $changes{'categorizecomm'} = 1;
6809: $domconfig{'coursecategories'} = {
6810: togglecats => $env{'form.togglecats'},
6811: categorize => $env{'form.categorize'},
6812: togglecatscomm => $env{'form.togglecatscomm'},
6813: categorizecomm => $env{'form.categorizecomm'},
6814: };
6815: }
6816: if (ref($cathash) eq 'HASH') {
6817: if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '') && ($env{'form.instcode'} == 0)) {
6818: push (@deletecategory,'instcode::0');
6819: }
6820: if (($domconfig{'coursecategories'}{'cats'}{'communities::0'} ne '') && ($env{'form.communities'} == 0)) {
6821: push(@deletecategory,'communities::0');
6822: }
6823: }
6824: my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
6825: if (ref($cathash) eq 'HASH') {
6826: if (@deletecategory > 0) {
6827: #FIXME Need to remove category from all courses using a deleted category
6828: &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
6829: foreach my $item (@deletecategory) {
6830: if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
6831: delete($domconfig{'coursecategories'}{'cats'}{$item});
6832: $deletions{$item} = 1;
6833: &recurse_cat_deletes($item,$cathash,\%deletions);
6834: }
6835: }
6836: }
6837: foreach my $item (keys(%{$cathash})) {
6838: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
6839: if ($cathash->{$item} ne $env{'form.'.$item}) {
6840: $reorderings{$item} = 1;
6841: $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
6842: }
6843: if ($env{'form.addcategory_name_'.$item} ne '') {
6844: my $newcat = $env{'form.addcategory_name_'.$item};
6845: my $newdepth = $depth+1;
6846: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
6847: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
6848: $adds{$newitem} = 1;
6849: }
6850: if ($env{'form.subcat_'.$item} ne '') {
6851: my $newcat = $env{'form.subcat_'.$item};
6852: my $newdepth = $depth+1;
6853: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
6854: $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
6855: $adds{$newitem} = 1;
6856: }
6857: }
6858: }
6859: if ($env{'form.instcode'} eq '1') {
6860: if (ref($cathash) eq 'HASH') {
6861: my $newitem = 'instcode::0';
6862: if ($cathash->{$newitem} eq '') {
6863: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
6864: $adds{$newitem} = 1;
6865: }
6866: } else {
6867: my $newitem = 'instcode::0';
6868: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
6869: $adds{$newitem} = 1;
6870: }
6871: }
6872: if ($env{'form.communities'} eq '1') {
6873: if (ref($cathash) eq 'HASH') {
6874: my $newitem = 'communities::0';
6875: if ($cathash->{$newitem} eq '') {
6876: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
6877: $adds{$newitem} = 1;
6878: }
6879: } else {
6880: my $newitem = 'communities::0';
6881: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
6882: $adds{$newitem} = 1;
6883: }
6884: }
6885: if ($env{'form.addcategory_name'} ne '') {
6886: if (($env{'form.addcategory_name'} ne 'instcode') &&
6887: ($env{'form.addcategory_name'} ne 'communities')) {
6888: my $newitem = &escape($env{'form.addcategory_name'}).'::0';
6889: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
6890: $adds{$newitem} = 1;
6891: }
6892: }
6893: my $putresult;
6894: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
6895: if (keys(%deletions) > 0) {
6896: foreach my $key (keys(%deletions)) {
6897: if ($predelallitems{$key} ne '') {
6898: $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
6899: }
6900: }
6901: }
6902: my (@chkcats,@chktrails,%chkallitems);
6903: &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
6904: if (ref($chkcats[0]) eq 'ARRAY') {
6905: my $depth = 0;
6906: my $chg = 0;
6907: for (my $i=0; $i<@{$chkcats[0]}; $i++) {
6908: my $name = $chkcats[0][$i];
6909: my $item;
6910: if ($name eq '') {
6911: $chg ++;
6912: } else {
6913: $item = &escape($name).'::0';
6914: if ($chg) {
6915: $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
6916: }
6917: $depth ++;
6918: &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
6919: $depth --;
6920: }
6921: }
6922: }
6923: }
6924: if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
6925: $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
6926: if ($putresult eq 'ok') {
6927: my %title = (
6928: togglecats => 'Show/Hide a course in catalog',
6929: categorize => 'Assign a category to a course',
6930: togglecatscomm => 'Show/Hide a community in catalog',
6931: categorizecomm => 'Assign a category to a community',
6932: );
6933: my %level = (
6934: dom => 'set in Domain ("Modify Course/Community")',
6935: crs => 'set in Course ("Course Configuration")',
6936: comm => 'set in Community ("Community Configuration")',
6937: );
6938: $resulttext = &mt('Changes made:').'<ul>';
6939: if ($changes{'togglecats'}) {
6940: $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>';
6941: }
6942: if ($changes{'categorize'}) {
6943: $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
6944: }
6945: if ($changes{'togglecatscomm'}) {
6946: $resulttext .= '<li>'.&mt("$title{'togglecatscomm'} $level{$env{'form.togglecatscomm'}}").'</li>';
6947: }
6948: if ($changes{'categorizecomm'}) {
6949: $resulttext .= '<li>'.&mt("$title{'categorizecomm'} $level{$env{'form.categorizecomm'}}").'</li>';
6950: }
6951: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
6952: my $cathash;
6953: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
6954: $cathash = $domconfig{'coursecategories'}{'cats'};
6955: } else {
6956: $cathash = {};
6957: }
6958: my (@cats,@trails,%allitems);
6959: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
6960: if (keys(%deletions) > 0) {
6961: $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
6962: foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) {
6963: $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
6964: }
6965: $resulttext .= '</ul></li>';
6966: }
6967: if (keys(%reorderings) > 0) {
6968: my %sort_by_trail;
6969: $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
6970: foreach my $key (keys(%reorderings)) {
6971: if ($allitems{$key} ne '') {
6972: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
6973: }
6974: }
6975: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
6976: $resulttext .= '<li>'.$trails[$trail].'</li>';
6977: }
6978: $resulttext .= '</ul></li>';
6979: }
6980: if (keys(%adds) > 0) {
6981: my %sort_by_trail;
6982: $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
6983: foreach my $key (keys(%adds)) {
6984: if ($allitems{$key} ne '') {
6985: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
6986: }
6987: }
6988: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
6989: $resulttext .= '<li>'.$trails[$trail].'</li>';
6990: }
6991: $resulttext .= '</ul></li>';
6992: }
6993: }
6994: $resulttext .= '</ul>';
6995: } else {
6996: $resulttext = '<span class="LC_error">'.
6997: &mt('An error occurred: [_1]',$putresult).'</span>';
6998: }
6999: } else {
7000: $resulttext = &mt('No changes made to course and community categories');
7001: }
7002: return $resulttext;
7003: }
7004:
7005: sub modify_serverstatuses {
7006: my ($dom,%domconfig) = @_;
7007: my ($resulttext,%changes,%currserverstatus,%newserverstatus);
7008: if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
7009: %currserverstatus = %{$domconfig{'serverstatuses'}};
7010: }
7011: my @pages = &serverstatus_pages();
7012: foreach my $type (@pages) {
7013: $newserverstatus{$type}{'namedusers'} = '';
7014: $newserverstatus{$type}{'machines'} = '';
7015: if (defined($env{'form.'.$type.'_namedusers'})) {
7016: my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
7017: my @okusers;
7018: foreach my $user (@users) {
7019: my ($uname,$udom) = split(/:/,$user);
7020: if (($udom =~ /^$match_domain$/) &&
7021: (&Apache::lonnet::domain($udom)) &&
7022: ($uname =~ /^$match_username$/)) {
7023: if (!grep(/^\Q$user\E/,@okusers)) {
7024: push(@okusers,$user);
7025: }
7026: }
7027: }
7028: if (@okusers > 0) {
7029: @okusers = sort(@okusers);
7030: $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
7031: }
7032: }
7033: if (defined($env{'form.'.$type.'_machines'})) {
7034: my @machines = split(/,/,$env{'form.'.$type.'_machines'});
7035: my @okmachines;
7036: foreach my $ip (@machines) {
7037: my @parts = split(/\./,$ip);
7038: next if (@parts < 4);
7039: my $badip = 0;
7040: for (my $i=0; $i<4; $i++) {
7041: if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
7042: $badip = 1;
7043: last;
7044: }
7045: }
7046: if (!$badip) {
7047: push(@okmachines,$ip);
7048: }
7049: }
7050: @okmachines = sort(@okmachines);
7051: $newserverstatus{$type}{'machines'} = join(',',@okmachines);
7052: }
7053: }
7054: my %serverstatushash = (
7055: serverstatuses => \%newserverstatus,
7056: );
7057: foreach my $type (@pages) {
7058: foreach my $setting ('namedusers','machines') {
7059: my (@current,@new);
7060: if (ref($currserverstatus{$type}) eq 'HASH') {
7061: if ($currserverstatus{$type}{$setting} ne '') {
7062: @current = split(/,/,$currserverstatus{$type}{$setting});
7063: }
7064: }
7065: if ($newserverstatus{$type}{$setting} ne '') {
7066: @new = split(/,/,$newserverstatus{$type}{$setting});
7067: }
7068: if (@current > 0) {
7069: if (@new > 0) {
7070: foreach my $item (@current) {
7071: if (!grep(/^\Q$item\E$/,@new)) {
7072: $changes{$type}{$setting} = 1;
7073: last;
7074: }
7075: }
7076: foreach my $item (@new) {
7077: if (!grep(/^\Q$item\E$/,@current)) {
7078: $changes{$type}{$setting} = 1;
7079: last;
7080: }
7081: }
7082: } else {
7083: $changes{$type}{$setting} = 1;
7084: }
7085: } elsif (@new > 0) {
7086: $changes{$type}{$setting} = 1;
7087: }
7088: }
7089: }
7090: if (keys(%changes) > 0) {
7091: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
7092: my $putresult = &Apache::lonnet::put_dom('configuration',
7093: \%serverstatushash,$dom);
7094: if ($putresult eq 'ok') {
7095: $resulttext .= &mt('Changes made:').'<ul>';
7096: foreach my $type (@pages) {
7097: if (ref($changes{$type}) eq 'HASH') {
7098: $resulttext .= '<li>'.$titles->{$type}.'<ul>';
7099: if ($changes{$type}{'namedusers'}) {
7100: if ($newserverstatus{$type}{'namedusers'} eq '') {
7101: $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n";
7102: } else {
7103: $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n";
7104: }
7105: }
7106: if ($changes{$type}{'machines'}) {
7107: if ($newserverstatus{$type}{'machines'} eq '') {
7108: $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n";
7109: } else {
7110: $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n";
7111: }
7112:
7113: }
7114: $resulttext .= '</ul></li>';
7115: }
7116: }
7117: $resulttext .= '</ul>';
7118: } else {
7119: $resulttext = '<span class="LC_error">'.
7120: &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>';
7121:
7122: }
7123: } else {
7124: $resulttext = &mt('No changes made to access to server status pages');
7125: }
7126: return $resulttext;
7127: }
7128:
7129: sub modify_helpsettings {
7130: my ($r,$dom,$confname,%domconfig) = @_;
7131: my ($resulttext,$errors,%changes,%helphash);
7132:
7133: my $customhelpfile = $env{'form.loginhelpurl.filename'};
7134: my $defaulthelpfile = 'defaulthelp.html';
7135: my $servadm = $r->dir_config('lonAdmEMail');
7136: my ($configuserok,$author_ok,$switchserver) =
7137: &config_check($dom,$confname,$servadm);
7138:
7139: my %defaultchecked = ('submitbugs' => 'on');
7140: my @offon = ('off','on');
7141: my %title = ( submitbugs => 'Display link for users to submit a bug',
7142: loginhelpurl => 'Unauthenticated login help page set to custom file');
7143:
7144: my @toggles = ('submitbugs');
7145:
7146: $helphash{'helpsettings'} = {};
7147:
7148: if (ref($domconfig{'helpsettings'}) ne 'HASH') {
7149: if ($domconfig{'helpsettings'} eq '') {
7150: $domconfig{'helpsettings'} = {};
7151: }
7152: }
7153:
7154: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
7155:
7156: foreach my $item (@toggles) {
7157:
7158: if ($defaultchecked{$item} eq 'on') {
7159: if (($domconfig{'helpsettings'}{$item} eq '') &&
7160: ($env{'form.'.$item} eq '0')) {
7161: $changes{$item} = 1;
7162: } elsif ($domconfig{'helpsettings'}{$item} ne $env{'form.'.$item}) {
7163: $changes{$item} = 1;
7164: }
7165: } elsif ($defaultchecked{$item} eq 'off') {
7166: if (($domconfig{'helpsettings'}{$item} eq '') &&
7167: ($env{'form.'.$item} eq '1')) {
7168: $changes{$item} = 1;
7169: } elsif ($domconfig{'helpsettings'}{$item} ne $env{'form.'.$item}) {
7170: $changes{$item} = 1;
7171: }
7172: }
7173: $helphash{'helpsettings'}{$item} = $env{'form.'.$item};
7174: }
7175:
7176: if ($customhelpfile ne '') {
7177: my $error;
7178: if ($configuserok eq 'ok') {
7179: if ($switchserver) {
7180: $error = &mt("Upload of custom help file is not permitted to this server: [_1]",$switchserver);
7181: } else {
7182: if ($author_ok eq 'ok') {
7183: my ($result,$loginhelpurl) =
7184: &publishlogo($r,'upload','loginhelpurl',$dom,
7185: $confname,'help','','',$customhelpfile);
7186: if ($result eq 'ok') {
7187: $helphash{'helpsettings'}{'loginhelpurl'} = $loginhelpurl;
7188: $changes{'loginhelpurl'} = 1;
7189: } else {
7190: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$customhelpfile,$result);
7191: }
7192: } else {
7193: $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);
7194: }
7195: }
7196: } else {
7197: $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);
7198: }
7199: if ($error) {
7200: &Apache::lonnet::logthis($error);
7201: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
7202: }
7203: }
7204:
7205: if ($domconfig{'helpsettings'}{'loginhelpurl'} ne '') {
7206: if ($env{'form.loginhelpurl_del'}) {
7207: $helphash{'helpsettings'}{'loginhelpurl'} = '';
7208: $changes{'loginhelpurl'} = 1;
7209: }
7210: }
7211: }
7212:
7213:
7214: my $putresult;
7215:
7216: if (keys(%changes) > 0) {
7217: $putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom);
7218: } else {
7219: $putresult = 'ok';
7220: }
7221:
7222: if ($putresult eq 'ok') {
7223: if (keys(%changes) > 0) {
7224: $resulttext = &mt('Changes made:').'<ul>';
7225: foreach my $item (sort(keys(%changes))) {
7226: if ($item eq 'submitbugs') {
7227: $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
7228: }
7229: if ($item eq 'loginhelpurl') {
7230: if ($helphash{'helpsettings'}{'loginhelpurl'} eq '') {
7231: $resulttext .= '<li>'.&mt('[_1] help file removed; [_2] file will be used for the unathorized help page in this domain.',$customhelpfile,$defaulthelpfile).'</li>';
7232: } else {
7233: $resulttext .= '<li>'.&mt("$title{$item} [_1]",$customhelpfile).'</li>';
7234: }
7235: }
7236: }
7237: $resulttext .= '</ul>';
7238: } else {
7239: $resulttext = &mt('No changes made to help settings');
7240: }
7241: } else {
7242: $resulttext = '<span class="LC_error">'.
7243: &mt('An error occurred: [_1]',$putresult).'</span>';
7244: }
7245: if ($errors) {
7246: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
7247: $errors.'</ul>';
7248: }
7249: return $resulttext;
7250: }
7251:
7252: sub modify_coursedefaults {
7253: my ($dom,%domconfig) = @_;
7254: my ($resulttext,$errors,%changes,%defaultshash);
7255: my %defaultchecked = ('canuse_pdfforms' => 'off');
7256: my @offon = ('off','on');
7257: my @toggles = ('canuse_pdfforms');
7258:
7259: $defaultshash{'coursedefaults'} = {};
7260:
7261: if (ref($domconfig{'coursedefaults'}) ne 'HASH') {
7262: if ($domconfig{'coursedefaults'} eq '') {
7263: $domconfig{'coursedefaults'} = {};
7264: }
7265: }
7266:
7267: if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
7268: foreach my $item (@toggles) {
7269: if ($defaultchecked{$item} eq 'on') {
7270: if (($domconfig{'coursedefaults'}{$item} eq '') &&
7271: ($env{'form.'.$item} eq '0')) {
7272: $changes{$item} = 1;
7273: } elsif ($domconfig{'coursdefaults'}{$item} ne $env{'form.'.$item}) {
7274: $changes{$item} = 1;
7275: }
7276: } elsif ($defaultchecked{$item} eq 'off') {
7277: if (($domconfig{'coursedefaults'}{$item} eq '') &&
7278: ($env{'form.'.$item} eq '1')) {
7279: $changes{$item} = 1;
7280: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
7281: $changes{$item} = 1;
7282: }
7283: }
7284: $defaultshash{'coursedefaults'}{$item} = $env{'form.'.$item};
7285: }
7286: my $currdefresponder = $domconfig{'coursedefaults'}{'anonsurvey_threshold'};
7287: my $newdefresponder = $env{'form.anonsurvey_threshold'};
7288: $newdefresponder =~ s/\D//g;
7289: if ($newdefresponder eq '' || $newdefresponder < 1) {
7290: $newdefresponder = 1;
7291: }
7292: $defaultshash{'coursedefaults'}{'anonsurvey_threshold'} = $newdefresponder;
7293: if ($currdefresponder ne $newdefresponder) {
7294: unless ($currdefresponder eq '' && $newdefresponder == 10) {
7295: $changes{'anonsurvey_threshold'} = 1;
7296: }
7297: }
7298: }
7299: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
7300: $dom);
7301: if ($putresult eq 'ok') {
7302: if (keys(%changes) > 0) {
7303: if ($changes{'canuse_pdfforms'}) {
7304: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
7305: $domdefaults{'canuse_pdfforms'}=$defaultshash{'coursedefaults'}{'canuse_pdfforms'};
7306: my $cachetime = 24*60*60;
7307: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
7308: }
7309: $resulttext = &mt('Changes made:').'<ul>';
7310: foreach my $item (sort(keys(%changes))) {
7311: if ($item eq 'canuse_pdfforms') {
7312: if ($env{'form.'.$item} eq '1') {
7313: $resulttext .= '<li>'.&mt("Course/Community users can create/upload PDF forms set to 'on'").'</li>';
7314: } else {
7315: $resulttext .= '<li>'.&mt('Course/Community users can create/upload PDF forms set to "off"').'</li>';
7316: }
7317: } elsif ($item eq 'anonsurvey_threshold') {
7318: $resulttext .= '<li>'.&mt('Responder count required for display of anonymous survey submissions set to [_1].',$defaultshash{'coursedefaults'}{'anonsurvey_threshold'}).'</li>';
7319: }
7320: }
7321: $resulttext .= '</ul>';
7322: } else {
7323: $resulttext = &mt('No changes made to course defaults');
7324: }
7325: } else {
7326: $resulttext = '<span class="LC_error">'.
7327: &mt('An error occurred: [_1]',$putresult).'</span>';
7328: }
7329: return $resulttext;
7330: }
7331:
7332: sub modify_usersessions {
7333: my ($dom,%domconfig) = @_;
7334: my @hostingtypes = ('version','excludedomain','includedomain');
7335: my @offloadtypes = ('primary','default');
7336: my %types = (
7337: remote => \@hostingtypes,
7338: hosted => \@hostingtypes,
7339: spares => \@offloadtypes,
7340: );
7341: my @prefixes = ('remote','hosted','spares');
7342: my @lcversions = &Apache::lonnet::all_loncaparevs();
7343: my (%by_ip,%by_location,@intdoms);
7344: &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
7345: my @locations = sort(keys(%by_location));
7346: my (%defaultshash,%changes);
7347: foreach my $prefix (@prefixes) {
7348: $defaultshash{'usersessions'}{$prefix} = {};
7349: }
7350: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
7351: my $resulttext;
7352: my %iphost = &Apache::lonnet::get_iphost();
7353: foreach my $prefix (@prefixes) {
7354: next if ($prefix eq 'spares');
7355: foreach my $type (@{$types{$prefix}}) {
7356: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
7357: if ($type eq 'version') {
7358: my $value = $env{'form.'.$prefix.'_'.$type};
7359: my $okvalue;
7360: if ($value ne '') {
7361: if (grep(/^\Q$value\E$/,@lcversions)) {
7362: $okvalue = $value;
7363: }
7364: }
7365: if (ref($domconfig{'usersessions'}) eq 'HASH') {
7366: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
7367: if ($domconfig{'usersessions'}{$prefix}{$type} ne '') {
7368: if ($inuse == 0) {
7369: $changes{$prefix}{$type} = 1;
7370: } else {
7371: if ($okvalue ne $domconfig{'usersessions'}{$prefix}{$type}) {
7372: $changes{$prefix}{$type} = 1;
7373: }
7374: if ($okvalue ne '') {
7375: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
7376: }
7377: }
7378: } else {
7379: if (($inuse == 1) && ($okvalue ne '')) {
7380: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
7381: $changes{$prefix}{$type} = 1;
7382: }
7383: }
7384: } else {
7385: if (($inuse == 1) && ($okvalue ne '')) {
7386: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
7387: $changes{$prefix}{$type} = 1;
7388: }
7389: }
7390: } else {
7391: if (($inuse == 1) && ($okvalue ne '')) {
7392: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
7393: $changes{$prefix}{$type} = 1;
7394: }
7395: }
7396: } else {
7397: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
7398: my @okvals;
7399: foreach my $val (@vals) {
7400: if ($val =~ /:/) {
7401: my @items = split(/:/,$val);
7402: foreach my $item (@items) {
7403: if (ref($by_location{$item}) eq 'ARRAY') {
7404: push(@okvals,$item);
7405: }
7406: }
7407: } else {
7408: if (ref($by_location{$val}) eq 'ARRAY') {
7409: push(@okvals,$val);
7410: }
7411: }
7412: }
7413: @okvals = sort(@okvals);
7414: if (ref($domconfig{'usersessions'}) eq 'HASH') {
7415: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
7416: if (ref($domconfig{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
7417: if ($inuse == 0) {
7418: $changes{$prefix}{$type} = 1;
7419: } else {
7420: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
7421: my @changed = &Apache::loncommon::compare_arrays($domconfig{'usersessions'}{$prefix}{$type},$defaultshash{'usersessions'}{$prefix}{$type});
7422: if (@changed > 0) {
7423: $changes{$prefix}{$type} = 1;
7424: }
7425: }
7426: } else {
7427: if ($inuse == 1) {
7428: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
7429: $changes{$prefix}{$type} = 1;
7430: }
7431: }
7432: } else {
7433: if ($inuse == 1) {
7434: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
7435: $changes{$prefix}{$type} = 1;
7436: }
7437: }
7438: } else {
7439: if ($inuse == 1) {
7440: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
7441: $changes{$prefix}{$type} = 1;
7442: }
7443: }
7444: }
7445: }
7446: }
7447:
7448: my @alldoms = &Apache::lonnet::all_domains();
7449: my %servers = &Apache::lonnet::internet_dom_servers($dom);
7450: my %spareid = ¤t_offloads_to($dom,$domconfig{'usersessions'},\%servers);
7451: my $savespares;
7452:
7453: foreach my $lonhost (sort(keys(%servers))) {
7454: my $serverhomeID =
7455: &Apache::lonnet::get_server_homeID($servers{$lonhost});
7456: my $serverhostname = &Apache::lonnet::hostname($lonhost);
7457: $defaultshash{'usersessions'}{'spares'}{$lonhost} = {};
7458: my %spareschg;
7459: foreach my $type (@{$types{'spares'}}) {
7460: my @okspares;
7461: my @checked = &Apache::loncommon::get_env_multiple('form.spare_'.$type.'_'.$lonhost);
7462: foreach my $server (@checked) {
7463: if (&Apache::lonnet::hostname($server) ne '') {
7464: unless (&Apache::lonnet::hostname($server) eq $serverhostname) {
7465: unless (grep(/^\Q$server\E$/,@okspares)) {
7466: push(@okspares,$server);
7467: }
7468: }
7469: }
7470: }
7471: my $new = $env{'form.newspare_'.$type.'_'.$lonhost};
7472: my $newspare;
7473: if (($new ne '') && (&Apache::lonnet::hostname($new))) {
7474: unless (&Apache::lonnet::hostname($new) eq $serverhostname) {
7475: $newspare = $new;
7476: }
7477: }
7478: my @spares;
7479: if (($newspare ne '') && (!grep(/^\Q$newspare\E$/,@okspares))) {
7480: @spares = sort(@okspares,$newspare);
7481: } else {
7482: @spares = sort(@okspares);
7483: }
7484: $defaultshash{'usersessions'}{'spares'}{$lonhost}{$type} = \@spares;
7485: if (ref($spareid{$lonhost}) eq 'HASH') {
7486: if (ref($spareid{$lonhost}{$type}) eq 'ARRAY') {
7487: my @diffs = &Apache::loncommon::compare_arrays($spareid{$lonhost}{$type},\@spares);
7488: if (@diffs > 0) {
7489: $spareschg{$type} = 1;
7490: }
7491: }
7492: }
7493: }
7494: if (keys(%spareschg) > 0) {
7495: $changes{'spares'}{$lonhost} = \%spareschg;
7496: }
7497: }
7498:
7499: if (ref($domconfig{'usersessions'}) eq 'HASH') {
7500: if (ref($domconfig{'usersessions'}{'spares'}) eq 'HASH') {
7501: if (ref($changes{'spares'}) eq 'HASH') {
7502: if (keys(%{$changes{'spares'}}) > 0) {
7503: $savespares = 1;
7504: }
7505: }
7506: } else {
7507: $savespares = 1;
7508: }
7509: }
7510:
7511: my $nochgmsg = &mt('No changes made to settings for user session hosting/offloading.');
7512: if ((keys(%changes) > 0) || ($savespares)) {
7513: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
7514: $dom);
7515: if ($putresult eq 'ok') {
7516: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
7517: if (ref($defaultshash{'usersessions'}{'remote'}) eq 'HASH') {
7518: $domdefaults{'remotesessions'} = $defaultshash{'usersessions'}{'remote'};
7519: }
7520: if (ref($defaultshash{'usersessions'}{'hosted'}) eq 'HASH') {
7521: $domdefaults{'hostedsessions'} = $defaultshash{'usersessions'}{'hosted'};
7522: }
7523: }
7524: my $cachetime = 24*60*60;
7525: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
7526: if (keys(%changes) > 0) {
7527: my %lt = &usersession_titles();
7528: $resulttext = &mt('Changes made:').'<ul>';
7529: foreach my $prefix (@prefixes) {
7530: if (ref($changes{$prefix}) eq 'HASH') {
7531: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
7532: if ($prefix eq 'spares') {
7533: if (ref($changes{$prefix}) eq 'HASH') {
7534: foreach my $lonhost (sort(keys(%{$changes{$prefix}}))) {
7535: $resulttext .= '<li><b>'.$lonhost.'</b> ';
7536: my $lonhostdom = &Apache::lonnet::host_domain($lonhost);
7537: &Apache::lonnet::remote_devalidate_cache($lonhost,'spares',$lonhostdom);
7538: if (ref($changes{$prefix}{$lonhost}) eq 'HASH') {
7539: foreach my $type (@{$types{$prefix}}) {
7540: if ($changes{$prefix}{$lonhost}{$type}) {
7541: my $offloadto = &mt('None');
7542: if (ref($defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}) eq 'ARRAY') {
7543: if (@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}} > 0) {
7544: $offloadto = join(', ',@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}});
7545: }
7546: }
7547: $resulttext .= &mt('[_1] set to: [_2].','<i>'.$lt{$type}.'</i>',$offloadto).(' 'x3);
7548: }
7549: }
7550: }
7551: $resulttext .= '</li>';
7552: }
7553: }
7554: } else {
7555: foreach my $type (@{$types{$prefix}}) {
7556: if (defined($changes{$prefix}{$type})) {
7557: my $newvalue;
7558: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
7559: if (ref($defaultshash{'usersessions'}{$prefix})) {
7560: if ($type eq 'version') {
7561: $newvalue = $defaultshash{'usersessions'}{$prefix}{$type};
7562: } elsif (ref($defaultshash{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
7563: if (@{$defaultshash{'usersessions'}{$prefix}{$type}} > 0) {
7564: $newvalue = join(', ',@{$defaultshash{'usersessions'}{$prefix}{$type}});
7565: }
7566: }
7567: }
7568: }
7569: if ($newvalue eq '') {
7570: if ($type eq 'version') {
7571: $resulttext .= '<li>'.&mt('[_1] set to: off',$lt{$type}).'</li>';
7572: } else {
7573: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
7574: }
7575: } else {
7576: if ($type eq 'version') {
7577: $newvalue .= ' '.&mt('(or later)');
7578: }
7579: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
7580: }
7581: }
7582: }
7583: }
7584: $resulttext .= '</ul>';
7585: }
7586: }
7587: $resulttext .= '</ul>';
7588: } else {
7589: $resulttext = $nochgmsg;
7590: }
7591: } else {
7592: $resulttext = '<span class="LC_error">'.
7593: &mt('An error occurred: [_1]',$putresult).'</span>';
7594: }
7595: } else {
7596: $resulttext = $nochgmsg;
7597: }
7598: return $resulttext;
7599: }
7600:
7601: sub modify_loadbalancing {
7602: my ($dom,%domconfig) = @_;
7603: my $primary_id = &Apache::lonnet::domain($dom,'primary');
7604: my $intdom = &Apache::lonnet::internet_dom($primary_id);
7605: my ($othertitle,$usertypes,$types) =
7606: &Apache::loncommon::sorted_inst_types($dom);
7607: my %servers = &Apache::lonnet::internet_dom_servers($dom);
7608: my @sparestypes = ('primary','default');
7609: my %typetitles = &sparestype_titles();
7610: my $resulttext;
7611: if (keys(%servers) > 1) {
7612: my ($currbalancer,$currtargets,$currrules);
7613: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
7614: $currbalancer = $domconfig{'loadbalancing'}{'lonhost'};
7615: $currtargets = $domconfig{'loadbalancing'}{'targets'};
7616: $currrules = $domconfig{'loadbalancing'}{'rules'};
7617: } else {
7618: ($currbalancer,$currtargets) =
7619: &Apache::lonnet::get_lonbalancer_config(\%servers);
7620: }
7621: my ($saveloadbalancing,%defaultshash,%changes);
7622: my ($alltypes,$othertypes,$titles) =
7623: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
7624: my %ruletitles = &offloadtype_text();
7625: my $balancer = $env{'form.loadbalancing_lonhost'};
7626: if (!$servers{$balancer}) {
7627: undef($balancer);
7628: }
7629: if ($currbalancer ne $balancer) {
7630: $changes{'lonhost'} = 1;
7631: }
7632: $defaultshash{'loadbalancing'}{'lonhost'} = $balancer;
7633: if ($balancer ne '') {
7634: unless (ref($domconfig{'loadbalancing'}) eq 'HASH') {
7635: $saveloadbalancing = 1;
7636: }
7637: foreach my $sparetype (@sparestypes) {
7638: my @targets = &Apache::loncommon::get_env_multiple('form.loadbalancing_target_'.$sparetype);
7639: my @offloadto;
7640: foreach my $target (@targets) {
7641: if (($servers{$target}) && ($target ne $balancer)) {
7642: if ($sparetype eq 'default') {
7643: if (ref($defaultshash{'loadbalancing'}{'targets'}{'primary'}) eq 'ARRAY') {
7644: next if (grep(/^\Q$target\E$/,@{$defaultshash{'loadbalancing'}{'targets'}{'primary'}}));
7645: }
7646: }
7647: unless(grep(/^\Q$target\E$/,@offloadto)) {
7648: push(@offloadto,$target);
7649: }
7650: }
7651: $defaultshash{'loadbalancing'}{'targets'}{$sparetype} = \@offloadto;
7652: }
7653: }
7654: } else {
7655: foreach my $sparetype (@sparestypes) {
7656: $defaultshash{'loadbalancing'}{'targets'}{$sparetype} = [];
7657: }
7658: }
7659: if (ref($currtargets) eq 'HASH') {
7660: foreach my $sparetype (@sparestypes) {
7661: if (ref($currtargets->{$sparetype}) eq 'ARRAY') {
7662: my @targetdiffs = &Apache::loncommon::compare_arrays($currtargets->{$sparetype},$defaultshash{'loadbalancing'}{'targets'}{$sparetype});
7663: if (@targetdiffs > 0) {
7664: $changes{'targets'} = 1;
7665: }
7666: } elsif (ref($defaultshash{'loadbalancing'}{'targets'}{$sparetype}) eq 'ARRAY') {
7667: if (@{$defaultshash{'loadbalancing'}{'targets'}{$sparetype}} > 0) {
7668: $changes{'targets'} = 1;
7669: }
7670: }
7671: }
7672: } else {
7673: foreach my $sparetype (@sparestypes) {
7674: if (ref($defaultshash{'loadbalancing'}{'targets'}{$sparetype}) eq 'ARRAY') {
7675: if (@{$defaultshash{'loadbalancing'}{'targets'}{$sparetype}} > 0) {
7676: $changes{'targets'} = 1;
7677: }
7678: }
7679: }
7680: }
7681: my $ishomedom;
7682: if ($balancer ne '') {
7683: if (&Apache::lonnet::host_domain($balancer) eq $dom) {
7684: $ishomedom = 1;
7685: }
7686: }
7687: if (ref($alltypes) eq 'ARRAY') {
7688: foreach my $type (@{$alltypes}) {
7689: my $rule;
7690: if ($balancer ne '') {
7691: unless ((($type eq '_LC_external') || ($type eq '_LC_internetdom')) &&
7692: (!$ishomedom)) {
7693: $rule = $env{'form.loadbalancing_rules_'.$type};
7694: }
7695: if ($rule eq 'specific') {
7696: $rule = $env{'form.loadbalancing_singleserver_'.$type};
7697: }
7698: }
7699: $defaultshash{'loadbalancing'}{'rules'}{$type} = $rule;
7700: if (ref($currrules) eq 'HASH') {
7701: if ($rule ne $currrules->{$type}) {
7702: $changes{'rules'}{$type} = 1;
7703: }
7704: } elsif ($rule ne '') {
7705: $changes{'rules'}{$type} = 1;
7706: }
7707: }
7708: }
7709: my $nochgmsg = &mt('No changes made to Load Balancer settings.');
7710: if ((keys(%changes) > 0) || ($saveloadbalancing)) {
7711: my $putresult = &Apache::lonnet::put_dom('configuration',
7712: \%defaultshash,$dom);
7713: if ($putresult eq 'ok') {
7714: if (keys(%changes) > 0) {
7715: if ($changes{'lonhost'}) {
7716: if ($currbalancer ne '') {
7717: &Apache::lonnet::remote_devalidate_cache($currbalancer,'loadbalancing',$dom);
7718: }
7719: if ($balancer eq '') {
7720: $resulttext .= '<li>'.&mt('Load Balancing with dedicated server discontinued').'</li>';
7721: } else {
7722: &Apache::lonnet::remote_devalidate_cache($balancer,'loadbalancing',$dom);
7723: $resulttext .= '<li>'.&mt('Dedicated Load Balancer server set to [_1]',$balancer);
7724: }
7725: } else {
7726: &Apache::lonnet::remote_devalidate_cache($balancer,'loadbalancing',$dom);
7727: }
7728: if (($changes{'targets'}) && ($balancer ne '')) {
7729: my %offloadstr;
7730: foreach my $sparetype (@sparestypes) {
7731: if (ref($defaultshash{'loadbalancing'}{'targets'}{$sparetype}) eq 'ARRAY') {
7732: if (@{$defaultshash{'loadbalancing'}{'targets'}{$sparetype}} > 0) {
7733: $offloadstr{$sparetype} = join(', ',@{$defaultshash{'loadbalancing'}{'targets'}{$sparetype}});
7734: }
7735: }
7736: }
7737: if (keys(%offloadstr) == 0) {
7738: $resulttext .= '<li>'.&mt("Servers to which Load Balance server offloads set to 'None', by default").'</li>';
7739: } else {
7740: my $showoffload;
7741: foreach my $sparetype (@sparestypes) {
7742: $showoffload .= '<i>'.$typetitles{$sparetype}.'</i>: ';
7743: if (defined($offloadstr{$sparetype})) {
7744: $showoffload .= $offloadstr{$sparetype};
7745: } else {
7746: $showoffload .= &mt('None');
7747: }
7748: $showoffload .= (' 'x3);
7749: }
7750: $resulttext .= '<li>'.&mt('By default, Load Balancer server set to offload to: [_1]',$showoffload).'</li>';
7751: }
7752: }
7753: if ((ref($changes{'rules'}) eq 'HASH') && ($balancer ne '')) {
7754: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
7755: foreach my $type (@{$alltypes}) {
7756: if ($changes{'rules'}{$type}) {
7757: my $rule = $defaultshash{'loadbalancing'}{'rules'}{$type};
7758: my $balancetext;
7759: if ($rule eq '') {
7760: $balancetext = $ruletitles{'default'};
7761: } elsif (($rule eq 'homeserver') || ($rule eq 'externalbalancer')) {
7762: $balancetext = $ruletitles{$rule};
7763: } else {
7764: $balancetext = &mt('offload to [_1]',$defaultshash{'loadbalancing'}{'rules'}{$type});
7765: }
7766: $resulttext .= '<li>'.&mt('Load Balancing for [_1] set to: [_2]',$titles->{$type},$balancetext).'</li>';
7767: }
7768: }
7769: }
7770: }
7771: if ($resulttext ne '') {
7772: $resulttext = &mt('Changes made:').'<ul>'.$resulttext.'</ul>';
7773: } else {
7774: $resulttext = $nochgmsg;
7775: }
7776: } else {
7777: $resulttext = $nochgmsg;
7778: if ($balancer ne '') {
7779: &Apache::lonnet::remote_devalidate_cache($balancer,'loadbalancing',$dom);
7780: }
7781: }
7782: } else {
7783: $resulttext = '<span class="LC_error">'.
7784: &mt('An error occurred: [_1]',$putresult).'</span>';
7785: }
7786: } else {
7787: $resulttext = $nochgmsg;
7788: }
7789: } else {
7790: $resulttext = &mt('Load Balancing unavailable as this domain only has one server.');
7791: }
7792: return $resulttext;
7793: }
7794:
7795: sub recurse_check {
7796: my ($chkcats,$categories,$depth,$name) = @_;
7797: if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
7798: my $chg = 0;
7799: for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
7800: my $category = $chkcats->[$depth]{$name}[$j];
7801: my $item;
7802: if ($category eq '') {
7803: $chg ++;
7804: } else {
7805: my $deeper = $depth + 1;
7806: $item = &escape($category).':'.&escape($name).':'.$depth;
7807: if ($chg) {
7808: $categories->{$item} -= $chg;
7809: }
7810: &recurse_check($chkcats,$categories,$deeper,$category);
7811: $deeper --;
7812: }
7813: }
7814: }
7815: return;
7816: }
7817:
7818: sub recurse_cat_deletes {
7819: my ($item,$coursecategories,$deletions) = @_;
7820: my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
7821: my $subdepth = $depth + 1;
7822: if (ref($coursecategories) eq 'HASH') {
7823: foreach my $subitem (keys(%{$coursecategories})) {
7824: my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
7825: if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
7826: delete($coursecategories->{$subitem});
7827: $deletions->{$subitem} = 1;
7828: &recurse_cat_deletes($subitem,$coursecategories,$deletions);
7829: }
7830: }
7831: }
7832: return;
7833: }
7834:
7835: sub get_active_dcs {
7836: my ($dom) = @_;
7837: my %dompersonnel = &Apache::lonnet::get_domain_roles($dom,['dc']);
7838: my %domcoords;
7839: my $numdcs = 0;
7840: my $now = time;
7841: foreach my $server (keys(%dompersonnel)) {
7842: foreach my $user (sort(keys(%{$dompersonnel{$server}}))) {
7843: my ($trole,$uname,$udom,$runame,$rudom,$rsec) = split(/:/,$user);
7844: my ($end,$start) = split(':',$dompersonnel{$server}{$user});
7845: if (($end eq '') || ($end == 0) || ($end > $now)) {
7846: if ($start <= $now) {
7847: $domcoords{$uname.':'.$udom} = $dompersonnel{$server}{$user};
7848: }
7849: }
7850: }
7851: }
7852: return %domcoords;
7853: }
7854:
7855: sub active_dc_picker {
7856: my ($dom,$curr_dc) = @_;
7857: my %domcoords = &get_active_dcs($dom);
7858: my @dcs = sort(keys(%domcoords));
7859: my $numdcs = scalar(@dcs);
7860: my $datatable;
7861: my $numinrow = 2;
7862: if ($numdcs > 1) {
7863: $datatable = '<table>';
7864: for (my $i=0; $i<@dcs; $i++) {
7865: my $rem = $i%($numinrow);
7866: if ($rem == 0) {
7867: if ($i > 0) {
7868: $datatable .= '</tr>';
7869: }
7870: $datatable .= '<tr>';
7871: }
7872: my $check = ' ';
7873: if ($curr_dc eq '') {
7874: if (!$i) {
7875: $check = ' checked="checked" ';
7876: }
7877: } elsif ($dcs[$i] eq $curr_dc) {
7878: $check = ' checked="checked" ';
7879: }
7880: if ($i == @dcs - 1) {
7881: my $colsleft = $numinrow - $rem;
7882: if ($colsleft > 1) {
7883: $datatable .= '<td colspan="'.$colsleft.'">';
7884: } else {
7885: $datatable .= '<td>';
7886: }
7887: } else {
7888: $datatable .= '<td>';
7889: }
7890: my ($dcname,$dcdom) = split(':',$dcs[$i]);
7891: $datatable .= '<span class="LC_nobreak"><label>'.
7892: '<input type="radio" name="autocreate_xmldc"'.
7893: ' value="'.$dcs[$i].'"'.$check.'/>'.
7894: &Apache::loncommon::plainname($dcname,$dcdom).
7895: '</label></span></td>';
7896: }
7897: $datatable .= '</tr></table>';
7898: } elsif (@dcs) {
7899: $datatable .= '<input type="hidden" name="autocreate_dc" value="'.
7900: $dcs[0].'" />';
7901: }
7902: return ($numdcs,$datatable);
7903: }
7904:
7905: sub usersession_titles {
7906: return &Apache::lonlocal::texthash(
7907: hosted => 'Hosting of sessions for users from other domains on servers in this domain',
7908: remote => 'Hosting of sessions for users in this domain on servers in other domains',
7909: spares => 'Servers offloaded to, when busy',
7910: version => 'LON-CAPA version requirement',
7911: excludedomain => 'Allow all, but exclude specific domains',
7912: includedomain => 'Deny all, but include specific domains',
7913: primary => 'Primary (checked first)',
7914: default => 'Default',
7915: );
7916: }
7917:
7918: sub id_for_thisdom {
7919: my (%servers) = @_;
7920: my %altids;
7921: foreach my $server (keys(%servers)) {
7922: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
7923: if ($serverhome ne $server) {
7924: $altids{$serverhome} = $server;
7925: }
7926: }
7927: return %altids;
7928: }
7929:
7930: sub count_servers {
7931: my ($currbalancer,%servers) = @_;
7932: my (@spares,$numspares);
7933: foreach my $lonhost (sort(keys(%servers))) {
7934: next if ($currbalancer eq $lonhost);
7935: push(@spares,$lonhost);
7936: }
7937: if ($currbalancer) {
7938: $numspares = scalar(@spares);
7939: } else {
7940: $numspares = scalar(@spares) - 1;
7941: }
7942: return ($numspares,@spares);
7943: }
7944:
7945: sub lonbalance_targets_js {
7946: my ($dom,$types,$servers) = @_;
7947: my $select = &mt('Select');
7948: my ($alltargets,$allishome,$allinsttypes,@alltypes);
7949: if (ref($servers) eq 'HASH') {
7950: $alltargets = join("','",sort(keys(%{$servers})));
7951: my @homedoms;
7952: foreach my $server (sort(keys(%{$servers}))) {
7953: if (&Apache::lonnet::host_domain($server) eq $dom) {
7954: push(@homedoms,'1');
7955: } else {
7956: push(@homedoms,'0');
7957: }
7958: }
7959: $allishome = join("','",@homedoms);
7960: }
7961: if (ref($types) eq 'ARRAY') {
7962: if (@{$types} > 0) {
7963: @alltypes = @{$types};
7964: }
7965: }
7966: push(@alltypes,'default','_LC_adv','_LC_author','_LC_internetdom','_LC_external');
7967: $allinsttypes = join("','",@alltypes);
7968: return <<"END";
7969:
7970: <script type="text/javascript">
7971: // <![CDATA[
7972:
7973: function toggleTargets() {
7974: var balancer = document.display.loadbalancing_lonhost.options[document.display.loadbalancing_lonhost.selectedIndex].value;
7975: if (balancer == '') {
7976: hideSpares();
7977: } else {
7978: var homedoms = new Array('$allishome');
7979: var ishomedom = homedoms[document.display.loadbalancing_lonhost.selectedIndex];
7980: showSpares(balancer,ishomedom);
7981: }
7982: return;
7983: }
7984:
7985: function showSpares(balancer,ishomedom) {
7986: var alltargets = new Array('$alltargets');
7987: var insttypes = new Array('$allinsttypes');
7988: var offloadtypes = new Array('primary','default');
7989:
7990: document.getElementById('loadbalancing_targets').style.display='block';
7991: document.getElementById('loadbalancing_disabled').style.display='none';
7992:
7993: for (var i=0; i<offloadtypes.length; i++) {
7994: var count = 0;
7995: for (var j=0; j<alltargets.length; j++) {
7996: if (alltargets[j] != balancer) {
7997: document.getElementById('loadbalancing_target_'+offloadtypes[i]+'_'+count).value = alltargets[j];
7998: document.getElementById('loadbalancing_targettxt_'+offloadtypes[i]+'_'+count).style.textAlign='left';
7999: document.getElementById('loadbalancing_targettxt_'+offloadtypes[i]+'_'+count).style.textFace='normal';
8000: document.getElementById('loadbalancing_targettxt_'+offloadtypes[i]+'_'+count).innerHTML = alltargets[j];
8001: count ++;
8002: }
8003: }
8004: }
8005: for (var k=0; k<insttypes.length; k++) {
8006: if ((insttypes[k] == '_LC_external') || (insttypes[k] == '_LC_internetdom')) {
8007: if (ishomedom == 1) {
8008: document.getElementById('balanceruletitle_'+insttypes[k]).style.display='block';
8009: document.getElementById('balancerule_'+insttypes[k]).style.display='block';
8010: } else {
8011: document.getElementById('balanceruletitle_'+insttypes[k]).style.display='none';
8012: document.getElementById('balancerule_'+insttypes[k]).style.display='none';
8013:
8014: }
8015: } else {
8016: document.getElementById('balanceruletitle_'+insttypes[k]).style.display='block';
8017: document.getElementById('balancerule_'+insttypes[k]).style.display='block';
8018: }
8019: if ((insttypes[k] != '_LC_external') &&
8020: ((insttypes[k] != '_LC_internetdom') ||
8021: ((insttypes[k] == '_LC_internetdom') && (ishomedom == 1)))) {
8022: document.getElementById('loadbalancing_singleserver_'+insttypes[k]).options[0] = new Option("","",true,true);
8023: for (var m=0; m<alltargets.length; m++) {
8024: var idx = m+1;
8025: if (alltargets[m] != balancer) {
8026: document.getElementById('loadbalancing_singleserver_'+insttypes[k]).options[idx] = new Option(alltargets[m],alltargets[m],false,false);
8027: }
8028: }
8029: }
8030: }
8031: return;
8032: }
8033:
8034: function hideSpares() {
8035: var alltargets = new Array('$alltargets');
8036: var insttypes = new Array('$allinsttypes');
8037: var offloadtypes = new Array('primary','default');
8038:
8039: document.getElementById('loadbalancing_targets').style.display='none';
8040: document.getElementById('loadbalancing_disabled').style.display='block';
8041:
8042: var total = alltargets.length - 1;
8043: for (var i=0; i<offloadtypes; i++) {
8044: for (var j=0; j<total; j++) {
8045: document.getElementById('loadbalancing_target_'+offloadtypes[i]+'_'+j).checked = false;
8046: document.getElementById('loadbalancing_target_'+offloadtypes[i]+'_'+j).value = '';
8047: document.getElementById('loadbalancing_targettxt_'+offloadtypes[i]+'_'+j).innerHTML = '';
8048: }
8049: }
8050: for (var k=0; k<insttypes.length; k++) {
8051: document.getElementById('balanceruletitle_'+insttypes[k]).style.display='none';
8052: document.getElementById('balancerule_'+insttypes[k]).style.display='none';
8053: if (insttypes[k] != '_LC_external') {
8054: document.getElementById('loadbalancing_singleserver_'+insttypes[k]).length = 0;
8055: document.getElementById('loadbalancing_singleserver_'+insttypes[k]).options[0] = new Option("","",true,true);
8056: }
8057: }
8058: return;
8059: }
8060:
8061: function checkOffloads(item,type) {
8062: var alltargets = new Array('$alltargets');
8063: var offloadtypes = new Array('primary','default');
8064: if (item.checked) {
8065: var total = alltargets.length - 1;
8066: var other;
8067: if (type == offloadtypes[0]) {
8068: other = offloadtypes[1];
8069: } else {
8070: other = offloadtypes[0];
8071: }
8072: for (var i=0; i<total; i++) {
8073: var server = document.getElementById('loadbalancing_target_'+other+'_'+i).value;
8074: if (server == item.value) {
8075: if (document.getElementById('loadbalancing_target_'+other+'_'+i).checked) {
8076: document.getElementById('loadbalancing_target_'+other+'_'+i).checked = false;
8077: }
8078: }
8079: }
8080: }
8081: return;
8082: }
8083:
8084: function singleServerToggle(type) {
8085: var offloadtoSelIdx = document.getElementById('loadbalancing_singleserver_'+type).selectedIndex;
8086: if (offloadtoSelIdx == 0) {
8087: document.getElementById('loadbalancing_rules_'+type+'_0').checked = true;
8088: document.getElementById('loadbalancing_singleserver_'+type).options[0].text = '';
8089:
8090: } else {
8091: document.getElementById('loadbalancing_rules_'+type+'_2').checked = true;
8092: document.getElementById('loadbalancing_singleserver_'+type).options[0].text = '$select';
8093: }
8094: return;
8095: }
8096:
8097: function balanceruleChange(formname,type) {
8098: if (type == '_LC_external') {
8099: return;
8100: }
8101: var typesRules = getIndicesByName(formname,'loadbalancing_rules_'+type);
8102: for (var i=0; i<typesRules.length; i++) {
8103: if (formname.elements[typesRules[i]].checked) {
8104: if (formname.elements[typesRules[i]].value != 'specific') {
8105: document.getElementById('loadbalancing_singleserver_'+type).selectedIndex = 0;
8106: document.getElementById('loadbalancing_singleserver_'+type).options[0].text = '';
8107: } else {
8108: document.getElementById('loadbalancing_singleserver_'+type).options[0].text = '$select';
8109: }
8110: }
8111: }
8112: return;
8113: }
8114:
8115: // ]]>
8116: </script>
8117:
8118: END
8119: }
8120:
8121: sub new_spares_js {
8122: my @sparestypes = ('primary','default');
8123: my $types = join("','",@sparestypes);
8124: my $select = &mt('Select');
8125: return <<"END";
8126:
8127: <script type="text/javascript">
8128: // <![CDATA[
8129:
8130: function updateNewSpares(formname,lonhost) {
8131: var types = new Array('$types');
8132: var include = new Array();
8133: var exclude = new Array();
8134: for (var i=0; i<types.length; i++) {
8135: var spareboxes = getIndicesByName(formname,'spare_'+types[i]+'_'+lonhost);
8136: for (var j=0; j<spareboxes.length; j++) {
8137: if (formname.elements[spareboxes[j]].checked) {
8138: exclude.push(formname.elements[spareboxes[j]].value);
8139: } else {
8140: include.push(formname.elements[spareboxes[j]].value);
8141: }
8142: }
8143: }
8144: for (var i=0; i<types.length; i++) {
8145: var newSpare = document.getElementById('newspare_'+types[i]+'_'+lonhost);
8146: var selIdx = newSpare.selectedIndex;
8147: var currnew = newSpare.options[selIdx].value;
8148: var okSpares = new Array();
8149: for (var j=0; j<newSpare.options.length; j++) {
8150: var possible = newSpare.options[j].value;
8151: if (possible != '') {
8152: if (exclude.indexOf(possible) == -1) {
8153: okSpares.push(possible);
8154: } else {
8155: if (currnew == possible) {
8156: selIdx = 0;
8157: }
8158: }
8159: }
8160: }
8161: for (var k=0; k<include.length; k++) {
8162: if (okSpares.indexOf(include[k]) == -1) {
8163: okSpares.push(include[k]);
8164: }
8165: }
8166: okSpares.sort();
8167: newSpare.options.length = 0;
8168: if (selIdx == 0) {
8169: newSpare.options[0] = new Option("$select","",true,true);
8170: } else {
8171: newSpare.options[0] = new Option("$select","",false,false);
8172: }
8173: for (var m=0; m<okSpares.length; m++) {
8174: var idx = m+1;
8175: var selThis = 0;
8176: if (selIdx != 0) {
8177: if (okSpares[m] == currnew) {
8178: selThis = 1;
8179: }
8180: }
8181: if (selThis == 1) {
8182: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],true,true);
8183: } else {
8184: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],false,false);
8185: }
8186: }
8187: }
8188: return;
8189: }
8190:
8191: function checkNewSpares(lonhost,type) {
8192: var newSpare = document.getElementById('newspare_'+type+'_'+lonhost);
8193: var chosen = newSpare.options[newSpare.selectedIndex].value;
8194: if (chosen != '') {
8195: var othertype;
8196: var othernewSpare;
8197: if (type == 'primary') {
8198: othernewSpare = document.getElementById('newspare_default_'+lonhost);
8199: }
8200: if (type == 'default') {
8201: othernewSpare = document.getElementById('newspare_primary_'+lonhost);
8202: }
8203: if (othernewSpare.options[othernewSpare.selectedIndex].value == chosen) {
8204: othernewSpare.selectedIndex = 0;
8205: }
8206: }
8207: return;
8208: }
8209:
8210: // ]]>
8211: </script>
8212:
8213: END
8214:
8215: }
8216:
8217: sub common_domprefs_js {
8218: return <<"END";
8219:
8220: <script type="text/javascript">
8221: // <![CDATA[
8222:
8223: function getIndicesByName(formname,item) {
8224: var group = new Array();
8225: for (var i=0;i<formname.elements.length;i++) {
8226: if (formname.elements[i].name == item) {
8227: group.push(formname.elements[i].id);
8228: }
8229: }
8230: return group;
8231: }
8232:
8233: // ]]>
8234: </script>
8235:
8236: END
8237:
8238: }
8239:
8240: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>