1: # The LearningOnline Network with CAPA
2: # Handler to set domain-wide configuration settings
3: #
4: # $Id: domainprefs.pm,v 1.202 2013/08/08 00:53:32 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 affiliated with the institution. Accordingly, each domain
49: may define a default set of logos and a color scheme which can be used to "brand"
50: the LON-CAPA instance. In addition, an institution will typically have a language
51: and timezone which are used for the majority of courses.
52:
53: LON-CAPA provides a mechanism to display and modify these defaults, as well as a
54: host of other domain-wide settings which determine the types of functionality
55: available to users and courses in the domain.
56:
57: There is also a mechanism to configure cataloging of courses in the domain, and
58: controls on the operation of automated processes which govern such things as
59: roster updates, user directory updates and processing of course requests.
60:
61: The domain coordination manual which is built dynamically on install/update of
62: LON-CAPA from the relevant help items provides more information about domain
63: configuration.
64:
65: Most of the domain settings are stored in the configuration.db GDBM file which is
66: housed on the primary library server for the domain in /home/httpd/lonUsers/$dom,
67: where $dom is the domain. The configuration.db stores settings in a number of
68: frozen hashes of hashes. In a few cases, domain information must be uploaded to
69: the domain as files (e.g., image files for logos etc., or plain text files for
70: bubblesheet formats). In this case the domainprefs.pm must be running in a user
71: session hosted on the primary library server in the domain, as these files are
72: stored in author space belonging to a special $dom-domainconfig user.
73:
74: domainprefs.pm in combination with lonconfigsettings.pm will retrieve and display
75: the current settings, and provides an interface to make modifications.
76:
77: =head1 SUBROUTINES
78:
79: =over
80:
81: =item print_quotas()
82:
83: Inputs: 4
84:
85: $dom,$settings,$rowtotal,$action.
86:
87: $dom is the domain, $settings is a reference to a hash of current settings for
88: the current context, $rowtotal is a reference to the scalar used to record the
89: number of rows displayed on the page, and $action is the context (quotas,
90: requestcourses or requestauthor).
91:
92: The print_quotas routine was orginally created to display/store information
93: about default quota sizes for portfolio spaces for the different types of
94: institutional affiliation in the domain (e.g., Faculty, Staff, Student etc.),
95: but is now also used to manage availability of user tools:
96: i.e., blogs, aboutme page, and portfolios, and the course request tool,
97: used by course owners to request creation of a course, and to display/store
98: default quota sizes for authoring spaces.
99:
100: Outputs: 1
101:
102: $datatable - HTML containing form elements which allow settings to be changed.
103:
104: In the case of course requests, radio buttons are displayed for each institutional
105: affiliate type (and also default, and _LC_adv) for each of the course types
106: (official, unofficial and community). In each case the radio buttons allow the
107: selection of one of four values:
108:
109: 0, approval, validate, autolimit=N (where N is blank, or a positive integer).
110: which have the following effects:
111:
112: 0
113:
114: =over
115:
116: - course requests are not allowed for this course types/affiliation
117:
118: =back
119:
120: approval
121:
122: =over
123:
124: - course requests must be approved by a Doman Coordinator in the
125: course's domain
126:
127: =back
128:
129: validate
130:
131: =over
132:
133: - an institutional validation (e.g., check requestor is instructor
134: of record) needs to be passed before the course will be created. The required
135: validation is in localenroll.pm on the primary library server for the course
136: domain.
137:
138: =back
139:
140: autolimit
141:
142: =over
143:
144: - course requests will be processed automatically up to a limit of
145: N requests for the course type for the particular requestor.
146: If N is undefined, there is no limit to the number of course requests
147: which a course owner may submit and have processed automatically.
148:
149: =back
150:
151: =item modify_quotas()
152:
153: =back
154:
155: =cut
156:
157: package Apache::domainprefs;
158:
159: use strict;
160: use Apache::Constants qw(:common :http);
161: use Apache::lonnet;
162: use Apache::loncommon();
163: use Apache::lonhtmlcommon();
164: use Apache::lonlocal;
165: use Apache::lonmsg();
166: use Apache::lonconfigsettings;
167: use LONCAPA qw(:DEFAULT :match);
168: use LONCAPA::Enrollment;
169: use LONCAPA::lonauthcgi();
170: use File::Copy;
171: use Locale::Language;
172: use DateTime::TimeZone;
173: use DateTime::Locale;
174:
175: my $registered_cleanup;
176: my $modified_urls;
177:
178: sub handler {
179: my $r=shift;
180: if ($r->header_only) {
181: &Apache::loncommon::content_type($r,'text/html');
182: $r->send_http_header;
183: return OK;
184: }
185:
186: my $context = 'domain';
187: my $dom = $env{'request.role.domain'};
188: my $domdesc = &Apache::lonnet::domain($dom,'description');
189: if (&Apache::lonnet::allowed('mau',$dom)) {
190: &Apache::loncommon::content_type($r,'text/html');
191: $r->send_http_header;
192: } else {
193: $env{'user.error.msg'}=
194: "/adm/domainprefs:mau:0:0:Cannot modify domain settings";
195: return HTTP_NOT_ACCEPTABLE;
196: }
197:
198: $registered_cleanup=0;
199: @{$modified_urls}=();
200:
201: &Apache::lonhtmlcommon::clear_breadcrumbs();
202: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
203: ['phase','actions']);
204: my $phase = 'pickactions';
205: if ( exists($env{'form.phase'}) ) {
206: $phase = $env{'form.phase'};
207: }
208: my %servers = &Apache::lonnet::internet_dom_servers($dom);
209: my %domconfig =
210: &Apache::lonnet::get_dom('configuration',['login','rolecolors',
211: 'quotas','autoenroll','autoupdate','autocreate',
212: 'directorysrch','usercreation','usermodification',
213: 'contacts','defaults','scantron','coursecategories',
214: 'serverstatuses','requestcourses','helpsettings',
215: 'coursedefaults','usersessions','loadbalancing',
216: 'requestauthor'],$dom);
217: my @prefs_order = ('rolecolors','login','defaults','quotas','autoenroll',
218: 'autoupdate','autocreate','directorysrch','contacts',
219: 'usercreation','usermodification','scantron',
220: 'requestcourses','requestauthor','coursecategories',
221: 'serverstatuses','helpsettings',
222: 'coursedefaults','usersessions');
223: my %existing;
224: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
225: %existing = %{$domconfig{'loadbalancing'}};
226: }
227: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
228: push(@prefs_order,'loadbalancing');
229: }
230: my %prefs = (
231: 'rolecolors' =>
232: { text => 'Default color schemes',
233: help => 'Domain_Configuration_Color_Schemes',
234: header => [{col1 => 'Student Settings',
235: col2 => '',},
236: {col1 => 'Coordinator Settings',
237: col2 => '',},
238: {col1 => 'Author Settings',
239: col2 => '',},
240: {col1 => 'Administrator Settings',
241: col2 => '',}],
242: },
243: 'login' =>
244: { text => 'Log-in page options',
245: help => 'Domain_Configuration_Login_Page',
246: header => [{col1 => 'Log-in Page Items',
247: col2 => '',},
248: {col1 => 'Log-in Help',
249: col2 => 'Value'}],
250: },
251: 'defaults' =>
252: { text => 'Default authentication/language/timezone/portal',
253: help => 'Domain_Configuration_LangTZAuth',
254: header => [{col1 => 'Setting',
255: col2 => 'Value'}],
256: },
257: 'quotas' =>
258: { text => 'Blogs, personal web pages, webDAV/quotas, portfolios',
259: help => 'Domain_Configuration_Quotas',
260: header => [{col1 => 'User affiliation',
261: col2 => 'Available tools',
262: col3 => 'Quotas, Mb; (Authoring requires role)',}],
263: },
264: 'autoenroll' =>
265: { text => 'Auto-enrollment settings',
266: help => 'Domain_Configuration_Auto_Enrollment',
267: header => [{col1 => 'Configuration setting',
268: col2 => 'Value(s)'}],
269: },
270: 'autoupdate' =>
271: { text => 'Auto-update settings',
272: help => 'Domain_Configuration_Auto_Updates',
273: header => [{col1 => 'Setting',
274: col2 => 'Value',},
275: {col1 => 'Setting',
276: col2 => 'Affiliation'},
277: {col1 => 'User population',
278: col2 => 'Updateable user data'}],
279: },
280: 'autocreate' =>
281: { text => 'Auto-course creation settings',
282: help => 'Domain_Configuration_Auto_Creation',
283: header => [{col1 => 'Configuration Setting',
284: col2 => 'Value',}],
285: },
286: 'directorysrch' =>
287: { text => 'Institutional directory searches',
288: help => 'Domain_Configuration_InstDirectory_Search',
289: header => [{col1 => 'Setting',
290: col2 => 'Value',}],
291: },
292: 'contacts' =>
293: { text => 'Contact Information',
294: help => 'Domain_Configuration_Contact_Info',
295: header => [{col1 => 'Setting',
296: col2 => 'Value',}],
297: },
298:
299: 'usercreation' =>
300: { text => 'User creation',
301: help => 'Domain_Configuration_User_Creation',
302: header => [{col1 => 'Format rule type',
303: col2 => 'Format rules in force'},
304: {col1 => 'User account creation',
305: col2 => 'Usernames which may be created',},
306: {col1 => 'Context',
307: col2 => 'Assignable authentication types'}],
308: },
309: 'usermodification' =>
310: { text => 'User modification',
311: help => 'Domain_Configuration_User_Modification',
312: header => [{col1 => 'Target user has role',
313: col2 => 'User information updateable in author context'},
314: {col1 => 'Target user has role',
315: col2 => 'User information updateable in course context'},
316: {col1 => "Status of user",
317: col2 => 'Information settable when self-creating account (if directory data blank)'}],
318: },
319: 'scantron' =>
320: { text => 'Bubblesheet format file',
321: help => 'Domain_Configuration_Scantron_Format',
322: header => [ {col1 => 'Item',
323: col2 => '',
324: }],
325: },
326: 'requestcourses' =>
327: {text => 'Request creation of courses',
328: help => 'Domain_Configuration_Request_Courses',
329: header => [{col1 => 'User affiliation',
330: col2 => 'Availability/Processing of requests',},
331: {col1 => 'Setting',
332: col2 => 'Value'}],
333: },
334: 'requestauthor' =>
335: {text => 'Request authoring space',
336: help => 'Domain_Configuration_Request_Author',
337: header => [{col1 => 'User affiliation',
338: col2 => 'Availability/Processing of requests',},
339: {col1 => 'Setting',
340: col2 => 'Value'}],
341: },
342: 'coursecategories' =>
343: { text => 'Cataloging of courses/communities',
344: help => 'Domain_Configuration_Cataloging_Courses',
345: header => [{col1 => 'Category settings',
346: col2 => '',},
347: {col1 => 'Categories',
348: col2 => '',
349: }],
350: },
351: 'serverstatuses' =>
352: {text => 'Access to server status pages',
353: help => 'Domain_Configuration_Server_Status',
354: header => [{col1 => 'Status Page',
355: col2 => 'Other named users',
356: col3 => 'Specific IPs',
357: }],
358: },
359: 'helpsettings' =>
360: {text => 'Help page settings',
361: help => 'Domain_Configuration_Help_Settings',
362: header => [{col1 => 'Help Settings (logged-in users)',
363: col2 => 'Value'}],
364: },
365: 'coursedefaults' =>
366: {text => 'Course/Community defaults',
367: help => 'Domain_Configuration_Course_Defaults',
368: header => [{col1 => 'Defaults which can be overridden in each course by a CC',
369: col2 => 'Value',},
370: {col1 => 'Defaults which can be overridden for each course by a DC',
371: col2 => 'Value',},],
372: },
373: 'privacy' =>
374: {text => 'User Privacy',
375: help => 'Domain_Configuration_User_Privacy',
376: header => [{col1 => 'Setting',
377: col2 => 'Value',}],
378: },
379: 'usersessions' =>
380: {text => 'User session hosting/offloading',
381: help => 'Domain_Configuration_User_Sessions',
382: header => [{col1 => 'Domain server',
383: col2 => 'Servers to offload sessions to when busy'},
384: {col1 => 'Hosting of users from other domains',
385: col2 => 'Rules'},
386: {col1 => "Hosting domain's own users elsewhere",
387: col2 => 'Rules'}],
388: },
389: 'loadbalancing' =>
390: {text => 'Dedicated Load Balancer(s)',
391: help => 'Domain_Configuration_Load_Balancing',
392: header => [{col1 => 'Balancers',
393: col2 => 'Default destinations',
394: col3 => 'User affiliation',
395: col4 => 'Overrides'},
396: ],
397: },
398: );
399: if (keys(%servers) > 1) {
400: $prefs{'login'} = { text => 'Log-in page options',
401: help => 'Domain_Configuration_Login_Page',
402: header => [{col1 => 'Log-in Service',
403: col2 => 'Server Setting',},
404: {col1 => 'Log-in Page Items',
405: col2 => ''},
406: {col1 => 'Log-in Help',
407: col2 => 'Value'}],
408: };
409: }
410:
411: my @roles = ('student','coordinator','author','admin');
412: my @actions = &Apache::loncommon::get_env_multiple('form.actions');
413: &Apache::lonhtmlcommon::add_breadcrumb
414: ({href=>"javascript:changePage(document.$phase,'pickactions')",
415: text=>"Settings to display/modify"});
416: my $confname = $dom.'-domainconfig';
417:
418: if ($phase eq 'process') {
419: &Apache::lonconfigsettings::make_changes($r,$dom,$phase,$context,\@prefs_order,\%prefs,\%domconfig,$confname,\@roles);
420: } elsif ($phase eq 'display') {
421: my $js = &recaptcha_js().
422: &credits_js();
423: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
424: my ($othertitle,$usertypes,$types) =
425: &Apache::loncommon::sorted_inst_types($dom);
426: $js .= &lonbalance_targets_js($dom,$types,\%servers,
427: $domconfig{'loadbalancing'}).
428: &new_spares_js().
429: &common_domprefs_js().
430: &Apache::loncommon::javascript_array_indexof();
431: }
432: &Apache::lonconfigsettings::display_settings($r,$dom,$phase,$context,\@prefs_order,\%prefs,\%domconfig,$confname,$js);
433: } else {
434: # check if domconfig user exists for the domain.
435: my $servadm = $r->dir_config('lonAdmEMail');
436: my ($configuserok,$author_ok,$switchserver) =
437: &config_check($dom,$confname,$servadm);
438: unless ($configuserok eq 'ok') {
439: &Apache::lonconfigsettings::print_header($r,$phase,$context);
440: $r->print(&mt('The domain configuration user "[_1]" has yet to be created.',
441: $confname).
442: '<br />'
443: );
444: if ($switchserver) {
445: $r->print(&mt('Ordinarily, that domain configuration user is created when the ./UPDATE script is run to install LON-CAPA for the first time.').
446: '<br />'.
447: &mt('However, that does not apply when new domains are added to a multi-domain server, and ./UPDATE has not been run recently.').
448: '<br />'.
449: &mt('The "[_1]" user can be created automatically when a Domain Coordinator visits the web-based "Set domain configuration" screen, in a session hosted on the primary library server.',$confname).
450: '<br />'.
451: &mt('To do that now, use the following link: [_1]',$switchserver)
452: );
453: } else {
454: $r->print(&mt('To create that user from the command line run the ./UPDATE script found in the top level directory of the extracted LON-CAPA tarball.').
455: '<br />'.
456: &mt('Once that is done, you will be able to use the web-based "Set domain configuration" to configure the domain')
457: );
458: }
459: $r->print(&Apache::loncommon::end_page());
460: return OK;
461: }
462: if (keys(%domconfig) == 0) {
463: my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
464: my @ids=&Apache::lonnet::current_machine_ids();
465: if (!grep(/^\Q$primarylibserv\E$/,@ids)) {
466: my %designhash = &Apache::loncommon::get_domainconf($dom);
467: my @loginimages = ('img','logo','domlogo','login');
468: my $custom_img_count = 0;
469: foreach my $img (@loginimages) {
470: if ($designhash{$dom.'.login.'.$img} ne '') {
471: $custom_img_count ++;
472: }
473: }
474: foreach my $role (@roles) {
475: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
476: $custom_img_count ++;
477: }
478: }
479: if ($custom_img_count > 0) {
480: &Apache::lonconfigsettings::print_header($r,$phase,$context);
481: my $switch_server = &check_switchserver($dom,$confname);
482: $r->print(
483: &mt('Domain configuration settings have yet to be saved for this domain via the web-based domain preferences interface.').'<br />'.
484: &mt("While this remains so, you must switch to the domain's primary library server in order to update settings.").'<br /><br />'.
485: &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 />'.
486: &mt("However, you will still need to switch to the domain's primary library server to upload new images or logos.").'<br /><br />');
487: if ($switch_server) {
488: $r->print($switch_server.' '.&mt('to primary library server for domain: [_1]',$dom));
489: }
490: $r->print(&Apache::loncommon::end_page());
491: return OK;
492: }
493: }
494: }
495: &Apache::lonconfigsettings::display_choices($r,$phase,$context,\@prefs_order,\%prefs);
496: }
497: return OK;
498: }
499:
500: sub process_changes {
501: my ($r,$dom,$confname,$action,$roles,$values) = @_;
502: my %domconfig;
503: if (ref($values) eq 'HASH') {
504: %domconfig = %{$values};
505: }
506: my $output;
507: if ($action eq 'login') {
508: $output = &modify_login($r,$dom,$confname,%domconfig);
509: } elsif ($action eq 'rolecolors') {
510: $output = &modify_rolecolors($r,$dom,$confname,$roles,
511: %domconfig);
512: } elsif ($action eq 'quotas') {
513: $output = &modify_quotas($dom,$action,%domconfig);
514: } elsif ($action eq 'autoenroll') {
515: $output = &modify_autoenroll($dom,%domconfig);
516: } elsif ($action eq 'autoupdate') {
517: $output = &modify_autoupdate($dom,%domconfig);
518: } elsif ($action eq 'autocreate') {
519: $output = &modify_autocreate($dom,%domconfig);
520: } elsif ($action eq 'directorysrch') {
521: $output = &modify_directorysrch($dom,%domconfig);
522: } elsif ($action eq 'usercreation') {
523: $output = &modify_usercreation($dom,%domconfig);
524: } elsif ($action eq 'usermodification') {
525: $output = &modify_usermodification($dom,%domconfig);
526: } elsif ($action eq 'contacts') {
527: $output = &modify_contacts($dom,%domconfig);
528: } elsif ($action eq 'defaults') {
529: $output = &modify_defaults($dom,$r);
530: } elsif ($action eq 'scantron') {
531: $output = &modify_scantron($r,$dom,$confname,%domconfig);
532: } elsif ($action eq 'coursecategories') {
533: $output = &modify_coursecategories($dom,%domconfig);
534: } elsif ($action eq 'serverstatuses') {
535: $output = &modify_serverstatuses($dom,%domconfig);
536: } elsif ($action eq 'requestcourses') {
537: $output = &modify_quotas($dom,$action,%domconfig);
538: } elsif ($action eq 'requestauthor') {
539: $output = &modify_quotas($dom,$action,%domconfig);
540: } elsif ($action eq 'helpsettings') {
541: $output = &modify_helpsettings($r,$dom,$confname,%domconfig);
542: } elsif ($action eq 'coursedefaults') {
543: $output = &modify_coursedefaults($dom,%domconfig);
544: } elsif ($action eq 'usersessions') {
545: $output = &modify_usersessions($dom,%domconfig);
546: } elsif ($action eq 'loadbalancing') {
547: $output = &modify_loadbalancing($dom,%domconfig);
548: }
549: return $output;
550: }
551:
552: sub print_config_box {
553: my ($r,$dom,$confname,$phase,$action,$item,$settings) = @_;
554: my $rowtotal = 0;
555: my $output;
556: if ($action eq 'coursecategories') {
557: $output = &coursecategories_javascript($settings);
558: }
559: $output .=
560: '<table class="LC_nested_outer">
561: <tr>
562: <th align="left" valign="middle"><span class="LC_nobreak">'.
563: &mt($item->{text}).' '.
564: &Apache::loncommon::help_open_topic($item->{'help'}).'</span></th>'."\n".
565: '</tr>';
566: $rowtotal ++;
567: my $numheaders = 1;
568: if (ref($item->{'header'}) eq 'ARRAY') {
569: $numheaders = scalar(@{$item->{'header'}});
570: }
571: if ($numheaders > 1) {
572: my $colspan = '';
573: my $rightcolspan = '';
574: if (($action eq 'rolecolors') || ($action eq 'coursecategories') ||
575: (($action eq 'login') && ($numheaders < 3))) {
576: $colspan = ' colspan="2"';
577: }
578: if ($action eq 'usersessions') {
579: $rightcolspan = ' colspan="3"';
580: }
581: $output .= '
582: <tr>
583: <td>
584: <table class="LC_nested">
585: <tr class="LC_info_row">
586: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[0]->{'col1'}).'</td>
587: <td class="LC_right_item"'.$rightcolspan.'>'.&mt($item->{'header'}->[0]->{'col2'}).'</td>
588: </tr>';
589: $rowtotal ++;
590: if ($action eq 'autoupdate') {
591: $output .= &print_autoupdate('top',$dom,$settings,\$rowtotal);
592: } elsif ($action eq 'usercreation') {
593: $output .= &print_usercreation('top',$dom,$settings,\$rowtotal);
594: } elsif ($action eq 'usermodification') {
595: $output .= &print_usermodification('top',$dom,$settings,\$rowtotal);
596: } elsif ($action eq 'coursecategories') {
597: $output .= &print_coursecategories('top',$dom,$item,$settings,\$rowtotal);
598: } elsif ($action eq 'login') {
599: if ($numheaders == 3) {
600: $colspan = ' colspan="2"';
601: $output .= &print_login('service',$dom,$confname,$phase,$settings,\$rowtotal);
602: } else {
603: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal);
604: }
605: } elsif ($action eq 'requestcourses') {
606: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
607: } elsif ($action eq 'requestauthor') {
608: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
609: } elsif ($action eq 'usersessions') {
610: $output .= &print_usersessions('top',$dom,$settings,\$rowtotal);
611: } elsif ($action eq 'rolecolors') {
612: $output .= &print_rolecolors($phase,'student',$dom,$confname,$settings,\$rowtotal);
613: } elsif ($action eq 'coursedefaults') {
614: $output .= &print_coursedefaults('top',$dom,$settings,\$rowtotal);
615: }
616: $output .= '
617: </table>
618: </td>
619: </tr>
620: <tr>
621: <td>
622: <table class="LC_nested">
623: <tr class="LC_info_row">
624: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col1'}).'</td>';
625: $output .= '
626: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col2'}).'</td>
627: </tr>';
628: $rowtotal ++;
629: if ($action eq 'autoupdate') {
630: $output .= &print_autoupdate('middle',$dom,$settings,\$rowtotal).'
631: </table>
632: </td>
633: </tr>
634: <tr>
635: <td>
636: <table class="LC_nested">
637: <tr class="LC_info_row">
638: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
639: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
640: &print_autoupdate('bottom',$dom,$settings,\$rowtotal);
641: $rowtotal ++;
642: } elsif ($action eq 'usercreation') {
643: $output .= &print_usercreation('middle',$dom,$settings,\$rowtotal).'
644: </table>
645: </td>
646: </tr>
647: <tr>
648: <td>
649: <table class="LC_nested">
650: <tr class="LC_info_row">
651: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
652: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
653: &print_usercreation('bottom',$dom,$settings,\$rowtotal);
654: $rowtotal ++;
655: } elsif ($action eq 'usermodification') {
656: $output .= &print_usermodification('middle',$dom,$settings,\$rowtotal).'
657: </table>
658: </td>
659: </tr>
660: <tr>
661: <td>
662: <table class="LC_nested">
663: <tr class="LC_info_row">
664: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
665: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
666: &print_usermodification('bottom',$dom,$settings,\$rowtotal);
667: $rowtotal ++;
668: } elsif ($action eq 'coursecategories') {
669: $output .= &print_coursecategories('bottom',$dom,$item,$settings,\$rowtotal);
670: } elsif ($action eq 'login') {
671: if ($numheaders == 3) {
672: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal).'
673: </table>
674: </td>
675: </tr>
676: <tr>
677: <td>
678: <table class="LC_nested">
679: <tr class="LC_info_row">
680: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
681: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
682: &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
683: $rowtotal ++;
684: } else {
685: $output .= &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
686: }
687: } elsif ($action eq 'requestcourses') {
688: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
689: } elsif ($action eq 'requestauthor') {
690: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
691: } elsif ($action eq 'usersessions') {
692: $output .= &print_usersessions('middle',$dom,$settings,\$rowtotal).'
693: </table>
694: </td>
695: </tr>
696: <tr>
697: <td>
698: <table class="LC_nested">
699: <tr class="LC_info_row">
700: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
701: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
702: &print_usersessions('bottom',$dom,$settings,\$rowtotal);
703: $rowtotal ++;
704: } elsif ($action eq 'coursedefaults') {
705: $output .= &print_coursedefaults('bottom',$dom,$settings,\$rowtotal);
706: } elsif ($action eq 'rolecolors') {
707: $output .= &print_rolecolors($phase,'coordinator',$dom,$confname,$settings,\$rowtotal).'
708: </table>
709: </td>
710: </tr>
711: <tr>
712: <td>
713: <table class="LC_nested">
714: <tr class="LC_info_row">
715: <td class="LC_left_item"'.$colspan.' valign="top">'.
716: &mt($item->{'header'}->[2]->{'col1'}).'</td>
717: <td class="LC_right_item" valign="top">'.
718: &mt($item->{'header'}->[2]->{'col2'}).'</td>
719: </tr>'.
720: &print_rolecolors($phase,'author',$dom,$confname,$settings,\$rowtotal).'
721: </table>
722: </td>
723: </tr>
724: <tr>
725: <td>
726: <table class="LC_nested">
727: <tr class="LC_info_row">
728: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
729: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
730: </tr>'.
731: &print_rolecolors($phase,'admin',$dom,$confname,$settings,\$rowtotal);
732: $rowtotal += 2;
733: }
734: } else {
735: $output .= '
736: <tr>
737: <td>
738: <table class="LC_nested">
739: <tr class="LC_info_row">';
740: if (($action eq 'login') || ($action eq 'directorysrch')) {
741: $output .= '
742: <td class="LC_left_item" colspan="2">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
743: } elsif ($action eq 'serverstatuses') {
744: $output .= '
745: <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).
746: '<br />('.&mt('Automatic access for Dom. Coords.').')</td>';
747:
748: } else {
749: $output .= '
750: <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
751: }
752: if (defined($item->{'header'}->[0]->{'col3'})) {
753: $output .= '<td class="LC_left_item" valign="top">'.
754: &mt($item->{'header'}->[0]->{'col2'});
755: if ($action eq 'serverstatuses') {
756: $output .= '<br />(<tt>'.&mt('user1:domain1,user2:domain2 etc.').'</tt>)';
757: }
758: } else {
759: $output .= '<td class="LC_right_item" valign="top">'.
760: &mt($item->{'header'}->[0]->{'col2'});
761: }
762: $output .= '</td>';
763: if ($item->{'header'}->[0]->{'col3'}) {
764: if (defined($item->{'header'}->[0]->{'col4'})) {
765: $output .= '<td class="LC_left_item" valign="top">'.
766: &mt($item->{'header'}->[0]->{'col3'});
767: } else {
768: $output .= '<td class="LC_right_item" valign="top">'.
769: &mt($item->{'header'}->[0]->{'col3'});
770: }
771: if ($action eq 'serverstatuses') {
772: $output .= '<br />(<tt>'.&mt('IP1,IP2 etc.').'</tt>)';
773: }
774: $output .= '</td>';
775: }
776: if ($item->{'header'}->[0]->{'col4'}) {
777: $output .= '<td class="LC_right_item" valign="top">'.
778: &mt($item->{'header'}->[0]->{'col4'});
779: }
780: $output .= '</tr>';
781: $rowtotal ++;
782: if ($action eq 'quotas') {
783: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
784: } elsif ($action eq 'autoenroll') {
785: $output .= &print_autoenroll($dom,$settings,\$rowtotal);
786: } elsif ($action eq 'autocreate') {
787: $output .= &print_autocreate($dom,$settings,\$rowtotal);
788: } elsif ($action eq 'directorysrch') {
789: $output .= &print_directorysrch($dom,$settings,\$rowtotal);
790: } elsif ($action eq 'contacts') {
791: $output .= &print_contacts($dom,$settings,\$rowtotal);
792: } elsif ($action eq 'defaults') {
793: $output .= &print_defaults($dom,\$rowtotal);
794: } elsif ($action eq 'scantron') {
795: $output .= &print_scantronformat($r,$dom,$confname,$settings,\$rowtotal);
796: } elsif ($action eq 'serverstatuses') {
797: $output .= &print_serverstatuses($dom,$settings,\$rowtotal);
798: } elsif ($action eq 'helpsettings') {
799: $output .= &print_helpsettings($dom,$confname,$settings,\$rowtotal);
800: } elsif ($action eq 'loadbalancing') {
801: $output .= &print_loadbalancing($dom,$settings,\$rowtotal);
802: }
803: }
804: $output .= '
805: </table>
806: </td>
807: </tr>
808: </table><br />';
809: return ($output,$rowtotal);
810: }
811:
812: sub print_login {
813: my ($caller,$dom,$confname,$phase,$settings,$rowtotal) = @_;
814: my ($css_class,$datatable);
815: my %choices = &login_choices();
816:
817: if ($caller eq 'service') {
818: my %servers = &Apache::lonnet::internet_dom_servers($dom);
819: my $choice = $choices{'disallowlogin'};
820: $css_class = ' class="LC_odd_row"';
821: $datatable .= '<tr'.$css_class.'><td>'.$choice.'</td>'.
822: '<td align="right"><table><tr><th>'.$choices{'hostid'}.'</th>'.
823: '<th>'.$choices{'server'}.'</th>'.
824: '<th>'.$choices{'serverpath'}.'</th>'.
825: '<th>'.$choices{'custompath'}.'</th>'.
826: '<th><span class="LC_nobreak">'.$choices{'exempt'}.'</span></th></tr>'."\n";
827: my %disallowed;
828: if (ref($settings) eq 'HASH') {
829: if (ref($settings->{'loginvia'}) eq 'HASH') {
830: %disallowed = %{$settings->{'loginvia'}};
831: }
832: }
833: foreach my $lonhost (sort(keys(%servers))) {
834: my $direct = 'selected="selected"';
835: if (ref($disallowed{$lonhost}) eq 'HASH') {
836: if ($disallowed{$lonhost}{'server'} ne '') {
837: $direct = '';
838: }
839: }
840: $datatable .= '<tr><td>'.$servers{$lonhost}.'</td>'.
841: '<td><select name="'.$lonhost.'_server">'.
842: '<option value=""'.$direct.'>'.$choices{'directlogin'}.
843: '</option>';
844: foreach my $hostid (sort(keys(%servers))) {
845: next if ($servers{$hostid} eq $servers{$lonhost});
846: my $selected = '';
847: if (ref($disallowed{$lonhost}) eq 'HASH') {
848: if ($hostid eq $disallowed{$lonhost}{'server'}) {
849: $selected = 'selected="selected"';
850: }
851: }
852: $datatable .= '<option value="'.$hostid.'"'.$selected.'>'.
853: $servers{$hostid}.'</option>';
854: }
855: $datatable .= '</select></td>'.
856: '<td><select name="'.$lonhost.'_serverpath">';
857: foreach my $path ('','/','/adm/login','/adm/roles','custom') {
858: my $pathname = $path;
859: if ($path eq 'custom') {
860: $pathname = &mt('Custom Path').' ->';
861: }
862: my $selected = '';
863: if (ref($disallowed{$lonhost}) eq 'HASH') {
864: if ($path eq $disallowed{$lonhost}{'serverpath'}) {
865: $selected = 'selected="selected"';
866: }
867: } elsif ($path eq '') {
868: $selected = 'selected="selected"';
869: }
870: $datatable .= '<option value="'.$path.'"'.$selected.'>'.$pathname.'</option>';
871: }
872: $datatable .= '</select></td>';
873: my ($custom,$exempt);
874: if (ref($disallowed{$lonhost}) eq 'HASH') {
875: $custom = $disallowed{$lonhost}{'custompath'};
876: $exempt = $disallowed{$lonhost}{'exempt'};
877: }
878: $datatable .= '<td><input type="text" name="'.$lonhost.'_custompath" size="6" value="'.$custom.'" /></td>'.
879: '<td><input type="text" name="'.$lonhost.'_exempt" size="8" value="'.$exempt.'" /></td>'.
880: '</tr>';
881: }
882: $datatable .= '</table></td></tr>';
883: return $datatable;
884: } elsif ($caller eq 'page') {
885: my %defaultchecked = (
886: 'coursecatalog' => 'on',
887: 'helpdesk' => 'on',
888: 'adminmail' => 'off',
889: 'newuser' => 'off',
890: );
891: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
892: my (%checkedon,%checkedoff);
893: foreach my $item (@toggles) {
894: if ($defaultchecked{$item} eq 'on') {
895: $checkedon{$item} = ' checked="checked" ';
896: $checkedoff{$item} = ' ';
897: } elsif ($defaultchecked{$item} eq 'off') {
898: $checkedoff{$item} = ' checked="checked" ';
899: $checkedon{$item} = ' ';
900: }
901: }
902: my @images = ('img','logo','domlogo','login');
903: my @logintext = ('textcol','bgcol');
904: my @bgs = ('pgbg','mainbg','sidebg');
905: my @links = ('link','alink','vlink');
906: my %designhash = &Apache::loncommon::get_domainconf($dom);
907: my %defaultdesign = %Apache::loncommon::defaultdesign;
908: my (%is_custom,%designs);
909: my %defaults = (
910: font => $defaultdesign{'login.font'},
911: );
912: foreach my $item (@images) {
913: $defaults{$item} = $defaultdesign{'login.'.$item};
914: $defaults{'showlogo'}{$item} = 1;
915: }
916: foreach my $item (@bgs) {
917: $defaults{'bgs'}{$item} = $defaultdesign{'login.'.$item};
918: }
919: foreach my $item (@logintext) {
920: $defaults{'logintext'}{$item} = $defaultdesign{'login.'.$item};
921: }
922: foreach my $item (@links) {
923: $defaults{'links'}{$item} = $defaultdesign{'login.'.$item};
924: }
925: if (ref($settings) eq 'HASH') {
926: foreach my $item (@toggles) {
927: if ($settings->{$item} eq '1') {
928: $checkedon{$item} = ' checked="checked" ';
929: $checkedoff{$item} = ' ';
930: } elsif ($settings->{$item} eq '0') {
931: $checkedoff{$item} = ' checked="checked" ';
932: $checkedon{$item} = ' ';
933: }
934: }
935: foreach my $item (@images) {
936: if (defined($settings->{$item})) {
937: $designs{$item} = $settings->{$item};
938: $is_custom{$item} = 1;
939: }
940: if (defined($settings->{'showlogo'}{$item})) {
941: $designs{'showlogo'}{$item} = $settings->{'showlogo'}{$item};
942: }
943: }
944: foreach my $item (@logintext) {
945: if ($settings->{$item} ne '') {
946: $designs{'logintext'}{$item} = $settings->{$item};
947: $is_custom{$item} = 1;
948: }
949: }
950: if ($settings->{'font'} ne '') {
951: $designs{'font'} = $settings->{'font'};
952: $is_custom{'font'} = 1;
953: }
954: foreach my $item (@bgs) {
955: if ($settings->{$item} ne '') {
956: $designs{'bgs'}{$item} = $settings->{$item};
957: $is_custom{$item} = 1;
958: }
959: }
960: foreach my $item (@links) {
961: if ($settings->{$item} ne '') {
962: $designs{'links'}{$item} = $settings->{$item};
963: $is_custom{$item} = 1;
964: }
965: }
966: } else {
967: if ($designhash{$dom.'.login.font'} ne '') {
968: $designs{'font'} = $designhash{$dom.'.login.font'};
969: $is_custom{'font'} = 1;
970: }
971: foreach my $item (@images) {
972: if ($designhash{$dom.'.login.'.$item} ne '') {
973: $designs{$item} = $designhash{$dom.'.login.'.$item};
974: $is_custom{$item} = 1;
975: }
976: }
977: foreach my $item (@bgs) {
978: if ($designhash{$dom.'.login.'.$item} ne '') {
979: $designs{'bgs'}{$item} = $designhash{$dom.'.login.'.$item};
980: $is_custom{$item} = 1;
981: }
982: }
983: foreach my $item (@links) {
984: if ($designhash{$dom.'.login.'.$item} ne '') {
985: $designs{'links'}{$item} = $designhash{$dom.'.login.'.$item};
986: $is_custom{$item} = 1;
987: }
988: }
989: }
990: my %alt_text = &Apache::lonlocal::texthash ( img => 'Log-in banner',
991: logo => 'Institution Logo',
992: domlogo => 'Domain Logo',
993: login => 'Login box');
994: my $itemcount = 1;
995: foreach my $item (@toggles) {
996: $css_class = $itemcount%2?' class="LC_odd_row"':'';
997: $datatable .=
998: '<tr'.$css_class.'><td colspan="2">'.$choices{$item}.
999: '</td><td>'.
1000: '<span class="LC_nobreak"><label><input type="radio" name="'.
1001: $item.'"'.$checkedon{$item}.' value="1" />'.&mt('Yes').
1002: '</label> <label><input type="radio" name="'.$item.'"'.
1003: $checkedoff{$item}.' value="0" />'.&mt('No').'</label></span></td>'.
1004: '</tr>';
1005: $itemcount ++;
1006: }
1007: $datatable .= &display_color_options($dom,$confname,$phase,'login',$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal,\@logintext);
1008: $datatable .= '</tr></table></td></tr>';
1009: } elsif ($caller eq 'help') {
1010: my ($defaulturl,$defaulttype,%url,%type,%lt,%langchoices);
1011: my $switchserver = &check_switchserver($dom,$confname);
1012: my $itemcount = 1;
1013: $defaulturl = '/adm/loginproblems.html';
1014: $defaulttype = 'default';
1015: %lt = &Apache::lonlocal::texthash (
1016: del => 'Delete?',
1017: rep => 'Replace:',
1018: upl => 'Upload:',
1019: default => 'Default',
1020: custom => 'Custom',
1021: );
1022: %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
1023: my @currlangs;
1024: if (ref($settings) eq 'HASH') {
1025: if (ref($settings->{'helpurl'}) eq 'HASH') {
1026: foreach my $key (sort(keys(%{$settings->{'helpurl'}}))) {
1027: next if ($settings->{'helpurl'}{$key} eq '');
1028: $url{$key} = $settings->{'helpurl'}{$key}.'?inhibitmenu=yes';
1029: $type{$key} = 'custom';
1030: unless ($key eq 'nolang') {
1031: push(@currlangs,$key);
1032: }
1033: }
1034: } elsif ($settings->{'helpurl'} ne '') {
1035: $type{'nolang'} = 'custom';
1036: $url{'nolang'} = $settings->{'helpurl'}.'?inhibitmenu=yes';
1037: }
1038: }
1039: foreach my $lang ('nolang',sort(@currlangs)) {
1040: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1041: $datatable .= '<tr'.$css_class.'>';
1042: if ($url{$lang} eq '') {
1043: $url{$lang} = $defaulturl;
1044: }
1045: if ($type{$lang} eq '') {
1046: $type{$lang} = $defaulttype;
1047: }
1048: $datatable .= '<td colspan="2"><span class="LC_nobreak">';
1049: if ($lang eq 'nolang') {
1050: $datatable .= &mt('Log-in help page if no specific language file: [_1]',
1051: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1052: } else {
1053: $datatable .= &mt('Log-in help page for language: [_1] is [_2]',
1054: $langchoices{$lang},
1055: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1056: }
1057: $datatable .= '</span></td>'."\n".
1058: '<td class="LC_left_item">';
1059: if ($type{$lang} eq 'custom') {
1060: $datatable .= '<span class="LC_nobreak"><label>'.
1061: '<input type="checkbox" name="loginhelpurl_del" value="'.$lang.'" />'.
1062: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1063: } else {
1064: $datatable .= $lt{'upl'};
1065: }
1066: $datatable .='<br />';
1067: if ($switchserver) {
1068: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1069: } else {
1070: $datatable .= '<input type="file" name="loginhelpurl_'.$lang.'" />';
1071: }
1072: $datatable .= '</td></tr>';
1073: $itemcount ++;
1074: }
1075: my @addlangs;
1076: foreach my $lang (sort(keys(%langchoices))) {
1077: next if ((grep(/^\Q$lang\E$/,@currlangs)) || ($lang eq 'x_chef'));
1078: push(@addlangs,$lang);
1079: }
1080: if (@addlangs > 0) {
1081: my %toadd;
1082: map { $toadd{$_} = $langchoices{$_} ; } @addlangs;
1083: $toadd{''} = &mt('Select');
1084: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1085: $datatable .= '<tr'.$css_class.'><td class="LC_left_item" colspan="2">'.
1086: &mt('Add log-in help page for a specific language:').' '.
1087: &Apache::loncommon::select_form('','loginhelpurl_add_lang',\%toadd).
1088: '</td><td class="LC_left_item">'.$lt{'upl'}.'<br />';
1089: if ($switchserver) {
1090: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1091: } else {
1092: $datatable .= '<input type="file" name="loginhelpurl_add_file" />';
1093: }
1094: $datatable .= '</td></tr>';
1095: $itemcount ++;
1096: }
1097: $datatable .= &captcha_choice('login',$settings,$itemcount);
1098: }
1099: return $datatable;
1100: }
1101:
1102: sub login_choices {
1103: my %choices =
1104: &Apache::lonlocal::texthash (
1105: coursecatalog => 'Display Course/Community Catalog link?',
1106: adminmail => "Display Administrator's E-mail Address?",
1107: helpdesk => 'Display "Contact Helpdesk" link',
1108: disallowlogin => "Login page requests redirected",
1109: hostid => "Server",
1110: server => "Redirect to:",
1111: serverpath => "Path",
1112: custompath => "Custom",
1113: exempt => "Exempt IP(s)",
1114: directlogin => "No redirect",
1115: newuser => "Link to create a user account",
1116: img => "Header",
1117: logo => "Main Logo",
1118: domlogo => "Domain Logo",
1119: login => "Log-in Header",
1120: textcol => "Text color",
1121: bgcol => "Box color",
1122: bgs => "Background colors",
1123: links => "Link colors",
1124: font => "Font color",
1125: pgbg => "Header",
1126: mainbg => "Page",
1127: sidebg => "Login box",
1128: link => "Link",
1129: alink => "Active link",
1130: vlink => "Visited link",
1131: );
1132: return %choices;
1133: }
1134:
1135: sub print_rolecolors {
1136: my ($phase,$role,$dom,$confname,$settings,$rowtotal) = @_;
1137: my %choices = &color_font_choices();
1138: my @bgs = ('pgbg','tabbg','sidebg');
1139: my @links = ('link','alink','vlink');
1140: my @images = ('img');
1141: my %alt_text = &Apache::lonlocal::texthash(img => "Banner for $role role");
1142: my %designhash = &Apache::loncommon::get_domainconf($dom);
1143: my %defaultdesign = %Apache::loncommon::defaultdesign;
1144: my (%is_custom,%designs);
1145: my %defaults = &role_defaults($role,\@bgs,\@links,\@images);
1146: if (ref($settings) eq 'HASH') {
1147: if (ref($settings->{$role}) eq 'HASH') {
1148: if ($settings->{$role}->{'img'} ne '') {
1149: $designs{'img'} = $settings->{$role}->{'img'};
1150: $is_custom{'img'} = 1;
1151: }
1152: if ($settings->{$role}->{'font'} ne '') {
1153: $designs{'font'} = $settings->{$role}->{'font'};
1154: $is_custom{'font'} = 1;
1155: }
1156: if ($settings->{$role}->{'fontmenu'} ne '') {
1157: $designs{'fontmenu'} = $settings->{$role}->{'fontmenu'};
1158: $is_custom{'fontmenu'} = 1;
1159: }
1160: foreach my $item (@bgs) {
1161: if ($settings->{$role}->{$item} ne '') {
1162: $designs{'bgs'}{$item} = $settings->{$role}->{$item};
1163: $is_custom{$item} = 1;
1164: }
1165: }
1166: foreach my $item (@links) {
1167: if ($settings->{$role}->{$item} ne '') {
1168: $designs{'links'}{$item} = $settings->{$role}->{$item};
1169: $is_custom{$item} = 1;
1170: }
1171: }
1172: }
1173: } else {
1174: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
1175: $designs{img} = $designhash{$dom.'.'.$role.'.img'};
1176: $is_custom{'img'} = 1;
1177: }
1178: if ($designhash{$dom.'.'.$role.'.fontmenu'} ne '') {
1179: $designs{fontmenu} = $designhash{$dom.'.'.$role.'.fontmenu'};
1180: $is_custom{'fontmenu'} = 1;
1181: }
1182: if ($designhash{$dom.'.'.$role.'.font'} ne '') {
1183: $designs{font} = $designhash{$dom.'.'.$role.'.font'};
1184: $is_custom{'font'} = 1;
1185: }
1186: foreach my $item (@bgs) {
1187: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1188: $designs{'bgs'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1189: $is_custom{$item} = 1;
1190:
1191: }
1192: }
1193: foreach my $item (@links) {
1194: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1195: $designs{'links'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1196: $is_custom{$item} = 1;
1197: }
1198: }
1199: }
1200: my $itemcount = 1;
1201: my $datatable = &display_color_options($dom,$confname,$phase,$role,$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal);
1202: $datatable .= '</tr></table></td></tr>';
1203: return $datatable;
1204: }
1205:
1206: sub role_defaults {
1207: my ($role,$bgs,$links,$images,$logintext) = @_;
1208: my %defaults;
1209: unless ((ref($bgs) eq 'ARRAY') && (ref($links) eq 'ARRAY') && (ref($images) eq 'ARRAY')) {
1210: return %defaults;
1211: }
1212: my %defaultdesign = %Apache::loncommon::defaultdesign;
1213: if ($role eq 'login') {
1214: %defaults = (
1215: font => $defaultdesign{$role.'.font'},
1216: );
1217: if (ref($logintext) eq 'ARRAY') {
1218: foreach my $item (@{$logintext}) {
1219: $defaults{'logintext'}{$item} = $defaultdesign{$role.'.'.$item};
1220: }
1221: }
1222: foreach my $item (@{$images}) {
1223: $defaults{'showlogo'}{$item} = 1;
1224: }
1225: } else {
1226: %defaults = (
1227: img => $defaultdesign{$role.'.img'},
1228: font => $defaultdesign{$role.'.font'},
1229: fontmenu => $defaultdesign{$role.'.fontmenu'},
1230: );
1231: }
1232: foreach my $item (@{$bgs}) {
1233: $defaults{'bgs'}{$item} = $defaultdesign{$role.'.'.$item};
1234: }
1235: foreach my $item (@{$links}) {
1236: $defaults{'links'}{$item} = $defaultdesign{$role.'.'.$item};
1237: }
1238: foreach my $item (@{$images}) {
1239: $defaults{$item} = $defaultdesign{$role.'.'.$item};
1240: }
1241: return %defaults;
1242: }
1243:
1244: sub display_color_options {
1245: my ($dom,$confname,$phase,$role,$itemcount,$choices,$is_custom,$defaults,$designs,
1246: $images,$bgs,$links,$alt_text,$rowtotal,$logintext) = @_;
1247: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1248: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1249: my $datatable = '<tr'.$css_class.'>'.
1250: '<td>'.$choices->{'font'}.'</td>';
1251: if (!$is_custom->{'font'}) {
1252: $datatable .= '<td>'.&mt('Default in use:').' <span id="css_default_'.$role.'_font" style="color: '.$defaults->{'font'}.';">'.$defaults->{'font'}.'</span></td>';
1253: } else {
1254: $datatable .= '<td> </td>';
1255: }
1256: my $current_color = $designs->{'font'} ? $designs->{'font'} : $defaults->{'font'};
1257:
1258: $datatable .= '<td><span class="LC_nobreak">'.
1259: '<input type="text" class="colorchooser" size="10" name="'.$role.'_font"'.
1260: ' value="'.$current_color.'" /> '.
1261: ' </td></tr>';
1262: unless ($role eq 'login') {
1263: $datatable .= '<tr'.$css_class.'>'.
1264: '<td>'.$choices->{'fontmenu'}.'</td>';
1265: if (!$is_custom->{'fontmenu'}) {
1266: $datatable .= '<td>'.&mt('Default in use:').' <span id="css_default_'.$role.'_font" style="color: '.$defaults->{'fontmenu'}.';">'.$defaults->{'fontmenu'}.'</span></td>';
1267: } else {
1268: $datatable .= '<td> </td>';
1269: }
1270: $current_color = $designs->{'fontmenu'} ?
1271: $designs->{'fontmenu'} : $defaults->{'fontmenu'};
1272: $datatable .= '<td><span class="LC_nobreak">'.
1273: '<input class="colorchooser" type="text" size="10" name="'
1274: .$role.'_fontmenu"'.
1275: ' value="'.$current_color.'" /> '.
1276: ' </td></tr>';
1277: }
1278: my $switchserver = &check_switchserver($dom,$confname);
1279: foreach my $img (@{$images}) {
1280: $itemcount ++;
1281: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1282: $datatable .= '<tr'.$css_class.'>'.
1283: '<td>'.$choices->{$img};
1284: my ($imgfile,$img_import,$login_hdr_pick,$logincolors);
1285: if ($role eq 'login') {
1286: if ($img eq 'login') {
1287: $login_hdr_pick =
1288: &login_header_options($img,$role,$defaults,$is_custom,$choices);
1289: $logincolors =
1290: &login_text_colors($img,$role,$logintext,$phase,$choices,
1291: $designs,$defaults);
1292: } elsif ($img ne 'domlogo') {
1293: $datatable.= &logo_display_options($img,$defaults,$designs);
1294: }
1295: }
1296: $datatable .= '</td>';
1297: if ($designs->{$img} ne '') {
1298: $imgfile = $designs->{$img};
1299: $img_import = ($imgfile =~ m{^/adm/});
1300: } else {
1301: $imgfile = $defaults->{$img};
1302: }
1303: if ($imgfile) {
1304: my ($showfile,$fullsize);
1305: if ($imgfile =~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
1306: my $urldir = $1;
1307: my $filename = $2;
1308: my @info = &Apache::lonnet::stat_file($designs->{$img});
1309: if (@info) {
1310: my $thumbfile = 'tn-'.$filename;
1311: my @thumb=&Apache::lonnet::stat_file($urldir.'/'.$thumbfile);
1312: if (@thumb) {
1313: $showfile = $urldir.'/'.$thumbfile;
1314: } else {
1315: $showfile = $imgfile;
1316: }
1317: } else {
1318: $showfile = '';
1319: }
1320: } elsif ($imgfile =~ m-^/(adm/[^/]+)/([^/]+)$-) {
1321: $showfile = $imgfile;
1322: my $imgdir = $1;
1323: my $filename = $2;
1324: if (-e "$londocroot/$imgdir/tn-".$filename) {
1325: $showfile = "/$imgdir/tn-".$filename;
1326: } else {
1327: my $input = $londocroot.$imgfile;
1328: my $output = "$londocroot/$imgdir/tn-".$filename;
1329: if (!-e $output) {
1330: my ($width,$height) = &thumb_dimensions();
1331: my ($fullwidth,$fullheight) = &check_dimensions($input);
1332: if ($fullwidth ne '' && $fullheight ne '') {
1333: if ($fullwidth > $width && $fullheight > $height) {
1334: my $size = $width.'x'.$height;
1335: system("convert -sample $size $input $output");
1336: $showfile = "/$imgdir/tn-".$filename;
1337: }
1338: }
1339: }
1340: }
1341: }
1342: if ($showfile) {
1343: if ($showfile =~ m{^/(adm|res)/}) {
1344: if ($showfile =~ m{^/res/}) {
1345: my $local_showfile =
1346: &Apache::lonnet::filelocation('',$showfile);
1347: &Apache::lonnet::repcopy($local_showfile);
1348: }
1349: $showfile = &Apache::loncommon::lonhttpdurl($showfile);
1350: }
1351: if ($imgfile) {
1352: if ($imgfile =~ m{^/(adm|res)/}) {
1353: if ($imgfile =~ m{^/res/}) {
1354: my $local_imgfile =
1355: &Apache::lonnet::filelocation('',$imgfile);
1356: &Apache::lonnet::repcopy($local_imgfile);
1357: }
1358: $fullsize = &Apache::loncommon::lonhttpdurl($imgfile);
1359: } else {
1360: $fullsize = $imgfile;
1361: }
1362: }
1363: $datatable .= '<td>';
1364: if ($img eq 'login') {
1365: $datatable .= $login_hdr_pick;
1366: }
1367: $datatable .= &image_changes($is_custom->{$img},$alt_text->{$img},$img_import,
1368: $showfile,$fullsize,$role,$img,$imgfile,$logincolors);
1369: } else {
1370: $datatable .= '<td> </td><td class="LC_left_item">'.
1371: &mt('Upload:').'<br />';
1372: }
1373: } else {
1374: $datatable .= '<td> </td><td class="LC_left_item">'.
1375: &mt('Upload:').'<br />';
1376: }
1377: if ($switchserver) {
1378: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1379: } else {
1380: if ($img ne 'login') { # suppress file selection for Log-in header
1381: $datatable .=' <input type="file" name="'.$role.'_'.$img.'" />';
1382: }
1383: }
1384: $datatable .= '</td></tr>';
1385: }
1386: $itemcount ++;
1387: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1388: $datatable .= '<tr'.$css_class.'>'.
1389: '<td>'.$choices->{'bgs'}.'</td>';
1390: my $bgs_def;
1391: foreach my $item (@{$bgs}) {
1392: if (!$is_custom->{$item}) {
1393: $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>';
1394: }
1395: }
1396: if ($bgs_def) {
1397: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$bgs_def.'</tr></table></td>';
1398: } else {
1399: $datatable .= '<td> </td>';
1400: }
1401: $datatable .= '<td class="LC_right_item">'.
1402: '<table border="0"><tr>';
1403:
1404: foreach my $item (@{$bgs}) {
1405: $datatable .= '<td align="center">'.$choices->{$item};
1406: my $color = $designs->{'bgs'}{$item} ? $designs->{'bgs'}{$item} : $defaults->{'bgs'}{$item};
1407: if ($designs->{'bgs'}{$item}) {
1408: $datatable .= ' ';
1409: }
1410: $datatable .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1411: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1412: }
1413: $datatable .= '</tr></table></td></tr>';
1414: $itemcount ++;
1415: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1416: $datatable .= '<tr'.$css_class.'>'.
1417: '<td>'.$choices->{'links'}.'</td>';
1418: my $links_def;
1419: foreach my $item (@{$links}) {
1420: if (!$is_custom->{$item}) {
1421: $links_def .= '<td>'.$choices->{$item}.'<br /><span id="css_default_'.$role.'_'.$item.'" style="color: '.$defaults->{'links'}{$item}.';">'.$defaults->{'links'}{$item}.'</span></td>';
1422: }
1423: }
1424: if ($links_def) {
1425: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$links_def.'</tr></table></td>';
1426: } else {
1427: $datatable .= '<td> </td>';
1428: }
1429: $datatable .= '<td class="LC_right_item">'.
1430: '<table border="0"><tr>';
1431: foreach my $item (@{$links}) {
1432: my $color = $designs->{'link'}{$item} ? $designs->{'link'}{$item} : $defaults->{'links'}{$item};
1433: $datatable .= '<td align="center">'.$choices->{$item}."\n";
1434: if ($designs->{'links'}{$item}) {
1435: $datatable.=' ';
1436: }
1437: $datatable .= '<br /><input type="text" size="8" class="colorchooser" name="'.$role.'_'.$item.'" value="'.$color.
1438: '" /></td>';
1439: }
1440: $$rowtotal += $itemcount;
1441: return $datatable;
1442: }
1443:
1444: sub logo_display_options {
1445: my ($img,$defaults,$designs) = @_;
1446: my $checkedon;
1447: if (ref($defaults) eq 'HASH') {
1448: if (ref($defaults->{'showlogo'}) eq 'HASH') {
1449: if ($defaults->{'showlogo'}{$img}) {
1450: $checkedon = 'checked="checked" ';
1451: }
1452: }
1453: }
1454: if (ref($designs) eq 'HASH') {
1455: if (ref($designs->{'showlogo'}) eq 'HASH') {
1456: if (defined($designs->{'showlogo'}{$img})) {
1457: if ($designs->{'showlogo'}{$img} == 0) {
1458: $checkedon = '';
1459: } elsif ($designs->{'showlogo'}{$img} == 1) {
1460: $checkedon = 'checked="checked" ';
1461: }
1462: }
1463: }
1464: }
1465: return '<br /><label> <input type="checkbox" name="'.
1466: 'login_showlogo_'.$img.'" value="1" '.$checkedon.'/>'.
1467: &mt('show').'</label>'."\n";
1468: }
1469:
1470: sub login_header_options {
1471: my ($img,$role,$defaults,$is_custom,$choices) = @_;
1472: my $output = '';
1473: if ((!$is_custom->{'textcol'}) || (!$is_custom->{'bgcol'})) {
1474: $output .= &mt('Text default(s):').'<br />';
1475: if (!$is_custom->{'textcol'}) {
1476: $output .= $choices->{'textcol'}.': '.$defaults->{'logintext'}{'textcol'}.
1477: ' ';
1478: }
1479: if (!$is_custom->{'bgcol'}) {
1480: $output .= $choices->{'bgcol'}.': '.
1481: '<span id="css_'.$role.'_font" style="background-color: '.
1482: $defaults->{'logintext'}{'bgcol'}.';"> </span>';
1483: }
1484: $output .= '<br />';
1485: }
1486: $output .='<br />';
1487: return $output;
1488: }
1489:
1490: sub login_text_colors {
1491: my ($img,$role,$logintext,$phase,$choices,$designs,$defaults) = @_;
1492: my $color_menu = '<table border="0"><tr>';
1493: foreach my $item (@{$logintext}) {
1494: $color_menu .= '<td align="center">'.$choices->{$item};
1495: my $color = $designs->{'logintext'}{$item} ? $designs->{'logintext'}{$item} : $defaults->{'logintext'}{$item};
1496: $color_menu .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1497: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1498: }
1499: $color_menu .= '</tr></table><br />';
1500: return $color_menu;
1501: }
1502:
1503: sub image_changes {
1504: my ($is_custom,$alt_text,$img_import,$showfile,$fullsize,$role,$img,$imgfile,$logincolors) = @_;
1505: my $output;
1506: if ($img eq 'login') {
1507: # suppress image for Log-in header
1508: } elsif (!$is_custom) {
1509: if ($img ne 'domlogo') {
1510: $output .= &mt('Default image:').'<br />';
1511: } else {
1512: $output .= &mt('Default in use:').'<br />';
1513: }
1514: }
1515: if ($img eq 'login') { # suppress image for Log-in header
1516: $output .= '<td>'.$logincolors;
1517: } else {
1518: if ($img_import) {
1519: $output .= '<input type="hidden" name="'.$role.'_import_'.$img.'" value="'.$imgfile.'" />';
1520: }
1521: $output .= '<a href="'.$fullsize.'" target="_blank"><img src="'.
1522: $showfile.'" alt="'.$alt_text.'" border="0" /></a></td>';
1523: if ($is_custom) {
1524: $output .= '<td>'.$logincolors.'<span class="LC_nobreak"><label>'.
1525: '<input type="checkbox" name="'.
1526: $role.'_del_'.$img.'" value="1" />'.&mt('Delete?').
1527: '</label> '.&mt('Replace:').'</span><br />';
1528: } else {
1529: $output .= '<td valign="middle">'.$logincolors.&mt('Upload:').'<br />';
1530: }
1531: }
1532: return $output;
1533: }
1534:
1535: sub print_quotas {
1536: my ($dom,$settings,$rowtotal,$action) = @_;
1537: my $context;
1538: if ($action eq 'quotas') {
1539: $context = 'tools';
1540: } else {
1541: $context = $action;
1542: }
1543: my ($datatable,$defaultquota,$authorquota,@usertools,@options,%validations);
1544: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1545: my $typecount = 0;
1546: my ($css_class,%titles);
1547: if ($context eq 'requestcourses') {
1548: @usertools = ('official','unofficial','community');
1549: @options =('norequest','approval','validate','autolimit');
1550: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
1551: %titles = &courserequest_titles();
1552: } elsif ($context eq 'requestauthor') {
1553: @usertools = ('author');
1554: @options = ('norequest','approval','automatic');
1555: %titles = &authorrequest_titles();
1556: } else {
1557: @usertools = ('aboutme','blog','webdav','portfolio');
1558: %titles = &tool_titles();
1559: }
1560: if (ref($types) eq 'ARRAY') {
1561: foreach my $type (@{$types}) {
1562: my ($currdefquota,$currauthorquota);
1563: unless (($context eq 'requestcourses') ||
1564: ($context eq 'requestauthor')) {
1565: if (ref($settings) eq 'HASH') {
1566: if (ref($settings->{defaultquota}) eq 'HASH') {
1567: $currdefquota = $settings->{defaultquota}->{$type};
1568: } else {
1569: $currdefquota = $settings->{$type};
1570: }
1571: if (ref($settings->{authorquota}) eq 'HASH') {
1572: $currauthorquota = $settings->{authorquota}->{$type};
1573: }
1574: }
1575: }
1576: if (defined($usertypes->{$type})) {
1577: $typecount ++;
1578: $css_class = $typecount%2?' class="LC_odd_row"':'';
1579: $datatable .= '<tr'.$css_class.'>'.
1580: '<td>'.$usertypes->{$type}.'</td>'.
1581: '<td class="LC_left_item">';
1582: if ($context eq 'requestcourses') {
1583: $datatable .= '<table><tr>';
1584: }
1585: my %cell;
1586: foreach my $item (@usertools) {
1587: if ($context eq 'requestcourses') {
1588: my ($curroption,$currlimit);
1589: if (ref($settings) eq 'HASH') {
1590: if (ref($settings->{$item}) eq 'HASH') {
1591: $curroption = $settings->{$item}->{$type};
1592: if ($curroption =~ /^autolimit=(\d*)$/) {
1593: $currlimit = $1;
1594: }
1595: }
1596: }
1597: if (!$curroption) {
1598: $curroption = 'norequest';
1599: }
1600: $datatable .= '<th>'.$titles{$item}.'</th>';
1601: foreach my $option (@options) {
1602: my $val = $option;
1603: if ($option eq 'norequest') {
1604: $val = 0;
1605: }
1606: if ($option eq 'validate') {
1607: my $canvalidate = 0;
1608: if (ref($validations{$item}) eq 'HASH') {
1609: if ($validations{$item}{$type}) {
1610: $canvalidate = 1;
1611: }
1612: }
1613: next if (!$canvalidate);
1614: }
1615: my $checked = '';
1616: if ($option eq $curroption) {
1617: $checked = ' checked="checked"';
1618: } elsif ($option eq 'autolimit') {
1619: if ($curroption =~ /^autolimit/) {
1620: $checked = ' checked="checked"';
1621: }
1622: }
1623: $cell{$item} .= '<span class="LC_nobreak"><label>'.
1624: '<input type="radio" name="crsreq_'.$item.
1625: '_'.$type.'" value="'.$val.'"'.$checked.' />'.
1626: $titles{$option}.'</label>';
1627: if ($option eq 'autolimit') {
1628: $cell{$item} .= ' <input type="text" name="crsreq_'.
1629: $item.'_limit_'.$type.'" size="1" '.
1630: 'value="'.$currlimit.'" />';
1631: }
1632: $cell{$item} .= '</span> ';
1633: if ($option eq 'autolimit') {
1634: $cell{$item} .= $titles{'unlimited'};
1635: }
1636: }
1637: } elsif ($context eq 'requestauthor') {
1638: my $curroption;
1639: if (ref($settings) eq 'HASH') {
1640: $curroption = $settings->{$type};
1641: }
1642: if (!$curroption) {
1643: $curroption = 'norequest';
1644: }
1645: foreach my $option (@options) {
1646: my $val = $option;
1647: if ($option eq 'norequest') {
1648: $val = 0;
1649: }
1650: my $checked = '';
1651: if ($option eq $curroption) {
1652: $checked = ' checked="checked"';
1653: }
1654: $datatable .= '<span class="LC_nobreak"><label>'.
1655: '<input type="radio" name="authorreq_'.$type.
1656: '" value="'.$val.'"'.$checked.' />'.
1657: $titles{$option}.'</label></span> ';
1658: }
1659: } else {
1660: my $checked = 'checked="checked" ';
1661: if (ref($settings) eq 'HASH') {
1662: if (ref($settings->{$item}) eq 'HASH') {
1663: if ($settings->{$item}->{$type} == 0) {
1664: $checked = '';
1665: } elsif ($settings->{$item}->{$type} == 1) {
1666: $checked = 'checked="checked" ';
1667: }
1668: }
1669: }
1670: $datatable .= '<span class="LC_nobreak"><label>'.
1671: '<input type="checkbox" name="'.$context.'_'.$item.
1672: '" value="'.$type.'" '.$checked.'/>'.$titles{$item}.
1673: '</label></span> ';
1674: }
1675: }
1676: if ($context eq 'requestcourses') {
1677: $datatable .= '</tr><tr>';
1678: foreach my $item (@usertools) {
1679: $datatable .= '<td style="vertical-align: top">'.$cell{$item}.'</td>';
1680: }
1681: $datatable .= '</tr></table>';
1682: }
1683: $datatable .= '</td>';
1684: unless (($context eq 'requestcourses') ||
1685: ($context eq 'requestauthor')) {
1686: $datatable .=
1687: '<td class="LC_right_item">'.
1688: '<span class="LC_nobreak">'.&mt('Portfolio').': '.
1689: '<input type="text" name="quota_'.$type.
1690: '" value="'.$currdefquota.
1691: '" size="5" /></span>'.(' ' x 2).
1692: '<span class="LC_nobreak">'.&mt('Authoring').': '.
1693: '<input type="text" name="authorquota_'.$type.
1694: '" value="'.$currauthorquota.
1695: '" size="5" /></span></td>';
1696: }
1697: $datatable .= '</tr>';
1698: }
1699: }
1700: }
1701: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1702: $defaultquota = '20';
1703: $authorquota = '500';
1704: if (ref($settings) eq 'HASH') {
1705: if (ref($settings->{'defaultquota'}) eq 'HASH') {
1706: $defaultquota = $settings->{'defaultquota'}->{'default'};
1707: } elsif (defined($settings->{'default'})) {
1708: $defaultquota = $settings->{'default'};
1709: }
1710: if (ref($settings->{'authorquota'}) eq 'HASH') {
1711: $authorquota = $settings->{'authorquota'}->{'default'};
1712: }
1713: }
1714: }
1715: $typecount ++;
1716: $css_class = $typecount%2?' class="LC_odd_row"':'';
1717: $datatable .= '<tr'.$css_class.'>'.
1718: '<td>'.$othertitle.'</td>'.
1719: '<td class="LC_left_item">';
1720: if ($context eq 'requestcourses') {
1721: $datatable .= '<table><tr>';
1722: }
1723: my %defcell;
1724: foreach my $item (@usertools) {
1725: if ($context eq 'requestcourses') {
1726: my ($curroption,$currlimit);
1727: if (ref($settings) eq 'HASH') {
1728: if (ref($settings->{$item}) eq 'HASH') {
1729: $curroption = $settings->{$item}->{'default'};
1730: if ($curroption =~ /^autolimit=(\d*)$/) {
1731: $currlimit = $1;
1732: }
1733: }
1734: }
1735: if (!$curroption) {
1736: $curroption = 'norequest';
1737: }
1738: $datatable .= '<th>'.$titles{$item}.'</th>';
1739: foreach my $option (@options) {
1740: my $val = $option;
1741: if ($option eq 'norequest') {
1742: $val = 0;
1743: }
1744: if ($option eq 'validate') {
1745: my $canvalidate = 0;
1746: if (ref($validations{$item}) eq 'HASH') {
1747: if ($validations{$item}{'default'}) {
1748: $canvalidate = 1;
1749: }
1750: }
1751: next if (!$canvalidate);
1752: }
1753: my $checked = '';
1754: if ($option eq $curroption) {
1755: $checked = ' checked="checked"';
1756: } elsif ($option eq 'autolimit') {
1757: if ($curroption =~ /^autolimit/) {
1758: $checked = ' checked="checked"';
1759: }
1760: }
1761: $defcell{$item} .= '<span class="LC_nobreak"><label>'.
1762: '<input type="radio" name="crsreq_'.$item.
1763: '_default" value="'.$val.'"'.$checked.' />'.
1764: $titles{$option}.'</label>';
1765: if ($option eq 'autolimit') {
1766: $defcell{$item} .= ' <input type="text" name="crsreq_'.
1767: $item.'_limit_default" size="1" '.
1768: 'value="'.$currlimit.'" />';
1769: }
1770: $defcell{$item} .= '</span> ';
1771: if ($option eq 'autolimit') {
1772: $defcell{$item} .= $titles{'unlimited'};
1773: }
1774: }
1775: } elsif ($context eq 'requestauthor') {
1776: my $curroption;
1777: if (ref($settings) eq 'HASH') {
1778: $curroption = $settings->{'default'};
1779: }
1780: if (!$curroption) {
1781: $curroption = 'norequest';
1782: }
1783: foreach my $option (@options) {
1784: my $val = $option;
1785: if ($option eq 'norequest') {
1786: $val = 0;
1787: }
1788: my $checked = '';
1789: if ($option eq $curroption) {
1790: $checked = ' checked="checked"';
1791: }
1792: $datatable .= '<span class="LC_nobreak"><label>'.
1793: '<input type="radio" name="authorreq_default"'.
1794: ' value="'.$val.'"'.$checked.' />'.
1795: $titles{$option}.'</label></span> ';
1796: }
1797: } else {
1798: my $checked = 'checked="checked" ';
1799: if (ref($settings) eq 'HASH') {
1800: if (ref($settings->{$item}) eq 'HASH') {
1801: if ($settings->{$item}->{'default'} == 0) {
1802: $checked = '';
1803: } elsif ($settings->{$item}->{'default'} == 1) {
1804: $checked = 'checked="checked" ';
1805: }
1806: }
1807: }
1808: $datatable .= '<span class="LC_nobreak"><label>'.
1809: '<input type="checkbox" name="'.$context.'_'.$item.
1810: '" value="default" '.$checked.'/>'.$titles{$item}.
1811: '</label></span> ';
1812: }
1813: }
1814: if ($context eq 'requestcourses') {
1815: $datatable .= '</tr><tr>';
1816: foreach my $item (@usertools) {
1817: $datatable .= '<td style="vertical-align: top">'.$defcell{$item}.'</td>';
1818: }
1819: $datatable .= '</tr></table>';
1820: }
1821: $datatable .= '</td>';
1822: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1823: $datatable .= '<td class="LC_right_item">'.
1824: '<span class="LC_nobreak">'.&mt('Portfolio').': '.
1825: '<input type="text" name="defaultquota" value="'.
1826: $defaultquota.'" size="5" /></span>'.(' ' x2).
1827: '<span class="LC_nobreak">'.&mt('Authoring').': '.
1828: '<input type="text" name="authorquota" value="'.
1829: $authorquota.'" size="5" /></span></td>';
1830: }
1831: $datatable .= '</tr>';
1832: $typecount ++;
1833: $css_class = $typecount%2?' class="LC_odd_row"':'';
1834: $datatable .= '<tr'.$css_class.'>'.
1835: '<td>'.&mt('LON-CAPA Advanced Users').'<br />';
1836: if ($context eq 'requestcourses') {
1837: $datatable .= &mt('(overrides affiliation, if set)').
1838: '</td>'.
1839: '<td class="LC_left_item">'.
1840: '<table><tr>';
1841: } else {
1842: $datatable .= &mt('(overrides affiliation, if checked)').
1843: '</td>'.
1844: '<td class="LC_left_item" colspan="2">'.
1845: '<br />';
1846: }
1847: my %advcell;
1848: foreach my $item (@usertools) {
1849: if ($context eq 'requestcourses') {
1850: my ($curroption,$currlimit);
1851: if (ref($settings) eq 'HASH') {
1852: if (ref($settings->{$item}) eq 'HASH') {
1853: $curroption = $settings->{$item}->{'_LC_adv'};
1854: if ($curroption =~ /^autolimit=(\d*)$/) {
1855: $currlimit = $1;
1856: }
1857: }
1858: }
1859: $datatable .= '<th>'.$titles{$item}.'</th>';
1860: my $checked = '';
1861: if ($curroption eq '') {
1862: $checked = ' checked="checked"';
1863: }
1864: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
1865: '<input type="radio" name="crsreq_'.$item.
1866: '__LC_adv" value=""'.$checked.' />'.
1867: &mt('No override set').'</label></span> ';
1868: foreach my $option (@options) {
1869: my $val = $option;
1870: if ($option eq 'norequest') {
1871: $val = 0;
1872: }
1873: if ($option eq 'validate') {
1874: my $canvalidate = 0;
1875: if (ref($validations{$item}) eq 'HASH') {
1876: if ($validations{$item}{'_LC_adv'}) {
1877: $canvalidate = 1;
1878: }
1879: }
1880: next if (!$canvalidate);
1881: }
1882: my $checked = '';
1883: if ($val eq $curroption) {
1884: $checked = ' checked="checked"';
1885: } elsif ($option eq 'autolimit') {
1886: if ($curroption =~ /^autolimit/) {
1887: $checked = ' checked="checked"';
1888: }
1889: }
1890: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
1891: '<input type="radio" name="crsreq_'.$item.
1892: '__LC_adv" value="'.$val.'"'.$checked.' />'.
1893: $titles{$option}.'</label>';
1894: if ($option eq 'autolimit') {
1895: $advcell{$item} .= ' <input type="text" name="crsreq_'.
1896: $item.'_limit__LC_adv" size="1" '.
1897: 'value="'.$currlimit.'" />';
1898: }
1899: $advcell{$item} .= '</span> ';
1900: if ($option eq 'autolimit') {
1901: $advcell{$item} .= $titles{'unlimited'};
1902: }
1903: }
1904: } elsif ($context eq 'requestauthor') {
1905: my $curroption;
1906: if (ref($settings) eq 'HASH') {
1907: $curroption = $settings->{'_LC_adv'};
1908: }
1909: my $checked = '';
1910: if ($curroption eq '') {
1911: $checked = ' checked="checked"';
1912: }
1913: $datatable .= '<span class="LC_nobreak"><label>'.
1914: '<input type="radio" name="authorreq__LC_adv"'.
1915: ' value=""'.$checked.' />'.
1916: &mt('No override set').'</label></span> ';
1917: foreach my $option (@options) {
1918: my $val = $option;
1919: if ($option eq 'norequest') {
1920: $val = 0;
1921: }
1922: my $checked = '';
1923: if ($val eq $curroption) {
1924: $checked = ' checked="checked"';
1925: }
1926: $datatable .= '<span class="LC_nobreak"><label>'.
1927: '<input type="radio" name="authorreq__LC_adv"'.
1928: ' value="'.$val.'"'.$checked.' />'.
1929: $titles{$option}.'</label></span> ';
1930: }
1931: } else {
1932: my $checked = 'checked="checked" ';
1933: if (ref($settings) eq 'HASH') {
1934: if (ref($settings->{$item}) eq 'HASH') {
1935: if ($settings->{$item}->{'_LC_adv'} == 0) {
1936: $checked = '';
1937: } elsif ($settings->{$item}->{'_LC_adv'} == 1) {
1938: $checked = 'checked="checked" ';
1939: }
1940: }
1941: }
1942: $datatable .= '<span class="LC_nobreak"><label>'.
1943: '<input type="checkbox" name="'.$context.'_'.$item.
1944: '" value="_LC_adv" '.$checked.'/>'.$titles{$item}.
1945: '</label></span> ';
1946: }
1947: }
1948: if ($context eq 'requestcourses') {
1949: $datatable .= '</tr><tr>';
1950: foreach my $item (@usertools) {
1951: $datatable .= '<td style="vertical-align: top">'.$advcell{$item}.'</td>';
1952: }
1953: $datatable .= '</tr></table>';
1954: }
1955: $datatable .= '</td></tr>';
1956: $$rowtotal += $typecount;
1957: return $datatable;
1958: }
1959:
1960: sub print_requestmail {
1961: my ($dom,$action,$settings,$rowtotal) = @_;
1962: my ($now,$datatable,%currapp,$rows);
1963: $now = time;
1964: if (ref($settings) eq 'HASH') {
1965: if (ref($settings->{'notify'}) eq 'HASH') {
1966: if ($settings->{'notify'}{'approval'} ne '') {
1967: map {$currapp{$_}=1;} split(/,/,$settings->{'notify'}{'approval'});
1968: }
1969: }
1970: }
1971: my $numinrow = 2;
1972: my $css_class = 'class="LC_odd_row"';
1973: my $text;
1974: if ($action eq 'requestcourses') {
1975: $text = &mt('Receive notification of course requests requiring approval');
1976: } else {
1977: $text = &mt('Receive notification of authoring space requests requiring approval')
1978: }
1979: $datatable = '<tr '.$css_class.'>'.
1980: ' <td>'.$text.'</td>'.
1981: ' <td class="LC_left_item">';
1982: my ($numdc,$table,$rows) = &active_dc_picker($dom,$numinrow,'checkbox',
1983: 'reqapprovalnotify',%currapp);
1984: if ($numdc > 0) {
1985: $datatable .= $table;
1986: } else {
1987: $datatable .= &mt('There are no active Domain Coordinators');
1988: }
1989: $datatable .='</td></tr>';
1990: $$rowtotal += $rows;
1991: return $datatable;
1992: }
1993:
1994: sub print_autoenroll {
1995: my ($dom,$settings,$rowtotal) = @_;
1996: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
1997: my ($defdom,$runon,$runoff,$coownerson,$coownersoff);
1998: if (ref($settings) eq 'HASH') {
1999: if (exists($settings->{'run'})) {
2000: if ($settings->{'run'} eq '0') {
2001: $runoff = ' checked="checked" ';
2002: $runon = ' ';
2003: } else {
2004: $runon = ' checked="checked" ';
2005: $runoff = ' ';
2006: }
2007: } else {
2008: if ($autorun) {
2009: $runon = ' checked="checked" ';
2010: $runoff = ' ';
2011: } else {
2012: $runoff = ' checked="checked" ';
2013: $runon = ' ';
2014: }
2015: }
2016: if (exists($settings->{'co-owners'})) {
2017: if ($settings->{'co-owners'} eq '0') {
2018: $coownersoff = ' checked="checked" ';
2019: $coownerson = ' ';
2020: } else {
2021: $coownerson = ' checked="checked" ';
2022: $coownersoff = ' ';
2023: }
2024: } else {
2025: $coownersoff = ' checked="checked" ';
2026: $coownerson = ' ';
2027: }
2028: if (exists($settings->{'sender_domain'})) {
2029: $defdom = $settings->{'sender_domain'};
2030: }
2031: } else {
2032: if ($autorun) {
2033: $runon = ' checked="checked" ';
2034: $runoff = ' ';
2035: } else {
2036: $runoff = ' checked="checked" ';
2037: $runon = ' ';
2038: }
2039: }
2040: my $domform = &Apache::loncommon::select_dom_form($defdom,'sender_domain',1);
2041: my $notif_sender;
2042: if (ref($settings) eq 'HASH') {
2043: $notif_sender = $settings->{'sender_uname'};
2044: }
2045: my $datatable='<tr class="LC_odd_row">'.
2046: '<td>'.&mt('Auto-enrollment active?').'</td>'.
2047: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2048: '<input type="radio" name="autoenroll_run"'.
2049: $runon.' value="1" />'.&mt('Yes').'</label> '.
2050: '<label><input type="radio" name="autoenroll_run"'.
2051: $runoff.' value="0" />'.&mt('No').'</label></span></td>'.
2052: '</tr><tr>'.
2053: '<td>'.&mt('Notification messages - sender').
2054: '</td><td class="LC_right_item"><span class="LC_nobreak">'.
2055: &mt('username').': '.
2056: '<input type="text" name="sender_uname" value="'.
2057: $notif_sender.'" size="10" /> '.&mt('domain').
2058: ': '.$domform.'</span></td></tr>'.
2059: '<tr class="LC_odd_row">'.
2060: '<td>'.&mt('Automatically assign co-ownership').'</td>'.
2061: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2062: '<input type="radio" name="autoassign_coowners"'.
2063: $coownerson.' value="1" />'.&mt('Yes').'</label> '.
2064: '<label><input type="radio" name="autoassign_coowners"'.
2065: $coownersoff.' value="0" />'.&mt('No').'</label></span></td>'.
2066: '</tr>';
2067: $$rowtotal += 3;
2068: return $datatable;
2069: }
2070:
2071: sub print_autoupdate {
2072: my ($position,$dom,$settings,$rowtotal) = @_;
2073: my $datatable;
2074: if ($position eq 'top') {
2075: my $updateon = ' ';
2076: my $updateoff = ' checked="checked" ';
2077: my $classlistson = ' ';
2078: my $classlistsoff = ' checked="checked" ';
2079: if (ref($settings) eq 'HASH') {
2080: if ($settings->{'run'} eq '1') {
2081: $updateon = $updateoff;
2082: $updateoff = ' ';
2083: }
2084: if ($settings->{'classlists'} eq '1') {
2085: $classlistson = $classlistsoff;
2086: $classlistsoff = ' ';
2087: }
2088: }
2089: my %title = (
2090: run => 'Auto-update active?',
2091: classlists => 'Update information in classlists?',
2092: );
2093: $datatable = '<tr class="LC_odd_row">'.
2094: '<td>'.&mt($title{'run'}).'</td>'.
2095: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2096: '<input type="radio" name="autoupdate_run"'.
2097: $updateon.' value="1" />'.&mt('Yes').'</label> '.
2098: '<label><input type="radio" name="autoupdate_run"'.
2099: $updateoff.'value="0" />'.&mt('No').'</label></span></td>'.
2100: '</tr><tr>'.
2101: '<td>'.&mt($title{'classlists'}).'</td>'.
2102: '<td class="LC_right_item"><span class="LC_nobreak">'.
2103: '<label><input type="radio" name="classlists"'.
2104: $classlistson.' value="1" />'.&mt('Yes').'</label> '.
2105: '<label><input type="radio" name="classlists"'.
2106: $classlistsoff.'value="0" />'.&mt('No').'</label></span></td>'.
2107: '</tr>';
2108: $$rowtotal += 2;
2109: } elsif ($position eq 'middle') {
2110: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
2111: my $numinrow = 3;
2112: my $locknamesettings;
2113: $datatable .= &insttypes_row($settings,$types,$usertypes,
2114: $dom,$numinrow,$othertitle,
2115: 'lockablenames');
2116: $$rowtotal ++;
2117: } else {
2118: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
2119: my @fields = ('lastname','firstname','middlename','generation',
2120: 'permanentemail','id');
2121: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
2122: my $numrows = 0;
2123: if (ref($types) eq 'ARRAY') {
2124: if (@{$types} > 0) {
2125: $datatable =
2126: &usertype_update_row($settings,$usertypes,\%fieldtitles,
2127: \@fields,$types,\$numrows);
2128: $$rowtotal += @{$types};
2129: }
2130: }
2131: $datatable .=
2132: &usertype_update_row($settings,{'default' => $othertitle},
2133: \%fieldtitles,\@fields,['default'],
2134: \$numrows);
2135: $$rowtotal ++;
2136: }
2137: return $datatable;
2138: }
2139:
2140: sub print_autocreate {
2141: my ($dom,$settings,$rowtotal) = @_;
2142: my (%createon,%createoff,%currhash);
2143: my @types = ('xml','req');
2144: if (ref($settings) eq 'HASH') {
2145: foreach my $item (@types) {
2146: $createoff{$item} = ' checked="checked" ';
2147: $createon{$item} = ' ';
2148: if (exists($settings->{$item})) {
2149: if ($settings->{$item}) {
2150: $createon{$item} = ' checked="checked" ';
2151: $createoff{$item} = ' ';
2152: }
2153: }
2154: }
2155: if ($settings->{'xmldc'} ne '') {
2156: $currhash{$settings->{'xmldc'}} = 1;
2157: }
2158: } else {
2159: foreach my $item (@types) {
2160: $createoff{$item} = ' checked="checked" ';
2161: $createon{$item} = ' ';
2162: }
2163: }
2164: $$rowtotal += 2;
2165: my $numinrow = 2;
2166: my $datatable='<tr class="LC_odd_row">'.
2167: '<td>'.&mt('Create pending official courses from XML files').'</td>'.
2168: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2169: '<input type="radio" name="autocreate_xml"'.
2170: $createon{'xml'}.' value="1" />'.&mt('Yes').'</label> '.
2171: '<label><input type="radio" name="autocreate_xml"'.
2172: $createoff{'xml'}.' value="0" />'.&mt('No').'</label></span>'.
2173: '</td></tr><tr>'.
2174: '<td>'.&mt('Create pending requests for official courses (if validated)').'</td>'.
2175: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2176: '<input type="radio" name="autocreate_req"'.
2177: $createon{'req'}.' value="1" />'.&mt('Yes').'</label> '.
2178: '<label><input type="radio" name="autocreate_req"'.
2179: $createoff{'req'}.' value="0" />'.&mt('No').'</label></span>';
2180: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
2181: 'autocreate_xmldc',%currhash);
2182: if ($numdc > 1) {
2183: $datatable .= '</td></tr><tr class="LC_odd_row"><td>'.
2184: &mt('Course creation processed as: (choose Dom. Coord.)').
2185: '</td><td class="LC_left_item">'.$dctable.'</td></tr>';
2186: } else {
2187: $datatable .= $dctable.'</td></tr>';
2188: }
2189: $$rowtotal += $rows;
2190: return $datatable;
2191: }
2192:
2193: sub print_directorysrch {
2194: my ($dom,$settings,$rowtotal) = @_;
2195: my $srchon = ' ';
2196: my $srchoff = ' checked="checked" ';
2197: my ($exacton,$containson,$beginson);
2198: my $localon = ' ';
2199: my $localoff = ' checked="checked" ';
2200: if (ref($settings) eq 'HASH') {
2201: if ($settings->{'available'} eq '1') {
2202: $srchon = $srchoff;
2203: $srchoff = ' ';
2204: }
2205: if ($settings->{'localonly'} eq '1') {
2206: $localon = $localoff;
2207: $localoff = ' ';
2208: }
2209: if (ref($settings->{'searchtypes'}) eq 'ARRAY') {
2210: foreach my $type (@{$settings->{'searchtypes'}}) {
2211: if ($type eq 'exact') {
2212: $exacton = ' checked="checked" ';
2213: } elsif ($type eq 'contains') {
2214: $containson = ' checked="checked" ';
2215: } elsif ($type eq 'begins') {
2216: $beginson = ' checked="checked" ';
2217: }
2218: }
2219: } else {
2220: if ($settings->{'searchtypes'} eq 'exact') {
2221: $exacton = ' checked="checked" ';
2222: } elsif ($settings->{'searchtypes'} eq 'contains') {
2223: $containson = ' checked="checked" ';
2224: } elsif ($settings->{'searchtypes'} eq 'specify') {
2225: $exacton = ' checked="checked" ';
2226: $containson = ' checked="checked" ';
2227: }
2228: }
2229: }
2230: my ($searchtitles,$titleorder) = &sorted_searchtitles();
2231: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
2232:
2233: my $numinrow = 4;
2234: my $cansrchrow = 0;
2235: my $datatable='<tr class="LC_odd_row">'.
2236: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Directory search available?').'</span></td>'.
2237: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2238: '<input type="radio" name="dirsrch_available"'.
2239: $srchon.' value="1" />'.&mt('Yes').'</label> '.
2240: '<label><input type="radio" name="dirsrch_available"'.
2241: $srchoff.' value="0" />'.&mt('No').'</label></span></td>'.
2242: '</tr><tr>'.
2243: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search?').'</span></td>'.
2244: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2245: '<input type="radio" name="dirsrch_localonly"'.
2246: $localoff.' value="0" />'.&mt('Yes').'</label> '.
2247: '<label><input type="radio" name="dirsrch_localonly"'.
2248: $localon.' value="1" />'.&mt('No').'</label></span></td>'.
2249: '</tr>';
2250: $$rowtotal += 2;
2251: if (ref($usertypes) eq 'HASH') {
2252: if (keys(%{$usertypes}) > 0) {
2253: $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
2254: $numinrow,$othertitle,'cansearch');
2255: $cansrchrow = 1;
2256: }
2257: }
2258: if ($cansrchrow) {
2259: $$rowtotal ++;
2260: $datatable .= '<tr>';
2261: } else {
2262: $datatable .= '<tr class="LC_odd_row">';
2263: }
2264: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Supported search methods').
2265: '</span></td><td class="LC_left_item" colspan="2"><table><tr>';
2266: foreach my $title (@{$titleorder}) {
2267: if (defined($searchtitles->{$title})) {
2268: my $check = ' ';
2269: if (ref($settings) eq 'HASH') {
2270: if (ref($settings->{'searchby'}) eq 'ARRAY') {
2271: if (grep(/^\Q$title\E$/,@{$settings->{'searchby'}})) {
2272: $check = ' checked="checked" ';
2273: }
2274: }
2275: }
2276: $datatable .= '<td class="LC_left_item">'.
2277: '<span class="LC_nobreak"><label>'.
2278: '<input type="checkbox" name="searchby" '.
2279: 'value="'.$title.'"'.$check.'/>'.
2280: $searchtitles->{$title}.'</label></span></td>';
2281: }
2282: }
2283: $datatable .= '</tr></table></td></tr>';
2284: $$rowtotal ++;
2285: if ($cansrchrow) {
2286: $datatable .= '<tr class="LC_odd_row">';
2287: } else {
2288: $datatable .= '<tr>';
2289: }
2290: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Search latitude').'</span></td>'.
2291: '<td class="LC_left_item" colspan="2">'.
2292: '<span class="LC_nobreak"><label>'.
2293: '<input type="checkbox" name="searchtypes" '.
2294: $exacton.' value="exact" />'.&mt('Exact match').
2295: '</label> '.
2296: '<label><input type="checkbox" name="searchtypes" '.
2297: $beginson.' value="begins" />'.&mt('Begins with').
2298: '</label> '.
2299: '<label><input type="checkbox" name="searchtypes" '.
2300: $containson.' value="contains" />'.&mt('Contains').
2301: '</label></span></td></tr>';
2302: $$rowtotal ++;
2303: return $datatable;
2304: }
2305:
2306: sub print_contacts {
2307: my ($dom,$settings,$rowtotal) = @_;
2308: my $datatable;
2309: my @contacts = ('adminemail','supportemail');
2310: my (%checked,%to,%otheremails,%bccemails);
2311: my @mailings = ('errormail','packagesmail','lonstatusmail','helpdeskmail',
2312: 'requestsmail','updatesmail');
2313: foreach my $type (@mailings) {
2314: $otheremails{$type} = '';
2315: }
2316: $bccemails{'helpdeskmail'} = '';
2317: if (ref($settings) eq 'HASH') {
2318: foreach my $item (@contacts) {
2319: if (exists($settings->{$item})) {
2320: $to{$item} = $settings->{$item};
2321: }
2322: }
2323: foreach my $type (@mailings) {
2324: if (exists($settings->{$type})) {
2325: if (ref($settings->{$type}) eq 'HASH') {
2326: foreach my $item (@contacts) {
2327: if ($settings->{$type}{$item}) {
2328: $checked{$type}{$item} = ' checked="checked" ';
2329: }
2330: }
2331: $otheremails{$type} = $settings->{$type}{'others'};
2332: if ($type eq 'helpdeskmail') {
2333: $bccemails{$type} = $settings->{$type}{'bcc'};
2334: }
2335: }
2336: } elsif ($type eq 'lonstatusmail') {
2337: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
2338: }
2339: }
2340: } else {
2341: $to{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
2342: $to{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
2343: $checked{'errormail'}{'adminemail'} = ' checked="checked" ';
2344: $checked{'packagesmail'}{'adminemail'} = ' checked="checked" ';
2345: $checked{'helpdeskmail'}{'supportemail'} = ' checked="checked" ';
2346: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
2347: $checked{'requestsmail'}{'adminemail'} = ' checked="checked" ';
2348: $checked{'updatesmail'}{'adminemail'} = ' checked="checked" ';
2349: }
2350: my ($titles,$short_titles) = &contact_titles();
2351: my $rownum = 0;
2352: my $css_class;
2353: foreach my $item (@contacts) {
2354: $rownum ++;
2355: $css_class = $rownum%2?' class="LC_odd_row"':'';
2356: $datatable .= '<tr'.$css_class.'>'.
2357: '<td><span class="LC_nobreak">'.$titles->{$item}.
2358: '</span></td><td class="LC_right_item">'.
2359: '<input type="text" name="'.$item.'" value="'.
2360: $to{$item}.'" /></td></tr>';
2361: }
2362: foreach my $type (@mailings) {
2363: $rownum ++;
2364: $css_class = $rownum%2?' class="LC_odd_row"':'';
2365: $datatable .= '<tr'.$css_class.'>'.
2366: '<td><span class="LC_nobreak">'.
2367: $titles->{$type}.': </span></td>'.
2368: '<td class="LC_left_item">'.
2369: '<span class="LC_nobreak">';
2370: foreach my $item (@contacts) {
2371: $datatable .= '<label>'.
2372: '<input type="checkbox" name="'.$type.'"'.
2373: $checked{$type}{$item}.
2374: ' value="'.$item.'" />'.$short_titles->{$item}.
2375: '</label> ';
2376: }
2377: $datatable .= '</span><br />'.&mt('Others').': '.
2378: '<input type="text" name="'.$type.'_others" '.
2379: 'value="'.$otheremails{$type}.'" />';
2380: if ($type eq 'helpdeskmail') {
2381: $datatable .= '<br />'.&mt('Bcc:').(' 'x6).
2382: '<input type="text" name="'.$type.'_bcc" '.
2383: 'value="'.$bccemails{$type}.'" />';
2384: }
2385: $datatable .= '</td></tr>'."\n";
2386: }
2387: $$rowtotal += $rownum;
2388: return $datatable;
2389: }
2390:
2391: sub print_helpsettings {
2392: my ($dom,$confname,$settings,$rowtotal) = @_;
2393: my ($datatable,$itemcount);
2394: $itemcount = 1;
2395: my (%choices,%defaultchecked,@toggles);
2396: $choices{'submitbugs'} = &mt('Display link to: [_1]?',
2397: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
2398: &mt('LON-CAPA bug tracker'),600,500));
2399: %defaultchecked = ('submitbugs' => 'on');
2400: @toggles = ('submitbugs',);
2401:
2402: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
2403: \%choices,$itemcount);
2404: return $datatable;
2405: }
2406:
2407: sub radiobutton_prefs {
2408: my ($settings,$toggles,$defaultchecked,$choices,$itemcount,$onclick,
2409: $additional) = @_;
2410: return unless ((ref($toggles) eq 'ARRAY') && (ref($defaultchecked) eq 'HASH') &&
2411: (ref($choices) eq 'HASH'));
2412:
2413: my (%checkedon,%checkedoff,$datatable,$css_class);
2414:
2415: foreach my $item (@{$toggles}) {
2416: if ($defaultchecked->{$item} eq 'on') {
2417: $checkedon{$item} = ' checked="checked" ';
2418: $checkedoff{$item} = ' ';
2419: } elsif ($defaultchecked->{$item} eq 'off') {
2420: $checkedoff{$item} = ' checked="checked" ';
2421: $checkedon{$item} = ' ';
2422: }
2423: }
2424: if (ref($settings) eq 'HASH') {
2425: foreach my $item (@{$toggles}) {
2426: if ($settings->{$item} eq '1') {
2427: $checkedon{$item} = ' checked="checked" ';
2428: $checkedoff{$item} = ' ';
2429: } elsif ($settings->{$item} eq '0') {
2430: $checkedoff{$item} = ' checked="checked" ';
2431: $checkedon{$item} = ' ';
2432: }
2433: }
2434: }
2435: if ($onclick) {
2436: $onclick = ' onclick="'.$onclick.'"';
2437: }
2438: foreach my $item (@{$toggles}) {
2439: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2440: $datatable .=
2441: '<tr'.$css_class.'><td valign="top">'.
2442: '<span class="LC_nobreak">'.$choices->{$item}.
2443: '</span></td>'.
2444: '<td class="LC_right_item"><span class="LC_nobreak">'.
2445: '<label><input type="radio" name="'.
2446: $item.'" '.$checkedon{$item}.' value="1"'.$onclick.' />'.&mt('Yes').
2447: '</label> <label><input type="radio" name="'.$item.'" '.
2448: $checkedoff{$item}.' value="0"'.$onclick.' />'.&mt('No').'</label>'.
2449: '</span>'.$additional.
2450: '</td>'.
2451: '</tr>';
2452: $itemcount ++;
2453: }
2454: return ($datatable,$itemcount);
2455: }
2456:
2457: sub print_coursedefaults {
2458: my ($position,$dom,$settings,$rowtotal) = @_;
2459: my ($css_class,$datatable,%checkedon,%checkedoff,%defaultchecked,@toggles);
2460: my $itemcount = 1;
2461: my %choices = &Apache::lonlocal::texthash (
2462: canuse_pdfforms => 'Course/Community users can create/upload PDF forms',
2463: uploadquota => 'Default quota for files uploaded directly to course/community using Course Editor (MB)',
2464: anonsurvey_threshold => 'Responder count needed before showing submissions for anonymous surveys',
2465: coursecredits => 'Credits can be specified for courses',
2466: );
2467: my %staticdefaults = (
2468: anonsurvey_threshold => 10,
2469: uploadquota => 500,
2470: );
2471: if ($position eq 'top') {
2472: %defaultchecked = ('canuse_pdfforms' => 'off');
2473: @toggles = ('canuse_pdfforms');
2474: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
2475: \%choices,$itemcount);
2476: } else {
2477: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
2478: my ($currdefresponder,$def_official_credits,$def_unofficial_credits,%curruploadquota);
2479: my $currusecredits = 0;
2480: my @types = ('official','unofficial','community');
2481: if (ref($settings) eq 'HASH') {
2482: $currdefresponder = $settings->{'anonsurvey_threshold'};
2483: if (ref($settings->{'uploadquota'}) eq 'HASH') {
2484: foreach my $type (keys(%{$settings->{'uploadquota'}})) {
2485: $curruploadquota{$type} = $settings->{'uploadquota'}{$type};
2486: }
2487: }
2488: if (ref($settings->{'coursecredits'}) eq 'HASH') {
2489: $def_official_credits = $settings->{'coursecredits'}->{'official'};
2490: $def_unofficial_credits = $settings->{'coursecredits'}->{'unofficial'};
2491: if (($def_official_credits ne '') || ($def_unofficial_credits ne '')) {
2492: $currusecredits = 1;
2493: }
2494: }
2495: }
2496: if (!$currdefresponder) {
2497: $currdefresponder = $staticdefaults{'anonsurvey_threshold'};
2498: } elsif ($currdefresponder < 1) {
2499: $currdefresponder = 1;
2500: }
2501: foreach my $type (@types) {
2502: if ($curruploadquota{$type} eq '') {
2503: $curruploadquota{$type} = $staticdefaults{'uploadquota'};
2504: }
2505: }
2506: $datatable .=
2507: '<tr'.$css_class.'><td><span class="LC_nobreak">'.
2508: $choices{'anonsurvey_threshold'}.
2509: '</span></td>'.
2510: '<td class="LC_right_item"><span class="LC_nobreak">'.
2511: '<input type="text" name="anonsurvey_threshold"'.
2512: ' value="'.$currdefresponder.'" size="5" /></span>'.
2513: '</td></tr>'."\n".
2514: '<tr><td><span class="LC_nobreak">'.
2515: $choices{'uploadquota'}.
2516: '</span></td>'.
2517: '<td align="right" class="LC_right_item">'.
2518: '<table><tr>';
2519: foreach my $type (@types) {
2520: $datatable .= '<td align="center">'.&mt($type).'<br />'.
2521: '<input type="text" name="uploadquota_'.$type.'"'.
2522: ' value="'.$curruploadquota{$type}.'" size="5" /></td>';
2523: }
2524: $datatable .= '</tr></table></td></tr>'."\n";
2525: $itemcount += 2;
2526: my $onclick = 'toggleCredits(this.form);';
2527: my $display = 'none';
2528: if ($currusecredits) {
2529: $display = 'block';
2530: }
2531: my $additional = '<div id="credits" style="display: '.$display.'">'.
2532: '<span class="LC_nobreak">'.
2533: &mt('Default credits for official courses [_1]',
2534: '<input type="text" name="official_credits" value="'.
2535: $def_official_credits.'" size="3" />').
2536: '</span><br />'.
2537: '<span class="LC_nobreak">'.
2538: &mt('Default credits for unofficial courses [_1]',
2539: '<input type="text" name="unofficial_credits" value="'.
2540: $def_unofficial_credits.'" size="3" />').
2541: '</span></div>'."\n";
2542: %defaultchecked = ('coursecredits' => 'off');
2543: @toggles = ('coursecredits');
2544: my $current = {
2545: 'coursecredits' => $currusecredits,
2546: };
2547: (my $table,$itemcount) =
2548: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
2549: \%choices,$itemcount,$onclick,$additional);
2550: $datatable .= $table;
2551: }
2552: $$rowtotal += $itemcount;
2553: return $datatable;
2554: }
2555:
2556: sub print_usersessions {
2557: my ($position,$dom,$settings,$rowtotal) = @_;
2558: my ($css_class,$datatable,%checked,%choices);
2559: my (%by_ip,%by_location,@intdoms);
2560: &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
2561:
2562: my @alldoms = &Apache::lonnet::all_domains();
2563: my %serverhomes = %Apache::lonnet::serverhomeIDs;
2564: my %servers = &Apache::lonnet::internet_dom_servers($dom);
2565: my %altids = &id_for_thisdom(%servers);
2566: my $itemcount = 1;
2567: if ($position eq 'top') {
2568: if (keys(%serverhomes) > 1) {
2569: my %spareid = ¤t_offloads_to($dom,$settings,\%servers);
2570: $datatable .= &spares_row($dom,\%servers,\%spareid,\%serverhomes,\%altids,$rowtotal);
2571: } else {
2572: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
2573: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one server.');
2574: }
2575: } else {
2576: if (keys(%by_location) == 0) {
2577: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
2578: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one institution.');
2579: } else {
2580: my %lt = &usersession_titles();
2581: my $numinrow = 5;
2582: my $prefix;
2583: my @types;
2584: if ($position eq 'bottom') {
2585: $prefix = 'remote';
2586: @types = ('version','excludedomain','includedomain');
2587: } else {
2588: $prefix = 'hosted';
2589: @types = ('excludedomain','includedomain');
2590: }
2591: my (%current,%checkedon,%checkedoff);
2592: my @lcversions = &Apache::lonnet::all_loncaparevs();
2593: my @locations = sort(keys(%by_location));
2594: foreach my $type (@types) {
2595: $checkedon{$type} = '';
2596: $checkedoff{$type} = ' checked="checked"';
2597: }
2598: if (ref($settings) eq 'HASH') {
2599: if (ref($settings->{$prefix}) eq 'HASH') {
2600: foreach my $key (keys(%{$settings->{$prefix}})) {
2601: $current{$key} = $settings->{$prefix}{$key};
2602: if ($key eq 'version') {
2603: if ($current{$key} ne '') {
2604: $checkedon{$key} = ' checked="checked"';
2605: $checkedoff{$key} = '';
2606: }
2607: } elsif (ref($current{$key}) eq 'ARRAY') {
2608: $checkedon{$key} = ' checked="checked"';
2609: $checkedoff{$key} = '';
2610: }
2611: }
2612: }
2613: }
2614: foreach my $type (@types) {
2615: next if ($type ne 'version' && !@locations);
2616: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
2617: $datatable .= '<tr'.$css_class.'>
2618: <td><span class="LC_nobreak">'.$lt{$type}.'</span><br />
2619: <span class="LC_nobreak">
2620: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedoff{$type}.' value="0" />'.&mt('Not in use').'</label>
2621: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedon{$type}.' value="1" />'.&mt('In use').'</label></span></td><td>';
2622: if ($type eq 'version') {
2623: my $selector = '<select name="'.$prefix.'_version">';
2624: foreach my $version (@lcversions) {
2625: my $selected = '';
2626: if ($current{'version'} eq $version) {
2627: $selected = ' selected="selected"';
2628: }
2629: $selector .= ' <option value="'.$version.'"'.
2630: $selected.'>'.$version.'</option>';
2631: }
2632: $selector .= '</select> ';
2633: $datatable .= &mt('remote server must be version: [_1] or later',$selector);
2634: } else {
2635: $datatable.= '<div><input type="button" value="'.&mt('check all').'" '.
2636: 'onclick="javascript:checkAll(document.display.'.$prefix.'_'.$type.')"'.
2637: ' />'.(' 'x2).
2638: '<input type="button" value="'.&mt('uncheck all').'" '.
2639: 'onclick="javascript:uncheckAll(document.display.'.$prefix.'_'.$type.')" />'.
2640: "\n".
2641: '</div><div><table>';
2642: my $rem;
2643: for (my $i=0; $i<@locations; $i++) {
2644: my ($showloc,$value,$checkedtype);
2645: if (ref($by_location{$locations[$i]}) eq 'ARRAY') {
2646: my $ip = $by_location{$locations[$i]}->[0];
2647: if (ref($by_ip{$ip}) eq 'ARRAY') {
2648: $value = join(':',@{$by_ip{$ip}});
2649: $showloc = join(', ',@{$by_ip{$ip}});
2650: if (ref($current{$type}) eq 'ARRAY') {
2651: foreach my $loc (@{$by_ip{$ip}}) {
2652: if (grep(/^\Q$loc\E$/,@{$current{$type}})) {
2653: $checkedtype = ' checked="checked"';
2654: last;
2655: }
2656: }
2657: }
2658: }
2659: }
2660: $rem = $i%($numinrow);
2661: if ($rem == 0) {
2662: if ($i > 0) {
2663: $datatable .= '</tr>';
2664: }
2665: $datatable .= '<tr>';
2666: }
2667: $datatable .= '<td class="LC_left_item">'.
2668: '<span class="LC_nobreak"><label>'.
2669: '<input type="checkbox" name="'.$prefix.'_'.$type.
2670: '" value="'.$value.'"'.$checkedtype.' />'.$showloc.
2671: '</label></span></td>';
2672: }
2673: $rem = @locations%($numinrow);
2674: my $colsleft = $numinrow - $rem;
2675: if ($colsleft > 1 ) {
2676: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
2677: ' </td>';
2678: } elsif ($colsleft == 1) {
2679: $datatable .= '<td class="LC_left_item"> </td>';
2680: }
2681: $datatable .= '</tr></table>';
2682: }
2683: $datatable .= '</td></tr>';
2684: $itemcount ++;
2685: }
2686: }
2687: }
2688: $$rowtotal += $itemcount;
2689: return $datatable;
2690: }
2691:
2692: sub build_location_hashes {
2693: my ($intdoms,$by_ip,$by_location) = @_;
2694: return unless((ref($intdoms) eq 'ARRAY') && (ref($by_ip) eq 'HASH') &&
2695: (ref($by_location) eq 'HASH'));
2696: my %iphost = &Apache::lonnet::get_iphost();
2697: my $primary_id = &Apache::lonnet::domain($env{'request.role.domain'},'primary');
2698: my $primary_ip = &Apache::lonnet::get_host_ip($primary_id);
2699: if (ref($iphost{$primary_ip}) eq 'ARRAY') {
2700: foreach my $id (@{$iphost{$primary_ip}}) {
2701: my $intdom = &Apache::lonnet::internet_dom($id);
2702: unless(grep(/^\Q$intdom\E$/,@{$intdoms})) {
2703: push(@{$intdoms},$intdom);
2704: }
2705: }
2706: }
2707: foreach my $ip (keys(%iphost)) {
2708: if (ref($iphost{$ip}) eq 'ARRAY') {
2709: foreach my $id (@{$iphost{$ip}}) {
2710: my $location = &Apache::lonnet::internet_dom($id);
2711: if ($location) {
2712: next if (grep(/^\Q$location\E$/,@{$intdoms}));
2713: if (ref($by_ip->{$ip}) eq 'ARRAY') {
2714: unless(grep(/^\Q$location\E$/,@{$by_ip->{$ip}})) {
2715: push(@{$by_ip->{$ip}},$location);
2716: }
2717: } else {
2718: $by_ip->{$ip} = [$location];
2719: }
2720: }
2721: }
2722: }
2723: }
2724: foreach my $ip (sort(keys(%{$by_ip}))) {
2725: if (ref($by_ip->{$ip}) eq 'ARRAY') {
2726: @{$by_ip->{$ip}} = sort(@{$by_ip->{$ip}});
2727: my $first = $by_ip->{$ip}->[0];
2728: if (ref($by_location->{$first}) eq 'ARRAY') {
2729: unless (grep(/^\Q$ip\E$/,@{$by_location->{$first}})) {
2730: push(@{$by_location->{$first}},$ip);
2731: }
2732: } else {
2733: $by_location->{$first} = [$ip];
2734: }
2735: }
2736: }
2737: return;
2738: }
2739:
2740: sub current_offloads_to {
2741: my ($dom,$settings,$servers) = @_;
2742: my (%spareid,%otherdomconfigs);
2743: if (ref($servers) eq 'HASH') {
2744: foreach my $lonhost (sort(keys(%{$servers}))) {
2745: my $gotspares;
2746: if (ref($settings) eq 'HASH') {
2747: if (ref($settings->{'spares'}) eq 'HASH') {
2748: if (ref($settings->{'spares'}{$lonhost}) eq 'HASH') {
2749: $spareid{$lonhost}{'primary'} = $settings->{'spares'}{$lonhost}{'primary'};
2750: $spareid{$lonhost}{'default'} = $settings->{'spares'}{$lonhost}{'default'};
2751: $gotspares = 1;
2752: }
2753: }
2754: }
2755: unless ($gotspares) {
2756: my $gotspares;
2757: my $serverhomeID =
2758: &Apache::lonnet::get_server_homeID($servers->{$lonhost});
2759: my $serverhomedom =
2760: &Apache::lonnet::host_domain($serverhomeID);
2761: if ($serverhomedom ne $dom) {
2762: if (ref($otherdomconfigs{$serverhomedom} eq 'HASH')) {
2763: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
2764: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
2765: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
2766: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
2767: $gotspares = 1;
2768: }
2769: }
2770: } else {
2771: $otherdomconfigs{$serverhomedom} =
2772: &Apache::lonnet::get_dom('configuration',['usersessions'],$serverhomedom);
2773: if (ref($otherdomconfigs{$serverhomedom}) eq 'HASH') {
2774: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
2775: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
2776: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{$lonhost}) eq 'HASH') {
2777: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
2778: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
2779: $gotspares = 1;
2780: }
2781: }
2782: }
2783: }
2784: }
2785: }
2786: }
2787: unless ($gotspares) {
2788: if ($lonhost eq $Apache::lonnet::perlvar{'lonHostID'}) {
2789: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
2790: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
2791: } else {
2792: my $server_hostname = &Apache::lonnet::hostname($lonhost);
2793: my $server_homeID = &Apache::lonnet::get_server_homeID($server_hostname);
2794: if ($server_homeID eq $Apache::lonnet::perlvar{'lonHostID'}) {
2795: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
2796: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
2797: } else {
2798: my %what = (
2799: spareid => 1,
2800: );
2801: my ($result,$returnhash) =
2802: &Apache::lonnet::get_remote_globals($lonhost,\%what);
2803: if ($result eq 'ok') {
2804: if (ref($returnhash) eq 'HASH') {
2805: if (ref($returnhash->{'spareid'}) eq 'HASH') {
2806: $spareid{$lonhost}{'primary'} = $returnhash->{'spareid'}->{'primary'};
2807: $spareid{$lonhost}{'default'} = $returnhash->{'spareid'}->{'default'};
2808: }
2809: }
2810: }
2811: }
2812: }
2813: }
2814: }
2815: }
2816: return %spareid;
2817: }
2818:
2819: sub spares_row {
2820: my ($dom,$servers,$spareid,$serverhomes,$altids,$rowtotal) = @_;
2821: my $css_class;
2822: my $numinrow = 4;
2823: my $itemcount = 1;
2824: my $datatable;
2825: my %typetitles = &sparestype_titles();
2826: if ((ref($servers) eq 'HASH') && (ref($spareid) eq 'HASH') && (ref($altids) eq 'HASH')) {
2827: foreach my $server (sort(keys(%{$servers}))) {
2828: my $serverhome = &Apache::lonnet::get_server_homeID($servers->{$server});
2829: my ($othercontrol,$serverdom);
2830: if ($serverhome ne $server) {
2831: $serverdom = &Apache::lonnet::host_domain($serverhome);
2832: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
2833: } else {
2834: $serverdom = &Apache::lonnet::host_domain($server);
2835: if ($serverdom ne $dom) {
2836: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
2837: }
2838: }
2839: next unless (ref($spareid->{$server}) eq 'HASH');
2840: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
2841: $datatable .= '<tr'.$css_class.'>
2842: <td rowspan="2">
2843: <span class="LC_nobreak">'.
2844: &mt('[_1] when busy, offloads to:'
2845: ,'<b>'.$server.'</b>').
2846: "\n";
2847: my (%current,%canselect);
2848: my @choices =
2849: &possible_newspares($server,$spareid->{$server},$serverhomes,$altids);
2850: foreach my $type ('primary','default') {
2851: if (ref($spareid->{$server}) eq 'HASH') {
2852: if (ref($spareid->{$server}{$type}) eq 'ARRAY') {
2853: my @spares = @{$spareid->{$server}{$type}};
2854: if (@spares > 0) {
2855: if ($othercontrol) {
2856: $current{$type} = join(', ',@spares);
2857: } else {
2858: $current{$type} .= '<table>';
2859: my $numspares = scalar(@spares);
2860: for (my $i=0; $i<@spares; $i++) {
2861: my $rem = $i%($numinrow);
2862: if ($rem == 0) {
2863: if ($i > 0) {
2864: $current{$type} .= '</tr>';
2865: }
2866: $current{$type} .= '<tr>';
2867: }
2868: $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'".');" /> '.
2869: $spareid->{$server}{$type}[$i].
2870: '</label></td>'."\n";
2871: }
2872: my $rem = @spares%($numinrow);
2873: my $colsleft = $numinrow - $rem;
2874: if ($colsleft > 1 ) {
2875: $current{$type} .= '<td colspan="'.$colsleft.
2876: '" class="LC_left_item">'.
2877: ' </td>';
2878: } elsif ($colsleft == 1) {
2879: $current{$type} .= '<td class="LC_left_item"> </td>'."\n";
2880: }
2881: $current{$type} .= '</tr></table>';
2882: }
2883: }
2884: }
2885: if ($current{$type} eq '') {
2886: $current{$type} = &mt('None specified');
2887: }
2888: if ($othercontrol) {
2889: if ($type eq 'primary') {
2890: $canselect{$type} = $othercontrol;
2891: }
2892: } else {
2893: $canselect{$type} =
2894: &mt('Add new [_1]'.$type.'[_2]:','<i>','</i>').' '.
2895: '<select name="newspare_'.$type.'_'.$server.'" '.
2896: 'id="newspare_'.$type.'_'.$server.'" onchange="checkNewSpares('."'$server','$type'".');">'."\n".
2897: '<option value="" selected ="selected">'.&mt('Select').'</option>'."\n";
2898: if (@choices > 0) {
2899: foreach my $lonhost (@choices) {
2900: $canselect{$type} .= '<option value="'.$lonhost.'">'.$lonhost.'</option>'."\n";
2901: }
2902: }
2903: $canselect{$type} .= '</select>'."\n";
2904: }
2905: } else {
2906: $current{$type} = &mt('Could not be determined');
2907: if ($type eq 'primary') {
2908: $canselect{$type} = $othercontrol;
2909: }
2910: }
2911: if ($type eq 'default') {
2912: $datatable .= '<tr'.$css_class.'>';
2913: }
2914: $datatable .= '<td><i>'.$typetitles{$type}.'</i></td>'."\n".
2915: '<td>'.$current{$type}.'</td>'."\n".
2916: '<td>'.$canselect{$type}.'</td></tr>'."\n";
2917: }
2918: $itemcount ++;
2919: }
2920: }
2921: $$rowtotal += $itemcount;
2922: return $datatable;
2923: }
2924:
2925: sub possible_newspares {
2926: my ($server,$currspares,$serverhomes,$altids) = @_;
2927: my $serverhostname = &Apache::lonnet::hostname($server);
2928: my %excluded;
2929: if ($serverhostname ne '') {
2930: %excluded = (
2931: $serverhostname => 1,
2932: );
2933: }
2934: if (ref($currspares) eq 'HASH') {
2935: foreach my $type (keys(%{$currspares})) {
2936: if (ref($currspares->{$type}) eq 'ARRAY') {
2937: if (@{$currspares->{$type}} > 0) {
2938: foreach my $curr (@{$currspares->{$type}}) {
2939: my $hostname = &Apache::lonnet::hostname($curr);
2940: $excluded{$hostname} = 1;
2941: }
2942: }
2943: }
2944: }
2945: }
2946: my @choices;
2947: if ((ref($serverhomes) eq 'HASH') && (ref($altids) eq 'HASH')) {
2948: if (keys(%{$serverhomes}) > 1) {
2949: foreach my $name (sort(keys(%{$serverhomes}))) {
2950: unless ($excluded{$name}) {
2951: if (exists($altids->{$serverhomes->{$name}})) {
2952: push(@choices,$altids->{$serverhomes->{$name}});
2953: } else {
2954: push(@choices,$serverhomes->{$name});
2955: }
2956: }
2957: }
2958: }
2959: }
2960: return sort(@choices);
2961: }
2962:
2963: sub print_loadbalancing {
2964: my ($dom,$settings,$rowtotal) = @_;
2965: my $primary_id = &Apache::lonnet::domain($dom,'primary');
2966: my $intdom = &Apache::lonnet::internet_dom($primary_id);
2967: my $numinrow = 1;
2968: my $datatable;
2969: my %servers = &Apache::lonnet::internet_dom_servers($dom);
2970: my (%currbalancer,%currtargets,%currrules,%existing);
2971: if (ref($settings) eq 'HASH') {
2972: %existing = %{$settings};
2973: }
2974: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
2975: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
2976: \%currtargets,\%currrules);
2977: } else {
2978: return;
2979: }
2980: my ($othertitle,$usertypes,$types) =
2981: &Apache::loncommon::sorted_inst_types($dom);
2982: my $rownum = 6;
2983: if (ref($types) eq 'ARRAY') {
2984: $rownum += scalar(@{$types});
2985: }
2986: my @css_class = ('LC_odd_row','LC_even_row');
2987: my $balnum = 0;
2988: my $islast;
2989: my (@toshow,$disabledtext);
2990: if (keys(%currbalancer) > 0) {
2991: @toshow = sort(keys(%currbalancer));
2992: if (scalar(@toshow) < scalar(keys(%servers)) + 1) {
2993: push(@toshow,'');
2994: }
2995: } else {
2996: @toshow = ('');
2997: $disabledtext = &mt('No existing load balancer');
2998: }
2999: foreach my $lonhost (@toshow) {
3000: if ($balnum == scalar(@toshow)-1) {
3001: $islast = 1;
3002: } else {
3003: $islast = 0;
3004: }
3005: my $cssidx = $balnum%2;
3006: my $targets_div_style = 'display: none';
3007: my $disabled_div_style = 'display: block';
3008: my $homedom_div_style = 'display: none';
3009: $datatable .= '<tr class="'.$css_class[$cssidx].'">'.
3010: '<td rowspan="'.$rownum.'" valign="top">'.
3011: '<p>';
3012: if ($lonhost eq '') {
3013: $datatable .= '<span class="LC_nobreak">';
3014: if (keys(%currbalancer) > 0) {
3015: $datatable .= &mt('Add balancer:');
3016: } else {
3017: $datatable .= &mt('Enable balancer:');
3018: }
3019: $datatable .= ' '.
3020: '<select name="loadbalancing_lonhost_'.$balnum.'"'.
3021: ' id="loadbalancing_lonhost_'.$balnum.'"'.
3022: ' onchange="toggleTargets('."'$balnum'".');">'."\n".
3023: '<option value="" selected="selected">'.&mt('None').
3024: '</option>'."\n";
3025: foreach my $server (sort(keys(%servers))) {
3026: next if ($currbalancer{$server});
3027: $datatable .= '<option value="'.$server.'">'.$server.'</option>'."\n";
3028: }
3029: $datatable .=
3030: '</select>'."\n".
3031: '<input type="hidden" name="loadbalancing_prevlonhost_'.$balnum.'" id="loadbalancing_prevlonhost_'.$balnum.'" value="" /> </span>'."\n";
3032: } else {
3033: $datatable .= '<i>'.$lonhost.'</i><br /><span class="LC_nobreak">'.
3034: '<label><input type="checkbox" name="loadbalancing_delete" value="'.$balnum.'" id="loadbalancing_delete_'.$balnum.'" onclick="javascript:balancerDeleteChange('."'$balnum'".');" /> '.
3035: &mt('Stop balancing').'</label>'.
3036: '<input type="hidden" name="loadbalancing_lonhost_'.$balnum.'" value="'.$lonhost.'" id="loadbalancing_lonhost_'.$balnum.'" /></span>';
3037: $targets_div_style = 'display: block';
3038: $disabled_div_style = 'display: none';
3039: if ($dom eq &Apache::lonnet::host_domain($lonhost)) {
3040: $homedom_div_style = 'display: block';
3041: }
3042: }
3043: $datatable .= '</p></td><td rowspan="'.$rownum.'" valign="top">'.
3044: '<div id="loadbalancing_disabled_'.$balnum.'" style="'.
3045: $disabled_div_style.'">'.$disabledtext.'</div>'."\n".
3046: '<div id="loadbalancing_targets_'.$balnum.'" style="'.$targets_div_style.'">'.&mt('Offloads to:').'<br />';
3047: my ($numspares,@spares) = &count_servers($lonhost,%servers);
3048: my @sparestypes = ('primary','default');
3049: my %typetitles = &sparestype_titles();
3050: foreach my $sparetype (@sparestypes) {
3051: my $targettable;
3052: for (my $i=0; $i<$numspares; $i++) {
3053: my $checked;
3054: if (ref($currtargets{$lonhost}) eq 'HASH') {
3055: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
3056: if (grep(/^\Q$spares[$i]\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
3057: $checked = ' checked="checked"';
3058: }
3059: }
3060: }
3061: my ($chkboxval,$disabled);
3062: if (($lonhost ne '') && (exists($servers{$lonhost}))) {
3063: $chkboxval = $spares[$i];
3064: }
3065: if (exists($currbalancer{$spares[$i]})) {
3066: $disabled = ' disabled="disabled"';
3067: }
3068: $targettable .=
3069: '<td><label><input type="checkbox" name="loadbalancing_target_'.$balnum.'_'.$sparetype.'"'.
3070: $checked.$disabled.' value="'.$chkboxval.'" id="loadbalancing_target_'.$balnum.'_'.$sparetype.'_'.$i.'" onclick="checkOffloads('."this,'$balnum','$sparetype'".');" /><span id="loadbalancing_targettxt_'.$balnum.'_'.$sparetype.'_'.$i.'"> '.$chkboxval.
3071: '</span></label></td>';
3072: my $rem = $i%($numinrow);
3073: if ($rem == 0) {
3074: if (($i > 0) && ($i < $numspares-1)) {
3075: $targettable .= '</tr>';
3076: }
3077: if ($i < $numspares-1) {
3078: $targettable .= '<tr>';
3079: }
3080: }
3081: }
3082: if ($targettable ne '') {
3083: my $rem = $numspares%($numinrow);
3084: my $colsleft = $numinrow - $rem;
3085: if ($colsleft > 1 ) {
3086: $targettable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
3087: ' </td>';
3088: } elsif ($colsleft == 1) {
3089: $targettable .= '<td class="LC_left_item"> </td>';
3090: }
3091: $datatable .= '<i>'.$typetitles{$sparetype}.'</i><br />'.
3092: '<table><tr>'.$targettable.'</tr></table><br />';
3093: }
3094: }
3095: $datatable .= '</div></td></tr>'.
3096: &loadbalancing_rules($dom,$intdom,$currrules{$lonhost},
3097: $othertitle,$usertypes,$types,\%servers,
3098: \%currbalancer,$lonhost,
3099: $targets_div_style,$homedom_div_style,
3100: $css_class[$cssidx],$balnum,$islast);
3101: $$rowtotal += $rownum;
3102: $balnum ++;
3103: }
3104: $datatable .= '<input type="hidden" name="loadbalancing_total" id="loadbalancing_total" value="'.$balnum.'" />';
3105: return $datatable;
3106: }
3107:
3108: sub get_loadbalancers_config {
3109: my ($servers,$existing,$currbalancer,$currtargets,$currrules) = @_;
3110: return unless ((ref($servers) eq 'HASH') &&
3111: (ref($existing) eq 'HASH') && (ref($currbalancer) eq 'HASH') &&
3112: (ref($currtargets) eq 'HASH') && (ref($currrules) eq 'HASH'));
3113: if (keys(%{$existing}) > 0) {
3114: my $oldlonhost;
3115: foreach my $key (sort(keys(%{$existing}))) {
3116: if ($key eq 'lonhost') {
3117: $oldlonhost = $existing->{'lonhost'};
3118: $currbalancer->{$oldlonhost} = 1;
3119: } elsif ($key eq 'targets') {
3120: if ($oldlonhost) {
3121: $currtargets->{$oldlonhost} = $existing->{'targets'};
3122: }
3123: } elsif ($key eq 'rules') {
3124: if ($oldlonhost) {
3125: $currrules->{$oldlonhost} = $existing->{'rules'};
3126: }
3127: } elsif (ref($existing->{$key}) eq 'HASH') {
3128: $currbalancer->{$key} = 1;
3129: $currtargets->{$key} = $existing->{$key}{'targets'};
3130: $currrules->{$key} = $existing->{$key}{'rules'};
3131: }
3132: }
3133: } else {
3134: my ($balancerref,$targetsref) =
3135: &Apache::lonnet::get_lonbalancer_config($servers);
3136: if ((ref($balancerref) eq 'HASH') && (ref($targetsref) eq 'HASH')) {
3137: foreach my $server (sort(keys(%{$balancerref}))) {
3138: $currbalancer->{$server} = 1;
3139: $currtargets->{$server} = $targetsref->{$server};
3140: }
3141: }
3142: }
3143: return;
3144: }
3145:
3146: sub loadbalancing_rules {
3147: my ($dom,$intdom,$currrules,$othertitle,$usertypes,$types,$servers,
3148: $currbalancer,$lonhost,$targets_div_style,$homedom_div_style,
3149: $css_class,$balnum,$islast) = @_;
3150: my $output;
3151: my $num = 0;
3152: my ($alltypes,$othertypes,$titles) =
3153: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
3154: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
3155: foreach my $type (@{$alltypes}) {
3156: $num ++;
3157: my $current;
3158: if (ref($currrules) eq 'HASH') {
3159: $current = $currrules->{$type};
3160: }
3161: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
3162: if ($dom ne &Apache::lonnet::host_domain($lonhost)) {
3163: $current = '';
3164: }
3165: }
3166: $output .= &loadbalance_rule_row($type,$titles->{$type},$current,
3167: $servers,$currbalancer,$lonhost,$dom,
3168: $targets_div_style,$homedom_div_style,
3169: $css_class,$balnum,$num,$islast);
3170: }
3171: }
3172: return $output;
3173: }
3174:
3175: sub loadbalancing_titles {
3176: my ($dom,$intdom,$usertypes,$types) = @_;
3177: my %othertypes = (
3178: '_LC_adv' => &mt('Advanced users from [_1]',$dom),
3179: '_LC_author' => &mt('Users from [_1] with author role',$dom),
3180: '_LC_internetdom' => &mt('Users not from [_1], but from [_2]',$dom,$intdom),
3181: '_LC_external' => &mt('Users not from [_1]',$intdom),
3182: );
3183: my @alltypes = ('_LC_adv','_LC_author','_LC_internetdom','_LC_external');
3184: if (ref($types) eq 'ARRAY') {
3185: unshift(@alltypes,@{$types},'default');
3186: }
3187: my %titles;
3188: foreach my $type (@alltypes) {
3189: if ($type =~ /^_LC_/) {
3190: $titles{$type} = $othertypes{$type};
3191: } elsif ($type eq 'default') {
3192: $titles{$type} = &mt('All users from [_1]',$dom);
3193: if (ref($types) eq 'ARRAY') {
3194: if (@{$types} > 0) {
3195: $titles{$type} = &mt('Other users from [_1]',$dom);
3196: }
3197: }
3198: } elsif (ref($usertypes) eq 'HASH') {
3199: $titles{$type} = $usertypes->{$type};
3200: }
3201: }
3202: return (\@alltypes,\%othertypes,\%titles);
3203: }
3204:
3205: sub loadbalance_rule_row {
3206: my ($type,$title,$current,$servers,$currbalancer,$lonhost,$dom,
3207: $targets_div_style,$homedom_div_style,$css_class,$balnum,$num,$islast) = @_;
3208: my @rulenames = ('default','homeserver');
3209: my %ruletitles = &offloadtype_text();
3210: if ($type eq '_LC_external') {
3211: push(@rulenames,'externalbalancer');
3212: } else {
3213: push(@rulenames,'specific');
3214: }
3215: push(@rulenames,'none');
3216: my $style = $targets_div_style;
3217: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
3218: $style = $homedom_div_style;
3219: }
3220: my $space;
3221: if ($islast && $num == 1) {
3222: $space = '<div display="inline-block"> </div>';
3223: }
3224: my $output =
3225: '<tr class="'.$css_class.'" id="balanceruletr_'.$balnum.'_'.$num.'"><td valign="top">'.$space.
3226: '<div id="balanceruletitle_'.$balnum.'_'.$type.'" style="'.$style.'">'.$title.'</div></td>'."\n".
3227: '<td valaign="top">'.$space.
3228: '<div id="balancerule_'.$balnum.'_'.$type.'" style="'.$style.'">'."\n";
3229: for (my $i=0; $i<@rulenames; $i++) {
3230: my $rule = $rulenames[$i];
3231: my ($checked,$extra);
3232: if ($rulenames[$i] eq 'default') {
3233: $rule = '';
3234: }
3235: if ($rulenames[$i] eq 'specific') {
3236: if (ref($servers) eq 'HASH') {
3237: my $default;
3238: if (($current ne '') && (exists($servers->{$current}))) {
3239: $checked = ' checked="checked"';
3240: }
3241: unless ($checked) {
3242: $default = ' selected="selected"';
3243: }
3244: $extra =
3245: ': <select name="loadbalancing_singleserver_'.$balnum.'_'.$type.
3246: '" id="loadbalancing_singleserver_'.$balnum.'_'.$type.
3247: '" onchange="singleServerToggle('."'$balnum','$type'".')">'."\n".
3248: '<option value=""'.$default.'></option>'."\n";
3249: foreach my $server (sort(keys(%{$servers}))) {
3250: if (ref($currbalancer) eq 'HASH') {
3251: next if (exists($currbalancer->{$server}));
3252: }
3253: my $selected;
3254: if ($server eq $current) {
3255: $selected = ' selected="selected"';
3256: }
3257: $extra .= '<option value="'.$server.'"'.$selected.'>'.$server.'</option>';
3258: }
3259: $extra .= '</select>';
3260: }
3261: } elsif ($rule eq $current) {
3262: $checked = ' checked="checked"';
3263: }
3264: $output .= '<span class="LC_nobreak"><label>'.
3265: '<input type="radio" name="loadbalancing_rules_'.$balnum.'_'.$type.
3266: '" id="loadbalancing_rules_'.$balnum.'_'.$type.'_'.$i.'" value="'.
3267: $rule.'" onclick="balanceruleChange('."this.form,'$balnum','$type'".
3268: ')"'.$checked.' /> '.$ruletitles{$rulenames[$i]}.
3269: '</label>'.$extra.'</span><br />'."\n";
3270: }
3271: $output .= '</div></td></tr>'."\n";
3272: return $output;
3273: }
3274:
3275: sub offloadtype_text {
3276: my %ruletitles = &Apache::lonlocal::texthash (
3277: 'default' => 'Offloads to default destinations',
3278: 'homeserver' => "Offloads to user's home server",
3279: 'externalbalancer' => "Offloads to Load Balancer in user's domain",
3280: 'specific' => 'Offloads to specific server',
3281: 'none' => 'No offload',
3282: );
3283: return %ruletitles;
3284: }
3285:
3286: sub sparestype_titles {
3287: my %typestitles = &Apache::lonlocal::texthash (
3288: 'primary' => 'primary',
3289: 'default' => 'default',
3290: );
3291: return %typestitles;
3292: }
3293:
3294: sub contact_titles {
3295: my %titles = &Apache::lonlocal::texthash (
3296: 'supportemail' => 'Support E-mail address',
3297: 'adminemail' => 'Default Server Admin E-mail address',
3298: 'errormail' => 'Error reports to be e-mailed to',
3299: 'packagesmail' => 'Package update alerts to be e-mailed to',
3300: 'helpdeskmail' => 'Helpdesk requests to be e-mailed to',
3301: 'lonstatusmail' => 'E-mail from nightly status check (warnings/errors)',
3302: 'requestsmail' => 'E-mail from course requests requiring approval',
3303: 'updatesmail' => 'E-mail from nightly check of LON-CAPA module integrity/updates',
3304: );
3305: my %short_titles = &Apache::lonlocal::texthash (
3306: adminemail => 'Admin E-mail address',
3307: supportemail => 'Support E-mail',
3308: );
3309: return (\%titles,\%short_titles);
3310: }
3311:
3312: sub tool_titles {
3313: my %titles = &Apache::lonlocal::texthash (
3314: aboutme => 'Personal web page',
3315: blog => 'Blog',
3316: webdav => 'WebDAV',
3317: portfolio => 'Portfolio',
3318: official => 'Official courses (with institutional codes)',
3319: unofficial => 'Unofficial courses',
3320: community => 'Communities',
3321: );
3322: return %titles;
3323: }
3324:
3325: sub courserequest_titles {
3326: my %titles = &Apache::lonlocal::texthash (
3327: official => 'Official',
3328: unofficial => 'Unofficial',
3329: community => 'Communities',
3330: norequest => 'Not allowed',
3331: approval => 'Approval by Dom. Coord.',
3332: validate => 'With validation',
3333: autolimit => 'Numerical limit',
3334: unlimited => '(blank for unlimited)',
3335: );
3336: return %titles;
3337: }
3338:
3339: sub authorrequest_titles {
3340: my %titles = &Apache::lonlocal::texthash (
3341: norequest => 'Not allowed',
3342: approval => 'Approval by Dom. Coord.',
3343: automatic => 'Automatic approval',
3344: );
3345: return %titles;
3346: }
3347:
3348: sub courserequest_conditions {
3349: my %conditions = &Apache::lonlocal::texthash (
3350: approval => '(Processing of request subject to approval by Domain Coordinator).',
3351: validate => '(Processing of request subject to institutional validation).',
3352: );
3353: return %conditions;
3354: }
3355:
3356:
3357: sub print_usercreation {
3358: my ($position,$dom,$settings,$rowtotal) = @_;
3359: my $numinrow = 4;
3360: my $datatable;
3361: if ($position eq 'top') {
3362: $$rowtotal ++;
3363: my $rowcount = 0;
3364: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username');
3365: if (ref($rules) eq 'HASH') {
3366: if (keys(%{$rules}) > 0) {
3367: $datatable .= &user_formats_row('username',$settings,$rules,
3368: $ruleorder,$numinrow,$rowcount);
3369: $$rowtotal ++;
3370: $rowcount ++;
3371: }
3372: }
3373: my ($idrules,$idruleorder) = &Apache::lonnet::inst_userrules($dom,'id');
3374: if (ref($idrules) eq 'HASH') {
3375: if (keys(%{$idrules}) > 0) {
3376: $datatable .= &user_formats_row('id',$settings,$idrules,
3377: $idruleorder,$numinrow,$rowcount);
3378: $$rowtotal ++;
3379: $rowcount ++;
3380: }
3381: }
3382: my ($emailrules,$emailruleorder) =
3383: &Apache::lonnet::inst_userrules($dom,'email');
3384: if (ref($emailrules) eq 'HASH') {
3385: if (keys(%{$emailrules}) > 0) {
3386: $datatable .= &user_formats_row('email',$settings,$emailrules,
3387: $emailruleorder,$numinrow,$rowcount);
3388: $$rowtotal ++;
3389: $rowcount ++;
3390: }
3391: }
3392: if ($rowcount == 0) {
3393: $datatable .= '<tr><td colspan="2">'.&mt('No format rules have been defined for usernames or IDs in this domain.').'</td></tr>';
3394: $$rowtotal ++;
3395: $rowcount ++;
3396: }
3397: } elsif ($position eq 'middle') {
3398: my @creators = ('author','course','requestcrs','selfcreate');
3399: my ($rules,$ruleorder) =
3400: &Apache::lonnet::inst_userrules($dom,'username');
3401: my %lt = &usercreation_types();
3402: my %checked;
3403: my @selfcreate;
3404: if (ref($settings) eq 'HASH') {
3405: if (ref($settings->{'cancreate'}) eq 'HASH') {
3406: foreach my $item (@creators) {
3407: $checked{$item} = $settings->{'cancreate'}{$item};
3408: }
3409: if (ref($settings->{'cancreate'}{'selfcreate'}) eq 'ARRAY') {
3410: @selfcreate = @{$settings->{'cancreate'}{'selfcreate'}};
3411: } elsif ($settings->{'cancreate'}{'selfcreate'} ne '') {
3412: if ($settings->{'cancreate'}{'selfcreate'} eq 'any') {
3413: @selfcreate = ('email','login','sso');
3414: } elsif ($settings->{'cancreate'}{'selfcreate'} ne 'none') {
3415: @selfcreate = ($settings->{'cancreate'}{'selfcreate'});
3416: }
3417: }
3418: } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {
3419: foreach my $item (@creators) {
3420: if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {
3421: $checked{$item} = 'none';
3422: }
3423: }
3424: }
3425: }
3426: my $rownum = 0;
3427: foreach my $item (@creators) {
3428: $rownum ++;
3429: if ($item ne 'selfcreate') {
3430: if ($checked{$item} eq '') {
3431: $checked{$item} = 'any';
3432: }
3433: }
3434: my $css_class;
3435: if ($rownum%2) {
3436: $css_class = '';
3437: } else {
3438: $css_class = ' class="LC_odd_row" ';
3439: }
3440: $datatable .= '<tr'.$css_class.'>'.
3441: '<td><span class="LC_nobreak">'.$lt{$item}.
3442: '</span></td><td align="right">';
3443: my @options;
3444: if ($item eq 'selfcreate') {
3445: push(@options,('email','login','sso'));
3446: } else {
3447: @options = ('any');
3448: if (ref($rules) eq 'HASH') {
3449: if (keys(%{$rules}) > 0) {
3450: push(@options,('official','unofficial'));
3451: }
3452: }
3453: push(@options,'none');
3454: }
3455: foreach my $option (@options) {
3456: my $type = 'radio';
3457: my $check = ' ';
3458: if ($item eq 'selfcreate') {
3459: $type = 'checkbox';
3460: if (grep(/^\Q$option\E$/,@selfcreate)) {
3461: $check = ' checked="checked" ';
3462: }
3463: } else {
3464: if ($checked{$item} eq $option) {
3465: $check = ' checked="checked" ';
3466: }
3467: }
3468: $datatable .= '<span class="LC_nobreak"><label>'.
3469: '<input type="'.$type.'" name="can_createuser_'.
3470: $item.'" value="'.$option.'"'.$check.'/> '.
3471: $lt{$option}.'</label> </span>';
3472: }
3473: $datatable .= '</td></tr>';
3474: }
3475: my ($othertitle,$usertypes,$types) =
3476: &Apache::loncommon::sorted_inst_types($dom);
3477: my $createsettings;
3478: if (ref($settings) eq 'HASH') {
3479: $createsettings = $settings->{cancreate};
3480: }
3481: if (ref($usertypes) eq 'HASH') {
3482: if (keys(%{$usertypes}) > 0) {
3483: $datatable .= &insttypes_row($createsettings,$types,$usertypes,
3484: $dom,$numinrow,$othertitle,
3485: 'statustocreate');
3486: $$rowtotal ++;
3487: $rownum ++;
3488: }
3489: }
3490: $datatable .= &captcha_choice('cancreate',$createsettings,$rownum);
3491: } else {
3492: my @contexts = ('author','course','domain');
3493: my @authtypes = ('int','krb4','krb5','loc');
3494: my %checked;
3495: if (ref($settings) eq 'HASH') {
3496: if (ref($settings->{'authtypes'}) eq 'HASH') {
3497: foreach my $item (@contexts) {
3498: if (ref($settings->{'authtypes'}{$item}) eq 'HASH') {
3499: foreach my $auth (@authtypes) {
3500: if ($settings->{'authtypes'}{$item}{$auth}) {
3501: $checked{$item}{$auth} = ' checked="checked" ';
3502: }
3503: }
3504: }
3505: }
3506: }
3507: } else {
3508: foreach my $item (@contexts) {
3509: foreach my $auth (@authtypes) {
3510: $checked{$item}{$auth} = ' checked="checked" ';
3511: }
3512: }
3513: }
3514: my %title = &context_names();
3515: my %authname = &authtype_names();
3516: my $rownum = 0;
3517: my $css_class;
3518: foreach my $item (@contexts) {
3519: if ($rownum%2) {
3520: $css_class = '';
3521: } else {
3522: $css_class = ' class="LC_odd_row" ';
3523: }
3524: $datatable .= '<tr'.$css_class.'>'.
3525: '<td>'.$title{$item}.
3526: '</td><td class="LC_left_item">'.
3527: '<span class="LC_nobreak">';
3528: foreach my $auth (@authtypes) {
3529: $datatable .= '<label>'.
3530: '<input type="checkbox" name="'.$item.'_auth" '.
3531: $checked{$item}{$auth}.' value="'.$auth.'" />'.
3532: $authname{$auth}.'</label> ';
3533: }
3534: $datatable .= '</span></td></tr>';
3535: $rownum ++;
3536: }
3537: $$rowtotal += $rownum;
3538: }
3539: return $datatable;
3540: }
3541:
3542: sub captcha_choice {
3543: my ($context,$settings,$itemcount) = @_;
3544: my ($keyentry,$currpub,$currpriv,%checked,$rowname,$pubtext,$privtext);
3545: my %lt = &captcha_phrases();
3546: $keyentry = 'hidden';
3547: if ($context eq 'cancreate') {
3548: $rowname = &mt('CAPTCHA validation (e-mail as username)');
3549: } elsif ($context eq 'login') {
3550: $rowname = &mt('"Contact helpdesk" CAPTCHA validation');
3551: }
3552: if (ref($settings) eq 'HASH') {
3553: if ($settings->{'captcha'}) {
3554: $checked{$settings->{'captcha'}} = ' checked="checked"';
3555: } else {
3556: $checked{'original'} = ' checked="checked"';
3557: }
3558: if ($settings->{'captcha'} eq 'recaptcha') {
3559: $pubtext = $lt{'pub'};
3560: $privtext = $lt{'priv'};
3561: $keyentry = 'text';
3562: }
3563: if (ref($settings->{'recaptchakeys'}) eq 'HASH') {
3564: $currpub = $settings->{'recaptchakeys'}{'public'};
3565: $currpriv = $settings->{'recaptchakeys'}{'private'};
3566: }
3567: } else {
3568: $checked{'original'} = ' checked="checked"';
3569: }
3570: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
3571: my $output = '<tr'.$css_class.'>'.
3572: '<td class="LC_left_item">'.$rowname.'</td><td class="LC_left_item" colspan="2">'."\n".
3573: '<table><tr><td>'."\n";
3574: foreach my $option ('original','recaptcha','notused') {
3575: $output .= '<span class="LC_nobreak"><label><input type="radio" name="'.$context.'_captcha" value="'.
3576: $option.'" '.$checked{$option}.' onchange="javascript:updateCaptcha('."this,'$context'".');" />'.
3577: $lt{$option}.'</label></span>';
3578: unless ($option eq 'notused') {
3579: $output .= (' 'x2)."\n";
3580: }
3581: }
3582: #
3583: # Note: If reCAPTCHA is to be used for LON-CAPA servers in a domain, a domain coordinator should visit:
3584: # https://www.google.com/recaptcha and generate a Public and Private key. For domains with multiple
3585: # servers a single key pair will be used for all servers, so the internet domain (e.g., yourcollege.edu)
3586: # specified for use with the key should be broad enough to accommodate all servers in the LON-CAPA domain.
3587: #
3588: $output .= '</td></tr>'."\n".
3589: '<tr><td>'."\n".
3590: '<span class="LC_nobreak"><span id="'.$context.'_recaptchapubtxt">'.$pubtext.'</span> '."\n".
3591: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapub" name="'.$context.'_recaptchapub" value="'.
3592: $currpub.'" size="40" /></span><br />'."\n".
3593: '<span class="LC_nobreak"><span id="'.$context.'_recaptchaprivtxt">'.$privtext.'</span> '."\n".
3594: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapriv" name="'.$context.'_recaptchapriv" value="'.
3595: $currpriv.'" size="40" /></span></td></tr></table>'."\n".
3596: '</td></tr>';
3597: return $output;
3598: }
3599:
3600: sub user_formats_row {
3601: my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount) = @_;
3602: my $output;
3603: my %text = (
3604: 'username' => 'new usernames',
3605: 'id' => 'IDs',
3606: 'email' => 'self-created accounts (e-mail)',
3607: );
3608: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
3609: $output = '<tr '.$css_class.'>'.
3610: '<td><span class="LC_nobreak">';
3611: if ($type eq 'email') {
3612: $output .= &mt("Formats disallowed for $text{$type}: ");
3613: } else {
3614: $output .= &mt("Format rules to check for $text{$type}: ");
3615: }
3616: $output .= '</span></td>'.
3617: '<td class="LC_left_item" colspan="2"><table>';
3618: my $rem;
3619: if (ref($ruleorder) eq 'ARRAY') {
3620: for (my $i=0; $i<@{$ruleorder}; $i++) {
3621: if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
3622: my $rem = $i%($numinrow);
3623: if ($rem == 0) {
3624: if ($i > 0) {
3625: $output .= '</tr>';
3626: }
3627: $output .= '<tr>';
3628: }
3629: my $check = ' ';
3630: if (ref($settings) eq 'HASH') {
3631: if (ref($settings->{$type.'_rule'}) eq 'ARRAY') {
3632: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) {
3633: $check = ' checked="checked" ';
3634: }
3635: }
3636: }
3637: $output .= '<td class="LC_left_item">'.
3638: '<span class="LC_nobreak"><label>'.
3639: '<input type="checkbox" name="'.$type.'_rule" '.
3640: 'value="'.$ruleorder->[$i].'"'.$check.'/>'.
3641: $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
3642: }
3643: }
3644: $rem = @{$ruleorder}%($numinrow);
3645: }
3646: my $colsleft = $numinrow - $rem;
3647: if ($colsleft > 1 ) {
3648: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
3649: ' </td>';
3650: } elsif ($colsleft == 1) {
3651: $output .= '<td class="LC_left_item"> </td>';
3652: }
3653: $output .= '</tr></table></td></tr>';
3654: return $output;
3655: }
3656:
3657: sub usercreation_types {
3658: my %lt = &Apache::lonlocal::texthash (
3659: author => 'When adding a co-author',
3660: course => 'When adding a user to a course',
3661: requestcrs => 'When requesting a course',
3662: selfcreate => 'User creates own account',
3663: any => 'Any',
3664: official => 'Institutional only ',
3665: unofficial => 'Non-institutional only',
3666: email => 'E-mail address',
3667: login => 'Institutional Login',
3668: sso => 'SSO',
3669: none => 'None',
3670: );
3671: return %lt;
3672: }
3673:
3674: sub authtype_names {
3675: my %lt = &Apache::lonlocal::texthash(
3676: int => 'Internal',
3677: krb4 => 'Kerberos 4',
3678: krb5 => 'Kerberos 5',
3679: loc => 'Local',
3680: );
3681: return %lt;
3682: }
3683:
3684: sub context_names {
3685: my %context_title = &Apache::lonlocal::texthash(
3686: author => 'Creating users when an Author',
3687: course => 'Creating users when in a course',
3688: domain => 'Creating users when a Domain Coordinator',
3689: );
3690: return %context_title;
3691: }
3692:
3693: sub print_usermodification {
3694: my ($position,$dom,$settings,$rowtotal) = @_;
3695: my $numinrow = 4;
3696: my ($context,$datatable,$rowcount);
3697: if ($position eq 'top') {
3698: $rowcount = 0;
3699: $context = 'author';
3700: foreach my $role ('ca','aa') {
3701: $datatable .= &modifiable_userdata_row($context,$role,$settings,
3702: $numinrow,$rowcount);
3703: $$rowtotal ++;
3704: $rowcount ++;
3705: }
3706: } elsif ($position eq 'middle') {
3707: $context = 'course';
3708: $rowcount = 0;
3709: foreach my $role ('st','ep','ta','in','cr') {
3710: $datatable .= &modifiable_userdata_row($context,$role,$settings,
3711: $numinrow,$rowcount);
3712: $$rowtotal ++;
3713: $rowcount ++;
3714: }
3715: } elsif ($position eq 'bottom') {
3716: $context = 'selfcreate';
3717: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
3718: $usertypes->{'default'} = $othertitle;
3719: if (ref($types) eq 'ARRAY') {
3720: push(@{$types},'default');
3721: $usertypes->{'default'} = $othertitle;
3722: foreach my $status (@{$types}) {
3723: $datatable .= &modifiable_userdata_row($context,$status,$settings,
3724: $numinrow,$rowcount,$usertypes);
3725: $$rowtotal ++;
3726: $rowcount ++;
3727: }
3728: }
3729: }
3730: return $datatable;
3731: }
3732:
3733: sub print_defaults {
3734: my ($dom,$rowtotal) = @_;
3735: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def',
3736: 'datelocale_def','portal_def');
3737: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
3738: my $titles = &defaults_titles($dom);
3739: my $rownum = 0;
3740: my ($datatable,$css_class);
3741: foreach my $item (@items) {
3742: if ($rownum%2) {
3743: $css_class = '';
3744: } else {
3745: $css_class = ' class="LC_odd_row" ';
3746: }
3747: $datatable .= '<tr'.$css_class.'>'.
3748: '<td><span class="LC_nobreak">'.$titles->{$item}.
3749: '</span></td><td class="LC_right_item">';
3750: if ($item eq 'auth_def') {
3751: my @authtypes = ('internal','krb4','krb5','localauth');
3752: my %shortauth = (
3753: internal => 'int',
3754: krb4 => 'krb4',
3755: krb5 => 'krb5',
3756: localauth => 'loc'
3757: );
3758: my %authnames = &authtype_names();
3759: foreach my $auth (@authtypes) {
3760: my $checked = ' ';
3761: if ($domdefaults{$item} eq $auth) {
3762: $checked = ' checked="checked" ';
3763: }
3764: $datatable .= '<label><input type="radio" name="'.$item.
3765: '" value="'.$auth.'"'.$checked.'/>'.
3766: $authnames{$shortauth{$auth}}.'</label> ';
3767: }
3768: } elsif ($item eq 'timezone_def') {
3769: my $includeempty = 1;
3770: $datatable .= &Apache::loncommon::select_timezone($item,$domdefaults{$item},undef,$includeempty);
3771: } elsif ($item eq 'datelocale_def') {
3772: my $includeempty = 1;
3773: $datatable .= &Apache::loncommon::select_datelocale($item,$domdefaults{$item},undef,$includeempty);
3774: } elsif ($item eq 'lang_def') {
3775: my %langchoices = &get_languages_hash();
3776: $langchoices{''} = 'No language preference';
3777: %langchoices = &Apache::lonlocal::texthash(%langchoices);
3778: $datatable .= &Apache::loncommon::select_form($domdefaults{$item},$item,
3779: \%langchoices);
3780: } else {
3781: my $size;
3782: if ($item eq 'portal_def') {
3783: $size = ' size="25"';
3784: }
3785: $datatable .= '<input type="text" name="'.$item.'" value="'.
3786: $domdefaults{$item}.'"'.$size.' />';
3787: }
3788: $datatable .= '</td></tr>';
3789: $rownum ++;
3790: }
3791: $$rowtotal += $rownum;
3792: return $datatable;
3793: }
3794:
3795: sub get_languages_hash {
3796: my %langchoices;
3797: foreach my $id (&Apache::loncommon::languageids()) {
3798: my $code = &Apache::loncommon::supportedlanguagecode($id);
3799: if ($code ne '') {
3800: $langchoices{$code} = &Apache::loncommon::plainlanguagedescription($id);
3801: }
3802: }
3803: return %langchoices;
3804: }
3805:
3806: sub defaults_titles {
3807: my ($dom) = @_;
3808: my %titles = &Apache::lonlocal::texthash (
3809: 'auth_def' => 'Default authentication type',
3810: 'auth_arg_def' => 'Default authentication argument',
3811: 'lang_def' => 'Default language',
3812: 'timezone_def' => 'Default timezone',
3813: 'datelocale_def' => 'Default locale for dates',
3814: 'portal_def' => 'Portal/Default URL',
3815: );
3816: if ($dom) {
3817: my $uprimary_id = &Apache::lonnet::domain($dom,'primary');
3818: my $uint_dom = &Apache::lonnet::internet_dom($uprimary_id);
3819: my $protocol = $Apache::lonnet::protocol{$uprimary_id};
3820: $protocol = 'http' if ($protocol ne 'https');
3821: if ($uint_dom) {
3822: $titles{'portal_def'} .= ' '.&mt('(for example: [_1])',$protocol.'://loncapa.'.
3823: $uint_dom);
3824: }
3825: }
3826: return (\%titles);
3827: }
3828:
3829: sub print_scantronformat {
3830: my ($r,$dom,$confname,$settings,$rowtotal) = @_;
3831: my $itemcount = 1;
3832: my ($datatable,$css_class,$scantronurl,$is_custom,%error,%scantronurls,
3833: %confhash);
3834: my $switchserver = &check_switchserver($dom,$confname);
3835: my %lt = &Apache::lonlocal::texthash (
3836: default => 'Default bubblesheet format file error',
3837: custom => 'Custom bubblesheet format file error',
3838: );
3839: my %scantronfiles = (
3840: default => 'default.tab',
3841: custom => 'custom.tab',
3842: );
3843: foreach my $key (keys(%scantronfiles)) {
3844: $scantronurls{$key} = '/res/'.$dom.'/'.$confname.'/scantron/'
3845: .$scantronfiles{$key};
3846: }
3847: my @defaultinfo = &Apache::lonnet::stat_file($scantronurls{'default'});
3848: if ((!@defaultinfo) || ($defaultinfo[0] eq 'no_such_dir')) {
3849: if (!$switchserver) {
3850: my $servadm = $r->dir_config('lonAdmEMail');
3851: my ($configuserok,$author_ok) = &config_check($dom,$confname,$servadm);
3852: if ($configuserok eq 'ok') {
3853: if ($author_ok eq 'ok') {
3854: my %legacyfile = (
3855: default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab',
3856: custom => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab',
3857: );
3858: my %md5chk;
3859: foreach my $type (keys(%legacyfile)) {
3860: ($md5chk{$type}) = split(/ /,`md5sum $legacyfile{$type}`);
3861: chomp($md5chk{$type});
3862: }
3863: if ($md5chk{'default'} ne $md5chk{'custom'}) {
3864: foreach my $type (keys(%legacyfile)) {
3865: ($scantronurls{$type},my $error) =
3866: &legacy_scantronformat($r,$dom,$confname,
3867: $type,$legacyfile{$type},
3868: $scantronurls{$type},
3869: $scantronfiles{$type});
3870: if ($error ne '') {
3871: $error{$type} = $error;
3872: }
3873: }
3874: if (keys(%error) == 0) {
3875: $is_custom = 1;
3876: $confhash{'scantron'}{'scantronformat'} =
3877: $scantronurls{'custom'};
3878: my $putresult =
3879: &Apache::lonnet::put_dom('configuration',
3880: \%confhash,$dom);
3881: if ($putresult ne 'ok') {
3882: $error{'custom'} =
3883: '<span class="LC_error">'.
3884: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
3885: }
3886: }
3887: } else {
3888: ($scantronurls{'default'},my $error) =
3889: &legacy_scantronformat($r,$dom,$confname,
3890: 'default',$legacyfile{'default'},
3891: $scantronurls{'default'},
3892: $scantronfiles{'default'});
3893: if ($error eq '') {
3894: $confhash{'scantron'}{'scantronformat'} = '';
3895: my $putresult =
3896: &Apache::lonnet::put_dom('configuration',
3897: \%confhash,$dom);
3898: if ($putresult ne 'ok') {
3899: $error{'default'} =
3900: '<span class="LC_error">'.
3901: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
3902: }
3903: } else {
3904: $error{'default'} = $error;
3905: }
3906: }
3907: }
3908: }
3909: } else {
3910: $error{'default'} = &mt("Unable to copy default bubblesheet formatfile to domain's RES space: [_1]",$switchserver);
3911: }
3912: }
3913: if (ref($settings) eq 'HASH') {
3914: if ($settings->{'scantronformat'} eq "/res/$dom/$confname/scantron/custom.tab") {
3915: my @info = &Apache::lonnet::stat_file($settings->{'scantronformat'});
3916: if ((!@info) || ($info[0] eq 'no_such_dir')) {
3917: $scantronurl = '';
3918: } else {
3919: $scantronurl = $settings->{'scantronformat'};
3920: }
3921: $is_custom = 1;
3922: } else {
3923: $scantronurl = $scantronurls{'default'};
3924: }
3925: } else {
3926: if ($is_custom) {
3927: $scantronurl = $scantronurls{'custom'};
3928: } else {
3929: $scantronurl = $scantronurls{'default'};
3930: }
3931: }
3932: $css_class = $itemcount%2?' class="LC_odd_row"':'';
3933: $datatable .= '<tr'.$css_class.'>';
3934: if (!$is_custom) {
3935: $datatable .= '<td>'.&mt('Default in use:').'<br />'.
3936: '<span class="LC_nobreak">';
3937: if ($scantronurl) {
3938: $datatable .= &Apache::loncommon::modal_link($scantronurl,&mt('Default bubblesheet format file'),600,500,
3939: undef,undef,undef,undef,'background-color:#ffffff');
3940: } else {
3941: $datatable = &mt('File unavailable for display');
3942: }
3943: $datatable .= '</span></td>';
3944: if (keys(%error) == 0) {
3945: $datatable .= '<td valign="bottom">';
3946: if (!$switchserver) {
3947: $datatable .= &mt('Upload:').'<br />';
3948: }
3949: } else {
3950: my $errorstr;
3951: foreach my $key (sort(keys(%error))) {
3952: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
3953: }
3954: $datatable .= '<td>'.$errorstr;
3955: }
3956: } else {
3957: if (keys(%error) > 0) {
3958: my $errorstr;
3959: foreach my $key (sort(keys(%error))) {
3960: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
3961: }
3962: $datatable .= '<td>'.$errorstr.'</td><td> ';
3963: } elsif ($scantronurl) {
3964: my $link = &Apache::loncommon::modal_link($scantronurl,&mt('Custom bubblesheet format file'),600,500,
3965: undef,undef,undef,undef,'background-color:#ffffff');
3966: $datatable .= '<td><span class="LC_nobreak">'.
3967: $link.
3968: '<label><input type="checkbox" name="scantronformat_del"'.
3969: ' value="1" />'.&mt('Delete?').'</label></span></td>'.
3970: '<td><span class="LC_nobreak"> '.
3971: &mt('Replace:').'</span><br />';
3972: }
3973: }
3974: if (keys(%error) == 0) {
3975: if ($switchserver) {
3976: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
3977: } else {
3978: $datatable .='<span class="LC_nobreak"> '.
3979: '<input type="file" name="scantronformat" /></span>';
3980: }
3981: }
3982: $datatable .= '</td></tr>';
3983: $$rowtotal ++;
3984: return $datatable;
3985: }
3986:
3987: sub legacy_scantronformat {
3988: my ($r,$dom,$confname,$file,$legacyfile,$newurl,$newfile) = @_;
3989: my ($url,$error);
3990: my @statinfo = &Apache::lonnet::stat_file($newurl);
3991: if ((!@statinfo) || ($statinfo[0] eq 'no_such_dir')) {
3992: (my $result,$url) =
3993: &publishlogo($r,'copy',$legacyfile,$dom,$confname,'scantron',
3994: '','',$newfile);
3995: if ($result ne 'ok') {
3996: $error = &mt("An error occurred publishing the [_1] bubblesheet format file in RES space. Error was: [_2].",$newfile,$result);
3997: }
3998: }
3999: return ($url,$error);
4000: }
4001:
4002: sub print_coursecategories {
4003: my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;
4004: my $datatable;
4005: if ($position eq 'top') {
4006: my $toggle_cats_crs = ' ';
4007: my $toggle_cats_dom = ' checked="checked" ';
4008: my $can_cat_crs = ' ';
4009: my $can_cat_dom = ' checked="checked" ';
4010: my $toggle_catscomm_comm = ' ';
4011: my $toggle_catscomm_dom = ' checked="checked" ';
4012: my $can_catcomm_comm = ' ';
4013: my $can_catcomm_dom = ' checked="checked" ';
4014:
4015: if (ref($settings) eq 'HASH') {
4016: if ($settings->{'togglecats'} eq 'crs') {
4017: $toggle_cats_crs = $toggle_cats_dom;
4018: $toggle_cats_dom = ' ';
4019: }
4020: if ($settings->{'categorize'} eq 'crs') {
4021: $can_cat_crs = $can_cat_dom;
4022: $can_cat_dom = ' ';
4023: }
4024: if ($settings->{'togglecatscomm'} eq 'comm') {
4025: $toggle_catscomm_comm = $toggle_catscomm_dom;
4026: $toggle_catscomm_dom = ' ';
4027: }
4028: if ($settings->{'categorizecomm'} eq 'comm') {
4029: $can_catcomm_comm = $can_catcomm_dom;
4030: $can_catcomm_dom = ' ';
4031: }
4032: }
4033: my %title = &Apache::lonlocal::texthash (
4034: togglecats => 'Show/Hide a course in catalog',
4035: togglecatscomm => 'Show/Hide a community in catalog',
4036: categorize => 'Assign a category to a course',
4037: categorizecomm => 'Assign a category to a community',
4038: );
4039: my %level = &Apache::lonlocal::texthash (
4040: dom => 'Set in Domain',
4041: crs => 'Set in Course',
4042: comm => 'Set in Community',
4043: );
4044: $datatable = '<tr class="LC_odd_row">'.
4045: '<td>'.$title{'togglecats'}.'</td>'.
4046: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4047: '<input type="radio" name="togglecats"'.
4048: $toggle_cats_dom.' value="dom" />'.$level{'dom'}.'</label> '.
4049: '<label><input type="radio" name="togglecats"'.
4050: $toggle_cats_crs.' value="crs" />'.$level{'crs'}.'</label></span></td>'.
4051: '</tr><tr>'.
4052: '<td>'.$title{'categorize'}.'</td>'.
4053: '<td class="LC_right_item"><span class="LC_nobreak">'.
4054: '<label><input type="radio" name="categorize"'.
4055: $can_cat_dom.' value="dom" />'.$level{'dom'}.'</label> '.
4056: '<label><input type="radio" name="categorize"'.
4057: $can_cat_crs.'value="crs" />'.$level{'crs'}.'</label></span></td>'.
4058: '</tr><tr class="LC_odd_row">'.
4059: '<td>'.$title{'togglecatscomm'}.'</td>'.
4060: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4061: '<input type="radio" name="togglecatscomm"'.
4062: $toggle_catscomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
4063: '<label><input type="radio" name="togglecatscomm"'.
4064: $toggle_catscomm_comm.' value="comm" />'.$level{'comm'}.'</label></span></td>'.
4065: '</tr><tr>'.
4066: '<td>'.$title{'categorizecomm'}.'</td>'.
4067: '<td class="LC_right_item"><span class="LC_nobreak">'.
4068: '<label><input type="radio" name="categorizecomm"'.
4069: $can_catcomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
4070: '<label><input type="radio" name="categorizecomm"'.
4071: $can_catcomm_comm.'value="comm" />'.$level{'comm'}.'</label></span></td>'.
4072: '</tr>';
4073: $$rowtotal += 4;
4074: } else {
4075: my $css_class;
4076: my $itemcount = 1;
4077: my $cathash;
4078: if (ref($settings) eq 'HASH') {
4079: $cathash = $settings->{'cats'};
4080: }
4081: if (ref($cathash) eq 'HASH') {
4082: my (@cats,@trails,%allitems,%idx,@jsarray);
4083: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
4084: \%allitems,\%idx,\@jsarray);
4085: my $maxdepth = scalar(@cats);
4086: my $colattrib = '';
4087: if ($maxdepth > 2) {
4088: $colattrib = ' colspan="2" ';
4089: }
4090: my @path;
4091: if (@cats > 0) {
4092: if (ref($cats[0]) eq 'ARRAY') {
4093: my $numtop = @{$cats[0]};
4094: my $maxnum = $numtop;
4095: my %default_names = (
4096: instcode => &mt('Official courses'),
4097: communities => &mt('Communities'),
4098: );
4099:
4100: if ((!grep(/^instcode$/,@{$cats[0]})) ||
4101: ($cathash->{'instcode::0'} eq '') ||
4102: (!grep(/^communities$/,@{$cats[0]})) ||
4103: ($cathash->{'communities::0'} eq '')) {
4104: $maxnum ++;
4105: }
4106: my $lastidx;
4107: for (my $i=0; $i<$numtop; $i++) {
4108: my $parent = $cats[0][$i];
4109: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4110: my $item = &escape($parent).'::0';
4111: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$item','$idx{$item}'".');"';
4112: $lastidx = $idx{$item};
4113: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
4114: .'<select name="'.$item.'"'.$chgstr.'>';
4115: for (my $k=0; $k<=$maxnum; $k++) {
4116: my $vpos = $k+1;
4117: my $selstr;
4118: if ($k == $i) {
4119: $selstr = ' selected="selected" ';
4120: }
4121: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4122: }
4123: $datatable .= '</select></td><td>';
4124: if ($parent eq 'instcode' || $parent eq 'communities') {
4125: $datatable .= '<span class="LC_nobreak">'
4126: .$default_names{$parent}.'</span>';
4127: if ($parent eq 'instcode') {
4128: $datatable .= '<br /><span class="LC_nobreak">('
4129: .&mt('with institutional codes')
4130: .')</span></td><td'.$colattrib.'>';
4131: } else {
4132: $datatable .= '<table><tr><td>';
4133: }
4134: $datatable .= '<span class="LC_nobreak">'
4135: .'<label><input type="radio" name="'
4136: .$parent.'" value="1" checked="checked" />'
4137: .&mt('Display').'</label>';
4138: if ($parent eq 'instcode') {
4139: $datatable .= ' ';
4140: } else {
4141: $datatable .= '</span></td></tr><tr><td>'
4142: .'<span class="LC_nobreak">';
4143: }
4144: $datatable .= '<label><input type="radio" name="'
4145: .$parent.'" value="0" />'
4146: .&mt('Do not display').'</label></span>';
4147: if ($parent eq 'communities') {
4148: $datatable .= '</td></tr></table>';
4149: }
4150: $datatable .= '</td>';
4151: } else {
4152: $datatable .= $parent
4153: .' <label><input type="checkbox" name="deletecategory" '
4154: .'value="'.$item.'" />'.&mt('Delete').'</label></span></td>';
4155: }
4156: my $depth = 1;
4157: push(@path,$parent);
4158: $datatable .= &build_category_rows($itemcount,\@cats,$depth,$parent,\@path,\%idx);
4159: pop(@path);
4160: $datatable .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
4161: $itemcount ++;
4162: }
4163: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4164: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','$lastidx'".');"';
4165: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="addcategory_pos"'.$chgstr.'>';
4166: for (my $k=0; $k<=$maxnum; $k++) {
4167: my $vpos = $k+1;
4168: my $selstr;
4169: if ($k == $numtop) {
4170: $selstr = ' selected="selected" ';
4171: }
4172: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4173: }
4174: $datatable .= '</select></span></td><td colspan="2">'.&mt('Add category:').' '
4175: .'<input type="text" size="20" name="addcategory_name" value="" /></td>'
4176: .'</tr>'."\n";
4177: $itemcount ++;
4178: foreach my $default ('instcode','communities') {
4179: if ((!grep(/^\Q$default\E$/,@{$cats[0]})) || ($cathash->{$default.'::0'} eq '')) {
4180: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4181: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','$lastidx'".');"';
4182: $datatable .= '<tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr><tr '.$css_class.'><td>'.
4183: '<span class="LC_nobreak"><select name="'.$default.'_pos"'.$chgstr.'>';
4184: for (my $k=0; $k<=$maxnum; $k++) {
4185: my $vpos = $k+1;
4186: my $selstr;
4187: if ($k == $maxnum) {
4188: $selstr = ' selected="selected" ';
4189: }
4190: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4191: }
4192: $datatable .= '</select></span></td>'.
4193: '<td><span class="LC_nobreak">'.
4194: $default_names{$default}.'</span>';
4195: if ($default eq 'instcode') {
4196: $datatable .= '<br /><span class="LC_nobreak">('
4197: .&mt('with institutional codes').')</span>';
4198: }
4199: $datatable .= '</td>'
4200: .'<td><span class="LC_nobreak"><label><input type="radio" name="'.$default.'" value="1" />'
4201: .&mt('Display').'</label> '
4202: .'<label><input type="radio" name="'.$default.'" value="0" checked="checked"/>'
4203: .&mt('Do not display').'</label></span></td></tr>';
4204: }
4205: }
4206: }
4207: } else {
4208: $datatable .= &initialize_categories($itemcount);
4209: }
4210: } else {
4211: $datatable .= '<td class="LC_right_item">'.$hdritem->{'header'}->[0]->{'col2'}.'</td>'
4212: .&initialize_categories($itemcount);
4213: }
4214: $$rowtotal += $itemcount;
4215: }
4216: return $datatable;
4217: }
4218:
4219: sub print_serverstatuses {
4220: my ($dom,$settings,$rowtotal) = @_;
4221: my $datatable;
4222: my @pages = &serverstatus_pages();
4223: my (%namedaccess,%machineaccess);
4224: foreach my $type (@pages) {
4225: $namedaccess{$type} = '';
4226: $machineaccess{$type}= '';
4227: }
4228: if (ref($settings) eq 'HASH') {
4229: foreach my $type (@pages) {
4230: if (exists($settings->{$type})) {
4231: if (ref($settings->{$type}) eq 'HASH') {
4232: foreach my $key (keys(%{$settings->{$type}})) {
4233: if ($key eq 'namedusers') {
4234: $namedaccess{$type} = $settings->{$type}->{$key};
4235: } elsif ($key eq 'machines') {
4236: $machineaccess{$type} = $settings->{$type}->{$key};
4237: }
4238: }
4239: }
4240: }
4241: }
4242: }
4243: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
4244: my $rownum = 0;
4245: my $css_class;
4246: foreach my $type (@pages) {
4247: $rownum ++;
4248: $css_class = $rownum%2?' class="LC_odd_row"':'';
4249: $datatable .= '<tr'.$css_class.'>'.
4250: '<td><span class="LC_nobreak">'.
4251: $titles->{$type}.'</span></td>'.
4252: '<td class="LC_left_item">'.
4253: '<input type="text" name="'.$type.'_namedusers" '.
4254: 'value="'.$namedaccess{$type}.'" size="30" /></td>'.
4255: '<td class="LC_right_item">'.
4256: '<span class="LC_nobreak">'.
4257: '<input type="text" name="'.$type.'_machines" '.
4258: 'value="'.$machineaccess{$type}.'" size="10" />'.
4259: '</td></tr>'."\n";
4260: }
4261: $$rowtotal += $rownum;
4262: return $datatable;
4263: }
4264:
4265: sub serverstatus_pages {
4266: return ('userstatus','lonstatus','loncron','server-status','codeversions',
4267: 'checksums','clusterstatus','metadata_keywords','metadata_harvest',
4268: 'takeoffline','takeonline','showenv','toggledebug','ping','domconf');
4269: }
4270:
4271: sub coursecategories_javascript {
4272: my ($settings) = @_;
4273: my ($output,$jstext,$cathash);
4274: if (ref($settings) eq 'HASH') {
4275: $cathash = $settings->{'cats'};
4276: }
4277: if (ref($cathash) eq 'HASH') {
4278: my (@cats,@jsarray,%idx);
4279: &Apache::loncommon::gather_categories($cathash,\@cats,\%idx,\@jsarray);
4280: if (@jsarray > 0) {
4281: $jstext = ' var categories = Array('.scalar(@jsarray).');'."\n";
4282: for (my $i=0; $i<@jsarray; $i++) {
4283: if (ref($jsarray[$i]) eq 'ARRAY') {
4284: my $catstr = join('","',@{$jsarray[$i]});
4285: $jstext .= ' categories['.$i.'] = Array("'.$catstr.'");'."\n";
4286: }
4287: }
4288: }
4289: } else {
4290: $jstext = ' var categories = Array(1);'."\n".
4291: ' categories[0] = Array("instcode_pos");'."\n";
4292: }
4293: my $instcode_reserved = &mt('The name: "instcode" is a reserved category');
4294: my $communities_reserved = &mt('The name: "communities" is a reserved category');
4295: my $choose_again = '\\n'.&mt('Please use a different name for the new top level category');
4296: $output = <<"ENDSCRIPT";
4297: <script type="text/javascript">
4298: // <![CDATA[
4299: function reorderCats(form,parent,item,idx) {
4300: var changedVal;
4301: $jstext
4302: var newpos = 'addcategory_pos';
4303: var current = new Array;
4304: if (parent == '') {
4305: var has_instcode = 0;
4306: var maxtop = categories[idx].length;
4307: for (var j=0; j<maxtop; j++) {
4308: if (categories[idx][j] == 'instcode::0') {
4309: has_instcode == 1;
4310: }
4311: }
4312: if (has_instcode == 0) {
4313: categories[idx][maxtop] = 'instcode_pos';
4314: }
4315: } else {
4316: newpos += '_'+parent;
4317: }
4318: var maxh = 1 + categories[idx].length;
4319: var current = new Array;
4320: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
4321: if (item == newpos) {
4322: changedVal = newitemVal;
4323: } else {
4324: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
4325: current[newitemVal] = newpos;
4326: }
4327: for (var i=0; i<categories[idx].length; i++) {
4328: var elementName = categories[idx][i];
4329: if (elementName != item) {
4330: if (form.elements[elementName]) {
4331: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
4332: current[currVal] = elementName;
4333: }
4334: }
4335: }
4336: var oldVal;
4337: for (var j=0; j<maxh; j++) {
4338: if (current[j] == undefined) {
4339: oldVal = j;
4340: }
4341: }
4342: if (oldVal < changedVal) {
4343: for (var k=oldVal+1; k<=changedVal ; k++) {
4344: var elementName = current[k];
4345: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
4346: }
4347: } else {
4348: for (var k=changedVal; k<oldVal; k++) {
4349: var elementName = current[k];
4350: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
4351: }
4352: }
4353: return;
4354: }
4355:
4356: function categoryCheck(form) {
4357: if (form.elements['addcategory_name'].value == 'instcode') {
4358: alert('$instcode_reserved\\n$choose_again');
4359: return false;
4360: }
4361: if (form.elements['addcategory_name'].value == 'communities') {
4362: alert('$communities_reserved\\n$choose_again');
4363: return false;
4364: }
4365: return true;
4366: }
4367:
4368: // ]]>
4369: </script>
4370:
4371: ENDSCRIPT
4372: return $output;
4373: }
4374:
4375: sub initialize_categories {
4376: my ($itemcount) = @_;
4377: my ($datatable,$css_class,$chgstr);
4378: my %default_names = (
4379: instcode => 'Official courses (with institutional codes)',
4380: communities => 'Communities',
4381: );
4382: my $select0 = ' selected="selected"';
4383: my $select1 = '';
4384: foreach my $default ('instcode','communities') {
4385: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4386: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'',$default"."_pos','0'".');"';
4387: if ($default eq 'communities') {
4388: $select1 = $select0;
4389: $select0 = '';
4390: }
4391: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
4392: .'<select name="'.$default.'_pos">'
4393: .'<option value="0"'.$select0.'>1</option>'
4394: .'<option value="1"'.$select1.'>2</option>'
4395: .'<option value="2">3</option></select> '
4396: .$default_names{$default}
4397: .'</span></td><td><span class="LC_nobreak">'
4398: .'<label><input type="radio" name="'.$default.'" value="1" checked="checked" />'
4399: .&mt('Display').'</label> <label>'
4400: .'<input type="radio" name="'.$default.'" value="0" />'.&mt('Do not display')
4401: .'</label></span></td></tr>';
4402: $itemcount ++;
4403: }
4404: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4405: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','0'".');"';
4406: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
4407: .'<select name="addcategory_pos"'.$chgstr.'>'
4408: .'<option value="0">1</option>'
4409: .'<option value="1">2</option>'
4410: .'<option value="2" selected="selected">3</option></select> '
4411: .&mt('Add category').'</td><td>'.&mt('Name:')
4412: .' <input type="text" size="20" name="addcategory_name" value="" /></td></tr>';
4413: return $datatable;
4414: }
4415:
4416: sub build_category_rows {
4417: my ($itemcount,$cats,$depth,$parent,$path,$idx) = @_;
4418: my ($text,$name,$item,$chgstr);
4419: if (ref($cats) eq 'ARRAY') {
4420: my $maxdepth = scalar(@{$cats});
4421: if (ref($cats->[$depth]) eq 'HASH') {
4422: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
4423: my $numchildren = @{$cats->[$depth]{$parent}};
4424: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
4425: $text .= '<td><table class="LC_datatable">';
4426: my ($idxnum,$parent_name,$parent_item);
4427: my $higher = $depth - 1;
4428: if ($higher == 0) {
4429: $parent_name = &escape($parent).'::'.$higher;
4430: } else {
4431: if (ref($path) eq 'ARRAY') {
4432: $parent_name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
4433: }
4434: }
4435: $parent_item = 'addcategory_pos_'.$parent_name;
4436: for (my $j=0; $j<=$numchildren; $j++) {
4437: if ($j < $numchildren) {
4438: $name = $cats->[$depth]{$parent}[$j];
4439: $item = &escape($name).':'.&escape($parent).':'.$depth;
4440: $idxnum = $idx->{$item};
4441: } else {
4442: $name = $parent_name;
4443: $item = $parent_item;
4444: }
4445: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'$parent_name','$item','$idxnum'".');"';
4446: $text .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="'.$item.'"'.$chgstr.'>';
4447: for (my $i=0; $i<=$numchildren; $i++) {
4448: my $vpos = $i+1;
4449: my $selstr;
4450: if ($j == $i) {
4451: $selstr = ' selected="selected" ';
4452: }
4453: $text .= '<option value="'.$i.'"'.$selstr.'>'.$vpos.'</option>';
4454: }
4455: $text .= '</select> ';
4456: if ($j < $numchildren) {
4457: my $deeper = $depth+1;
4458: $text .= $name.' '
4459: .'<label><input type="checkbox" name="deletecategory" value="'
4460: .$item.'" />'.&mt('Delete').'</label></span></td><td>';
4461: if(ref($path) eq 'ARRAY') {
4462: push(@{$path},$name);
4463: $text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path,$idx);
4464: pop(@{$path});
4465: }
4466: } else {
4467: $text .= &mt('Add subcategory:').' </span><input type="textbox" size="20" name="addcategory_name_';
4468: if ($j == $numchildren) {
4469: $text .= $name;
4470: } else {
4471: $text .= $item;
4472: }
4473: $text .= '" value="" />';
4474: }
4475: $text .= '</td></tr>';
4476: }
4477: $text .= '</table></td>';
4478: } else {
4479: my $higher = $depth-1;
4480: if ($higher == 0) {
4481: $name = &escape($parent).'::'.$higher;
4482: } else {
4483: if (ref($path) eq 'ARRAY') {
4484: $name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
4485: }
4486: }
4487: my $colspan;
4488: if ($parent ne 'instcode') {
4489: $colspan = $maxdepth - $depth - 1;
4490: $text .= '<td colspan="'.$colspan.'">'.&mt('Add subcategory:').'<input type="textbox" size="20" name="subcat_'.$name.'" value="" /></td>';
4491: }
4492: }
4493: }
4494: }
4495: return $text;
4496: }
4497:
4498: sub modifiable_userdata_row {
4499: my ($context,$role,$settings,$numinrow,$rowcount,$usertypes) = @_;
4500: my $rolename;
4501: if ($context eq 'selfcreate') {
4502: if (ref($usertypes) eq 'HASH') {
4503: $rolename = $usertypes->{$role};
4504: } else {
4505: $rolename = $role;
4506: }
4507: } else {
4508: if ($role eq 'cr') {
4509: $rolename = &mt('Custom role');
4510: } else {
4511: $rolename = &Apache::lonnet::plaintext($role);
4512: }
4513: }
4514: my @fields = ('lastname','firstname','middlename','generation',
4515: 'permanentemail','id');
4516: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
4517: my $output;
4518: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
4519: $output = '<tr '.$css_class.'>'.
4520: '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
4521: '<td class="LC_left_item" colspan="2"><table>';
4522: my $rem;
4523: my %checks;
4524: if (ref($settings) eq 'HASH') {
4525: if (ref($settings->{$context}) eq 'HASH') {
4526: if (ref($settings->{$context}->{$role}) eq 'HASH') {
4527: foreach my $field (@fields) {
4528: if ($settings->{$context}->{$role}->{$field}) {
4529: $checks{$field} = ' checked="checked" ';
4530: }
4531: }
4532: }
4533: }
4534: }
4535: for (my $i=0; $i<@fields; $i++) {
4536: my $rem = $i%($numinrow);
4537: if ($rem == 0) {
4538: if ($i > 0) {
4539: $output .= '</tr>';
4540: }
4541: $output .= '<tr>';
4542: }
4543: my $check = ' ';
4544: if (exists($checks{$fields[$i]})) {
4545: $check = $checks{$fields[$i]}
4546: } else {
4547: if ($role eq 'st') {
4548: if (ref($settings) ne 'HASH') {
4549: $check = ' checked="checked" ';
4550: }
4551: }
4552: }
4553: $output .= '<td class="LC_left_item">'.
4554: '<span class="LC_nobreak"><label>'.
4555: '<input type="checkbox" name="canmodify_'.$role.'" '.
4556: 'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
4557: '</label></span></td>';
4558: $rem = @fields%($numinrow);
4559: }
4560: my $colsleft = $numinrow - $rem;
4561: if ($colsleft > 1 ) {
4562: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
4563: ' </td>';
4564: } elsif ($colsleft == 1) {
4565: $output .= '<td class="LC_left_item"> </td>';
4566: }
4567: $output .= '</tr></table></td></tr>';
4568: return $output;
4569: }
4570:
4571: sub insttypes_row {
4572: my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle,$context) = @_;
4573: my %lt = &Apache::lonlocal::texthash (
4574: cansearch => 'Users allowed to search',
4575: statustocreate => 'Institutional affiliation(s) able to create own account (login/SSO)',
4576: lockablenames => 'User preference to lock name',
4577: );
4578: my $showdom;
4579: if ($context eq 'cansearch') {
4580: $showdom = ' ('.$dom.')';
4581: }
4582: my $class = 'LC_left_item';
4583: if ($context eq 'statustocreate') {
4584: $class = 'LC_right_item';
4585: }
4586: my $output = '<tr class="LC_odd_row">'.
4587: '<td>'.$lt{$context}.$showdom.
4588: '</td><td class="'.$class.'" colspan="2"><table>';
4589: my $rem;
4590: if (ref($types) eq 'ARRAY') {
4591: for (my $i=0; $i<@{$types}; $i++) {
4592: if (defined($usertypes->{$types->[$i]})) {
4593: my $rem = $i%($numinrow);
4594: if ($rem == 0) {
4595: if ($i > 0) {
4596: $output .= '</tr>';
4597: }
4598: $output .= '<tr>';
4599: }
4600: my $check = ' ';
4601: if (ref($settings) eq 'HASH') {
4602: if (ref($settings->{$context}) eq 'ARRAY') {
4603: if (grep(/^\Q$types->[$i]\E$/,@{$settings->{$context}})) {
4604: $check = ' checked="checked" ';
4605: }
4606: } elsif ($context eq 'statustocreate') {
4607: $check = ' checked="checked" ';
4608: }
4609: }
4610: $output .= '<td class="LC_left_item">'.
4611: '<span class="LC_nobreak"><label>'.
4612: '<input type="checkbox" name="'.$context.'" '.
4613: 'value="'.$types->[$i].'"'.$check.'/>'.
4614: $usertypes->{$types->[$i]}.'</label></span></td>';
4615: }
4616: }
4617: $rem = @{$types}%($numinrow);
4618: }
4619: my $colsleft = $numinrow - $rem;
4620: if (($rem == 0) && (@{$types} > 0)) {
4621: $output .= '<tr>';
4622: }
4623: if ($colsleft > 1) {
4624: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
4625: } else {
4626: $output .= '<td class="LC_left_item">';
4627: }
4628: my $defcheck = ' ';
4629: if (ref($settings) eq 'HASH') {
4630: if (ref($settings->{$context}) eq 'ARRAY') {
4631: if (grep(/^default$/,@{$settings->{$context}})) {
4632: $defcheck = ' checked="checked" ';
4633: }
4634: } elsif ($context eq 'statustocreate') {
4635: $defcheck = ' checked="checked" ';
4636: }
4637: }
4638: $output .= '<span class="LC_nobreak"><label>'.
4639: '<input type="checkbox" name="'.$context.'" '.
4640: 'value="default"'.$defcheck.'/>'.
4641: $othertitle.'</label></span></td>'.
4642: '</tr></table></td></tr>';
4643: return $output;
4644: }
4645:
4646: sub sorted_searchtitles {
4647: my %searchtitles = &Apache::lonlocal::texthash(
4648: 'uname' => 'username',
4649: 'lastname' => 'last name',
4650: 'lastfirst' => 'last name, first name',
4651: );
4652: my @titleorder = ('uname','lastname','lastfirst');
4653: return (\%searchtitles,\@titleorder);
4654: }
4655:
4656: sub sorted_searchtypes {
4657: my %srchtypes_desc = (
4658: exact => 'is exact match',
4659: contains => 'contains ..',
4660: begins => 'begins with ..',
4661: );
4662: my @srchtypeorder = ('exact','begins','contains');
4663: return (\%srchtypes_desc,\@srchtypeorder);
4664: }
4665:
4666: sub usertype_update_row {
4667: my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
4668: my $datatable;
4669: my $numinrow = 4;
4670: foreach my $type (@{$types}) {
4671: if (defined($usertypes->{$type})) {
4672: $$rownums ++;
4673: my $css_class = $$rownums%2?' class="LC_odd_row"':'';
4674: $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
4675: '</td><td class="LC_left_item"><table>';
4676: for (my $i=0; $i<@{$fields}; $i++) {
4677: my $rem = $i%($numinrow);
4678: if ($rem == 0) {
4679: if ($i > 0) {
4680: $datatable .= '</tr>';
4681: }
4682: $datatable .= '<tr>';
4683: }
4684: my $check = ' ';
4685: if (ref($settings) eq 'HASH') {
4686: if (ref($settings->{'fields'}) eq 'HASH') {
4687: if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
4688: if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
4689: $check = ' checked="checked" ';
4690: }
4691: }
4692: }
4693: }
4694:
4695: if ($i == @{$fields}-1) {
4696: my $colsleft = $numinrow - $rem;
4697: if ($colsleft > 1) {
4698: $datatable .= '<td colspan="'.$colsleft.'">';
4699: } else {
4700: $datatable .= '<td>';
4701: }
4702: } else {
4703: $datatable .= '<td>';
4704: }
4705: $datatable .= '<span class="LC_nobreak"><label>'.
4706: '<input type="checkbox" name="updateable_'.$type.
4707: '_'.$fields->[$i].'" value="1"'.$check.'/>'.
4708: $fieldtitles->{$fields->[$i]}.'</label></span></td>';
4709: }
4710: $datatable .= '</tr></table></td></tr>';
4711: }
4712: }
4713: return $datatable;
4714: }
4715:
4716: sub modify_login {
4717: my ($r,$dom,$confname,%domconfig) = @_;
4718: my ($resulttext,$errors,$colchgtext,%changes,%colchanges,%newfile,%newurl,
4719: %curr_loginvia,%loginhash,@currlangs,@newlangs,$addedfile,%title,@offon);
4720: %title = ( coursecatalog => 'Display course catalog',
4721: adminmail => 'Display administrator E-mail address',
4722: helpdesk => 'Display "Contact Helpdesk" link',
4723: newuser => 'Link for visitors to create a user account',
4724: loginheader => 'Log-in box header');
4725: @offon = ('off','on');
4726: if (ref($domconfig{login}) eq 'HASH') {
4727: if (ref($domconfig{login}{loginvia}) eq 'HASH') {
4728: foreach my $lonhost (keys(%{$domconfig{login}{loginvia}})) {
4729: $curr_loginvia{$lonhost} = $domconfig{login}{loginvia}{$lonhost};
4730: }
4731: }
4732: }
4733: ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
4734: \%domconfig,\%loginhash);
4735: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
4736: foreach my $item (@toggles) {
4737: $loginhash{login}{$item} = $env{'form.'.$item};
4738: }
4739: $loginhash{login}{loginheader} = $env{'form.loginheader'};
4740: if (ref($colchanges{'login'}) eq 'HASH') {
4741: $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
4742: \%loginhash);
4743: }
4744:
4745: my %servers = &Apache::lonnet::internet_dom_servers($dom);
4746: my @loginvia_attribs = ('serverpath','custompath','exempt');
4747: if (keys(%servers) > 1) {
4748: foreach my $lonhost (keys(%servers)) {
4749: next if ($env{'form.'.$lonhost.'_server'} eq $lonhost);
4750: if (ref($curr_loginvia{$lonhost}) eq 'HASH') {
4751: if ($env{'form.'.$lonhost.'_server'} eq $curr_loginvia{$lonhost}{'server'}) {
4752: $loginhash{login}{loginvia}{$lonhost}{'server'} = $curr_loginvia{$lonhost}{'server'};
4753: } elsif ($curr_loginvia{$lonhost}{'server'} ne '') {
4754: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
4755: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
4756: $changes{'loginvia'}{$lonhost} = 1;
4757: } else {
4758: $loginhash{login}{loginvia}{$lonhost}{'server'} = '';
4759: $changes{'loginvia'}{$lonhost} = 1;
4760: }
4761: } else {
4762: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
4763: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
4764: $changes{'loginvia'}{$lonhost} = 1;
4765: }
4766: }
4767: if ($loginhash{login}{loginvia}{$lonhost}{'server'} eq '') {
4768: foreach my $item (@loginvia_attribs) {
4769: $loginhash{login}{loginvia}{$lonhost}{$item} = '';
4770: }
4771: } else {
4772: foreach my $item (@loginvia_attribs) {
4773: my $new = $env{'form.'.$lonhost.'_'.$item};
4774: if (($item eq 'serverpath') && ($new eq 'custom')) {
4775: $env{'form.'.$lonhost.'_custompath'} =~ s/\s+//g;
4776: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
4777: $new = '/';
4778: }
4779: }
4780: if (($item eq 'custompath') &&
4781: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
4782: $new = '';
4783: }
4784: if ($new ne $curr_loginvia{$lonhost}{$item}) {
4785: $changes{'loginvia'}{$lonhost} = 1;
4786: }
4787: if ($item eq 'exempt') {
4788: $new =~ s/^\s+//;
4789: $new =~ s/\s+$//;
4790: my @poss_ips = split(/\s*[,:]\s*/,$new);
4791: my @okips;
4792: foreach my $ip (@poss_ips) {
4793: if ($ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
4794: if (($1 <= 255) && ($2 <= 255) && ($3 <= 255) && ($4 <= 255)) {
4795: push(@okips,$ip);
4796: }
4797: }
4798: }
4799: if (@okips > 0) {
4800: $new = join(',',@okips);
4801: } else {
4802: $new = '';
4803: }
4804: }
4805: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
4806: }
4807: }
4808: } else {
4809: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
4810: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
4811: $changes{'loginvia'}{$lonhost} = 1;
4812: foreach my $item (@loginvia_attribs) {
4813: my $new = $env{'form.'.$lonhost.'_'.$item};
4814: if (($item eq 'serverpath') && ($new eq 'custom')) {
4815: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
4816: $new = '/';
4817: }
4818: }
4819: if (($item eq 'custompath') &&
4820: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
4821: $new = '';
4822: }
4823: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
4824: }
4825: }
4826: }
4827: }
4828: }
4829:
4830: my $servadm = $r->dir_config('lonAdmEMail');
4831: my %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
4832: if (ref($domconfig{'login'}) eq 'HASH') {
4833: if (ref($domconfig{'login'}{'helpurl'}) eq 'HASH') {
4834: foreach my $lang (sort(keys(%{$domconfig{'login'}{'helpurl'}}))) {
4835: if ($lang eq 'nolang') {
4836: push(@currlangs,$lang);
4837: } elsif (defined($langchoices{$lang})) {
4838: push(@currlangs,$lang);
4839: } else {
4840: next;
4841: }
4842: }
4843: }
4844: }
4845: my @delurls = &Apache::loncommon::get_env_multiple('form.loginhelpurl_del');
4846: if (@currlangs > 0) {
4847: foreach my $lang (@currlangs) {
4848: if (grep(/^\Q$lang\E$/,@delurls)) {
4849: $changes{'helpurl'}{$lang} = 1;
4850: } elsif ($env{'form.loginhelpurl_'.$lang.'.filename'}) {
4851: $changes{'helpurl'}{$lang} = 1;
4852: $newfile{$lang} = $env{'form.loginhelpurl_'.$lang.'.filename'};
4853: push(@newlangs,$lang);
4854: } else {
4855: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
4856: }
4857: }
4858: }
4859: unless (grep(/^nolang$/,@currlangs)) {
4860: if ($env{'form.loginhelpurl_nolang.filename'}) {
4861: $changes{'helpurl'}{'nolang'} = 1;
4862: $newfile{'nolang'} = $env{'form.loginhelpurl_nolang.filename'};
4863: push(@newlangs,'nolang');
4864: }
4865: }
4866: if ($env{'form.loginhelpurl_add_lang'}) {
4867: if ((defined($langchoices{$env{'form.loginhelpurl_add_lang'}})) &&
4868: ($env{'form.loginhelpurl_add_file.filename'})) {
4869: $newfile{$env{'form.loginhelpurl_add_lang'}} = $env{'form.loginhelpurl_add_file.filename'};
4870: $addedfile = $env{'form.loginhelpurl_add_lang'};
4871: }
4872: }
4873: if ((@newlangs > 0) || ($addedfile)) {
4874: my $error;
4875: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
4876: if ($configuserok eq 'ok') {
4877: if ($switchserver) {
4878: $error = &mt("Upload of custom help file is not permitted to this server: [_1]",$switchserver);
4879: } elsif ($author_ok eq 'ok') {
4880: my @allnew = @newlangs;
4881: if ($addedfile ne '') {
4882: push(@allnew,$addedfile);
4883: }
4884: foreach my $lang (@allnew) {
4885: my $formelem = 'loginhelpurl_'.$lang;
4886: if ($lang eq $env{'form.loginhelpurl_add_lang'}) {
4887: $formelem = 'loginhelpurl_add_file';
4888: }
4889: (my $result,$newurl{$lang}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
4890: "help/$lang",'','',$newfile{$lang});
4891: if ($result eq 'ok') {
4892: $loginhash{'login'}{'helpurl'}{$lang} = $newurl{$lang};
4893: $changes{'helpurl'}{$lang} = 1;
4894: } else {
4895: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$newfile{$lang},$result);
4896: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
4897: if ((grep(/^\Q$lang\E$/,@currlangs)) &&
4898: (!grep(/^\Q$lang\E$/,@delurls))) {
4899:
4900: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
4901: }
4902: }
4903: }
4904: } else {
4905: $error = &mt("Upload of custom log-in help file(s) failed because an author role could not be assigned to a Domain Configuration user ([_1]) in domain: [_2]. Error was: [_3].",$confname,$dom,$author_ok);
4906: }
4907: } else {
4908: $error = &mt("Upload of custom log-in help file(s) failed because a Domain Configuration user ([_1]) could not be created in domain: [_2]. Error was: [_3].",$confname,$dom,$configuserok);
4909: }
4910: if ($error) {
4911: &Apache::lonnet::logthis($error);
4912: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
4913: }
4914: }
4915: &process_captcha('login',\%changes,$loginhash{'login'},$domconfig{'login'});
4916:
4917: my $defaulthelpfile = '/adm/loginproblems.html';
4918: my $defaulttext = &mt('Default in use');
4919:
4920: my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
4921: $dom);
4922: if ($putresult eq 'ok') {
4923: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
4924: my %defaultchecked = (
4925: 'coursecatalog' => 'on',
4926: 'helpdesk' => 'on',
4927: 'adminmail' => 'off',
4928: 'newuser' => 'off',
4929: );
4930: if (ref($domconfig{'login'}) eq 'HASH') {
4931: foreach my $item (@toggles) {
4932: if ($defaultchecked{$item} eq 'on') {
4933: if (($domconfig{'login'}{$item} eq '0') &&
4934: ($env{'form.'.$item} eq '1')) {
4935: $changes{$item} = 1;
4936: } elsif (($domconfig{'login'}{$item} eq '' ||
4937: $domconfig{'login'}{$item} eq '1') &&
4938: ($env{'form.'.$item} eq '0')) {
4939: $changes{$item} = 1;
4940: }
4941: } elsif ($defaultchecked{$item} eq 'off') {
4942: if (($domconfig{'login'}{$item} eq '1') &&
4943: ($env{'form.'.$item} eq '0')) {
4944: $changes{$item} = 1;
4945: } elsif (($domconfig{'login'}{$item} eq '' ||
4946: $domconfig{'login'}{$item} eq '0') &&
4947: ($env{'form.'.$item} eq '1')) {
4948: $changes{$item} = 1;
4949: }
4950: }
4951: }
4952: }
4953: if (keys(%changes) > 0 || $colchgtext) {
4954: &Apache::loncommon::devalidate_domconfig_cache($dom);
4955: $resulttext = &mt('Changes made:').'<ul>';
4956: foreach my $item (sort(keys(%changes))) {
4957: if ($item eq 'loginvia') {
4958: if (ref($changes{$item}) eq 'HASH') {
4959: $resulttext .= '<li>'.&mt('Log-in page availability:').'<ul>';
4960: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
4961: if (defined($servers{$loginhash{login}{loginvia}{$lonhost}{'server'}})) {
4962: if (ref($loginhash{login}{loginvia}{$lonhost}) eq 'HASH') {
4963: my $protocol = $Apache::lonnet::protocol{$env{'form.'.$lonhost.'_server'}};
4964: $protocol = 'http' if ($protocol ne 'https');
4965: my $target = $protocol.'://'.$servers{$env{'form.'.$lonhost.'_server'}};
4966:
4967: if ($loginhash{login}{loginvia}{$lonhost}{'serverpath'} eq 'custom') {
4968: $target .= $loginhash{login}{loginvia}{$lonhost}{'custompath'};
4969: } else {
4970: $target .= $loginhash{login}{loginvia}{$lonhost}{'serverpath'};
4971: }
4972: $resulttext .= '<li>'.&mt('Server: [_1] log-in page redirects to [_2].',$servers{$lonhost},'<a href="'.$target.'">'.$target.'</a>');
4973: if ($loginhash{login}{loginvia}{$lonhost}{'exempt'} ne '') {
4974: $resulttext .= ' '.&mt('No redirection for clients from following IPs:').' '.$loginhash{login}{loginvia}{$lonhost}{'exempt'};
4975: }
4976: $resulttext .= '</li>';
4977: } else {
4978: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$lonhost).'</li>';
4979: }
4980: } else {
4981: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$servers{$lonhost}).'</li>';
4982: }
4983: }
4984: $resulttext .= '</ul></li>';
4985: }
4986: } elsif ($item eq 'helpurl') {
4987: if (ref($changes{$item}) eq 'HASH') {
4988: foreach my $lang (sort(keys(%{$changes{$item}}))) {
4989: if (grep(/^\Q$lang\E$/,@delurls)) {
4990: my ($chg,$link);
4991: $link = &Apache::loncommon::modal_link($defaulthelpfile,$defaulttext,600,500);
4992: if ($lang eq 'nolang') {
4993: $chg = &mt('custom log-in help file removed for no preferred language; [_1]',$link);
4994: } else {
4995: $chg = &mt('custom log-in help file removed for specific language: [_1]; [_2]',$langchoices{$lang},$link);
4996: }
4997: $resulttext .= '<li>'.$chg.'</li>';
4998: } else {
4999: my $chg;
5000: if ($lang eq 'nolang') {
5001: $chg = &mt('custom log-in help file for no preferred language');
5002: } else {
5003: $chg = &mt('custom log-in help file for specific language: [_1]',$langchoices{$lang});
5004: }
5005: $resulttext .= '<li>'.&Apache::loncommon::modal_link(
5006: $loginhash{'login'}{'helpurl'}{$lang}.
5007: '?inhibitmenu=yes',$chg,600,500).
5008: '</li>';
5009: }
5010: }
5011: }
5012: } elsif ($item eq 'captcha') {
5013: if (ref($loginhash{'login'}) eq 'HASH') {
5014: my $chgtxt;
5015: if ($loginhash{'login'}{$item} eq 'notused') {
5016: $chgtxt .= &mt('No CAPTCHA validation in use for helpdesk form.');
5017: } else {
5018: my %captchas = &captcha_phrases();
5019: if ($captchas{$loginhash{'login'}{$item}}) {
5020: $chgtxt .= &mt("Validation for helpdesk form set to $captchas{$loginhash{'login'}{$item}}.");
5021: } else {
5022: $chgtxt .= &mt('Validation for helpdesk form set to unknown type.');
5023: }
5024: }
5025: $resulttext .= '<li>'.$chgtxt.'</li>';
5026: }
5027: } elsif ($item eq 'recaptchakeys') {
5028: if (ref($loginhash{'login'}) eq 'HASH') {
5029: my ($privkey,$pubkey);
5030: if (ref($loginhash{'login'}{$item}) eq 'HASH') {
5031: $pubkey = $loginhash{'login'}{$item}{'public'};
5032: $privkey = $loginhash{'login'}{$item}{'private'};
5033: }
5034: my $chgtxt .= &mt('ReCAPTCHA keys changes').'<ul>';
5035: if (!$pubkey) {
5036: $chgtxt .= '<li>'.&mt('Public key deleted').'</li>';
5037: } else {
5038: $chgtxt .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
5039: }
5040: if (!$privkey) {
5041: $chgtxt .= '<li>'.&mt('Private key deleted').'</li>';
5042: } else {
5043: $chgtxt .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
5044: }
5045: $chgtxt .= '</ul>';
5046: $resulttext .= '<li>'.$chgtxt.'</li>';
5047: }
5048: } else {
5049: $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
5050: }
5051: }
5052: $resulttext .= $colchgtext.'</ul>';
5053: } else {
5054: $resulttext = &mt('No changes made to log-in page settings');
5055: }
5056: } else {
5057: $resulttext = '<span class="LC_error">'.
5058: &mt('An error occurred: [_1]',$putresult).'</span>';
5059: }
5060: if ($errors) {
5061: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
5062: $errors.'</ul>';
5063: }
5064: return $resulttext;
5065: }
5066:
5067: sub color_font_choices {
5068: my %choices =
5069: &Apache::lonlocal::texthash (
5070: img => "Header",
5071: bgs => "Background colors",
5072: links => "Link colors",
5073: images => "Images",
5074: font => "Font color",
5075: fontmenu => "Font menu",
5076: pgbg => "Page",
5077: tabbg => "Header",
5078: sidebg => "Border",
5079: link => "Link",
5080: alink => "Active link",
5081: vlink => "Visited link",
5082: );
5083: return %choices;
5084: }
5085:
5086: sub modify_rolecolors {
5087: my ($r,$dom,$confname,$roles,%domconfig) = @_;
5088: my ($resulttext,%rolehash);
5089: $rolehash{'rolecolors'} = {};
5090: if (ref($domconfig{'rolecolors'}) ne 'HASH') {
5091: if ($domconfig{'rolecolors'} eq '') {
5092: $domconfig{'rolecolors'} = {};
5093: }
5094: }
5095: my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
5096: $domconfig{'rolecolors'},$rolehash{'rolecolors'});
5097: my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
5098: $dom);
5099: if ($putresult eq 'ok') {
5100: if (keys(%changes) > 0) {
5101: &Apache::loncommon::devalidate_domconfig_cache($dom);
5102: $resulttext = &display_colorchgs($dom,\%changes,$roles,
5103: $rolehash{'rolecolors'});
5104: } else {
5105: $resulttext = &mt('No changes made to default color schemes');
5106: }
5107: } else {
5108: $resulttext = '<span class="LC_error">'.
5109: &mt('An error occurred: [_1]',$putresult).'</span>';
5110: }
5111: if ($errors) {
5112: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
5113: $errors.'</ul>';
5114: }
5115: return $resulttext;
5116: }
5117:
5118: sub modify_colors {
5119: my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
5120: my (%changes,%choices);
5121: my @bgs;
5122: my @links = ('link','alink','vlink');
5123: my @logintext;
5124: my @images;
5125: my $servadm = $r->dir_config('lonAdmEMail');
5126: my $errors;
5127: my %defaults;
5128: foreach my $role (@{$roles}) {
5129: if ($role eq 'login') {
5130: %choices = &login_choices();
5131: @logintext = ('textcol','bgcol');
5132: } else {
5133: %choices = &color_font_choices();
5134: }
5135: if ($role eq 'login') {
5136: @images = ('img','logo','domlogo','login');
5137: @bgs = ('pgbg','mainbg','sidebg');
5138: } else {
5139: @images = ('img');
5140: @bgs = ('pgbg','tabbg','sidebg');
5141: }
5142: my %defaults = &role_defaults($role,\@bgs,\@links,\@images,\@logintext);
5143: unless ($env{'form.'.$role.'_font'} eq $defaults{'font'}) {
5144: $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
5145: }
5146: if ($role eq 'login') {
5147: foreach my $item (@logintext) {
5148: unless ($env{'form.'.$role.'_'.$item} eq $defaults{'logintext'}{$item}) {
5149: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
5150: }
5151: }
5152: } else {
5153: unless($env{'form.'.$role.'_fontmenu'} eq $defaults{'fontmenu'}) {
5154: $confhash->{$role}{'fontmenu'} = $env{'form.'.$role.'_fontmenu'};
5155: }
5156: }
5157: foreach my $item (@bgs) {
5158: unless ($env{'form.'.$role.'_'.$item} eq $defaults{'bgs'}{$item} ) {
5159: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
5160: }
5161: }
5162: foreach my $item (@links) {
5163: unless ($env{'form.'.$role.'_'.$item} eq $defaults{'links'}{$item}) {
5164: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
5165: }
5166: }
5167: my ($configuserok,$author_ok,$switchserver) =
5168: &config_check($dom,$confname,$servadm);
5169: my ($width,$height) = &thumb_dimensions();
5170: if (ref($domconfig->{$role}) ne 'HASH') {
5171: $domconfig->{$role} = {};
5172: }
5173: foreach my $img (@images) {
5174: if (($role eq 'login') && (($img eq 'img') || ($img eq 'logo'))) {
5175: if (defined($env{'form.login_showlogo_'.$img})) {
5176: $confhash->{$role}{'showlogo'}{$img} = 1;
5177: } else {
5178: $confhash->{$role}{'showlogo'}{$img} = 0;
5179: }
5180: }
5181: if ( ! $env{'form.'.$role.'_'.$img.'.filename'}
5182: && !defined($domconfig->{$role}{$img})
5183: && !$env{'form.'.$role.'_del_'.$img}
5184: && $env{'form.'.$role.'_import_'.$img}) {
5185: # import the old configured image from the .tab setting
5186: # if they haven't provided a new one
5187: $domconfig->{$role}{$img} =
5188: $env{'form.'.$role.'_import_'.$img};
5189: }
5190: if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
5191: my $error;
5192: if ($configuserok eq 'ok') {
5193: if ($switchserver) {
5194: $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
5195: } else {
5196: if ($author_ok eq 'ok') {
5197: my ($result,$logourl) =
5198: &publishlogo($r,'upload',$role.'_'.$img,
5199: $dom,$confname,$img,$width,$height);
5200: if ($result eq 'ok') {
5201: $confhash->{$role}{$img} = $logourl;
5202: $changes{$role}{'images'}{$img} = 1;
5203: } else {
5204: $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);
5205: }
5206: } else {
5207: $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);
5208: }
5209: }
5210: } else {
5211: $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);
5212: }
5213: if ($error) {
5214: &Apache::lonnet::logthis($error);
5215: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
5216: }
5217: } elsif ($domconfig->{$role}{$img} ne '') {
5218: if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
5219: my $error;
5220: if ($configuserok eq 'ok') {
5221: # is confname an author?
5222: if ($switchserver eq '') {
5223: if ($author_ok eq 'ok') {
5224: my ($result,$logourl) =
5225: &publishlogo($r,'copy',$domconfig->{$role}{$img},
5226: $dom,$confname,$img,$width,$height);
5227: if ($result eq 'ok') {
5228: $confhash->{$role}{$img} = $logourl;
5229: $changes{$role}{'images'}{$img} = 1;
5230: }
5231: }
5232: }
5233: }
5234: }
5235: }
5236: }
5237: if (ref($domconfig) eq 'HASH') {
5238: if (ref($domconfig->{$role}) eq 'HASH') {
5239: foreach my $img (@images) {
5240: if ($domconfig->{$role}{$img} ne '') {
5241: if ($env{'form.'.$role.'_del_'.$img}) {
5242: $confhash->{$role}{$img} = '';
5243: $changes{$role}{'images'}{$img} = 1;
5244: } else {
5245: if ($confhash->{$role}{$img} eq '') {
5246: $confhash->{$role}{$img} = $domconfig->{$role}{$img};
5247: }
5248: }
5249: } else {
5250: if ($env{'form.'.$role.'_del_'.$img}) {
5251: $confhash->{$role}{$img} = '';
5252: $changes{$role}{'images'}{$img} = 1;
5253: }
5254: }
5255: if (($role eq 'login') && (($img eq 'logo') || ($img eq 'img'))) {
5256: if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') {
5257: if ($confhash->{$role}{'showlogo'}{$img} ne
5258: $domconfig->{$role}{'showlogo'}{$img}) {
5259: $changes{$role}{'showlogo'}{$img} = 1;
5260: }
5261: } else {
5262: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
5263: $changes{$role}{'showlogo'}{$img} = 1;
5264: }
5265: }
5266: }
5267: }
5268: if ($domconfig->{$role}{'font'} ne '') {
5269: if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
5270: $changes{$role}{'font'} = 1;
5271: }
5272: } else {
5273: if ($confhash->{$role}{'font'}) {
5274: $changes{$role}{'font'} = 1;
5275: }
5276: }
5277: if ($role ne 'login') {
5278: if ($domconfig->{$role}{'fontmenu'} ne '') {
5279: if ($confhash->{$role}{'fontmenu'} ne $domconfig->{$role}{'fontmenu'}) {
5280: $changes{$role}{'fontmenu'} = 1;
5281: }
5282: } else {
5283: if ($confhash->{$role}{'fontmenu'}) {
5284: $changes{$role}{'fontmenu'} = 1;
5285: }
5286: }
5287: }
5288: foreach my $item (@bgs) {
5289: if ($domconfig->{$role}{$item} ne '') {
5290: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
5291: $changes{$role}{'bgs'}{$item} = 1;
5292: }
5293: } else {
5294: if ($confhash->{$role}{$item}) {
5295: $changes{$role}{'bgs'}{$item} = 1;
5296: }
5297: }
5298: }
5299: foreach my $item (@links) {
5300: if ($domconfig->{$role}{$item} ne '') {
5301: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
5302: $changes{$role}{'links'}{$item} = 1;
5303: }
5304: } else {
5305: if ($confhash->{$role}{$item}) {
5306: $changes{$role}{'links'}{$item} = 1;
5307: }
5308: }
5309: }
5310: foreach my $item (@logintext) {
5311: if ($domconfig->{$role}{$item} ne '') {
5312: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
5313: $changes{$role}{'logintext'}{$item} = 1;
5314: }
5315: } else {
5316: if ($confhash->{$role}{$item}) {
5317: $changes{$role}{'logintext'}{$item} = 1;
5318: }
5319: }
5320: }
5321: } else {
5322: &default_change_checker($role,\@images,\@links,\@bgs,
5323: \@logintext,$confhash,\%changes);
5324: }
5325: } else {
5326: &default_change_checker($role,\@images,\@links,\@bgs,
5327: \@logintext,$confhash,\%changes);
5328: }
5329: }
5330: return ($errors,%changes);
5331: }
5332:
5333: sub config_check {
5334: my ($dom,$confname,$servadm) = @_;
5335: my ($configuserok,$author_ok,$switchserver,%currroles);
5336: my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
5337: ($configuserok,%currroles) = &check_configuser($uhome,$dom,
5338: $confname,$servadm);
5339: if ($configuserok eq 'ok') {
5340: $switchserver = &check_switchserver($dom,$confname);
5341: if ($switchserver eq '') {
5342: $author_ok = &check_authorstatus($dom,$confname,%currroles);
5343: }
5344: }
5345: return ($configuserok,$author_ok,$switchserver);
5346: }
5347:
5348: sub default_change_checker {
5349: my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
5350: foreach my $item (@{$links}) {
5351: if ($confhash->{$role}{$item}) {
5352: $changes->{$role}{'links'}{$item} = 1;
5353: }
5354: }
5355: foreach my $item (@{$bgs}) {
5356: if ($confhash->{$role}{$item}) {
5357: $changes->{$role}{'bgs'}{$item} = 1;
5358: }
5359: }
5360: foreach my $item (@{$logintext}) {
5361: if ($confhash->{$role}{$item}) {
5362: $changes->{$role}{'logintext'}{$item} = 1;
5363: }
5364: }
5365: foreach my $img (@{$images}) {
5366: if ($env{'form.'.$role.'_del_'.$img}) {
5367: $confhash->{$role}{$img} = '';
5368: $changes->{$role}{'images'}{$img} = 1;
5369: }
5370: if ($role eq 'login') {
5371: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
5372: $changes->{$role}{'showlogo'}{$img} = 1;
5373: }
5374: }
5375: }
5376: if ($confhash->{$role}{'font'}) {
5377: $changes->{$role}{'font'} = 1;
5378: }
5379: }
5380:
5381: sub display_colorchgs {
5382: my ($dom,$changes,$roles,$confhash) = @_;
5383: my (%choices,$resulttext);
5384: if (!grep(/^login$/,@{$roles})) {
5385: $resulttext = &mt('Changes made:').'<br />';
5386: }
5387: foreach my $role (@{$roles}) {
5388: if ($role eq 'login') {
5389: %choices = &login_choices();
5390: } else {
5391: %choices = &color_font_choices();
5392: }
5393: if (ref($changes->{$role}) eq 'HASH') {
5394: if ($role ne 'login') {
5395: $resulttext .= '<h4>'.&mt($role).'</h4>';
5396: }
5397: foreach my $key (sort(keys(%{$changes->{$role}}))) {
5398: if ($role ne 'login') {
5399: $resulttext .= '<ul>';
5400: }
5401: if (ref($changes->{$role}{$key}) eq 'HASH') {
5402: if ($role ne 'login') {
5403: $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
5404: }
5405: foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
5406: if (($role eq 'login') && ($key eq 'showlogo')) {
5407: if ($confhash->{$role}{$key}{$item}) {
5408: $resulttext .= '<li>'.&mt("$choices{$item} set to be displayed").'</li>';
5409: } else {
5410: $resulttext .= '<li>'.&mt("$choices{$item} set to not be displayed").'</li>';
5411: }
5412: } elsif ($confhash->{$role}{$item} eq '') {
5413: $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
5414: } else {
5415: my $newitem = $confhash->{$role}{$item};
5416: if ($key eq 'images') {
5417: $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" valign="bottom" />';
5418: }
5419: $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
5420: }
5421: }
5422: if ($role ne 'login') {
5423: $resulttext .= '</ul></li>';
5424: }
5425: } else {
5426: if ($confhash->{$role}{$key} eq '') {
5427: $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
5428: } else {
5429: $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
5430: }
5431: }
5432: if ($role ne 'login') {
5433: $resulttext .= '</ul>';
5434: }
5435: }
5436: }
5437: }
5438: return $resulttext;
5439: }
5440:
5441: sub thumb_dimensions {
5442: return ('200','50');
5443: }
5444:
5445: sub check_dimensions {
5446: my ($inputfile) = @_;
5447: my ($fullwidth,$fullheight);
5448: if ($inputfile =~ m|^[/\w.\-]+$|) {
5449: if (open(PIPE,"identify $inputfile 2>&1 |")) {
5450: my $imageinfo = <PIPE>;
5451: if (!close(PIPE)) {
5452: &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
5453: }
5454: chomp($imageinfo);
5455: my ($fullsize) =
5456: ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
5457: if ($fullsize) {
5458: ($fullwidth,$fullheight) = split(/x/,$fullsize);
5459: }
5460: }
5461: }
5462: return ($fullwidth,$fullheight);
5463: }
5464:
5465: sub check_configuser {
5466: my ($uhome,$dom,$confname,$servadm) = @_;
5467: my ($configuserok,%currroles);
5468: if ($uhome eq 'no_host') {
5469: srand( time() ^ ($$ + ($$ << 15)) ); # Seed rand.
5470: my $configpass = &LONCAPA::Enrollment::create_password();
5471: $configuserok =
5472: &Apache::lonnet::modifyuser($dom,$confname,'','internal',
5473: $configpass,'','','','','',undef,$servadm);
5474: } else {
5475: $configuserok = 'ok';
5476: %currroles =
5477: &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
5478: }
5479: return ($configuserok,%currroles);
5480: }
5481:
5482: sub check_authorstatus {
5483: my ($dom,$confname,%currroles) = @_;
5484: my $author_ok;
5485: if (!$currroles{':'.$dom.':au'}) {
5486: my $start = time;
5487: my $end = 0;
5488: $author_ok =
5489: &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
5490: 'au',$end,$start,'','','domconfig');
5491: } else {
5492: $author_ok = 'ok';
5493: }
5494: return $author_ok;
5495: }
5496:
5497: sub publishlogo {
5498: my ($r,$action,$formname,$dom,$confname,$subdir,$thumbwidth,$thumbheight,$savefileas) = @_;
5499: my ($output,$fname,$logourl);
5500: if ($action eq 'upload') {
5501: $fname=$env{'form.'.$formname.'.filename'};
5502: chop($env{'form.'.$formname});
5503: } else {
5504: ($fname) = ($formname =~ /([^\/]+)$/);
5505: }
5506: if ($savefileas ne '') {
5507: $fname = $savefileas;
5508: }
5509: $fname=&Apache::lonnet::clean_filename($fname);
5510: # See if there is anything left
5511: unless ($fname) { return ('error: no uploaded file'); }
5512: $fname="$subdir/$fname";
5513: my $docroot=$r->dir_config('lonDocRoot');
5514: my $filepath="$docroot/priv";
5515: my $relpath = "$dom/$confname";
5516: my ($fnamepath,$file,$fetchthumb);
5517: $file=$fname;
5518: if ($fname=~m|/|) {
5519: ($fnamepath,$file) = ($fname =~ m|^(.*)/([^/]+)$|);
5520: }
5521: my @parts=split(/\//,"$filepath/$relpath/$fnamepath");
5522: my $count;
5523: for ($count=5;$count<=$#parts;$count++) {
5524: $filepath.="/$parts[$count]";
5525: if ((-e $filepath)!=1) {
5526: mkdir($filepath,02770);
5527: }
5528: }
5529: # Check for bad extension and disallow upload
5530: if ($file=~/\.(\w+)$/ &&
5531: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
5532: $output =
5533: &mt('Invalid file extension ([_1]) - reserved for LONCAPA use.',$1);
5534: } elsif ($file=~/\.(\w+)$/ &&
5535: !defined(&Apache::loncommon::fileembstyle($1))) {
5536: $output = &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
5537: } elsif ($file=~/\.(\d+)\.(\w+)$/) {
5538: $output = &mt('Filename not allowed - rename the file to remove the number immediately before the file extension([_1]) and re-upload.',$2);
5539: } elsif (-d "$filepath/$file") {
5540: $output = &mt('Filename is a directory name - rename the file and re-upload');
5541: } else {
5542: my $source = $filepath.'/'.$file;
5543: my $logfile;
5544: if (!open($logfile,">>$source".'.log')) {
5545: return (&mt('No write permission to Authoring Space'));
5546: }
5547: print $logfile
5548: "\n================= Publish ".localtime()." ================\n".
5549: $env{'user.name'}.':'.$env{'user.domain'}."\n";
5550: # Save the file
5551: if (!open(FH,'>'.$source)) {
5552: &Apache::lonnet::logthis('Failed to create '.$source);
5553: return (&mt('Failed to create file'));
5554: }
5555: if ($action eq 'upload') {
5556: if (!print FH ($env{'form.'.$formname})) {
5557: &Apache::lonnet::logthis('Failed to write to '.$source);
5558: return (&mt('Failed to write file'));
5559: }
5560: } else {
5561: my $original = &Apache::lonnet::filelocation('',$formname);
5562: if(!copy($original,$source)) {
5563: &Apache::lonnet::logthis('Failed to copy '.$original.' to '.$source);
5564: return (&mt('Failed to write file'));
5565: }
5566: }
5567: close(FH);
5568: chmod(0660, $source); # Permissions to rw-rw---.
5569:
5570: my $targetdir=$docroot.'/res/'.$dom.'/'.$confname .'/'.$fnamepath;
5571: my $copyfile=$targetdir.'/'.$file;
5572:
5573: my @parts=split(/\//,$targetdir);
5574: my $path="/$parts[1]/$parts[2]/$parts[3]/$parts[4]";
5575: for (my $count=5;$count<=$#parts;$count++) {
5576: $path.="/$parts[$count]";
5577: if (!-e $path) {
5578: print $logfile "\nCreating directory ".$path;
5579: mkdir($path,02770);
5580: }
5581: }
5582: my $versionresult;
5583: if (-e $copyfile) {
5584: $versionresult = &logo_versioning($targetdir,$file,$logfile);
5585: } else {
5586: $versionresult = 'ok';
5587: }
5588: if ($versionresult eq 'ok') {
5589: if (copy($source,$copyfile)) {
5590: print $logfile "\nCopied original source to ".$copyfile."\n";
5591: $output = 'ok';
5592: $logourl = '/res/'.$dom.'/'.$confname.'/'.$fname;
5593: push(@{$modified_urls},[$copyfile,$source]);
5594: my $metaoutput =
5595: &write_metadata($dom,$confname,$formname,$targetdir,$file,$logfile);
5596: unless ($registered_cleanup) {
5597: my $handlers = $r->get_handlers('PerlCleanupHandler');
5598: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
5599: $registered_cleanup=1;
5600: }
5601: } else {
5602: print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";
5603: $output = &mt('Failed to copy file to RES space').", $!";
5604: }
5605: if (($thumbwidth =~ /^\d+$/) && ($thumbheight =~ /^\d+$/)) {
5606: my $inputfile = $filepath.'/'.$file;
5607: my $outfile = $filepath.'/'.'tn-'.$file;
5608: my ($fullwidth,$fullheight) = &check_dimensions($inputfile);
5609: if ($fullwidth ne '' && $fullheight ne '') {
5610: if ($fullwidth > $thumbwidth && $fullheight > $thumbheight) {
5611: my $thumbsize = $thumbwidth.'x'.$thumbheight;
5612: system("convert -sample $thumbsize $inputfile $outfile");
5613: chmod(0660, $filepath.'/tn-'.$file);
5614: if (-e $outfile) {
5615: my $copyfile=$targetdir.'/tn-'.$file;
5616: if (copy($outfile,$copyfile)) {
5617: print $logfile "\nCopied source to ".$copyfile."\n";
5618: my $thumb_metaoutput =
5619: &write_metadata($dom,$confname,$formname,
5620: $targetdir,'tn-'.$file,$logfile);
5621: push(@{$modified_urls},[$copyfile,$outfile]);
5622: unless ($registered_cleanup) {
5623: my $handlers = $r->get_handlers('PerlCleanupHandler');
5624: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
5625: $registered_cleanup=1;
5626: }
5627: } else {
5628: print $logfile "\nUnable to write ".$copyfile.
5629: ':'.$!."\n";
5630: }
5631: }
5632: }
5633: }
5634: }
5635: } else {
5636: $output = $versionresult;
5637: }
5638: }
5639: return ($output,$logourl);
5640: }
5641:
5642: sub logo_versioning {
5643: my ($targetdir,$file,$logfile) = @_;
5644: my $target = $targetdir.'/'.$file;
5645: my ($maxversion,$fn,$extn,$output);
5646: $maxversion = 0;
5647: if ($file =~ /^(.+)\.(\w+)$/) {
5648: $fn=$1;
5649: $extn=$2;
5650: }
5651: opendir(DIR,$targetdir);
5652: while (my $filename=readdir(DIR)) {
5653: if ($filename=~/\Q$fn\E\.(\d+)\.\Q$extn\E$/) {
5654: $maxversion=($1>$maxversion)?$1:$maxversion;
5655: }
5656: }
5657: $maxversion++;
5658: print $logfile "\nCreating old version ".$maxversion."\n";
5659: my $copyfile=$targetdir.'/'.$fn.'.'.$maxversion.'.'.$extn;
5660: if (copy($target,$copyfile)) {
5661: print $logfile "Copied old target to ".$copyfile."\n";
5662: $copyfile=$copyfile.'.meta';
5663: if (copy($target.'.meta',$copyfile)) {
5664: print $logfile "Copied old target metadata to ".$copyfile."\n";
5665: $output = 'ok';
5666: } else {
5667: print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";
5668: $output = &mt('Failed to copy old meta').", $!, ";
5669: }
5670: } else {
5671: print $logfile "Unable to write ".$copyfile.':'.$!."\n";
5672: $output = &mt('Failed to copy old target').", $!, ";
5673: }
5674: return $output;
5675: }
5676:
5677: sub write_metadata {
5678: my ($dom,$confname,$formname,$targetdir,$file,$logfile) = @_;
5679: my (%metadatafields,%metadatakeys,$output);
5680: $metadatafields{'title'}=$formname;
5681: $metadatafields{'creationdate'}=time;
5682: $metadatafields{'lastrevisiondate'}=time;
5683: $metadatafields{'copyright'}='public';
5684: $metadatafields{'modifyinguser'}=$env{'user.name'}.':'.
5685: $env{'user.domain'};
5686: $metadatafields{'authorspace'}=$confname.':'.$dom;
5687: $metadatafields{'domain'}=$dom;
5688: {
5689: print $logfile "\nWrite metadata file for ".$targetdir.'/'.$file;
5690: my $mfh;
5691: if (open($mfh,'>'.$targetdir.'/'.$file.'.meta')) {
5692: foreach (sort(keys(%metadatafields))) {
5693: unless ($_=~/\./) {
5694: my $unikey=$_;
5695: $unikey=~/^([A-Za-z]+)/;
5696: my $tag=$1;
5697: $tag=~tr/A-Z/a-z/;
5698: print $mfh "\n\<$tag";
5699: foreach (split(/\,/,$metadatakeys{$unikey})) {
5700: my $value=$metadatafields{$unikey.'.'.$_};
5701: $value=~s/\"/\'\'/g;
5702: print $mfh ' '.$_.'="'.$value.'"';
5703: }
5704: print $mfh '>'.
5705: &HTML::Entities::encode($metadatafields{$unikey},'<>&"')
5706: .'</'.$tag.'>';
5707: }
5708: }
5709: $output = 'ok';
5710: print $logfile "\nWrote metadata";
5711: close($mfh);
5712: } else {
5713: print $logfile "\nFailed to open metadata file";
5714: $output = &mt('Could not write metadata');
5715: }
5716: }
5717: return $output;
5718: }
5719:
5720: sub notifysubscribed {
5721: foreach my $targetsource (@{$modified_urls}){
5722: next unless (ref($targetsource) eq 'ARRAY');
5723: my ($target,$source)=@{$targetsource};
5724: if ($source ne '') {
5725: if (open(my $logfh,'>>'.$source.'.log')) {
5726: print $logfh "\nCleanup phase: Notifications\n";
5727: my @subscribed=&subscribed_hosts($target);
5728: foreach my $subhost (@subscribed) {
5729: print $logfh "\nNotifying host ".$subhost.':';
5730: my $reply=&Apache::lonnet::critical('update:'.$target,$subhost);
5731: print $logfh $reply;
5732: }
5733: my @subscribedmeta=&subscribed_hosts("$target.meta");
5734: foreach my $subhost (@subscribedmeta) {
5735: print $logfh "\nNotifying host for metadata only ".$subhost.':';
5736: my $reply=&Apache::lonnet::critical('update:'.$target.'.meta',
5737: $subhost);
5738: print $logfh $reply;
5739: }
5740: print $logfh "\n============ Done ============\n";
5741: close($logfh);
5742: }
5743: }
5744: }
5745: return OK;
5746: }
5747:
5748: sub subscribed_hosts {
5749: my ($target) = @_;
5750: my @subscribed;
5751: if (open(my $fh,"<$target.subscription")) {
5752: while (my $subline=<$fh>) {
5753: if ($subline =~ /^($match_lonid):/) {
5754: my $host = $1;
5755: if ($host ne $Apache::lonnet::perlvar{'lonHostID'}) {
5756: unless (grep(/^\Q$host\E$/,@subscribed)) {
5757: push(@subscribed,$host);
5758: }
5759: }
5760: }
5761: }
5762: }
5763: return @subscribed;
5764: }
5765:
5766: sub check_switchserver {
5767: my ($dom,$confname) = @_;
5768: my ($allowed,$switchserver);
5769: my $home = &Apache::lonnet::homeserver($confname,$dom);
5770: if ($home eq 'no_host') {
5771: $home = &Apache::lonnet::domain($dom,'primary');
5772: }
5773: my @ids=&Apache::lonnet::current_machine_ids();
5774: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
5775: if (!$allowed) {
5776: $switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role=dc./'.$dom.'/&destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
5777: }
5778: return $switchserver;
5779: }
5780:
5781: sub modify_quotas {
5782: my ($dom,$action,%domconfig) = @_;
5783: my ($context,@usertools,@options,%validations,%titles,%confhash,%toolshash,
5784: %limithash,$toolregexp,%conditions,$resulttext,%changes);
5785: if ($action eq 'quotas') {
5786: $context = 'tools';
5787: } else {
5788: $context = $action;
5789: }
5790: if ($context eq 'requestcourses') {
5791: @usertools = ('official','unofficial','community');
5792: @options =('norequest','approval','validate','autolimit');
5793: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
5794: %titles = &courserequest_titles();
5795: $toolregexp = join('|',@usertools);
5796: %conditions = &courserequest_conditions();
5797: } elsif ($context eq 'requestauthor') {
5798: @usertools = ('author');
5799: %titles = &authorrequest_titles();
5800: } else {
5801: @usertools = ('aboutme','blog','webdav','portfolio');
5802: %titles = &tool_titles();
5803: }
5804: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
5805: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
5806: foreach my $key (keys(%env)) {
5807: if ($context eq 'requestcourses') {
5808: if ($key =~ /^form\.crsreq_($toolregexp)_(.+)$/) {
5809: my $item = $1;
5810: my $type = $2;
5811: if ($type =~ /^limit_(.+)/) {
5812: $limithash{$item}{$1} = $env{$key};
5813: } else {
5814: $confhash{$item}{$type} = $env{$key};
5815: }
5816: }
5817: } elsif ($context eq 'requestauthor') {
5818: if ($key =~ /^\Qform.authorreq_\E(.+)$/) {
5819: $confhash{$1} = $env{$key};
5820: }
5821: } else {
5822: if ($key =~ /^form\.quota_(.+)$/) {
5823: $confhash{'defaultquota'}{$1} = $env{$key};
5824: } elsif ($key =~ /^form\.authorquota_(.+)$/) {
5825: $confhash{'authorquota'}{$1} = $env{$key};
5826: } elsif ($key =~ /^form\.\Q$context\E_(.+)$/) {
5827: @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key);
5828: }
5829: }
5830: }
5831: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
5832: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.reqapprovalnotify');
5833: @approvalnotify = sort(@approvalnotify);
5834: $confhash{'notify'}{'approval'} = join(',',@approvalnotify);
5835: if (ref($domconfig{$action}) eq 'HASH') {
5836: if (ref($domconfig{$action}{'notify'}) eq 'HASH') {
5837: if ($domconfig{$action}{'notify'}{'approval'} ne $confhash{'notify'}{'approval'}) {
5838: $changes{'notify'}{'approval'} = 1;
5839: }
5840: } else {
5841: if ($confhash{'notify'}{'approval'}) {
5842: $changes{'notify'}{'approval'} = 1;
5843: }
5844: }
5845: } else {
5846: if ($confhash{'notify'}{'approval'}) {
5847: $changes{'notify'}{'approval'} = 1;
5848: }
5849: }
5850: } else {
5851: $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
5852: $confhash{'authorquota'}{'default'} = $env{'form.authorquota'};
5853: }
5854: foreach my $item (@usertools) {
5855: foreach my $type (@{$types},'default','_LC_adv') {
5856: my $unset;
5857: if ($context eq 'requestcourses') {
5858: $unset = '0';
5859: if ($type eq '_LC_adv') {
5860: $unset = '';
5861: }
5862: if ($confhash{$item}{$type} eq 'autolimit') {
5863: $confhash{$item}{$type} .= '=';
5864: unless ($limithash{$item}{$type} =~ /\D/) {
5865: $confhash{$item}{$type} .= $limithash{$item}{$type};
5866: }
5867: }
5868: } elsif ($context eq 'requestauthor') {
5869: $unset = '0';
5870: if ($type eq '_LC_adv') {
5871: $unset = '';
5872: }
5873: } else {
5874: if (grep(/^\Q$type\E$/,@{$toolshash{$item}})) {
5875: $confhash{$item}{$type} = 1;
5876: } else {
5877: $confhash{$item}{$type} = 0;
5878: }
5879: }
5880: if (ref($domconfig{$action}) eq 'HASH') {
5881: if ($action eq 'requestauthor') {
5882: if ($domconfig{$action}{$type} ne $confhash{$type}) {
5883: $changes{$type} = 1;
5884: }
5885: } elsif (ref($domconfig{$action}{$item}) eq 'HASH') {
5886: if ($domconfig{$action}{$item}{$type} ne $confhash{$item}{$type}) {
5887: $changes{$item}{$type} = 1;
5888: }
5889: } else {
5890: if ($context eq 'requestcourses') {
5891: if ($confhash{$item}{$type} ne $unset) {
5892: $changes{$item}{$type} = 1;
5893: }
5894: } else {
5895: if (!$confhash{$item}{$type}) {
5896: $changes{$item}{$type} = 1;
5897: }
5898: }
5899: }
5900: } else {
5901: if ($context eq 'requestcourses') {
5902: if ($confhash{$item}{$type} ne $unset) {
5903: $changes{$item}{$type} = 1;
5904: }
5905: } elsif ($context eq 'requestauthor') {
5906: if ($confhash{$type} ne $unset) {
5907: $changes{$type} = 1;
5908: }
5909: } else {
5910: if (!$confhash{$item}{$type}) {
5911: $changes{$item}{$type} = 1;
5912: }
5913: }
5914: }
5915: }
5916: }
5917: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
5918: if (ref($domconfig{'quotas'}) eq 'HASH') {
5919: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
5920: foreach my $key (keys(%{$domconfig{'quotas'}{'defaultquota'}})) {
5921: if (exists($confhash{'defaultquota'}{$key})) {
5922: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{'defaultquota'}{$key}) {
5923: $changes{'defaultquota'}{$key} = 1;
5924: }
5925: } else {
5926: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{'defaultquota'}{$key};
5927: }
5928: }
5929: } else {
5930: foreach my $key (keys(%{$domconfig{'quotas'}})) {
5931: if (exists($confhash{'defaultquota'}{$key})) {
5932: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{$key}) {
5933: $changes{'defaultquota'}{$key} = 1;
5934: }
5935: } else {
5936: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{$key};
5937: }
5938: }
5939: }
5940: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
5941: foreach my $key (keys(%{$domconfig{'quotas'}{'authorquota'}})) {
5942: if (exists($confhash{'authorquota'}{$key})) {
5943: if ($confhash{'authorquota'}{$key} ne $domconfig{'quotas'}{'authorquota'}{$key}) {
5944: $changes{'authorquota'}{$key} = 1;
5945: }
5946: } else {
5947: $confhash{'authorquota'}{$key} = $domconfig{'quotas'}{'authorquota'}{$key};
5948: }
5949: }
5950: }
5951: }
5952: if (ref($confhash{'defaultquota'}) eq 'HASH') {
5953: foreach my $key (keys(%{$confhash{'defaultquota'}})) {
5954: if (ref($domconfig{'quotas'}) eq 'HASH') {
5955: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
5956: if (!exists($domconfig{'quotas'}{'defaultquota'}{$key})) {
5957: $changes{'defaultquota'}{$key} = 1;
5958: }
5959: } else {
5960: if (!exists($domconfig{'quotas'}{$key})) {
5961: $changes{'defaultquota'}{$key} = 1;
5962: }
5963: }
5964: } else {
5965: $changes{'defaultquota'}{$key} = 1;
5966: }
5967: }
5968: }
5969: if (ref($confhash{'authorquota'}) eq 'HASH') {
5970: foreach my $key (keys(%{$confhash{'authorquota'}})) {
5971: if (ref($domconfig{'quotas'}) eq 'HASH') {
5972: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
5973: if (!exists($domconfig{'quotas'}{'authorquota'}{$key})) {
5974: $changes{'authorquota'}{$key} = 1;
5975: }
5976: } else {
5977: $changes{'authorquota'}{$key} = 1;
5978: }
5979: } else {
5980: $changes{'authorquota'}{$key} = 1;
5981: }
5982: }
5983: }
5984: }
5985:
5986: if ($context eq 'requestauthor') {
5987: $domdefaults{'requestauthor'} = \%confhash;
5988: } else {
5989: foreach my $key (keys(%confhash)) {
5990: $domdefaults{$key} = $confhash{$key};
5991: }
5992: }
5993:
5994: my %quotahash = (
5995: $action => { %confhash }
5996: );
5997: my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
5998: $dom);
5999: if ($putresult eq 'ok') {
6000: if (keys(%changes) > 0) {
6001: my $cachetime = 24*60*60;
6002: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
6003:
6004: $resulttext = &mt('Changes made:').'<ul>';
6005: unless (($context eq 'requestcourses') ||
6006: ($context eq 'requestauthor')) {
6007: if (ref($changes{'defaultquota'}) eq 'HASH') {
6008: $resulttext .= '<li>'.&mt('Portfolio default quotas').'<ul>';
6009: foreach my $type (@{$types},'default') {
6010: if (defined($changes{'defaultquota'}{$type})) {
6011: my $typetitle = $usertypes->{$type};
6012: if ($type eq 'default') {
6013: $typetitle = $othertitle;
6014: }
6015: $resulttext .= '<li>'.&mt('[_1] set to [_2] Mb',$typetitle,$confhash{'defaultquota'}{$type}).'</li>';
6016: }
6017: }
6018: $resulttext .= '</ul></li>';
6019: }
6020: if (ref($changes{'authorquota'}) eq 'HASH') {
6021: $resulttext .= '<li>'.&mt('Authoring space default quotas').'<ul>';
6022: foreach my $type (@{$types},'default') {
6023: if (defined($changes{'authorquota'}{$type})) {
6024: my $typetitle = $usertypes->{$type};
6025: if ($type eq 'default') {
6026: $typetitle = $othertitle;
6027: }
6028: $resulttext .= '<li>'.&mt('[_1] set to [_2] Mb',$typetitle,$confhash{'authorquota'}{$type}).'</li>';
6029: }
6030: }
6031: $resulttext .= '</ul></li>';
6032: }
6033: }
6034: my %newenv;
6035: foreach my $item (@usertools) {
6036: my (%haschgs,%inconf);
6037: if ($context eq 'requestauthor') {
6038: %haschgs = %changes;
6039: %inconf = %confhash;
6040: } else {
6041: if (ref($changes{$item}) eq 'HASH') {
6042: %haschgs = %{$changes{$item}};
6043: }
6044: if (ref($confhash{$item}) eq 'HASH') {
6045: %inconf = %{$confhash{$item}};
6046: }
6047: }
6048: if (keys(%haschgs) > 0) {
6049: my $newacc =
6050: &Apache::lonnet::usertools_access($env{'user.name'},
6051: $env{'user.domain'},
6052: $item,'reload',$context);
6053: if (($context eq 'requestcourses') ||
6054: ($context eq 'requestauthor')) {
6055: if ($env{'environment.canrequest.'.$item} ne $newacc) {
6056: $newenv{'environment.canrequest.'.$item} = $newacc;
6057: }
6058: } else {
6059: if ($env{'environment.availabletools.'.$item} ne $newacc) {
6060: $newenv{'environment.availabletools.'.$item} = $newacc;
6061: }
6062: }
6063: unless ($context eq 'requestauthor') {
6064: $resulttext .= '<li>'.$titles{$item}.'<ul>';
6065: }
6066: foreach my $type (@{$types},'default','_LC_adv') {
6067: if ($haschgs{$type}) {
6068: my $typetitle = $usertypes->{$type};
6069: if ($type eq 'default') {
6070: $typetitle = $othertitle;
6071: } elsif ($type eq '_LC_adv') {
6072: $typetitle = 'LON-CAPA Advanced Users';
6073: }
6074: if ($inconf{$type}) {
6075: if ($context eq 'requestcourses') {
6076: my $cond;
6077: if ($inconf{$type} =~ /^autolimit=(\d*)$/) {
6078: if ($1 eq '') {
6079: $cond = &mt('(Automatic processing of any request).');
6080: } else {
6081: $cond = &mt('(Automatic processing of requests up to limit of [quant,_1,request] per user).',$1);
6082: }
6083: } else {
6084: $cond = $conditions{$inconf{$type}};
6085: }
6086: $resulttext .= '<li>'.&mt('Set to be available to [_1].',$typetitle).' '.$cond.'</li>';
6087: } elsif ($context eq 'requestauthor') {
6088: $resulttext .= '<li>'.&mt('Set to "[_1]" for "[_2]".',
6089: $titles{$inconf{$type}},$typetitle);
6090:
6091: } else {
6092: $resulttext .= '<li>'.&mt('Set to be available to [_1]',$typetitle).'</li>';
6093: }
6094: } else {
6095: if ($type eq '_LC_adv') {
6096: if ($inconf{$type} eq '0') {
6097: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
6098: } else {
6099: $resulttext .= '<li>'.&mt('No override set for [_1]',$typetitle).'</li>';
6100: }
6101: } else {
6102: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
6103: }
6104: }
6105: }
6106: }
6107: unless ($context eq 'requestauthor') {
6108: $resulttext .= '</ul></li>';
6109: }
6110: }
6111: }
6112: if (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
6113: if (ref($changes{'notify'}) eq 'HASH') {
6114: if ($changes{'notify'}{'approval'}) {
6115: if (ref($confhash{'notify'}) eq 'HASH') {
6116: if ($confhash{'notify'}{'approval'}) {
6117: $resulttext .= '<li>'.&mt('Notification of requests requiring approval will be sent to: ').$confhash{'notify'}{'approval'}.'</li>';
6118: } else {
6119: $resulttext .= '<li>'.&mt('No Domain Coordinators will receive notification of requests requiring approval.').'</li>';
6120: }
6121: }
6122: }
6123: }
6124: }
6125: $resulttext .= '</ul>';
6126: if (keys(%newenv)) {
6127: &Apache::lonnet::appenv(\%newenv);
6128: }
6129: } else {
6130: if ($context eq 'requestcourses') {
6131: $resulttext = &mt('No changes made to rights to request creation of courses.');
6132: } elsif ($context eq 'requestauthor') {
6133: $resulttext = &mt('No changes made to rights to request author space.');
6134: } else {
6135: $resulttext = &mt('No changes made to availability of personal information pages, blogs, portfolios or default quotas');
6136: }
6137: }
6138: } else {
6139: $resulttext = '<span class="LC_error">'.
6140: &mt('An error occurred: [_1]',$putresult).'</span>';
6141: }
6142: return $resulttext;
6143: }
6144:
6145: sub modify_autoenroll {
6146: my ($dom,%domconfig) = @_;
6147: my ($resulttext,%changes);
6148: my %currautoenroll;
6149: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
6150: foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
6151: $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
6152: }
6153: }
6154: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
6155: my %title = ( run => 'Auto-enrollment active',
6156: sender => 'Sender for notification messages',
6157: coowners => 'Automatic assignment of co-ownership to instructors of record (institutional data)');
6158: my @offon = ('off','on');
6159: my $sender_uname = $env{'form.sender_uname'};
6160: my $sender_domain = $env{'form.sender_domain'};
6161: if ($sender_domain eq '') {
6162: $sender_uname = '';
6163: } elsif ($sender_uname eq '') {
6164: $sender_domain = '';
6165: }
6166: my $coowners = $env{'form.autoassign_coowners'};
6167: my %autoenrollhash = (
6168: autoenroll => { 'run' => $env{'form.autoenroll_run'},
6169: 'sender_uname' => $sender_uname,
6170: 'sender_domain' => $sender_domain,
6171: 'co-owners' => $coowners,
6172: }
6173: );
6174: my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
6175: $dom);
6176: if ($putresult eq 'ok') {
6177: if (exists($currautoenroll{'run'})) {
6178: if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
6179: $changes{'run'} = 1;
6180: }
6181: } elsif ($autorun) {
6182: if ($env{'form.autoenroll_run'} ne '1') {
6183: $changes{'run'} = 1;
6184: }
6185: }
6186: if ($currautoenroll{'sender_uname'} ne $sender_uname) {
6187: $changes{'sender'} = 1;
6188: }
6189: if ($currautoenroll{'sender_domain'} ne $sender_domain) {
6190: $changes{'sender'} = 1;
6191: }
6192: if ($currautoenroll{'co-owners'} ne '') {
6193: if ($currautoenroll{'co-owners'} ne $coowners) {
6194: $changes{'coowners'} = 1;
6195: }
6196: } elsif ($coowners) {
6197: $changes{'coowners'} = 1;
6198: }
6199: if (keys(%changes) > 0) {
6200: $resulttext = &mt('Changes made:').'<ul>';
6201: if ($changes{'run'}) {
6202: $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
6203: }
6204: if ($changes{'sender'}) {
6205: if ($sender_uname eq '' || $sender_domain eq '') {
6206: $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
6207: } else {
6208: $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
6209: }
6210: }
6211: if ($changes{'coowners'}) {
6212: $resulttext .= '<li>'.&mt("$title{'coowners'} set to $offon[$env{'form.autoassign_coowners'}]").'</li>';
6213: &Apache::loncommon::devalidate_domconfig_cache($dom);
6214: }
6215: $resulttext .= '</ul>';
6216: } else {
6217: $resulttext = &mt('No changes made to auto-enrollment settings');
6218: }
6219: } else {
6220: $resulttext = '<span class="LC_error">'.
6221: &mt('An error occurred: [_1]',$putresult).'</span>';
6222: }
6223: return $resulttext;
6224: }
6225:
6226: sub modify_autoupdate {
6227: my ($dom,%domconfig) = @_;
6228: my ($resulttext,%currautoupdate,%fields,%changes);
6229: if (ref($domconfig{'autoupdate'}) eq 'HASH') {
6230: foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
6231: $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
6232: }
6233: }
6234: my @offon = ('off','on');
6235: my %title = &Apache::lonlocal::texthash (
6236: run => 'Auto-update:',
6237: classlists => 'Updates to user information in classlists?'
6238: );
6239: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
6240: my %fieldtitles = &Apache::lonlocal::texthash (
6241: id => 'Student/Employee ID',
6242: permanentemail => 'E-mail address',
6243: lastname => 'Last Name',
6244: firstname => 'First Name',
6245: middlename => 'Middle Name',
6246: generation => 'Generation',
6247: );
6248: $othertitle = &mt('All users');
6249: if (keys(%{$usertypes}) > 0) {
6250: $othertitle = &mt('Other users');
6251: }
6252: foreach my $key (keys(%env)) {
6253: if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
6254: my ($usertype,$item) = ($1,$2);
6255: if (grep(/^\Q$item\E$/,keys(%fieldtitles))) {
6256: if ($usertype eq 'default') {
6257: push(@{$fields{$1}},$2);
6258: } elsif (ref($types) eq 'ARRAY') {
6259: if (grep(/^\Q$usertype\E$/,@{$types})) {
6260: push(@{$fields{$1}},$2);
6261: }
6262: }
6263: }
6264: }
6265: }
6266: my @lockablenames = &Apache::loncommon::get_env_multiple('form.lockablenames');
6267: @lockablenames = sort(@lockablenames);
6268: if (ref($currautoupdate{'lockablenames'}) eq 'ARRAY') {
6269: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
6270: if (@changed) {
6271: $changes{'lockablenames'} = 1;
6272: }
6273: } else {
6274: if (@lockablenames) {
6275: $changes{'lockablenames'} = 1;
6276: }
6277: }
6278: my %updatehash = (
6279: autoupdate => { run => $env{'form.autoupdate_run'},
6280: classlists => $env{'form.classlists'},
6281: fields => {%fields},
6282: lockablenames => \@lockablenames,
6283: }
6284: );
6285: foreach my $key (keys(%currautoupdate)) {
6286: if (($key eq 'run') || ($key eq 'classlists')) {
6287: if (exists($updatehash{autoupdate}{$key})) {
6288: if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
6289: $changes{$key} = 1;
6290: }
6291: }
6292: } elsif ($key eq 'fields') {
6293: if (ref($currautoupdate{$key}) eq 'HASH') {
6294: foreach my $item (@{$types},'default') {
6295: if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
6296: my $change = 0;
6297: foreach my $type (@{$currautoupdate{$key}{$item}}) {
6298: if (!exists($fields{$item})) {
6299: $change = 1;
6300: last;
6301: } elsif (ref($fields{$item}) eq 'ARRAY') {
6302: if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
6303: $change = 1;
6304: last;
6305: }
6306: }
6307: }
6308: if ($change) {
6309: push(@{$changes{$key}},$item);
6310: }
6311: }
6312: }
6313: }
6314: } elsif ($key eq 'lockablenames') {
6315: if (ref($currautoupdate{$key}) eq 'ARRAY') {
6316: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
6317: if (@changed) {
6318: $changes{'lockablenames'} = 1;
6319: }
6320: } else {
6321: if (@lockablenames) {
6322: $changes{'lockablenames'} = 1;
6323: }
6324: }
6325: }
6326: }
6327: unless (grep(/^\Qlockablenames\E$/,keys(%currautoupdate))) {
6328: if (@lockablenames) {
6329: $changes{'lockablenames'} = 1;
6330: }
6331: }
6332: foreach my $item (@{$types},'default') {
6333: if (defined($fields{$item})) {
6334: if (ref($currautoupdate{'fields'}) eq 'HASH') {
6335: if (ref($currautoupdate{'fields'}{$item}) eq 'ARRAY') {
6336: my $change = 0;
6337: if (ref($fields{$item}) eq 'ARRAY') {
6338: foreach my $type (@{$fields{$item}}) {
6339: if (!grep(/^\Q$type\E$/,@{$currautoupdate{'fields'}{$item}})) {
6340: $change = 1;
6341: last;
6342: }
6343: }
6344: }
6345: if ($change) {
6346: push(@{$changes{'fields'}},$item);
6347: }
6348: } else {
6349: push(@{$changes{'fields'}},$item);
6350: }
6351: } else {
6352: push(@{$changes{'fields'}},$item);
6353: }
6354: }
6355: }
6356: my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
6357: $dom);
6358: if ($putresult eq 'ok') {
6359: if (keys(%changes) > 0) {
6360: $resulttext = &mt('Changes made:').'<ul>';
6361: foreach my $key (sort(keys(%changes))) {
6362: if ($key eq 'lockablenames') {
6363: $resulttext .= '<li>';
6364: if (@lockablenames) {
6365: $usertypes->{'default'} = $othertitle;
6366: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update), available for the following affiliations:").' '.
6367: join(', ', map { $usertypes->{$_}; } @lockablenames).'</li>';
6368: } else {
6369: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update) is unavailable.");
6370: }
6371: $resulttext .= '</li>';
6372: } elsif (ref($changes{$key}) eq 'ARRAY') {
6373: foreach my $item (@{$changes{$key}}) {
6374: my @newvalues;
6375: foreach my $type (@{$fields{$item}}) {
6376: push(@newvalues,$fieldtitles{$type});
6377: }
6378: my $newvaluestr;
6379: if (@newvalues > 0) {
6380: $newvaluestr = join(', ',@newvalues);
6381: } else {
6382: $newvaluestr = &mt('none');
6383: }
6384: if ($item eq 'default') {
6385: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
6386: } else {
6387: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
6388: }
6389: }
6390: } else {
6391: my $newvalue;
6392: if ($key eq 'run') {
6393: $newvalue = $offon[$env{'form.autoupdate_run'}];
6394: } else {
6395: $newvalue = $offon[$env{'form.'.$key}];
6396: }
6397: $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
6398: }
6399: }
6400: $resulttext .= '</ul>';
6401: } else {
6402: $resulttext = &mt('No changes made to autoupdates');
6403: }
6404: } else {
6405: $resulttext = '<span class="LC_error">'.
6406: &mt('An error occurred: [_1]',$putresult).'</span>';
6407: }
6408: return $resulttext;
6409: }
6410:
6411: sub modify_autocreate {
6412: my ($dom,%domconfig) = @_;
6413: my ($resulttext,%changes,%currautocreate,%newvals,%autocreatehash);
6414: if (ref($domconfig{'autocreate'}) eq 'HASH') {
6415: foreach my $key (keys(%{$domconfig{'autocreate'}})) {
6416: $currautocreate{$key} = $domconfig{'autocreate'}{$key};
6417: }
6418: }
6419: my %title= ( xml => 'Auto-creation of courses in XML course description files',
6420: req => 'Auto-creation of validated requests for official courses',
6421: xmldc => 'Identity of course creator of courses from XML files',
6422: );
6423: my @types = ('xml','req');
6424: foreach my $item (@types) {
6425: $newvals{$item} = $env{'form.autocreate_'.$item};
6426: $newvals{$item} =~ s/\D//g;
6427: $newvals{$item} = 0 if ($newvals{$item} eq '');
6428: }
6429: $newvals{'xmldc'} = $env{'form.autocreate_xmldc'};
6430: my %domcoords = &get_active_dcs($dom);
6431: unless (exists($domcoords{$newvals{'xmldc'}})) {
6432: $newvals{'xmldc'} = '';
6433: }
6434: %autocreatehash = (
6435: autocreate => { xml => $newvals{'xml'},
6436: req => $newvals{'req'},
6437: }
6438: );
6439: if ($newvals{'xmldc'} ne '') {
6440: $autocreatehash{'autocreate'}{'xmldc'} = $newvals{'xmldc'};
6441: }
6442: my $putresult = &Apache::lonnet::put_dom('configuration',\%autocreatehash,
6443: $dom);
6444: if ($putresult eq 'ok') {
6445: my @items = @types;
6446: if ($newvals{'xml'}) {
6447: push(@items,'xmldc');
6448: }
6449: foreach my $item (@items) {
6450: if (exists($currautocreate{$item})) {
6451: if ($currautocreate{$item} ne $newvals{$item}) {
6452: $changes{$item} = 1;
6453: }
6454: } elsif ($newvals{$item}) {
6455: $changes{$item} = 1;
6456: }
6457: }
6458: if (keys(%changes) > 0) {
6459: my @offon = ('off','on');
6460: $resulttext = &mt('Changes made:').'<ul>';
6461: foreach my $item (@types) {
6462: if ($changes{$item}) {
6463: my $newtxt = $offon[$newvals{$item}];
6464: $resulttext .= '<li>'.
6465: &mt("$title{$item} set to [_1]$newtxt [_2]",
6466: '<b>','</b>').
6467: '</li>';
6468: }
6469: }
6470: if ($changes{'xmldc'}) {
6471: my ($dcname,$dcdom) = split(':',$newvals{'xmldc'});
6472: my $newtxt = &Apache::loncommon::plainname($dcname,$dcdom);
6473: $resulttext .= '<li>'.&mt("$title{'xmldc'} set to [_1]",'<b>'.$newtxt.'</b>').'</li>';
6474: }
6475: $resulttext .= '</ul>';
6476: } else {
6477: $resulttext = &mt('No changes made to auto-creation settings');
6478: }
6479: } else {
6480: $resulttext = '<span class="LC_error">'.
6481: &mt('An error occurred: [_1]',$putresult).'</span>';
6482: }
6483: return $resulttext;
6484: }
6485:
6486: sub modify_directorysrch {
6487: my ($dom,%domconfig) = @_;
6488: my ($resulttext,%changes);
6489: my %currdirsrch;
6490: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
6491: foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
6492: $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
6493: }
6494: }
6495: my %title = ( available => 'Directory search available',
6496: localonly => 'Other domains can search',
6497: searchby => 'Search types',
6498: searchtypes => 'Search latitude');
6499: my @offon = ('off','on');
6500: my @otherdoms = ('Yes','No');
6501:
6502: my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');
6503: my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
6504: my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
6505:
6506: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
6507: if (keys(%{$usertypes}) == 0) {
6508: @cansearch = ('default');
6509: } else {
6510: if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
6511: foreach my $type (@{$currdirsrch{'cansearch'}}) {
6512: if (!grep(/^\Q$type\E$/,@cansearch)) {
6513: push(@{$changes{'cansearch'}},$type);
6514: }
6515: }
6516: foreach my $type (@cansearch) {
6517: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
6518: push(@{$changes{'cansearch'}},$type);
6519: }
6520: }
6521: } else {
6522: push(@{$changes{'cansearch'}},@cansearch);
6523: }
6524: }
6525:
6526: if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
6527: foreach my $by (@{$currdirsrch{'searchby'}}) {
6528: if (!grep(/^\Q$by\E$/,@searchby)) {
6529: push(@{$changes{'searchby'}},$by);
6530: }
6531: }
6532: foreach my $by (@searchby) {
6533: if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
6534: push(@{$changes{'searchby'}},$by);
6535: }
6536: }
6537: } else {
6538: push(@{$changes{'searchby'}},@searchby);
6539: }
6540:
6541: if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
6542: foreach my $type (@{$currdirsrch{'searchtypes'}}) {
6543: if (!grep(/^\Q$type\E$/,@searchtypes)) {
6544: push(@{$changes{'searchtypes'}},$type);
6545: }
6546: }
6547: foreach my $type (@searchtypes) {
6548: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
6549: push(@{$changes{'searchtypes'}},$type);
6550: }
6551: }
6552: } else {
6553: if (exists($currdirsrch{'searchtypes'})) {
6554: foreach my $type (@searchtypes) {
6555: if ($type ne $currdirsrch{'searchtypes'}) {
6556: push(@{$changes{'searchtypes'}},$type);
6557: }
6558: }
6559: if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
6560: push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
6561: }
6562: } else {
6563: push(@{$changes{'searchtypes'}},@searchtypes);
6564: }
6565: }
6566:
6567: my %dirsrch_hash = (
6568: directorysrch => { available => $env{'form.dirsrch_available'},
6569: cansearch => \@cansearch,
6570: localonly => $env{'form.dirsrch_localonly'},
6571: searchby => \@searchby,
6572: searchtypes => \@searchtypes,
6573: }
6574: );
6575: my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
6576: $dom);
6577: if ($putresult eq 'ok') {
6578: if (exists($currdirsrch{'available'})) {
6579: if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
6580: $changes{'available'} = 1;
6581: }
6582: } else {
6583: if ($env{'form.dirsrch_available'} eq '1') {
6584: $changes{'available'} = 1;
6585: }
6586: }
6587: if (exists($currdirsrch{'localonly'})) {
6588: if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_localonly'}) {
6589: $changes{'localonly'} = 1;
6590: }
6591: } else {
6592: if ($env{'form.dirsrch_localonly'} eq '1') {
6593: $changes{'localonly'} = 1;
6594: }
6595: }
6596: if (keys(%changes) > 0) {
6597: $resulttext = &mt('Changes made:').'<ul>';
6598: if ($changes{'available'}) {
6599: $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
6600: }
6601: if ($changes{'localonly'}) {
6602: $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_localonly'}]").'</li>';
6603: }
6604:
6605: if (ref($changes{'cansearch'}) eq 'ARRAY') {
6606: my $chgtext;
6607: if (ref($usertypes) eq 'HASH') {
6608: if (keys(%{$usertypes}) > 0) {
6609: foreach my $type (@{$types}) {
6610: if (grep(/^\Q$type\E$/,@cansearch)) {
6611: $chgtext .= $usertypes->{$type}.'; ';
6612: }
6613: }
6614: if (grep(/^default$/,@cansearch)) {
6615: $chgtext .= $othertitle;
6616: } else {
6617: $chgtext =~ s/\; $//;
6618: }
6619: $resulttext .=
6620: '<li>'.
6621: &mt("Users from domain '[_1]' permitted to search the institutional directory set to: [_2]",
6622: '<span class="LC_cusr_emph">'.$dom.'</span>',$chgtext).
6623: '</li>';
6624: }
6625: }
6626: }
6627: if (ref($changes{'searchby'}) eq 'ARRAY') {
6628: my ($searchtitles,$titleorder) = &sorted_searchtitles();
6629: my $chgtext;
6630: foreach my $type (@{$titleorder}) {
6631: if (grep(/^\Q$type\E$/,@searchby)) {
6632: if (defined($searchtitles->{$type})) {
6633: $chgtext .= $searchtitles->{$type}.'; ';
6634: }
6635: }
6636: }
6637: $chgtext =~ s/\; $//;
6638: $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
6639: }
6640: if (ref($changes{'searchtypes'}) eq 'ARRAY') {
6641: my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes();
6642: my $chgtext;
6643: foreach my $type (@{$srchtypeorder}) {
6644: if (grep(/^\Q$type\E$/,@searchtypes)) {
6645: if (defined($srchtypes_desc->{$type})) {
6646: $chgtext .= $srchtypes_desc->{$type}.'; ';
6647: }
6648: }
6649: }
6650: $chgtext =~ s/\; $//;
6651: $resulttext .= '<li>'.&mt($title{'searchtypes'}.' set to: "[_1]"',$chgtext).'</li>';
6652: }
6653: $resulttext .= '</ul>';
6654: } else {
6655: $resulttext = &mt('No changes made to institution directory search settings');
6656: }
6657: } else {
6658: $resulttext = '<span class="LC_error">'.
6659: &mt('An error occurred: [_1]',$putresult).'</span>';
6660: }
6661: return $resulttext;
6662: }
6663:
6664: sub modify_contacts {
6665: my ($dom,%domconfig) = @_;
6666: my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
6667: if (ref($domconfig{'contacts'}) eq 'HASH') {
6668: foreach my $key (keys(%{$domconfig{'contacts'}})) {
6669: $currsetting{$key} = $domconfig{'contacts'}{$key};
6670: }
6671: }
6672: my (%others,%to,%bcc);
6673: my @contacts = ('supportemail','adminemail');
6674: my @mailings = ('errormail','packagesmail','helpdeskmail','lonstatusmail',
6675: 'requestsmail','updatesmail');
6676: foreach my $type (@mailings) {
6677: @{$newsetting{$type}} =
6678: &Apache::loncommon::get_env_multiple('form.'.$type);
6679: foreach my $item (@contacts) {
6680: if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
6681: $contacts_hash{contacts}{$type}{$item} = 1;
6682: } else {
6683: $contacts_hash{contacts}{$type}{$item} = 0;
6684: }
6685: }
6686: $others{$type} = $env{'form.'.$type.'_others'};
6687: $contacts_hash{contacts}{$type}{'others'} = $others{$type};
6688: if ($type eq 'helpdeskmail') {
6689: $bcc{$type} = $env{'form.'.$type.'_bcc'};
6690: $contacts_hash{contacts}{$type}{'bcc'} = $bcc{$type};
6691: }
6692: }
6693: foreach my $item (@contacts) {
6694: $to{$item} = $env{'form.'.$item};
6695: $contacts_hash{'contacts'}{$item} = $to{$item};
6696: }
6697: if (keys(%currsetting) > 0) {
6698: foreach my $item (@contacts) {
6699: if ($to{$item} ne $currsetting{$item}) {
6700: $changes{$item} = 1;
6701: }
6702: }
6703: foreach my $type (@mailings) {
6704: foreach my $item (@contacts) {
6705: if (ref($currsetting{$type}) eq 'HASH') {
6706: if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
6707: push(@{$changes{$type}},$item);
6708: }
6709: } else {
6710: push(@{$changes{$type}},@{$newsetting{$type}});
6711: }
6712: }
6713: if ($others{$type} ne $currsetting{$type}{'others'}) {
6714: push(@{$changes{$type}},'others');
6715: }
6716: if ($type eq 'helpdeskmail') {
6717: if ($bcc{$type} ne $currsetting{$type}{'bcc'}) {
6718: push(@{$changes{$type}},'bcc');
6719: }
6720: }
6721: }
6722: } else {
6723: my %default;
6724: $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
6725: $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
6726: $default{'errormail'} = 'adminemail';
6727: $default{'packagesmail'} = 'adminemail';
6728: $default{'helpdeskmail'} = 'supportemail';
6729: $default{'lonstatusmail'} = 'adminemail';
6730: $default{'requestsmail'} = 'adminemail';
6731: $default{'updatesmail'} = 'adminemail';
6732: foreach my $item (@contacts) {
6733: if ($to{$item} ne $default{$item}) {
6734: $changes{$item} = 1;
6735: }
6736: }
6737: foreach my $type (@mailings) {
6738: if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
6739:
6740: push(@{$changes{$type}},@{$newsetting{$type}});
6741: }
6742: if ($others{$type} ne '') {
6743: push(@{$changes{$type}},'others');
6744: }
6745: if ($type eq 'helpdeskmail') {
6746: if ($bcc{$type} ne '') {
6747: push(@{$changes{$type}},'bcc');
6748: }
6749: }
6750: }
6751: }
6752: my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
6753: $dom);
6754: if ($putresult eq 'ok') {
6755: if (keys(%changes) > 0) {
6756: my ($titles,$short_titles) = &contact_titles();
6757: $resulttext = &mt('Changes made:').'<ul>';
6758: foreach my $item (@contacts) {
6759: if ($changes{$item}) {
6760: $resulttext .= '<li>'.$titles->{$item}.
6761: &mt(' set to: ').
6762: '<span class="LC_cusr_emph">'.
6763: $to{$item}.'</span></li>';
6764: }
6765: }
6766: foreach my $type (@mailings) {
6767: if (ref($changes{$type}) eq 'ARRAY') {
6768: $resulttext .= '<li>'.$titles->{$type}.': ';
6769: my @text;
6770: foreach my $item (@{$newsetting{$type}}) {
6771: push(@text,$short_titles->{$item});
6772: }
6773: if ($others{$type} ne '') {
6774: push(@text,$others{$type});
6775: }
6776: $resulttext .= '<span class="LC_cusr_emph">'.
6777: join(', ',@text).'</span>';
6778: if ($type eq 'helpdeskmail') {
6779: if ($bcc{$type} ne '') {
6780: $resulttext .= ' '.&mt('with Bcc to').': <span class="LC_cusr_emph">'.$bcc{$type}.'</span>';
6781: }
6782: }
6783: $resulttext .= '</li>';
6784: }
6785: }
6786: $resulttext .= '</ul>';
6787: } else {
6788: $resulttext = &mt('No changes made to contact information');
6789: }
6790: } else {
6791: $resulttext = '<span class="LC_error">'.
6792: &mt('An error occurred: [_1].',$putresult).'</span>';
6793: }
6794: return $resulttext;
6795: }
6796:
6797: sub modify_usercreation {
6798: my ($dom,%domconfig) = @_;
6799: my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate);
6800: my $warningmsg;
6801: if (ref($domconfig{'usercreation'}) eq 'HASH') {
6802: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
6803: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
6804: }
6805: }
6806: my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
6807: my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
6808: my @email_rule = &Apache::loncommon::get_env_multiple('form.email_rule');
6809: my @contexts = ('author','course','requestcrs','selfcreate');
6810: foreach my $item(@contexts) {
6811: if ($item eq 'selfcreate') {
6812: @{$cancreate{$item}} = &Apache::loncommon::get_env_multiple('form.can_createuser_'.$item);
6813: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
6814: if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) || ($domdefaults{'auth_def'} eq 'localauth'))) {
6815: if (ref($cancreate{$item}) eq 'ARRAY') {
6816: if (grep(/^login$/,@{$cancreate{$item}})) {
6817: $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.');
6818: }
6819: }
6820: }
6821: } else {
6822: $cancreate{$item} = $env{'form.can_createuser_'.$item};
6823: }
6824: }
6825: my ($othertitle,$usertypes,$types) =
6826: &Apache::loncommon::sorted_inst_types($dom);
6827: if (ref($types) eq 'ARRAY') {
6828: if (@{$types} > 0) {
6829: @{$cancreate{'statustocreate'}} =
6830: &Apache::loncommon::get_env_multiple('form.statustocreate');
6831: } else {
6832: @{$cancreate{'statustocreate'}} = ();
6833: }
6834: push(@contexts,'statustocreate');
6835: }
6836: &process_captcha('cancreate',\%changes,\%cancreate,\%curr_usercreation);
6837: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
6838: foreach my $item (@contexts) {
6839: if (($item eq 'selfcreate') || ($item eq 'statustocreate')) {
6840: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
6841: foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
6842: if (ref($cancreate{$item}) eq 'ARRAY') {
6843: if (!grep(/^$curr$/,@{$cancreate{$item}})) {
6844: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6845: push(@{$changes{'cancreate'}},$item);
6846: }
6847: }
6848: }
6849: }
6850: } else {
6851: if ($curr_usercreation{'cancreate'}{$item} eq '') {
6852: if (@{$cancreate{$item}} > 0) {
6853: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6854: push(@{$changes{'cancreate'}},$item);
6855: }
6856: }
6857: } else {
6858: if ($curr_usercreation{'cancreate'}{$item} eq 'any') {
6859: if (@{$cancreate{$item}} < 3) {
6860: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6861: push(@{$changes{'cancreate'}},$item);
6862: }
6863: }
6864: } elsif ($curr_usercreation{'cancreate'}{$item} eq 'none') {
6865: if (@{$cancreate{$item}} > 0) {
6866: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6867: push(@{$changes{'cancreate'}},$item);
6868: }
6869: }
6870: } elsif (!grep(/^$curr_usercreation{'cancreate'}{$item}$/,@{$cancreate{$item}})) {
6871: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6872: push(@{$changes{'cancreate'}},$item);
6873: }
6874: }
6875: }
6876: }
6877: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6878: foreach my $type (@{$cancreate{$item}}) {
6879: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
6880: if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
6881: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6882: push(@{$changes{'cancreate'}},$item);
6883: }
6884: }
6885: } elsif (($curr_usercreation{'cancreate'}{$item} ne 'any') &&
6886: ($curr_usercreation{'cancreate'}{$item} ne 'none')) {
6887: if ($curr_usercreation{'cancreate'}{$item} ne $type) {
6888: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6889: push(@{$changes{'cancreate'}},$item);
6890: }
6891: }
6892: }
6893: }
6894: }
6895: } else {
6896: if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
6897: push(@{$changes{'cancreate'}},$item);
6898: }
6899: }
6900: }
6901: } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
6902: foreach my $item (@contexts) {
6903: if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
6904: if ($cancreate{$item} ne 'any') {
6905: push(@{$changes{'cancreate'}},$item);
6906: }
6907: } else {
6908: if ($cancreate{$item} ne 'none') {
6909: push(@{$changes{'cancreate'}},$item);
6910: }
6911: }
6912: }
6913: } else {
6914: foreach my $item (@contexts) {
6915: push(@{$changes{'cancreate'}},$item);
6916: }
6917: }
6918:
6919: if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
6920: foreach my $type (@{$curr_usercreation{'username_rule'}}) {
6921: if (!grep(/^\Q$type\E$/,@username_rule)) {
6922: push(@{$changes{'username_rule'}},$type);
6923: }
6924: }
6925: foreach my $type (@username_rule) {
6926: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
6927: push(@{$changes{'username_rule'}},$type);
6928: }
6929: }
6930: } else {
6931: push(@{$changes{'username_rule'}},@username_rule);
6932: }
6933:
6934: if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
6935: foreach my $type (@{$curr_usercreation{'id_rule'}}) {
6936: if (!grep(/^\Q$type\E$/,@id_rule)) {
6937: push(@{$changes{'id_rule'}},$type);
6938: }
6939: }
6940: foreach my $type (@id_rule) {
6941: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
6942: push(@{$changes{'id_rule'}},$type);
6943: }
6944: }
6945: } else {
6946: push(@{$changes{'id_rule'}},@id_rule);
6947: }
6948:
6949: if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
6950: foreach my $type (@{$curr_usercreation{'email_rule'}}) {
6951: if (!grep(/^\Q$type\E$/,@email_rule)) {
6952: push(@{$changes{'email_rule'}},$type);
6953: }
6954: }
6955: foreach my $type (@email_rule) {
6956: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'email_rule'}})) {
6957: push(@{$changes{'email_rule'}},$type);
6958: }
6959: }
6960: } else {
6961: push(@{$changes{'email_rule'}},@email_rule);
6962: }
6963:
6964: my @authen_contexts = ('author','course','domain');
6965: my @authtypes = ('int','krb4','krb5','loc');
6966: my %authhash;
6967: foreach my $item (@authen_contexts) {
6968: my @authallowed = &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
6969: foreach my $auth (@authtypes) {
6970: if (grep(/^\Q$auth\E$/,@authallowed)) {
6971: $authhash{$item}{$auth} = 1;
6972: } else {
6973: $authhash{$item}{$auth} = 0;
6974: }
6975: }
6976: }
6977: if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
6978: foreach my $item (@authen_contexts) {
6979: if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
6980: foreach my $auth (@authtypes) {
6981: if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
6982: push(@{$changes{'authtypes'}},$item);
6983: last;
6984: }
6985: }
6986: }
6987: }
6988: } else {
6989: foreach my $item (@authen_contexts) {
6990: push(@{$changes{'authtypes'}},$item);
6991: }
6992: }
6993:
6994: my %usercreation_hash = (
6995: usercreation => {
6996: cancreate => \%cancreate,
6997: username_rule => \@username_rule,
6998: id_rule => \@id_rule,
6999: email_rule => \@email_rule,
7000: authtypes => \%authhash,
7001: }
7002: );
7003:
7004: my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
7005: $dom);
7006:
7007: my %selfcreatetypes = (
7008: sso => 'users authenticated by institutional single sign on',
7009: login => 'users authenticated by institutional log-in',
7010: email => 'users who provide a valid e-mail address for use as the username',
7011: );
7012: if ($putresult eq 'ok') {
7013: if (keys(%changes) > 0) {
7014: $resulttext = &mt('Changes made:').'<ul>';
7015: if (ref($changes{'cancreate'}) eq 'ARRAY') {
7016: my %lt = &usercreation_types();
7017: foreach my $type (@{$changes{'cancreate'}}) {
7018: my $chgtext;
7019: unless (($type eq 'statustocreate') || ($type eq 'captcha') || ($type eq 'recaptchakeys')) {
7020: $chgtext = $lt{$type}.', ';
7021: }
7022: if ($type eq 'selfcreate') {
7023: if (@{$cancreate{$type}} == 0) {
7024: $chgtext .= &mt('creation of a new user account is not permitted.');
7025: } else {
7026: $chgtext .= &mt('creation of a new account is permitted for:').'<ul>';
7027: foreach my $case (@{$cancreate{$type}}) {
7028: $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
7029: }
7030: $chgtext .= '</ul>';
7031: if (ref($cancreate{$type}) eq 'ARRAY') {
7032: if (grep(/^(login|sso)$/,@{$cancreate{$type}})) {
7033: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
7034: if (@{$cancreate{'statustocreate'}} == 0) {
7035: $chgtext .= '<br /><span class="LC_warning">'.&mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").'</span>';
7036: }
7037: }
7038: }
7039: }
7040: }
7041: } elsif ($type eq 'statustocreate') {
7042: if ((ref($cancreate{'selfcreate'}) eq 'ARRAY') &&
7043: (ref($cancreate{'statustocreate'}) eq 'ARRAY')) {
7044: if (@{$cancreate{'selfcreate'}} > 0) {
7045: if (@{$cancreate{'statustocreate'}} == 0) {
7046:
7047: $chgtext .= &mt("Institutional affiliations permitted to create accounts set to 'None'.");
7048: if (!grep(/^email$/,@{$cancreate{'selfcreate'}})) {
7049: $chgtext .= '<br /><span class="LC_warning">'.&mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").'</span>';
7050: }
7051: } elsif (ref($usertypes) eq 'HASH') {
7052: if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
7053: $chgtext .= &mt('Creation of a new account for an institutional user is restricted to the following institutional affiliation(s):');
7054: } else {
7055: $chgtext .= &mt('Institutional affiliations permitted to create accounts with institutional authentication were set as follows:');
7056: }
7057: $chgtext .= '<ul>';
7058: foreach my $case (@{$cancreate{$type}}) {
7059: if ($case eq 'default') {
7060: $chgtext .= '<li>'.$othertitle.'</li>';
7061: } else {
7062: $chgtext .= '<li>'.$usertypes->{$case}.'</li>';
7063: }
7064: }
7065: $chgtext .= '</ul>';
7066: if (!grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
7067: $chgtext .= '<br /><span class="LC_warning">'.&mt('However, users authenticated by institutional login/single sign on are not currently permitted to create accounts.').'</span>';
7068: }
7069: }
7070: } else {
7071: if (@{$cancreate{$type}} == 0) {
7072: $chgtext .= &mt("Institutional affiliations permitted to create accounts were set to 'none'.");
7073: } else {
7074: $chgtext .= &mt('Although institutional affiliations permitted to create accounts were changed, self creation of accounts is not currently permitted for any authentication types.');
7075: }
7076: }
7077: }
7078: } elsif ($type eq 'captcha') {
7079: if ($cancreate{$type} eq 'notused') {
7080: $chgtext .= &mt('No CAPTCHA validation in use for self-creation screen.');
7081: } else {
7082: my %captchas = &captcha_phrases();
7083: if ($captchas{$cancreate{$type}}) {
7084: $chgtext .= &mt("Validation for self-creation screen set to $captchas{$cancreate{$type}}.");
7085: } else {
7086: $chgtext .= &mt('Validation for self-creation screen set to unknown type.');
7087: }
7088: }
7089: } elsif ($type eq 'recaptchakeys') {
7090: my ($privkey,$pubkey);
7091: if (ref($cancreate{$type}) eq 'HASH') {
7092: $pubkey = $cancreate{$type}{'public'};
7093: $privkey = $cancreate{$type}{'private'};
7094: }
7095: $chgtext .= &mt('ReCAPTCHA keys changes').'<ul>';
7096: if (!$pubkey) {
7097: $chgtext .= '<li>'.&mt('Public key deleted').'</li>';
7098: } else {
7099: $chgtext .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
7100: }
7101: if (!$privkey) {
7102: $chgtext .= '<li>'.&mt('Private key deleted').'</li>';
7103: } else {
7104: $chgtext .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
7105: }
7106: $chgtext .= '</ul>';
7107: } else {
7108: if ($cancreate{$type} eq 'none') {
7109: $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
7110: } elsif ($cancreate{$type} eq 'any') {
7111: $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
7112: } elsif ($cancreate{$type} eq 'official') {
7113: $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
7114: } elsif ($cancreate{$type} eq 'unofficial') {
7115: $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
7116: }
7117: }
7118: $resulttext .= '<li>'.$chgtext.'</li>';
7119: }
7120: }
7121: if (ref($changes{'username_rule'}) eq 'ARRAY') {
7122: my ($rules,$ruleorder) =
7123: &Apache::lonnet::inst_userrules($dom,'username');
7124: my $chgtext = '<ul>';
7125: foreach my $type (@username_rule) {
7126: if (ref($rules->{$type}) eq 'HASH') {
7127: $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
7128: }
7129: }
7130: $chgtext .= '</ul>';
7131: if (@username_rule > 0) {
7132: $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
7133: } else {
7134: $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>';
7135: }
7136: }
7137: if (ref($changes{'id_rule'}) eq 'ARRAY') {
7138: my ($idrules,$idruleorder) =
7139: &Apache::lonnet::inst_userrules($dom,'id');
7140: my $chgtext = '<ul>';
7141: foreach my $type (@id_rule) {
7142: if (ref($idrules->{$type}) eq 'HASH') {
7143: $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
7144: }
7145: }
7146: $chgtext .= '</ul>';
7147: if (@id_rule > 0) {
7148: $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
7149: } else {
7150: $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
7151: }
7152: }
7153: if (ref($changes{'email_rule'}) eq 'ARRAY') {
7154: my ($emailrules,$emailruleorder) =
7155: &Apache::lonnet::inst_userrules($dom,'email');
7156: my $chgtext = '<ul>';
7157: foreach my $type (@email_rule) {
7158: if (ref($emailrules->{$type}) eq 'HASH') {
7159: $chgtext .= '<li>'.$emailrules->{$type}{'name'}.'</li>';
7160: }
7161: }
7162: $chgtext .= '</ul>';
7163: if (@email_rule > 0) {
7164: $resulttext .= '<li>'.&mt('Accounts may not be created by users self-enrolling with e-mail addresses of the following types: ').$chgtext.'</li>';
7165: } else {
7166: $resulttext .= '<li>'.&mt('There are now no restrictions on e-mail addresses which may be used as a username when self-enrolling.').'</li>';
7167: }
7168: }
7169:
7170: my %authname = &authtype_names();
7171: my %context_title = &context_names();
7172: if (ref($changes{'authtypes'}) eq 'ARRAY') {
7173: my $chgtext = '<ul>';
7174: foreach my $type (@{$changes{'authtypes'}}) {
7175: my @allowed;
7176: $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
7177: foreach my $auth (@authtypes) {
7178: if ($authhash{$type}{$auth}) {
7179: push(@allowed,$authname{$auth});
7180: }
7181: }
7182: if (@allowed > 0) {
7183: $chgtext .= join(', ',@allowed).'</li>';
7184: } else {
7185: $chgtext .= &mt('none').'</li>';
7186: }
7187: }
7188: $chgtext .= '</ul>';
7189: $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
7190: $resulttext .= '</li>';
7191: }
7192: $resulttext .= '</ul>';
7193: } else {
7194: $resulttext = &mt('No changes made to user creation settings');
7195: }
7196: } else {
7197: $resulttext = '<span class="LC_error">'.
7198: &mt('An error occurred: [_1]',$putresult).'</span>';
7199: }
7200: if ($warningmsg ne '') {
7201: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
7202: }
7203: return $resulttext;
7204: }
7205:
7206: sub process_captcha {
7207: my ($container,$changes,$newsettings,$current) = @_;
7208: return unless ((ref($changes) eq 'HASH') && (ref($newsettings) eq 'HASH') || (ref($current) eq 'HASH'));
7209: $newsettings->{'captcha'} = $env{'form.'.$container.'_captcha'};
7210: unless ($newsettings->{'captcha'} eq 'recaptcha' || $newsettings->{'captcha'} eq 'notused') {
7211: $newsettings->{'captcha'} = 'original';
7212: }
7213: if ($current->{'captcha'} ne $newsettings->{'captcha'}) {
7214: if ($container eq 'cancreate') {
7215: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
7216: push(@{$changes->{'cancreate'}},'captcha');
7217: } elsif (!defined($changes->{'cancreate'})) {
7218: $changes->{'cancreate'} = ['captcha'];
7219: }
7220: } else {
7221: $changes->{'captcha'} = 1;
7222: }
7223: }
7224: my ($newpub,$newpriv,$currpub,$currpriv);
7225: if ($newsettings->{'captcha'} eq 'recaptcha') {
7226: $newpub = $env{'form.'.$container.'_recaptchapub'};
7227: $newpriv = $env{'form.'.$container.'_recaptchapriv'};
7228: $newpub =~ s/\W//g;
7229: $newpriv =~ s/\W//g;
7230: $newsettings->{'recaptchakeys'} = {
7231: public => $newpub,
7232: private => $newpriv,
7233: };
7234: }
7235: if (ref($current->{'recaptchakeys'}) eq 'HASH') {
7236: $currpub = $current->{'recaptchakeys'}{'public'};
7237: $currpriv = $current->{'recaptchakeys'}{'private'};
7238: unless ($newsettings->{'captcha'} eq 'recaptcha') {
7239: $newsettings->{'recaptchakeys'} = {
7240: public => '',
7241: private => '',
7242: }
7243: }
7244: }
7245: if (($newpub ne $currpub) || ($newpriv ne $currpriv)) {
7246: if ($container eq 'cancreate') {
7247: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
7248: push(@{$changes->{'cancreate'}},'recaptchakeys');
7249: } elsif (!defined($changes->{'cancreate'})) {
7250: $changes->{'cancreate'} = ['recaptchakeys'];
7251: }
7252: } else {
7253: $changes->{'recaptchakeys'} = 1;
7254: }
7255: }
7256: return;
7257: }
7258:
7259: sub modify_usermodification {
7260: my ($dom,%domconfig) = @_;
7261: my ($resulttext,%curr_usermodification,%changes);
7262: if (ref($domconfig{'usermodification'}) eq 'HASH') {
7263: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
7264: $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
7265: }
7266: }
7267: my @contexts = ('author','course','selfcreate');
7268: my %context_title = (
7269: author => 'In author context',
7270: course => 'In course context',
7271: selfcreate => 'When self creating account',
7272: );
7273: my @fields = ('lastname','firstname','middlename','generation',
7274: 'permanentemail','id');
7275: my %roles = (
7276: author => ['ca','aa'],
7277: course => ['st','ep','ta','in','cr'],
7278: );
7279: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
7280: if (ref($types) eq 'ARRAY') {
7281: push(@{$types},'default');
7282: $usertypes->{'default'} = $othertitle;
7283: }
7284: $roles{'selfcreate'} = $types;
7285: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
7286: my %modifyhash;
7287: foreach my $context (@contexts) {
7288: foreach my $role (@{$roles{$context}}) {
7289: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$role);
7290: foreach my $item (@fields) {
7291: if (grep(/^\Q$item\E$/,@modifiable)) {
7292: $modifyhash{$context}{$role}{$item} = 1;
7293: } else {
7294: $modifyhash{$context}{$role}{$item} = 0;
7295: }
7296: }
7297: }
7298: if (ref($curr_usermodification{$context}) eq 'HASH') {
7299: foreach my $role (@{$roles{$context}}) {
7300: if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
7301: foreach my $field (@fields) {
7302: if ($modifyhash{$context}{$role}{$field} ne
7303: $curr_usermodification{$context}{$role}{$field}) {
7304: push(@{$changes{$context}},$role);
7305: last;
7306: }
7307: }
7308: }
7309: }
7310: } else {
7311: foreach my $context (@contexts) {
7312: foreach my $role (@{$roles{$context}}) {
7313: push(@{$changes{$context}},$role);
7314: }
7315: }
7316: }
7317: }
7318: my %usermodification_hash = (
7319: usermodification => \%modifyhash,
7320: );
7321: my $putresult = &Apache::lonnet::put_dom('configuration',
7322: \%usermodification_hash,$dom);
7323: if ($putresult eq 'ok') {
7324: if (keys(%changes) > 0) {
7325: $resulttext = &mt('Changes made: ').'<ul>';
7326: foreach my $context (@contexts) {
7327: if (ref($changes{$context}) eq 'ARRAY') {
7328: $resulttext .= '<li>'.$context_title{$context}.':<ul>';
7329: if (ref($changes{$context}) eq 'ARRAY') {
7330: foreach my $role (@{$changes{$context}}) {
7331: my $rolename;
7332: if ($context eq 'selfcreate') {
7333: $rolename = $role;
7334: if (ref($usertypes) eq 'HASH') {
7335: if ($usertypes->{$role} ne '') {
7336: $rolename = $usertypes->{$role};
7337: }
7338: }
7339: } else {
7340: if ($role eq 'cr') {
7341: $rolename = &mt('Custom');
7342: } else {
7343: $rolename = &Apache::lonnet::plaintext($role);
7344: }
7345: }
7346: my @modifiable;
7347: if ($context eq 'selfcreate') {
7348: $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): ');
7349: } else {
7350: $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
7351: }
7352: foreach my $field (@fields) {
7353: if ($modifyhash{$context}{$role}{$field}) {
7354: push(@modifiable,$fieldtitles{$field});
7355: }
7356: }
7357: if (@modifiable > 0) {
7358: $resulttext .= join(', ',@modifiable);
7359: } else {
7360: $resulttext .= &mt('none');
7361: }
7362: $resulttext .= '</li>';
7363: }
7364: $resulttext .= '</ul></li>';
7365: }
7366: }
7367: }
7368: $resulttext .= '</ul>';
7369: } else {
7370: $resulttext = &mt('No changes made to user modification settings');
7371: }
7372: } else {
7373: $resulttext = '<span class="LC_error">'.
7374: &mt('An error occurred: [_1]',$putresult).'</span>';
7375: }
7376: return $resulttext;
7377: }
7378:
7379: sub modify_defaults {
7380: my ($dom,$r) = @_;
7381: my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
7382: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
7383: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def','portal_def');
7384: my @authtypes = ('internal','krb4','krb5','localauth');
7385: foreach my $item (@items) {
7386: $newvalues{$item} = $env{'form.'.$item};
7387: if ($item eq 'auth_def') {
7388: if ($newvalues{$item} ne '') {
7389: if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
7390: push(@errors,$item);
7391: }
7392: }
7393: } elsif ($item eq 'lang_def') {
7394: if ($newvalues{$item} ne '') {
7395: if ($newvalues{$item} =~ /^(\w+)/) {
7396: my $langcode = $1;
7397: if ($langcode ne 'x_chef') {
7398: if (code2language($langcode) eq '') {
7399: push(@errors,$item);
7400: }
7401: }
7402: } else {
7403: push(@errors,$item);
7404: }
7405: }
7406: } elsif ($item eq 'timezone_def') {
7407: if ($newvalues{$item} ne '') {
7408: if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
7409: push(@errors,$item);
7410: }
7411: }
7412: } elsif ($item eq 'datelocale_def') {
7413: if ($newvalues{$item} ne '') {
7414: my @datelocale_ids = DateTime::Locale->ids();
7415: if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
7416: push(@errors,$item);
7417: }
7418: }
7419: } elsif ($item eq 'portal_def') {
7420: if ($newvalues{$item} ne '') {
7421: 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])\/?$/) {
7422: push(@errors,$item);
7423: }
7424: }
7425: }
7426: if (grep(/^\Q$item\E$/,@errors)) {
7427: $newvalues{$item} = $domdefaults{$item};
7428: } elsif ($domdefaults{$item} ne $newvalues{$item}) {
7429: $changes{$item} = 1;
7430: }
7431: $domdefaults{$item} = $newvalues{$item};
7432: }
7433: my %defaults_hash = (
7434: defaults => \%newvalues,
7435: );
7436: my $title = &defaults_titles();
7437: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
7438: $dom);
7439: if ($putresult eq 'ok') {
7440: if (keys(%changes) > 0) {
7441: $resulttext = &mt('Changes made:').'<ul>';
7442: my $version = $r->dir_config('lonVersion');
7443: 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";
7444: foreach my $item (sort(keys(%changes))) {
7445: my $value = $env{'form.'.$item};
7446: if ($value eq '') {
7447: $value = &mt('none');
7448: } elsif ($item eq 'auth_def') {
7449: my %authnames = &authtype_names();
7450: my %shortauth = (
7451: internal => 'int',
7452: krb4 => 'krb4',
7453: krb5 => 'krb5',
7454: localauth => 'loc',
7455: );
7456: $value = $authnames{$shortauth{$value}};
7457: }
7458: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
7459: $mailmsgtext .= "$title->{$item} set to $value\n";
7460: }
7461: $resulttext .= '</ul>';
7462: $mailmsgtext .= "\n";
7463: my $cachetime = 24*60*60;
7464: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
7465: if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
7466: my $sysmail = $r->dir_config('lonSysEMail');
7467: &Apache::lonmsg::sendemail($sysmail,"LON-CAPA Domain Settings Change - $dom",$mailmsgtext);
7468: }
7469: } else {
7470: $resulttext = &mt('No changes made to default authentication/language/timezone settings');
7471: }
7472: } else {
7473: $resulttext = '<span class="LC_error">'.
7474: &mt('An error occurred: [_1]',$putresult).'</span>';
7475: }
7476: if (@errors > 0) {
7477: $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
7478: foreach my $item (@errors) {
7479: $resulttext .= ' "'.$title->{$item}.'",';
7480: }
7481: $resulttext =~ s/,$//;
7482: }
7483: return $resulttext;
7484: }
7485:
7486: sub modify_scantron {
7487: my ($r,$dom,$confname,%domconfig) = @_;
7488: my ($resulttext,%confhash,%changes,$errors);
7489: my $custom = 'custom.tab';
7490: my $default = 'default.tab';
7491: my $servadm = $r->dir_config('lonAdmEMail');
7492: my ($configuserok,$author_ok,$switchserver) =
7493: &config_check($dom,$confname,$servadm);
7494: if ($env{'form.scantronformat.filename'} ne '') {
7495: my $error;
7496: if ($configuserok eq 'ok') {
7497: if ($switchserver) {
7498: $error = &mt("Upload of bubblesheet format file is not permitted to this server: [_1]",$switchserver);
7499: } else {
7500: if ($author_ok eq 'ok') {
7501: my ($result,$scantronurl) =
7502: &publishlogo($r,'upload','scantronformat',$dom,
7503: $confname,'scantron','','',$custom);
7504: if ($result eq 'ok') {
7505: $confhash{'scantron'}{'scantronformat'} = $scantronurl;
7506: $changes{'scantronformat'} = 1;
7507: } else {
7508: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
7509: }
7510: } else {
7511: $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);
7512: }
7513: }
7514: } else {
7515: $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);
7516: }
7517: if ($error) {
7518: &Apache::lonnet::logthis($error);
7519: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
7520: }
7521: }
7522: if (ref($domconfig{'scantron'}) eq 'HASH') {
7523: if ($domconfig{'scantron'}{'scantronformat'} ne '') {
7524: if ($env{'form.scantronformat_del'}) {
7525: $confhash{'scantron'}{'scantronformat'} = '';
7526: $changes{'scantronformat'} = 1;
7527: }
7528: }
7529: }
7530: if (keys(%confhash) > 0) {
7531: my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
7532: $dom);
7533: if ($putresult eq 'ok') {
7534: if (keys(%changes) > 0) {
7535: if (ref($confhash{'scantron'}) eq 'HASH') {
7536: $resulttext = &mt('Changes made:').'<ul>';
7537: if ($confhash{'scantron'}{'scantronformat'} eq '') {
7538: $resulttext .= '<li>'.&mt('[_1] bubblesheet format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
7539: } else {
7540: $resulttext .= '<li>'.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
7541: }
7542: $resulttext .= '</ul>';
7543: } else {
7544: $resulttext = &mt('Changes made to bubblesheet format file.');
7545: }
7546: $resulttext .= '</ul>';
7547: &Apache::loncommon::devalidate_domconfig_cache($dom);
7548: } else {
7549: $resulttext = &mt('No changes made to bubblesheet format file');
7550: }
7551: } else {
7552: $resulttext = '<span class="LC_error">'.
7553: &mt('An error occurred: [_1]',$putresult).'</span>';
7554: }
7555: } else {
7556: $resulttext = &mt('No changes made to bubblesheet format file');
7557: }
7558: if ($errors) {
7559: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
7560: $errors.'</ul>';
7561: }
7562: return $resulttext;
7563: }
7564:
7565: sub modify_coursecategories {
7566: my ($dom,%domconfig) = @_;
7567: my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
7568: $cathash);
7569: my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
7570: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
7571: $cathash = $domconfig{'coursecategories'}{'cats'};
7572: if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
7573: $changes{'togglecats'} = 1;
7574: $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
7575: }
7576: if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
7577: $changes{'categorize'} = 1;
7578: $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
7579: }
7580: if ($domconfig{'coursecategories'}{'togglecatscomm'} ne $env{'form.togglecatscomm'}) {
7581: $changes{'togglecatscomm'} = 1;
7582: $domconfig{'coursecategories'}{'togglecatscomm'} = $env{'form.togglecatscomm'};
7583: }
7584: if ($domconfig{'coursecategories'}{'categorizecomm'} ne $env{'form.categorizecomm'}) {
7585: $changes{'categorizecomm'} = 1;
7586: $domconfig{'coursecategories'}{'categorizecomm'} = $env{'form.categorizecomm'};
7587: }
7588: } else {
7589: $changes{'togglecats'} = 1;
7590: $changes{'categorize'} = 1;
7591: $changes{'togglecatscomm'} = 1;
7592: $changes{'categorizecomm'} = 1;
7593: $domconfig{'coursecategories'} = {
7594: togglecats => $env{'form.togglecats'},
7595: categorize => $env{'form.categorize'},
7596: togglecatscomm => $env{'form.togglecatscomm'},
7597: categorizecomm => $env{'form.categorizecomm'},
7598: };
7599: }
7600: if (ref($cathash) eq 'HASH') {
7601: if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '') && ($env{'form.instcode'} == 0)) {
7602: push (@deletecategory,'instcode::0');
7603: }
7604: if (($domconfig{'coursecategories'}{'cats'}{'communities::0'} ne '') && ($env{'form.communities'} == 0)) {
7605: push(@deletecategory,'communities::0');
7606: }
7607: }
7608: my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
7609: if (ref($cathash) eq 'HASH') {
7610: if (@deletecategory > 0) {
7611: #FIXME Need to remove category from all courses using a deleted category
7612: &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
7613: foreach my $item (@deletecategory) {
7614: if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
7615: delete($domconfig{'coursecategories'}{'cats'}{$item});
7616: $deletions{$item} = 1;
7617: &recurse_cat_deletes($item,$cathash,\%deletions);
7618: }
7619: }
7620: }
7621: foreach my $item (keys(%{$cathash})) {
7622: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
7623: if ($cathash->{$item} ne $env{'form.'.$item}) {
7624: $reorderings{$item} = 1;
7625: $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
7626: }
7627: if ($env{'form.addcategory_name_'.$item} ne '') {
7628: my $newcat = $env{'form.addcategory_name_'.$item};
7629: my $newdepth = $depth+1;
7630: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
7631: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
7632: $adds{$newitem} = 1;
7633: }
7634: if ($env{'form.subcat_'.$item} ne '') {
7635: my $newcat = $env{'form.subcat_'.$item};
7636: my $newdepth = $depth+1;
7637: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
7638: $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
7639: $adds{$newitem} = 1;
7640: }
7641: }
7642: }
7643: if ($env{'form.instcode'} eq '1') {
7644: if (ref($cathash) eq 'HASH') {
7645: my $newitem = 'instcode::0';
7646: if ($cathash->{$newitem} eq '') {
7647: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
7648: $adds{$newitem} = 1;
7649: }
7650: } else {
7651: my $newitem = 'instcode::0';
7652: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
7653: $adds{$newitem} = 1;
7654: }
7655: }
7656: if ($env{'form.communities'} eq '1') {
7657: if (ref($cathash) eq 'HASH') {
7658: my $newitem = 'communities::0';
7659: if ($cathash->{$newitem} eq '') {
7660: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
7661: $adds{$newitem} = 1;
7662: }
7663: } else {
7664: my $newitem = 'communities::0';
7665: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
7666: $adds{$newitem} = 1;
7667: }
7668: }
7669: if ($env{'form.addcategory_name'} ne '') {
7670: if (($env{'form.addcategory_name'} ne 'instcode') &&
7671: ($env{'form.addcategory_name'} ne 'communities')) {
7672: my $newitem = &escape($env{'form.addcategory_name'}).'::0';
7673: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
7674: $adds{$newitem} = 1;
7675: }
7676: }
7677: my $putresult;
7678: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
7679: if (keys(%deletions) > 0) {
7680: foreach my $key (keys(%deletions)) {
7681: if ($predelallitems{$key} ne '') {
7682: $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
7683: }
7684: }
7685: }
7686: my (@chkcats,@chktrails,%chkallitems);
7687: &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
7688: if (ref($chkcats[0]) eq 'ARRAY') {
7689: my $depth = 0;
7690: my $chg = 0;
7691: for (my $i=0; $i<@{$chkcats[0]}; $i++) {
7692: my $name = $chkcats[0][$i];
7693: my $item;
7694: if ($name eq '') {
7695: $chg ++;
7696: } else {
7697: $item = &escape($name).'::0';
7698: if ($chg) {
7699: $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
7700: }
7701: $depth ++;
7702: &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
7703: $depth --;
7704: }
7705: }
7706: }
7707: }
7708: if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
7709: $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
7710: if ($putresult eq 'ok') {
7711: my %title = (
7712: togglecats => 'Show/Hide a course in catalog',
7713: categorize => 'Assign a category to a course',
7714: togglecatscomm => 'Show/Hide a community in catalog',
7715: categorizecomm => 'Assign a category to a community',
7716: );
7717: my %level = (
7718: dom => 'set in Domain ("Modify Course/Community")',
7719: crs => 'set in Course ("Course Configuration")',
7720: comm => 'set in Community ("Community Configuration")',
7721: );
7722: $resulttext = &mt('Changes made:').'<ul>';
7723: if ($changes{'togglecats'}) {
7724: $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>';
7725: }
7726: if ($changes{'categorize'}) {
7727: $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
7728: }
7729: if ($changes{'togglecatscomm'}) {
7730: $resulttext .= '<li>'.&mt("$title{'togglecatscomm'} $level{$env{'form.togglecatscomm'}}").'</li>';
7731: }
7732: if ($changes{'categorizecomm'}) {
7733: $resulttext .= '<li>'.&mt("$title{'categorizecomm'} $level{$env{'form.categorizecomm'}}").'</li>';
7734: }
7735: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
7736: my $cathash;
7737: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
7738: $cathash = $domconfig{'coursecategories'}{'cats'};
7739: } else {
7740: $cathash = {};
7741: }
7742: my (@cats,@trails,%allitems);
7743: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
7744: if (keys(%deletions) > 0) {
7745: $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
7746: foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) {
7747: $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
7748: }
7749: $resulttext .= '</ul></li>';
7750: }
7751: if (keys(%reorderings) > 0) {
7752: my %sort_by_trail;
7753: $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
7754: foreach my $key (keys(%reorderings)) {
7755: if ($allitems{$key} ne '') {
7756: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
7757: }
7758: }
7759: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
7760: $resulttext .= '<li>'.$trails[$trail].'</li>';
7761: }
7762: $resulttext .= '</ul></li>';
7763: }
7764: if (keys(%adds) > 0) {
7765: my %sort_by_trail;
7766: $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
7767: foreach my $key (keys(%adds)) {
7768: if ($allitems{$key} ne '') {
7769: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
7770: }
7771: }
7772: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
7773: $resulttext .= '<li>'.$trails[$trail].'</li>';
7774: }
7775: $resulttext .= '</ul></li>';
7776: }
7777: }
7778: $resulttext .= '</ul>';
7779: } else {
7780: $resulttext = '<span class="LC_error">'.
7781: &mt('An error occurred: [_1]',$putresult).'</span>';
7782: }
7783: } else {
7784: $resulttext = &mt('No changes made to course and community categories');
7785: }
7786: return $resulttext;
7787: }
7788:
7789: sub modify_serverstatuses {
7790: my ($dom,%domconfig) = @_;
7791: my ($resulttext,%changes,%currserverstatus,%newserverstatus);
7792: if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
7793: %currserverstatus = %{$domconfig{'serverstatuses'}};
7794: }
7795: my @pages = &serverstatus_pages();
7796: foreach my $type (@pages) {
7797: $newserverstatus{$type}{'namedusers'} = '';
7798: $newserverstatus{$type}{'machines'} = '';
7799: if (defined($env{'form.'.$type.'_namedusers'})) {
7800: my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
7801: my @okusers;
7802: foreach my $user (@users) {
7803: my ($uname,$udom) = split(/:/,$user);
7804: if (($udom =~ /^$match_domain$/) &&
7805: (&Apache::lonnet::domain($udom)) &&
7806: ($uname =~ /^$match_username$/)) {
7807: if (!grep(/^\Q$user\E/,@okusers)) {
7808: push(@okusers,$user);
7809: }
7810: }
7811: }
7812: if (@okusers > 0) {
7813: @okusers = sort(@okusers);
7814: $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
7815: }
7816: }
7817: if (defined($env{'form.'.$type.'_machines'})) {
7818: my @machines = split(/,/,$env{'form.'.$type.'_machines'});
7819: my @okmachines;
7820: foreach my $ip (@machines) {
7821: my @parts = split(/\./,$ip);
7822: next if (@parts < 4);
7823: my $badip = 0;
7824: for (my $i=0; $i<4; $i++) {
7825: if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
7826: $badip = 1;
7827: last;
7828: }
7829: }
7830: if (!$badip) {
7831: push(@okmachines,$ip);
7832: }
7833: }
7834: @okmachines = sort(@okmachines);
7835: $newserverstatus{$type}{'machines'} = join(',',@okmachines);
7836: }
7837: }
7838: my %serverstatushash = (
7839: serverstatuses => \%newserverstatus,
7840: );
7841: foreach my $type (@pages) {
7842: foreach my $setting ('namedusers','machines') {
7843: my (@current,@new);
7844: if (ref($currserverstatus{$type}) eq 'HASH') {
7845: if ($currserverstatus{$type}{$setting} ne '') {
7846: @current = split(/,/,$currserverstatus{$type}{$setting});
7847: }
7848: }
7849: if ($newserverstatus{$type}{$setting} ne '') {
7850: @new = split(/,/,$newserverstatus{$type}{$setting});
7851: }
7852: if (@current > 0) {
7853: if (@new > 0) {
7854: foreach my $item (@current) {
7855: if (!grep(/^\Q$item\E$/,@new)) {
7856: $changes{$type}{$setting} = 1;
7857: last;
7858: }
7859: }
7860: foreach my $item (@new) {
7861: if (!grep(/^\Q$item\E$/,@current)) {
7862: $changes{$type}{$setting} = 1;
7863: last;
7864: }
7865: }
7866: } else {
7867: $changes{$type}{$setting} = 1;
7868: }
7869: } elsif (@new > 0) {
7870: $changes{$type}{$setting} = 1;
7871: }
7872: }
7873: }
7874: if (keys(%changes) > 0) {
7875: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
7876: my $putresult = &Apache::lonnet::put_dom('configuration',
7877: \%serverstatushash,$dom);
7878: if ($putresult eq 'ok') {
7879: $resulttext .= &mt('Changes made:').'<ul>';
7880: foreach my $type (@pages) {
7881: if (ref($changes{$type}) eq 'HASH') {
7882: $resulttext .= '<li>'.$titles->{$type}.'<ul>';
7883: if ($changes{$type}{'namedusers'}) {
7884: if ($newserverstatus{$type}{'namedusers'} eq '') {
7885: $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n";
7886: } else {
7887: $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n";
7888: }
7889: }
7890: if ($changes{$type}{'machines'}) {
7891: if ($newserverstatus{$type}{'machines'} eq '') {
7892: $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n";
7893: } else {
7894: $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n";
7895: }
7896:
7897: }
7898: $resulttext .= '</ul></li>';
7899: }
7900: }
7901: $resulttext .= '</ul>';
7902: } else {
7903: $resulttext = '<span class="LC_error">'.
7904: &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>';
7905:
7906: }
7907: } else {
7908: $resulttext = &mt('No changes made to access to server status pages');
7909: }
7910: return $resulttext;
7911: }
7912:
7913: sub modify_helpsettings {
7914: my ($r,$dom,$confname,%domconfig) = @_;
7915: my ($resulttext,$errors,%changes,%helphash);
7916: my %defaultchecked = ('submitbugs' => 'on');
7917: my @offon = ('off','on');
7918: my @toggles = ('submitbugs');
7919: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
7920: foreach my $item (@toggles) {
7921: if ($defaultchecked{$item} eq 'on') {
7922: if ($domconfig{'helpsettings'}{$item} eq '') {
7923: if ($env{'form.'.$item} eq '0') {
7924: $changes{$item} = 1;
7925: }
7926: } elsif ($domconfig{'helpsettings'}{$item} ne $env{'form.'.$item}) {
7927: $changes{$item} = 1;
7928: }
7929: } elsif ($defaultchecked{$item} eq 'off') {
7930: if ($domconfig{'helpsettings'}{$item} eq '') {
7931: if ($env{'form.'.$item} eq '1') {
7932: $changes{$item} = 1;
7933: }
7934: } elsif ($domconfig{'helpsettings'}{$item} ne $env{'form.'.$item}) {
7935: $changes{$item} = 1;
7936: }
7937: }
7938: if (($env{'form.'.$item} eq '0') || ($env{'form.'.$item} eq '1')) {
7939: $helphash{'helpsettings'}{$item} = $env{'form.'.$item};
7940: }
7941: }
7942: }
7943: my $putresult;
7944: if (keys(%changes) > 0) {
7945: $putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom);
7946: if ($putresult eq 'ok') {
7947: $resulttext = &mt('Changes made:').'<ul>';
7948: foreach my $item (sort(keys(%changes))) {
7949: if ($item eq 'submitbugs') {
7950: $resulttext .= '<li>'.&mt('Display link to: [_1] set to "'.$offon[$env{'form.'.$item}].'".',
7951: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
7952: &mt('LON-CAPA bug tracker'),600,500)).'</li>';
7953: }
7954: }
7955: $resulttext .= '</ul>';
7956: } else {
7957: $resulttext = &mt('No changes made to help settings');
7958: $errors .= '<li><span class="LC_error">'.
7959: &mt('An error occurred storing the settings: [_1]',
7960: $putresult).'</span></li>';
7961: }
7962: }
7963: if ($errors) {
7964: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
7965: $errors.'</ul>';
7966: }
7967: return $resulttext;
7968: }
7969:
7970: sub modify_coursedefaults {
7971: my ($dom,%domconfig) = @_;
7972: my ($resulttext,$errors,%changes,%defaultshash);
7973: my %defaultchecked = ('canuse_pdfforms' => 'off');
7974: my @toggles = ('canuse_pdfforms');
7975: my @numbers = ('anonsurvey_threshold','uploadquota_official','uploadquota_unofficial',
7976: 'uploadquota_community');
7977: my @types = ('official','unofficial','community');
7978: my %staticdefaults = (
7979: anonsurvey_threshold => 10,
7980: uploadquota => 500,
7981: );
7982:
7983: $defaultshash{'coursedefaults'} = {};
7984:
7985: if (ref($domconfig{'coursedefaults'}) ne 'HASH') {
7986: if ($domconfig{'coursedefaults'} eq '') {
7987: $domconfig{'coursedefaults'} = {};
7988: }
7989: }
7990:
7991: if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
7992: foreach my $item (@toggles) {
7993: if ($defaultchecked{$item} eq 'on') {
7994: if (($domconfig{'coursedefaults'}{$item} eq '') &&
7995: ($env{'form.'.$item} eq '0')) {
7996: $changes{$item} = 1;
7997: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
7998: $changes{$item} = 1;
7999: }
8000: } elsif ($defaultchecked{$item} eq 'off') {
8001: if (($domconfig{'coursedefaults'}{$item} eq '') &&
8002: ($env{'form.'.$item} eq '1')) {
8003: $changes{$item} = 1;
8004: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
8005: $changes{$item} = 1;
8006: }
8007: }
8008: $defaultshash{'coursedefaults'}{$item} = $env{'form.'.$item};
8009: }
8010: foreach my $item (@numbers) {
8011: my ($currdef,$newdef);
8012: my $newdef = $env{'form.'.$item};
8013: if ($item eq 'anonsurvey_threshold') {
8014: $currdef = $domconfig{'coursedefaults'}{$item};
8015: $newdef =~ s/\D//g;
8016: if ($newdef eq '' || $newdef < 1) {
8017: $newdef = 1;
8018: }
8019: $defaultshash{'coursedefaults'}{$item} = $newdef;
8020: } else {
8021: my ($type) = ($item =~ /^\Quploadquota_\E(\w+)$/);
8022: if (ref($domconfig{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
8023: $currdef = $domconfig{'coursedefaults'}{'uploadquota'}{$type};
8024: }
8025: $newdef =~ s/[^\w.\-]//g;
8026: $defaultshash{'coursedefaults'}{'uploadquota'}{$type} = $newdef;
8027: }
8028: if ($currdef ne $newdef) {
8029: my $staticdef;
8030: if ($item eq 'anonsurvey_threshold') {
8031: unless (($currdef eq '') && ($newdef == $staticdefaults{$item})) {
8032: $changes{$item} = 1;
8033: }
8034: } else {
8035: unless (($currdef eq '') && ($newdef == $staticdefaults{'uploadquota'})) {
8036: $changes{'uploadquota'} = 1;
8037: }
8038: }
8039: }
8040: }
8041: my $officialcreds = $env{'form.official_credits'};
8042: $officialcreds =~ s/^[^\d\.]//g;
8043: my $unofficialcreds = $env{'form.unofficial_credits'};
8044: $unofficialcreds =~ s/^[^\d\.]//g;
8045: if (ref($domconfig{'coursedefaults'}{'coursecredits'} ne 'HASH') &&
8046: ($env{'form.coursecredits'} eq '1')) {
8047: $changes{'coursecredits'} = 1;
8048: } else {
8049: if (($domconfig{'coursedefaults'}{'coursecredits'}{'official'} ne $officialcreds) ||
8050: ($domconfig{'coursedefaults'}{'coursecredits'}{'unofficial'} ne $unofficialcreds)) {
8051: $changes{'coursecredits'} = 1;
8052: }
8053: }
8054: $defaultshash{'coursedefaults'}{'coursecredits'} = {
8055: official => $officialcreds,
8056: unofficial => $unofficialcreds,
8057: }
8058: }
8059: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
8060: $dom);
8061: if ($putresult eq 'ok') {
8062: my %domdefaults;
8063: if (keys(%changes) > 0) {
8064: if (($changes{'canuse_pdfforms'}) || ($changes{'coursecredits'}) || ($changes{'uploadquota'})) {
8065: %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
8066: if ($changes{'canuse_pdfforms'}) {
8067: $domdefaults{'canuse_pdfforms'}=$defaultshash{'coursedefaults'}{'canuse_pdfforms'};
8068: }
8069: if ($changes{'coursecredits'}) {
8070: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
8071: $domdefaults{'officialcredits'} =
8072: $defaultshash{'coursedefaults'}{'coursecredits'}{'official'};
8073: $domdefaults{'unofficialcredits'} =
8074: $defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'};
8075: }
8076: }
8077: if ($changes{'uploadquota'}) {
8078: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
8079: foreach my $type (@types) {
8080: $domdefaults{$type.'quota'}=$defaultshash{'coursedefaults'}{'uploadquota'}{$type};
8081: }
8082: }
8083: }
8084: my $cachetime = 24*60*60;
8085: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
8086: }
8087: $resulttext = &mt('Changes made:').'<ul>';
8088: foreach my $item (sort(keys(%changes))) {
8089: if ($item eq 'canuse_pdfforms') {
8090: if ($env{'form.'.$item} eq '1') {
8091: $resulttext .= '<li>'.&mt("Course/Community users can create/upload PDF forms set to 'on'").'</li>';
8092: } else {
8093: $resulttext .= '<li>'.&mt('Course/Community users can create/upload PDF forms set to "off"').'</li>';
8094: }
8095: } elsif ($item eq 'anonsurvey_threshold') {
8096: $resulttext .= '<li>'.&mt('Responder count required for display of anonymous survey submissions set to [_1].',$defaultshash{'coursedefaults'}{'anonsurvey_threshold'}).'</li>';
8097: } elsif ($item eq 'uploadquota') {
8098: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
8099: $resulttext .= '<li>'.&mt('Default quota for content uploaded to a course/community via Course Editor set as follows:').'<ul>'.
8100: '<li>'.&mt('Official courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'official'}.'</b>').'</li>'.
8101: '<li>'.&mt('Unofficial courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'unofficial'}.'</b>').'</li>'.
8102: '<li>'.&mt('Communities: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'community'}.'</b>').'</li>'.
8103: '</ul>'.
8104: '</li>';
8105: } else {
8106: $resulttext .= '<li>'.&mt('Default quota for content uploaded via Course Editor remains default: [_1] MB',$staticdefaults{'uploadquota'}).'</li>';
8107: }
8108: } elsif ($item eq 'coursecredits') {
8109: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
8110: if (($domdefaults{'officialcredits'} eq '') &&
8111: ($domdefaults{'unofficialcredits'} eq '')) {
8112: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
8113: } else {
8114: $resulttext .= '<li>'.&mt('Student credits can be set per course by a Domain Coordinator, with the following defaults applying:').'<ul>'.
8115: '<li>'.&mt('Official courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'official'}).'</li>'.
8116: '<li>'.&mt('Unofficial courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'}).'</li>'.
8117: '</ul>'.
8118: '</li>';
8119: }
8120: } else {
8121: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
8122: }
8123: }
8124: }
8125: $resulttext .= '</ul>';
8126: } else {
8127: $resulttext = &mt('No changes made to course defaults');
8128: }
8129: } else {
8130: $resulttext = '<span class="LC_error">'.
8131: &mt('An error occurred: [_1]',$putresult).'</span>';
8132: }
8133: return $resulttext;
8134: }
8135:
8136: sub modify_usersessions {
8137: my ($dom,%domconfig) = @_;
8138: my @hostingtypes = ('version','excludedomain','includedomain');
8139: my @offloadtypes = ('primary','default');
8140: my %types = (
8141: remote => \@hostingtypes,
8142: hosted => \@hostingtypes,
8143: spares => \@offloadtypes,
8144: );
8145: my @prefixes = ('remote','hosted','spares');
8146: my @lcversions = &Apache::lonnet::all_loncaparevs();
8147: my (%by_ip,%by_location,@intdoms);
8148: &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
8149: my @locations = sort(keys(%by_location));
8150: my (%defaultshash,%changes);
8151: foreach my $prefix (@prefixes) {
8152: $defaultshash{'usersessions'}{$prefix} = {};
8153: }
8154: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
8155: my $resulttext;
8156: my %iphost = &Apache::lonnet::get_iphost();
8157: foreach my $prefix (@prefixes) {
8158: next if ($prefix eq 'spares');
8159: foreach my $type (@{$types{$prefix}}) {
8160: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
8161: if ($type eq 'version') {
8162: my $value = $env{'form.'.$prefix.'_'.$type};
8163: my $okvalue;
8164: if ($value ne '') {
8165: if (grep(/^\Q$value\E$/,@lcversions)) {
8166: $okvalue = $value;
8167: }
8168: }
8169: if (ref($domconfig{'usersessions'}) eq 'HASH') {
8170: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
8171: if ($domconfig{'usersessions'}{$prefix}{$type} ne '') {
8172: if ($inuse == 0) {
8173: $changes{$prefix}{$type} = 1;
8174: } else {
8175: if ($okvalue ne $domconfig{'usersessions'}{$prefix}{$type}) {
8176: $changes{$prefix}{$type} = 1;
8177: }
8178: if ($okvalue ne '') {
8179: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
8180: }
8181: }
8182: } else {
8183: if (($inuse == 1) && ($okvalue ne '')) {
8184: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
8185: $changes{$prefix}{$type} = 1;
8186: }
8187: }
8188: } else {
8189: if (($inuse == 1) && ($okvalue ne '')) {
8190: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
8191: $changes{$prefix}{$type} = 1;
8192: }
8193: }
8194: } else {
8195: if (($inuse == 1) && ($okvalue ne '')) {
8196: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
8197: $changes{$prefix}{$type} = 1;
8198: }
8199: }
8200: } else {
8201: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
8202: my @okvals;
8203: foreach my $val (@vals) {
8204: if ($val =~ /:/) {
8205: my @items = split(/:/,$val);
8206: foreach my $item (@items) {
8207: if (ref($by_location{$item}) eq 'ARRAY') {
8208: push(@okvals,$item);
8209: }
8210: }
8211: } else {
8212: if (ref($by_location{$val}) eq 'ARRAY') {
8213: push(@okvals,$val);
8214: }
8215: }
8216: }
8217: @okvals = sort(@okvals);
8218: if (ref($domconfig{'usersessions'}) eq 'HASH') {
8219: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
8220: if (ref($domconfig{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
8221: if ($inuse == 0) {
8222: $changes{$prefix}{$type} = 1;
8223: } else {
8224: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
8225: my @changed = &Apache::loncommon::compare_arrays($domconfig{'usersessions'}{$prefix}{$type},$defaultshash{'usersessions'}{$prefix}{$type});
8226: if (@changed > 0) {
8227: $changes{$prefix}{$type} = 1;
8228: }
8229: }
8230: } else {
8231: if ($inuse == 1) {
8232: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
8233: $changes{$prefix}{$type} = 1;
8234: }
8235: }
8236: } else {
8237: if ($inuse == 1) {
8238: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
8239: $changes{$prefix}{$type} = 1;
8240: }
8241: }
8242: } else {
8243: if ($inuse == 1) {
8244: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
8245: $changes{$prefix}{$type} = 1;
8246: }
8247: }
8248: }
8249: }
8250: }
8251:
8252: my @alldoms = &Apache::lonnet::all_domains();
8253: my %servers = &Apache::lonnet::internet_dom_servers($dom);
8254: my %spareid = ¤t_offloads_to($dom,$domconfig{'usersessions'},\%servers);
8255: my $savespares;
8256:
8257: foreach my $lonhost (sort(keys(%servers))) {
8258: my $serverhomeID =
8259: &Apache::lonnet::get_server_homeID($servers{$lonhost});
8260: my $serverhostname = &Apache::lonnet::hostname($lonhost);
8261: $defaultshash{'usersessions'}{'spares'}{$lonhost} = {};
8262: my %spareschg;
8263: foreach my $type (@{$types{'spares'}}) {
8264: my @okspares;
8265: my @checked = &Apache::loncommon::get_env_multiple('form.spare_'.$type.'_'.$lonhost);
8266: foreach my $server (@checked) {
8267: if (&Apache::lonnet::hostname($server) ne '') {
8268: unless (&Apache::lonnet::hostname($server) eq $serverhostname) {
8269: unless (grep(/^\Q$server\E$/,@okspares)) {
8270: push(@okspares,$server);
8271: }
8272: }
8273: }
8274: }
8275: my $new = $env{'form.newspare_'.$type.'_'.$lonhost};
8276: my $newspare;
8277: if (($new ne '') && (&Apache::lonnet::hostname($new))) {
8278: unless (&Apache::lonnet::hostname($new) eq $serverhostname) {
8279: $newspare = $new;
8280: }
8281: }
8282: my @spares;
8283: if (($newspare ne '') && (!grep(/^\Q$newspare\E$/,@okspares))) {
8284: @spares = sort(@okspares,$newspare);
8285: } else {
8286: @spares = sort(@okspares);
8287: }
8288: $defaultshash{'usersessions'}{'spares'}{$lonhost}{$type} = \@spares;
8289: if (ref($spareid{$lonhost}) eq 'HASH') {
8290: if (ref($spareid{$lonhost}{$type}) eq 'ARRAY') {
8291: my @diffs = &Apache::loncommon::compare_arrays($spareid{$lonhost}{$type},\@spares);
8292: if (@diffs > 0) {
8293: $spareschg{$type} = 1;
8294: }
8295: }
8296: }
8297: }
8298: if (keys(%spareschg) > 0) {
8299: $changes{'spares'}{$lonhost} = \%spareschg;
8300: }
8301: }
8302:
8303: if (ref($domconfig{'usersessions'}) eq 'HASH') {
8304: if (ref($domconfig{'usersessions'}{'spares'}) eq 'HASH') {
8305: if (ref($changes{'spares'}) eq 'HASH') {
8306: if (keys(%{$changes{'spares'}}) > 0) {
8307: $savespares = 1;
8308: }
8309: }
8310: } else {
8311: $savespares = 1;
8312: }
8313: }
8314:
8315: my $nochgmsg = &mt('No changes made to settings for user session hosting/offloading.');
8316: if ((keys(%changes) > 0) || ($savespares)) {
8317: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
8318: $dom);
8319: if ($putresult eq 'ok') {
8320: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
8321: if (ref($defaultshash{'usersessions'}{'remote'}) eq 'HASH') {
8322: $domdefaults{'remotesessions'} = $defaultshash{'usersessions'}{'remote'};
8323: }
8324: if (ref($defaultshash{'usersessions'}{'hosted'}) eq 'HASH') {
8325: $domdefaults{'hostedsessions'} = $defaultshash{'usersessions'}{'hosted'};
8326: }
8327: }
8328: my $cachetime = 24*60*60;
8329: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
8330: if (keys(%changes) > 0) {
8331: my %lt = &usersession_titles();
8332: $resulttext = &mt('Changes made:').'<ul>';
8333: foreach my $prefix (@prefixes) {
8334: if (ref($changes{$prefix}) eq 'HASH') {
8335: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
8336: if ($prefix eq 'spares') {
8337: if (ref($changes{$prefix}) eq 'HASH') {
8338: foreach my $lonhost (sort(keys(%{$changes{$prefix}}))) {
8339: $resulttext .= '<li><b>'.$lonhost.'</b> ';
8340: my $lonhostdom = &Apache::lonnet::host_domain($lonhost);
8341: &Apache::lonnet::remote_devalidate_cache($lonhost,'spares',$lonhostdom);
8342: if (ref($changes{$prefix}{$lonhost}) eq 'HASH') {
8343: foreach my $type (@{$types{$prefix}}) {
8344: if ($changes{$prefix}{$lonhost}{$type}) {
8345: my $offloadto = &mt('None');
8346: if (ref($defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}) eq 'ARRAY') {
8347: if (@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}} > 0) {
8348: $offloadto = join(', ',@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}});
8349: }
8350: }
8351: $resulttext .= &mt('[_1] set to: [_2].','<i>'.$lt{$type}.'</i>',$offloadto).(' 'x3);
8352: }
8353: }
8354: }
8355: $resulttext .= '</li>';
8356: }
8357: }
8358: } else {
8359: foreach my $type (@{$types{$prefix}}) {
8360: if (defined($changes{$prefix}{$type})) {
8361: my $newvalue;
8362: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
8363: if (ref($defaultshash{'usersessions'}{$prefix})) {
8364: if ($type eq 'version') {
8365: $newvalue = $defaultshash{'usersessions'}{$prefix}{$type};
8366: } elsif (ref($defaultshash{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
8367: if (@{$defaultshash{'usersessions'}{$prefix}{$type}} > 0) {
8368: $newvalue = join(', ',@{$defaultshash{'usersessions'}{$prefix}{$type}});
8369: }
8370: }
8371: }
8372: }
8373: if ($newvalue eq '') {
8374: if ($type eq 'version') {
8375: $resulttext .= '<li>'.&mt('[_1] set to: off',$lt{$type}).'</li>';
8376: } else {
8377: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
8378: }
8379: } else {
8380: if ($type eq 'version') {
8381: $newvalue .= ' '.&mt('(or later)');
8382: }
8383: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
8384: }
8385: }
8386: }
8387: }
8388: $resulttext .= '</ul>';
8389: }
8390: }
8391: $resulttext .= '</ul>';
8392: } else {
8393: $resulttext = $nochgmsg;
8394: }
8395: } else {
8396: $resulttext = '<span class="LC_error">'.
8397: &mt('An error occurred: [_1]',$putresult).'</span>';
8398: }
8399: } else {
8400: $resulttext = $nochgmsg;
8401: }
8402: return $resulttext;
8403: }
8404:
8405: sub modify_loadbalancing {
8406: my ($dom,%domconfig) = @_;
8407: my $primary_id = &Apache::lonnet::domain($dom,'primary');
8408: my $intdom = &Apache::lonnet::internet_dom($primary_id);
8409: my ($othertitle,$usertypes,$types) =
8410: &Apache::loncommon::sorted_inst_types($dom);
8411: my %servers = &Apache::lonnet::internet_dom_servers($dom);
8412: my @sparestypes = ('primary','default');
8413: my %typetitles = &sparestype_titles();
8414: my $resulttext;
8415: my (%currbalancer,%currtargets,%currrules,%existing);
8416: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
8417: %existing = %{$domconfig{'loadbalancing'}};
8418: }
8419: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
8420: \%currtargets,\%currrules);
8421: my ($saveloadbalancing,%defaultshash,%changes);
8422: my ($alltypes,$othertypes,$titles) =
8423: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
8424: my %ruletitles = &offloadtype_text();
8425: my @deletions = &Apache::loncommon::get_env_multiple('form.loadbalancing_delete');
8426: for (my $i=0; $i<$env{'form.loadbalancing_total'}; $i++) {
8427: my $balancer = $env{'form.loadbalancing_lonhost_'.$i};
8428: if ($balancer eq '') {
8429: next;
8430: }
8431: if (!exists($servers{$balancer})) {
8432: if (exists($currbalancer{$balancer})) {
8433: push(@{$changes{'delete'}},$balancer);
8434: }
8435: next;
8436: }
8437: if ((@deletions > 0) && (grep(/^\Q$i\E$/,@deletions))) {
8438: push(@{$changes{'delete'}},$balancer);
8439: next;
8440: }
8441: if (!exists($currbalancer{$balancer})) {
8442: push(@{$changes{'add'}},$balancer);
8443: }
8444: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'} = [];
8445: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'default'} = [];
8446: $defaultshash{'loadbalancing'}{$balancer}{'rules'} = {};
8447: unless (ref($domconfig{'loadbalancing'}) eq 'HASH') {
8448: $saveloadbalancing = 1;
8449: }
8450: foreach my $sparetype (@sparestypes) {
8451: my @targets = &Apache::loncommon::get_env_multiple('form.loadbalancing_target_'.$i.'_'.$sparetype);
8452: my @offloadto;
8453: foreach my $target (@targets) {
8454: if (($servers{$target}) && ($target ne $balancer)) {
8455: if ($sparetype eq 'default') {
8456: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}) eq 'ARRAY') {
8457: next if (grep(/^\Q$target\E$/,@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}}));
8458: }
8459: }
8460: unless(grep(/^\Q$target\E$/,@offloadto)) {
8461: push(@offloadto,$target);
8462: }
8463: }
8464: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype} = \@offloadto;
8465: }
8466: }
8467: if (ref($currtargets{$balancer}) eq 'HASH') {
8468: foreach my $sparetype (@sparestypes) {
8469: if (ref($currtargets{$balancer}{$sparetype}) eq 'ARRAY') {
8470: my @targetdiffs = &Apache::loncommon::compare_arrays($currtargets{$balancer}{$sparetype},$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype});
8471: if (@targetdiffs > 0) {
8472: $changes{'curr'}{$balancer}{'targets'} = 1;
8473: }
8474: } elsif (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
8475: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
8476: $changes{'curr'}{$balancer}{'targets'} = 1;
8477: }
8478: }
8479: }
8480: } else {
8481: if (ref($defaultshash{'loadbalancing'}{$balancer}) eq 'HASH') {
8482: foreach my $sparetype (@sparestypes) {
8483: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
8484: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
8485: $changes{'curr'}{$balancer}{'targets'} = 1;
8486: }
8487: }
8488: }
8489: }
8490: }
8491: my $ishomedom;
8492: if (&Apache::lonnet::host_domain($balancer) eq $dom) {
8493: $ishomedom = 1;
8494: }
8495: if (ref($alltypes) eq 'ARRAY') {
8496: foreach my $type (@{$alltypes}) {
8497: my $rule;
8498: unless ((($type eq '_LC_external') || ($type eq '_LC_internetdom')) &&
8499: (!$ishomedom)) {
8500: $rule = $env{'form.loadbalancing_rules_'.$i.'_'.$type};
8501: }
8502: if ($rule eq 'specific') {
8503: $rule = $env{'form.loadbalancing_singleserver_'.$i.'_'.$type};
8504: }
8505: $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type} = $rule;
8506: if (ref($currrules{$balancer}) eq 'HASH') {
8507: if ($rule ne $currrules{$balancer}{$type}) {
8508: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
8509: }
8510: } elsif ($rule ne '') {
8511: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
8512: }
8513: }
8514: }
8515: }
8516: my $nochgmsg = &mt('No changes made to Load Balancer settings.');
8517: if ((keys(%changes) > 0) || ($saveloadbalancing)) {
8518: unless (ref($defaultshash{'loadbalancing'}) eq 'HASH') {
8519: $defaultshash{'loadbalancing'} = {};
8520: }
8521: my $putresult = &Apache::lonnet::put_dom('configuration',
8522: \%defaultshash,$dom);
8523:
8524: if ($putresult eq 'ok') {
8525: if (keys(%changes) > 0) {
8526: if (ref($changes{'delete'}) eq 'ARRAY') {
8527: foreach my $balancer (sort(@{$changes{'delete'}})) {
8528: $resulttext .= '<li>'.&mt('Load Balancing discontinued for: [_1]',$balancer).'</li>';
8529: &Apache::lonnet::remote_devalidate_cache($balancer,'loadbalancing',$dom);
8530: }
8531: }
8532: if (ref($changes{'add'}) eq 'ARRAY') {
8533: foreach my $balancer (sort(@{$changes{'add'}})) {
8534: $resulttext .= '<li>'.&mt('Load Balancing enabled for: [_1]',$balancer);
8535: }
8536: }
8537: if (ref($changes{'curr'}) eq 'HASH') {
8538: foreach my $balancer (sort(keys(%{$changes{'curr'}}))) {
8539: if (ref($changes{'curr'}{$balancer}) eq 'HASH') {
8540: if ($changes{'curr'}{$balancer}{'targets'}) {
8541: my %offloadstr;
8542: foreach my $sparetype (@sparestypes) {
8543: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
8544: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
8545: $offloadstr{$sparetype} = join(', ',@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
8546: }
8547: }
8548: }
8549: if (keys(%offloadstr) == 0) {
8550: $resulttext .= '<li>'.&mt("Servers to which Load Balance server offloads set to 'None', by default").'</li>';
8551: } else {
8552: my $showoffload;
8553: foreach my $sparetype (@sparestypes) {
8554: $showoffload .= '<i>'.$typetitles{$sparetype}.'</i>: ';
8555: if (defined($offloadstr{$sparetype})) {
8556: $showoffload .= $offloadstr{$sparetype};
8557: } else {
8558: $showoffload .= &mt('None');
8559: }
8560: $showoffload .= (' 'x3);
8561: }
8562: $resulttext .= '<li>'.&mt('By default, Load Balancer: [_1] set to offload to - [_2]',$balancer,$showoffload).'</li>';
8563: }
8564: }
8565: }
8566: if (ref($changes{'curr'}{$balancer}{'rules'}) eq 'HASH') {
8567: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
8568: foreach my $type (@{$alltypes}) {
8569: if ($changes{'curr'}{$balancer}{'rules'}{$type}) {
8570: my $rule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
8571: my $balancetext;
8572: if ($rule eq '') {
8573: $balancetext = $ruletitles{'default'};
8574: } elsif (($rule eq 'homeserver') || ($rule eq 'externalbalancer')) {
8575: $balancetext = $ruletitles{$rule};
8576: } else {
8577: $balancetext = &mt('offload to [_1]',$defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type});
8578: }
8579: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- balancing for [_2] set to - "[_3]"',$balancer,$titles->{$type},$balancetext).'</li>';
8580: }
8581: }
8582: }
8583: }
8584: &Apache::lonnet::remote_devalidate_cache($balancer,'loadbalancing',$dom);
8585: }
8586: }
8587: if ($resulttext ne '') {
8588: $resulttext = &mt('Changes made:').'<ul>'.$resulttext.'</ul>';
8589: } else {
8590: $resulttext = $nochgmsg;
8591: }
8592: } else {
8593: $resulttext = $nochgmsg;
8594: }
8595: } else {
8596: $resulttext = '<span class="LC_error">'.
8597: &mt('An error occurred: [_1]',$putresult).'</span>';
8598: }
8599: } else {
8600: $resulttext = $nochgmsg;
8601: }
8602: return $resulttext;
8603: }
8604:
8605: sub recurse_check {
8606: my ($chkcats,$categories,$depth,$name) = @_;
8607: if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
8608: my $chg = 0;
8609: for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
8610: my $category = $chkcats->[$depth]{$name}[$j];
8611: my $item;
8612: if ($category eq '') {
8613: $chg ++;
8614: } else {
8615: my $deeper = $depth + 1;
8616: $item = &escape($category).':'.&escape($name).':'.$depth;
8617: if ($chg) {
8618: $categories->{$item} -= $chg;
8619: }
8620: &recurse_check($chkcats,$categories,$deeper,$category);
8621: $deeper --;
8622: }
8623: }
8624: }
8625: return;
8626: }
8627:
8628: sub recurse_cat_deletes {
8629: my ($item,$coursecategories,$deletions) = @_;
8630: my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
8631: my $subdepth = $depth + 1;
8632: if (ref($coursecategories) eq 'HASH') {
8633: foreach my $subitem (keys(%{$coursecategories})) {
8634: my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
8635: if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
8636: delete($coursecategories->{$subitem});
8637: $deletions->{$subitem} = 1;
8638: &recurse_cat_deletes($subitem,$coursecategories,$deletions);
8639: }
8640: }
8641: }
8642: return;
8643: }
8644:
8645: sub get_active_dcs {
8646: my ($dom) = @_;
8647: my $now = time;
8648: my %dompersonnel = &Apache::lonnet::get_domain_roles($dom,['dc'],$now,$now);
8649: my %domcoords;
8650: my $numdcs = 0;
8651: foreach my $server (keys(%dompersonnel)) {
8652: foreach my $user (sort(keys(%{$dompersonnel{$server}}))) {
8653: my ($trole,$uname,$udom,$runame,$rudom,$rsec) = split(/:/,$user);
8654: $domcoords{$uname.':'.$udom} = $dompersonnel{$server}{$user};
8655: }
8656: }
8657: return %domcoords;
8658: }
8659:
8660: sub active_dc_picker {
8661: my ($dom,$numinrow,$inputtype,$name,%currhash) = @_;
8662: my %domcoords = &get_active_dcs($dom);
8663: my @domcoord = keys(%domcoords);
8664: if (keys(%currhash)) {
8665: foreach my $dc (keys(%currhash)) {
8666: unless (exists($domcoords{$dc})) {
8667: push(@domcoord,$dc);
8668: }
8669: }
8670: }
8671: @domcoord = sort(@domcoord);
8672: my $numdcs = scalar(@domcoord);
8673: my $rows = 0;
8674: my $table;
8675: if ($numdcs > 1) {
8676: $table = '<table>';
8677: for (my $i=0; $i<@domcoord; $i++) {
8678: my $rem = $i%($numinrow);
8679: if ($rem == 0) {
8680: if ($i > 0) {
8681: $table .= '</tr>';
8682: }
8683: $table .= '<tr>';
8684: $rows ++;
8685: }
8686: my $check = '';
8687: if ($inputtype eq 'radio') {
8688: if (keys(%currhash) == 0) {
8689: if (!$i) {
8690: $check = ' checked="checked"';
8691: }
8692: } elsif (exists($currhash{$domcoord[$i]})) {
8693: $check = ' checked="checked"';
8694: }
8695: } else {
8696: if (exists($currhash{$domcoord[$i]})) {
8697: $check = ' checked="checked"';
8698: }
8699: }
8700: if ($i == @domcoord - 1) {
8701: my $colsleft = $numinrow - $rem;
8702: if ($colsleft > 1) {
8703: $table .= '<td class="LC_left_item" colspan="'.$colsleft.'">';
8704: } else {
8705: $table .= '<td class="LC_left_item">';
8706: }
8707: } else {
8708: $table .= '<td class="LC_left_item">';
8709: }
8710: my ($dcname,$dcdom) = split(':',$domcoord[$i]);
8711: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
8712: $table .= '<span class="LC_nobreak"><label>'.
8713: '<input type="'.$inputtype.'" name="'.$name.'"'.
8714: ' value="'.$domcoord[$i].'"'.$check.' />'.$user;
8715: if ($user ne $dcname.':'.$dcdom) {
8716: $table .= ' ('.$dcname.':'.$dcdom.')'.
8717: '</label></span></td>';
8718: }
8719: }
8720: $table .= '</tr></table>';
8721: } elsif ($numdcs == 1) {
8722: if ($inputtype eq 'radio') {
8723: $table .= '<input type="hidden" name="'.$name.'" value="'.$domcoord[0].'" />';
8724: } else {
8725: my $check;
8726: if (exists($currhash{$domcoord[0]})) {
8727: $check = ' checked="checked"';
8728: }
8729: $table .= '<input type="checkbox" name="'.$name.'" '.
8730: 'value="'.$domcoord[0].'"'.$check.' />';
8731: $rows ++;
8732: }
8733: }
8734: return ($numdcs,$table,$rows);
8735: }
8736:
8737: sub usersession_titles {
8738: return &Apache::lonlocal::texthash(
8739: hosted => 'Hosting of sessions for users from other domains on servers in this domain',
8740: remote => 'Hosting of sessions for users in this domain on servers in other domains',
8741: spares => 'Servers offloaded to, when busy',
8742: version => 'LON-CAPA version requirement',
8743: excludedomain => 'Allow all, but exclude specific domains',
8744: includedomain => 'Deny all, but include specific domains',
8745: primary => 'Primary (checked first)',
8746: default => 'Default',
8747: );
8748: }
8749:
8750: sub id_for_thisdom {
8751: my (%servers) = @_;
8752: my %altids;
8753: foreach my $server (keys(%servers)) {
8754: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
8755: if ($serverhome ne $server) {
8756: $altids{$serverhome} = $server;
8757: }
8758: }
8759: return %altids;
8760: }
8761:
8762: sub count_servers {
8763: my ($currbalancer,%servers) = @_;
8764: my (@spares,$numspares);
8765: foreach my $lonhost (sort(keys(%servers))) {
8766: next if ($currbalancer eq $lonhost);
8767: push(@spares,$lonhost);
8768: }
8769: if ($currbalancer) {
8770: $numspares = scalar(@spares);
8771: } else {
8772: $numspares = scalar(@spares) - 1;
8773: }
8774: return ($numspares,@spares);
8775: }
8776:
8777: sub lonbalance_targets_js {
8778: my ($dom,$types,$servers,$settings) = @_;
8779: my $select = &mt('Select');
8780: my ($alltargets,$allishome,$allinsttypes,@alltypes);
8781: if (ref($servers) eq 'HASH') {
8782: $alltargets = join("','",sort(keys(%{$servers})));
8783: my @homedoms;
8784: foreach my $server (sort(keys(%{$servers}))) {
8785: if (&Apache::lonnet::host_domain($server) eq $dom) {
8786: push(@homedoms,'1');
8787: } else {
8788: push(@homedoms,'0');
8789: }
8790: }
8791: $allishome = join("','",@homedoms);
8792: }
8793: if (ref($types) eq 'ARRAY') {
8794: if (@{$types} > 0) {
8795: @alltypes = @{$types};
8796: }
8797: }
8798: push(@alltypes,'default','_LC_adv','_LC_author','_LC_internetdom','_LC_external');
8799: $allinsttypes = join("','",@alltypes);
8800: my (%currbalancer,%currtargets,%currrules,%existing);
8801: if (ref($settings) eq 'HASH') {
8802: %existing = %{$settings};
8803: }
8804: &get_loadbalancers_config($servers,\%existing,\%currbalancer,
8805: \%currtargets,\%currrules);
8806: my $balancers = join("','",sort(keys(%currbalancer)));
8807: return <<"END";
8808:
8809: <script type="text/javascript">
8810: // <![CDATA[
8811:
8812: currBalancers = new Array('$balancers');
8813:
8814: function toggleTargets(balnum) {
8815: var lonhostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
8816: var prevhostitem = document.getElementById('loadbalancing_prevlonhost_'+balnum);
8817: var balancer = lonhostitem.options[lonhostitem.selectedIndex].value;
8818: var prevbalancer = prevhostitem.value;
8819: var baltotal = document.getElementById('loadbalancing_total').value;
8820: prevhostitem.value = balancer;
8821: if (prevbalancer != '') {
8822: var prevIdx = currBalancers.indexOf(prevbalancer);
8823: if (prevIdx != -1) {
8824: currBalancers.splice(prevIdx,1);
8825: }
8826: }
8827: if (balancer == '') {
8828: hideSpares(balnum);
8829: } else {
8830: var currIdx = currBalancers.indexOf(balancer);
8831: if (currIdx == -1) {
8832: currBalancers.push(balancer);
8833: }
8834: var homedoms = new Array('$allishome');
8835: var ishomedom = homedoms[lonhostitem.selectedIndex];
8836: showSpares(balancer,ishomedom,balnum);
8837: }
8838: balancerChange(balnum,baltotal,'change',prevbalancer,balancer);
8839: return;
8840: }
8841:
8842: function showSpares(balancer,ishomedom,balnum) {
8843: var alltargets = new Array('$alltargets');
8844: var insttypes = new Array('$allinsttypes');
8845: var offloadtypes = new Array('primary','default');
8846:
8847: document.getElementById('loadbalancing_targets_'+balnum).style.display='block';
8848: document.getElementById('loadbalancing_disabled_'+balnum).style.display='none';
8849:
8850: for (var i=0; i<offloadtypes.length; i++) {
8851: var count = 0;
8852: for (var j=0; j<alltargets.length; j++) {
8853: if (alltargets[j] != balancer) {
8854: var item = document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+count);
8855: item.value = alltargets[j];
8856: item.style.textAlign='left';
8857: item.style.textFace='normal';
8858: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+count).innerHTML = alltargets[j];
8859: if (currBalancers.indexOf(alltargets[j]) == -1) {
8860: item.disabled = '';
8861: } else {
8862: item.disabled = 'disabled';
8863: item.checked = false;
8864: }
8865: count ++;
8866: }
8867: }
8868: }
8869: for (var k=0; k<insttypes.length; k++) {
8870: if ((insttypes[k] == '_LC_external') || (insttypes[k] == '_LC_internetdom')) {
8871: if (ishomedom == 1) {
8872: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
8873: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
8874: } else {
8875: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
8876: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
8877:
8878: }
8879: } else {
8880: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
8881: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
8882: }
8883: if ((insttypes[k] != '_LC_external') &&
8884: ((insttypes[k] != '_LC_internetdom') ||
8885: ((insttypes[k] == '_LC_internetdom') && (ishomedom == 1)))) {
8886: var item = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]);
8887: item.options.length = 0;
8888: item.options[0] = new Option("","",true,true);
8889: var idx = 0;
8890: for (var m=0; m<alltargets.length; m++) {
8891: if ((currBalancers.indexOf(alltargets[m]) == -1) && (alltargets[m] != balancer)) {
8892: idx ++;
8893: item.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
8894:
8895: }
8896: }
8897: }
8898: }
8899: return;
8900: }
8901:
8902: function hideSpares(balnum) {
8903: var alltargets = new Array('$alltargets');
8904: var insttypes = new Array('$allinsttypes');
8905: var offloadtypes = new Array('primary','default');
8906:
8907: document.getElementById('loadbalancing_targets_'+balnum).style.display='none';
8908: document.getElementById('loadbalancing_disabled_'+balnum).style.display='block';
8909:
8910: var total = alltargets.length - 1;
8911: for (var i=0; i<offloadtypes; i++) {
8912: for (var j=0; j<total; j++) {
8913: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).checked = false;
8914: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).value = '';
8915: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+j).innerHTML = '';
8916: }
8917: }
8918: for (var k=0; k<insttypes.length; k++) {
8919: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
8920: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
8921: if (insttypes[k] != '_LC_external') {
8922: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).length = 0;
8923: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).options[0] = new Option("","",true,true);
8924: }
8925: }
8926: return;
8927: }
8928:
8929: function checkOffloads(item,balnum,type) {
8930: var alltargets = new Array('$alltargets');
8931: var offloadtypes = new Array('primary','default');
8932: if (item.checked) {
8933: var total = alltargets.length - 1;
8934: var other;
8935: if (type == offloadtypes[0]) {
8936: other = offloadtypes[1];
8937: } else {
8938: other = offloadtypes[0];
8939: }
8940: for (var i=0; i<total; i++) {
8941: var server = document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).value;
8942: if (server == item.value) {
8943: if (document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked) {
8944: document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked = false;
8945: }
8946: }
8947: }
8948: }
8949: return;
8950: }
8951:
8952: function singleServerToggle(balnum,type) {
8953: var offloadtoSelIdx = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex;
8954: if (offloadtoSelIdx == 0) {
8955: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_0').checked = true;
8956: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
8957:
8958: } else {
8959: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_2').checked = true;
8960: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
8961: }
8962: return;
8963: }
8964:
8965: function balanceruleChange(formname,balnum,type) {
8966: if (type == '_LC_external') {
8967: return;
8968: }
8969: var typesRules = getIndicesByName(formname,'loadbalancing_rules_'+balnum+'_'+type);
8970: for (var i=0; i<typesRules.length; i++) {
8971: if (formname.elements[typesRules[i]].checked) {
8972: if (formname.elements[typesRules[i]].value != 'specific') {
8973: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex = 0;
8974: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
8975: } else {
8976: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
8977: }
8978: }
8979: }
8980: return;
8981: }
8982:
8983: function balancerDeleteChange(balnum) {
8984: var hostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
8985: var baltotal = document.getElementById('loadbalancing_total').value;
8986: var addtarget;
8987: var removetarget;
8988: var action = 'delete';
8989: if (document.getElementById('loadbalancing_delete_'+balnum)) {
8990: var lonhost = hostitem.value;
8991: var currIdx = currBalancers.indexOf(lonhost);
8992: if (document.getElementById('loadbalancing_delete_'+balnum).checked) {
8993: if (currIdx != -1) {
8994: currBalancers.splice(currIdx,1);
8995: }
8996: addtarget = lonhost;
8997: } else {
8998: if (currIdx == -1) {
8999: currBalancers.push(lonhost);
9000: }
9001: removetarget = lonhost;
9002: action = 'undelete';
9003: }
9004: balancerChange(balnum,baltotal,action,addtarget,removetarget);
9005: }
9006: return;
9007: }
9008:
9009: function balancerChange(balnum,baltotal,action,addtarget,removetarget) {
9010: if (baltotal > 1) {
9011: var offloadtypes = new Array('primary','default');
9012: var alltargets = new Array('$alltargets');
9013: var insttypes = new Array('$allinsttypes');
9014: for (var i=0; i<baltotal; i++) {
9015: if (i != balnum) {
9016: for (var j=0; j<offloadtypes.length; j++) {
9017: var total = alltargets.length - 1;
9018: for (var k=0; k<total; k++) {
9019: var serveritem = document.getElementById('loadbalancing_target_'+i+'_'+offloadtypes[j]+'_'+k);
9020: var server = serveritem.value;
9021: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
9022: if (server == addtarget) {
9023: serveritem.disabled = '';
9024: }
9025: }
9026: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
9027: if (server == removetarget) {
9028: serveritem.disabled = 'disabled';
9029: serveritem.checked = false;
9030: }
9031: }
9032: }
9033: }
9034: for (var j=0; j<insttypes.length; j++) {
9035: if (insttypes[j] != '_LC_external') {
9036: if (document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j])) {
9037: var singleserver = document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j]);
9038: var currSel = singleserver.selectedIndex;
9039: var currVal = singleserver.options[currSel].value;
9040: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
9041: var numoptions = singleserver.options.length;
9042: var needsnew = 1;
9043: for (var k=0; k<numoptions; k++) {
9044: if (singleserver.options[k] == addtarget) {
9045: needsnew = 0;
9046: break;
9047: }
9048: }
9049: if (needsnew == 1) {
9050: singleserver.options[numoptions] = new Option(addtarget,addtarget,false,false);
9051: }
9052: }
9053: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
9054: singleserver.options.length = 0;
9055: if ((currVal) && (currVal != removetarget)) {
9056: singleserver.options[0] = new Option("","",false,false);
9057: } else {
9058: singleserver.options[0] = new Option("","",true,true);
9059: }
9060: var idx = 0;
9061: for (var m=0; m<alltargets.length; m++) {
9062: if (currBalancers.indexOf(alltargets[m]) == -1) {
9063: idx ++;
9064: if (currVal == alltargets[m]) {
9065: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],true,true);
9066: } else {
9067: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
9068: }
9069: }
9070: }
9071: }
9072: }
9073: }
9074: }
9075: }
9076: }
9077: }
9078: return;
9079: }
9080:
9081: // ]]>
9082: </script>
9083:
9084: END
9085: }
9086:
9087: sub new_spares_js {
9088: my @sparestypes = ('primary','default');
9089: my $types = join("','",@sparestypes);
9090: my $select = &mt('Select');
9091: return <<"END";
9092:
9093: <script type="text/javascript">
9094: // <![CDATA[
9095:
9096: function updateNewSpares(formname,lonhost) {
9097: var types = new Array('$types');
9098: var include = new Array();
9099: var exclude = new Array();
9100: for (var i=0; i<types.length; i++) {
9101: var spareboxes = getIndicesByName(formname,'spare_'+types[i]+'_'+lonhost);
9102: for (var j=0; j<spareboxes.length; j++) {
9103: if (formname.elements[spareboxes[j]].checked) {
9104: exclude.push(formname.elements[spareboxes[j]].value);
9105: } else {
9106: include.push(formname.elements[spareboxes[j]].value);
9107: }
9108: }
9109: }
9110: for (var i=0; i<types.length; i++) {
9111: var newSpare = document.getElementById('newspare_'+types[i]+'_'+lonhost);
9112: var selIdx = newSpare.selectedIndex;
9113: var currnew = newSpare.options[selIdx].value;
9114: var okSpares = new Array();
9115: for (var j=0; j<newSpare.options.length; j++) {
9116: var possible = newSpare.options[j].value;
9117: if (possible != '') {
9118: if (exclude.indexOf(possible) == -1) {
9119: okSpares.push(possible);
9120: } else {
9121: if (currnew == possible) {
9122: selIdx = 0;
9123: }
9124: }
9125: }
9126: }
9127: for (var k=0; k<include.length; k++) {
9128: if (okSpares.indexOf(include[k]) == -1) {
9129: okSpares.push(include[k]);
9130: }
9131: }
9132: okSpares.sort();
9133: newSpare.options.length = 0;
9134: if (selIdx == 0) {
9135: newSpare.options[0] = new Option("$select","",true,true);
9136: } else {
9137: newSpare.options[0] = new Option("$select","",false,false);
9138: }
9139: for (var m=0; m<okSpares.length; m++) {
9140: var idx = m+1;
9141: var selThis = 0;
9142: if (selIdx != 0) {
9143: if (okSpares[m] == currnew) {
9144: selThis = 1;
9145: }
9146: }
9147: if (selThis == 1) {
9148: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],true,true);
9149: } else {
9150: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],false,false);
9151: }
9152: }
9153: }
9154: return;
9155: }
9156:
9157: function checkNewSpares(lonhost,type) {
9158: var newSpare = document.getElementById('newspare_'+type+'_'+lonhost);
9159: var chosen = newSpare.options[newSpare.selectedIndex].value;
9160: if (chosen != '') {
9161: var othertype;
9162: var othernewSpare;
9163: if (type == 'primary') {
9164: othernewSpare = document.getElementById('newspare_default_'+lonhost);
9165: }
9166: if (type == 'default') {
9167: othernewSpare = document.getElementById('newspare_primary_'+lonhost);
9168: }
9169: if (othernewSpare.options[othernewSpare.selectedIndex].value == chosen) {
9170: othernewSpare.selectedIndex = 0;
9171: }
9172: }
9173: return;
9174: }
9175:
9176: // ]]>
9177: </script>
9178:
9179: END
9180:
9181: }
9182:
9183: sub common_domprefs_js {
9184: return <<"END";
9185:
9186: <script type="text/javascript">
9187: // <![CDATA[
9188:
9189: function getIndicesByName(formname,item) {
9190: var group = new Array();
9191: for (var i=0;i<formname.elements.length;i++) {
9192: if (formname.elements[i].name == item) {
9193: group.push(formname.elements[i].id);
9194: }
9195: }
9196: return group;
9197: }
9198:
9199: // ]]>
9200: </script>
9201:
9202: END
9203:
9204: }
9205:
9206: sub recaptcha_js {
9207: my %lt = &captcha_phrases();
9208: return <<"END";
9209:
9210: <script type="text/javascript">
9211: // <![CDATA[
9212:
9213: function updateCaptcha(caller,context) {
9214: var privitem;
9215: var pubitem;
9216: var privtext;
9217: var pubtext;
9218: if (document.getElementById(context+'_recaptchapub')) {
9219: pubitem = document.getElementById(context+'_recaptchapub');
9220: } else {
9221: return;
9222: }
9223: if (document.getElementById(context+'_recaptchapriv')) {
9224: privitem = document.getElementById(context+'_recaptchapriv');
9225: } else {
9226: return;
9227: }
9228: if (document.getElementById(context+'_recaptchapubtxt')) {
9229: pubtext = document.getElementById(context+'_recaptchapubtxt');
9230: } else {
9231: return;
9232: }
9233: if (document.getElementById(context+'_recaptchaprivtxt')) {
9234: privtext = document.getElementById(context+'_recaptchaprivtxt');
9235: } else {
9236: return;
9237: }
9238: if (caller.checked) {
9239: if (caller.value == 'recaptcha') {
9240: pubitem.type = 'text';
9241: privitem.type = 'text';
9242: pubitem.size = '40';
9243: privitem.size = '40';
9244: pubtext.innerHTML = "$lt{'pub'}";
9245: privtext.innerHTML = "$lt{'priv'}";
9246: } else {
9247: pubitem.type = 'hidden';
9248: privitem.type = 'hidden';
9249: pubtext.innerHTML = '';
9250: privtext.innerHTML = '';
9251: }
9252: }
9253: return;
9254: }
9255:
9256: // ]]>
9257: </script>
9258:
9259: END
9260:
9261: }
9262:
9263: sub credits_js {
9264: return <<"END";
9265:
9266: <script type="text/javascript">
9267: // <![CDATA[
9268:
9269: function toggleCredits(domForm) {
9270: if (document.getElementById('credits')) {
9271: creditsitem = document.getElementById('credits');
9272: var creditsLength = domForm.coursecredits.length;
9273: if (creditsLength) {
9274: var currval;
9275: for (var i=0; i<creditsLength; i++) {
9276: if (domForm.coursecredits[i].checked) {
9277: currval = domForm.coursecredits[i].value;
9278: }
9279: }
9280: if (currval == 1) {
9281: creditsitem.style.display = 'block';
9282: } else {
9283: creditsitem.style.display = 'none';
9284: }
9285: }
9286: }
9287: return;
9288: }
9289:
9290: // ]]>
9291: </script>
9292:
9293: END
9294:
9295: }
9296:
9297: sub captcha_phrases {
9298: return &Apache::lonlocal::texthash (
9299: priv => 'Private key',
9300: pub => 'Public key',
9301: original => 'original (CAPTCHA)',
9302: recaptcha => 'successor (ReCAPTCHA)',
9303: notused => 'unused',
9304: );
9305: }
9306:
9307: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>