Annotation of loncom/interface/domainprefs.pm, revision 1.200
1.1 raeburn 1: # The LearningOnline Network with CAPA
2: # Handler to set domain-wide configuration settings
3: #
1.200 ! raeburn 4: # $Id: domainprefs.pm,v 1.199 2013/07/15 17:42:11 raeburn Exp $
1.2 albertel 5: #
1.1 raeburn 6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA#
23: # /home/httpd/html/adm/gpl.txt
24: #
25: # http://www.lon-capa.org/
26: #
27: #
28: ###############################################################
29: ##############################################################
30:
1.101 raeburn 31: =pod
32:
33: =head1 NAME
34:
35: Apache::domainprefs.pm
36:
37: =head1 SYNOPSIS
38:
39: Handles configuration of a LON-CAPA domain.
40:
41: This is part of the LearningOnline Network with CAPA project
42: described at http://www.lon-capa.org.
43:
44:
45: =head1 OVERVIEW
46:
47: Each institution using LON-CAPA will typically have a single domain designated
1.183 bisitz 48: for use by individuals affiliated with the institution. Accordingly, each domain
1.101 raeburn 49: may define a default set of logos and a color scheme which can be used to "brand"
50: the LON-CAPA instance. In addition, an institution will typically have a language
51: and timezone which are used for the majority of courses.
52:
53: LON-CAPA provides a mechanism to display and modify these defaults, as well as a
54: host of other domain-wide settings which determine the types of functionality
55: available to users and courses in the domain.
56:
57: There is also a mechanism to configure cataloging of courses in the domain, and
58: controls on the operation of automated processes which govern such things as
59: roster updates, user directory updates and processing of course requests.
60:
61: The domain coordination manual which is built dynamically on install/update of
62: LON-CAPA from the relevant help items provides more information about domain
63: configuration.
64:
65: Most of the domain settings are stored in the configuration.db GDBM file which is
66: housed on the primary library server for the domain in /home/httpd/lonUsers/$dom,
67: where $dom is the domain. The configuration.db stores settings in a number of
68: frozen hashes of hashes. In a few cases, domain information must be uploaded to
69: the domain as files (e.g., image files for logos etc., or plain text files for
70: bubblesheet formats). In this case the domainprefs.pm must be running in a user
71: session hosted on the primary library server in the domain, as these files are
72: stored in author space belonging to a special $dom-domainconfig user.
73:
74: domainprefs.pm in combination with lonconfigsettings.pm will retrieve and display
75: the current settings, and provides an interface to make modifications.
76:
77: =head1 SUBROUTINES
78:
79: =over
80:
81: =item print_quotas()
82:
83: Inputs: 4
84:
85: $dom,$settings,$rowtotal,$action.
86:
87: $dom is the domain, $settings is a reference to a hash of current settings for
88: the current context, $rowtotal is a reference to the scalar used to record the
1.163 raeburn 89: number of rows displayed on the page, and $action is the context (quotas,
90: requestcourses or requestauthor).
1.101 raeburn 91:
92: The print_quotas routine was orginally created to display/store information
93: about default quota sizes for portfolio spaces for the different types of
94: institutional affiliation in the domain (e.g., Faculty, Staff, Student etc.),
95: but is now also used to manage availability of user tools:
96: i.e., blogs, aboutme page, and portfolios, and the course request tool,
1.197 raeburn 97: used by course owners to request creation of a course, and to display/store
98: default quota sizes for authoring spaces.
1.101 raeburn 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:
1.104 raeburn 109: 0, approval, validate, autolimit=N (where N is blank, or a positive integer).
1.101 raeburn 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:
1.104 raeburn 120: approval
1.101 raeburn 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:
1.143 raeburn 144: - course requests will be processed automatically up to a limit of
1.101 raeburn 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:
1.1 raeburn 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;
1.43 raeburn 165: use Apache::lonmsg();
1.91 raeburn 166: use Apache::lonconfigsettings;
1.69 raeburn 167: use LONCAPA qw(:DEFAULT :match);
1.6 raeburn 168: use LONCAPA::Enrollment;
1.81 raeburn 169: use LONCAPA::lonauthcgi();
1.9 raeburn 170: use File::Copy;
1.43 raeburn 171: use Locale::Language;
1.62 raeburn 172: use DateTime::TimeZone;
1.68 raeburn 173: use DateTime::Locale;
1.1 raeburn 174:
1.155 raeburn 175: my $registered_cleanup;
176: my $modified_urls;
177:
1.1 raeburn 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:
1.91 raeburn 186: my $context = 'domain';
1.1 raeburn 187: my $dom = $env{'request.role.domain'};
1.5 albertel 188: my $domdesc = &Apache::lonnet::domain($dom,'description');
1.1 raeburn 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: }
1.155 raeburn 197:
198: $registered_cleanup=0;
199: @{$modified_urls}=();
200:
1.1 raeburn 201: &Apache::lonhtmlcommon::clear_breadcrumbs();
202: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.58 raeburn 203: ['phase','actions']);
1.30 raeburn 204: my $phase = 'pickactions';
1.3 raeburn 205: if ( exists($env{'form.phase'}) ) {
206: $phase = $env{'form.phase'};
207: }
1.150 raeburn 208: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.3 raeburn 209: my %domconfig =
1.6 raeburn 210: &Apache::lonnet::get_dom('configuration',['login','rolecolors',
1.125 raeburn 211: 'quotas','autoenroll','autoupdate','autocreate',
212: 'directorysrch','usercreation','usermodification',
213: 'contacts','defaults','scantron','coursecategories',
214: 'serverstatuses','requestcourses','helpsettings',
1.163 raeburn 215: 'coursedefaults','usersessions','loadbalancing',
216: 'requestauthor'],$dom);
1.43 raeburn 217: my @prefs_order = ('rolecolors','login','defaults','quotas','autoenroll',
1.125 raeburn 218: 'autoupdate','autocreate','directorysrch','contacts',
1.48 raeburn 219: 'usercreation','usermodification','scantron',
1.163 raeburn 220: 'requestcourses','requestauthor','coursecategories',
221: 'serverstatuses','helpsettings',
1.137 raeburn 222: 'coursedefaults','usersessions');
1.171 raeburn 223: my %existing;
224: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
225: %existing = %{$domconfig{'loadbalancing'}};
226: }
227: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
1.150 raeburn 228: push(@prefs_order,'loadbalancing');
229: }
1.30 raeburn 230: my %prefs = (
231: 'rolecolors' =>
232: { text => 'Default color schemes',
1.67 raeburn 233: help => 'Domain_Configuration_Color_Schemes',
1.30 raeburn 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: },
1.110 raeburn 243: 'login' =>
1.30 raeburn 244: { text => 'Log-in page options',
1.67 raeburn 245: help => 'Domain_Configuration_Login_Page',
1.168 raeburn 246: header => [{col1 => 'Log-in Page Items',
247: col2 => '',},
248: {col1 => 'Log-in Help',
249: col2 => 'Value'}],
1.30 raeburn 250: },
1.43 raeburn 251: 'defaults' =>
1.141 raeburn 252: { text => 'Default authentication/language/timezone/portal',
1.67 raeburn 253: help => 'Domain_Configuration_LangTZAuth',
1.43 raeburn 254: header => [{col1 => 'Setting',
255: col2 => 'Value'}],
256: },
1.30 raeburn 257: 'quotas' =>
1.197 raeburn 258: { text => 'Blogs, personal web pages, webDAV/quotas, portfolios',
1.67 raeburn 259: help => 'Domain_Configuration_Quotas',
1.77 raeburn 260: header => [{col1 => 'User affiliation',
1.72 raeburn 261: col2 => 'Available tools',
1.197 raeburn 262: col3 => 'Quotas, Mb; (Authoring requires role)',}],
1.30 raeburn 263: },
264: 'autoenroll' =>
265: { text => 'Auto-enrollment settings',
1.67 raeburn 266: help => 'Domain_Configuration_Auto_Enrollment',
1.30 raeburn 267: header => [{col1 => 'Configuration setting',
268: col2 => 'Value(s)'}],
269: },
270: 'autoupdate' =>
271: { text => 'Auto-update settings',
1.67 raeburn 272: help => 'Domain_Configuration_Auto_Updates',
1.30 raeburn 273: header => [{col1 => 'Setting',
274: col2 => 'Value',},
1.131 raeburn 275: {col1 => 'Setting',
276: col2 => 'Affiliation'},
1.43 raeburn 277: {col1 => 'User population',
1.131 raeburn 278: col2 => 'Updateable user data'}],
1.30 raeburn 279: },
1.125 raeburn 280: 'autocreate' =>
281: { text => 'Auto-course creation settings',
282: help => 'Domain_Configuration_Auto_Creation',
283: header => [{col1 => 'Configuration Setting',
284: col2 => 'Value',}],
285: },
1.30 raeburn 286: 'directorysrch' =>
287: { text => 'Institutional directory searches',
1.67 raeburn 288: help => 'Domain_Configuration_InstDirectory_Search',
1.30 raeburn 289: header => [{col1 => 'Setting',
290: col2 => 'Value',}],
291: },
292: 'contacts' =>
293: { text => 'Contact Information',
1.67 raeburn 294: help => 'Domain_Configuration_Contact_Info',
1.30 raeburn 295: header => [{col1 => 'Setting',
296: col2 => 'Value',}],
297: },
298:
299: 'usercreation' =>
300: { text => 'User creation',
1.67 raeburn 301: help => 'Domain_Configuration_User_Creation',
1.43 raeburn 302: header => [{col1 => 'Format rule type',
303: col2 => 'Format rules in force'},
1.34 raeburn 304: {col1 => 'User account creation',
305: col2 => 'Usernames which may be created',},
1.30 raeburn 306: {col1 => 'Context',
1.43 raeburn 307: col2 => 'Assignable authentication types'}],
1.30 raeburn 308: },
1.69 raeburn 309: 'usermodification' =>
1.33 raeburn 310: { text => 'User modification',
1.67 raeburn 311: help => 'Domain_Configuration_User_Modification',
1.33 raeburn 312: header => [{col1 => 'Target user has role',
313: col2 => 'User information updateable in author context'},
314: {col1 => 'Target user has role',
1.63 raeburn 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)'}],
1.33 raeburn 318: },
1.69 raeburn 319: 'scantron' =>
1.95 www 320: { text => 'Bubblesheet format file',
1.67 raeburn 321: help => 'Domain_Configuration_Scantron_Format',
1.46 raeburn 322: header => [ {col1 => 'Item',
323: col2 => '',
324: }],
325: },
1.86 raeburn 326: 'requestcourses' =>
327: {text => 'Request creation of courses',
328: help => 'Domain_Configuration_Request_Courses',
329: header => [{col1 => 'User affiliation',
1.102 raeburn 330: col2 => 'Availability/Processing of requests',},
331: {col1 => 'Setting',
332: col2 => 'Value'}],
1.86 raeburn 333: },
1.163 raeburn 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: },
1.69 raeburn 342: 'coursecategories' =>
1.120 raeburn 343: { text => 'Cataloging of courses/communities',
1.67 raeburn 344: help => 'Domain_Configuration_Cataloging_Courses',
1.69 raeburn 345: header => [{col1 => 'Category settings',
1.57 raeburn 346: col2 => '',},
347: {col1 => 'Categories',
348: col2 => '',
349: }],
1.69 raeburn 350: },
351: 'serverstatuses' =>
1.77 raeburn 352: {text => 'Access to server status pages',
1.69 raeburn 353: help => 'Domain_Configuration_Server_Status',
354: header => [{col1 => 'Status Page',
355: col2 => 'Other named users',
356: col3 => 'Specific IPs',
357: }],
358: },
1.118 jms 359: 'helpsettings' =>
360: {text => 'Help page settings',
361: help => 'Domain_Configuration_Help_Settings',
1.166 raeburn 362: header => [{col1 => 'Help Settings (logged-in users)',
363: col2 => 'Value'}],
1.118 jms 364: },
1.121 raeburn 365: 'coursedefaults' =>
366: {text => 'Course/Community defaults',
367: help => 'Domain_Configuration_Course_Defaults',
1.139 raeburn 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',},],
1.121 raeburn 372: },
1.120 raeburn 373: 'privacy' =>
374: {text => 'User Privacy',
375: help => 'Domain_Configuration_User_Privacy',
376: header => [{col1 => 'Setting',
377: col2 => 'Value',}],
378: },
1.141 raeburn 379: 'usersessions' =>
1.145 raeburn 380: {text => 'User session hosting/offloading',
1.137 raeburn 381: help => 'Domain_Configuration_User_Sessions',
1.145 raeburn 382: header => [{col1 => 'Domain server',
383: col2 => 'Servers to offload sessions to when busy'},
384: {col1 => 'Hosting of users from other domains',
1.137 raeburn 385: col2 => 'Rules'},
386: {col1 => "Hosting domain's own users elsewhere",
387: col2 => 'Rules'}],
388: },
1.150 raeburn 389: 'loadbalancing' =>
1.185 raeburn 390: {text => 'Dedicated Load Balancer(s)',
1.150 raeburn 391: help => 'Domain_Configuration_Load_Balancing',
1.171 raeburn 392: header => [{col1 => 'Balancers',
1.150 raeburn 393: col2 => 'Default destinations',
1.183 bisitz 394: col3 => 'User affiliation',
1.150 raeburn 395: col4 => 'Overrides'},
396: ],
397: },
1.3 raeburn 398: );
1.110 raeburn 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',
1.168 raeburn 405: col2 => ''},
406: {col1 => 'Log-in Help',
407: col2 => 'Value'}],
1.110 raeburn 408: };
409: }
1.174 foxr 410:
1.6 raeburn 411: my @roles = ('student','coordinator','author','admin');
1.30 raeburn 412: my @actions = &Apache::loncommon::get_env_multiple('form.actions');
1.3 raeburn 413: &Apache::lonhtmlcommon::add_breadcrumb
1.30 raeburn 414: ({href=>"javascript:changePage(document.$phase,'pickactions')",
1.133 raeburn 415: text=>"Settings to display/modify"});
1.9 raeburn 416: my $confname = $dom.'-domainconfig';
1.174 foxr 417:
1.3 raeburn 418: if ($phase eq 'process') {
1.91 raeburn 419: &Apache::lonconfigsettings::make_changes($r,$dom,$phase,$context,\@prefs_order,\%prefs,\%domconfig,$confname,\@roles);
1.30 raeburn 420: } elsif ($phase eq 'display') {
1.192 raeburn 421: my $js = &recaptcha_js().
422: &credits_js();
1.171 raeburn 423: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
1.152 raeburn 424: my ($othertitle,$usertypes,$types) =
425: &Apache::loncommon::sorted_inst_types($dom);
1.171 raeburn 426: $js .= &lonbalance_targets_js($dom,$types,\%servers,
427: $domconfig{'loadbalancing'}).
1.170 raeburn 428: &new_spares_js().
429: &common_domprefs_js().
430: &Apache::loncommon::javascript_array_indexof();
1.152 raeburn 431: }
1.150 raeburn 432: &Apache::lonconfigsettings::display_settings($r,$dom,$phase,$context,\@prefs_order,\%prefs,\%domconfig,$confname,$js);
1.1 raeburn 433: } else {
1.180 raeburn 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') {
1.181 raeburn 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: );
1.180 raeburn 444: if ($switchserver) {
1.181 raeburn 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: );
1.180 raeburn 458: }
459: $r->print(&Apache::loncommon::end_page());
460: return OK;
461: }
1.21 raeburn 462: if (keys(%domconfig) == 0) {
463: my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
1.29 raeburn 464: my @ids=&Apache::lonnet::current_machine_ids();
465: if (!grep(/^\Q$primarylibserv\E$/,@ids)) {
1.21 raeburn 466: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.41 raeburn 467: my @loginimages = ('img','logo','domlogo','login');
1.21 raeburn 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) {
1.94 raeburn 480: &Apache::lonconfigsettings::print_header($r,$phase,$context);
1.21 raeburn 481: my $switch_server = &check_switchserver($dom,$confname);
1.29 raeburn 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) {
1.30 raeburn 488: $r->print($switch_server.' '.&mt('to primary library server for domain: [_1]',$dom));
1.29 raeburn 489: }
1.91 raeburn 490: $r->print(&Apache::loncommon::end_page());
1.21 raeburn 491: return OK;
492: }
493: }
494: }
1.91 raeburn 495: &Apache::lonconfigsettings::display_choices($r,$phase,$context,\@prefs_order,\%prefs);
1.3 raeburn 496: }
497: return OK;
498: }
499:
500: sub process_changes {
1.92 raeburn 501: my ($r,$dom,$confname,$action,$roles,$values) = @_;
502: my %domconfig;
503: if (ref($values) eq 'HASH') {
504: %domconfig = %{$values};
505: }
1.3 raeburn 506: my $output;
507: if ($action eq 'login') {
1.9 raeburn 508: $output = &modify_login($r,$dom,$confname,%domconfig);
1.6 raeburn 509: } elsif ($action eq 'rolecolors') {
1.9 raeburn 510: $output = &modify_rolecolors($r,$dom,$confname,$roles,
511: %domconfig);
1.3 raeburn 512: } elsif ($action eq 'quotas') {
1.86 raeburn 513: $output = &modify_quotas($dom,$action,%domconfig);
1.3 raeburn 514: } elsif ($action eq 'autoenroll') {
515: $output = &modify_autoenroll($dom,%domconfig);
516: } elsif ($action eq 'autoupdate') {
517: $output = &modify_autoupdate($dom,%domconfig);
1.125 raeburn 518: } elsif ($action eq 'autocreate') {
519: $output = &modify_autocreate($dom,%domconfig);
1.23 raeburn 520: } elsif ($action eq 'directorysrch') {
521: $output = &modify_directorysrch($dom,%domconfig);
1.27 raeburn 522: } elsif ($action eq 'usercreation') {
1.28 raeburn 523: $output = &modify_usercreation($dom,%domconfig);
1.33 raeburn 524: } elsif ($action eq 'usermodification') {
525: $output = &modify_usermodification($dom,%domconfig);
1.28 raeburn 526: } elsif ($action eq 'contacts') {
527: $output = &modify_contacts($dom,%domconfig);
1.43 raeburn 528: } elsif ($action eq 'defaults') {
529: $output = &modify_defaults($dom,$r);
1.46 raeburn 530: } elsif ($action eq 'scantron') {
1.48 raeburn 531: $output = &modify_scantron($r,$dom,$confname,%domconfig);
532: } elsif ($action eq 'coursecategories') {
533: $output = &modify_coursecategories($dom,%domconfig);
1.69 raeburn 534: } elsif ($action eq 'serverstatuses') {
535: $output = &modify_serverstatuses($dom,%domconfig);
1.86 raeburn 536: } elsif ($action eq 'requestcourses') {
537: $output = &modify_quotas($dom,$action,%domconfig);
1.163 raeburn 538: } elsif ($action eq 'requestauthor') {
539: $output = &modify_quotas($dom,$action,%domconfig);
1.118 jms 540: } elsif ($action eq 'helpsettings') {
1.122 jms 541: $output = &modify_helpsettings($r,$dom,$confname,%domconfig);
1.121 raeburn 542: } elsif ($action eq 'coursedefaults') {
543: $output = &modify_coursedefaults($dom,%domconfig);
1.137 raeburn 544: } elsif ($action eq 'usersessions') {
545: $output = &modify_usersessions($dom,%domconfig);
1.150 raeburn 546: } elsif ($action eq 'loadbalancing') {
547: $output = &modify_loadbalancing($dom,%domconfig);
1.3 raeburn 548: }
549: return $output;
550: }
551:
552: sub print_config_box {
1.9 raeburn 553: my ($r,$dom,$confname,$phase,$action,$item,$settings) = @_;
1.30 raeburn 554: my $rowtotal = 0;
1.49 raeburn 555: my $output;
556: if ($action eq 'coursecategories') {
557: $output = &coursecategories_javascript($settings);
1.91 raeburn 558: }
1.49 raeburn 559: $output .=
1.30 raeburn 560: '<table class="LC_nested_outer">
1.3 raeburn 561: <tr>
1.66 raeburn 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>';
1.30 raeburn 566: $rowtotal ++;
1.110 raeburn 567: my $numheaders = 1;
568: if (ref($item->{'header'}) eq 'ARRAY') {
569: $numheaders = scalar(@{$item->{'header'}});
570: }
571: if ($numheaders > 1) {
1.64 raeburn 572: my $colspan = '';
1.145 raeburn 573: my $rightcolspan = '';
1.168 raeburn 574: if (($action eq 'rolecolors') || ($action eq 'coursecategories') ||
575: (($action eq 'login') && ($numheaders < 3))) {
1.64 raeburn 576: $colspan = ' colspan="2"';
577: }
1.145 raeburn 578: if ($action eq 'usersessions') {
579: $rightcolspan = ' colspan="3"';
580: }
1.30 raeburn 581: $output .= '
1.3 raeburn 582: <tr>
583: <td>
584: <table class="LC_nested">
585: <tr class="LC_info_row">
1.59 bisitz 586: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[0]->{'col1'}).'</td>
1.145 raeburn 587: <td class="LC_right_item"'.$rightcolspan.'>'.&mt($item->{'header'}->[0]->{'col2'}).'</td>
1.30 raeburn 588: </tr>';
1.69 raeburn 589: $rowtotal ++;
1.6 raeburn 590: if ($action eq 'autoupdate') {
1.30 raeburn 591: $output .= &print_autoupdate('top',$dom,$settings,\$rowtotal);
1.28 raeburn 592: } elsif ($action eq 'usercreation') {
1.33 raeburn 593: $output .= &print_usercreation('top',$dom,$settings,\$rowtotal);
594: } elsif ($action eq 'usermodification') {
595: $output .= &print_usermodification('top',$dom,$settings,\$rowtotal);
1.57 raeburn 596: } elsif ($action eq 'coursecategories') {
597: $output .= &print_coursecategories('top',$dom,$item,$settings,\$rowtotal);
1.110 raeburn 598: } elsif ($action eq 'login') {
1.168 raeburn 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: }
1.102 raeburn 605: } elsif ($action eq 'requestcourses') {
606: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.163 raeburn 607: } elsif ($action eq 'requestauthor') {
608: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.137 raeburn 609: } elsif ($action eq 'usersessions') {
610: $output .= &print_usersessions('top',$dom,$settings,\$rowtotal);
1.122 jms 611: } elsif ($action eq 'rolecolors') {
1.30 raeburn 612: $output .= &print_rolecolors($phase,'student',$dom,$confname,$settings,\$rowtotal);
1.139 raeburn 613: } elsif ($action eq 'coursedefaults') {
614: $output .= &print_coursedefaults('top',$dom,$settings,\$rowtotal);
1.6 raeburn 615: }
1.30 raeburn 616: $output .= '
1.6 raeburn 617: </table>
618: </td>
619: </tr>
620: <tr>
621: <td>
622: <table class="LC_nested">
623: <tr class="LC_info_row">
1.59 bisitz 624: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col1'}).'</td>';
1.57 raeburn 625: $output .= '
1.59 bisitz 626: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col2'}).'</td>
1.30 raeburn 627: </tr>';
628: $rowtotal ++;
1.6 raeburn 629: if ($action eq 'autoupdate') {
1.131 raeburn 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 ++;
1.28 raeburn 642: } elsif ($action eq 'usercreation') {
1.34 raeburn 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">
1.59 bisitz 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>'.
1.34 raeburn 653: &print_usercreation('bottom',$dom,$settings,\$rowtotal);
654: $rowtotal ++;
1.33 raeburn 655: } elsif ($action eq 'usermodification') {
1.63 raeburn 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 ++;
1.57 raeburn 668: } elsif ($action eq 'coursecategories') {
669: $output .= &print_coursecategories('bottom',$dom,$item,$settings,\$rowtotal);
1.110 raeburn 670: } elsif ($action eq 'login') {
1.168 raeburn 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: }
1.102 raeburn 687: } elsif ($action eq 'requestcourses') {
1.163 raeburn 688: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
689: } elsif ($action eq 'requestauthor') {
690: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
1.137 raeburn 691: } elsif ($action eq 'usersessions') {
1.145 raeburn 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 ++;
1.139 raeburn 704: } elsif ($action eq 'coursedefaults') {
705: $output .= &print_coursedefaults('bottom',$dom,$settings,\$rowtotal);
1.122 jms 706: } elsif ($action eq 'rolecolors') {
1.30 raeburn 707: $output .= &print_rolecolors($phase,'coordinator',$dom,$confname,$settings,\$rowtotal).'
1.6 raeburn 708: </table>
709: </td>
710: </tr>
711: <tr>
712: <td>
713: <table class="LC_nested">
714: <tr class="LC_info_row">
1.69 raeburn 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>
1.3 raeburn 719: </tr>'.
1.30 raeburn 720: &print_rolecolors($phase,'author',$dom,$confname,$settings,\$rowtotal).'
1.3 raeburn 721: </table>
722: </td>
723: </tr>
724: <tr>
725: <td>
726: <table class="LC_nested">
727: <tr class="LC_info_row">
1.59 bisitz 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>
1.3 raeburn 730: </tr>'.
1.30 raeburn 731: &print_rolecolors($phase,'admin',$dom,$confname,$settings,\$rowtotal);
732: $rowtotal += 2;
1.6 raeburn 733: }
1.3 raeburn 734: } else {
1.30 raeburn 735: $output .= '
1.3 raeburn 736: <tr>
737: <td>
738: <table class="LC_nested">
1.30 raeburn 739: <tr class="LC_info_row">';
1.24 raeburn 740: if (($action eq 'login') || ($action eq 'directorysrch')) {
1.30 raeburn 741: $output .= '
1.59 bisitz 742: <td class="LC_left_item" colspan="2">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
1.69 raeburn 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:
1.6 raeburn 748: } else {
1.30 raeburn 749: $output .= '
1.69 raeburn 750: <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
751: }
1.72 raeburn 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: }
1.69 raeburn 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'}) {
1.150 raeburn 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: }
1.69 raeburn 771: if ($action eq 'serverstatuses') {
772: $output .= '<br />(<tt>'.&mt('IP1,IP2 etc.').'</tt>)';
773: }
774: $output .= '</td>';
1.6 raeburn 775: }
1.150 raeburn 776: if ($item->{'header'}->[0]->{'col4'}) {
777: $output .= '<td class="LC_right_item" valign="top">'.
778: &mt($item->{'header'}->[0]->{'col4'});
779: }
1.69 raeburn 780: $output .= '</tr>';
1.48 raeburn 781: $rowtotal ++;
1.168 raeburn 782: if ($action eq 'quotas') {
1.86 raeburn 783: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.3 raeburn 784: } elsif ($action eq 'autoenroll') {
1.30 raeburn 785: $output .= &print_autoenroll($dom,$settings,\$rowtotal);
1.125 raeburn 786: } elsif ($action eq 'autocreate') {
787: $output .= &print_autocreate($dom,$settings,\$rowtotal);
1.23 raeburn 788: } elsif ($action eq 'directorysrch') {
1.30 raeburn 789: $output .= &print_directorysrch($dom,$settings,\$rowtotal);
1.28 raeburn 790: } elsif ($action eq 'contacts') {
1.30 raeburn 791: $output .= &print_contacts($dom,$settings,\$rowtotal);
1.43 raeburn 792: } elsif ($action eq 'defaults') {
793: $output .= &print_defaults($dom,\$rowtotal);
1.46 raeburn 794: } elsif ($action eq 'scantron') {
795: $output .= &print_scantronformat($r,$dom,$confname,$settings,\$rowtotal);
1.69 raeburn 796: } elsif ($action eq 'serverstatuses') {
797: $output .= &print_serverstatuses($dom,$settings,\$rowtotal);
1.118 jms 798: } elsif ($action eq 'helpsettings') {
1.168 raeburn 799: $output .= &print_helpsettings($dom,$confname,$settings,\$rowtotal);
1.150 raeburn 800: } elsif ($action eq 'loadbalancing') {
801: $output .= &print_loadbalancing($dom,$settings,\$rowtotal);
1.121 raeburn 802: }
1.3 raeburn 803: }
1.30 raeburn 804: $output .= '
1.3 raeburn 805: </table>
806: </td>
807: </tr>
1.30 raeburn 808: </table><br />';
809: return ($output,$rowtotal);
1.1 raeburn 810: }
811:
1.3 raeburn 812: sub print_login {
1.168 raeburn 813: my ($caller,$dom,$confname,$phase,$settings,$rowtotal) = @_;
1.110 raeburn 814: my ($css_class,$datatable);
1.6 raeburn 815: my %choices = &login_choices();
1.110 raeburn 816:
1.168 raeburn 817: if ($caller eq 'service') {
1.149 raeburn 818: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.110 raeburn 819: my $choice = $choices{'disallowlogin'};
820: $css_class = ' class="LC_odd_row"';
1.128 raeburn 821: $datatable .= '<tr'.$css_class.'><td>'.$choice.'</td>'.
1.110 raeburn 822: '<td align="right"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1.128 raeburn 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";
1.110 raeburn 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"';
1.128 raeburn 835: if (ref($disallowed{$lonhost}) eq 'HASH') {
836: if ($disallowed{$lonhost}{'server'} ne '') {
837: $direct = '';
838: }
1.110 raeburn 839: }
1.115 raeburn 840: $datatable .= '<tr><td>'.$servers{$lonhost}.'</td>'.
1.128 raeburn 841: '<td><select name="'.$lonhost.'_server">'.
1.110 raeburn 842: '<option value=""'.$direct.'>'.$choices{'directlogin'}.
843: '</option>';
1.184 raeburn 844: foreach my $hostid (sort(keys(%servers))) {
1.115 raeburn 845: next if ($servers{$hostid} eq $servers{$lonhost});
1.110 raeburn 846: my $selected = '';
1.128 raeburn 847: if (ref($disallowed{$lonhost}) eq 'HASH') {
848: if ($hostid eq $disallowed{$lonhost}{'server'}) {
849: $selected = 'selected="selected"';
850: }
1.110 raeburn 851: }
852: $datatable .= '<option value="'.$hostid.'"'.$selected.'>'.
853: $servers{$hostid}.'</option>';
854: }
1.128 raeburn 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>';
1.110 raeburn 881: }
882: $datatable .= '</table></td></tr>';
883: return $datatable;
1.168 raeburn 884: } elsif ($caller eq 'page') {
885: my %defaultchecked = (
886: 'coursecatalog' => 'on',
1.188 raeburn 887: 'helpdesk' => 'on',
1.168 raeburn 888: 'adminmail' => 'off',
889: 'newuser' => 'off',
890: );
1.188 raeburn 891: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.168 raeburn 892: my (%checkedon,%checkedoff);
1.42 raeburn 893: foreach my $item (@toggles) {
1.168 raeburn 894: if ($defaultchecked{$item} eq 'on') {
895: $checkedon{$item} = ' checked="checked" ';
1.42 raeburn 896: $checkedoff{$item} = ' ';
1.168 raeburn 897: } elsif ($defaultchecked{$item} eq 'off') {
898: $checkedoff{$item} = ' checked="checked" ';
1.42 raeburn 899: $checkedon{$item} = ' ';
900: }
1.1 raeburn 901: }
1.168 raeburn 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: );
1.6 raeburn 912: foreach my $item (@images) {
1.168 raeburn 913: $defaults{$item} = $defaultdesign{'login.'.$item};
914: $defaults{'showlogo'}{$item} = 1;
915: }
916: foreach my $item (@bgs) {
917: $defaults{'bgs'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 918: }
1.41 raeburn 919: foreach my $item (@logintext) {
1.168 raeburn 920: $defaults{'logintext'}{$item} = $defaultdesign{'login.'.$item};
1.41 raeburn 921: }
1.168 raeburn 922: foreach my $item (@links) {
923: $defaults{'links'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 924: }
1.168 raeburn 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: }
1.6 raeburn 982: }
1.168 raeburn 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: }
1.6 raeburn 988: }
989: }
1.168 raeburn 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 ++;
1.6 raeburn 1006: }
1.168 raeburn 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';
1.8 raeburn 1037: }
1038: }
1.168 raeburn 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.'" />';
1.6 raeburn 1071: }
1.168 raeburn 1072: $datatable .= '</td></tr>';
1073: $itemcount ++;
1.6 raeburn 1074: }
1.168 raeburn 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" />';
1.6 raeburn 1093: }
1.168 raeburn 1094: $datatable .= '</td></tr>';
1.169 raeburn 1095: $itemcount ++;
1.6 raeburn 1096: }
1.169 raeburn 1097: $datatable .= &captcha_choice('login',$settings,$itemcount);
1.1 raeburn 1098: }
1.6 raeburn 1099: return $datatable;
1100: }
1101:
1102: sub login_choices {
1103: my %choices =
1104: &Apache::lonlocal::texthash (
1.116 bisitz 1105: coursecatalog => 'Display Course/Community Catalog link?',
1.110 raeburn 1106: adminmail => "Display Administrator's E-mail Address?",
1.188 raeburn 1107: helpdesk => 'Display "Contact Helpdesk" link',
1.110 raeburn 1108: disallowlogin => "Login page requests redirected",
1109: hostid => "Server",
1.128 raeburn 1110: server => "Redirect to:",
1111: serverpath => "Path",
1112: custompath => "Custom",
1113: exempt => "Exempt IP(s)",
1.110 raeburn 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",
1.6 raeburn 1131: );
1132: return %choices;
1133: }
1134:
1135: sub print_rolecolors {
1.30 raeburn 1136: my ($phase,$role,$dom,$confname,$settings,$rowtotal) = @_;
1.6 raeburn 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");
1.7 albertel 1142: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.6 raeburn 1143: my %defaultdesign = %Apache::loncommon::defaultdesign;
1144: my (%is_custom,%designs);
1.200 ! raeburn 1145: my %defaults = &role_defaults($role,\@bgs,\@links,\@images);
1.6 raeburn 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: }
1.97 tempelho 1156: if ($settings->{$role}->{'fontmenu'} ne '') {
1157: $designs{'fontmenu'} = $settings->{$role}->{'fontmenu'};
1158: $is_custom{'fontmenu'} = 1;
1159: }
1.6 raeburn 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: }
1.97 tempelho 1178: if ($designhash{$dom.'.'.$role.'.fontmenu'} ne '') {
1179: $designs{fontmenu} = $designhash{$dom.'.'.$role.'.fontmenu'};
1180: $is_custom{'fontmenu'} = 1;
1181: }
1.6 raeburn 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;
1.30 raeburn 1201: my $datatable = &display_color_options($dom,$confname,$phase,$role,$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal);
1.6 raeburn 1202: $datatable .= '</tr></table></td></tr>';
1203: return $datatable;
1204: }
1205:
1.200 ! raeburn 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:
1.6 raeburn 1244: sub display_color_options {
1.9 raeburn 1245: my ($dom,$confname,$phase,$role,$itemcount,$choices,$is_custom,$defaults,$designs,
1.135 bisitz 1246: $images,$bgs,$links,$alt_text,$rowtotal,$logintext) = @_;
1.159 raeburn 1247: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.6 raeburn 1248: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.176 raeburn 1249: my $datatable = '<tr'.$css_class.'>'.
1.6 raeburn 1250: '<td>'.$choices->{'font'}.'</td>';
1251: if (!$is_custom->{'font'}) {
1.30 raeburn 1252: $datatable .= '<td>'.&mt('Default in use:').' <span id="css_default_'.$role.'_font" style="color: '.$defaults->{'font'}.';">'.$defaults->{'font'}.'</span></td>';
1.6 raeburn 1253: } else {
1254: $datatable .= '<td> </td>';
1255: }
1.174 foxr 1256: my $current_color = $designs->{'font'} ? $designs->{'font'} : $defaults->{'font'};
1257:
1.8 raeburn 1258: $datatable .= '<td><span class="LC_nobreak">'.
1.174 foxr 1259: '<input type="text" class="colorchooser" size="10" name="'.$role.'_font"'.
1260: ' value="'.$current_color.'" /> '.
1261: ' </td></tr>';
1.107 raeburn 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: }
1.174 foxr 1270: $current_color = $designs->{'fontmenu'} ?
1271: $designs->{'fontmenu'} : $defaults->{'fontmenu'};
1.107 raeburn 1272: $datatable .= '<td><span class="LC_nobreak">'.
1.174 foxr 1273: '<input class="colorchooser" type="text" size="10" name="'
1274: .$role.'_fontmenu"'.
1275: ' value="'.$current_color.'" /> '.
1276: ' </td></tr>';
1.97 tempelho 1277: }
1.9 raeburn 1278: my $switchserver = &check_switchserver($dom,$confname);
1.6 raeburn 1279: foreach my $img (@{$images}) {
1.18 albertel 1280: $itemcount ++;
1.6 raeburn 1281: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.8 raeburn 1282: $datatable .= '<tr'.$css_class.'>'.
1.70 raeburn 1283: '<td>'.$choices->{$img};
1.41 raeburn 1284: my ($imgfile,$img_import,$login_hdr_pick,$logincolors);
1.70 raeburn 1285: if ($role eq 'login') {
1286: if ($img eq 'login') {
1287: $login_hdr_pick =
1.135 bisitz 1288: &login_header_options($img,$role,$defaults,$is_custom,$choices);
1.70 raeburn 1289: $logincolors =
1290: &login_text_colors($img,$role,$logintext,$phase,$choices,
1291: $designs);
1292: } elsif ($img ne 'domlogo') {
1293: $datatable.= &logo_display_options($img,$defaults,$designs);
1294: }
1295: }
1296: $datatable .= '</td>';
1.6 raeburn 1297: if ($designs->{$img} ne '') {
1298: $imgfile = $designs->{$img};
1.18 albertel 1299: $img_import = ($imgfile =~ m{^/adm/});
1.6 raeburn 1300: } else {
1301: $imgfile = $defaults->{$img};
1302: }
1303: if ($imgfile) {
1.9 raeburn 1304: my ($showfile,$fullsize);
1305: if ($imgfile =~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
1.6 raeburn 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/[^/]+)/([^/]+)$-) {
1.16 raeburn 1321: $showfile = $imgfile;
1.6 raeburn 1322: my $imgdir = $1;
1323: my $filename = $2;
1.159 raeburn 1324: if (-e "$londocroot/$imgdir/tn-".$filename) {
1.6 raeburn 1325: $showfile = "/$imgdir/tn-".$filename;
1326: } else {
1.159 raeburn 1327: my $input = $londocroot.$imgfile;
1328: my $output = "$londocroot/$imgdir/tn-".$filename;
1.6 raeburn 1329: if (!-e $output) {
1.9 raeburn 1330: my ($width,$height) = &thumb_dimensions();
1.16 raeburn 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");
1.159 raeburn 1336: $showfile = "/$imgdir/tn-".$filename;
1.16 raeburn 1337: }
1338: }
1.6 raeburn 1339: }
1340: }
1.16 raeburn 1341: }
1.6 raeburn 1342: if ($showfile) {
1.40 raeburn 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: }
1.41 raeburn 1363: $datatable .= '<td>';
1364: if ($img eq 'login') {
1.135 bisitz 1365: $datatable .= $login_hdr_pick;
1366: }
1.41 raeburn 1367: $datatable .= &image_changes($is_custom->{$img},$alt_text->{$img},$img_import,
1368: $showfile,$fullsize,$role,$img,$imgfile,$logincolors);
1.6 raeburn 1369: } else {
1370: $datatable .= '<td colspan="2" class="LC_right_item"><br />'.
1371: &mt('Upload:');
1372: }
1373: } else {
1374: $datatable .= '<td colspan="2" class="LC_right_item"><br />'.
1375: &mt('Upload:');
1376: }
1.9 raeburn 1377: if ($switchserver) {
1378: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1379: } else {
1.135 bisitz 1380: if ($img ne 'login') { # suppress file selection for Log-in header
1381: $datatable .=' <input type="file" name="'.$role.'_'.$img.'" />';
1382: }
1.9 raeburn 1383: }
1384: $datatable .= '</td></tr>';
1.6 raeburn 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}) {
1.70 raeburn 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>';
1.6 raeburn 1394: }
1395: }
1396: if ($bgs_def) {
1.8 raeburn 1397: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$bgs_def.'</tr></table></td>';
1.6 raeburn 1398: } else {
1399: $datatable .= '<td> </td>';
1400: }
1401: $datatable .= '<td class="LC_right_item">'.
1402: '<table border="0"><tr>';
1.174 foxr 1403:
1.6 raeburn 1404: foreach my $item (@{$bgs}) {
1.174 foxr 1405: $datatable .= '<td align="center">';
1406: my $color = $designs->{'bgs'}{$item} ? $designs->{'bgs'}{$item} : $defaults->{'bgs'}{$item};
1.6 raeburn 1407: if ($designs->{'bgs'}{$item}) {
1.174 foxr 1408: $datatable .= ' ';
1.6 raeburn 1409: }
1.174 foxr 1410: $datatable .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1.41 raeburn 1411: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.6 raeburn 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}) {
1.30 raeburn 1421: $links_def .= '<td>'.$choices->{$item}.'<br /><span id="css_default_'.$role.'_'.$item.'" style="color: '.$defaults->{'links'}{$item}.';">'.$defaults->{'links'}{$item}.'</span></td>';
1.6 raeburn 1422: }
1423: }
1424: if ($links_def) {
1.8 raeburn 1425: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$links_def.'</tr></table></td>';
1.6 raeburn 1426: } else {
1427: $datatable .= '<td> </td>';
1428: }
1429: $datatable .= '<td class="LC_right_item">'.
1430: '<table border="0"><tr>';
1431: foreach my $item (@{$links}) {
1.174 foxr 1432: my $color = $designs->{'link'}{$item} ? $designs->{'link'}{$item} : $defaults->{'links'}{$item};
1433: $datatable .= '<td align="center">'."\n";
1434:
1.6 raeburn 1435: if ($designs->{'links'}{$item}) {
1.174 foxr 1436: $datatable.=' ';
1.6 raeburn 1437: }
1.174 foxr 1438: $datatable .= '<br /><input type="text" size="8" class="colorchooser" name="'.$role.'_'.$item.'" value="'.$color.
1.6 raeburn 1439: '" /></td>';
1440: }
1.30 raeburn 1441: $$rowtotal += $itemcount;
1.3 raeburn 1442: return $datatable;
1443: }
1444:
1.70 raeburn 1445: sub logo_display_options {
1446: my ($img,$defaults,$designs) = @_;
1447: my $checkedon;
1448: if (ref($defaults) eq 'HASH') {
1449: if (ref($defaults->{'showlogo'}) eq 'HASH') {
1450: if ($defaults->{'showlogo'}{$img}) {
1451: $checkedon = 'checked="checked" ';
1452: }
1453: }
1454: }
1455: if (ref($designs) eq 'HASH') {
1456: if (ref($designs->{'showlogo'}) eq 'HASH') {
1457: if (defined($designs->{'showlogo'}{$img})) {
1458: if ($designs->{'showlogo'}{$img} == 0) {
1459: $checkedon = '';
1460: } elsif ($designs->{'showlogo'}{$img} == 1) {
1461: $checkedon = 'checked="checked" ';
1462: }
1463: }
1464: }
1465: }
1466: return '<br /><label> <input type="checkbox" name="'.
1467: 'login_showlogo_'.$img.'" value="1" '.$checkedon.'/>'.
1468: &mt('show').'</label>'."\n";
1469: }
1470:
1.41 raeburn 1471: sub login_header_options {
1.135 bisitz 1472: my ($img,$role,$defaults,$is_custom,$choices) = @_;
1473: my $output = '';
1.41 raeburn 1474: if ((!$is_custom->{'textcol'}) || (!$is_custom->{'bgcol'})) {
1.135 bisitz 1475: $output .= &mt('Text default(s):').'<br />';
1.41 raeburn 1476: if (!$is_custom->{'textcol'}) {
1477: $output .= $choices->{'textcol'}.': '.$defaults->{'logintext'}{'textcol'}.
1478: ' ';
1479: }
1480: if (!$is_custom->{'bgcol'}) {
1481: $output .= $choices->{'bgcol'}.': '.
1482: '<span id="css_'.$role.'_font" style="background-color: '.
1483: $defaults->{'logintext'}{'bgcol'}.';"> </span>';
1484: }
1485: $output .= '<br />';
1486: }
1487: $output .='<br />';
1488: return $output;
1489: }
1490:
1491: sub login_text_colors {
1492: my ($img,$role,$logintext,$phase,$choices,$designs) = @_;
1493: my $color_menu = '<table border="0"><tr>';
1494: foreach my $item (@{$logintext}) {
1495: my $link = &color_pick($phase,$role,$item,$choices->{$item},$designs->{'logintext'}{$item});
1496: $color_menu .= '<td align="center">'.$link;
1497: if ($designs->{'logintext'}{$item}) {
1498: $color_menu .= ' <span id="css_'.$role.'_'.$item.'" style="background-color: '.$designs->{'logintext'}{$item}.';"> </span>';
1499: }
1500: $color_menu .= '<br /><input type="text" size="8" name="'.$role.'_'.$item.'" value="'.
1501: $designs->{'logintext'}{$item}.'" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>'.
1502: '<td> </td>';
1503: }
1504: $color_menu .= '</tr></table><br />';
1505: return $color_menu;
1506: }
1507:
1508: sub image_changes {
1509: my ($is_custom,$alt_text,$img_import,$showfile,$fullsize,$role,$img,$imgfile,$logincolors) = @_;
1510: my $output;
1.135 bisitz 1511: if ($img eq 'login') {
1512: # suppress image for Log-in header
1513: } elsif (!$is_custom) {
1.70 raeburn 1514: if ($img ne 'domlogo') {
1.41 raeburn 1515: $output .= &mt('Default image:').'<br />';
1516: } else {
1517: $output .= &mt('Default in use:').'<br />';
1518: }
1519: }
1.135 bisitz 1520: if ($img eq 'login') { # suppress image for Log-in header
1521: $output .= '<td>'.$logincolors;
1.41 raeburn 1522: } else {
1.135 bisitz 1523: if ($img_import) {
1524: $output .= '<input type="hidden" name="'.$role.'_import_'.$img.'" value="'.$imgfile.'" />';
1525: }
1526: $output .= '<a href="'.$fullsize.'" target="_blank"><img src="'.
1527: $showfile.'" alt="'.$alt_text.'" border="0" /></a></td>';
1528: if ($is_custom) {
1529: $output .= '<td>'.$logincolors.'<span class="LC_nobreak"><label>'.
1530: '<input type="checkbox" name="'.
1531: $role.'_del_'.$img.'" value="1" />'.&mt('Delete?').
1532: '</label> '.&mt('Replace:').'</span><br />';
1533: } else {
1534: $output .= '<td valign="bottom">'.$logincolors.&mt('Upload:').'<br />';
1535: }
1.41 raeburn 1536: }
1537: return $output;
1538: }
1539:
1.6 raeburn 1540: sub color_pick {
1541: my ($phase,$role,$item,$desc,$curcol) = @_;
1542: my $link = '<a href="javascript:pjump('."'color_custom','".$desc.
1543: "','".$curcol."','".$role.'_'.$item."','parmform.pres','psub'".
1544: ');">'.$desc.'</a>';
1545: return $link;
1546: }
1547:
1.3 raeburn 1548: sub print_quotas {
1.86 raeburn 1549: my ($dom,$settings,$rowtotal,$action) = @_;
1550: my $context;
1551: if ($action eq 'quotas') {
1552: $context = 'tools';
1553: } else {
1554: $context = $action;
1555: }
1.197 raeburn 1556: my ($datatable,$defaultquota,$authorquota,@usertools,@options,%validations);
1.44 raeburn 1557: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.3 raeburn 1558: my $typecount = 0;
1.101 raeburn 1559: my ($css_class,%titles);
1.86 raeburn 1560: if ($context eq 'requestcourses') {
1.98 raeburn 1561: @usertools = ('official','unofficial','community');
1.106 raeburn 1562: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 1563: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
1564: %titles = &courserequest_titles();
1.163 raeburn 1565: } elsif ($context eq 'requestauthor') {
1566: @usertools = ('author');
1567: @options = ('norequest','approval','automatic');
1568: %titles = &authorrequest_titles();
1.86 raeburn 1569: } else {
1.162 raeburn 1570: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 1571: %titles = &tool_titles();
1.86 raeburn 1572: }
1.26 raeburn 1573: if (ref($types) eq 'ARRAY') {
1.23 raeburn 1574: foreach my $type (@{$types}) {
1.197 raeburn 1575: my ($currdefquota,$currauthorquota);
1.163 raeburn 1576: unless (($context eq 'requestcourses') ||
1577: ($context eq 'requestauthor')) {
1.86 raeburn 1578: if (ref($settings) eq 'HASH') {
1579: if (ref($settings->{defaultquota}) eq 'HASH') {
1.197 raeburn 1580: $currdefquota = $settings->{defaultquota}->{$type};
1.86 raeburn 1581: } else {
1582: $currdefquota = $settings->{$type};
1583: }
1.197 raeburn 1584: if (ref($settings->{authorquota}) eq 'HASH') {
1585: $currauthorquota = $settings->{authorquota}->{$type};
1586: }
1.78 raeburn 1587: }
1.72 raeburn 1588: }
1.3 raeburn 1589: if (defined($usertypes->{$type})) {
1590: $typecount ++;
1591: $css_class = $typecount%2?' class="LC_odd_row"':'';
1.72 raeburn 1592: $datatable .= '<tr'.$css_class.'>'.
1.3 raeburn 1593: '<td>'.$usertypes->{$type}.'</td>'.
1.72 raeburn 1594: '<td class="LC_left_item">';
1.101 raeburn 1595: if ($context eq 'requestcourses') {
1596: $datatable .= '<table><tr>';
1597: }
1598: my %cell;
1.72 raeburn 1599: foreach my $item (@usertools) {
1.101 raeburn 1600: if ($context eq 'requestcourses') {
1601: my ($curroption,$currlimit);
1602: if (ref($settings) eq 'HASH') {
1603: if (ref($settings->{$item}) eq 'HASH') {
1604: $curroption = $settings->{$item}->{$type};
1605: if ($curroption =~ /^autolimit=(\d*)$/) {
1606: $currlimit = $1;
1607: }
1608: }
1609: }
1610: if (!$curroption) {
1611: $curroption = 'norequest';
1612: }
1613: $datatable .= '<th>'.$titles{$item}.'</th>';
1614: foreach my $option (@options) {
1615: my $val = $option;
1616: if ($option eq 'norequest') {
1617: $val = 0;
1618: }
1619: if ($option eq 'validate') {
1620: my $canvalidate = 0;
1621: if (ref($validations{$item}) eq 'HASH') {
1622: if ($validations{$item}{$type}) {
1623: $canvalidate = 1;
1624: }
1625: }
1626: next if (!$canvalidate);
1627: }
1628: my $checked = '';
1629: if ($option eq $curroption) {
1630: $checked = ' checked="checked"';
1631: } elsif ($option eq 'autolimit') {
1632: if ($curroption =~ /^autolimit/) {
1633: $checked = ' checked="checked"';
1634: }
1635: }
1636: $cell{$item} .= '<span class="LC_nobreak"><label>'.
1637: '<input type="radio" name="crsreq_'.$item.
1638: '_'.$type.'" value="'.$val.'"'.$checked.' />'.
1.127 raeburn 1639: $titles{$option}.'</label>';
1.101 raeburn 1640: if ($option eq 'autolimit') {
1.127 raeburn 1641: $cell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 1642: $item.'_limit_'.$type.'" size="1" '.
1.103 raeburn 1643: 'value="'.$currlimit.'" />';
1.101 raeburn 1644: }
1.127 raeburn 1645: $cell{$item} .= '</span> ';
1.103 raeburn 1646: if ($option eq 'autolimit') {
1.127 raeburn 1647: $cell{$item} .= $titles{'unlimited'};
1.103 raeburn 1648: }
1.101 raeburn 1649: }
1.163 raeburn 1650: } elsif ($context eq 'requestauthor') {
1651: my $curroption;
1652: if (ref($settings) eq 'HASH') {
1653: $curroption = $settings->{$type};
1654: }
1655: if (!$curroption) {
1656: $curroption = 'norequest';
1657: }
1658: foreach my $option (@options) {
1659: my $val = $option;
1660: if ($option eq 'norequest') {
1661: $val = 0;
1662: }
1663: my $checked = '';
1664: if ($option eq $curroption) {
1665: $checked = ' checked="checked"';
1666: }
1667: $datatable .= '<span class="LC_nobreak"><label>'.
1668: '<input type="radio" name="authorreq_'.$type.
1669: '" value="'.$val.'"'.$checked.' />'.
1670: $titles{$option}.'</label></span> ';
1671: }
1.101 raeburn 1672: } else {
1673: my $checked = 'checked="checked" ';
1674: if (ref($settings) eq 'HASH') {
1675: if (ref($settings->{$item}) eq 'HASH') {
1676: if ($settings->{$item}->{$type} == 0) {
1677: $checked = '';
1678: } elsif ($settings->{$item}->{$type} == 1) {
1679: $checked = 'checked="checked" ';
1680: }
1.78 raeburn 1681: }
1.72 raeburn 1682: }
1.101 raeburn 1683: $datatable .= '<span class="LC_nobreak"><label>'.
1684: '<input type="checkbox" name="'.$context.'_'.$item.
1685: '" value="'.$type.'" '.$checked.'/>'.$titles{$item}.
1686: '</label></span> ';
1.72 raeburn 1687: }
1.101 raeburn 1688: }
1689: if ($context eq 'requestcourses') {
1690: $datatable .= '</tr><tr>';
1691: foreach my $item (@usertools) {
1.106 raeburn 1692: $datatable .= '<td style="vertical-align: top">'.$cell{$item}.'</td>';
1.101 raeburn 1693: }
1694: $datatable .= '</tr></table>';
1.72 raeburn 1695: }
1.86 raeburn 1696: $datatable .= '</td>';
1.163 raeburn 1697: unless (($context eq 'requestcourses') ||
1698: ($context eq 'requestauthor')) {
1.86 raeburn 1699: $datatable .=
1.197 raeburn 1700: '<td class="LC_right_item">'.
1701: '<span class="LC_nobreak">'.&mt('Portfolio').': '.
1.3 raeburn 1702: '<input type="text" name="quota_'.$type.
1.72 raeburn 1703: '" value="'.$currdefquota.
1.197 raeburn 1704: '" size="5" /></span>'.(' ' x 2).
1705: '<span class="LC_nobreak">'.&mt('Authoring').': '.
1706: '<input type="text" name="authorquota_'.$type.
1707: '" value="'.$currauthorquota.
1708: '" size="5" /></span></td>';
1.86 raeburn 1709: }
1710: $datatable .= '</tr>';
1.3 raeburn 1711: }
1712: }
1713: }
1.163 raeburn 1714: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 1715: $defaultquota = '20';
1.197 raeburn 1716: $authorquota = '500';
1.86 raeburn 1717: if (ref($settings) eq 'HASH') {
1718: if (ref($settings->{'defaultquota'}) eq 'HASH') {
1719: $defaultquota = $settings->{'defaultquota'}->{'default'};
1720: } elsif (defined($settings->{'default'})) {
1721: $defaultquota = $settings->{'default'};
1722: }
1.197 raeburn 1723: if (ref($settings->{'authorquota'}) eq 'HASH') {
1724: $authorquota = $settings->{'authorquota'}->{'default'};
1725: }
1.3 raeburn 1726: }
1727: }
1728: $typecount ++;
1729: $css_class = $typecount%2?' class="LC_odd_row"':'';
1730: $datatable .= '<tr'.$css_class.'>'.
1.26 raeburn 1731: '<td>'.$othertitle.'</td>'.
1.72 raeburn 1732: '<td class="LC_left_item">';
1.101 raeburn 1733: if ($context eq 'requestcourses') {
1734: $datatable .= '<table><tr>';
1735: }
1736: my %defcell;
1.72 raeburn 1737: foreach my $item (@usertools) {
1.101 raeburn 1738: if ($context eq 'requestcourses') {
1739: my ($curroption,$currlimit);
1740: if (ref($settings) eq 'HASH') {
1741: if (ref($settings->{$item}) eq 'HASH') {
1742: $curroption = $settings->{$item}->{'default'};
1743: if ($curroption =~ /^autolimit=(\d*)$/) {
1744: $currlimit = $1;
1745: }
1746: }
1747: }
1748: if (!$curroption) {
1749: $curroption = 'norequest';
1750: }
1751: $datatable .= '<th>'.$titles{$item}.'</th>';
1752: foreach my $option (@options) {
1753: my $val = $option;
1754: if ($option eq 'norequest') {
1755: $val = 0;
1756: }
1757: if ($option eq 'validate') {
1758: my $canvalidate = 0;
1759: if (ref($validations{$item}) eq 'HASH') {
1760: if ($validations{$item}{'default'}) {
1761: $canvalidate = 1;
1762: }
1763: }
1764: next if (!$canvalidate);
1765: }
1766: my $checked = '';
1767: if ($option eq $curroption) {
1768: $checked = ' checked="checked"';
1769: } elsif ($option eq 'autolimit') {
1770: if ($curroption =~ /^autolimit/) {
1771: $checked = ' checked="checked"';
1772: }
1773: }
1774: $defcell{$item} .= '<span class="LC_nobreak"><label>'.
1775: '<input type="radio" name="crsreq_'.$item.
1776: '_default" value="'.$val.'"'.$checked.' />'.
1777: $titles{$option}.'</label>';
1778: if ($option eq 'autolimit') {
1.127 raeburn 1779: $defcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 1780: $item.'_limit_default" size="1" '.
1781: 'value="'.$currlimit.'" />';
1782: }
1.127 raeburn 1783: $defcell{$item} .= '</span> ';
1.104 raeburn 1784: if ($option eq 'autolimit') {
1.127 raeburn 1785: $defcell{$item} .= $titles{'unlimited'};
1.104 raeburn 1786: }
1.101 raeburn 1787: }
1.163 raeburn 1788: } elsif ($context eq 'requestauthor') {
1789: my $curroption;
1790: if (ref($settings) eq 'HASH') {
1.172 raeburn 1791: $curroption = $settings->{'default'};
1.163 raeburn 1792: }
1793: if (!$curroption) {
1794: $curroption = 'norequest';
1795: }
1796: foreach my $option (@options) {
1797: my $val = $option;
1798: if ($option eq 'norequest') {
1799: $val = 0;
1800: }
1801: my $checked = '';
1802: if ($option eq $curroption) {
1803: $checked = ' checked="checked"';
1804: }
1805: $datatable .= '<span class="LC_nobreak"><label>'.
1806: '<input type="radio" name="authorreq_default"'.
1807: ' value="'.$val.'"'.$checked.' />'.
1808: $titles{$option}.'</label></span> ';
1809: }
1.101 raeburn 1810: } else {
1811: my $checked = 'checked="checked" ';
1812: if (ref($settings) eq 'HASH') {
1813: if (ref($settings->{$item}) eq 'HASH') {
1814: if ($settings->{$item}->{'default'} == 0) {
1815: $checked = '';
1816: } elsif ($settings->{$item}->{'default'} == 1) {
1817: $checked = 'checked="checked" ';
1818: }
1.78 raeburn 1819: }
1.72 raeburn 1820: }
1.101 raeburn 1821: $datatable .= '<span class="LC_nobreak"><label>'.
1822: '<input type="checkbox" name="'.$context.'_'.$item.
1823: '" value="default" '.$checked.'/>'.$titles{$item}.
1824: '</label></span> ';
1825: }
1826: }
1827: if ($context eq 'requestcourses') {
1828: $datatable .= '</tr><tr>';
1829: foreach my $item (@usertools) {
1.106 raeburn 1830: $datatable .= '<td style="vertical-align: top">'.$defcell{$item}.'</td>';
1.72 raeburn 1831: }
1.101 raeburn 1832: $datatable .= '</tr></table>';
1.72 raeburn 1833: }
1.86 raeburn 1834: $datatable .= '</td>';
1.163 raeburn 1835: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.197 raeburn 1836: $datatable .= '<td class="LC_right_item">'.
1837: '<span class="LC_nobreak">'.&mt('Portfolio').': '.
1.86 raeburn 1838: '<input type="text" name="defaultquota" value="'.
1.197 raeburn 1839: $defaultquota.'" size="5" /></span>'.(' ' x2).
1840: '<span class="LC_nobreak">'.&mt('Authoring').': '.
1841: '<input type="text" name="authorquota" value="'.
1842: $authorquota.'" size="5" /></span></td>';
1.86 raeburn 1843: }
1844: $datatable .= '</tr>';
1.72 raeburn 1845: $typecount ++;
1846: $css_class = $typecount%2?' class="LC_odd_row"':'';
1847: $datatable .= '<tr'.$css_class.'>'.
1.197 raeburn 1848: '<td>'.&mt('LON-CAPA Advanced Users').'<br />';
1.104 raeburn 1849: if ($context eq 'requestcourses') {
1.109 raeburn 1850: $datatable .= &mt('(overrides affiliation, if set)').
1851: '</td>'.
1852: '<td class="LC_left_item">'.
1853: '<table><tr>';
1.101 raeburn 1854: } else {
1.109 raeburn 1855: $datatable .= &mt('(overrides affiliation, if checked)').
1856: '</td>'.
1857: '<td class="LC_left_item" colspan="2">'.
1858: '<br />';
1.101 raeburn 1859: }
1860: my %advcell;
1.72 raeburn 1861: foreach my $item (@usertools) {
1.101 raeburn 1862: if ($context eq 'requestcourses') {
1863: my ($curroption,$currlimit);
1864: if (ref($settings) eq 'HASH') {
1865: if (ref($settings->{$item}) eq 'HASH') {
1866: $curroption = $settings->{$item}->{'_LC_adv'};
1867: if ($curroption =~ /^autolimit=(\d*)$/) {
1868: $currlimit = $1;
1869: }
1870: }
1871: }
1872: $datatable .= '<th>'.$titles{$item}.'</th>';
1.104 raeburn 1873: my $checked = '';
1874: if ($curroption eq '') {
1875: $checked = ' checked="checked"';
1876: }
1877: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
1878: '<input type="radio" name="crsreq_'.$item.
1879: '__LC_adv" value=""'.$checked.' />'.
1880: &mt('No override set').'</label></span> ';
1.101 raeburn 1881: foreach my $option (@options) {
1882: my $val = $option;
1883: if ($option eq 'norequest') {
1884: $val = 0;
1885: }
1886: if ($option eq 'validate') {
1887: my $canvalidate = 0;
1888: if (ref($validations{$item}) eq 'HASH') {
1889: if ($validations{$item}{'_LC_adv'}) {
1890: $canvalidate = 1;
1891: }
1892: }
1893: next if (!$canvalidate);
1894: }
1895: my $checked = '';
1.104 raeburn 1896: if ($val eq $curroption) {
1.101 raeburn 1897: $checked = ' checked="checked"';
1898: } elsif ($option eq 'autolimit') {
1899: if ($curroption =~ /^autolimit/) {
1900: $checked = ' checked="checked"';
1901: }
1902: }
1903: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
1904: '<input type="radio" name="crsreq_'.$item.
1905: '__LC_adv" value="'.$val.'"'.$checked.' />'.
1906: $titles{$option}.'</label>';
1907: if ($option eq 'autolimit') {
1.127 raeburn 1908: $advcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 1909: $item.'_limit__LC_adv" size="1" '.
1910: 'value="'.$currlimit.'" />';
1911: }
1.127 raeburn 1912: $advcell{$item} .= '</span> ';
1.104 raeburn 1913: if ($option eq 'autolimit') {
1.127 raeburn 1914: $advcell{$item} .= $titles{'unlimited'};
1.104 raeburn 1915: }
1.101 raeburn 1916: }
1.163 raeburn 1917: } elsif ($context eq 'requestauthor') {
1918: my $curroption;
1919: if (ref($settings) eq 'HASH') {
1920: $curroption = $settings->{'_LC_adv'};
1921: }
1922: my $checked = '';
1923: if ($curroption eq '') {
1924: $checked = ' checked="checked"';
1925: }
1926: $datatable .= '<span class="LC_nobreak"><label>'.
1927: '<input type="radio" name="authorreq__LC_adv"'.
1928: ' value=""'.$checked.' />'.
1929: &mt('No override set').'</label></span> ';
1930: foreach my $option (@options) {
1931: my $val = $option;
1932: if ($option eq 'norequest') {
1933: $val = 0;
1934: }
1935: my $checked = '';
1936: if ($val eq $curroption) {
1937: $checked = ' checked="checked"';
1938: }
1939: $datatable .= '<span class="LC_nobreak"><label>'.
1.173 raeburn 1940: '<input type="radio" name="authorreq__LC_adv"'.
1941: ' value="'.$val.'"'.$checked.' />'.
1.163 raeburn 1942: $titles{$option}.'</label></span> ';
1943: }
1.101 raeburn 1944: } else {
1945: my $checked = 'checked="checked" ';
1946: if (ref($settings) eq 'HASH') {
1947: if (ref($settings->{$item}) eq 'HASH') {
1948: if ($settings->{$item}->{'_LC_adv'} == 0) {
1949: $checked = '';
1950: } elsif ($settings->{$item}->{'_LC_adv'} == 1) {
1951: $checked = 'checked="checked" ';
1952: }
1.79 raeburn 1953: }
1.72 raeburn 1954: }
1.101 raeburn 1955: $datatable .= '<span class="LC_nobreak"><label>'.
1956: '<input type="checkbox" name="'.$context.'_'.$item.
1957: '" value="_LC_adv" '.$checked.'/>'.$titles{$item}.
1958: '</label></span> ';
1959: }
1960: }
1961: if ($context eq 'requestcourses') {
1962: $datatable .= '</tr><tr>';
1963: foreach my $item (@usertools) {
1.106 raeburn 1964: $datatable .= '<td style="vertical-align: top">'.$advcell{$item}.'</td>';
1.72 raeburn 1965: }
1.101 raeburn 1966: $datatable .= '</tr></table>';
1.72 raeburn 1967: }
1.98 raeburn 1968: $datatable .= '</td></tr>';
1.30 raeburn 1969: $$rowtotal += $typecount;
1.3 raeburn 1970: return $datatable;
1971: }
1972:
1.163 raeburn 1973: sub print_requestmail {
1974: my ($dom,$action,$settings,$rowtotal) = @_;
1.191 raeburn 1975: my ($now,$datatable,%currapp,$rows);
1.102 raeburn 1976: $now = time;
1977: if (ref($settings) eq 'HASH') {
1978: if (ref($settings->{'notify'}) eq 'HASH') {
1979: if ($settings->{'notify'}{'approval'} ne '') {
1.191 raeburn 1980: map {$currapp{$_}=1;} split(/,/,$settings->{'notify'}{'approval'});
1.102 raeburn 1981: }
1982: }
1983: }
1.191 raeburn 1984: my $numinrow = 2;
1.102 raeburn 1985: my $css_class = 'class="LC_odd_row"';
1.163 raeburn 1986: my $text;
1987: if ($action eq 'requestcourses') {
1988: $text = &mt('Receive notification of course requests requiring approval');
1989: } else {
1990: $text = &mt('Receive notification of authoring space requests requiring approval')
1991: }
1992: $datatable = '<tr '.$css_class.'>'.
1993: ' <td>'.$text.'</td>'.
1.102 raeburn 1994: ' <td class="LC_left_item">';
1.191 raeburn 1995: my ($numdc,$table,$rows) = &active_dc_picker($dom,$numinrow,'checkbox',
1996: 'reqapprovalnotify',%currapp);
1997: if ($numdc > 0) {
1998: $datatable .= $table;
1.102 raeburn 1999: } else {
2000: $datatable .= &mt('There are no active Domain Coordinators');
2001: }
2002: $datatable .='</td></tr>';
2003: $$rowtotal += $rows;
2004: return $datatable;
2005: }
2006:
1.3 raeburn 2007: sub print_autoenroll {
1.30 raeburn 2008: my ($dom,$settings,$rowtotal) = @_;
1.3 raeburn 2009: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
1.129 raeburn 2010: my ($defdom,$runon,$runoff,$coownerson,$coownersoff);
1.3 raeburn 2011: if (ref($settings) eq 'HASH') {
2012: if (exists($settings->{'run'})) {
2013: if ($settings->{'run'} eq '0') {
2014: $runoff = ' checked="checked" ';
2015: $runon = ' ';
2016: } else {
2017: $runon = ' checked="checked" ';
2018: $runoff = ' ';
2019: }
2020: } else {
2021: if ($autorun) {
2022: $runon = ' checked="checked" ';
2023: $runoff = ' ';
2024: } else {
2025: $runoff = ' checked="checked" ';
2026: $runon = ' ';
2027: }
2028: }
1.129 raeburn 2029: if (exists($settings->{'co-owners'})) {
2030: if ($settings->{'co-owners'} eq '0') {
2031: $coownersoff = ' checked="checked" ';
2032: $coownerson = ' ';
2033: } else {
2034: $coownerson = ' checked="checked" ';
2035: $coownersoff = ' ';
2036: }
2037: } else {
2038: $coownersoff = ' checked="checked" ';
2039: $coownerson = ' ';
2040: }
1.3 raeburn 2041: if (exists($settings->{'sender_domain'})) {
2042: $defdom = $settings->{'sender_domain'};
2043: }
1.14 raeburn 2044: } else {
2045: if ($autorun) {
2046: $runon = ' checked="checked" ';
2047: $runoff = ' ';
2048: } else {
2049: $runoff = ' checked="checked" ';
2050: $runon = ' ';
2051: }
1.3 raeburn 2052: }
2053: my $domform = &Apache::loncommon::select_dom_form($defdom,'sender_domain',1);
1.39 raeburn 2054: my $notif_sender;
2055: if (ref($settings) eq 'HASH') {
2056: $notif_sender = $settings->{'sender_uname'};
2057: }
1.3 raeburn 2058: my $datatable='<tr class="LC_odd_row">'.
2059: '<td>'.&mt('Auto-enrollment active?').'</td>'.
1.8 raeburn 2060: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 2061: '<input type="radio" name="autoenroll_run"'.
1.8 raeburn 2062: $runon.' value="1" />'.&mt('Yes').'</label> '.
2063: '<label><input type="radio" name="autoenroll_run"'.
1.14 raeburn 2064: $runoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 2065: '</tr><tr>'.
2066: '<td>'.&mt('Notification messages - sender').
1.8 raeburn 2067: '</td><td class="LC_right_item"><span class="LC_nobreak">'.
1.3 raeburn 2068: &mt('username').': '.
2069: '<input type="text" name="sender_uname" value="'.
1.39 raeburn 2070: $notif_sender.'" size="10" /> '.&mt('domain').
1.129 raeburn 2071: ': '.$domform.'</span></td></tr>'.
2072: '<tr class="LC_odd_row">'.
2073: '<td>'.&mt('Automatically assign co-ownership').'</td>'.
2074: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2075: '<input type="radio" name="autoassign_coowners"'.
2076: $coownerson.' value="1" />'.&mt('Yes').'</label> '.
2077: '<label><input type="radio" name="autoassign_coowners"'.
2078: $coownersoff.' value="0" />'.&mt('No').'</label></span></td>'.
2079: '</tr>';
2080: $$rowtotal += 3;
1.3 raeburn 2081: return $datatable;
2082: }
2083:
2084: sub print_autoupdate {
1.30 raeburn 2085: my ($position,$dom,$settings,$rowtotal) = @_;
1.3 raeburn 2086: my $datatable;
2087: if ($position eq 'top') {
2088: my $updateon = ' ';
2089: my $updateoff = ' checked="checked" ';
2090: my $classlistson = ' ';
2091: my $classlistsoff = ' checked="checked" ';
2092: if (ref($settings) eq 'HASH') {
2093: if ($settings->{'run'} eq '1') {
2094: $updateon = $updateoff;
2095: $updateoff = ' ';
2096: }
2097: if ($settings->{'classlists'} eq '1') {
2098: $classlistson = $classlistsoff;
2099: $classlistsoff = ' ';
2100: }
2101: }
2102: my %title = (
2103: run => 'Auto-update active?',
2104: classlists => 'Update information in classlists?',
2105: );
2106: $datatable = '<tr class="LC_odd_row">'.
2107: '<td>'.&mt($title{'run'}).'</td>'.
1.8 raeburn 2108: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 2109: '<input type="radio" name="autoupdate_run"'.
1.8 raeburn 2110: $updateon.' value="1" />'.&mt('Yes').'</label> '.
2111: '<label><input type="radio" name="autoupdate_run"'.
2112: $updateoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 2113: '</tr><tr>'.
2114: '<td>'.&mt($title{'classlists'}).'</td>'.
1.8 raeburn 2115: '<td class="LC_right_item"><span class="LC_nobreak">'.
2116: '<label><input type="radio" name="classlists"'.
2117: $classlistson.' value="1" />'.&mt('Yes').'</label> '.
2118: '<label><input type="radio" name="classlists"'.
2119: $classlistsoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 2120: '</tr>';
1.30 raeburn 2121: $$rowtotal += 2;
1.131 raeburn 2122: } elsif ($position eq 'middle') {
2123: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
2124: my $numinrow = 3;
2125: my $locknamesettings;
2126: $datatable .= &insttypes_row($settings,$types,$usertypes,
2127: $dom,$numinrow,$othertitle,
2128: 'lockablenames');
2129: $$rowtotal ++;
1.3 raeburn 2130: } else {
1.44 raeburn 2131: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.132 raeburn 2132: my @fields = ('lastname','firstname','middlename','generation',
1.20 raeburn 2133: 'permanentemail','id');
1.33 raeburn 2134: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1.3 raeburn 2135: my $numrows = 0;
1.26 raeburn 2136: if (ref($types) eq 'ARRAY') {
2137: if (@{$types} > 0) {
2138: $datatable =
2139: &usertype_update_row($settings,$usertypes,\%fieldtitles,
2140: \@fields,$types,\$numrows);
1.30 raeburn 2141: $$rowtotal += @{$types};
1.26 raeburn 2142: }
1.3 raeburn 2143: }
2144: $datatable .=
2145: &usertype_update_row($settings,{'default' => $othertitle},
2146: \%fieldtitles,\@fields,['default'],
2147: \$numrows);
1.30 raeburn 2148: $$rowtotal ++;
1.3 raeburn 2149: }
2150: return $datatable;
2151: }
2152:
1.125 raeburn 2153: sub print_autocreate {
2154: my ($dom,$settings,$rowtotal) = @_;
1.191 raeburn 2155: my (%createon,%createoff,%currhash);
1.125 raeburn 2156: my @types = ('xml','req');
2157: if (ref($settings) eq 'HASH') {
2158: foreach my $item (@types) {
2159: $createoff{$item} = ' checked="checked" ';
2160: $createon{$item} = ' ';
2161: if (exists($settings->{$item})) {
2162: if ($settings->{$item}) {
2163: $createon{$item} = ' checked="checked" ';
2164: $createoff{$item} = ' ';
2165: }
2166: }
2167: }
1.191 raeburn 2168: if ($settings->{'xmldc'} ne '') {
2169: $currhash{$settings->{'xmldc'}} = 1;
2170: }
1.125 raeburn 2171: } else {
2172: foreach my $item (@types) {
2173: $createoff{$item} = ' checked="checked" ';
2174: $createon{$item} = ' ';
2175: }
2176: }
2177: $$rowtotal += 2;
1.191 raeburn 2178: my $numinrow = 2;
1.125 raeburn 2179: my $datatable='<tr class="LC_odd_row">'.
2180: '<td>'.&mt('Create pending official courses from XML files').'</td>'.
2181: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2182: '<input type="radio" name="autocreate_xml"'.
2183: $createon{'xml'}.' value="1" />'.&mt('Yes').'</label> '.
2184: '<label><input type="radio" name="autocreate_xml"'.
1.143 raeburn 2185: $createoff{'xml'}.' value="0" />'.&mt('No').'</label></span>'.
2186: '</td></tr><tr>'.
2187: '<td>'.&mt('Create pending requests for official courses (if validated)').'</td>'.
2188: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2189: '<input type="radio" name="autocreate_req"'.
2190: $createon{'req'}.' value="1" />'.&mt('Yes').'</label> '.
2191: '<label><input type="radio" name="autocreate_req"'.
2192: $createoff{'req'}.' value="0" />'.&mt('No').'</label></span>';
1.191 raeburn 2193: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
2194: 'autocreate_xmldc',%currhash);
1.125 raeburn 2195: if ($numdc > 1) {
1.143 raeburn 2196: $datatable .= '</td></tr><tr class="LC_odd_row"><td>'.
2197: &mt('Course creation processed as: (choose Dom. Coord.)').
2198: '</td><td class="LC_left_item">'.$dctable.'</td></tr>';
1.125 raeburn 2199: } else {
1.143 raeburn 2200: $datatable .= $dctable.'</td></tr>';
1.125 raeburn 2201: }
1.191 raeburn 2202: $$rowtotal += $rows;
1.125 raeburn 2203: return $datatable;
2204: }
2205:
1.23 raeburn 2206: sub print_directorysrch {
1.30 raeburn 2207: my ($dom,$settings,$rowtotal) = @_;
1.23 raeburn 2208: my $srchon = ' ';
2209: my $srchoff = ' checked="checked" ';
1.25 raeburn 2210: my ($exacton,$containson,$beginson);
1.24 raeburn 2211: my $localon = ' ';
2212: my $localoff = ' checked="checked" ';
1.23 raeburn 2213: if (ref($settings) eq 'HASH') {
2214: if ($settings->{'available'} eq '1') {
2215: $srchon = $srchoff;
2216: $srchoff = ' ';
2217: }
1.24 raeburn 2218: if ($settings->{'localonly'} eq '1') {
2219: $localon = $localoff;
2220: $localoff = ' ';
2221: }
1.25 raeburn 2222: if (ref($settings->{'searchtypes'}) eq 'ARRAY') {
2223: foreach my $type (@{$settings->{'searchtypes'}}) {
2224: if ($type eq 'exact') {
2225: $exacton = ' checked="checked" ';
2226: } elsif ($type eq 'contains') {
2227: $containson = ' checked="checked" ';
2228: } elsif ($type eq 'begins') {
2229: $beginson = ' checked="checked" ';
2230: }
2231: }
2232: } else {
2233: if ($settings->{'searchtypes'} eq 'exact') {
2234: $exacton = ' checked="checked" ';
2235: } elsif ($settings->{'searchtypes'} eq 'contains') {
2236: $containson = ' checked="checked" ';
2237: } elsif ($settings->{'searchtypes'} eq 'specify') {
2238: $exacton = ' checked="checked" ';
2239: $containson = ' checked="checked" ';
2240: }
1.23 raeburn 2241: }
2242: }
2243: my ($searchtitles,$titleorder) = &sorted_searchtitles();
1.45 raeburn 2244: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.23 raeburn 2245:
2246: my $numinrow = 4;
1.26 raeburn 2247: my $cansrchrow = 0;
1.23 raeburn 2248: my $datatable='<tr class="LC_odd_row">'.
1.30 raeburn 2249: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Directory search available?').'</span></td>'.
1.23 raeburn 2250: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2251: '<input type="radio" name="dirsrch_available"'.
2252: $srchon.' value="1" />'.&mt('Yes').'</label> '.
2253: '<label><input type="radio" name="dirsrch_available"'.
2254: $srchoff.' value="0" />'.&mt('No').'</label></span></td>'.
2255: '</tr><tr>'.
1.30 raeburn 2256: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search?').'</span></td>'.
1.24 raeburn 2257: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2258: '<input type="radio" name="dirsrch_localonly"'.
2259: $localoff.' value="0" />'.&mt('Yes').'</label> '.
2260: '<label><input type="radio" name="dirsrch_localonly"'.
2261: $localon.' value="1" />'.&mt('No').'</label></span></td>'.
1.25 raeburn 2262: '</tr>';
1.30 raeburn 2263: $$rowtotal += 2;
1.26 raeburn 2264: if (ref($usertypes) eq 'HASH') {
2265: if (keys(%{$usertypes}) > 0) {
1.93 raeburn 2266: $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
2267: $numinrow,$othertitle,'cansearch');
1.26 raeburn 2268: $cansrchrow = 1;
2269: }
2270: }
2271: if ($cansrchrow) {
1.30 raeburn 2272: $$rowtotal ++;
1.26 raeburn 2273: $datatable .= '<tr>';
2274: } else {
2275: $datatable .= '<tr class="LC_odd_row">';
2276: }
1.30 raeburn 2277: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Supported search methods').
2278: '</span></td><td class="LC_left_item" colspan="2"><table><tr>';
1.25 raeburn 2279: foreach my $title (@{$titleorder}) {
2280: if (defined($searchtitles->{$title})) {
2281: my $check = ' ';
1.93 raeburn 2282: if (ref($settings) eq 'HASH') {
1.39 raeburn 2283: if (ref($settings->{'searchby'}) eq 'ARRAY') {
2284: if (grep(/^\Q$title\E$/,@{$settings->{'searchby'}})) {
2285: $check = ' checked="checked" ';
2286: }
1.25 raeburn 2287: }
2288: }
2289: $datatable .= '<td class="LC_left_item">'.
2290: '<span class="LC_nobreak"><label>'.
2291: '<input type="checkbox" name="searchby" '.
2292: 'value="'.$title.'"'.$check.'/>'.
2293: $searchtitles->{$title}.'</label></span></td>';
2294: }
2295: }
1.26 raeburn 2296: $datatable .= '</tr></table></td></tr>';
1.30 raeburn 2297: $$rowtotal ++;
1.26 raeburn 2298: if ($cansrchrow) {
2299: $datatable .= '<tr class="LC_odd_row">';
2300: } else {
2301: $datatable .= '<tr>';
2302: }
1.30 raeburn 2303: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Search latitude').'</span></td>'.
1.26 raeburn 2304: '<td class="LC_left_item" colspan="2">'.
1.25 raeburn 2305: '<span class="LC_nobreak"><label>'.
2306: '<input type="checkbox" name="searchtypes" '.
2307: $exacton.' value="exact" />'.&mt('Exact match').
2308: '</label> '.
2309: '<label><input type="checkbox" name="searchtypes" '.
2310: $beginson.' value="begins" />'.&mt('Begins with').
2311: '</label> '.
2312: '<label><input type="checkbox" name="searchtypes" '.
2313: $containson.' value="contains" />'.&mt('Contains').
2314: '</label></span></td></tr>';
1.30 raeburn 2315: $$rowtotal ++;
1.25 raeburn 2316: return $datatable;
2317: }
2318:
1.28 raeburn 2319: sub print_contacts {
1.30 raeburn 2320: my ($dom,$settings,$rowtotal) = @_;
1.28 raeburn 2321: my $datatable;
2322: my @contacts = ('adminemail','supportemail');
1.134 raeburn 2323: my (%checked,%to,%otheremails,%bccemails);
1.102 raeburn 2324: my @mailings = ('errormail','packagesmail','lonstatusmail','helpdeskmail',
1.190 raeburn 2325: 'requestsmail','updatesmail');
1.28 raeburn 2326: foreach my $type (@mailings) {
2327: $otheremails{$type} = '';
2328: }
1.134 raeburn 2329: $bccemails{'helpdeskmail'} = '';
1.28 raeburn 2330: if (ref($settings) eq 'HASH') {
2331: foreach my $item (@contacts) {
2332: if (exists($settings->{$item})) {
2333: $to{$item} = $settings->{$item};
2334: }
2335: }
2336: foreach my $type (@mailings) {
2337: if (exists($settings->{$type})) {
2338: if (ref($settings->{$type}) eq 'HASH') {
2339: foreach my $item (@contacts) {
2340: if ($settings->{$type}{$item}) {
2341: $checked{$type}{$item} = ' checked="checked" ';
2342: }
2343: }
2344: $otheremails{$type} = $settings->{$type}{'others'};
1.134 raeburn 2345: if ($type eq 'helpdeskmail') {
2346: $bccemails{$type} = $settings->{$type}{'bcc'};
2347: }
1.28 raeburn 2348: }
1.89 raeburn 2349: } elsif ($type eq 'lonstatusmail') {
2350: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
1.28 raeburn 2351: }
2352: }
2353: } else {
2354: $to{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
2355: $to{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
2356: $checked{'errormail'}{'adminemail'} = ' checked="checked" ';
2357: $checked{'packagesmail'}{'adminemail'} = ' checked="checked" ';
1.89 raeburn 2358: $checked{'helpdeskmail'}{'supportemail'} = ' checked="checked" ';
2359: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
1.102 raeburn 2360: $checked{'requestsmail'}{'adminemail'} = ' checked="checked" ';
1.190 raeburn 2361: $checked{'updatesmail'}{'adminemail'} = ' checked="checked" ';
1.28 raeburn 2362: }
2363: my ($titles,$short_titles) = &contact_titles();
2364: my $rownum = 0;
2365: my $css_class;
2366: foreach my $item (@contacts) {
1.69 raeburn 2367: $rownum ++;
2368: $css_class = $rownum%2?' class="LC_odd_row"':'';
1.30 raeburn 2369: $datatable .= '<tr'.$css_class.'>'.
2370: '<td><span class="LC_nobreak">'.$titles->{$item}.
2371: '</span></td><td class="LC_right_item">'.
1.28 raeburn 2372: '<input type="text" name="'.$item.'" value="'.
2373: $to{$item}.'" /></td></tr>';
2374: }
2375: foreach my $type (@mailings) {
1.69 raeburn 2376: $rownum ++;
2377: $css_class = $rownum%2?' class="LC_odd_row"':'';
1.28 raeburn 2378: $datatable .= '<tr'.$css_class.'>'.
1.30 raeburn 2379: '<td><span class="LC_nobreak">'.
2380: $titles->{$type}.': </span></td>'.
1.28 raeburn 2381: '<td class="LC_left_item">'.
2382: '<span class="LC_nobreak">';
2383: foreach my $item (@contacts) {
2384: $datatable .= '<label>'.
2385: '<input type="checkbox" name="'.$type.'"'.
2386: $checked{$type}{$item}.
2387: ' value="'.$item.'" />'.$short_titles->{$item}.
2388: '</label> ';
2389: }
2390: $datatable .= '</span><br />'.&mt('Others').': '.
2391: '<input type="text" name="'.$type.'_others" '.
1.134 raeburn 2392: 'value="'.$otheremails{$type}.'" />';
2393: if ($type eq 'helpdeskmail') {
1.136 raeburn 2394: $datatable .= '<br />'.&mt('Bcc:').(' 'x6).
1.134 raeburn 2395: '<input type="text" name="'.$type.'_bcc" '.
2396: 'value="'.$bccemails{$type}.'" />';
2397: }
2398: $datatable .= '</td></tr>'."\n";
1.28 raeburn 2399: }
1.30 raeburn 2400: $$rowtotal += $rownum;
1.28 raeburn 2401: return $datatable;
2402: }
2403:
1.118 jms 2404: sub print_helpsettings {
1.168 raeburn 2405: my ($dom,$confname,$settings,$rowtotal) = @_;
2406: my ($datatable,$itemcount);
1.166 raeburn 2407: $itemcount = 1;
1.168 raeburn 2408: my (%choices,%defaultchecked,@toggles);
2409: $choices{'submitbugs'} = &mt('Display link to: [_1]?',
2410: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
2411: &mt('LON-CAPA bug tracker'),600,500));
2412: %defaultchecked = ('submitbugs' => 'on');
2413: @toggles = ('submitbugs',);
1.166 raeburn 2414:
1.168 raeburn 2415: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
2416: \%choices,$itemcount);
1.166 raeburn 2417: return $datatable;
1.121 raeburn 2418: }
2419:
2420: sub radiobutton_prefs {
1.192 raeburn 2421: my ($settings,$toggles,$defaultchecked,$choices,$itemcount,$onclick,
2422: $additional) = @_;
1.121 raeburn 2423: return unless ((ref($toggles) eq 'ARRAY') && (ref($defaultchecked) eq 'HASH') &&
2424: (ref($choices) eq 'HASH'));
2425:
1.170 raeburn 2426: my (%checkedon,%checkedoff,$datatable,$css_class);
1.121 raeburn 2427:
2428: foreach my $item (@{$toggles}) {
2429: if ($defaultchecked->{$item} eq 'on') {
1.118 jms 2430: $checkedon{$item} = ' checked="checked" ';
2431: $checkedoff{$item} = ' ';
1.121 raeburn 2432: } elsif ($defaultchecked->{$item} eq 'off') {
1.118 jms 2433: $checkedoff{$item} = ' checked="checked" ';
2434: $checkedon{$item} = ' ';
2435: }
2436: }
2437: if (ref($settings) eq 'HASH') {
1.121 raeburn 2438: foreach my $item (@{$toggles}) {
1.118 jms 2439: if ($settings->{$item} eq '1') {
2440: $checkedon{$item} = ' checked="checked" ';
2441: $checkedoff{$item} = ' ';
2442: } elsif ($settings->{$item} eq '0') {
2443: $checkedoff{$item} = ' checked="checked" ';
2444: $checkedon{$item} = ' ';
2445: }
2446: }
1.121 raeburn 2447: }
1.192 raeburn 2448: if ($onclick) {
2449: $onclick = ' onclick="'.$onclick.'"';
2450: }
1.121 raeburn 2451: foreach my $item (@{$toggles}) {
1.118 jms 2452: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.121 raeburn 2453: $datatable .=
1.192 raeburn 2454: '<tr'.$css_class.'><td valign="top">'.
2455: '<span class="LC_nobreak">'.$choices->{$item}.
1.118 jms 2456: '</span></td>'.
2457: '<td class="LC_right_item"><span class="LC_nobreak">'.
2458: '<label><input type="radio" name="'.
1.192 raeburn 2459: $item.'" '.$checkedon{$item}.' value="1"'.$onclick.' />'.&mt('Yes').
1.118 jms 2460: '</label> <label><input type="radio" name="'.$item.'" '.
1.192 raeburn 2461: $checkedoff{$item}.' value="0"'.$onclick.' />'.&mt('No').'</label>'.
2462: '</span>'.$additional.
2463: '</td>'.
1.118 jms 2464: '</tr>';
2465: $itemcount ++;
1.121 raeburn 2466: }
2467: return ($datatable,$itemcount);
2468: }
2469:
2470: sub print_coursedefaults {
1.139 raeburn 2471: my ($position,$dom,$settings,$rowtotal) = @_;
1.192 raeburn 2472: my ($css_class,$datatable,%checkedon,%checkedoff,%defaultchecked,@toggles);
1.121 raeburn 2473: my $itemcount = 1;
1.192 raeburn 2474: my %choices = &Apache::lonlocal::texthash (
2475: canuse_pdfforms => 'Course/Community users can create/upload PDF forms',
1.198 raeburn 2476: uploadquota => 'Default quota for files uploaded directly to course/community using Course Editor (MB)',
1.192 raeburn 2477: anonsurvey_threshold => 'Responder count needed before showing submissions for anonymous surveys',
2478: coursecredits => 'Credits can be specified for courses',
2479: );
1.198 raeburn 2480: my %staticdefaults = (
2481: anonsurvey_threshold => 10,
2482: uploadquota => 500,
2483: );
1.139 raeburn 2484: if ($position eq 'top') {
2485: %defaultchecked = ('canuse_pdfforms' => 'off');
1.192 raeburn 2486: @toggles = ('canuse_pdfforms');
1.139 raeburn 2487: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
1.121 raeburn 2488: \%choices,$itemcount);
1.139 raeburn 2489: } else {
2490: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.198 raeburn 2491: my ($currdefresponder,$def_official_credits,$def_unofficial_credits,%curruploadquota);
1.192 raeburn 2492: my $currusecredits = 0;
1.198 raeburn 2493: my @types = ('official','unofficial','community');
1.139 raeburn 2494: if (ref($settings) eq 'HASH') {
2495: $currdefresponder = $settings->{'anonsurvey_threshold'};
1.198 raeburn 2496: if (ref($settings->{'uploadquota'}) eq 'HASH') {
2497: foreach my $type (keys(%{$settings->{'uploadquota'}})) {
2498: $curruploadquota{$type} = $settings->{'uploadquota'}{$type};
2499: }
2500: }
1.192 raeburn 2501: if (ref($settings->{'coursecredits'}) eq 'HASH') {
2502: $def_official_credits = $settings->{'coursecredits'}->{'official'};
2503: $def_unofficial_credits = $settings->{'coursecredits'}->{'unofficial'};
2504: if (($def_official_credits ne '') || ($def_unofficial_credits ne '')) {
2505: $currusecredits = 1;
2506: }
2507: }
1.139 raeburn 2508: }
2509: if (!$currdefresponder) {
1.198 raeburn 2510: $currdefresponder = $staticdefaults{'anonsurvey_threshold'};
1.139 raeburn 2511: } elsif ($currdefresponder < 1) {
2512: $currdefresponder = 1;
2513: }
1.198 raeburn 2514: foreach my $type (@types) {
2515: if ($curruploadquota{$type} eq '') {
2516: $curruploadquota{$type} = $staticdefaults{'uploadquota'};
2517: }
2518: }
1.139 raeburn 2519: $datatable .=
1.192 raeburn 2520: '<tr'.$css_class.'><td><span class="LC_nobreak">'.
2521: $choices{'anonsurvey_threshold'}.
1.139 raeburn 2522: '</span></td>'.
2523: '<td class="LC_right_item"><span class="LC_nobreak">'.
2524: '<input type="text" name="anonsurvey_threshold"'.
2525: ' value="'.$currdefresponder.'" size="5" /></span>'.
1.198 raeburn 2526: '</td></tr>'."\n".
2527: '<tr><td><span class="LC_nobreak">'.
2528: $choices{'uploadquota'}.
2529: '</span></td>'.
2530: '<td align="right" class="LC_right_item">'.
2531: '<table><tr>';
2532: foreach my $type (@types) {
2533: $datatable .= '<td align="center">'.&mt($type).'<br />'.
2534: '<input type="text" name="uploadquota_'.$type.'"'.
2535: ' value="'.$curruploadquota{$type}.'" size="5" /></td>';
2536: }
2537: $datatable .= '</tr></table></td></tr>'."\n";
2538: $itemcount += 2;
1.192 raeburn 2539: my $onclick = 'toggleCredits(this.form);';
2540: my $display = 'none';
2541: if ($currusecredits) {
2542: $display = 'block';
2543: }
2544: my $additional = '<div id="credits" style="display: '.$display.'">'.
2545: '<span class="LC_nobreak">'.
2546: &mt('Default credits for official courses [_1]',
2547: '<input type="text" name="official_credits" value="'.
2548: $def_official_credits.'" size="3" />').
2549: '</span><br />'.
2550: '<span class="LC_nobreak">'.
2551: &mt('Default credits for unofficial courses [_1]',
2552: '<input type="text" name="unofficial_credits" value="'.
2553: $def_unofficial_credits.'" size="3" />').
2554: '</span></div>'."\n";
2555: %defaultchecked = ('coursecredits' => 'off');
2556: @toggles = ('coursecredits');
2557: my $current = {
2558: 'coursecredits' => $currusecredits,
2559: };
2560: (my $table,$itemcount) =
2561: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
2562: \%choices,$itemcount,$onclick,$additional);
2563: $datatable .= $table;
1.139 raeburn 2564: }
1.192 raeburn 2565: $$rowtotal += $itemcount;
1.121 raeburn 2566: return $datatable;
1.118 jms 2567: }
2568:
1.137 raeburn 2569: sub print_usersessions {
2570: my ($position,$dom,$settings,$rowtotal) = @_;
2571: my ($css_class,$datatable,%checked,%choices);
1.140 raeburn 2572: my (%by_ip,%by_location,@intdoms);
2573: &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
1.145 raeburn 2574:
2575: my @alldoms = &Apache::lonnet::all_domains();
1.152 raeburn 2576: my %serverhomes = %Apache::lonnet::serverhomeIDs;
1.149 raeburn 2577: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.152 raeburn 2578: my %altids = &id_for_thisdom(%servers);
1.145 raeburn 2579: my $itemcount = 1;
2580: if ($position eq 'top') {
1.152 raeburn 2581: if (keys(%serverhomes) > 1) {
1.145 raeburn 2582: my %spareid = ¤t_offloads_to($dom,$settings,\%servers);
1.152 raeburn 2583: $datatable .= &spares_row($dom,\%servers,\%spareid,\%serverhomes,\%altids,$rowtotal);
1.145 raeburn 2584: } else {
1.140 raeburn 2585: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.150 raeburn 2586: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one server.');
1.140 raeburn 2587: }
1.137 raeburn 2588: } else {
1.145 raeburn 2589: if (keys(%by_location) == 0) {
2590: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.150 raeburn 2591: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one institution.');
1.145 raeburn 2592: } else {
2593: my %lt = &usersession_titles();
2594: my $numinrow = 5;
2595: my $prefix;
2596: my @types;
2597: if ($position eq 'bottom') {
2598: $prefix = 'remote';
2599: @types = ('version','excludedomain','includedomain');
2600: } else {
2601: $prefix = 'hosted';
2602: @types = ('excludedomain','includedomain');
2603: }
2604: my (%current,%checkedon,%checkedoff);
2605: my @lcversions = &Apache::lonnet::all_loncaparevs();
2606: my @locations = sort(keys(%by_location));
2607: foreach my $type (@types) {
2608: $checkedon{$type} = '';
2609: $checkedoff{$type} = ' checked="checked"';
2610: }
2611: if (ref($settings) eq 'HASH') {
2612: if (ref($settings->{$prefix}) eq 'HASH') {
2613: foreach my $key (keys(%{$settings->{$prefix}})) {
2614: $current{$key} = $settings->{$prefix}{$key};
2615: if ($key eq 'version') {
2616: if ($current{$key} ne '') {
2617: $checkedon{$key} = ' checked="checked"';
2618: $checkedoff{$key} = '';
2619: }
2620: } elsif (ref($current{$key}) eq 'ARRAY') {
2621: $checkedon{$key} = ' checked="checked"';
2622: $checkedoff{$key} = '';
2623: }
1.137 raeburn 2624: }
2625: }
2626: }
1.145 raeburn 2627: foreach my $type (@types) {
2628: next if ($type ne 'version' && !@locations);
2629: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
2630: $datatable .= '<tr'.$css_class.'>
2631: <td><span class="LC_nobreak">'.$lt{$type}.'</span><br />
2632: <span class="LC_nobreak">
2633: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedoff{$type}.' value="0" />'.&mt('Not in use').'</label>
2634: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedon{$type}.' value="1" />'.&mt('In use').'</label></span></td><td>';
2635: if ($type eq 'version') {
2636: my $selector = '<select name="'.$prefix.'_version">';
2637: foreach my $version (@lcversions) {
2638: my $selected = '';
2639: if ($current{'version'} eq $version) {
2640: $selected = ' selected="selected"';
2641: }
2642: $selector .= ' <option value="'.$version.'"'.
2643: $selected.'>'.$version.'</option>';
2644: }
2645: $selector .= '</select> ';
2646: $datatable .= &mt('remote server must be version: [_1] or later',$selector);
2647: } else {
2648: $datatable.= '<div><input type="button" value="'.&mt('check all').'" '.
2649: 'onclick="javascript:checkAll(document.display.'.$prefix.'_'.$type.')"'.
2650: ' />'.(' 'x2).
2651: '<input type="button" value="'.&mt('uncheck all').'" '.
2652: 'onclick="javascript:uncheckAll(document.display.'.$prefix.'_'.$type.')" />'.
2653: "\n".
2654: '</div><div><table>';
2655: my $rem;
2656: for (my $i=0; $i<@locations; $i++) {
2657: my ($showloc,$value,$checkedtype);
2658: if (ref($by_location{$locations[$i]}) eq 'ARRAY') {
2659: my $ip = $by_location{$locations[$i]}->[0];
2660: if (ref($by_ip{$ip}) eq 'ARRAY') {
2661: $value = join(':',@{$by_ip{$ip}});
2662: $showloc = join(', ',@{$by_ip{$ip}});
2663: if (ref($current{$type}) eq 'ARRAY') {
2664: foreach my $loc (@{$by_ip{$ip}}) {
2665: if (grep(/^\Q$loc\E$/,@{$current{$type}})) {
2666: $checkedtype = ' checked="checked"';
2667: last;
2668: }
2669: }
1.138 raeburn 2670: }
2671: }
2672: }
1.145 raeburn 2673: $rem = $i%($numinrow);
2674: if ($rem == 0) {
2675: if ($i > 0) {
2676: $datatable .= '</tr>';
2677: }
2678: $datatable .= '<tr>';
2679: }
2680: $datatable .= '<td class="LC_left_item">'.
2681: '<span class="LC_nobreak"><label>'.
2682: '<input type="checkbox" name="'.$prefix.'_'.$type.
2683: '" value="'.$value.'"'.$checkedtype.' />'.$showloc.
2684: '</label></span></td>';
1.137 raeburn 2685: }
1.145 raeburn 2686: $rem = @locations%($numinrow);
2687: my $colsleft = $numinrow - $rem;
2688: if ($colsleft > 1 ) {
2689: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
2690: ' </td>';
2691: } elsif ($colsleft == 1) {
2692: $datatable .= '<td class="LC_left_item"> </td>';
1.137 raeburn 2693: }
1.145 raeburn 2694: $datatable .= '</tr></table>';
1.137 raeburn 2695: }
1.145 raeburn 2696: $datatable .= '</td></tr>';
2697: $itemcount ++;
1.137 raeburn 2698: }
2699: }
2700: }
2701: $$rowtotal += $itemcount;
2702: return $datatable;
2703: }
2704:
1.138 raeburn 2705: sub build_location_hashes {
2706: my ($intdoms,$by_ip,$by_location) = @_;
2707: return unless((ref($intdoms) eq 'ARRAY') && (ref($by_ip) eq 'HASH') &&
2708: (ref($by_location) eq 'HASH'));
2709: my %iphost = &Apache::lonnet::get_iphost();
2710: my $primary_id = &Apache::lonnet::domain($env{'request.role.domain'},'primary');
2711: my $primary_ip = &Apache::lonnet::get_host_ip($primary_id);
2712: if (ref($iphost{$primary_ip}) eq 'ARRAY') {
2713: foreach my $id (@{$iphost{$primary_ip}}) {
2714: my $intdom = &Apache::lonnet::internet_dom($id);
2715: unless(grep(/^\Q$intdom\E$/,@{$intdoms})) {
2716: push(@{$intdoms},$intdom);
2717: }
2718: }
2719: }
2720: foreach my $ip (keys(%iphost)) {
2721: if (ref($iphost{$ip}) eq 'ARRAY') {
2722: foreach my $id (@{$iphost{$ip}}) {
2723: my $location = &Apache::lonnet::internet_dom($id);
2724: if ($location) {
2725: next if (grep(/^\Q$location\E$/,@{$intdoms}));
2726: if (ref($by_ip->{$ip}) eq 'ARRAY') {
2727: unless(grep(/^\Q$location\E$/,@{$by_ip->{$ip}})) {
2728: push(@{$by_ip->{$ip}},$location);
2729: }
2730: } else {
2731: $by_ip->{$ip} = [$location];
2732: }
2733: }
2734: }
2735: }
2736: }
2737: foreach my $ip (sort(keys(%{$by_ip}))) {
2738: if (ref($by_ip->{$ip}) eq 'ARRAY') {
2739: @{$by_ip->{$ip}} = sort(@{$by_ip->{$ip}});
2740: my $first = $by_ip->{$ip}->[0];
2741: if (ref($by_location->{$first}) eq 'ARRAY') {
2742: unless (grep(/^\Q$ip\E$/,@{$by_location->{$first}})) {
2743: push(@{$by_location->{$first}},$ip);
2744: }
2745: } else {
2746: $by_location->{$first} = [$ip];
2747: }
2748: }
2749: }
2750: return;
2751: }
2752:
1.145 raeburn 2753: sub current_offloads_to {
2754: my ($dom,$settings,$servers) = @_;
2755: my (%spareid,%otherdomconfigs);
1.152 raeburn 2756: if (ref($servers) eq 'HASH') {
1.145 raeburn 2757: foreach my $lonhost (sort(keys(%{$servers}))) {
2758: my $gotspares;
1.152 raeburn 2759: if (ref($settings) eq 'HASH') {
2760: if (ref($settings->{'spares'}) eq 'HASH') {
2761: if (ref($settings->{'spares'}{$lonhost}) eq 'HASH') {
2762: $spareid{$lonhost}{'primary'} = $settings->{'spares'}{$lonhost}{'primary'};
2763: $spareid{$lonhost}{'default'} = $settings->{'spares'}{$lonhost}{'default'};
2764: $gotspares = 1;
2765: }
1.145 raeburn 2766: }
2767: }
2768: unless ($gotspares) {
2769: my $gotspares;
2770: my $serverhomeID =
2771: &Apache::lonnet::get_server_homeID($servers->{$lonhost});
2772: my $serverhomedom =
2773: &Apache::lonnet::host_domain($serverhomeID);
2774: if ($serverhomedom ne $dom) {
2775: if (ref($otherdomconfigs{$serverhomedom} eq 'HASH')) {
2776: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
2777: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
2778: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
2779: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
2780: $gotspares = 1;
2781: }
2782: }
2783: } else {
2784: $otherdomconfigs{$serverhomedom} =
2785: &Apache::lonnet::get_dom('configuration',['usersessions'],$serverhomedom);
2786: if (ref($otherdomconfigs{$serverhomedom}) eq 'HASH') {
2787: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
2788: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
2789: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{$lonhost}) eq 'HASH') {
2790: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
2791: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
2792: $gotspares = 1;
2793: }
2794: }
2795: }
2796: }
2797: }
2798: }
2799: }
2800: unless ($gotspares) {
2801: if ($lonhost eq $Apache::lonnet::perlvar{'lonHostID'}) {
2802: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
2803: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
2804: } else {
2805: my $server_hostname = &Apache::lonnet::hostname($lonhost);
2806: my $server_homeID = &Apache::lonnet::get_server_homeID($server_hostname);
2807: if ($server_homeID eq $Apache::lonnet::perlvar{'lonHostID'}) {
2808: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
2809: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
2810: } else {
1.150 raeburn 2811: my %what = (
2812: spareid => 1,
2813: );
2814: my ($result,$returnhash) =
2815: &Apache::lonnet::get_remote_globals($lonhost,\%what);
2816: if ($result eq 'ok') {
2817: if (ref($returnhash) eq 'HASH') {
2818: if (ref($returnhash->{'spareid'}) eq 'HASH') {
2819: $spareid{$lonhost}{'primary'} = $returnhash->{'spareid'}->{'primary'};
2820: $spareid{$lonhost}{'default'} = $returnhash->{'spareid'}->{'default'};
2821: }
2822: }
1.145 raeburn 2823: }
2824: }
2825: }
2826: }
2827: }
2828: }
2829: return %spareid;
2830: }
2831:
2832: sub spares_row {
1.152 raeburn 2833: my ($dom,$servers,$spareid,$serverhomes,$altids,$rowtotal) = @_;
1.145 raeburn 2834: my $css_class;
2835: my $numinrow = 4;
2836: my $itemcount = 1;
2837: my $datatable;
1.152 raeburn 2838: my %typetitles = &sparestype_titles();
2839: if ((ref($servers) eq 'HASH') && (ref($spareid) eq 'HASH') && (ref($altids) eq 'HASH')) {
1.145 raeburn 2840: foreach my $server (sort(keys(%{$servers}))) {
1.152 raeburn 2841: my $serverhome = &Apache::lonnet::get_server_homeID($servers->{$server});
2842: my ($othercontrol,$serverdom);
2843: if ($serverhome ne $server) {
2844: $serverdom = &Apache::lonnet::host_domain($serverhome);
2845: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
2846: } else {
2847: $serverdom = &Apache::lonnet::host_domain($server);
2848: if ($serverdom ne $dom) {
2849: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
2850: }
2851: }
2852: next unless (ref($spareid->{$server}) eq 'HASH');
1.145 raeburn 2853: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
2854: $datatable .= '<tr'.$css_class.'>
2855: <td rowspan="2">
1.183 bisitz 2856: <span class="LC_nobreak">'.
2857: &mt('[_1] when busy, offloads to:'
2858: ,'<b>'.$server.'</b>').
2859: "\n";
1.145 raeburn 2860: my (%current,%canselect);
1.152 raeburn 2861: my @choices =
2862: &possible_newspares($server,$spareid->{$server},$serverhomes,$altids);
2863: foreach my $type ('primary','default') {
2864: if (ref($spareid->{$server}) eq 'HASH') {
1.145 raeburn 2865: if (ref($spareid->{$server}{$type}) eq 'ARRAY') {
2866: my @spares = @{$spareid->{$server}{$type}};
2867: if (@spares > 0) {
1.152 raeburn 2868: if ($othercontrol) {
2869: $current{$type} = join(', ',@spares);
2870: } else {
2871: $current{$type} .= '<table>';
2872: my $numspares = scalar(@spares);
2873: for (my $i=0; $i<@spares; $i++) {
2874: my $rem = $i%($numinrow);
2875: if ($rem == 0) {
2876: if ($i > 0) {
2877: $current{$type} .= '</tr>';
2878: }
2879: $current{$type} .= '<tr>';
1.145 raeburn 2880: }
1.152 raeburn 2881: $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'".');" /> '.
2882: $spareid->{$server}{$type}[$i].
2883: '</label></td>'."\n";
2884: }
2885: my $rem = @spares%($numinrow);
2886: my $colsleft = $numinrow - $rem;
2887: if ($colsleft > 1 ) {
2888: $current{$type} .= '<td colspan="'.$colsleft.
2889: '" class="LC_left_item">'.
2890: ' </td>';
2891: } elsif ($colsleft == 1) {
2892: $current{$type} .= '<td class="LC_left_item"> </td>'."\n";
1.145 raeburn 2893: }
1.152 raeburn 2894: $current{$type} .= '</tr></table>';
1.150 raeburn 2895: }
1.145 raeburn 2896: }
2897: }
2898: if ($current{$type} eq '') {
2899: $current{$type} = &mt('None specified');
2900: }
1.152 raeburn 2901: if ($othercontrol) {
2902: if ($type eq 'primary') {
2903: $canselect{$type} = $othercontrol;
2904: }
2905: } else {
2906: $canselect{$type} =
2907: &mt('Add new [_1]'.$type.'[_2]:','<i>','</i>').' '.
2908: '<select name="newspare_'.$type.'_'.$server.'" '.
2909: 'id="newspare_'.$type.'_'.$server.'" onchange="checkNewSpares('."'$server','$type'".');">'."\n".
2910: '<option value="" selected ="selected">'.&mt('Select').'</option>'."\n";
2911: if (@choices > 0) {
2912: foreach my $lonhost (@choices) {
2913: $canselect{$type} .= '<option value="'.$lonhost.'">'.$lonhost.'</option>'."\n";
2914: }
2915: }
2916: $canselect{$type} .= '</select>'."\n";
2917: }
2918: } else {
2919: $current{$type} = &mt('Could not be determined');
2920: if ($type eq 'primary') {
2921: $canselect{$type} = $othercontrol;
2922: }
1.145 raeburn 2923: }
1.152 raeburn 2924: if ($type eq 'default') {
2925: $datatable .= '<tr'.$css_class.'>';
2926: }
2927: $datatable .= '<td><i>'.$typetitles{$type}.'</i></td>'."\n".
2928: '<td>'.$current{$type}.'</td>'."\n".
2929: '<td>'.$canselect{$type}.'</td></tr>'."\n";
1.145 raeburn 2930: }
2931: $itemcount ++;
2932: }
2933: }
2934: $$rowtotal += $itemcount;
2935: return $datatable;
2936: }
2937:
1.152 raeburn 2938: sub possible_newspares {
2939: my ($server,$currspares,$serverhomes,$altids) = @_;
2940: my $serverhostname = &Apache::lonnet::hostname($server);
2941: my %excluded;
2942: if ($serverhostname ne '') {
2943: %excluded = (
2944: $serverhostname => 1,
2945: );
2946: }
2947: if (ref($currspares) eq 'HASH') {
2948: foreach my $type (keys(%{$currspares})) {
2949: if (ref($currspares->{$type}) eq 'ARRAY') {
2950: if (@{$currspares->{$type}} > 0) {
2951: foreach my $curr (@{$currspares->{$type}}) {
2952: my $hostname = &Apache::lonnet::hostname($curr);
2953: $excluded{$hostname} = 1;
2954: }
2955: }
2956: }
2957: }
2958: }
2959: my @choices;
2960: if ((ref($serverhomes) eq 'HASH') && (ref($altids) eq 'HASH')) {
2961: if (keys(%{$serverhomes}) > 1) {
2962: foreach my $name (sort(keys(%{$serverhomes}))) {
2963: unless ($excluded{$name}) {
2964: if (exists($altids->{$serverhomes->{$name}})) {
2965: push(@choices,$altids->{$serverhomes->{$name}});
2966: } else {
2967: push(@choices,$serverhomes->{$name});
1.145 raeburn 2968: }
2969: }
2970: }
2971: }
2972: }
1.152 raeburn 2973: return sort(@choices);
1.145 raeburn 2974: }
2975:
1.150 raeburn 2976: sub print_loadbalancing {
2977: my ($dom,$settings,$rowtotal) = @_;
2978: my $primary_id = &Apache::lonnet::domain($dom,'primary');
2979: my $intdom = &Apache::lonnet::internet_dom($primary_id);
2980: my $numinrow = 1;
2981: my $datatable;
2982: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.171 raeburn 2983: my (%currbalancer,%currtargets,%currrules,%existing);
2984: if (ref($settings) eq 'HASH') {
2985: %existing = %{$settings};
2986: }
2987: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
2988: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
2989: \%currtargets,\%currrules);
1.150 raeburn 2990: } else {
2991: return;
2992: }
2993: my ($othertitle,$usertypes,$types) =
2994: &Apache::loncommon::sorted_inst_types($dom);
2995: my $rownum = 6;
2996: if (ref($types) eq 'ARRAY') {
2997: $rownum += scalar(@{$types});
2998: }
1.171 raeburn 2999: my @css_class = ('LC_odd_row','LC_even_row');
3000: my $balnum = 0;
3001: my $islast;
3002: my (@toshow,$disabledtext);
3003: if (keys(%currbalancer) > 0) {
3004: @toshow = sort(keys(%currbalancer));
3005: if (scalar(@toshow) < scalar(keys(%servers)) + 1) {
3006: push(@toshow,'');
3007: }
3008: } else {
3009: @toshow = ('');
3010: $disabledtext = &mt('No existing load balancer');
3011: }
3012: foreach my $lonhost (@toshow) {
3013: if ($balnum == scalar(@toshow)-1) {
3014: $islast = 1;
3015: } else {
3016: $islast = 0;
3017: }
3018: my $cssidx = $balnum%2;
3019: my $targets_div_style = 'display: none';
3020: my $disabled_div_style = 'display: block';
3021: my $homedom_div_style = 'display: none';
3022: $datatable .= '<tr class="'.$css_class[$cssidx].'">'.
3023: '<td rowspan="'.$rownum.'" valign="top">'.
3024: '<p>';
3025: if ($lonhost eq '') {
3026: $datatable .= '<span class="LC_nobreak">';
3027: if (keys(%currbalancer) > 0) {
3028: $datatable .= &mt('Add balancer:');
3029: } else {
3030: $datatable .= &mt('Enable balancer:');
3031: }
3032: $datatable .= ' '.
3033: '<select name="loadbalancing_lonhost_'.$balnum.'"'.
3034: ' id="loadbalancing_lonhost_'.$balnum.'"'.
3035: ' onchange="toggleTargets('."'$balnum'".');">'."\n".
3036: '<option value="" selected="selected">'.&mt('None').
3037: '</option>'."\n";
3038: foreach my $server (sort(keys(%servers))) {
3039: next if ($currbalancer{$server});
3040: $datatable .= '<option value="'.$server.'">'.$server.'</option>'."\n";
3041: }
3042: $datatable .=
3043: '</select>'."\n".
3044: '<input type="hidden" name="loadbalancing_prevlonhost_'.$balnum.'" id="loadbalancing_prevlonhost_'.$balnum.'" value="" /> </span>'."\n";
3045: } else {
3046: $datatable .= '<i>'.$lonhost.'</i><br /><span class="LC_nobreak">'.
3047: '<label><input type="checkbox" name="loadbalancing_delete" value="'.$balnum.'" id="loadbalancing_delete_'.$balnum.'" onclick="javascript:balancerDeleteChange('."'$balnum'".');" /> '.
3048: &mt('Stop balancing').'</label>'.
3049: '<input type="hidden" name="loadbalancing_lonhost_'.$balnum.'" value="'.$lonhost.'" id="loadbalancing_lonhost_'.$balnum.'" /></span>';
3050: $targets_div_style = 'display: block';
3051: $disabled_div_style = 'display: none';
3052: if ($dom eq &Apache::lonnet::host_domain($lonhost)) {
3053: $homedom_div_style = 'display: block';
3054: }
3055: }
3056: $datatable .= '</p></td><td rowspan="'.$rownum.'" valign="top">'.
3057: '<div id="loadbalancing_disabled_'.$balnum.'" style="'.
3058: $disabled_div_style.'">'.$disabledtext.'</div>'."\n".
3059: '<div id="loadbalancing_targets_'.$balnum.'" style="'.$targets_div_style.'">'.&mt('Offloads to:').'<br />';
3060: my ($numspares,@spares) = &count_servers($lonhost,%servers);
3061: my @sparestypes = ('primary','default');
3062: my %typetitles = &sparestype_titles();
3063: foreach my $sparetype (@sparestypes) {
3064: my $targettable;
3065: for (my $i=0; $i<$numspares; $i++) {
3066: my $checked;
3067: if (ref($currtargets{$lonhost}) eq 'HASH') {
3068: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
3069: if (grep(/^\Q$spares[$i]\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
3070: $checked = ' checked="checked"';
3071: }
3072: }
3073: }
3074: my ($chkboxval,$disabled);
3075: if (($lonhost ne '') && (exists($servers{$lonhost}))) {
3076: $chkboxval = $spares[$i];
3077: }
3078: if (exists($currbalancer{$spares[$i]})) {
3079: $disabled = ' disabled="disabled"';
3080: }
3081: $targettable .=
3082: '<td><label><input type="checkbox" name="loadbalancing_target_'.$balnum.'_'.$sparetype.'"'.
3083: $checked.$disabled.' value="'.$chkboxval.'" id="loadbalancing_target_'.$balnum.'_'.$sparetype.'_'.$i.'" onclick="checkOffloads('."this,'$balnum','$sparetype'".');" /><span id="loadbalancing_targettxt_'.$balnum.'_'.$sparetype.'_'.$i.'"> '.$chkboxval.
3084: '</span></label></td>';
3085: my $rem = $i%($numinrow);
3086: if ($rem == 0) {
3087: if (($i > 0) && ($i < $numspares-1)) {
3088: $targettable .= '</tr>';
3089: }
3090: if ($i < $numspares-1) {
3091: $targettable .= '<tr>';
1.150 raeburn 3092: }
3093: }
3094: }
1.171 raeburn 3095: if ($targettable ne '') {
3096: my $rem = $numspares%($numinrow);
3097: my $colsleft = $numinrow - $rem;
3098: if ($colsleft > 1 ) {
3099: $targettable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
3100: ' </td>';
3101: } elsif ($colsleft == 1) {
3102: $targettable .= '<td class="LC_left_item"> </td>';
3103: }
3104: $datatable .= '<i>'.$typetitles{$sparetype}.'</i><br />'.
3105: '<table><tr>'.$targettable.'</tr></table><br />';
3106: }
3107: }
3108: $datatable .= '</div></td></tr>'.
3109: &loadbalancing_rules($dom,$intdom,$currrules{$lonhost},
3110: $othertitle,$usertypes,$types,\%servers,
3111: \%currbalancer,$lonhost,
3112: $targets_div_style,$homedom_div_style,
3113: $css_class[$cssidx],$balnum,$islast);
3114: $$rowtotal += $rownum;
3115: $balnum ++;
3116: }
3117: $datatable .= '<input type="hidden" name="loadbalancing_total" id="loadbalancing_total" value="'.$balnum.'" />';
3118: return $datatable;
3119: }
3120:
3121: sub get_loadbalancers_config {
3122: my ($servers,$existing,$currbalancer,$currtargets,$currrules) = @_;
3123: return unless ((ref($servers) eq 'HASH') &&
3124: (ref($existing) eq 'HASH') && (ref($currbalancer) eq 'HASH') &&
3125: (ref($currtargets) eq 'HASH') && (ref($currrules) eq 'HASH'));
3126: if (keys(%{$existing}) > 0) {
3127: my $oldlonhost;
3128: foreach my $key (sort(keys(%{$existing}))) {
3129: if ($key eq 'lonhost') {
3130: $oldlonhost = $existing->{'lonhost'};
3131: $currbalancer->{$oldlonhost} = 1;
3132: } elsif ($key eq 'targets') {
3133: if ($oldlonhost) {
3134: $currtargets->{$oldlonhost} = $existing->{'targets'};
3135: }
3136: } elsif ($key eq 'rules') {
3137: if ($oldlonhost) {
3138: $currrules->{$oldlonhost} = $existing->{'rules'};
3139: }
3140: } elsif (ref($existing->{$key}) eq 'HASH') {
3141: $currbalancer->{$key} = 1;
3142: $currtargets->{$key} = $existing->{$key}{'targets'};
3143: $currrules->{$key} = $existing->{$key}{'rules'};
1.150 raeburn 3144: }
3145: }
1.171 raeburn 3146: } else {
3147: my ($balancerref,$targetsref) =
3148: &Apache::lonnet::get_lonbalancer_config($servers);
3149: if ((ref($balancerref) eq 'HASH') && (ref($targetsref) eq 'HASH')) {
3150: foreach my $server (sort(keys(%{$balancerref}))) {
3151: $currbalancer->{$server} = 1;
3152: $currtargets->{$server} = $targetsref->{$server};
1.150 raeburn 3153: }
3154: }
3155: }
1.171 raeburn 3156: return;
1.150 raeburn 3157: }
3158:
3159: sub loadbalancing_rules {
3160: my ($dom,$intdom,$currrules,$othertitle,$usertypes,$types,$servers,
1.171 raeburn 3161: $currbalancer,$lonhost,$targets_div_style,$homedom_div_style,
3162: $css_class,$balnum,$islast) = @_;
1.150 raeburn 3163: my $output;
1.171 raeburn 3164: my $num = 0;
1.150 raeburn 3165: my ($alltypes,$othertypes,$titles) =
3166: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
3167: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
3168: foreach my $type (@{$alltypes}) {
1.171 raeburn 3169: $num ++;
1.150 raeburn 3170: my $current;
3171: if (ref($currrules) eq 'HASH') {
3172: $current = $currrules->{$type};
3173: }
3174: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.171 raeburn 3175: if ($dom ne &Apache::lonnet::host_domain($lonhost)) {
1.150 raeburn 3176: $current = '';
3177: }
3178: }
3179: $output .= &loadbalance_rule_row($type,$titles->{$type},$current,
1.171 raeburn 3180: $servers,$currbalancer,$lonhost,$dom,
3181: $targets_div_style,$homedom_div_style,
3182: $css_class,$balnum,$num,$islast);
1.150 raeburn 3183: }
3184: }
3185: return $output;
3186: }
3187:
3188: sub loadbalancing_titles {
3189: my ($dom,$intdom,$usertypes,$types) = @_;
3190: my %othertypes = (
3191: '_LC_adv' => &mt('Advanced users from [_1]',$dom),
3192: '_LC_author' => &mt('Users from [_1] with author role',$dom),
3193: '_LC_internetdom' => &mt('Users not from [_1], but from [_2]',$dom,$intdom),
3194: '_LC_external' => &mt('Users not from [_1]',$intdom),
3195: );
3196: my @alltypes = ('_LC_adv','_LC_author','_LC_internetdom','_LC_external');
3197: if (ref($types) eq 'ARRAY') {
3198: unshift(@alltypes,@{$types},'default');
3199: }
3200: my %titles;
3201: foreach my $type (@alltypes) {
3202: if ($type =~ /^_LC_/) {
3203: $titles{$type} = $othertypes{$type};
3204: } elsif ($type eq 'default') {
3205: $titles{$type} = &mt('All users from [_1]',$dom);
3206: if (ref($types) eq 'ARRAY') {
3207: if (@{$types} > 0) {
3208: $titles{$type} = &mt('Other users from [_1]',$dom);
3209: }
3210: }
3211: } elsif (ref($usertypes) eq 'HASH') {
3212: $titles{$type} = $usertypes->{$type};
3213: }
3214: }
3215: return (\@alltypes,\%othertypes,\%titles);
3216: }
3217:
3218: sub loadbalance_rule_row {
1.171 raeburn 3219: my ($type,$title,$current,$servers,$currbalancer,$lonhost,$dom,
3220: $targets_div_style,$homedom_div_style,$css_class,$balnum,$num,$islast) = @_;
1.150 raeburn 3221: my @rulenames = ('default','homeserver');
3222: my %ruletitles = &offloadtype_text();
3223: if ($type eq '_LC_external') {
3224: push(@rulenames,'externalbalancer');
3225: } else {
3226: push(@rulenames,'specific');
3227: }
1.161 raeburn 3228: push(@rulenames,'none');
1.150 raeburn 3229: my $style = $targets_div_style;
3230: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
3231: $style = $homedom_div_style;
3232: }
1.171 raeburn 3233: my $space;
3234: if ($islast && $num == 1) {
3235: $space = '<div display="inline-block"> </div>';
3236: }
1.150 raeburn 3237: my $output =
1.171 raeburn 3238: '<tr class="'.$css_class.'" id="balanceruletr_'.$balnum.'_'.$num.'"><td valign="top">'.$space.
3239: '<div id="balanceruletitle_'.$balnum.'_'.$type.'" style="'.$style.'">'.$title.'</div></td>'."\n".
3240: '<td valaign="top">'.$space.
3241: '<div id="balancerule_'.$balnum.'_'.$type.'" style="'.$style.'">'."\n";
1.150 raeburn 3242: for (my $i=0; $i<@rulenames; $i++) {
3243: my $rule = $rulenames[$i];
3244: my ($checked,$extra);
3245: if ($rulenames[$i] eq 'default') {
3246: $rule = '';
3247: }
3248: if ($rulenames[$i] eq 'specific') {
3249: if (ref($servers) eq 'HASH') {
3250: my $default;
3251: if (($current ne '') && (exists($servers->{$current}))) {
3252: $checked = ' checked="checked"';
3253: }
3254: unless ($checked) {
3255: $default = ' selected="selected"';
3256: }
1.171 raeburn 3257: $extra =
3258: ': <select name="loadbalancing_singleserver_'.$balnum.'_'.$type.
3259: '" id="loadbalancing_singleserver_'.$balnum.'_'.$type.
3260: '" onchange="singleServerToggle('."'$balnum','$type'".')">'."\n".
3261: '<option value=""'.$default.'></option>'."\n";
3262: foreach my $server (sort(keys(%{$servers}))) {
3263: if (ref($currbalancer) eq 'HASH') {
3264: next if (exists($currbalancer->{$server}));
3265: }
1.150 raeburn 3266: my $selected;
1.171 raeburn 3267: if ($server eq $current) {
1.150 raeburn 3268: $selected = ' selected="selected"';
3269: }
1.171 raeburn 3270: $extra .= '<option value="'.$server.'"'.$selected.'>'.$server.'</option>';
1.150 raeburn 3271: }
3272: $extra .= '</select>';
3273: }
3274: } elsif ($rule eq $current) {
3275: $checked = ' checked="checked"';
3276: }
3277: $output .= '<span class="LC_nobreak"><label>'.
1.171 raeburn 3278: '<input type="radio" name="loadbalancing_rules_'.$balnum.'_'.$type.
3279: '" id="loadbalancing_rules_'.$balnum.'_'.$type.'_'.$i.'" value="'.
3280: $rule.'" onclick="balanceruleChange('."this.form,'$balnum','$type'".
1.150 raeburn 3281: ')"'.$checked.' /> '.$ruletitles{$rulenames[$i]}.
3282: '</label>'.$extra.'</span><br />'."\n";
3283: }
3284: $output .= '</div></td></tr>'."\n";
3285: return $output;
3286: }
3287:
3288: sub offloadtype_text {
3289: my %ruletitles = &Apache::lonlocal::texthash (
3290: 'default' => 'Offloads to default destinations',
3291: 'homeserver' => "Offloads to user's home server",
3292: 'externalbalancer' => "Offloads to Load Balancer in user's domain",
3293: 'specific' => 'Offloads to specific server',
1.161 raeburn 3294: 'none' => 'No offload',
1.150 raeburn 3295: );
3296: return %ruletitles;
3297: }
3298:
3299: sub sparestype_titles {
3300: my %typestitles = &Apache::lonlocal::texthash (
3301: 'primary' => 'primary',
3302: 'default' => 'default',
3303: );
3304: return %typestitles;
3305: }
3306:
1.28 raeburn 3307: sub contact_titles {
3308: my %titles = &Apache::lonlocal::texthash (
3309: 'supportemail' => 'Support E-mail address',
1.69 raeburn 3310: 'adminemail' => 'Default Server Admin E-mail address',
1.28 raeburn 3311: 'errormail' => 'Error reports to be e-mailed to',
3312: 'packagesmail' => 'Package update alerts to be e-mailed to',
1.89 raeburn 3313: 'helpdeskmail' => 'Helpdesk requests to be e-mailed to',
3314: 'lonstatusmail' => 'E-mail from nightly status check (warnings/errors)',
1.102 raeburn 3315: 'requestsmail' => 'E-mail from course requests requiring approval',
1.190 raeburn 3316: 'updatesmail' => 'E-mail from nightly check of LON-CAPA module integrity/updates',
1.28 raeburn 3317: );
3318: my %short_titles = &Apache::lonlocal::texthash (
3319: adminemail => 'Admin E-mail address',
3320: supportemail => 'Support E-mail',
3321: );
3322: return (\%titles,\%short_titles);
3323: }
3324:
1.72 raeburn 3325: sub tool_titles {
3326: my %titles = &Apache::lonlocal::texthash (
1.162 raeburn 3327: aboutme => 'Personal web page',
1.86 raeburn 3328: blog => 'Blog',
1.162 raeburn 3329: webdav => 'WebDAV',
1.86 raeburn 3330: portfolio => 'Portfolio',
1.88 bisitz 3331: official => 'Official courses (with institutional codes)',
3332: unofficial => 'Unofficial courses',
1.98 raeburn 3333: community => 'Communities',
1.86 raeburn 3334: );
1.72 raeburn 3335: return %titles;
3336: }
3337:
1.101 raeburn 3338: sub courserequest_titles {
3339: my %titles = &Apache::lonlocal::texthash (
3340: official => 'Official',
3341: unofficial => 'Unofficial',
3342: community => 'Communities',
3343: norequest => 'Not allowed',
1.104 raeburn 3344: approval => 'Approval by Dom. Coord.',
1.101 raeburn 3345: validate => 'With validation',
3346: autolimit => 'Numerical limit',
1.103 raeburn 3347: unlimited => '(blank for unlimited)',
1.101 raeburn 3348: );
3349: return %titles;
3350: }
3351:
1.163 raeburn 3352: sub authorrequest_titles {
3353: my %titles = &Apache::lonlocal::texthash (
3354: norequest => 'Not allowed',
3355: approval => 'Approval by Dom. Coord.',
3356: automatic => 'Automatic approval',
3357: );
3358: return %titles;
3359: }
3360:
1.101 raeburn 3361: sub courserequest_conditions {
3362: my %conditions = &Apache::lonlocal::texthash (
1.104 raeburn 3363: approval => '(Processing of request subject to approval by Domain Coordinator).',
1.193 bisitz 3364: validate => '(Processing of request subject to institutional validation).',
1.101 raeburn 3365: );
3366: return %conditions;
3367: }
3368:
3369:
1.27 raeburn 3370: sub print_usercreation {
1.30 raeburn 3371: my ($position,$dom,$settings,$rowtotal) = @_;
1.27 raeburn 3372: my $numinrow = 4;
1.28 raeburn 3373: my $datatable;
3374: if ($position eq 'top') {
1.30 raeburn 3375: $$rowtotal ++;
1.34 raeburn 3376: my $rowcount = 0;
1.32 raeburn 3377: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username');
1.28 raeburn 3378: if (ref($rules) eq 'HASH') {
3379: if (keys(%{$rules}) > 0) {
1.32 raeburn 3380: $datatable .= &user_formats_row('username',$settings,$rules,
3381: $ruleorder,$numinrow,$rowcount);
1.30 raeburn 3382: $$rowtotal ++;
1.32 raeburn 3383: $rowcount ++;
3384: }
3385: }
3386: my ($idrules,$idruleorder) = &Apache::lonnet::inst_userrules($dom,'id');
3387: if (ref($idrules) eq 'HASH') {
3388: if (keys(%{$idrules}) > 0) {
3389: $datatable .= &user_formats_row('id',$settings,$idrules,
3390: $idruleorder,$numinrow,$rowcount);
3391: $$rowtotal ++;
3392: $rowcount ++;
1.28 raeburn 3393: }
3394: }
1.43 raeburn 3395: my ($emailrules,$emailruleorder) =
3396: &Apache::lonnet::inst_userrules($dom,'email');
3397: if (ref($emailrules) eq 'HASH') {
3398: if (keys(%{$emailrules}) > 0) {
3399: $datatable .= &user_formats_row('email',$settings,$emailrules,
3400: $emailruleorder,$numinrow,$rowcount);
3401: $$rowtotal ++;
3402: $rowcount ++;
3403: }
3404: }
1.39 raeburn 3405: if ($rowcount == 0) {
3406: $datatable .= '<tr><td colspan="2">'.&mt('No format rules have been defined for usernames or IDs in this domain.').'</td></tr>';
3407: $$rowtotal ++;
3408: $rowcount ++;
3409: }
1.34 raeburn 3410: } elsif ($position eq 'middle') {
1.100 raeburn 3411: my @creators = ('author','course','requestcrs','selfcreate');
1.37 raeburn 3412: my ($rules,$ruleorder) =
3413: &Apache::lonnet::inst_userrules($dom,'username');
1.34 raeburn 3414: my %lt = &usercreation_types();
3415: my %checked;
1.50 raeburn 3416: my @selfcreate;
1.34 raeburn 3417: if (ref($settings) eq 'HASH') {
3418: if (ref($settings->{'cancreate'}) eq 'HASH') {
3419: foreach my $item (@creators) {
3420: $checked{$item} = $settings->{'cancreate'}{$item};
3421: }
1.50 raeburn 3422: if (ref($settings->{'cancreate'}{'selfcreate'}) eq 'ARRAY') {
3423: @selfcreate = @{$settings->{'cancreate'}{'selfcreate'}};
3424: } elsif ($settings->{'cancreate'}{'selfcreate'} ne '') {
3425: if ($settings->{'cancreate'}{'selfcreate'} eq 'any') {
3426: @selfcreate = ('email','login','sso');
3427: } elsif ($settings->{'cancreate'}{'selfcreate'} ne 'none') {
3428: @selfcreate = ($settings->{'cancreate'}{'selfcreate'});
3429: }
3430: }
1.34 raeburn 3431: } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {
3432: foreach my $item (@creators) {
3433: if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {
3434: $checked{$item} = 'none';
3435: }
3436: }
3437: }
3438: }
3439: my $rownum = 0;
3440: foreach my $item (@creators) {
3441: $rownum ++;
1.50 raeburn 3442: if ($item ne 'selfcreate') {
3443: if ($checked{$item} eq '') {
1.43 raeburn 3444: $checked{$item} = 'any';
3445: }
1.34 raeburn 3446: }
3447: my $css_class;
3448: if ($rownum%2) {
3449: $css_class = '';
3450: } else {
3451: $css_class = ' class="LC_odd_row" ';
3452: }
3453: $datatable .= '<tr'.$css_class.'>'.
3454: '<td><span class="LC_nobreak">'.$lt{$item}.
3455: '</span></td><td align="right">';
1.50 raeburn 3456: my @options;
1.45 raeburn 3457: if ($item eq 'selfcreate') {
1.43 raeburn 3458: push(@options,('email','login','sso'));
3459: } else {
1.50 raeburn 3460: @options = ('any');
1.43 raeburn 3461: if (ref($rules) eq 'HASH') {
3462: if (keys(%{$rules}) > 0) {
3463: push(@options,('official','unofficial'));
3464: }
1.37 raeburn 3465: }
1.50 raeburn 3466: push(@options,'none');
1.37 raeburn 3467: }
3468: foreach my $option (@options) {
1.50 raeburn 3469: my $type = 'radio';
1.34 raeburn 3470: my $check = ' ';
1.50 raeburn 3471: if ($item eq 'selfcreate') {
3472: $type = 'checkbox';
3473: if (grep(/^\Q$option\E$/,@selfcreate)) {
3474: $check = ' checked="checked" ';
3475: }
3476: } else {
3477: if ($checked{$item} eq $option) {
3478: $check = ' checked="checked" ';
3479: }
1.34 raeburn 3480: }
3481: $datatable .= '<span class="LC_nobreak"><label>'.
1.50 raeburn 3482: '<input type="'.$type.'" name="can_createuser_'.
1.34 raeburn 3483: $item.'" value="'.$option.'"'.$check.'/> '.
3484: $lt{$option}.'</label> </span>';
3485: }
3486: $datatable .= '</td></tr>';
3487: }
1.93 raeburn 3488: my ($othertitle,$usertypes,$types) =
3489: &Apache::loncommon::sorted_inst_types($dom);
1.165 raeburn 3490: my $createsettings;
3491: if (ref($settings) eq 'HASH') {
3492: $createsettings = $settings->{cancreate};
3493: }
1.93 raeburn 3494: if (ref($usertypes) eq 'HASH') {
3495: if (keys(%{$usertypes}) > 0) {
1.99 raeburn 3496: $datatable .= &insttypes_row($createsettings,$types,$usertypes,
1.93 raeburn 3497: $dom,$numinrow,$othertitle,
3498: 'statustocreate');
3499: $$rowtotal ++;
1.169 raeburn 3500: $rownum ++;
1.93 raeburn 3501: }
3502: }
1.169 raeburn 3503: $datatable .= &captcha_choice('cancreate',$createsettings,$rownum);
1.28 raeburn 3504: } else {
3505: my @contexts = ('author','course','domain');
3506: my @authtypes = ('int','krb4','krb5','loc');
3507: my %checked;
3508: if (ref($settings) eq 'HASH') {
3509: if (ref($settings->{'authtypes'}) eq 'HASH') {
3510: foreach my $item (@contexts) {
3511: if (ref($settings->{'authtypes'}{$item}) eq 'HASH') {
3512: foreach my $auth (@authtypes) {
3513: if ($settings->{'authtypes'}{$item}{$auth}) {
3514: $checked{$item}{$auth} = ' checked="checked" ';
3515: }
3516: }
3517: }
3518: }
1.27 raeburn 3519: }
1.35 raeburn 3520: } else {
3521: foreach my $item (@contexts) {
1.36 raeburn 3522: foreach my $auth (@authtypes) {
1.35 raeburn 3523: $checked{$item}{$auth} = ' checked="checked" ';
3524: }
3525: }
1.27 raeburn 3526: }
1.28 raeburn 3527: my %title = &context_names();
3528: my %authname = &authtype_names();
3529: my $rownum = 0;
3530: my $css_class;
3531: foreach my $item (@contexts) {
3532: if ($rownum%2) {
3533: $css_class = '';
3534: } else {
3535: $css_class = ' class="LC_odd_row" ';
3536: }
1.30 raeburn 3537: $datatable .= '<tr'.$css_class.'>'.
1.28 raeburn 3538: '<td>'.$title{$item}.
3539: '</td><td class="LC_left_item">'.
3540: '<span class="LC_nobreak">';
3541: foreach my $auth (@authtypes) {
3542: $datatable .= '<label>'.
3543: '<input type="checkbox" name="'.$item.'_auth" '.
3544: $checked{$item}{$auth}.' value="'.$auth.'" />'.
3545: $authname{$auth}.'</label> ';
3546: }
3547: $datatable .= '</span></td></tr>';
3548: $rownum ++;
1.27 raeburn 3549: }
1.30 raeburn 3550: $$rowtotal += $rownum;
1.27 raeburn 3551: }
3552: return $datatable;
3553: }
3554:
1.165 raeburn 3555: sub captcha_choice {
1.169 raeburn 3556: my ($context,$settings,$itemcount) = @_;
1.165 raeburn 3557: my ($keyentry,$currpub,$currpriv,%checked,$rowname,$pubtext,$privtext);
3558: my %lt = &captcha_phrases();
3559: $keyentry = 'hidden';
3560: if ($context eq 'cancreate') {
3561: $rowname = &mt('CAPTCHA validation (e-mail as username)');
1.169 raeburn 3562: } elsif ($context eq 'login') {
3563: $rowname = &mt('"Contact helpdesk" CAPTCHA validation');
1.165 raeburn 3564: }
3565: if (ref($settings) eq 'HASH') {
3566: if ($settings->{'captcha'}) {
3567: $checked{$settings->{'captcha'}} = ' checked="checked"';
3568: } else {
3569: $checked{'original'} = ' checked="checked"';
3570: }
3571: if ($settings->{'captcha'} eq 'recaptcha') {
3572: $pubtext = $lt{'pub'};
3573: $privtext = $lt{'priv'};
3574: $keyentry = 'text';
3575: }
3576: if (ref($settings->{'recaptchakeys'}) eq 'HASH') {
3577: $currpub = $settings->{'recaptchakeys'}{'public'};
3578: $currpriv = $settings->{'recaptchakeys'}{'private'};
3579: }
3580: } else {
3581: $checked{'original'} = ' checked="checked"';
3582: }
1.169 raeburn 3583: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
3584: my $output = '<tr'.$css_class.'>'.
3585: '<td class="LC_left_item">'.$rowname.'</td><td class="LC_left_item" colspan="2">'."\n".
1.165 raeburn 3586: '<table><tr><td>'."\n";
3587: foreach my $option ('original','recaptcha','notused') {
3588: $output .= '<span class="LC_nobreak"><label><input type="radio" name="'.$context.'_captcha" value="'.
3589: $option.'" '.$checked{$option}.' onchange="javascript:updateCaptcha('."this,'$context'".');" />'.
3590: $lt{$option}.'</label></span>';
3591: unless ($option eq 'notused') {
3592: $output .= (' 'x2)."\n";
3593: }
3594: }
3595: #
3596: # Note: If reCAPTCHA is to be used for LON-CAPA servers in a domain, a domain coordinator should visit:
3597: # https://www.google.com/recaptcha and generate a Public and Private key. For domains with multiple
3598: # servers a single key pair will be used for all servers, so the internet domain (e.g., yourcollege.edu)
3599: # specified for use with the key should be broad enough to accommodate all servers in the LON-CAPA domain.
3600: #
3601: $output .= '</td></tr>'."\n".
3602: '<tr><td>'."\n".
3603: '<span class="LC_nobreak"><span id="'.$context.'_recaptchapubtxt">'.$pubtext.'</span> '."\n".
3604: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapub" name="'.$context.'_recaptchapub" value="'.
3605: $currpub.'" size="40" /></span><br />'."\n".
3606: '<span class="LC_nobreak"><span id="'.$context.'_recaptchaprivtxt">'.$privtext.'</span> '."\n".
3607: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapriv" name="'.$context.'_recaptchapriv" value="'.
3608: $currpriv.'" size="40" /></span></td></tr></table>'."\n".
3609: '</td></tr>';
3610: return $output;
3611: }
3612:
1.32 raeburn 3613: sub user_formats_row {
3614: my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount) = @_;
3615: my $output;
3616: my %text = (
3617: 'username' => 'new usernames',
3618: 'id' => 'IDs',
1.45 raeburn 3619: 'email' => 'self-created accounts (e-mail)',
1.32 raeburn 3620: );
3621: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
3622: $output = '<tr '.$css_class.'>'.
1.63 raeburn 3623: '<td><span class="LC_nobreak">';
3624: if ($type eq 'email') {
3625: $output .= &mt("Formats disallowed for $text{$type}: ");
3626: } else {
3627: $output .= &mt("Format rules to check for $text{$type}: ");
3628: }
3629: $output .= '</span></td>'.
3630: '<td class="LC_left_item" colspan="2"><table>';
1.27 raeburn 3631: my $rem;
3632: if (ref($ruleorder) eq 'ARRAY') {
3633: for (my $i=0; $i<@{$ruleorder}; $i++) {
3634: if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
3635: my $rem = $i%($numinrow);
3636: if ($rem == 0) {
3637: if ($i > 0) {
3638: $output .= '</tr>';
3639: }
3640: $output .= '<tr>';
3641: }
3642: my $check = ' ';
1.39 raeburn 3643: if (ref($settings) eq 'HASH') {
3644: if (ref($settings->{$type.'_rule'}) eq 'ARRAY') {
3645: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) {
3646: $check = ' checked="checked" ';
3647: }
1.27 raeburn 3648: }
3649: }
3650: $output .= '<td class="LC_left_item">'.
3651: '<span class="LC_nobreak"><label>'.
1.32 raeburn 3652: '<input type="checkbox" name="'.$type.'_rule" '.
1.27 raeburn 3653: 'value="'.$ruleorder->[$i].'"'.$check.'/>'.
3654: $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
3655: }
3656: }
3657: $rem = @{$ruleorder}%($numinrow);
3658: }
3659: my $colsleft = $numinrow - $rem;
3660: if ($colsleft > 1 ) {
3661: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
3662: ' </td>';
3663: } elsif ($colsleft == 1) {
3664: $output .= '<td class="LC_left_item"> </td>';
3665: }
3666: $output .= '</tr></table></td></tr>';
3667: return $output;
3668: }
3669:
1.34 raeburn 3670: sub usercreation_types {
3671: my %lt = &Apache::lonlocal::texthash (
3672: author => 'When adding a co-author',
3673: course => 'When adding a user to a course',
1.100 raeburn 3674: requestcrs => 'When requesting a course',
1.45 raeburn 3675: selfcreate => 'User creates own account',
1.34 raeburn 3676: any => 'Any',
3677: official => 'Institutional only ',
3678: unofficial => 'Non-institutional only',
1.85 schafran 3679: email => 'E-mail address',
1.43 raeburn 3680: login => 'Institutional Login',
3681: sso => 'SSO',
1.34 raeburn 3682: none => 'None',
3683: );
3684: return %lt;
1.48 raeburn 3685: }
1.34 raeburn 3686:
1.28 raeburn 3687: sub authtype_names {
3688: my %lt = &Apache::lonlocal::texthash(
3689: int => 'Internal',
3690: krb4 => 'Kerberos 4',
3691: krb5 => 'Kerberos 5',
3692: loc => 'Local',
3693: );
3694: return %lt;
3695: }
3696:
3697: sub context_names {
3698: my %context_title = &Apache::lonlocal::texthash(
3699: author => 'Creating users when an Author',
3700: course => 'Creating users when in a course',
3701: domain => 'Creating users when a Domain Coordinator',
3702: );
3703: return %context_title;
3704: }
3705:
1.33 raeburn 3706: sub print_usermodification {
3707: my ($position,$dom,$settings,$rowtotal) = @_;
3708: my $numinrow = 4;
3709: my ($context,$datatable,$rowcount);
3710: if ($position eq 'top') {
3711: $rowcount = 0;
3712: $context = 'author';
3713: foreach my $role ('ca','aa') {
3714: $datatable .= &modifiable_userdata_row($context,$role,$settings,
3715: $numinrow,$rowcount);
3716: $$rowtotal ++;
3717: $rowcount ++;
3718: }
1.63 raeburn 3719: } elsif ($position eq 'middle') {
1.33 raeburn 3720: $context = 'course';
3721: $rowcount = 0;
3722: foreach my $role ('st','ep','ta','in','cr') {
3723: $datatable .= &modifiable_userdata_row($context,$role,$settings,
3724: $numinrow,$rowcount);
3725: $$rowtotal ++;
3726: $rowcount ++;
3727: }
1.63 raeburn 3728: } elsif ($position eq 'bottom') {
3729: $context = 'selfcreate';
3730: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
3731: $usertypes->{'default'} = $othertitle;
3732: if (ref($types) eq 'ARRAY') {
3733: push(@{$types},'default');
3734: $usertypes->{'default'} = $othertitle;
3735: foreach my $status (@{$types}) {
3736: $datatable .= &modifiable_userdata_row($context,$status,$settings,
3737: $numinrow,$rowcount,$usertypes);
3738: $$rowtotal ++;
3739: $rowcount ++;
3740: }
3741: }
1.33 raeburn 3742: }
3743: return $datatable;
3744: }
3745:
1.43 raeburn 3746: sub print_defaults {
3747: my ($dom,$rowtotal) = @_;
1.68 raeburn 3748: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def',
1.141 raeburn 3749: 'datelocale_def','portal_def');
1.43 raeburn 3750: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.141 raeburn 3751: my $titles = &defaults_titles($dom);
1.43 raeburn 3752: my $rownum = 0;
3753: my ($datatable,$css_class);
3754: foreach my $item (@items) {
3755: if ($rownum%2) {
3756: $css_class = '';
3757: } else {
3758: $css_class = ' class="LC_odd_row" ';
3759: }
3760: $datatable .= '<tr'.$css_class.'>'.
3761: '<td><span class="LC_nobreak">'.$titles->{$item}.
3762: '</span></td><td class="LC_right_item">';
3763: if ($item eq 'auth_def') {
3764: my @authtypes = ('internal','krb4','krb5','localauth');
3765: my %shortauth = (
3766: internal => 'int',
3767: krb4 => 'krb4',
3768: krb5 => 'krb5',
3769: localauth => 'loc'
3770: );
3771: my %authnames = &authtype_names();
3772: foreach my $auth (@authtypes) {
3773: my $checked = ' ';
3774: if ($domdefaults{$item} eq $auth) {
3775: $checked = ' checked="checked" ';
3776: }
3777: $datatable .= '<label><input type="radio" name="'.$item.
3778: '" value="'.$auth.'"'.$checked.'/>'.
3779: $authnames{$shortauth{$auth}}.'</label> ';
3780: }
1.54 raeburn 3781: } elsif ($item eq 'timezone_def') {
3782: my $includeempty = 1;
3783: $datatable .= &Apache::loncommon::select_timezone($item,$domdefaults{$item},undef,$includeempty);
1.68 raeburn 3784: } elsif ($item eq 'datelocale_def') {
3785: my $includeempty = 1;
3786: $datatable .= &Apache::loncommon::select_datelocale($item,$domdefaults{$item},undef,$includeempty);
1.167 raeburn 3787: } elsif ($item eq 'lang_def') {
1.168 raeburn 3788: my %langchoices = &get_languages_hash();
3789: $langchoices{''} = 'No language preference';
1.167 raeburn 3790: %langchoices = &Apache::lonlocal::texthash(%langchoices);
3791: $datatable .= &Apache::loncommon::select_form($domdefaults{$item},$item,
3792: \%langchoices);
1.43 raeburn 3793: } else {
1.141 raeburn 3794: my $size;
3795: if ($item eq 'portal_def') {
3796: $size = ' size="25"';
3797: }
1.43 raeburn 3798: $datatable .= '<input type="text" name="'.$item.'" value="'.
1.141 raeburn 3799: $domdefaults{$item}.'"'.$size.' />';
1.43 raeburn 3800: }
3801: $datatable .= '</td></tr>';
3802: $rownum ++;
3803: }
3804: $$rowtotal += $rownum;
3805: return $datatable;
3806: }
3807:
1.168 raeburn 3808: sub get_languages_hash {
3809: my %langchoices;
3810: foreach my $id (&Apache::loncommon::languageids()) {
3811: my $code = &Apache::loncommon::supportedlanguagecode($id);
3812: if ($code ne '') {
3813: $langchoices{$code} = &Apache::loncommon::plainlanguagedescription($id);
3814: }
3815: }
3816: return %langchoices;
3817: }
3818:
1.43 raeburn 3819: sub defaults_titles {
1.141 raeburn 3820: my ($dom) = @_;
1.43 raeburn 3821: my %titles = &Apache::lonlocal::texthash (
3822: 'auth_def' => 'Default authentication type',
3823: 'auth_arg_def' => 'Default authentication argument',
3824: 'lang_def' => 'Default language',
1.54 raeburn 3825: 'timezone_def' => 'Default timezone',
1.68 raeburn 3826: 'datelocale_def' => 'Default locale for dates',
1.141 raeburn 3827: 'portal_def' => 'Portal/Default URL',
1.43 raeburn 3828: );
1.141 raeburn 3829: if ($dom) {
3830: my $uprimary_id = &Apache::lonnet::domain($dom,'primary');
3831: my $uint_dom = &Apache::lonnet::internet_dom($uprimary_id);
3832: my $protocol = $Apache::lonnet::protocol{$uprimary_id};
3833: $protocol = 'http' if ($protocol ne 'https');
3834: if ($uint_dom) {
3835: $titles{'portal_def'} .= ' '.&mt('(for example: [_1])',$protocol.'://loncapa.'.
3836: $uint_dom);
3837: }
3838: }
1.43 raeburn 3839: return (\%titles);
3840: }
3841:
1.46 raeburn 3842: sub print_scantronformat {
3843: my ($r,$dom,$confname,$settings,$rowtotal) = @_;
3844: my $itemcount = 1;
1.60 raeburn 3845: my ($datatable,$css_class,$scantronurl,$is_custom,%error,%scantronurls,
3846: %confhash);
1.46 raeburn 3847: my $switchserver = &check_switchserver($dom,$confname);
3848: my %lt = &Apache::lonlocal::texthash (
1.95 www 3849: default => 'Default bubblesheet format file error',
3850: custom => 'Custom bubblesheet format file error',
1.46 raeburn 3851: );
3852: my %scantronfiles = (
3853: default => 'default.tab',
3854: custom => 'custom.tab',
3855: );
3856: foreach my $key (keys(%scantronfiles)) {
3857: $scantronurls{$key} = '/res/'.$dom.'/'.$confname.'/scantron/'
3858: .$scantronfiles{$key};
3859: }
3860: my @defaultinfo = &Apache::lonnet::stat_file($scantronurls{'default'});
3861: if ((!@defaultinfo) || ($defaultinfo[0] eq 'no_such_dir')) {
3862: if (!$switchserver) {
3863: my $servadm = $r->dir_config('lonAdmEMail');
3864: my ($configuserok,$author_ok) = &config_check($dom,$confname,$servadm);
3865: if ($configuserok eq 'ok') {
3866: if ($author_ok eq 'ok') {
3867: my %legacyfile = (
3868: default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab',
3869: custom => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab',
3870: );
3871: my %md5chk;
3872: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 3873: ($md5chk{$type}) = split(/ /,`md5sum $legacyfile{$type}`);
3874: chomp($md5chk{$type});
1.46 raeburn 3875: }
3876: if ($md5chk{'default'} ne $md5chk{'custom'}) {
3877: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 3878: ($scantronurls{$type},my $error) =
1.46 raeburn 3879: &legacy_scantronformat($r,$dom,$confname,
3880: $type,$legacyfile{$type},
3881: $scantronurls{$type},
3882: $scantronfiles{$type});
1.60 raeburn 3883: if ($error ne '') {
3884: $error{$type} = $error;
3885: }
3886: }
3887: if (keys(%error) == 0) {
3888: $is_custom = 1;
3889: $confhash{'scantron'}{'scantronformat'} =
3890: $scantronurls{'custom'};
3891: my $putresult =
3892: &Apache::lonnet::put_dom('configuration',
3893: \%confhash,$dom);
3894: if ($putresult ne 'ok') {
3895: $error{'custom'} =
3896: '<span class="LC_error">'.
3897: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
3898: }
1.46 raeburn 3899: }
3900: } else {
1.60 raeburn 3901: ($scantronurls{'default'},my $error) =
1.46 raeburn 3902: &legacy_scantronformat($r,$dom,$confname,
3903: 'default',$legacyfile{'default'},
3904: $scantronurls{'default'},
3905: $scantronfiles{'default'});
1.60 raeburn 3906: if ($error eq '') {
3907: $confhash{'scantron'}{'scantronformat'} = '';
3908: my $putresult =
3909: &Apache::lonnet::put_dom('configuration',
3910: \%confhash,$dom);
3911: if ($putresult ne 'ok') {
3912: $error{'default'} =
3913: '<span class="LC_error">'.
3914: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
3915: }
3916: } else {
3917: $error{'default'} = $error;
3918: }
1.46 raeburn 3919: }
3920: }
3921: }
3922: } else {
1.95 www 3923: $error{'default'} = &mt("Unable to copy default bubblesheet formatfile to domain's RES space: [_1]",$switchserver);
1.46 raeburn 3924: }
3925: }
3926: if (ref($settings) eq 'HASH') {
3927: if ($settings->{'scantronformat'} eq "/res/$dom/$confname/scantron/custom.tab") {
3928: my @info = &Apache::lonnet::stat_file($settings->{'scantronformat'});
3929: if ((!@info) || ($info[0] eq 'no_such_dir')) {
3930: $scantronurl = '';
3931: } else {
3932: $scantronurl = $settings->{'scantronformat'};
3933: }
3934: $is_custom = 1;
3935: } else {
3936: $scantronurl = $scantronurls{'default'};
3937: }
3938: } else {
1.60 raeburn 3939: if ($is_custom) {
3940: $scantronurl = $scantronurls{'custom'};
3941: } else {
3942: $scantronurl = $scantronurls{'default'};
3943: }
1.46 raeburn 3944: }
3945: $css_class = $itemcount%2?' class="LC_odd_row"':'';
3946: $datatable .= '<tr'.$css_class.'>';
3947: if (!$is_custom) {
1.65 raeburn 3948: $datatable .= '<td>'.&mt('Default in use:').'<br />'.
3949: '<span class="LC_nobreak">';
1.46 raeburn 3950: if ($scantronurl) {
1.199 raeburn 3951: $datatable .= &Apache::loncommon::modal_link($scantronurl,&mt('Default bubblesheet format file'),600,500,
3952: undef,undef,undef,undef,'background-color:#ffffff');
1.46 raeburn 3953: } else {
3954: $datatable = &mt('File unavailable for display');
3955: }
1.65 raeburn 3956: $datatable .= '</span></td>';
1.60 raeburn 3957: if (keys(%error) == 0) {
3958: $datatable .= '<td valign="bottom">';
3959: if (!$switchserver) {
3960: $datatable .= &mt('Upload:').'<br />';
3961: }
3962: } else {
3963: my $errorstr;
3964: foreach my $key (sort(keys(%error))) {
3965: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
3966: }
3967: $datatable .= '<td>'.$errorstr;
3968: }
1.46 raeburn 3969: } else {
3970: if (keys(%error) > 0) {
3971: my $errorstr;
3972: foreach my $key (sort(keys(%error))) {
3973: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
3974: }
1.60 raeburn 3975: $datatable .= '<td>'.$errorstr.'</td><td> ';
1.46 raeburn 3976: } elsif ($scantronurl) {
1.199 raeburn 3977: my $link = &Apache::loncommon::modal_link($scantronurl,&mt('Custom bubblesheet format file'),600,500,
3978: undef,undef,undef,undef,'background-color:#ffffff');
1.65 raeburn 3979: $datatable .= '<td><span class="LC_nobreak">'.
1.199 raeburn 3980: $link.
3981: '<label><input type="checkbox" name="scantronformat_del"'.
3982: ' value="1" />'.&mt('Delete?').'</label></span></td>'.
1.65 raeburn 3983: '<td><span class="LC_nobreak"> '.
3984: &mt('Replace:').'</span><br />';
1.46 raeburn 3985: }
3986: }
3987: if (keys(%error) == 0) {
3988: if ($switchserver) {
3989: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
3990: } else {
1.65 raeburn 3991: $datatable .='<span class="LC_nobreak"> '.
3992: '<input type="file" name="scantronformat" /></span>';
1.46 raeburn 3993: }
3994: }
3995: $datatable .= '</td></tr>';
3996: $$rowtotal ++;
3997: return $datatable;
3998: }
3999:
4000: sub legacy_scantronformat {
4001: my ($r,$dom,$confname,$file,$legacyfile,$newurl,$newfile) = @_;
4002: my ($url,$error);
4003: my @statinfo = &Apache::lonnet::stat_file($newurl);
4004: if ((!@statinfo) || ($statinfo[0] eq 'no_such_dir')) {
4005: (my $result,$url) =
4006: &publishlogo($r,'copy',$legacyfile,$dom,$confname,'scantron',
4007: '','',$newfile);
4008: if ($result ne 'ok') {
1.130 raeburn 4009: $error = &mt("An error occurred publishing the [_1] bubblesheet format file in RES space. Error was: [_2].",$newfile,$result);
1.46 raeburn 4010: }
4011: }
4012: return ($url,$error);
4013: }
1.43 raeburn 4014:
1.49 raeburn 4015: sub print_coursecategories {
1.57 raeburn 4016: my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;
4017: my $datatable;
4018: if ($position eq 'top') {
4019: my $toggle_cats_crs = ' ';
4020: my $toggle_cats_dom = ' checked="checked" ';
4021: my $can_cat_crs = ' ';
4022: my $can_cat_dom = ' checked="checked" ';
1.120 raeburn 4023: my $toggle_catscomm_comm = ' ';
4024: my $toggle_catscomm_dom = ' checked="checked" ';
4025: my $can_catcomm_comm = ' ';
4026: my $can_catcomm_dom = ' checked="checked" ';
4027:
1.57 raeburn 4028: if (ref($settings) eq 'HASH') {
4029: if ($settings->{'togglecats'} eq 'crs') {
4030: $toggle_cats_crs = $toggle_cats_dom;
4031: $toggle_cats_dom = ' ';
4032: }
4033: if ($settings->{'categorize'} eq 'crs') {
4034: $can_cat_crs = $can_cat_dom;
4035: $can_cat_dom = ' ';
4036: }
1.120 raeburn 4037: if ($settings->{'togglecatscomm'} eq 'comm') {
4038: $toggle_catscomm_comm = $toggle_catscomm_dom;
4039: $toggle_catscomm_dom = ' ';
4040: }
4041: if ($settings->{'categorizecomm'} eq 'comm') {
4042: $can_catcomm_comm = $can_catcomm_dom;
4043: $can_catcomm_dom = ' ';
4044: }
1.57 raeburn 4045: }
4046: my %title = &Apache::lonlocal::texthash (
1.120 raeburn 4047: togglecats => 'Show/Hide a course in catalog',
4048: togglecatscomm => 'Show/Hide a community in catalog',
4049: categorize => 'Assign a category to a course',
4050: categorizecomm => 'Assign a category to a community',
1.57 raeburn 4051: );
4052: my %level = &Apache::lonlocal::texthash (
1.120 raeburn 4053: dom => 'Set in Domain',
4054: crs => 'Set in Course',
4055: comm => 'Set in Community',
1.57 raeburn 4056: );
4057: $datatable = '<tr class="LC_odd_row">'.
4058: '<td>'.$title{'togglecats'}.'</td>'.
4059: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4060: '<input type="radio" name="togglecats"'.
4061: $toggle_cats_dom.' value="dom" />'.$level{'dom'}.'</label> '.
4062: '<label><input type="radio" name="togglecats"'.
4063: $toggle_cats_crs.' value="crs" />'.$level{'crs'}.'</label></span></td>'.
4064: '</tr><tr>'.
4065: '<td>'.$title{'categorize'}.'</td>'.
4066: '<td class="LC_right_item"><span class="LC_nobreak">'.
4067: '<label><input type="radio" name="categorize"'.
4068: $can_cat_dom.' value="dom" />'.$level{'dom'}.'</label> '.
4069: '<label><input type="radio" name="categorize"'.
4070: $can_cat_crs.'value="crs" />'.$level{'crs'}.'</label></span></td>'.
1.120 raeburn 4071: '</tr><tr class="LC_odd_row">'.
4072: '<td>'.$title{'togglecatscomm'}.'</td>'.
4073: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4074: '<input type="radio" name="togglecatscomm"'.
4075: $toggle_catscomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
4076: '<label><input type="radio" name="togglecatscomm"'.
4077: $toggle_catscomm_comm.' value="comm" />'.$level{'comm'}.'</label></span></td>'.
4078: '</tr><tr>'.
4079: '<td>'.$title{'categorizecomm'}.'</td>'.
4080: '<td class="LC_right_item"><span class="LC_nobreak">'.
4081: '<label><input type="radio" name="categorizecomm"'.
4082: $can_catcomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
4083: '<label><input type="radio" name="categorizecomm"'.
4084: $can_catcomm_comm.'value="comm" />'.$level{'comm'}.'</label></span></td>'.
1.57 raeburn 4085: '</tr>';
1.120 raeburn 4086: $$rowtotal += 4;
1.57 raeburn 4087: } else {
4088: my $css_class;
4089: my $itemcount = 1;
4090: my $cathash;
4091: if (ref($settings) eq 'HASH') {
4092: $cathash = $settings->{'cats'};
4093: }
4094: if (ref($cathash) eq 'HASH') {
4095: my (@cats,@trails,%allitems,%idx,@jsarray);
4096: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
4097: \%allitems,\%idx,\@jsarray);
4098: my $maxdepth = scalar(@cats);
4099: my $colattrib = '';
4100: if ($maxdepth > 2) {
4101: $colattrib = ' colspan="2" ';
4102: }
4103: my @path;
4104: if (@cats > 0) {
4105: if (ref($cats[0]) eq 'ARRAY') {
4106: my $numtop = @{$cats[0]};
4107: my $maxnum = $numtop;
1.120 raeburn 4108: my %default_names = (
4109: instcode => &mt('Official courses'),
4110: communities => &mt('Communities'),
4111: );
4112:
4113: if ((!grep(/^instcode$/,@{$cats[0]})) ||
4114: ($cathash->{'instcode::0'} eq '') ||
4115: (!grep(/^communities$/,@{$cats[0]})) ||
4116: ($cathash->{'communities::0'} eq '')) {
1.57 raeburn 4117: $maxnum ++;
4118: }
4119: my $lastidx;
4120: for (my $i=0; $i<$numtop; $i++) {
4121: my $parent = $cats[0][$i];
4122: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4123: my $item = &escape($parent).'::0';
4124: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$item','$idx{$item}'".');"';
4125: $lastidx = $idx{$item};
4126: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
4127: .'<select name="'.$item.'"'.$chgstr.'>';
4128: for (my $k=0; $k<=$maxnum; $k++) {
4129: my $vpos = $k+1;
4130: my $selstr;
4131: if ($k == $i) {
4132: $selstr = ' selected="selected" ';
4133: }
4134: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4135: }
4136: $datatable .= '</select></td><td>';
1.120 raeburn 4137: if ($parent eq 'instcode' || $parent eq 'communities') {
4138: $datatable .= '<span class="LC_nobreak">'
4139: .$default_names{$parent}.'</span>';
4140: if ($parent eq 'instcode') {
4141: $datatable .= '<br /><span class="LC_nobreak">('
4142: .&mt('with institutional codes')
4143: .')</span></td><td'.$colattrib.'>';
4144: } else {
4145: $datatable .= '<table><tr><td>';
4146: }
4147: $datatable .= '<span class="LC_nobreak">'
4148: .'<label><input type="radio" name="'
4149: .$parent.'" value="1" checked="checked" />'
4150: .&mt('Display').'</label>';
4151: if ($parent eq 'instcode') {
4152: $datatable .= ' ';
4153: } else {
4154: $datatable .= '</span></td></tr><tr><td>'
4155: .'<span class="LC_nobreak">';
4156: }
4157: $datatable .= '<label><input type="radio" name="'
4158: .$parent.'" value="0" />'
4159: .&mt('Do not display').'</label></span>';
4160: if ($parent eq 'communities') {
4161: $datatable .= '</td></tr></table>';
4162: }
4163: $datatable .= '</td>';
1.57 raeburn 4164: } else {
4165: $datatable .= $parent
4166: .' <label><input type="checkbox" name="deletecategory" '
4167: .'value="'.$item.'" />'.&mt('Delete').'</label></span></td>';
4168: }
4169: my $depth = 1;
4170: push(@path,$parent);
4171: $datatable .= &build_category_rows($itemcount,\@cats,$depth,$parent,\@path,\%idx);
4172: pop(@path);
4173: $datatable .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
4174: $itemcount ++;
4175: }
1.48 raeburn 4176: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.57 raeburn 4177: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','$lastidx'".');"';
4178: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="addcategory_pos"'.$chgstr.'>';
1.48 raeburn 4179: for (my $k=0; $k<=$maxnum; $k++) {
4180: my $vpos = $k+1;
4181: my $selstr;
1.57 raeburn 4182: if ($k == $numtop) {
1.48 raeburn 4183: $selstr = ' selected="selected" ';
4184: }
4185: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4186: }
1.59 bisitz 4187: $datatable .= '</select></span></td><td colspan="2">'.&mt('Add category:').' '
1.57 raeburn 4188: .'<input type="text" size="20" name="addcategory_name" value="" /></td>'
4189: .'</tr>'."\n";
1.48 raeburn 4190: $itemcount ++;
1.120 raeburn 4191: foreach my $default ('instcode','communities') {
4192: if ((!grep(/^\Q$default\E$/,@{$cats[0]})) || ($cathash->{$default.'::0'} eq '')) {
4193: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4194: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','$lastidx'".');"';
4195: $datatable .= '<tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr><tr '.$css_class.'><td>'.
4196: '<span class="LC_nobreak"><select name="'.$default.'_pos"'.$chgstr.'>';
4197: for (my $k=0; $k<=$maxnum; $k++) {
4198: my $vpos = $k+1;
4199: my $selstr;
4200: if ($k == $maxnum) {
4201: $selstr = ' selected="selected" ';
4202: }
4203: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.57 raeburn 4204: }
1.120 raeburn 4205: $datatable .= '</select></span></td>'.
4206: '<td><span class="LC_nobreak">'.
4207: $default_names{$default}.'</span>';
4208: if ($default eq 'instcode') {
4209: $datatable .= '<br /><span class="LC_nobreak">('
4210: .&mt('with institutional codes').')</span>';
4211: }
4212: $datatable .= '</td>'
4213: .'<td><span class="LC_nobreak"><label><input type="radio" name="'.$default.'" value="1" />'
4214: .&mt('Display').'</label> '
4215: .'<label><input type="radio" name="'.$default.'" value="0" checked="checked"/>'
4216: .&mt('Do not display').'</label></span></td></tr>';
1.48 raeburn 4217: }
4218: }
4219: }
1.57 raeburn 4220: } else {
4221: $datatable .= &initialize_categories($itemcount);
1.48 raeburn 4222: }
4223: } else {
1.57 raeburn 4224: $datatable .= '<td class="LC_right_item">'.$hdritem->{'header'}->[0]->{'col2'}.'</td>'
4225: .&initialize_categories($itemcount);
1.48 raeburn 4226: }
1.57 raeburn 4227: $$rowtotal += $itemcount;
1.48 raeburn 4228: }
4229: return $datatable;
4230: }
4231:
1.69 raeburn 4232: sub print_serverstatuses {
4233: my ($dom,$settings,$rowtotal) = @_;
4234: my $datatable;
4235: my @pages = &serverstatus_pages();
4236: my (%namedaccess,%machineaccess);
4237: foreach my $type (@pages) {
4238: $namedaccess{$type} = '';
4239: $machineaccess{$type}= '';
4240: }
4241: if (ref($settings) eq 'HASH') {
4242: foreach my $type (@pages) {
4243: if (exists($settings->{$type})) {
4244: if (ref($settings->{$type}) eq 'HASH') {
4245: foreach my $key (keys(%{$settings->{$type}})) {
4246: if ($key eq 'namedusers') {
4247: $namedaccess{$type} = $settings->{$type}->{$key};
4248: } elsif ($key eq 'machines') {
4249: $machineaccess{$type} = $settings->{$type}->{$key};
4250: }
4251: }
4252: }
4253: }
4254: }
4255: }
1.81 raeburn 4256: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 4257: my $rownum = 0;
4258: my $css_class;
4259: foreach my $type (@pages) {
4260: $rownum ++;
4261: $css_class = $rownum%2?' class="LC_odd_row"':'';
4262: $datatable .= '<tr'.$css_class.'>'.
4263: '<td><span class="LC_nobreak">'.
4264: $titles->{$type}.'</span></td>'.
4265: '<td class="LC_left_item">'.
4266: '<input type="text" name="'.$type.'_namedusers" '.
4267: 'value="'.$namedaccess{$type}.'" size="30" /></td>'.
4268: '<td class="LC_right_item">'.
4269: '<span class="LC_nobreak">'.
4270: '<input type="text" name="'.$type.'_machines" '.
4271: 'value="'.$machineaccess{$type}.'" size="10" />'.
4272: '</td></tr>'."\n";
4273: }
4274: $$rowtotal += $rownum;
4275: return $datatable;
4276: }
4277:
4278: sub serverstatus_pages {
4279: return ('userstatus','lonstatus','loncron','server-status','codeversions',
1.189 raeburn 4280: 'checksums','clusterstatus','metadata_keywords','metadata_harvest',
1.156 raeburn 4281: 'takeoffline','takeonline','showenv','toggledebug','ping','domconf');
1.69 raeburn 4282: }
4283:
1.49 raeburn 4284: sub coursecategories_javascript {
4285: my ($settings) = @_;
1.57 raeburn 4286: my ($output,$jstext,$cathash);
1.49 raeburn 4287: if (ref($settings) eq 'HASH') {
1.57 raeburn 4288: $cathash = $settings->{'cats'};
4289: }
4290: if (ref($cathash) eq 'HASH') {
1.49 raeburn 4291: my (@cats,@jsarray,%idx);
1.57 raeburn 4292: &Apache::loncommon::gather_categories($cathash,\@cats,\%idx,\@jsarray);
1.49 raeburn 4293: if (@jsarray > 0) {
4294: $jstext = ' var categories = Array('.scalar(@jsarray).');'."\n";
4295: for (my $i=0; $i<@jsarray; $i++) {
4296: if (ref($jsarray[$i]) eq 'ARRAY') {
4297: my $catstr = join('","',@{$jsarray[$i]});
4298: $jstext .= ' categories['.$i.'] = Array("'.$catstr.'");'."\n";
4299: }
4300: }
4301: }
4302: } else {
4303: $jstext = ' var categories = Array(1);'."\n".
4304: ' categories[0] = Array("instcode_pos");'."\n";
4305: }
1.120 raeburn 4306: my $instcode_reserved = &mt('The name: "instcode" is a reserved category');
4307: my $communities_reserved = &mt('The name: "communities" is a reserved category');
4308: my $choose_again = '\\n'.&mt('Please use a different name for the new top level category');
1.49 raeburn 4309: $output = <<"ENDSCRIPT";
4310: <script type="text/javascript">
1.109 raeburn 4311: // <![CDATA[
1.49 raeburn 4312: function reorderCats(form,parent,item,idx) {
4313: var changedVal;
4314: $jstext
4315: var newpos = 'addcategory_pos';
4316: var current = new Array;
4317: if (parent == '') {
4318: var has_instcode = 0;
4319: var maxtop = categories[idx].length;
4320: for (var j=0; j<maxtop; j++) {
4321: if (categories[idx][j] == 'instcode::0') {
4322: has_instcode == 1;
4323: }
4324: }
4325: if (has_instcode == 0) {
4326: categories[idx][maxtop] = 'instcode_pos';
4327: }
4328: } else {
4329: newpos += '_'+parent;
4330: }
4331: var maxh = 1 + categories[idx].length;
4332: var current = new Array;
4333: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
4334: if (item == newpos) {
4335: changedVal = newitemVal;
4336: } else {
4337: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
4338: current[newitemVal] = newpos;
4339: }
4340: for (var i=0; i<categories[idx].length; i++) {
4341: var elementName = categories[idx][i];
4342: if (elementName != item) {
4343: if (form.elements[elementName]) {
4344: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
4345: current[currVal] = elementName;
4346: }
4347: }
4348: }
4349: var oldVal;
4350: for (var j=0; j<maxh; j++) {
4351: if (current[j] == undefined) {
4352: oldVal = j;
4353: }
4354: }
4355: if (oldVal < changedVal) {
4356: for (var k=oldVal+1; k<=changedVal ; k++) {
4357: var elementName = current[k];
4358: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
4359: }
4360: } else {
4361: for (var k=changedVal; k<oldVal; k++) {
4362: var elementName = current[k];
4363: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
4364: }
4365: }
4366: return;
4367: }
1.120 raeburn 4368:
4369: function categoryCheck(form) {
4370: if (form.elements['addcategory_name'].value == 'instcode') {
4371: alert('$instcode_reserved\\n$choose_again');
4372: return false;
4373: }
4374: if (form.elements['addcategory_name'].value == 'communities') {
4375: alert('$communities_reserved\\n$choose_again');
4376: return false;
4377: }
4378: return true;
4379: }
4380:
1.109 raeburn 4381: // ]]>
1.49 raeburn 4382: </script>
4383:
4384: ENDSCRIPT
4385: return $output;
4386: }
4387:
1.48 raeburn 4388: sub initialize_categories {
4389: my ($itemcount) = @_;
1.120 raeburn 4390: my ($datatable,$css_class,$chgstr);
4391: my %default_names = (
4392: instcode => 'Official courses (with institutional codes)',
4393: communities => 'Communities',
4394: );
4395: my $select0 = ' selected="selected"';
4396: my $select1 = '';
4397: foreach my $default ('instcode','communities') {
4398: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4399: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'',$default"."_pos','0'".');"';
4400: if ($default eq 'communities') {
4401: $select1 = $select0;
4402: $select0 = '';
4403: }
4404: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
4405: .'<select name="'.$default.'_pos">'
4406: .'<option value="0"'.$select0.'>1</option>'
4407: .'<option value="1"'.$select1.'>2</option>'
4408: .'<option value="2">3</option></select> '
4409: .$default_names{$default}
4410: .'</span></td><td><span class="LC_nobreak">'
4411: .'<label><input type="radio" name="'.$default.'" value="1" checked="checked" />'
4412: .&mt('Display').'</label> <label>'
4413: .'<input type="radio" name="'.$default.'" value="0" />'.&mt('Do not display')
1.48 raeburn 4414: .'</label></span></td></tr>';
1.120 raeburn 4415: $itemcount ++;
4416: }
1.48 raeburn 4417: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.49 raeburn 4418: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','0'".');"';
1.48 raeburn 4419: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.120 raeburn 4420: .'<select name="addcategory_pos"'.$chgstr.'>'
4421: .'<option value="0">1</option>'
4422: .'<option value="1">2</option>'
4423: .'<option value="2" selected="selected">3</option></select> '
1.48 raeburn 4424: .&mt('Add category').'</td><td>'.&mt('Name:')
4425: .' <input type="text" size="20" name="addcategory_name" value="" /></td></tr>';
4426: return $datatable;
4427: }
4428:
4429: sub build_category_rows {
1.49 raeburn 4430: my ($itemcount,$cats,$depth,$parent,$path,$idx) = @_;
4431: my ($text,$name,$item,$chgstr);
1.48 raeburn 4432: if (ref($cats) eq 'ARRAY') {
4433: my $maxdepth = scalar(@{$cats});
4434: if (ref($cats->[$depth]) eq 'HASH') {
4435: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
4436: my $numchildren = @{$cats->[$depth]{$parent}};
4437: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
4438: $text .= '<td><table class="LC_datatable">';
1.49 raeburn 4439: my ($idxnum,$parent_name,$parent_item);
4440: my $higher = $depth - 1;
4441: if ($higher == 0) {
4442: $parent_name = &escape($parent).'::'.$higher;
4443: } else {
4444: if (ref($path) eq 'ARRAY') {
4445: $parent_name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
4446: }
4447: }
4448: $parent_item = 'addcategory_pos_'.$parent_name;
1.48 raeburn 4449: for (my $j=0; $j<=$numchildren; $j++) {
1.49 raeburn 4450: if ($j < $numchildren) {
1.48 raeburn 4451: $name = $cats->[$depth]{$parent}[$j];
4452: $item = &escape($name).':'.&escape($parent).':'.$depth;
1.49 raeburn 4453: $idxnum = $idx->{$item};
4454: } else {
4455: $name = $parent_name;
4456: $item = $parent_item;
1.48 raeburn 4457: }
1.49 raeburn 4458: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'$parent_name','$item','$idxnum'".');"';
4459: $text .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="'.$item.'"'.$chgstr.'>';
1.48 raeburn 4460: for (my $i=0; $i<=$numchildren; $i++) {
4461: my $vpos = $i+1;
4462: my $selstr;
4463: if ($j == $i) {
4464: $selstr = ' selected="selected" ';
4465: }
4466: $text .= '<option value="'.$i.'"'.$selstr.'>'.$vpos.'</option>';
4467: }
4468: $text .= '</select> ';
4469: if ($j < $numchildren) {
4470: my $deeper = $depth+1;
4471: $text .= $name.' '
4472: .'<label><input type="checkbox" name="deletecategory" value="'
4473: .$item.'" />'.&mt('Delete').'</label></span></td><td>';
4474: if(ref($path) eq 'ARRAY') {
4475: push(@{$path},$name);
1.49 raeburn 4476: $text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path,$idx);
1.48 raeburn 4477: pop(@{$path});
4478: }
4479: } else {
1.59 bisitz 4480: $text .= &mt('Add subcategory:').' </span><input type="textbox" size="20" name="addcategory_name_';
1.48 raeburn 4481: if ($j == $numchildren) {
4482: $text .= $name;
4483: } else {
4484: $text .= $item;
4485: }
4486: $text .= '" value="" />';
4487: }
4488: $text .= '</td></tr>';
4489: }
4490: $text .= '</table></td>';
4491: } else {
4492: my $higher = $depth-1;
4493: if ($higher == 0) {
4494: $name = &escape($parent).'::'.$higher;
4495: } else {
4496: if (ref($path) eq 'ARRAY') {
4497: $name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
4498: }
4499: }
4500: my $colspan;
4501: if ($parent ne 'instcode') {
4502: $colspan = $maxdepth - $depth - 1;
4503: $text .= '<td colspan="'.$colspan.'">'.&mt('Add subcategory:').'<input type="textbox" size="20" name="subcat_'.$name.'" value="" /></td>';
4504: }
4505: }
4506: }
4507: }
4508: return $text;
4509: }
4510:
1.33 raeburn 4511: sub modifiable_userdata_row {
1.63 raeburn 4512: my ($context,$role,$settings,$numinrow,$rowcount,$usertypes) = @_;
1.33 raeburn 4513: my $rolename;
1.63 raeburn 4514: if ($context eq 'selfcreate') {
4515: if (ref($usertypes) eq 'HASH') {
4516: $rolename = $usertypes->{$role};
4517: } else {
4518: $rolename = $role;
4519: }
1.33 raeburn 4520: } else {
1.63 raeburn 4521: if ($role eq 'cr') {
4522: $rolename = &mt('Custom role');
4523: } else {
4524: $rolename = &Apache::lonnet::plaintext($role);
4525: }
1.33 raeburn 4526: }
4527: my @fields = ('lastname','firstname','middlename','generation',
4528: 'permanentemail','id');
4529: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
4530: my $output;
4531: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
4532: $output = '<tr '.$css_class.'>'.
4533: '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
4534: '<td class="LC_left_item" colspan="2"><table>';
4535: my $rem;
4536: my %checks;
4537: if (ref($settings) eq 'HASH') {
4538: if (ref($settings->{$context}) eq 'HASH') {
4539: if (ref($settings->{$context}->{$role}) eq 'HASH') {
4540: foreach my $field (@fields) {
4541: if ($settings->{$context}->{$role}->{$field}) {
4542: $checks{$field} = ' checked="checked" ';
4543: }
4544: }
4545: }
4546: }
4547: }
4548: for (my $i=0; $i<@fields; $i++) {
4549: my $rem = $i%($numinrow);
4550: if ($rem == 0) {
4551: if ($i > 0) {
4552: $output .= '</tr>';
4553: }
4554: $output .= '<tr>';
4555: }
4556: my $check = ' ';
4557: if (exists($checks{$fields[$i]})) {
4558: $check = $checks{$fields[$i]}
4559: } else {
4560: if ($role eq 'st') {
4561: if (ref($settings) ne 'HASH') {
4562: $check = ' checked="checked" ';
4563: }
4564: }
4565: }
4566: $output .= '<td class="LC_left_item">'.
4567: '<span class="LC_nobreak"><label>'.
4568: '<input type="checkbox" name="canmodify_'.$role.'" '.
4569: 'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
4570: '</label></span></td>';
4571: $rem = @fields%($numinrow);
4572: }
4573: my $colsleft = $numinrow - $rem;
4574: if ($colsleft > 1 ) {
4575: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
4576: ' </td>';
4577: } elsif ($colsleft == 1) {
4578: $output .= '<td class="LC_left_item"> </td>';
4579: }
4580: $output .= '</tr></table></td></tr>';
4581: return $output;
4582: }
1.28 raeburn 4583:
1.93 raeburn 4584: sub insttypes_row {
4585: my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle,$context) = @_;
4586: my %lt = &Apache::lonlocal::texthash (
4587: cansearch => 'Users allowed to search',
4588: statustocreate => 'Institutional affiliation(s) able to create own account (login/SSO)',
1.131 raeburn 4589: lockablenames => 'User preference to lock name',
1.93 raeburn 4590: );
4591: my $showdom;
4592: if ($context eq 'cansearch') {
4593: $showdom = ' ('.$dom.')';
4594: }
1.165 raeburn 4595: my $class = 'LC_left_item';
4596: if ($context eq 'statustocreate') {
4597: $class = 'LC_right_item';
4598: }
1.25 raeburn 4599: my $output = '<tr class="LC_odd_row">'.
1.93 raeburn 4600: '<td>'.$lt{$context}.$showdom.
1.165 raeburn 4601: '</td><td class="'.$class.'" colspan="2"><table>';
1.26 raeburn 4602: my $rem;
4603: if (ref($types) eq 'ARRAY') {
4604: for (my $i=0; $i<@{$types}; $i++) {
4605: if (defined($usertypes->{$types->[$i]})) {
4606: my $rem = $i%($numinrow);
4607: if ($rem == 0) {
4608: if ($i > 0) {
4609: $output .= '</tr>';
4610: }
4611: $output .= '<tr>';
1.23 raeburn 4612: }
1.26 raeburn 4613: my $check = ' ';
1.99 raeburn 4614: if (ref($settings) eq 'HASH') {
4615: if (ref($settings->{$context}) eq 'ARRAY') {
4616: if (grep(/^\Q$types->[$i]\E$/,@{$settings->{$context}})) {
4617: $check = ' checked="checked" ';
4618: }
4619: } elsif ($context eq 'statustocreate') {
1.26 raeburn 4620: $check = ' checked="checked" ';
4621: }
1.23 raeburn 4622: }
1.26 raeburn 4623: $output .= '<td class="LC_left_item">'.
4624: '<span class="LC_nobreak"><label>'.
1.93 raeburn 4625: '<input type="checkbox" name="'.$context.'" '.
1.26 raeburn 4626: 'value="'.$types->[$i].'"'.$check.'/>'.
4627: $usertypes->{$types->[$i]}.'</label></span></td>';
1.23 raeburn 4628: }
4629: }
1.26 raeburn 4630: $rem = @{$types}%($numinrow);
1.23 raeburn 4631: }
4632: my $colsleft = $numinrow - $rem;
1.131 raeburn 4633: if (($rem == 0) && (@{$types} > 0)) {
4634: $output .= '<tr>';
4635: }
1.23 raeburn 4636: if ($colsleft > 1) {
1.25 raeburn 4637: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
1.23 raeburn 4638: } else {
1.25 raeburn 4639: $output .= '<td class="LC_left_item">';
1.23 raeburn 4640: }
4641: my $defcheck = ' ';
1.99 raeburn 4642: if (ref($settings) eq 'HASH') {
4643: if (ref($settings->{$context}) eq 'ARRAY') {
4644: if (grep(/^default$/,@{$settings->{$context}})) {
4645: $defcheck = ' checked="checked" ';
4646: }
4647: } elsif ($context eq 'statustocreate') {
1.26 raeburn 4648: $defcheck = ' checked="checked" ';
4649: }
1.23 raeburn 4650: }
1.25 raeburn 4651: $output .= '<span class="LC_nobreak"><label>'.
1.93 raeburn 4652: '<input type="checkbox" name="'.$context.'" '.
1.25 raeburn 4653: 'value="default"'.$defcheck.'/>'.
4654: $othertitle.'</label></span></td>'.
4655: '</tr></table></td></tr>';
4656: return $output;
1.23 raeburn 4657: }
4658:
4659: sub sorted_searchtitles {
4660: my %searchtitles = &Apache::lonlocal::texthash(
4661: 'uname' => 'username',
4662: 'lastname' => 'last name',
4663: 'lastfirst' => 'last name, first name',
4664: );
4665: my @titleorder = ('uname','lastname','lastfirst');
4666: return (\%searchtitles,\@titleorder);
4667: }
4668:
1.25 raeburn 4669: sub sorted_searchtypes {
4670: my %srchtypes_desc = (
4671: exact => 'is exact match',
4672: contains => 'contains ..',
4673: begins => 'begins with ..',
4674: );
4675: my @srchtypeorder = ('exact','begins','contains');
4676: return (\%srchtypes_desc,\@srchtypeorder);
4677: }
4678:
1.3 raeburn 4679: sub usertype_update_row {
4680: my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
4681: my $datatable;
4682: my $numinrow = 4;
4683: foreach my $type (@{$types}) {
4684: if (defined($usertypes->{$type})) {
4685: $$rownums ++;
4686: my $css_class = $$rownums%2?' class="LC_odd_row"':'';
4687: $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
4688: '</td><td class="LC_left_item"><table>';
4689: for (my $i=0; $i<@{$fields}; $i++) {
4690: my $rem = $i%($numinrow);
4691: if ($rem == 0) {
4692: if ($i > 0) {
4693: $datatable .= '</tr>';
4694: }
4695: $datatable .= '<tr>';
4696: }
4697: my $check = ' ';
1.39 raeburn 4698: if (ref($settings) eq 'HASH') {
4699: if (ref($settings->{'fields'}) eq 'HASH') {
4700: if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
4701: if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
4702: $check = ' checked="checked" ';
4703: }
1.3 raeburn 4704: }
4705: }
4706: }
4707:
4708: if ($i == @{$fields}-1) {
4709: my $colsleft = $numinrow - $rem;
4710: if ($colsleft > 1) {
4711: $datatable .= '<td colspan="'.$colsleft.'">';
4712: } else {
4713: $datatable .= '<td>';
4714: }
4715: } else {
4716: $datatable .= '<td>';
4717: }
1.8 raeburn 4718: $datatable .= '<span class="LC_nobreak"><label>'.
4719: '<input type="checkbox" name="updateable_'.$type.
4720: '_'.$fields->[$i].'" value="1"'.$check.'/>'.
4721: $fieldtitles->{$fields->[$i]}.'</label></span></td>';
1.3 raeburn 4722: }
4723: $datatable .= '</tr></table></td></tr>';
4724: }
4725: }
4726: return $datatable;
1.1 raeburn 4727: }
4728:
4729: sub modify_login {
1.9 raeburn 4730: my ($r,$dom,$confname,%domconfig) = @_;
1.168 raeburn 4731: my ($resulttext,$errors,$colchgtext,%changes,%colchanges,%newfile,%newurl,
4732: %curr_loginvia,%loginhash,@currlangs,@newlangs,$addedfile,%title,@offon);
4733: %title = ( coursecatalog => 'Display course catalog',
4734: adminmail => 'Display administrator E-mail address',
1.188 raeburn 4735: helpdesk => 'Display "Contact Helpdesk" link',
1.168 raeburn 4736: newuser => 'Link for visitors to create a user account',
4737: loginheader => 'Log-in box header');
4738: @offon = ('off','on');
1.112 raeburn 4739: if (ref($domconfig{login}) eq 'HASH') {
4740: if (ref($domconfig{login}{loginvia}) eq 'HASH') {
4741: foreach my $lonhost (keys(%{$domconfig{login}{loginvia}})) {
4742: $curr_loginvia{$lonhost} = $domconfig{login}{loginvia}{$lonhost};
4743: }
4744: }
4745: }
1.9 raeburn 4746: ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
4747: \%domconfig,\%loginhash);
1.188 raeburn 4748: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 4749: foreach my $item (@toggles) {
4750: $loginhash{login}{$item} = $env{'form.'.$item};
4751: }
1.41 raeburn 4752: $loginhash{login}{loginheader} = $env{'form.loginheader'};
1.6 raeburn 4753: if (ref($colchanges{'login'}) eq 'HASH') {
4754: $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
4755: \%loginhash);
4756: }
1.110 raeburn 4757:
1.149 raeburn 4758: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.128 raeburn 4759: my @loginvia_attribs = ('serverpath','custompath','exempt');
1.110 raeburn 4760: if (keys(%servers) > 1) {
4761: foreach my $lonhost (keys(%servers)) {
1.128 raeburn 4762: next if ($env{'form.'.$lonhost.'_server'} eq $lonhost);
4763: if (ref($curr_loginvia{$lonhost}) eq 'HASH') {
4764: if ($env{'form.'.$lonhost.'_server'} eq $curr_loginvia{$lonhost}{'server'}) {
4765: $loginhash{login}{loginvia}{$lonhost}{'server'} = $curr_loginvia{$lonhost}{'server'};
4766: } elsif ($curr_loginvia{$lonhost}{'server'} ne '') {
4767: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
4768: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
4769: $changes{'loginvia'}{$lonhost} = 1;
4770: } else {
4771: $loginhash{login}{loginvia}{$lonhost}{'server'} = '';
4772: $changes{'loginvia'}{$lonhost} = 1;
4773: }
4774: } else {
4775: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
4776: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
4777: $changes{'loginvia'}{$lonhost} = 1;
4778: }
4779: }
4780: if ($loginhash{login}{loginvia}{$lonhost}{'server'} eq '') {
4781: foreach my $item (@loginvia_attribs) {
4782: $loginhash{login}{loginvia}{$lonhost}{$item} = '';
4783: }
4784: } else {
4785: foreach my $item (@loginvia_attribs) {
4786: my $new = $env{'form.'.$lonhost.'_'.$item};
4787: if (($item eq 'serverpath') && ($new eq 'custom')) {
4788: $env{'form.'.$lonhost.'_custompath'} =~ s/\s+//g;
4789: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
4790: $new = '/';
4791: }
4792: }
4793: if (($item eq 'custompath') &&
4794: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
4795: $new = '';
4796: }
4797: if ($new ne $curr_loginvia{$lonhost}{$item}) {
4798: $changes{'loginvia'}{$lonhost} = 1;
4799: }
4800: if ($item eq 'exempt') {
4801: $new =~ s/^\s+//;
4802: $new =~ s/\s+$//;
4803: my @poss_ips = split(/\s*[,:]\s*/,$new);
4804: my @okips;
4805: foreach my $ip (@poss_ips) {
4806: if ($ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
4807: if (($1 <= 255) && ($2 <= 255) && ($3 <= 255) && ($4 <= 255)) {
4808: push(@okips,$ip);
4809: }
4810: }
4811: }
4812: if (@okips > 0) {
4813: $new = join(',',@okips);
4814: } else {
4815: $new = '';
4816: }
4817: }
4818: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
4819: }
4820: }
1.112 raeburn 4821: } else {
1.128 raeburn 4822: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
4823: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
1.112 raeburn 4824: $changes{'loginvia'}{$lonhost} = 1;
1.128 raeburn 4825: foreach my $item (@loginvia_attribs) {
4826: my $new = $env{'form.'.$lonhost.'_'.$item};
4827: if (($item eq 'serverpath') && ($new eq 'custom')) {
4828: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
4829: $new = '/';
4830: }
4831: }
4832: if (($item eq 'custompath') &&
4833: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
4834: $new = '';
4835: }
4836: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
4837: }
1.110 raeburn 4838: }
4839: }
4840: }
4841: }
1.119 raeburn 4842:
1.168 raeburn 4843: my $servadm = $r->dir_config('lonAdmEMail');
4844: my %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
4845: if (ref($domconfig{'login'}) eq 'HASH') {
4846: if (ref($domconfig{'login'}{'helpurl'}) eq 'HASH') {
4847: foreach my $lang (sort(keys(%{$domconfig{'login'}{'helpurl'}}))) {
4848: if ($lang eq 'nolang') {
4849: push(@currlangs,$lang);
4850: } elsif (defined($langchoices{$lang})) {
4851: push(@currlangs,$lang);
4852: } else {
4853: next;
4854: }
4855: }
4856: }
4857: }
4858: my @delurls = &Apache::loncommon::get_env_multiple('form.loginhelpurl_del');
4859: if (@currlangs > 0) {
4860: foreach my $lang (@currlangs) {
4861: if (grep(/^\Q$lang\E$/,@delurls)) {
4862: $changes{'helpurl'}{$lang} = 1;
4863: } elsif ($env{'form.loginhelpurl_'.$lang.'.filename'}) {
4864: $changes{'helpurl'}{$lang} = 1;
4865: $newfile{$lang} = $env{'form.loginhelpurl_'.$lang.'.filename'};
4866: push(@newlangs,$lang);
4867: } else {
4868: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
4869: }
4870: }
4871: }
4872: unless (grep(/^nolang$/,@currlangs)) {
4873: if ($env{'form.loginhelpurl_nolang.filename'}) {
4874: $changes{'helpurl'}{'nolang'} = 1;
4875: $newfile{'nolang'} = $env{'form.loginhelpurl_nolang.filename'};
4876: push(@newlangs,'nolang');
4877: }
4878: }
4879: if ($env{'form.loginhelpurl_add_lang'}) {
4880: if ((defined($langchoices{$env{'form.loginhelpurl_add_lang'}})) &&
4881: ($env{'form.loginhelpurl_add_file.filename'})) {
4882: $newfile{$env{'form.loginhelpurl_add_lang'}} = $env{'form.loginhelpurl_add_file.filename'};
4883: $addedfile = $env{'form.loginhelpurl_add_lang'};
4884: }
4885: }
4886: if ((@newlangs > 0) || ($addedfile)) {
4887: my $error;
4888: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
4889: if ($configuserok eq 'ok') {
4890: if ($switchserver) {
4891: $error = &mt("Upload of custom help file is not permitted to this server: [_1]",$switchserver);
4892: } elsif ($author_ok eq 'ok') {
4893: my @allnew = @newlangs;
4894: if ($addedfile ne '') {
4895: push(@allnew,$addedfile);
4896: }
4897: foreach my $lang (@allnew) {
4898: my $formelem = 'loginhelpurl_'.$lang;
4899: if ($lang eq $env{'form.loginhelpurl_add_lang'}) {
4900: $formelem = 'loginhelpurl_add_file';
4901: }
4902: (my $result,$newurl{$lang}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
4903: "help/$lang",'','',$newfile{$lang});
4904: if ($result eq 'ok') {
4905: $loginhash{'login'}{'helpurl'}{$lang} = $newurl{$lang};
4906: $changes{'helpurl'}{$lang} = 1;
4907: } else {
4908: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$newfile{$lang},$result);
4909: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
4910: if ((grep(/^\Q$lang\E$/,@currlangs)) &&
4911: (!grep(/^\Q$lang\E$/,@delurls))) {
4912:
4913: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
4914: }
4915: }
4916: }
4917: } else {
4918: $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);
4919: }
4920: } else {
4921: $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);
4922: }
4923: if ($error) {
4924: &Apache::lonnet::logthis($error);
4925: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
4926: }
4927: }
1.169 raeburn 4928: &process_captcha('login',\%changes,$loginhash{'login'},$domconfig{'login'});
1.168 raeburn 4929:
4930: my $defaulthelpfile = '/adm/loginproblems.html';
4931: my $defaulttext = &mt('Default in use');
4932:
1.1 raeburn 4933: my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
4934: $dom);
4935: if ($putresult eq 'ok') {
1.188 raeburn 4936: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 4937: my %defaultchecked = (
4938: 'coursecatalog' => 'on',
1.188 raeburn 4939: 'helpdesk' => 'on',
1.42 raeburn 4940: 'adminmail' => 'off',
1.43 raeburn 4941: 'newuser' => 'off',
1.42 raeburn 4942: );
1.55 raeburn 4943: if (ref($domconfig{'login'}) eq 'HASH') {
4944: foreach my $item (@toggles) {
4945: if ($defaultchecked{$item} eq 'on') {
4946: if (($domconfig{'login'}{$item} eq '0') &&
4947: ($env{'form.'.$item} eq '1')) {
4948: $changes{$item} = 1;
4949: } elsif (($domconfig{'login'}{$item} eq '' ||
4950: $domconfig{'login'}{$item} eq '1') &&
4951: ($env{'form.'.$item} eq '0')) {
4952: $changes{$item} = 1;
4953: }
4954: } elsif ($defaultchecked{$item} eq 'off') {
4955: if (($domconfig{'login'}{$item} eq '1') &&
4956: ($env{'form.'.$item} eq '0')) {
4957: $changes{$item} = 1;
4958: } elsif (($domconfig{'login'}{$item} eq '' ||
4959: $domconfig{'login'}{$item} eq '0') &&
4960: ($env{'form.'.$item} eq '1')) {
4961: $changes{$item} = 1;
4962: }
1.42 raeburn 4963: }
4964: }
1.41 raeburn 4965: }
1.6 raeburn 4966: if (keys(%changes) > 0 || $colchgtext) {
1.41 raeburn 4967: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.1 raeburn 4968: $resulttext = &mt('Changes made:').'<ul>';
4969: foreach my $item (sort(keys(%changes))) {
1.135 bisitz 4970: if ($item eq 'loginvia') {
1.112 raeburn 4971: if (ref($changes{$item}) eq 'HASH') {
4972: $resulttext .= '<li>'.&mt('Log-in page availability:').'<ul>';
4973: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
1.128 raeburn 4974: if (defined($servers{$loginhash{login}{loginvia}{$lonhost}{'server'}})) {
4975: if (ref($loginhash{login}{loginvia}{$lonhost}) eq 'HASH') {
4976: my $protocol = $Apache::lonnet::protocol{$env{'form.'.$lonhost.'_server'}};
4977: $protocol = 'http' if ($protocol ne 'https');
4978: my $target = $protocol.'://'.$servers{$env{'form.'.$lonhost.'_server'}};
4979:
4980: if ($loginhash{login}{loginvia}{$lonhost}{'serverpath'} eq 'custom') {
4981: $target .= $loginhash{login}{loginvia}{$lonhost}{'custompath'};
4982: } else {
4983: $target .= $loginhash{login}{loginvia}{$lonhost}{'serverpath'};
4984: }
4985: $resulttext .= '<li>'.&mt('Server: [_1] log-in page redirects to [_2].',$servers{$lonhost},'<a href="'.$target.'">'.$target.'</a>');
4986: if ($loginhash{login}{loginvia}{$lonhost}{'exempt'} ne '') {
4987: $resulttext .= ' '.&mt('No redirection for clients from following IPs:').' '.$loginhash{login}{loginvia}{$lonhost}{'exempt'};
4988: }
4989: $resulttext .= '</li>';
4990: } else {
4991: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$lonhost).'</li>';
4992: }
1.112 raeburn 4993: } else {
1.128 raeburn 4994: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$servers{$lonhost}).'</li>';
1.112 raeburn 4995: }
4996: }
1.128 raeburn 4997: $resulttext .= '</ul></li>';
1.112 raeburn 4998: }
1.168 raeburn 4999: } elsif ($item eq 'helpurl') {
5000: if (ref($changes{$item}) eq 'HASH') {
5001: foreach my $lang (sort(keys(%{$changes{$item}}))) {
5002: if (grep(/^\Q$lang\E$/,@delurls)) {
5003: my ($chg,$link);
5004: $link = &Apache::loncommon::modal_link($defaulthelpfile,$defaulttext,600,500);
5005: if ($lang eq 'nolang') {
5006: $chg = &mt('custom log-in help file removed for no preferred language; [_1]',$link);
5007: } else {
5008: $chg = &mt('custom log-in help file removed for specific language: [_1]; [_2]',$langchoices{$lang},$link);
5009: }
5010: $resulttext .= '<li>'.$chg.'</li>';
5011: } else {
5012: my $chg;
5013: if ($lang eq 'nolang') {
5014: $chg = &mt('custom log-in help file for no preferred language');
5015: } else {
5016: $chg = &mt('custom log-in help file for specific language: [_1]',$langchoices{$lang});
5017: }
5018: $resulttext .= '<li>'.&Apache::loncommon::modal_link(
5019: $loginhash{'login'}{'helpurl'}{$lang}.
5020: '?inhibitmenu=yes',$chg,600,500).
5021: '</li>';
5022: }
5023: }
5024: }
1.169 raeburn 5025: } elsif ($item eq 'captcha') {
5026: if (ref($loginhash{'login'}) eq 'HASH') {
5027: my $chgtxt;
5028: if ($loginhash{'login'}{$item} eq 'notused') {
5029: $chgtxt .= &mt('No CAPTCHA validation in use for helpdesk form.');
5030: } else {
5031: my %captchas = &captcha_phrases();
5032: if ($captchas{$loginhash{'login'}{$item}}) {
5033: $chgtxt .= &mt("Validation for helpdesk form set to $captchas{$loginhash{'login'}{$item}}.");
5034: } else {
5035: $chgtxt .= &mt('Validation for helpdesk form set to unknown type.');
5036: }
5037: }
5038: $resulttext .= '<li>'.$chgtxt.'</li>';
5039: }
5040: } elsif ($item eq 'recaptchakeys') {
5041: if (ref($loginhash{'login'}) eq 'HASH') {
5042: my ($privkey,$pubkey);
5043: if (ref($loginhash{'login'}{$item}) eq 'HASH') {
5044: $pubkey = $loginhash{'login'}{$item}{'public'};
5045: $privkey = $loginhash{'login'}{$item}{'private'};
5046: }
5047: my $chgtxt .= &mt('ReCAPTCHA keys changes').'<ul>';
5048: if (!$pubkey) {
5049: $chgtxt .= '<li>'.&mt('Public key deleted').'</li>';
5050: } else {
5051: $chgtxt .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
5052: }
5053: if (!$privkey) {
5054: $chgtxt .= '<li>'.&mt('Private key deleted').'</li>';
5055: } else {
5056: $chgtxt .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
5057: }
5058: $chgtxt .= '</ul>';
5059: $resulttext .= '<li>'.$chgtxt.'</li>';
5060: }
1.41 raeburn 5061: } else {
5062: $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
5063: }
1.1 raeburn 5064: }
1.6 raeburn 5065: $resulttext .= $colchgtext.'</ul>';
1.1 raeburn 5066: } else {
5067: $resulttext = &mt('No changes made to log-in page settings');
5068: }
5069: } else {
1.11 albertel 5070: $resulttext = '<span class="LC_error">'.
5071: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 5072: }
1.6 raeburn 5073: if ($errors) {
1.9 raeburn 5074: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.6 raeburn 5075: $errors.'</ul>';
5076: }
5077: return $resulttext;
5078: }
5079:
5080: sub color_font_choices {
5081: my %choices =
5082: &Apache::lonlocal::texthash (
5083: img => "Header",
5084: bgs => "Background colors",
5085: links => "Link colors",
1.55 raeburn 5086: images => "Images",
1.6 raeburn 5087: font => "Font color",
1.97 tempelho 5088: fontmenu => "Font Menu",
1.76 raeburn 5089: pgbg => "Page",
1.6 raeburn 5090: tabbg => "Header",
5091: sidebg => "Border",
5092: link => "Link",
5093: alink => "Active link",
5094: vlink => "Visited link",
5095: );
5096: return %choices;
5097: }
5098:
5099: sub modify_rolecolors {
1.9 raeburn 5100: my ($r,$dom,$confname,$roles,%domconfig) = @_;
1.6 raeburn 5101: my ($resulttext,%rolehash);
5102: $rolehash{'rolecolors'} = {};
1.55 raeburn 5103: if (ref($domconfig{'rolecolors'}) ne 'HASH') {
5104: if ($domconfig{'rolecolors'} eq '') {
5105: $domconfig{'rolecolors'} = {};
5106: }
5107: }
1.9 raeburn 5108: my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
1.6 raeburn 5109: $domconfig{'rolecolors'},$rolehash{'rolecolors'});
5110: my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
5111: $dom);
5112: if ($putresult eq 'ok') {
5113: if (keys(%changes) > 0) {
1.41 raeburn 5114: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.6 raeburn 5115: $resulttext = &display_colorchgs($dom,\%changes,$roles,
5116: $rolehash{'rolecolors'});
5117: } else {
5118: $resulttext = &mt('No changes made to default color schemes');
5119: }
5120: } else {
1.11 albertel 5121: $resulttext = '<span class="LC_error">'.
5122: &mt('An error occurred: [_1]',$putresult).'</span>';
1.6 raeburn 5123: }
5124: if ($errors) {
5125: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
5126: $errors.'</ul>';
5127: }
5128: return $resulttext;
5129: }
5130:
5131: sub modify_colors {
1.9 raeburn 5132: my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
1.12 raeburn 5133: my (%changes,%choices);
1.51 raeburn 5134: my @bgs;
1.6 raeburn 5135: my @links = ('link','alink','vlink');
1.41 raeburn 5136: my @logintext;
1.6 raeburn 5137: my @images;
5138: my $servadm = $r->dir_config('lonAdmEMail');
5139: my $errors;
1.200 ! raeburn 5140: my %defaults;
1.6 raeburn 5141: foreach my $role (@{$roles}) {
5142: if ($role eq 'login') {
1.12 raeburn 5143: %choices = &login_choices();
1.41 raeburn 5144: @logintext = ('textcol','bgcol');
1.12 raeburn 5145: } else {
5146: %choices = &color_font_choices();
5147: }
5148: if ($role eq 'login') {
1.41 raeburn 5149: @images = ('img','logo','domlogo','login');
1.51 raeburn 5150: @bgs = ('pgbg','mainbg','sidebg');
1.6 raeburn 5151: } else {
5152: @images = ('img');
1.200 ! raeburn 5153: @bgs = ('pgbg','tabbg','sidebg');
! 5154: }
! 5155: my %defaults = &role_defaults($role,\@bgs,\@links,\@images,\@logintext);
! 5156: unless ($env{'form.'.$role.'_font'} eq $defaults{'font'}) {
! 5157: $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
! 5158: }
! 5159: if ($role eq 'login') {
! 5160: foreach my $item (@logintext) {
! 5161: unless ($env{'form.'.$role.'_'.$item} eq $defaults{'logintext'}{$item}) {
! 5162: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
! 5163: }
! 5164: }
! 5165: } else {
! 5166: unless($env{'form.'.$role.'_fontmenu'} eq $defaults{'fontmenu'}) {
! 5167: $confhash->{$role}{'fontmenu'} = $env{'form.'.$role.'_fontmenu'};
! 5168: }
1.6 raeburn 5169: }
1.200 ! raeburn 5170: foreach my $item (@bgs) {
! 5171: unless ($env{'form.'.$role.'_'.$item} eq $defaults{'bgs'}{$item} ) {
! 5172: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
! 5173: }
! 5174: }
! 5175: foreach my $item (@links) {
! 5176: unless ($env{'form.'.$role.'_'.$item} eq $defaults{'links'}{$item}) {
! 5177: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
! 5178: }
1.6 raeburn 5179: }
1.46 raeburn 5180: my ($configuserok,$author_ok,$switchserver) =
5181: &config_check($dom,$confname,$servadm);
1.9 raeburn 5182: my ($width,$height) = &thumb_dimensions();
1.40 raeburn 5183: if (ref($domconfig->{$role}) ne 'HASH') {
5184: $domconfig->{$role} = {};
5185: }
1.8 raeburn 5186: foreach my $img (@images) {
1.70 raeburn 5187: if (($role eq 'login') && (($img eq 'img') || ($img eq 'logo'))) {
5188: if (defined($env{'form.login_showlogo_'.$img})) {
5189: $confhash->{$role}{'showlogo'}{$img} = 1;
5190: } else {
5191: $confhash->{$role}{'showlogo'}{$img} = 0;
5192: }
5193: }
1.18 albertel 5194: if ( ! $env{'form.'.$role.'_'.$img.'.filename'}
5195: && !defined($domconfig->{$role}{$img})
5196: && !$env{'form.'.$role.'_del_'.$img}
5197: && $env{'form.'.$role.'_import_'.$img}) {
5198: # import the old configured image from the .tab setting
5199: # if they haven't provided a new one
5200: $domconfig->{$role}{$img} =
5201: $env{'form.'.$role.'_import_'.$img};
5202: }
1.6 raeburn 5203: if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
1.9 raeburn 5204: my $error;
1.6 raeburn 5205: if ($configuserok eq 'ok') {
1.9 raeburn 5206: if ($switchserver) {
1.12 raeburn 5207: $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
1.9 raeburn 5208: } else {
5209: if ($author_ok eq 'ok') {
5210: my ($result,$logourl) =
5211: &publishlogo($r,'upload',$role.'_'.$img,
5212: $dom,$confname,$img,$width,$height);
5213: if ($result eq 'ok') {
5214: $confhash->{$role}{$img} = $logourl;
1.12 raeburn 5215: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 5216: } else {
1.12 raeburn 5217: $error = &mt("Upload of [_1] image for $role page(s) failed because an error occurred publishing the file in RES space. Error was: [_2].",$choices{img},$result);
1.9 raeburn 5218: }
5219: } else {
1.46 raeburn 5220: $error = &mt("Upload of [_1] image for $role page(s) failed because an author role could not be assigned to a Domain Configuration user ([_2]) in domain: [_3]. Error was: [_4].",$choices{$img},$confname,$dom,$author_ok);
1.6 raeburn 5221: }
5222: }
5223: } else {
1.46 raeburn 5224: $error = &mt("Upload of [_1] image for $role page(s) failed because a Domain Configuration user ([_2]) could not be created in domain: [_3]. Error was: [_4].",$choices{$img},$confname,$dom,$configuserok);
1.9 raeburn 5225: }
5226: if ($error) {
1.8 raeburn 5227: &Apache::lonnet::logthis($error);
1.11 albertel 5228: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
1.8 raeburn 5229: }
5230: } elsif ($domconfig->{$role}{$img} ne '') {
1.9 raeburn 5231: if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
5232: my $error;
5233: if ($configuserok eq 'ok') {
5234: # is confname an author?
5235: if ($switchserver eq '') {
5236: if ($author_ok eq 'ok') {
5237: my ($result,$logourl) =
5238: &publishlogo($r,'copy',$domconfig->{$role}{$img},
5239: $dom,$confname,$img,$width,$height);
5240: if ($result eq 'ok') {
5241: $confhash->{$role}{$img} = $logourl;
1.18 albertel 5242: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 5243: }
5244: }
5245: }
5246: }
1.6 raeburn 5247: }
5248: }
5249: }
5250: if (ref($domconfig) eq 'HASH') {
5251: if (ref($domconfig->{$role}) eq 'HASH') {
5252: foreach my $img (@images) {
5253: if ($domconfig->{$role}{$img} ne '') {
5254: if ($env{'form.'.$role.'_del_'.$img}) {
5255: $confhash->{$role}{$img} = '';
1.12 raeburn 5256: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 5257: } else {
1.9 raeburn 5258: if ($confhash->{$role}{$img} eq '') {
5259: $confhash->{$role}{$img} = $domconfig->{$role}{$img};
5260: }
1.6 raeburn 5261: }
5262: } else {
5263: if ($env{'form.'.$role.'_del_'.$img}) {
5264: $confhash->{$role}{$img} = '';
1.12 raeburn 5265: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 5266: }
5267: }
1.70 raeburn 5268: if (($role eq 'login') && (($img eq 'logo') || ($img eq 'img'))) {
5269: if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') {
5270: if ($confhash->{$role}{'showlogo'}{$img} ne
5271: $domconfig->{$role}{'showlogo'}{$img}) {
5272: $changes{$role}{'showlogo'}{$img} = 1;
5273: }
5274: } else {
5275: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
5276: $changes{$role}{'showlogo'}{$img} = 1;
5277: }
5278: }
5279: }
5280: }
1.6 raeburn 5281: if ($domconfig->{$role}{'font'} ne '') {
5282: if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
5283: $changes{$role}{'font'} = 1;
5284: }
5285: } else {
5286: if ($confhash->{$role}{'font'}) {
5287: $changes{$role}{'font'} = 1;
5288: }
5289: }
1.107 raeburn 5290: if ($role ne 'login') {
5291: if ($domconfig->{$role}{'fontmenu'} ne '') {
5292: if ($confhash->{$role}{'fontmenu'} ne $domconfig->{$role}{'fontmenu'}) {
5293: $changes{$role}{'fontmenu'} = 1;
5294: }
5295: } else {
5296: if ($confhash->{$role}{'fontmenu'}) {
5297: $changes{$role}{'fontmenu'} = 1;
5298: }
1.97 tempelho 5299: }
5300: }
1.6 raeburn 5301: foreach my $item (@bgs) {
5302: if ($domconfig->{$role}{$item} ne '') {
5303: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
5304: $changes{$role}{'bgs'}{$item} = 1;
5305: }
5306: } else {
5307: if ($confhash->{$role}{$item}) {
5308: $changes{$role}{'bgs'}{$item} = 1;
5309: }
5310: }
5311: }
5312: foreach my $item (@links) {
5313: if ($domconfig->{$role}{$item} ne '') {
5314: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
5315: $changes{$role}{'links'}{$item} = 1;
5316: }
5317: } else {
5318: if ($confhash->{$role}{$item}) {
5319: $changes{$role}{'links'}{$item} = 1;
5320: }
5321: }
5322: }
1.41 raeburn 5323: foreach my $item (@logintext) {
5324: if ($domconfig->{$role}{$item} ne '') {
5325: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
5326: $changes{$role}{'logintext'}{$item} = 1;
5327: }
5328: } else {
5329: if ($confhash->{$role}{$item}) {
5330: $changes{$role}{'logintext'}{$item} = 1;
5331: }
5332: }
5333: }
1.6 raeburn 5334: } else {
5335: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 5336: \@logintext,$confhash,\%changes);
1.6 raeburn 5337: }
5338: } else {
5339: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 5340: \@logintext,$confhash,\%changes);
1.6 raeburn 5341: }
5342: }
5343: return ($errors,%changes);
5344: }
5345:
1.46 raeburn 5346: sub config_check {
5347: my ($dom,$confname,$servadm) = @_;
5348: my ($configuserok,$author_ok,$switchserver,%currroles);
5349: my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
5350: ($configuserok,%currroles) = &check_configuser($uhome,$dom,
5351: $confname,$servadm);
5352: if ($configuserok eq 'ok') {
5353: $switchserver = &check_switchserver($dom,$confname);
5354: if ($switchserver eq '') {
5355: $author_ok = &check_authorstatus($dom,$confname,%currroles);
5356: }
5357: }
5358: return ($configuserok,$author_ok,$switchserver);
5359: }
5360:
1.6 raeburn 5361: sub default_change_checker {
1.41 raeburn 5362: my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
1.6 raeburn 5363: foreach my $item (@{$links}) {
5364: if ($confhash->{$role}{$item}) {
5365: $changes->{$role}{'links'}{$item} = 1;
5366: }
5367: }
5368: foreach my $item (@{$bgs}) {
5369: if ($confhash->{$role}{$item}) {
5370: $changes->{$role}{'bgs'}{$item} = 1;
5371: }
5372: }
1.41 raeburn 5373: foreach my $item (@{$logintext}) {
5374: if ($confhash->{$role}{$item}) {
5375: $changes->{$role}{'logintext'}{$item} = 1;
5376: }
5377: }
1.6 raeburn 5378: foreach my $img (@{$images}) {
5379: if ($env{'form.'.$role.'_del_'.$img}) {
5380: $confhash->{$role}{$img} = '';
1.12 raeburn 5381: $changes->{$role}{'images'}{$img} = 1;
1.6 raeburn 5382: }
1.70 raeburn 5383: if ($role eq 'login') {
5384: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
5385: $changes->{$role}{'showlogo'}{$img} = 1;
5386: }
5387: }
1.6 raeburn 5388: }
5389: if ($confhash->{$role}{'font'}) {
5390: $changes->{$role}{'font'} = 1;
5391: }
1.48 raeburn 5392: }
1.6 raeburn 5393:
5394: sub display_colorchgs {
5395: my ($dom,$changes,$roles,$confhash) = @_;
5396: my (%choices,$resulttext);
5397: if (!grep(/^login$/,@{$roles})) {
5398: $resulttext = &mt('Changes made:').'<br />';
5399: }
5400: foreach my $role (@{$roles}) {
5401: if ($role eq 'login') {
5402: %choices = &login_choices();
5403: } else {
5404: %choices = &color_font_choices();
5405: }
5406: if (ref($changes->{$role}) eq 'HASH') {
5407: if ($role ne 'login') {
5408: $resulttext .= '<h4>'.&mt($role).'</h4>';
5409: }
5410: foreach my $key (sort(keys(%{$changes->{$role}}))) {
5411: if ($role ne 'login') {
5412: $resulttext .= '<ul>';
5413: }
5414: if (ref($changes->{$role}{$key}) eq 'HASH') {
5415: if ($role ne 'login') {
5416: $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
5417: }
5418: foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
1.70 raeburn 5419: if (($role eq 'login') && ($key eq 'showlogo')) {
5420: if ($confhash->{$role}{$key}{$item}) {
5421: $resulttext .= '<li>'.&mt("$choices{$item} set to be displayed").'</li>';
5422: } else {
5423: $resulttext .= '<li>'.&mt("$choices{$item} set to not be displayed").'</li>';
5424: }
5425: } elsif ($confhash->{$role}{$item} eq '') {
1.6 raeburn 5426: $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
5427: } else {
1.12 raeburn 5428: my $newitem = $confhash->{$role}{$item};
5429: if ($key eq 'images') {
5430: $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" valign="bottom" />';
5431: }
5432: $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
1.6 raeburn 5433: }
5434: }
5435: if ($role ne 'login') {
5436: $resulttext .= '</ul></li>';
5437: }
5438: } else {
5439: if ($confhash->{$role}{$key} eq '') {
5440: $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
5441: } else {
5442: $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
5443: }
5444: }
5445: if ($role ne 'login') {
5446: $resulttext .= '</ul>';
5447: }
5448: }
5449: }
5450: }
1.3 raeburn 5451: return $resulttext;
1.1 raeburn 5452: }
5453:
1.9 raeburn 5454: sub thumb_dimensions {
5455: return ('200','50');
5456: }
5457:
1.16 raeburn 5458: sub check_dimensions {
5459: my ($inputfile) = @_;
5460: my ($fullwidth,$fullheight);
5461: if ($inputfile =~ m|^[/\w.\-]+$|) {
5462: if (open(PIPE,"identify $inputfile 2>&1 |")) {
5463: my $imageinfo = <PIPE>;
5464: if (!close(PIPE)) {
5465: &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
5466: }
5467: chomp($imageinfo);
5468: my ($fullsize) =
1.21 raeburn 5469: ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
1.16 raeburn 5470: if ($fullsize) {
5471: ($fullwidth,$fullheight) = split(/x/,$fullsize);
5472: }
5473: }
5474: }
5475: return ($fullwidth,$fullheight);
5476: }
5477:
1.9 raeburn 5478: sub check_configuser {
5479: my ($uhome,$dom,$confname,$servadm) = @_;
5480: my ($configuserok,%currroles);
5481: if ($uhome eq 'no_host') {
5482: srand( time() ^ ($$ + ($$ << 15)) ); # Seed rand.
5483: my $configpass = &LONCAPA::Enrollment::create_password();
5484: $configuserok =
5485: &Apache::lonnet::modifyuser($dom,$confname,'','internal',
5486: $configpass,'','','','','',undef,$servadm);
5487: } else {
5488: $configuserok = 'ok';
5489: %currroles =
5490: &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
5491: }
5492: return ($configuserok,%currroles);
5493: }
5494:
5495: sub check_authorstatus {
5496: my ($dom,$confname,%currroles) = @_;
5497: my $author_ok;
1.40 raeburn 5498: if (!$currroles{':'.$dom.':au'}) {
1.9 raeburn 5499: my $start = time;
5500: my $end = 0;
5501: $author_ok =
5502: &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
1.47 raeburn 5503: 'au',$end,$start,'','','domconfig');
1.9 raeburn 5504: } else {
5505: $author_ok = 'ok';
5506: }
5507: return $author_ok;
5508: }
5509:
5510: sub publishlogo {
1.46 raeburn 5511: my ($r,$action,$formname,$dom,$confname,$subdir,$thumbwidth,$thumbheight,$savefileas) = @_;
1.9 raeburn 5512: my ($output,$fname,$logourl);
5513: if ($action eq 'upload') {
5514: $fname=$env{'form.'.$formname.'.filename'};
5515: chop($env{'form.'.$formname});
5516: } else {
5517: ($fname) = ($formname =~ /([^\/]+)$/);
5518: }
1.46 raeburn 5519: if ($savefileas ne '') {
5520: $fname = $savefileas;
5521: }
1.9 raeburn 5522: $fname=&Apache::lonnet::clean_filename($fname);
5523: # See if there is anything left
5524: unless ($fname) { return ('error: no uploaded file'); }
5525: $fname="$subdir/$fname";
1.164 raeburn 5526: my $docroot=$r->dir_config('lonDocRoot');
5527: my $filepath="$docroot/priv";
5528: my $relpath = "$dom/$confname";
1.9 raeburn 5529: my ($fnamepath,$file,$fetchthumb);
5530: $file=$fname;
5531: if ($fname=~m|/|) {
5532: ($fnamepath,$file) = ($fname =~ m|^(.*)/([^/]+)$|);
5533: }
1.164 raeburn 5534: my @parts=split(/\//,"$filepath/$relpath/$fnamepath");
1.9 raeburn 5535: my $count;
1.164 raeburn 5536: for ($count=5;$count<=$#parts;$count++) {
1.9 raeburn 5537: $filepath.="/$parts[$count]";
5538: if ((-e $filepath)!=1) {
5539: mkdir($filepath,02770);
5540: }
5541: }
5542: # Check for bad extension and disallow upload
5543: if ($file=~/\.(\w+)$/ &&
5544: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
5545: $output =
5546: &mt('Invalid file extension ([_1]) - reserved for LONCAPA use.',$1);
5547: } elsif ($file=~/\.(\w+)$/ &&
5548: !defined(&Apache::loncommon::fileembstyle($1))) {
5549: $output = &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
5550: } elsif ($file=~/\.(\d+)\.(\w+)$/) {
1.195 bisitz 5551: $output = &mt('Filename not allowed - rename the file to remove the number immediately before the file extension([_1]) and re-upload.',$2);
1.9 raeburn 5552: } elsif (-d "$filepath/$file") {
1.195 bisitz 5553: $output = &mt('Filename is a directory name - rename the file and re-upload');
1.9 raeburn 5554: } else {
5555: my $source = $filepath.'/'.$file;
5556: my $logfile;
5557: if (!open($logfile,">>$source".'.log')) {
1.196 raeburn 5558: return (&mt('No write permission to Authoring Space'));
1.9 raeburn 5559: }
5560: print $logfile
5561: "\n================= Publish ".localtime()." ================\n".
5562: $env{'user.name'}.':'.$env{'user.domain'}."\n";
5563: # Save the file
5564: if (!open(FH,'>'.$source)) {
5565: &Apache::lonnet::logthis('Failed to create '.$source);
5566: return (&mt('Failed to create file'));
5567: }
5568: if ($action eq 'upload') {
5569: if (!print FH ($env{'form.'.$formname})) {
5570: &Apache::lonnet::logthis('Failed to write to '.$source);
5571: return (&mt('Failed to write file'));
5572: }
5573: } else {
5574: my $original = &Apache::lonnet::filelocation('',$formname);
5575: if(!copy($original,$source)) {
5576: &Apache::lonnet::logthis('Failed to copy '.$original.' to '.$source);
5577: return (&mt('Failed to write file'));
5578: }
5579: }
5580: close(FH);
5581: chmod(0660, $source); # Permissions to rw-rw---.
5582:
5583: my $targetdir=$docroot.'/res/'.$dom.'/'.$confname .'/'.$fnamepath;
5584: my $copyfile=$targetdir.'/'.$file;
5585:
5586: my @parts=split(/\//,$targetdir);
5587: my $path="/$parts[1]/$parts[2]/$parts[3]/$parts[4]";
5588: for (my $count=5;$count<=$#parts;$count++) {
5589: $path.="/$parts[$count]";
5590: if (!-e $path) {
5591: print $logfile "\nCreating directory ".$path;
5592: mkdir($path,02770);
5593: }
5594: }
5595: my $versionresult;
5596: if (-e $copyfile) {
5597: $versionresult = &logo_versioning($targetdir,$file,$logfile);
5598: } else {
5599: $versionresult = 'ok';
5600: }
5601: if ($versionresult eq 'ok') {
5602: if (copy($source,$copyfile)) {
5603: print $logfile "\nCopied original source to ".$copyfile."\n";
5604: $output = 'ok';
5605: $logourl = '/res/'.$dom.'/'.$confname.'/'.$fname;
1.155 raeburn 5606: push(@{$modified_urls},[$copyfile,$source]);
5607: my $metaoutput =
5608: &write_metadata($dom,$confname,$formname,$targetdir,$file,$logfile);
5609: unless ($registered_cleanup) {
5610: my $handlers = $r->get_handlers('PerlCleanupHandler');
5611: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
5612: $registered_cleanup=1;
5613: }
1.9 raeburn 5614: } else {
5615: print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";
5616: $output = &mt('Failed to copy file to RES space').", $!";
5617: }
5618: if (($thumbwidth =~ /^\d+$/) && ($thumbheight =~ /^\d+$/)) {
5619: my $inputfile = $filepath.'/'.$file;
5620: my $outfile = $filepath.'/'.'tn-'.$file;
1.16 raeburn 5621: my ($fullwidth,$fullheight) = &check_dimensions($inputfile);
5622: if ($fullwidth ne '' && $fullheight ne '') {
5623: if ($fullwidth > $thumbwidth && $fullheight > $thumbheight) {
5624: my $thumbsize = $thumbwidth.'x'.$thumbheight;
5625: system("convert -sample $thumbsize $inputfile $outfile");
5626: chmod(0660, $filepath.'/tn-'.$file);
5627: if (-e $outfile) {
5628: my $copyfile=$targetdir.'/tn-'.$file;
5629: if (copy($outfile,$copyfile)) {
5630: print $logfile "\nCopied source to ".$copyfile."\n";
1.155 raeburn 5631: my $thumb_metaoutput =
5632: &write_metadata($dom,$confname,$formname,
5633: $targetdir,'tn-'.$file,$logfile);
5634: push(@{$modified_urls},[$copyfile,$outfile]);
5635: unless ($registered_cleanup) {
5636: my $handlers = $r->get_handlers('PerlCleanupHandler');
5637: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
5638: $registered_cleanup=1;
5639: }
1.16 raeburn 5640: } else {
5641: print $logfile "\nUnable to write ".$copyfile.
5642: ':'.$!."\n";
5643: }
5644: }
1.9 raeburn 5645: }
5646: }
5647: }
5648: } else {
5649: $output = $versionresult;
5650: }
5651: }
5652: return ($output,$logourl);
5653: }
5654:
5655: sub logo_versioning {
5656: my ($targetdir,$file,$logfile) = @_;
5657: my $target = $targetdir.'/'.$file;
5658: my ($maxversion,$fn,$extn,$output);
5659: $maxversion = 0;
5660: if ($file =~ /^(.+)\.(\w+)$/) {
5661: $fn=$1;
5662: $extn=$2;
5663: }
5664: opendir(DIR,$targetdir);
5665: while (my $filename=readdir(DIR)) {
5666: if ($filename=~/\Q$fn\E\.(\d+)\.\Q$extn\E$/) {
5667: $maxversion=($1>$maxversion)?$1:$maxversion;
5668: }
5669: }
5670: $maxversion++;
5671: print $logfile "\nCreating old version ".$maxversion."\n";
5672: my $copyfile=$targetdir.'/'.$fn.'.'.$maxversion.'.'.$extn;
5673: if (copy($target,$copyfile)) {
5674: print $logfile "Copied old target to ".$copyfile."\n";
5675: $copyfile=$copyfile.'.meta';
5676: if (copy($target.'.meta',$copyfile)) {
5677: print $logfile "Copied old target metadata to ".$copyfile."\n";
5678: $output = 'ok';
5679: } else {
5680: print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";
5681: $output = &mt('Failed to copy old meta').", $!, ";
5682: }
5683: } else {
5684: print $logfile "Unable to write ".$copyfile.':'.$!."\n";
5685: $output = &mt('Failed to copy old target').", $!, ";
5686: }
5687: return $output;
5688: }
5689:
5690: sub write_metadata {
5691: my ($dom,$confname,$formname,$targetdir,$file,$logfile) = @_;
5692: my (%metadatafields,%metadatakeys,$output);
5693: $metadatafields{'title'}=$formname;
5694: $metadatafields{'creationdate'}=time;
5695: $metadatafields{'lastrevisiondate'}=time;
5696: $metadatafields{'copyright'}='public';
5697: $metadatafields{'modifyinguser'}=$env{'user.name'}.':'.
5698: $env{'user.domain'};
5699: $metadatafields{'authorspace'}=$confname.':'.$dom;
5700: $metadatafields{'domain'}=$dom;
5701: {
5702: print $logfile "\nWrite metadata file for ".$targetdir.'/'.$file;
5703: my $mfh;
1.155 raeburn 5704: if (open($mfh,'>'.$targetdir.'/'.$file.'.meta')) {
1.184 raeburn 5705: foreach (sort(keys(%metadatafields))) {
1.155 raeburn 5706: unless ($_=~/\./) {
5707: my $unikey=$_;
5708: $unikey=~/^([A-Za-z]+)/;
5709: my $tag=$1;
5710: $tag=~tr/A-Z/a-z/;
5711: print $mfh "\n\<$tag";
5712: foreach (split(/\,/,$metadatakeys{$unikey})) {
5713: my $value=$metadatafields{$unikey.'.'.$_};
5714: $value=~s/\"/\'\'/g;
5715: print $mfh ' '.$_.'="'.$value.'"';
5716: }
5717: print $mfh '>'.
5718: &HTML::Entities::encode($metadatafields{$unikey},'<>&"')
5719: .'</'.$tag.'>';
5720: }
5721: }
5722: $output = 'ok';
5723: print $logfile "\nWrote metadata";
5724: close($mfh);
5725: } else {
5726: print $logfile "\nFailed to open metadata file";
1.9 raeburn 5727: $output = &mt('Could not write metadata');
5728: }
5729: }
1.155 raeburn 5730: return $output;
5731: }
5732:
5733: sub notifysubscribed {
5734: foreach my $targetsource (@{$modified_urls}){
5735: next unless (ref($targetsource) eq 'ARRAY');
5736: my ($target,$source)=@{$targetsource};
5737: if ($source ne '') {
5738: if (open(my $logfh,'>>'.$source.'.log')) {
5739: print $logfh "\nCleanup phase: Notifications\n";
5740: my @subscribed=&subscribed_hosts($target);
5741: foreach my $subhost (@subscribed) {
5742: print $logfh "\nNotifying host ".$subhost.':';
5743: my $reply=&Apache::lonnet::critical('update:'.$target,$subhost);
5744: print $logfh $reply;
5745: }
5746: my @subscribedmeta=&subscribed_hosts("$target.meta");
5747: foreach my $subhost (@subscribedmeta) {
5748: print $logfh "\nNotifying host for metadata only ".$subhost.':';
5749: my $reply=&Apache::lonnet::critical('update:'.$target.'.meta',
5750: $subhost);
5751: print $logfh $reply;
5752: }
5753: print $logfh "\n============ Done ============\n";
1.160 raeburn 5754: close($logfh);
1.155 raeburn 5755: }
5756: }
5757: }
5758: return OK;
5759: }
5760:
5761: sub subscribed_hosts {
5762: my ($target) = @_;
5763: my @subscribed;
5764: if (open(my $fh,"<$target.subscription")) {
5765: while (my $subline=<$fh>) {
5766: if ($subline =~ /^($match_lonid):/) {
5767: my $host = $1;
5768: if ($host ne $Apache::lonnet::perlvar{'lonHostID'}) {
5769: unless (grep(/^\Q$host\E$/,@subscribed)) {
5770: push(@subscribed,$host);
5771: }
5772: }
5773: }
5774: }
5775: }
5776: return @subscribed;
1.9 raeburn 5777: }
5778:
5779: sub check_switchserver {
5780: my ($dom,$confname) = @_;
5781: my ($allowed,$switchserver);
5782: my $home = &Apache::lonnet::homeserver($confname,$dom);
5783: if ($home eq 'no_host') {
5784: $home = &Apache::lonnet::domain($dom,'primary');
5785: }
5786: my @ids=&Apache::lonnet::current_machine_ids();
1.10 albertel 5787: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
5788: if (!$allowed) {
1.180 raeburn 5789: $switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role=dc./'.$dom.'/&destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
1.9 raeburn 5790: }
5791: return $switchserver;
5792: }
5793:
1.1 raeburn 5794: sub modify_quotas {
1.86 raeburn 5795: my ($dom,$action,%domconfig) = @_;
1.101 raeburn 5796: my ($context,@usertools,@options,%validations,%titles,%confhash,%toolshash,
5797: %limithash,$toolregexp,%conditions,$resulttext,%changes);
1.86 raeburn 5798: if ($action eq 'quotas') {
5799: $context = 'tools';
1.163 raeburn 5800: } else {
1.86 raeburn 5801: $context = $action;
5802: }
5803: if ($context eq 'requestcourses') {
1.98 raeburn 5804: @usertools = ('official','unofficial','community');
1.106 raeburn 5805: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 5806: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
5807: %titles = &courserequest_titles();
5808: $toolregexp = join('|',@usertools);
5809: %conditions = &courserequest_conditions();
1.163 raeburn 5810: } elsif ($context eq 'requestauthor') {
5811: @usertools = ('author');
5812: %titles = &authorrequest_titles();
1.86 raeburn 5813: } else {
1.162 raeburn 5814: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 5815: %titles = &tool_titles();
1.86 raeburn 5816: }
1.72 raeburn 5817: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.44 raeburn 5818: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 5819: foreach my $key (keys(%env)) {
1.101 raeburn 5820: if ($context eq 'requestcourses') {
5821: if ($key =~ /^form\.crsreq_($toolregexp)_(.+)$/) {
5822: my $item = $1;
5823: my $type = $2;
5824: if ($type =~ /^limit_(.+)/) {
5825: $limithash{$item}{$1} = $env{$key};
5826: } else {
5827: $confhash{$item}{$type} = $env{$key};
5828: }
5829: }
1.163 raeburn 5830: } elsif ($context eq 'requestauthor') {
5831: if ($key =~ /^\Qform.authorreq_\E(.+)$/) {
5832: $confhash{$1} = $env{$key};
5833: }
1.101 raeburn 5834: } else {
1.86 raeburn 5835: if ($key =~ /^form\.quota_(.+)$/) {
5836: $confhash{'defaultquota'}{$1} = $env{$key};
1.197 raeburn 5837: } elsif ($key =~ /^form\.authorquota_(.+)$/) {
5838: $confhash{'authorquota'}{$1} = $env{$key};
5839: } elsif ($key =~ /^form\.\Q$context\E_(.+)$/) {
1.101 raeburn 5840: @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key);
5841: }
1.72 raeburn 5842: }
5843: }
1.163 raeburn 5844: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.102 raeburn 5845: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.reqapprovalnotify');
5846: @approvalnotify = sort(@approvalnotify);
5847: $confhash{'notify'}{'approval'} = join(',',@approvalnotify);
5848: if (ref($domconfig{$action}) eq 'HASH') {
5849: if (ref($domconfig{$action}{'notify'}) eq 'HASH') {
5850: if ($domconfig{$action}{'notify'}{'approval'} ne $confhash{'notify'}{'approval'}) {
5851: $changes{'notify'}{'approval'} = 1;
5852: }
5853: } else {
1.144 raeburn 5854: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 5855: $changes{'notify'}{'approval'} = 1;
5856: }
5857: }
5858: } else {
1.144 raeburn 5859: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 5860: $changes{'notify'}{'approval'} = 1;
5861: }
5862: }
5863: } else {
1.86 raeburn 5864: $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
1.197 raeburn 5865: $confhash{'authorquota'}{'default'} = $env{'form.authorquota'};
1.86 raeburn 5866: }
1.72 raeburn 5867: foreach my $item (@usertools) {
5868: foreach my $type (@{$types},'default','_LC_adv') {
1.104 raeburn 5869: my $unset;
1.101 raeburn 5870: if ($context eq 'requestcourses') {
1.104 raeburn 5871: $unset = '0';
5872: if ($type eq '_LC_adv') {
5873: $unset = '';
5874: }
1.101 raeburn 5875: if ($confhash{$item}{$type} eq 'autolimit') {
5876: $confhash{$item}{$type} .= '=';
5877: unless ($limithash{$item}{$type} =~ /\D/) {
5878: $confhash{$item}{$type} .= $limithash{$item}{$type};
5879: }
5880: }
1.163 raeburn 5881: } elsif ($context eq 'requestauthor') {
5882: $unset = '0';
5883: if ($type eq '_LC_adv') {
5884: $unset = '';
5885: }
1.72 raeburn 5886: } else {
1.101 raeburn 5887: if (grep(/^\Q$type\E$/,@{$toolshash{$item}})) {
5888: $confhash{$item}{$type} = 1;
5889: } else {
5890: $confhash{$item}{$type} = 0;
5891: }
1.72 raeburn 5892: }
1.86 raeburn 5893: if (ref($domconfig{$action}) eq 'HASH') {
1.163 raeburn 5894: if ($action eq 'requestauthor') {
5895: if ($domconfig{$action}{$type} ne $confhash{$type}) {
5896: $changes{$type} = 1;
5897: }
5898: } elsif (ref($domconfig{$action}{$item}) eq 'HASH') {
1.86 raeburn 5899: if ($domconfig{$action}{$item}{$type} ne $confhash{$item}{$type}) {
5900: $changes{$item}{$type} = 1;
5901: }
5902: } else {
5903: if ($context eq 'requestcourses') {
1.104 raeburn 5904: if ($confhash{$item}{$type} ne $unset) {
1.86 raeburn 5905: $changes{$item}{$type} = 1;
5906: }
5907: } else {
5908: if (!$confhash{$item}{$type}) {
5909: $changes{$item}{$type} = 1;
5910: }
5911: }
5912: }
5913: } else {
5914: if ($context eq 'requestcourses') {
1.104 raeburn 5915: if ($confhash{$item}{$type} ne $unset) {
1.72 raeburn 5916: $changes{$item}{$type} = 1;
5917: }
1.163 raeburn 5918: } elsif ($context eq 'requestauthor') {
5919: if ($confhash{$type} ne $unset) {
5920: $changes{$type} = 1;
5921: }
1.72 raeburn 5922: } else {
5923: if (!$confhash{$item}{$type}) {
5924: $changes{$item}{$type} = 1;
5925: }
5926: }
5927: }
1.1 raeburn 5928: }
5929: }
1.163 raeburn 5930: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 5931: if (ref($domconfig{'quotas'}) eq 'HASH') {
5932: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
5933: foreach my $key (keys(%{$domconfig{'quotas'}{'defaultquota'}})) {
5934: if (exists($confhash{'defaultquota'}{$key})) {
5935: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{'defaultquota'}{$key}) {
5936: $changes{'defaultquota'}{$key} = 1;
5937: }
5938: } else {
5939: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{'defaultquota'}{$key};
1.72 raeburn 5940: }
5941: }
1.86 raeburn 5942: } else {
5943: foreach my $key (keys(%{$domconfig{'quotas'}})) {
5944: if (exists($confhash{'defaultquota'}{$key})) {
5945: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{$key}) {
5946: $changes{'defaultquota'}{$key} = 1;
5947: }
5948: } else {
5949: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{$key};
1.72 raeburn 5950: }
1.1 raeburn 5951: }
5952: }
1.197 raeburn 5953: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
5954: foreach my $key (keys(%{$domconfig{'quotas'}{'authorquota'}})) {
5955: if (exists($confhash{'authorquota'}{$key})) {
5956: if ($confhash{'authorquota'}{$key} ne $domconfig{'quotas'}{'authorquota'}{$key}) {
5957: $changes{'authorquota'}{$key} = 1;
5958: }
5959: } else {
5960: $confhash{'authorquota'}{$key} = $domconfig{'quotas'}{'authorquota'}{$key};
5961: }
5962: }
5963: }
1.1 raeburn 5964: }
1.86 raeburn 5965: if (ref($confhash{'defaultquota'}) eq 'HASH') {
5966: foreach my $key (keys(%{$confhash{'defaultquota'}})) {
5967: if (ref($domconfig{'quotas'}) eq 'HASH') {
5968: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
5969: if (!exists($domconfig{'quotas'}{'defaultquota'}{$key})) {
5970: $changes{'defaultquota'}{$key} = 1;
5971: }
5972: } else {
5973: if (!exists($domconfig{'quotas'}{$key})) {
5974: $changes{'defaultquota'}{$key} = 1;
5975: }
1.72 raeburn 5976: }
5977: } else {
1.86 raeburn 5978: $changes{'defaultquota'}{$key} = 1;
1.55 raeburn 5979: }
1.1 raeburn 5980: }
5981: }
1.197 raeburn 5982: if (ref($confhash{'authorquota'}) eq 'HASH') {
5983: foreach my $key (keys(%{$confhash{'authorquota'}})) {
5984: if (ref($domconfig{'quotas'}) eq 'HASH') {
5985: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
5986: if (!exists($domconfig{'quotas'}{'authorquota'}{$key})) {
5987: $changes{'authorquota'}{$key} = 1;
5988: }
5989: } else {
5990: $changes{'authorquota'}{$key} = 1;
5991: }
5992: } else {
5993: $changes{'authorquota'}{$key} = 1;
5994: }
5995: }
5996: }
1.1 raeburn 5997: }
1.72 raeburn 5998:
1.163 raeburn 5999: if ($context eq 'requestauthor') {
6000: $domdefaults{'requestauthor'} = \%confhash;
6001: } else {
6002: foreach my $key (keys(%confhash)) {
6003: $domdefaults{$key} = $confhash{$key};
6004: }
1.72 raeburn 6005: }
1.163 raeburn 6006:
1.1 raeburn 6007: my %quotahash = (
1.86 raeburn 6008: $action => { %confhash }
1.1 raeburn 6009: );
6010: my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
6011: $dom);
6012: if ($putresult eq 'ok') {
6013: if (keys(%changes) > 0) {
1.72 raeburn 6014: my $cachetime = 24*60*60;
6015: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
6016:
1.1 raeburn 6017: $resulttext = &mt('Changes made:').'<ul>';
1.163 raeburn 6018: unless (($context eq 'requestcourses') ||
6019: ($context eq 'requestauthor')) {
1.86 raeburn 6020: if (ref($changes{'defaultquota'}) eq 'HASH') {
6021: $resulttext .= '<li>'.&mt('Portfolio default quotas').'<ul>';
6022: foreach my $type (@{$types},'default') {
6023: if (defined($changes{'defaultquota'}{$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{'defaultquota'}{$type}).'</li>';
1.72 raeburn 6029: }
6030: }
1.86 raeburn 6031: $resulttext .= '</ul></li>';
1.72 raeburn 6032: }
1.197 raeburn 6033: if (ref($changes{'authorquota'}) eq 'HASH') {
6034: $resulttext .= '<li>'.&mt('Authoring space default quotas').'<ul>';
6035: foreach my $type (@{$types},'default') {
6036: if (defined($changes{'authorquota'}{$type})) {
6037: my $typetitle = $usertypes->{$type};
6038: if ($type eq 'default') {
6039: $typetitle = $othertitle;
6040: }
6041: $resulttext .= '<li>'.&mt('[_1] set to [_2] Mb',$typetitle,$confhash{'authorquota'}{$type}).'</li>';
6042: }
6043: }
6044: $resulttext .= '</ul></li>';
6045: }
1.72 raeburn 6046: }
1.80 raeburn 6047: my %newenv;
1.72 raeburn 6048: foreach my $item (@usertools) {
1.163 raeburn 6049: my (%haschgs,%inconf);
6050: if ($context eq 'requestauthor') {
6051: %haschgs = %changes;
6052: %inconf = %confhash;
6053: } else {
6054: if (ref($changes{$item}) eq 'HASH') {
6055: %haschgs = %{$changes{$item}};
6056: }
6057: if (ref($confhash{$item}) eq 'HASH') {
6058: %inconf = %{$confhash{$item}};
6059: }
6060: }
6061: if (keys(%haschgs) > 0) {
1.80 raeburn 6062: my $newacc =
6063: &Apache::lonnet::usertools_access($env{'user.name'},
6064: $env{'user.domain'},
1.86 raeburn 6065: $item,'reload',$context);
1.163 raeburn 6066: if (($context eq 'requestcourses') ||
6067: ($context eq 'requestauthor')) {
1.108 raeburn 6068: if ($env{'environment.canrequest.'.$item} ne $newacc) {
6069: $newenv{'environment.canrequest.'.$item} = $newacc;
1.86 raeburn 6070: }
6071: } else {
6072: if ($env{'environment.availabletools.'.$item} ne $newacc) {
6073: $newenv{'environment.availabletools.'.$item} = $newacc;
6074: }
1.80 raeburn 6075: }
1.163 raeburn 6076: unless ($context eq 'requestauthor') {
6077: $resulttext .= '<li>'.$titles{$item}.'<ul>';
6078: }
1.72 raeburn 6079: foreach my $type (@{$types},'default','_LC_adv') {
1.163 raeburn 6080: if ($haschgs{$type}) {
1.72 raeburn 6081: my $typetitle = $usertypes->{$type};
6082: if ($type eq 'default') {
6083: $typetitle = $othertitle;
6084: } elsif ($type eq '_LC_adv') {
6085: $typetitle = 'LON-CAPA Advanced Users';
6086: }
1.163 raeburn 6087: if ($inconf{$type}) {
1.101 raeburn 6088: if ($context eq 'requestcourses') {
6089: my $cond;
1.163 raeburn 6090: if ($inconf{$type} =~ /^autolimit=(\d*)$/) {
1.101 raeburn 6091: if ($1 eq '') {
6092: $cond = &mt('(Automatic processing of any request).');
6093: } else {
6094: $cond = &mt('(Automatic processing of requests up to limit of [quant,_1,request] per user).',$1);
6095: }
6096: } else {
1.163 raeburn 6097: $cond = $conditions{$inconf{$type}};
1.101 raeburn 6098: }
6099: $resulttext .= '<li>'.&mt('Set to be available to [_1].',$typetitle).' '.$cond.'</li>';
1.172 raeburn 6100: } elsif ($context eq 'requestauthor') {
6101: $resulttext .= '<li>'.&mt('Set to "[_1]" for "[_2]".',
6102: $titles{$inconf{$type}},$typetitle);
6103:
1.101 raeburn 6104: } else {
6105: $resulttext .= '<li>'.&mt('Set to be available to [_1]',$typetitle).'</li>';
6106: }
1.72 raeburn 6107: } else {
1.104 raeburn 6108: if ($type eq '_LC_adv') {
1.163 raeburn 6109: if ($inconf{$type} eq '0') {
1.104 raeburn 6110: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
6111: } else {
6112: $resulttext .= '<li>'.&mt('No override set for [_1]',$typetitle).'</li>';
6113: }
6114: } else {
6115: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
6116: }
1.72 raeburn 6117: }
6118: }
1.26 raeburn 6119: }
1.163 raeburn 6120: unless ($context eq 'requestauthor') {
6121: $resulttext .= '</ul></li>';
6122: }
1.26 raeburn 6123: }
1.1 raeburn 6124: }
1.163 raeburn 6125: if (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.102 raeburn 6126: if (ref($changes{'notify'}) eq 'HASH') {
6127: if ($changes{'notify'}{'approval'}) {
6128: if (ref($confhash{'notify'}) eq 'HASH') {
6129: if ($confhash{'notify'}{'approval'}) {
6130: $resulttext .= '<li>'.&mt('Notification of requests requiring approval will be sent to: ').$confhash{'notify'}{'approval'}.'</li>';
6131: } else {
1.163 raeburn 6132: $resulttext .= '<li>'.&mt('No Domain Coordinators will receive notification of requests requiring approval.').'</li>';
1.102 raeburn 6133: }
6134: }
6135: }
6136: }
6137: }
1.1 raeburn 6138: $resulttext .= '</ul>';
1.80 raeburn 6139: if (keys(%newenv)) {
6140: &Apache::lonnet::appenv(\%newenv);
6141: }
1.1 raeburn 6142: } else {
1.86 raeburn 6143: if ($context eq 'requestcourses') {
6144: $resulttext = &mt('No changes made to rights to request creation of courses.');
1.163 raeburn 6145: } elsif ($context eq 'requestauthor') {
6146: $resulttext = &mt('No changes made to rights to request author space.');
1.86 raeburn 6147: } else {
1.90 weissno 6148: $resulttext = &mt('No changes made to availability of personal information pages, blogs, portfolios or default quotas');
1.86 raeburn 6149: }
1.1 raeburn 6150: }
6151: } else {
1.11 albertel 6152: $resulttext = '<span class="LC_error">'.
6153: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 6154: }
1.3 raeburn 6155: return $resulttext;
1.1 raeburn 6156: }
6157:
1.3 raeburn 6158: sub modify_autoenroll {
6159: my ($dom,%domconfig) = @_;
1.1 raeburn 6160: my ($resulttext,%changes);
6161: my %currautoenroll;
6162: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
6163: foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
6164: $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
6165: }
6166: }
6167: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
6168: my %title = ( run => 'Auto-enrollment active',
1.129 raeburn 6169: sender => 'Sender for notification messages',
6170: coowners => 'Automatic assignment of co-ownership to instructors of record (institutional data)');
1.1 raeburn 6171: my @offon = ('off','on');
1.17 raeburn 6172: my $sender_uname = $env{'form.sender_uname'};
6173: my $sender_domain = $env{'form.sender_domain'};
6174: if ($sender_domain eq '') {
6175: $sender_uname = '';
6176: } elsif ($sender_uname eq '') {
6177: $sender_domain = '';
6178: }
1.129 raeburn 6179: my $coowners = $env{'form.autoassign_coowners'};
1.1 raeburn 6180: my %autoenrollhash = (
1.129 raeburn 6181: autoenroll => { 'run' => $env{'form.autoenroll_run'},
6182: 'sender_uname' => $sender_uname,
6183: 'sender_domain' => $sender_domain,
6184: 'co-owners' => $coowners,
1.1 raeburn 6185: }
6186: );
1.4 raeburn 6187: my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
6188: $dom);
1.1 raeburn 6189: if ($putresult eq 'ok') {
6190: if (exists($currautoenroll{'run'})) {
6191: if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
6192: $changes{'run'} = 1;
6193: }
6194: } elsif ($autorun) {
6195: if ($env{'form.autoenroll_run'} ne '1') {
1.23 raeburn 6196: $changes{'run'} = 1;
1.1 raeburn 6197: }
6198: }
1.17 raeburn 6199: if ($currautoenroll{'sender_uname'} ne $sender_uname) {
1.1 raeburn 6200: $changes{'sender'} = 1;
6201: }
1.17 raeburn 6202: if ($currautoenroll{'sender_domain'} ne $sender_domain) {
1.1 raeburn 6203: $changes{'sender'} = 1;
6204: }
1.129 raeburn 6205: if ($currautoenroll{'co-owners'} ne '') {
6206: if ($currautoenroll{'co-owners'} ne $coowners) {
6207: $changes{'coowners'} = 1;
6208: }
6209: } elsif ($coowners) {
6210: $changes{'coowners'} = 1;
6211: }
1.1 raeburn 6212: if (keys(%changes) > 0) {
6213: $resulttext = &mt('Changes made:').'<ul>';
1.3 raeburn 6214: if ($changes{'run'}) {
1.1 raeburn 6215: $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
6216: }
6217: if ($changes{'sender'}) {
1.17 raeburn 6218: if ($sender_uname eq '' || $sender_domain eq '') {
6219: $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
6220: } else {
6221: $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
6222: }
1.1 raeburn 6223: }
1.129 raeburn 6224: if ($changes{'coowners'}) {
6225: $resulttext .= '<li>'.&mt("$title{'coowners'} set to $offon[$env{'form.autoassign_coowners'}]").'</li>';
6226: &Apache::loncommon::devalidate_domconfig_cache($dom);
6227: }
1.1 raeburn 6228: $resulttext .= '</ul>';
6229: } else {
6230: $resulttext = &mt('No changes made to auto-enrollment settings');
6231: }
6232: } else {
1.11 albertel 6233: $resulttext = '<span class="LC_error">'.
6234: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 6235: }
1.3 raeburn 6236: return $resulttext;
1.1 raeburn 6237: }
6238:
6239: sub modify_autoupdate {
1.3 raeburn 6240: my ($dom,%domconfig) = @_;
1.1 raeburn 6241: my ($resulttext,%currautoupdate,%fields,%changes);
6242: if (ref($domconfig{'autoupdate'}) eq 'HASH') {
6243: foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
6244: $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
6245: }
6246: }
6247: my @offon = ('off','on');
6248: my %title = &Apache::lonlocal::texthash (
6249: run => 'Auto-update:',
6250: classlists => 'Updates to user information in classlists?'
6251: );
1.44 raeburn 6252: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 6253: my %fieldtitles = &Apache::lonlocal::texthash (
6254: id => 'Student/Employee ID',
1.20 raeburn 6255: permanentemail => 'E-mail address',
1.1 raeburn 6256: lastname => 'Last Name',
6257: firstname => 'First Name',
6258: middlename => 'Middle Name',
1.132 raeburn 6259: generation => 'Generation',
1.1 raeburn 6260: );
1.142 raeburn 6261: $othertitle = &mt('All users');
1.1 raeburn 6262: if (keys(%{$usertypes}) > 0) {
1.26 raeburn 6263: $othertitle = &mt('Other users');
1.1 raeburn 6264: }
6265: foreach my $key (keys(%env)) {
6266: if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
1.132 raeburn 6267: my ($usertype,$item) = ($1,$2);
6268: if (grep(/^\Q$item\E$/,keys(%fieldtitles))) {
6269: if ($usertype eq 'default') {
6270: push(@{$fields{$1}},$2);
6271: } elsif (ref($types) eq 'ARRAY') {
6272: if (grep(/^\Q$usertype\E$/,@{$types})) {
6273: push(@{$fields{$1}},$2);
6274: }
6275: }
6276: }
1.1 raeburn 6277: }
6278: }
1.131 raeburn 6279: my @lockablenames = &Apache::loncommon::get_env_multiple('form.lockablenames');
6280: @lockablenames = sort(@lockablenames);
6281: if (ref($currautoupdate{'lockablenames'}) eq 'ARRAY') {
6282: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
6283: if (@changed) {
6284: $changes{'lockablenames'} = 1;
6285: }
6286: } else {
6287: if (@lockablenames) {
6288: $changes{'lockablenames'} = 1;
6289: }
6290: }
1.1 raeburn 6291: my %updatehash = (
6292: autoupdate => { run => $env{'form.autoupdate_run'},
6293: classlists => $env{'form.classlists'},
6294: fields => {%fields},
1.131 raeburn 6295: lockablenames => \@lockablenames,
1.1 raeburn 6296: }
6297: );
6298: foreach my $key (keys(%currautoupdate)) {
6299: if (($key eq 'run') || ($key eq 'classlists')) {
6300: if (exists($updatehash{autoupdate}{$key})) {
6301: if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
6302: $changes{$key} = 1;
6303: }
6304: }
6305: } elsif ($key eq 'fields') {
6306: if (ref($currautoupdate{$key}) eq 'HASH') {
1.26 raeburn 6307: foreach my $item (@{$types},'default') {
1.1 raeburn 6308: if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
6309: my $change = 0;
6310: foreach my $type (@{$currautoupdate{$key}{$item}}) {
6311: if (!exists($fields{$item})) {
6312: $change = 1;
1.132 raeburn 6313: last;
1.1 raeburn 6314: } elsif (ref($fields{$item}) eq 'ARRAY') {
1.26 raeburn 6315: if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
1.1 raeburn 6316: $change = 1;
1.132 raeburn 6317: last;
1.1 raeburn 6318: }
6319: }
6320: }
6321: if ($change) {
6322: push(@{$changes{$key}},$item);
6323: }
1.26 raeburn 6324: }
1.1 raeburn 6325: }
6326: }
1.131 raeburn 6327: } elsif ($key eq 'lockablenames') {
6328: if (ref($currautoupdate{$key}) eq 'ARRAY') {
6329: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
6330: if (@changed) {
6331: $changes{'lockablenames'} = 1;
6332: }
6333: } else {
6334: if (@lockablenames) {
6335: $changes{'lockablenames'} = 1;
6336: }
6337: }
6338: }
6339: }
6340: unless (grep(/^\Qlockablenames\E$/,keys(%currautoupdate))) {
6341: if (@lockablenames) {
6342: $changes{'lockablenames'} = 1;
1.1 raeburn 6343: }
6344: }
1.26 raeburn 6345: foreach my $item (@{$types},'default') {
6346: if (defined($fields{$item})) {
6347: if (ref($currautoupdate{'fields'}) eq 'HASH') {
1.132 raeburn 6348: if (ref($currautoupdate{'fields'}{$item}) eq 'ARRAY') {
6349: my $change = 0;
6350: if (ref($fields{$item}) eq 'ARRAY') {
6351: foreach my $type (@{$fields{$item}}) {
6352: if (!grep(/^\Q$type\E$/,@{$currautoupdate{'fields'}{$item}})) {
6353: $change = 1;
6354: last;
6355: }
6356: }
6357: }
6358: if ($change) {
6359: push(@{$changes{'fields'}},$item);
6360: }
6361: } else {
1.26 raeburn 6362: push(@{$changes{'fields'}},$item);
6363: }
6364: } else {
6365: push(@{$changes{'fields'}},$item);
1.1 raeburn 6366: }
6367: }
6368: }
6369: my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
6370: $dom);
6371: if ($putresult eq 'ok') {
6372: if (keys(%changes) > 0) {
6373: $resulttext = &mt('Changes made:').'<ul>';
6374: foreach my $key (sort(keys(%changes))) {
1.131 raeburn 6375: if ($key eq 'lockablenames') {
6376: $resulttext .= '<li>';
6377: if (@lockablenames) {
6378: $usertypes->{'default'} = $othertitle;
6379: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update), available for the following affiliations:").' '.
6380: join(', ', map { $usertypes->{$_}; } @lockablenames).'</li>';
6381: } else {
6382: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update) is unavailable.");
6383: }
6384: $resulttext .= '</li>';
6385: } elsif (ref($changes{$key}) eq 'ARRAY') {
1.1 raeburn 6386: foreach my $item (@{$changes{$key}}) {
6387: my @newvalues;
6388: foreach my $type (@{$fields{$item}}) {
6389: push(@newvalues,$fieldtitles{$type});
6390: }
1.3 raeburn 6391: my $newvaluestr;
6392: if (@newvalues > 0) {
6393: $newvaluestr = join(', ',@newvalues);
6394: } else {
6395: $newvaluestr = &mt('none');
1.6 raeburn 6396: }
1.1 raeburn 6397: if ($item eq 'default') {
1.26 raeburn 6398: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
1.1 raeburn 6399: } else {
1.26 raeburn 6400: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
1.1 raeburn 6401: }
6402: }
6403: } else {
6404: my $newvalue;
6405: if ($key eq 'run') {
6406: $newvalue = $offon[$env{'form.autoupdate_run'}];
6407: } else {
6408: $newvalue = $offon[$env{'form.'.$key}];
1.3 raeburn 6409: }
1.1 raeburn 6410: $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
6411: }
6412: }
6413: $resulttext .= '</ul>';
6414: } else {
1.3 raeburn 6415: $resulttext = &mt('No changes made to autoupdates');
1.1 raeburn 6416: }
6417: } else {
1.11 albertel 6418: $resulttext = '<span class="LC_error">'.
6419: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 6420: }
1.3 raeburn 6421: return $resulttext;
1.1 raeburn 6422: }
6423:
1.125 raeburn 6424: sub modify_autocreate {
6425: my ($dom,%domconfig) = @_;
6426: my ($resulttext,%changes,%currautocreate,%newvals,%autocreatehash);
6427: if (ref($domconfig{'autocreate'}) eq 'HASH') {
6428: foreach my $key (keys(%{$domconfig{'autocreate'}})) {
6429: $currautocreate{$key} = $domconfig{'autocreate'}{$key};
6430: }
6431: }
6432: my %title= ( xml => 'Auto-creation of courses in XML course description files',
6433: req => 'Auto-creation of validated requests for official courses',
6434: xmldc => 'Identity of course creator of courses from XML files',
6435: );
6436: my @types = ('xml','req');
6437: foreach my $item (@types) {
6438: $newvals{$item} = $env{'form.autocreate_'.$item};
6439: $newvals{$item} =~ s/\D//g;
6440: $newvals{$item} = 0 if ($newvals{$item} eq '');
6441: }
6442: $newvals{'xmldc'} = $env{'form.autocreate_xmldc'};
6443: my %domcoords = &get_active_dcs($dom);
6444: unless (exists($domcoords{$newvals{'xmldc'}})) {
6445: $newvals{'xmldc'} = '';
6446: }
6447: %autocreatehash = (
6448: autocreate => { xml => $newvals{'xml'},
6449: req => $newvals{'req'},
6450: }
6451: );
6452: if ($newvals{'xmldc'} ne '') {
6453: $autocreatehash{'autocreate'}{'xmldc'} = $newvals{'xmldc'};
6454: }
6455: my $putresult = &Apache::lonnet::put_dom('configuration',\%autocreatehash,
6456: $dom);
6457: if ($putresult eq 'ok') {
6458: my @items = @types;
6459: if ($newvals{'xml'}) {
6460: push(@items,'xmldc');
6461: }
6462: foreach my $item (@items) {
6463: if (exists($currautocreate{$item})) {
6464: if ($currautocreate{$item} ne $newvals{$item}) {
6465: $changes{$item} = 1;
6466: }
6467: } elsif ($newvals{$item}) {
6468: $changes{$item} = 1;
6469: }
6470: }
6471: if (keys(%changes) > 0) {
6472: my @offon = ('off','on');
6473: $resulttext = &mt('Changes made:').'<ul>';
6474: foreach my $item (@types) {
6475: if ($changes{$item}) {
6476: my $newtxt = $offon[$newvals{$item}];
1.178 raeburn 6477: $resulttext .= '<li>'.
6478: &mt("$title{$item} set to [_1]$newtxt [_2]",
6479: '<b>','</b>').
6480: '</li>';
1.125 raeburn 6481: }
6482: }
6483: if ($changes{'xmldc'}) {
6484: my ($dcname,$dcdom) = split(':',$newvals{'xmldc'});
6485: my $newtxt = &Apache::loncommon::plainname($dcname,$dcdom);
1.178 raeburn 6486: $resulttext .= '<li>'.&mt("$title{'xmldc'} set to [_1]",'<b>'.$newtxt.'</b>').'</li>';
1.125 raeburn 6487: }
6488: $resulttext .= '</ul>';
6489: } else {
6490: $resulttext = &mt('No changes made to auto-creation settings');
6491: }
6492: } else {
6493: $resulttext = '<span class="LC_error">'.
6494: &mt('An error occurred: [_1]',$putresult).'</span>';
6495: }
6496: return $resulttext;
6497: }
6498:
1.23 raeburn 6499: sub modify_directorysrch {
6500: my ($dom,%domconfig) = @_;
6501: my ($resulttext,%changes);
6502: my %currdirsrch;
6503: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
6504: foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
6505: $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
6506: }
6507: }
6508: my %title = ( available => 'Directory search available',
1.24 raeburn 6509: localonly => 'Other domains can search',
1.23 raeburn 6510: searchby => 'Search types',
6511: searchtypes => 'Search latitude');
6512: my @offon = ('off','on');
1.24 raeburn 6513: my @otherdoms = ('Yes','No');
1.23 raeburn 6514:
1.25 raeburn 6515: my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');
1.23 raeburn 6516: my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
6517: my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
6518:
1.44 raeburn 6519: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.26 raeburn 6520: if (keys(%{$usertypes}) == 0) {
6521: @cansearch = ('default');
6522: } else {
6523: if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
6524: foreach my $type (@{$currdirsrch{'cansearch'}}) {
6525: if (!grep(/^\Q$type\E$/,@cansearch)) {
6526: push(@{$changes{'cansearch'}},$type);
6527: }
1.23 raeburn 6528: }
1.26 raeburn 6529: foreach my $type (@cansearch) {
6530: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
6531: push(@{$changes{'cansearch'}},$type);
6532: }
1.23 raeburn 6533: }
1.26 raeburn 6534: } else {
6535: push(@{$changes{'cansearch'}},@cansearch);
1.23 raeburn 6536: }
6537: }
6538:
6539: if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
6540: foreach my $by (@{$currdirsrch{'searchby'}}) {
6541: if (!grep(/^\Q$by\E$/,@searchby)) {
6542: push(@{$changes{'searchby'}},$by);
6543: }
6544: }
6545: foreach my $by (@searchby) {
6546: if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
6547: push(@{$changes{'searchby'}},$by);
6548: }
6549: }
6550: } else {
6551: push(@{$changes{'searchby'}},@searchby);
6552: }
1.25 raeburn 6553:
6554: if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
6555: foreach my $type (@{$currdirsrch{'searchtypes'}}) {
6556: if (!grep(/^\Q$type\E$/,@searchtypes)) {
6557: push(@{$changes{'searchtypes'}},$type);
6558: }
6559: }
6560: foreach my $type (@searchtypes) {
6561: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
6562: push(@{$changes{'searchtypes'}},$type);
6563: }
6564: }
6565: } else {
6566: if (exists($currdirsrch{'searchtypes'})) {
6567: foreach my $type (@searchtypes) {
6568: if ($type ne $currdirsrch{'searchtypes'}) {
6569: push(@{$changes{'searchtypes'}},$type);
6570: }
6571: }
6572: if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
6573: push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
6574: }
6575: } else {
6576: push(@{$changes{'searchtypes'}},@searchtypes);
6577: }
6578: }
6579:
1.23 raeburn 6580: my %dirsrch_hash = (
6581: directorysrch => { available => $env{'form.dirsrch_available'},
6582: cansearch => \@cansearch,
1.24 raeburn 6583: localonly => $env{'form.dirsrch_localonly'},
1.23 raeburn 6584: searchby => \@searchby,
1.25 raeburn 6585: searchtypes => \@searchtypes,
1.23 raeburn 6586: }
6587: );
6588: my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
6589: $dom);
6590: if ($putresult eq 'ok') {
6591: if (exists($currdirsrch{'available'})) {
6592: if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
6593: $changes{'available'} = 1;
6594: }
6595: } else {
6596: if ($env{'form.dirsrch_available'} eq '1') {
6597: $changes{'available'} = 1;
6598: }
6599: }
1.24 raeburn 6600: if (exists($currdirsrch{'localonly'})) {
6601: if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_localonly'}) {
6602: $changes{'localonly'} = 1;
6603: }
6604: } else {
6605: if ($env{'form.dirsrch_localonly'} eq '1') {
6606: $changes{'localonly'} = 1;
6607: }
6608: }
1.23 raeburn 6609: if (keys(%changes) > 0) {
6610: $resulttext = &mt('Changes made:').'<ul>';
6611: if ($changes{'available'}) {
6612: $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
6613: }
1.24 raeburn 6614: if ($changes{'localonly'}) {
6615: $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_localonly'}]").'</li>';
6616: }
6617:
1.23 raeburn 6618: if (ref($changes{'cansearch'}) eq 'ARRAY') {
6619: my $chgtext;
1.26 raeburn 6620: if (ref($usertypes) eq 'HASH') {
6621: if (keys(%{$usertypes}) > 0) {
6622: foreach my $type (@{$types}) {
6623: if (grep(/^\Q$type\E$/,@cansearch)) {
6624: $chgtext .= $usertypes->{$type}.'; ';
6625: }
6626: }
6627: if (grep(/^default$/,@cansearch)) {
6628: $chgtext .= $othertitle;
6629: } else {
6630: $chgtext =~ s/\; $//;
6631: }
1.178 raeburn 6632: $resulttext .=
6633: '<li>'.
6634: &mt("Users from domain '[_1]' permitted to search the institutional directory set to: [_2]",
6635: '<span class="LC_cusr_emph">'.$dom.'</span>',$chgtext).
6636: '</li>';
1.23 raeburn 6637: }
6638: }
6639: }
6640: if (ref($changes{'searchby'}) eq 'ARRAY') {
6641: my ($searchtitles,$titleorder) = &sorted_searchtitles();
6642: my $chgtext;
6643: foreach my $type (@{$titleorder}) {
6644: if (grep(/^\Q$type\E$/,@searchby)) {
6645: if (defined($searchtitles->{$type})) {
6646: $chgtext .= $searchtitles->{$type}.'; ';
6647: }
6648: }
6649: }
6650: $chgtext =~ s/\; $//;
6651: $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
6652: }
1.25 raeburn 6653: if (ref($changes{'searchtypes'}) eq 'ARRAY') {
6654: my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes();
6655: my $chgtext;
6656: foreach my $type (@{$srchtypeorder}) {
6657: if (grep(/^\Q$type\E$/,@searchtypes)) {
6658: if (defined($srchtypes_desc->{$type})) {
6659: $chgtext .= $srchtypes_desc->{$type}.'; ';
6660: }
6661: }
6662: }
6663: $chgtext =~ s/\; $//;
1.178 raeburn 6664: $resulttext .= '<li>'.&mt($title{'searchtypes'}.' set to: "[_1]"',$chgtext).'</li>';
1.23 raeburn 6665: }
6666: $resulttext .= '</ul>';
6667: } else {
6668: $resulttext = &mt('No changes made to institution directory search settings');
6669: }
6670: } else {
6671: $resulttext = '<span class="LC_error">'.
1.27 raeburn 6672: &mt('An error occurred: [_1]',$putresult).'</span>';
6673: }
6674: return $resulttext;
6675: }
6676:
1.28 raeburn 6677: sub modify_contacts {
6678: my ($dom,%domconfig) = @_;
6679: my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
6680: if (ref($domconfig{'contacts'}) eq 'HASH') {
6681: foreach my $key (keys(%{$domconfig{'contacts'}})) {
6682: $currsetting{$key} = $domconfig{'contacts'}{$key};
6683: }
6684: }
1.134 raeburn 6685: my (%others,%to,%bcc);
1.28 raeburn 6686: my @contacts = ('supportemail','adminemail');
1.102 raeburn 6687: my @mailings = ('errormail','packagesmail','helpdeskmail','lonstatusmail',
1.190 raeburn 6688: 'requestsmail','updatesmail');
1.28 raeburn 6689: foreach my $type (@mailings) {
6690: @{$newsetting{$type}} =
6691: &Apache::loncommon::get_env_multiple('form.'.$type);
6692: foreach my $item (@contacts) {
6693: if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
6694: $contacts_hash{contacts}{$type}{$item} = 1;
6695: } else {
6696: $contacts_hash{contacts}{$type}{$item} = 0;
6697: }
6698: }
6699: $others{$type} = $env{'form.'.$type.'_others'};
6700: $contacts_hash{contacts}{$type}{'others'} = $others{$type};
1.134 raeburn 6701: if ($type eq 'helpdeskmail') {
6702: $bcc{$type} = $env{'form.'.$type.'_bcc'};
6703: $contacts_hash{contacts}{$type}{'bcc'} = $bcc{$type};
6704: }
1.28 raeburn 6705: }
6706: foreach my $item (@contacts) {
6707: $to{$item} = $env{'form.'.$item};
6708: $contacts_hash{'contacts'}{$item} = $to{$item};
6709: }
6710: if (keys(%currsetting) > 0) {
6711: foreach my $item (@contacts) {
6712: if ($to{$item} ne $currsetting{$item}) {
6713: $changes{$item} = 1;
6714: }
6715: }
6716: foreach my $type (@mailings) {
6717: foreach my $item (@contacts) {
6718: if (ref($currsetting{$type}) eq 'HASH') {
6719: if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
6720: push(@{$changes{$type}},$item);
6721: }
6722: } else {
6723: push(@{$changes{$type}},@{$newsetting{$type}});
6724: }
6725: }
6726: if ($others{$type} ne $currsetting{$type}{'others'}) {
6727: push(@{$changes{$type}},'others');
6728: }
1.134 raeburn 6729: if ($type eq 'helpdeskmail') {
6730: if ($bcc{$type} ne $currsetting{$type}{'bcc'}) {
6731: push(@{$changes{$type}},'bcc');
6732: }
6733: }
1.28 raeburn 6734: }
6735: } else {
6736: my %default;
6737: $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
6738: $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
6739: $default{'errormail'} = 'adminemail';
6740: $default{'packagesmail'} = 'adminemail';
6741: $default{'helpdeskmail'} = 'supportemail';
1.89 raeburn 6742: $default{'lonstatusmail'} = 'adminemail';
1.102 raeburn 6743: $default{'requestsmail'} = 'adminemail';
1.190 raeburn 6744: $default{'updatesmail'} = 'adminemail';
1.28 raeburn 6745: foreach my $item (@contacts) {
6746: if ($to{$item} ne $default{$item}) {
6747: $changes{$item} = 1;
6748: }
6749: }
6750: foreach my $type (@mailings) {
6751: if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
6752:
6753: push(@{$changes{$type}},@{$newsetting{$type}});
6754: }
6755: if ($others{$type} ne '') {
6756: push(@{$changes{$type}},'others');
1.134 raeburn 6757: }
6758: if ($type eq 'helpdeskmail') {
6759: if ($bcc{$type} ne '') {
6760: push(@{$changes{$type}},'bcc');
6761: }
6762: }
1.28 raeburn 6763: }
6764: }
6765: my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
6766: $dom);
6767: if ($putresult eq 'ok') {
6768: if (keys(%changes) > 0) {
6769: my ($titles,$short_titles) = &contact_titles();
6770: $resulttext = &mt('Changes made:').'<ul>';
6771: foreach my $item (@contacts) {
6772: if ($changes{$item}) {
6773: $resulttext .= '<li>'.$titles->{$item}.
6774: &mt(' set to: ').
6775: '<span class="LC_cusr_emph">'.
6776: $to{$item}.'</span></li>';
6777: }
6778: }
6779: foreach my $type (@mailings) {
6780: if (ref($changes{$type}) eq 'ARRAY') {
6781: $resulttext .= '<li>'.$titles->{$type}.': ';
6782: my @text;
6783: foreach my $item (@{$newsetting{$type}}) {
6784: push(@text,$short_titles->{$item});
6785: }
6786: if ($others{$type} ne '') {
6787: push(@text,$others{$type});
6788: }
6789: $resulttext .= '<span class="LC_cusr_emph">'.
1.134 raeburn 6790: join(', ',@text).'</span>';
6791: if ($type eq 'helpdeskmail') {
6792: if ($bcc{$type} ne '') {
6793: $resulttext .= ' '.&mt('with Bcc to').': <span class="LC_cusr_emph">'.$bcc{$type}.'</span>';
6794: }
6795: }
6796: $resulttext .= '</li>';
1.28 raeburn 6797: }
6798: }
6799: $resulttext .= '</ul>';
6800: } else {
1.34 raeburn 6801: $resulttext = &mt('No changes made to contact information');
1.28 raeburn 6802: }
6803: } else {
6804: $resulttext = '<span class="LC_error">'.
6805: &mt('An error occurred: [_1].',$putresult).'</span>';
6806: }
6807: return $resulttext;
6808: }
6809:
6810: sub modify_usercreation {
1.27 raeburn 6811: my ($dom,%domconfig) = @_;
1.34 raeburn 6812: my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate);
1.43 raeburn 6813: my $warningmsg;
1.27 raeburn 6814: if (ref($domconfig{'usercreation'}) eq 'HASH') {
6815: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
6816: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
6817: }
6818: }
6819: my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
1.32 raeburn 6820: my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
1.43 raeburn 6821: my @email_rule = &Apache::loncommon::get_env_multiple('form.email_rule');
1.100 raeburn 6822: my @contexts = ('author','course','requestcrs','selfcreate');
1.34 raeburn 6823: foreach my $item(@contexts) {
1.45 raeburn 6824: if ($item eq 'selfcreate') {
1.50 raeburn 6825: @{$cancreate{$item}} = &Apache::loncommon::get_env_multiple('form.can_createuser_'.$item);
1.43 raeburn 6826: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
6827: if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) || ($domdefaults{'auth_def'} eq 'localauth'))) {
1.50 raeburn 6828: if (ref($cancreate{$item}) eq 'ARRAY') {
6829: if (grep(/^login$/,@{$cancreate{$item}})) {
6830: $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.');
6831: }
1.43 raeburn 6832: }
6833: }
1.50 raeburn 6834: } else {
6835: $cancreate{$item} = $env{'form.can_createuser_'.$item};
1.43 raeburn 6836: }
1.34 raeburn 6837: }
1.93 raeburn 6838: my ($othertitle,$usertypes,$types) =
6839: &Apache::loncommon::sorted_inst_types($dom);
6840: if (ref($types) eq 'ARRAY') {
6841: if (@{$types} > 0) {
6842: @{$cancreate{'statustocreate'}} =
6843: &Apache::loncommon::get_env_multiple('form.statustocreate');
1.103 raeburn 6844: } else {
6845: @{$cancreate{'statustocreate'}} = ();
1.93 raeburn 6846: }
6847: push(@contexts,'statustocreate');
6848: }
1.165 raeburn 6849: &process_captcha('cancreate',\%changes,\%cancreate,\%curr_usercreation);
1.34 raeburn 6850: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
6851: foreach my $item (@contexts) {
1.93 raeburn 6852: if (($item eq 'selfcreate') || ($item eq 'statustocreate')) {
6853: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
1.50 raeburn 6854: foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
1.103 raeburn 6855: if (ref($cancreate{$item}) eq 'ARRAY') {
6856: if (!grep(/^$curr$/,@{$cancreate{$item}})) {
6857: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6858: push(@{$changes{'cancreate'}},$item);
6859: }
1.50 raeburn 6860: }
6861: }
6862: }
6863: } else {
6864: if ($curr_usercreation{'cancreate'}{$item} eq '') {
6865: if (@{$cancreate{$item}} > 0) {
6866: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6867: push(@{$changes{'cancreate'}},$item);
6868: }
6869: }
6870: } else {
6871: if ($curr_usercreation{'cancreate'}{$item} eq 'any') {
6872: if (@{$cancreate{$item}} < 3) {
6873: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6874: push(@{$changes{'cancreate'}},$item);
6875: }
6876: }
6877: } elsif ($curr_usercreation{'cancreate'}{$item} eq 'none') {
6878: if (@{$cancreate{$item}} > 0) {
6879: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6880: push(@{$changes{'cancreate'}},$item);
6881: }
6882: }
6883: } elsif (!grep(/^$curr_usercreation{'cancreate'}{$item}$/,@{$cancreate{$item}})) {
6884: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6885: push(@{$changes{'cancreate'}},$item);
6886: }
6887: }
6888: }
6889: }
6890: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6891: foreach my $type (@{$cancreate{$item}}) {
6892: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
6893: if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
6894: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6895: push(@{$changes{'cancreate'}},$item);
6896: }
6897: }
6898: } elsif (($curr_usercreation{'cancreate'}{$item} ne 'any') &&
6899: ($curr_usercreation{'cancreate'}{$item} ne 'none')) {
6900: if ($curr_usercreation{'cancreate'}{$item} ne $type) {
6901: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6902: push(@{$changes{'cancreate'}},$item);
6903: }
6904: }
6905: }
6906: }
6907: }
6908: } else {
6909: if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
6910: push(@{$changes{'cancreate'}},$item);
6911: }
6912: }
1.27 raeburn 6913: }
1.34 raeburn 6914: } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
6915: foreach my $item (@contexts) {
1.43 raeburn 6916: if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
1.34 raeburn 6917: if ($cancreate{$item} ne 'any') {
6918: push(@{$changes{'cancreate'}},$item);
6919: }
6920: } else {
6921: if ($cancreate{$item} ne 'none') {
6922: push(@{$changes{'cancreate'}},$item);
6923: }
1.27 raeburn 6924: }
6925: }
6926: } else {
1.43 raeburn 6927: foreach my $item (@contexts) {
1.34 raeburn 6928: push(@{$changes{'cancreate'}},$item);
6929: }
1.27 raeburn 6930: }
1.34 raeburn 6931:
1.27 raeburn 6932: if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
6933: foreach my $type (@{$curr_usercreation{'username_rule'}}) {
6934: if (!grep(/^\Q$type\E$/,@username_rule)) {
6935: push(@{$changes{'username_rule'}},$type);
6936: }
6937: }
6938: foreach my $type (@username_rule) {
6939: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
6940: push(@{$changes{'username_rule'}},$type);
6941: }
6942: }
6943: } else {
6944: push(@{$changes{'username_rule'}},@username_rule);
6945: }
6946:
1.32 raeburn 6947: if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
6948: foreach my $type (@{$curr_usercreation{'id_rule'}}) {
6949: if (!grep(/^\Q$type\E$/,@id_rule)) {
6950: push(@{$changes{'id_rule'}},$type);
6951: }
6952: }
6953: foreach my $type (@id_rule) {
6954: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
6955: push(@{$changes{'id_rule'}},$type);
6956: }
6957: }
6958: } else {
6959: push(@{$changes{'id_rule'}},@id_rule);
6960: }
6961:
1.43 raeburn 6962: if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
6963: foreach my $type (@{$curr_usercreation{'email_rule'}}) {
6964: if (!grep(/^\Q$type\E$/,@email_rule)) {
6965: push(@{$changes{'email_rule'}},$type);
6966: }
6967: }
6968: foreach my $type (@email_rule) {
6969: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'email_rule'}})) {
6970: push(@{$changes{'email_rule'}},$type);
6971: }
6972: }
6973: } else {
6974: push(@{$changes{'email_rule'}},@email_rule);
6975: }
6976:
6977: my @authen_contexts = ('author','course','domain');
1.28 raeburn 6978: my @authtypes = ('int','krb4','krb5','loc');
6979: my %authhash;
1.43 raeburn 6980: foreach my $item (@authen_contexts) {
1.28 raeburn 6981: my @authallowed = &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
6982: foreach my $auth (@authtypes) {
6983: if (grep(/^\Q$auth\E$/,@authallowed)) {
6984: $authhash{$item}{$auth} = 1;
6985: } else {
6986: $authhash{$item}{$auth} = 0;
6987: }
6988: }
6989: }
6990: if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
1.43 raeburn 6991: foreach my $item (@authen_contexts) {
1.28 raeburn 6992: if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
6993: foreach my $auth (@authtypes) {
6994: if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
6995: push(@{$changes{'authtypes'}},$item);
6996: last;
6997: }
6998: }
6999: }
7000: }
7001: } else {
1.43 raeburn 7002: foreach my $item (@authen_contexts) {
1.28 raeburn 7003: push(@{$changes{'authtypes'}},$item);
7004: }
7005: }
7006:
1.27 raeburn 7007: my %usercreation_hash = (
1.28 raeburn 7008: usercreation => {
1.34 raeburn 7009: cancreate => \%cancreate,
1.27 raeburn 7010: username_rule => \@username_rule,
1.32 raeburn 7011: id_rule => \@id_rule,
1.43 raeburn 7012: email_rule => \@email_rule,
1.32 raeburn 7013: authtypes => \%authhash,
1.27 raeburn 7014: }
7015: );
7016:
7017: my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
7018: $dom);
1.50 raeburn 7019:
7020: my %selfcreatetypes = (
7021: sso => 'users authenticated by institutional single sign on',
7022: login => 'users authenticated by institutional log-in',
7023: email => 'users who provide a valid e-mail address for use as the username',
7024: );
1.27 raeburn 7025: if ($putresult eq 'ok') {
7026: if (keys(%changes) > 0) {
7027: $resulttext = &mt('Changes made:').'<ul>';
7028: if (ref($changes{'cancreate'}) eq 'ARRAY') {
1.34 raeburn 7029: my %lt = &usercreation_types();
7030: foreach my $type (@{$changes{'cancreate'}}) {
1.100 raeburn 7031: my $chgtext;
1.165 raeburn 7032: unless (($type eq 'statustocreate') || ($type eq 'captcha') || ($type eq 'recaptchakeys')) {
1.100 raeburn 7033: $chgtext = $lt{$type}.', ';
7034: }
1.45 raeburn 7035: if ($type eq 'selfcreate') {
1.50 raeburn 7036: if (@{$cancreate{$type}} == 0) {
1.43 raeburn 7037: $chgtext .= &mt('creation of a new user account is not permitted.');
1.50 raeburn 7038: } else {
1.100 raeburn 7039: $chgtext .= &mt('creation of a new account is permitted for:').'<ul>';
1.50 raeburn 7040: foreach my $case (@{$cancreate{$type}}) {
7041: $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
7042: }
7043: $chgtext .= '</ul>';
1.100 raeburn 7044: if (ref($cancreate{$type}) eq 'ARRAY') {
7045: if (grep(/^(login|sso)$/,@{$cancreate{$type}})) {
7046: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
7047: if (@{$cancreate{'statustocreate'}} == 0) {
7048: $chgtext .= '<br /><span class="LC_warning">'.&mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").'</span>';
7049: }
7050: }
7051: }
7052: }
1.43 raeburn 7053: }
1.93 raeburn 7054: } elsif ($type eq 'statustocreate') {
1.96 raeburn 7055: if ((ref($cancreate{'selfcreate'}) eq 'ARRAY') &&
7056: (ref($cancreate{'statustocreate'}) eq 'ARRAY')) {
7057: if (@{$cancreate{'selfcreate'}} > 0) {
7058: if (@{$cancreate{'statustocreate'}} == 0) {
1.100 raeburn 7059:
7060: $chgtext .= &mt("Institutional affiliations permitted to create accounts set to 'None'.");
1.96 raeburn 7061: if (!grep(/^email$/,@{$cancreate{'selfcreate'}})) {
1.100 raeburn 7062: $chgtext .= '<br /><span class="LC_warning">'.&mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").'</span>';
7063: }
1.96 raeburn 7064: } elsif (ref($usertypes) eq 'HASH') {
7065: if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.100 raeburn 7066: $chgtext .= &mt('Creation of a new account for an institutional user is restricted to the following institutional affiliation(s):');
7067: } else {
7068: $chgtext .= &mt('Institutional affiliations permitted to create accounts with institutional authentication were set as follows:');
7069: }
7070: $chgtext .= '<ul>';
7071: foreach my $case (@{$cancreate{$type}}) {
7072: if ($case eq 'default') {
7073: $chgtext .= '<li>'.$othertitle.'</li>';
7074: } else {
7075: $chgtext .= '<li>'.$usertypes->{$case}.'</li>';
1.93 raeburn 7076: }
7077: }
1.100 raeburn 7078: $chgtext .= '</ul>';
7079: if (!grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
7080: $chgtext .= '<br /><span class="LC_warning">'.&mt('However, users authenticated by institutional login/single sign on are not currently permitted to create accounts.').'</span>';
7081: }
7082: }
7083: } else {
7084: if (@{$cancreate{$type}} == 0) {
7085: $chgtext .= &mt("Institutional affiliations permitted to create accounts were set to 'none'.");
7086: } else {
7087: $chgtext .= &mt('Although institutional affiliations permitted to create accounts were changed, self creation of accounts is not currently permitted for any authentication types.');
1.93 raeburn 7088: }
7089: }
7090: }
1.165 raeburn 7091: } elsif ($type eq 'captcha') {
7092: if ($cancreate{$type} eq 'notused') {
7093: $chgtext .= &mt('No CAPTCHA validation in use for self-creation screen.');
7094: } else {
7095: my %captchas = &captcha_phrases();
7096: if ($captchas{$cancreate{$type}}) {
7097: $chgtext .= &mt("Validation for self-creation screen set to $captchas{$cancreate{$type}}.");
7098: } else {
7099: $chgtext .= &mt('Validation for self-creation screen set to unknown type.');
7100: }
7101: }
7102: } elsif ($type eq 'recaptchakeys') {
7103: my ($privkey,$pubkey);
7104: if (ref($cancreate{$type}) eq 'HASH') {
7105: $pubkey = $cancreate{$type}{'public'};
7106: $privkey = $cancreate{$type}{'private'};
7107: }
7108: $chgtext .= &mt('ReCAPTCHA keys changes').'<ul>';
7109: if (!$pubkey) {
7110: $chgtext .= '<li>'.&mt('Public key deleted').'</li>';
7111: } else {
7112: $chgtext .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
7113: }
7114: if (!$privkey) {
7115: $chgtext .= '<li>'.&mt('Private key deleted').'</li>';
7116: } else {
7117: $chgtext .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
7118: }
7119: $chgtext .= '</ul>';
1.43 raeburn 7120: } else {
7121: if ($cancreate{$type} eq 'none') {
7122: $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
7123: } elsif ($cancreate{$type} eq 'any') {
7124: $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
7125: } elsif ($cancreate{$type} eq 'official') {
7126: $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
7127: } elsif ($cancreate{$type} eq 'unofficial') {
7128: $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
7129: }
1.34 raeburn 7130: }
7131: $resulttext .= '<li>'.$chgtext.'</li>';
1.27 raeburn 7132: }
7133: }
7134: if (ref($changes{'username_rule'}) eq 'ARRAY') {
1.32 raeburn 7135: my ($rules,$ruleorder) =
7136: &Apache::lonnet::inst_userrules($dom,'username');
1.27 raeburn 7137: my $chgtext = '<ul>';
7138: foreach my $type (@username_rule) {
7139: if (ref($rules->{$type}) eq 'HASH') {
7140: $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
7141: }
7142: }
7143: $chgtext .= '</ul>';
7144: if (@username_rule > 0) {
7145: $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
7146: } else {
1.28 raeburn 7147: $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>';
1.27 raeburn 7148: }
7149: }
1.32 raeburn 7150: if (ref($changes{'id_rule'}) eq 'ARRAY') {
7151: my ($idrules,$idruleorder) =
7152: &Apache::lonnet::inst_userrules($dom,'id');
7153: my $chgtext = '<ul>';
7154: foreach my $type (@id_rule) {
7155: if (ref($idrules->{$type}) eq 'HASH') {
7156: $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
7157: }
7158: }
7159: $chgtext .= '</ul>';
7160: if (@id_rule > 0) {
7161: $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
7162: } else {
7163: $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
7164: }
7165: }
1.43 raeburn 7166: if (ref($changes{'email_rule'}) eq 'ARRAY') {
7167: my ($emailrules,$emailruleorder) =
7168: &Apache::lonnet::inst_userrules($dom,'email');
7169: my $chgtext = '<ul>';
7170: foreach my $type (@email_rule) {
7171: if (ref($emailrules->{$type}) eq 'HASH') {
7172: $chgtext .= '<li>'.$emailrules->{$type}{'name'}.'</li>';
7173: }
7174: }
7175: $chgtext .= '</ul>';
7176: if (@email_rule > 0) {
7177: $resulttext .= '<li>'.&mt('Accounts may not be created by users self-enrolling with e-mail addresses of the following types: ').$chgtext.'</li>';
7178: } else {
7179: $resulttext .= '<li>'.&mt('There are now no restrictions on e-mail addresses which may be used as a username when self-enrolling.').'</li>';
7180: }
7181: }
7182:
1.28 raeburn 7183: my %authname = &authtype_names();
7184: my %context_title = &context_names();
7185: if (ref($changes{'authtypes'}) eq 'ARRAY') {
7186: my $chgtext = '<ul>';
7187: foreach my $type (@{$changes{'authtypes'}}) {
7188: my @allowed;
7189: $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
7190: foreach my $auth (@authtypes) {
7191: if ($authhash{$type}{$auth}) {
7192: push(@allowed,$authname{$auth});
7193: }
7194: }
1.43 raeburn 7195: if (@allowed > 0) {
7196: $chgtext .= join(', ',@allowed).'</li>';
7197: } else {
7198: $chgtext .= &mt('none').'</li>';
7199: }
1.28 raeburn 7200: }
7201: $chgtext .= '</ul>';
7202: $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
7203: $resulttext .= '</li>';
7204: }
1.27 raeburn 7205: $resulttext .= '</ul>';
7206: } else {
1.28 raeburn 7207: $resulttext = &mt('No changes made to user creation settings');
1.27 raeburn 7208: }
7209: } else {
7210: $resulttext = '<span class="LC_error">'.
1.23 raeburn 7211: &mt('An error occurred: [_1]',$putresult).'</span>';
7212: }
1.43 raeburn 7213: if ($warningmsg ne '') {
7214: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
7215: }
1.23 raeburn 7216: return $resulttext;
7217: }
7218:
1.165 raeburn 7219: sub process_captcha {
7220: my ($container,$changes,$newsettings,$current) = @_;
7221: return unless ((ref($changes) eq 'HASH') && (ref($newsettings) eq 'HASH') || (ref($current) eq 'HASH'));
7222: $newsettings->{'captcha'} = $env{'form.'.$container.'_captcha'};
7223: unless ($newsettings->{'captcha'} eq 'recaptcha' || $newsettings->{'captcha'} eq 'notused') {
7224: $newsettings->{'captcha'} = 'original';
7225: }
7226: if ($current->{'captcha'} ne $newsettings->{'captcha'}) {
1.169 raeburn 7227: if ($container eq 'cancreate') {
7228: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
7229: push(@{$changes->{'cancreate'}},'captcha');
7230: } elsif (!defined($changes->{'cancreate'})) {
7231: $changes->{'cancreate'} = ['captcha'];
7232: }
7233: } else {
7234: $changes->{'captcha'} = 1;
1.165 raeburn 7235: }
7236: }
7237: my ($newpub,$newpriv,$currpub,$currpriv);
7238: if ($newsettings->{'captcha'} eq 'recaptcha') {
7239: $newpub = $env{'form.'.$container.'_recaptchapub'};
7240: $newpriv = $env{'form.'.$container.'_recaptchapriv'};
1.169 raeburn 7241: $newpub =~ s/\W//g;
7242: $newpriv =~ s/\W//g;
7243: $newsettings->{'recaptchakeys'} = {
7244: public => $newpub,
7245: private => $newpriv,
7246: };
1.165 raeburn 7247: }
7248: if (ref($current->{'recaptchakeys'}) eq 'HASH') {
7249: $currpub = $current->{'recaptchakeys'}{'public'};
7250: $currpriv = $current->{'recaptchakeys'}{'private'};
1.179 raeburn 7251: unless ($newsettings->{'captcha'} eq 'recaptcha') {
7252: $newsettings->{'recaptchakeys'} = {
7253: public => '',
7254: private => '',
7255: }
7256: }
1.165 raeburn 7257: }
7258: if (($newpub ne $currpub) || ($newpriv ne $currpriv)) {
1.169 raeburn 7259: if ($container eq 'cancreate') {
7260: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
7261: push(@{$changes->{'cancreate'}},'recaptchakeys');
7262: } elsif (!defined($changes->{'cancreate'})) {
7263: $changes->{'cancreate'} = ['recaptchakeys'];
7264: }
7265: } else {
7266: $changes->{'recaptchakeys'} = 1;
1.165 raeburn 7267: }
7268: }
7269: return;
7270: }
7271:
1.33 raeburn 7272: sub modify_usermodification {
7273: my ($dom,%domconfig) = @_;
7274: my ($resulttext,%curr_usermodification,%changes);
7275: if (ref($domconfig{'usermodification'}) eq 'HASH') {
7276: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
7277: $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
7278: }
7279: }
1.63 raeburn 7280: my @contexts = ('author','course','selfcreate');
1.33 raeburn 7281: my %context_title = (
7282: author => 'In author context',
7283: course => 'In course context',
1.63 raeburn 7284: selfcreate => 'When self creating account',
1.33 raeburn 7285: );
7286: my @fields = ('lastname','firstname','middlename','generation',
7287: 'permanentemail','id');
7288: my %roles = (
7289: author => ['ca','aa'],
7290: course => ['st','ep','ta','in','cr'],
7291: );
1.63 raeburn 7292: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
7293: if (ref($types) eq 'ARRAY') {
7294: push(@{$types},'default');
7295: $usertypes->{'default'} = $othertitle;
7296: }
7297: $roles{'selfcreate'} = $types;
1.33 raeburn 7298: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
7299: my %modifyhash;
7300: foreach my $context (@contexts) {
7301: foreach my $role (@{$roles{$context}}) {
7302: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$role);
7303: foreach my $item (@fields) {
7304: if (grep(/^\Q$item\E$/,@modifiable)) {
7305: $modifyhash{$context}{$role}{$item} = 1;
7306: } else {
7307: $modifyhash{$context}{$role}{$item} = 0;
7308: }
7309: }
7310: }
7311: if (ref($curr_usermodification{$context}) eq 'HASH') {
7312: foreach my $role (@{$roles{$context}}) {
7313: if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
7314: foreach my $field (@fields) {
7315: if ($modifyhash{$context}{$role}{$field} ne
7316: $curr_usermodification{$context}{$role}{$field}) {
7317: push(@{$changes{$context}},$role);
7318: last;
7319: }
7320: }
7321: }
7322: }
7323: } else {
7324: foreach my $context (@contexts) {
7325: foreach my $role (@{$roles{$context}}) {
7326: push(@{$changes{$context}},$role);
7327: }
7328: }
7329: }
7330: }
7331: my %usermodification_hash = (
7332: usermodification => \%modifyhash,
7333: );
7334: my $putresult = &Apache::lonnet::put_dom('configuration',
7335: \%usermodification_hash,$dom);
7336: if ($putresult eq 'ok') {
7337: if (keys(%changes) > 0) {
7338: $resulttext = &mt('Changes made: ').'<ul>';
7339: foreach my $context (@contexts) {
7340: if (ref($changes{$context}) eq 'ARRAY') {
7341: $resulttext .= '<li>'.$context_title{$context}.':<ul>';
7342: if (ref($changes{$context}) eq 'ARRAY') {
7343: foreach my $role (@{$changes{$context}}) {
7344: my $rolename;
1.63 raeburn 7345: if ($context eq 'selfcreate') {
7346: $rolename = $role;
7347: if (ref($usertypes) eq 'HASH') {
7348: if ($usertypes->{$role} ne '') {
7349: $rolename = $usertypes->{$role};
7350: }
7351: }
1.33 raeburn 7352: } else {
1.63 raeburn 7353: if ($role eq 'cr') {
7354: $rolename = &mt('Custom');
7355: } else {
7356: $rolename = &Apache::lonnet::plaintext($role);
7357: }
1.33 raeburn 7358: }
7359: my @modifiable;
1.63 raeburn 7360: if ($context eq 'selfcreate') {
1.126 bisitz 7361: $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Self-creation of account by users with status: [_1]',$rolename).'</span> - '.&mt('modifiable fields (if institutional data blank): ');
1.63 raeburn 7362: } else {
7363: $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
7364: }
1.33 raeburn 7365: foreach my $field (@fields) {
7366: if ($modifyhash{$context}{$role}{$field}) {
7367: push(@modifiable,$fieldtitles{$field});
7368: }
7369: }
7370: if (@modifiable > 0) {
7371: $resulttext .= join(', ',@modifiable);
7372: } else {
7373: $resulttext .= &mt('none');
7374: }
7375: $resulttext .= '</li>';
7376: }
7377: $resulttext .= '</ul></li>';
7378: }
7379: }
7380: }
7381: $resulttext .= '</ul>';
7382: } else {
7383: $resulttext = &mt('No changes made to user modification settings');
7384: }
7385: } else {
7386: $resulttext = '<span class="LC_error">'.
7387: &mt('An error occurred: [_1]',$putresult).'</span>';
7388: }
7389: return $resulttext;
7390: }
7391:
1.43 raeburn 7392: sub modify_defaults {
7393: my ($dom,$r) = @_;
7394: my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
7395: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.141 raeburn 7396: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def','portal_def');
1.43 raeburn 7397: my @authtypes = ('internal','krb4','krb5','localauth');
7398: foreach my $item (@items) {
7399: $newvalues{$item} = $env{'form.'.$item};
7400: if ($item eq 'auth_def') {
7401: if ($newvalues{$item} ne '') {
7402: if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
7403: push(@errors,$item);
7404: }
7405: }
7406: } elsif ($item eq 'lang_def') {
7407: if ($newvalues{$item} ne '') {
7408: if ($newvalues{$item} =~ /^(\w+)/) {
7409: my $langcode = $1;
1.103 raeburn 7410: if ($langcode ne 'x_chef') {
7411: if (code2language($langcode) eq '') {
7412: push(@errors,$item);
7413: }
1.43 raeburn 7414: }
7415: } else {
7416: push(@errors,$item);
7417: }
7418: }
1.54 raeburn 7419: } elsif ($item eq 'timezone_def') {
7420: if ($newvalues{$item} ne '') {
1.62 raeburn 7421: if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
1.54 raeburn 7422: push(@errors,$item);
7423: }
7424: }
1.68 raeburn 7425: } elsif ($item eq 'datelocale_def') {
7426: if ($newvalues{$item} ne '') {
7427: my @datelocale_ids = DateTime::Locale->ids();
7428: if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
7429: push(@errors,$item);
7430: }
7431: }
1.141 raeburn 7432: } elsif ($item eq 'portal_def') {
7433: if ($newvalues{$item} ne '') {
7434: 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])\/?$/) {
7435: push(@errors,$item);
7436: }
7437: }
1.43 raeburn 7438: }
7439: if (grep(/^\Q$item\E$/,@errors)) {
7440: $newvalues{$item} = $domdefaults{$item};
7441: } elsif ($domdefaults{$item} ne $newvalues{$item}) {
7442: $changes{$item} = 1;
7443: }
1.72 raeburn 7444: $domdefaults{$item} = $newvalues{$item};
1.43 raeburn 7445: }
7446: my %defaults_hash = (
1.72 raeburn 7447: defaults => \%newvalues,
7448: );
1.43 raeburn 7449: my $title = &defaults_titles();
7450: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
7451: $dom);
7452: if ($putresult eq 'ok') {
7453: if (keys(%changes) > 0) {
7454: $resulttext = &mt('Changes made:').'<ul>';
7455: my $version = $r->dir_config('lonVersion');
7456: 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";
7457: foreach my $item (sort(keys(%changes))) {
7458: my $value = $env{'form.'.$item};
7459: if ($value eq '') {
7460: $value = &mt('none');
7461: } elsif ($item eq 'auth_def') {
7462: my %authnames = &authtype_names();
7463: my %shortauth = (
7464: internal => 'int',
7465: krb4 => 'krb4',
7466: krb5 => 'krb5',
7467: localauth => 'loc',
7468: );
7469: $value = $authnames{$shortauth{$value}};
7470: }
7471: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
7472: $mailmsgtext .= "$title->{$item} set to $value\n";
7473: }
7474: $resulttext .= '</ul>';
7475: $mailmsgtext .= "\n";
7476: my $cachetime = 24*60*60;
1.72 raeburn 7477: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.68 raeburn 7478: if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
1.54 raeburn 7479: my $sysmail = $r->dir_config('lonSysEMail');
7480: &Apache::lonmsg::sendemail($sysmail,"LON-CAPA Domain Settings Change - $dom",$mailmsgtext);
7481: }
1.43 raeburn 7482: } else {
1.54 raeburn 7483: $resulttext = &mt('No changes made to default authentication/language/timezone settings');
1.43 raeburn 7484: }
7485: } else {
7486: $resulttext = '<span class="LC_error">'.
7487: &mt('An error occurred: [_1]',$putresult).'</span>';
7488: }
7489: if (@errors > 0) {
7490: $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
7491: foreach my $item (@errors) {
7492: $resulttext .= ' "'.$title->{$item}.'",';
7493: }
7494: $resulttext =~ s/,$//;
7495: }
7496: return $resulttext;
7497: }
7498:
1.46 raeburn 7499: sub modify_scantron {
1.48 raeburn 7500: my ($r,$dom,$confname,%domconfig) = @_;
1.46 raeburn 7501: my ($resulttext,%confhash,%changes,$errors);
7502: my $custom = 'custom.tab';
7503: my $default = 'default.tab';
7504: my $servadm = $r->dir_config('lonAdmEMail');
7505: my ($configuserok,$author_ok,$switchserver) =
7506: &config_check($dom,$confname,$servadm);
7507: if ($env{'form.scantronformat.filename'} ne '') {
7508: my $error;
7509: if ($configuserok eq 'ok') {
7510: if ($switchserver) {
1.130 raeburn 7511: $error = &mt("Upload of bubblesheet format file is not permitted to this server: [_1]",$switchserver);
1.46 raeburn 7512: } else {
7513: if ($author_ok eq 'ok') {
7514: my ($result,$scantronurl) =
7515: &publishlogo($r,'upload','scantronformat',$dom,
7516: $confname,'scantron','','',$custom);
7517: if ($result eq 'ok') {
7518: $confhash{'scantron'}{'scantronformat'} = $scantronurl;
1.48 raeburn 7519: $changes{'scantronformat'} = 1;
1.46 raeburn 7520: } else {
7521: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
7522: }
7523: } else {
7524: $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);
7525: }
7526: }
7527: } else {
7528: $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);
7529: }
7530: if ($error) {
7531: &Apache::lonnet::logthis($error);
7532: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
7533: }
7534: }
1.48 raeburn 7535: if (ref($domconfig{'scantron'}) eq 'HASH') {
7536: if ($domconfig{'scantron'}{'scantronformat'} ne '') {
7537: if ($env{'form.scantronformat_del'}) {
7538: $confhash{'scantron'}{'scantronformat'} = '';
7539: $changes{'scantronformat'} = 1;
1.46 raeburn 7540: }
7541: }
7542: }
7543: if (keys(%confhash) > 0) {
7544: my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
7545: $dom);
7546: if ($putresult eq 'ok') {
7547: if (keys(%changes) > 0) {
1.48 raeburn 7548: if (ref($confhash{'scantron'}) eq 'HASH') {
7549: $resulttext = &mt('Changes made:').'<ul>';
7550: if ($confhash{'scantron'}{'scantronformat'} eq '') {
1.130 raeburn 7551: $resulttext .= '<li>'.&mt('[_1] bubblesheet format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
1.48 raeburn 7552: } else {
1.130 raeburn 7553: $resulttext .= '<li>'.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
1.46 raeburn 7554: }
1.48 raeburn 7555: $resulttext .= '</ul>';
7556: } else {
1.130 raeburn 7557: $resulttext = &mt('Changes made to bubblesheet format file.');
1.46 raeburn 7558: }
7559: $resulttext .= '</ul>';
7560: &Apache::loncommon::devalidate_domconfig_cache($dom);
7561: } else {
1.130 raeburn 7562: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 7563: }
7564: } else {
7565: $resulttext = '<span class="LC_error">'.
7566: &mt('An error occurred: [_1]',$putresult).'</span>';
7567: }
7568: } else {
1.130 raeburn 7569: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 7570: }
7571: if ($errors) {
7572: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
7573: $errors.'</ul>';
7574: }
7575: return $resulttext;
7576: }
7577:
1.48 raeburn 7578: sub modify_coursecategories {
7579: my ($dom,%domconfig) = @_;
1.57 raeburn 7580: my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
7581: $cathash);
1.48 raeburn 7582: my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
1.55 raeburn 7583: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
1.57 raeburn 7584: $cathash = $domconfig{'coursecategories'}{'cats'};
7585: if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
7586: $changes{'togglecats'} = 1;
7587: $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
7588: }
7589: if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
7590: $changes{'categorize'} = 1;
7591: $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
7592: }
1.120 raeburn 7593: if ($domconfig{'coursecategories'}{'togglecatscomm'} ne $env{'form.togglecatscomm'}) {
7594: $changes{'togglecatscomm'} = 1;
7595: $domconfig{'coursecategories'}{'togglecatscomm'} = $env{'form.togglecatscomm'};
7596: }
7597: if ($domconfig{'coursecategories'}{'categorizecomm'} ne $env{'form.categorizecomm'}) {
7598: $changes{'categorizecomm'} = 1;
7599: $domconfig{'coursecategories'}{'categorizecomm'} = $env{'form.categorizecomm'};
7600: }
1.57 raeburn 7601: } else {
7602: $changes{'togglecats'} = 1;
7603: $changes{'categorize'} = 1;
1.124 raeburn 7604: $changes{'togglecatscomm'} = 1;
7605: $changes{'categorizecomm'} = 1;
1.87 raeburn 7606: $domconfig{'coursecategories'} = {
7607: togglecats => $env{'form.togglecats'},
7608: categorize => $env{'form.categorize'},
1.124 raeburn 7609: togglecatscomm => $env{'form.togglecatscomm'},
7610: categorizecomm => $env{'form.categorizecomm'},
1.120 raeburn 7611: };
1.57 raeburn 7612: }
7613: if (ref($cathash) eq 'HASH') {
7614: if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '') && ($env{'form.instcode'} == 0)) {
1.55 raeburn 7615: push (@deletecategory,'instcode::0');
7616: }
1.120 raeburn 7617: if (($domconfig{'coursecategories'}{'cats'}{'communities::0'} ne '') && ($env{'form.communities'} == 0)) {
7618: push(@deletecategory,'communities::0');
7619: }
1.48 raeburn 7620: }
1.57 raeburn 7621: my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
7622: if (ref($cathash) eq 'HASH') {
1.48 raeburn 7623: if (@deletecategory > 0) {
7624: #FIXME Need to remove category from all courses using a deleted category
1.57 raeburn 7625: &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
1.48 raeburn 7626: foreach my $item (@deletecategory) {
1.57 raeburn 7627: if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
7628: delete($domconfig{'coursecategories'}{'cats'}{$item});
1.48 raeburn 7629: $deletions{$item} = 1;
1.57 raeburn 7630: &recurse_cat_deletes($item,$cathash,\%deletions);
1.48 raeburn 7631: }
7632: }
7633: }
1.57 raeburn 7634: foreach my $item (keys(%{$cathash})) {
1.48 raeburn 7635: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
1.57 raeburn 7636: if ($cathash->{$item} ne $env{'form.'.$item}) {
1.48 raeburn 7637: $reorderings{$item} = 1;
1.57 raeburn 7638: $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
1.48 raeburn 7639: }
7640: if ($env{'form.addcategory_name_'.$item} ne '') {
7641: my $newcat = $env{'form.addcategory_name_'.$item};
7642: my $newdepth = $depth+1;
7643: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 7644: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
1.48 raeburn 7645: $adds{$newitem} = 1;
7646: }
7647: if ($env{'form.subcat_'.$item} ne '') {
7648: my $newcat = $env{'form.subcat_'.$item};
7649: my $newdepth = $depth+1;
7650: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 7651: $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
1.48 raeburn 7652: $adds{$newitem} = 1;
7653: }
7654: }
7655: }
7656: if ($env{'form.instcode'} eq '1') {
1.57 raeburn 7657: if (ref($cathash) eq 'HASH') {
1.48 raeburn 7658: my $newitem = 'instcode::0';
1.57 raeburn 7659: if ($cathash->{$newitem} eq '') {
7660: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 7661: $adds{$newitem} = 1;
7662: }
7663: } else {
7664: my $newitem = 'instcode::0';
1.57 raeburn 7665: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 7666: $adds{$newitem} = 1;
7667: }
7668: }
1.120 raeburn 7669: if ($env{'form.communities'} eq '1') {
7670: if (ref($cathash) eq 'HASH') {
7671: my $newitem = 'communities::0';
7672: if ($cathash->{$newitem} eq '') {
7673: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
7674: $adds{$newitem} = 1;
7675: }
7676: } else {
7677: my $newitem = 'communities::0';
7678: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
7679: $adds{$newitem} = 1;
7680: }
7681: }
1.48 raeburn 7682: if ($env{'form.addcategory_name'} ne '') {
1.120 raeburn 7683: if (($env{'form.addcategory_name'} ne 'instcode') &&
7684: ($env{'form.addcategory_name'} ne 'communities')) {
7685: my $newitem = &escape($env{'form.addcategory_name'}).'::0';
7686: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
7687: $adds{$newitem} = 1;
7688: }
1.48 raeburn 7689: }
1.57 raeburn 7690: my $putresult;
1.48 raeburn 7691: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
7692: if (keys(%deletions) > 0) {
7693: foreach my $key (keys(%deletions)) {
7694: if ($predelallitems{$key} ne '') {
7695: $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
7696: }
7697: }
7698: }
7699: my (@chkcats,@chktrails,%chkallitems);
1.57 raeburn 7700: &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
1.48 raeburn 7701: if (ref($chkcats[0]) eq 'ARRAY') {
7702: my $depth = 0;
7703: my $chg = 0;
7704: for (my $i=0; $i<@{$chkcats[0]}; $i++) {
7705: my $name = $chkcats[0][$i];
7706: my $item;
7707: if ($name eq '') {
7708: $chg ++;
7709: } else {
7710: $item = &escape($name).'::0';
7711: if ($chg) {
1.57 raeburn 7712: $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
1.48 raeburn 7713: }
7714: $depth ++;
1.57 raeburn 7715: &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
1.48 raeburn 7716: $depth --;
7717: }
7718: }
7719: }
1.57 raeburn 7720: }
7721: if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
7722: $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
1.48 raeburn 7723: if ($putresult eq 'ok') {
1.57 raeburn 7724: my %title = (
1.120 raeburn 7725: togglecats => 'Show/Hide a course in catalog',
7726: categorize => 'Assign a category to a course',
7727: togglecatscomm => 'Show/Hide a community in catalog',
7728: categorizecomm => 'Assign a category to a community',
1.57 raeburn 7729: );
7730: my %level = (
1.120 raeburn 7731: dom => 'set in Domain ("Modify Course/Community")',
7732: crs => 'set in Course ("Course Configuration")',
7733: comm => 'set in Community ("Community Configuration")',
1.57 raeburn 7734: );
1.48 raeburn 7735: $resulttext = &mt('Changes made:').'<ul>';
1.57 raeburn 7736: if ($changes{'togglecats'}) {
7737: $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>';
7738: }
7739: if ($changes{'categorize'}) {
7740: $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
1.48 raeburn 7741: }
1.120 raeburn 7742: if ($changes{'togglecatscomm'}) {
7743: $resulttext .= '<li>'.&mt("$title{'togglecatscomm'} $level{$env{'form.togglecatscomm'}}").'</li>';
7744: }
7745: if ($changes{'categorizecomm'}) {
7746: $resulttext .= '<li>'.&mt("$title{'categorizecomm'} $level{$env{'form.categorizecomm'}}").'</li>';
7747: }
1.57 raeburn 7748: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
7749: my $cathash;
7750: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
7751: $cathash = $domconfig{'coursecategories'}{'cats'};
7752: } else {
7753: $cathash = {};
7754: }
7755: my (@cats,@trails,%allitems);
7756: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
7757: if (keys(%deletions) > 0) {
7758: $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
7759: foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) {
7760: $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
7761: }
7762: $resulttext .= '</ul></li>';
7763: }
7764: if (keys(%reorderings) > 0) {
7765: my %sort_by_trail;
7766: $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
7767: foreach my $key (keys(%reorderings)) {
7768: if ($allitems{$key} ne '') {
7769: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
7770: }
1.48 raeburn 7771: }
1.57 raeburn 7772: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
7773: $resulttext .= '<li>'.$trails[$trail].'</li>';
7774: }
7775: $resulttext .= '</ul></li>';
1.48 raeburn 7776: }
1.57 raeburn 7777: if (keys(%adds) > 0) {
7778: my %sort_by_trail;
7779: $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
7780: foreach my $key (keys(%adds)) {
7781: if ($allitems{$key} ne '') {
7782: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
7783: }
7784: }
7785: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
7786: $resulttext .= '<li>'.$trails[$trail].'</li>';
1.48 raeburn 7787: }
1.57 raeburn 7788: $resulttext .= '</ul></li>';
1.48 raeburn 7789: }
7790: }
7791: $resulttext .= '</ul>';
7792: } else {
7793: $resulttext = '<span class="LC_error">'.
1.57 raeburn 7794: &mt('An error occurred: [_1]',$putresult).'</span>';
1.48 raeburn 7795: }
7796: } else {
1.120 raeburn 7797: $resulttext = &mt('No changes made to course and community categories');
1.48 raeburn 7798: }
7799: return $resulttext;
7800: }
7801:
1.69 raeburn 7802: sub modify_serverstatuses {
7803: my ($dom,%domconfig) = @_;
7804: my ($resulttext,%changes,%currserverstatus,%newserverstatus);
7805: if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
7806: %currserverstatus = %{$domconfig{'serverstatuses'}};
7807: }
7808: my @pages = &serverstatus_pages();
7809: foreach my $type (@pages) {
7810: $newserverstatus{$type}{'namedusers'} = '';
7811: $newserverstatus{$type}{'machines'} = '';
7812: if (defined($env{'form.'.$type.'_namedusers'})) {
7813: my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
7814: my @okusers;
7815: foreach my $user (@users) {
7816: my ($uname,$udom) = split(/:/,$user);
7817: if (($udom =~ /^$match_domain$/) &&
7818: (&Apache::lonnet::domain($udom)) &&
7819: ($uname =~ /^$match_username$/)) {
7820: if (!grep(/^\Q$user\E/,@okusers)) {
7821: push(@okusers,$user);
7822: }
7823: }
7824: }
7825: if (@okusers > 0) {
7826: @okusers = sort(@okusers);
7827: $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
7828: }
7829: }
7830: if (defined($env{'form.'.$type.'_machines'})) {
7831: my @machines = split(/,/,$env{'form.'.$type.'_machines'});
7832: my @okmachines;
7833: foreach my $ip (@machines) {
7834: my @parts = split(/\./,$ip);
7835: next if (@parts < 4);
7836: my $badip = 0;
7837: for (my $i=0; $i<4; $i++) {
7838: if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
7839: $badip = 1;
7840: last;
7841: }
7842: }
7843: if (!$badip) {
7844: push(@okmachines,$ip);
7845: }
7846: }
7847: @okmachines = sort(@okmachines);
7848: $newserverstatus{$type}{'machines'} = join(',',@okmachines);
7849: }
7850: }
7851: my %serverstatushash = (
7852: serverstatuses => \%newserverstatus,
7853: );
7854: foreach my $type (@pages) {
1.83 raeburn 7855: foreach my $setting ('namedusers','machines') {
1.84 raeburn 7856: my (@current,@new);
1.83 raeburn 7857: if (ref($currserverstatus{$type}) eq 'HASH') {
1.84 raeburn 7858: if ($currserverstatus{$type}{$setting} ne '') {
7859: @current = split(/,/,$currserverstatus{$type}{$setting});
7860: }
7861: }
7862: if ($newserverstatus{$type}{$setting} ne '') {
7863: @new = split(/,/,$newserverstatus{$type}{$setting});
1.83 raeburn 7864: }
7865: if (@current > 0) {
7866: if (@new > 0) {
7867: foreach my $item (@current) {
7868: if (!grep(/^\Q$item\E$/,@new)) {
7869: $changes{$type}{$setting} = 1;
1.82 raeburn 7870: last;
7871: }
7872: }
1.84 raeburn 7873: foreach my $item (@new) {
7874: if (!grep(/^\Q$item\E$/,@current)) {
7875: $changes{$type}{$setting} = 1;
7876: last;
1.82 raeburn 7877: }
7878: }
7879: } else {
1.83 raeburn 7880: $changes{$type}{$setting} = 1;
1.69 raeburn 7881: }
1.83 raeburn 7882: } elsif (@new > 0) {
7883: $changes{$type}{$setting} = 1;
1.69 raeburn 7884: }
7885: }
7886: }
7887: if (keys(%changes) > 0) {
1.81 raeburn 7888: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 7889: my $putresult = &Apache::lonnet::put_dom('configuration',
7890: \%serverstatushash,$dom);
7891: if ($putresult eq 'ok') {
7892: $resulttext .= &mt('Changes made:').'<ul>';
7893: foreach my $type (@pages) {
1.84 raeburn 7894: if (ref($changes{$type}) eq 'HASH') {
1.69 raeburn 7895: $resulttext .= '<li>'.$titles->{$type}.'<ul>';
1.84 raeburn 7896: if ($changes{$type}{'namedusers'}) {
1.69 raeburn 7897: if ($newserverstatus{$type}{'namedusers'} eq '') {
7898: $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n";
7899: } else {
7900: $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n";
7901: }
1.84 raeburn 7902: }
7903: if ($changes{$type}{'machines'}) {
1.69 raeburn 7904: if ($newserverstatus{$type}{'machines'} eq '') {
7905: $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n";
7906: } else {
7907: $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n";
7908: }
7909:
7910: }
7911: $resulttext .= '</ul></li>';
7912: }
7913: }
7914: $resulttext .= '</ul>';
7915: } else {
7916: $resulttext = '<span class="LC_error">'.
7917: &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>';
7918:
7919: }
7920: } else {
7921: $resulttext = &mt('No changes made to access to server status pages');
7922: }
7923: return $resulttext;
7924: }
7925:
1.118 jms 7926: sub modify_helpsettings {
1.122 jms 7927: my ($r,$dom,$confname,%domconfig) = @_;
1.166 raeburn 7928: my ($resulttext,$errors,%changes,%helphash);
7929: my %defaultchecked = ('submitbugs' => 'on');
7930: my @offon = ('off','on');
1.118 jms 7931: my @toggles = ('submitbugs');
7932: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
7933: foreach my $item (@toggles) {
1.166 raeburn 7934: if ($defaultchecked{$item} eq 'on') {
7935: if ($domconfig{'helpsettings'}{$item} eq '') {
7936: if ($env{'form.'.$item} eq '0') {
7937: $changes{$item} = 1;
7938: }
7939: } elsif ($domconfig{'helpsettings'}{$item} ne $env{'form.'.$item}) {
7940: $changes{$item} = 1;
7941: }
7942: } elsif ($defaultchecked{$item} eq 'off') {
7943: if ($domconfig{'helpsettings'}{$item} eq '') {
7944: if ($env{'form.'.$item} eq '1') {
7945: $changes{$item} = 1;
7946: }
7947: } elsif ($domconfig{'helpsettings'}{$item} ne $env{'form.'.$item}) {
7948: $changes{$item} = 1;
7949: }
7950: }
7951: if (($env{'form.'.$item} eq '0') || ($env{'form.'.$item} eq '1')) {
7952: $helphash{'helpsettings'}{$item} = $env{'form.'.$item};
7953: }
7954: }
1.118 jms 7955: }
1.123 jms 7956: my $putresult;
7957: if (keys(%changes) > 0) {
1.166 raeburn 7958: $putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom);
1.168 raeburn 7959: if ($putresult eq 'ok') {
1.166 raeburn 7960: $resulttext = &mt('Changes made:').'<ul>';
7961: foreach my $item (sort(keys(%changes))) {
7962: if ($item eq 'submitbugs') {
7963: $resulttext .= '<li>'.&mt('Display link to: [_1] set to "'.$offon[$env{'form.'.$item}].'".',
7964: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
7965: &mt('LON-CAPA bug tracker'),600,500)).'</li>';
7966: }
7967: }
7968: $resulttext .= '</ul>';
7969: } else {
7970: $resulttext = &mt('No changes made to help settings');
1.168 raeburn 7971: $errors .= '<li><span class="LC_error">'.
7972: &mt('An error occurred storing the settings: [_1]',
7973: $putresult).'</span></li>';
1.166 raeburn 7974: }
1.118 jms 7975: }
7976: if ($errors) {
1.168 raeburn 7977: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.118 jms 7978: $errors.'</ul>';
7979: }
7980: return $resulttext;
7981: }
7982:
1.121 raeburn 7983: sub modify_coursedefaults {
7984: my ($dom,%domconfig) = @_;
7985: my ($resulttext,$errors,%changes,%defaultshash);
7986: my %defaultchecked = ('canuse_pdfforms' => 'off');
7987: my @toggles = ('canuse_pdfforms');
1.198 raeburn 7988: my @numbers = ('anonsurvey_threshold','uploadquota_official','uploadquota_unofficial',
7989: 'uploadquota_community');
7990: my @types = ('official','unofficial','community');
7991: my %staticdefaults = (
7992: anonsurvey_threshold => 10,
7993: uploadquota => 500,
7994: );
1.121 raeburn 7995:
7996: $defaultshash{'coursedefaults'} = {};
7997:
7998: if (ref($domconfig{'coursedefaults'}) ne 'HASH') {
7999: if ($domconfig{'coursedefaults'} eq '') {
8000: $domconfig{'coursedefaults'} = {};
8001: }
8002: }
8003:
8004: if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
8005: foreach my $item (@toggles) {
8006: if ($defaultchecked{$item} eq 'on') {
8007: if (($domconfig{'coursedefaults'}{$item} eq '') &&
8008: ($env{'form.'.$item} eq '0')) {
8009: $changes{$item} = 1;
1.192 raeburn 8010: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
1.121 raeburn 8011: $changes{$item} = 1;
8012: }
8013: } elsif ($defaultchecked{$item} eq 'off') {
8014: if (($domconfig{'coursedefaults'}{$item} eq '') &&
8015: ($env{'form.'.$item} eq '1')) {
8016: $changes{$item} = 1;
8017: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
8018: $changes{$item} = 1;
8019: }
8020: }
8021: $defaultshash{'coursedefaults'}{$item} = $env{'form.'.$item};
8022: }
1.198 raeburn 8023: foreach my $item (@numbers) {
8024: my ($currdef,$newdef);
8025: my $newdef = $env{'form.'.$item};
8026: if ($item eq 'anonsurvey_threshold') {
8027: $currdef = $domconfig{'coursedefaults'}{$item};
8028: $newdef =~ s/\D//g;
8029: if ($newdef eq '' || $newdef < 1) {
8030: $newdef = 1;
8031: }
8032: $defaultshash{'coursedefaults'}{$item} = $newdef;
8033: } else {
8034: my ($type) = ($item =~ /^\Quploadquota_\E(\w+)$/);
8035: if (ref($domconfig{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
8036: $currdef = $domconfig{'coursedefaults'}{'uploadquota'}{$type};
8037: }
8038: $newdef =~ s/[^\w.\-]//g;
8039: $defaultshash{'coursedefaults'}{'uploadquota'}{$type} = $newdef;
8040: }
8041: if ($currdef ne $newdef) {
8042: my $staticdef;
8043: if ($item eq 'anonsurvey_threshold') {
8044: unless (($currdef eq '') && ($newdef == $staticdefaults{$item})) {
8045: $changes{$item} = 1;
8046: }
8047: } else {
8048: unless (($currdef eq '') && ($newdef == $staticdefaults{'uploadquota'})) {
8049: $changes{'uploadquota'} = 1;
8050: }
8051: }
1.139 raeburn 8052: }
8053: }
1.192 raeburn 8054: my $officialcreds = $env{'form.official_credits'};
8055: $officialcreds =~ s/^[^\d\.]//g;
8056: my $unofficialcreds = $env{'form.unofficial_credits'};
8057: $unofficialcreds =~ s/^[^\d\.]//g;
8058: if (ref($domconfig{'coursedefaults'}{'coursecredits'} ne 'HASH') &&
8059: ($env{'form.coursecredits'} eq '1')) {
8060: $changes{'coursecredits'} = 1;
8061: } else {
8062: if (($domconfig{'coursedefaults'}{'coursecredits'}{'official'} ne $officialcreds) ||
8063: ($domconfig{'coursedefaults'}{'coursecredits'}{'unofficial'} ne $unofficialcreds)) {
8064: $changes{'coursecredits'} = 1;
8065: }
8066: }
8067: $defaultshash{'coursedefaults'}{'coursecredits'} = {
8068: official => $officialcreds,
8069: unofficial => $unofficialcreds,
8070: }
1.121 raeburn 8071: }
8072: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
8073: $dom);
8074: if ($putresult eq 'ok') {
1.192 raeburn 8075: my %domdefaults;
1.121 raeburn 8076: if (keys(%changes) > 0) {
1.198 raeburn 8077: if (($changes{'canuse_pdfforms'}) || ($changes{'coursecredits'}) || ($changes{'uploadquota'})) {
1.192 raeburn 8078: %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
8079: if ($changes{'canuse_pdfforms'}) {
8080: $domdefaults{'canuse_pdfforms'}=$defaultshash{'coursedefaults'}{'canuse_pdfforms'};
8081: }
8082: if ($changes{'coursecredits'}) {
8083: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
8084: $domdefaults{'officialcredits'} =
8085: $defaultshash{'coursedefaults'}{'coursecredits'}{'official'};
8086: $domdefaults{'unofficialcredits'} =
8087: $defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'};
8088: }
8089: }
1.198 raeburn 8090: if ($changes{'uploadquota'}) {
8091: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
8092: foreach my $type (@types) {
8093: $domdefaults{$type.'quota'}=$defaultshash{'coursedefaults'}{'uploadquota'}{$type};
8094: }
8095: }
8096: }
1.121 raeburn 8097: my $cachetime = 24*60*60;
8098: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
8099: }
8100: $resulttext = &mt('Changes made:').'<ul>';
8101: foreach my $item (sort(keys(%changes))) {
8102: if ($item eq 'canuse_pdfforms') {
8103: if ($env{'form.'.$item} eq '1') {
8104: $resulttext .= '<li>'.&mt("Course/Community users can create/upload PDF forms set to 'on'").'</li>';
8105: } else {
8106: $resulttext .= '<li>'.&mt('Course/Community users can create/upload PDF forms set to "off"').'</li>';
8107: }
1.139 raeburn 8108: } elsif ($item eq 'anonsurvey_threshold') {
1.192 raeburn 8109: $resulttext .= '<li>'.&mt('Responder count required for display of anonymous survey submissions set to [_1].',$defaultshash{'coursedefaults'}{'anonsurvey_threshold'}).'</li>';
1.198 raeburn 8110: } elsif ($item eq 'uploadquota') {
8111: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
8112: $resulttext .= '<li>'.&mt('Default quota for content uploaded to a course/community via Course Editor set as follows:').'<ul>'.
8113: '<li>'.&mt('Official courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'official'}.'</b>').'</li>'.
8114: '<li>'.&mt('Unofficial courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'unofficial'}.'</b>').'</li>'.
8115: '<li>'.&mt('Communities: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'community'}.'</b>').'</li>'.
8116: '</ul>'.
8117: '</li>';
8118: } else {
8119: $resulttext .= '<li>'.&mt('Default quota for content uploaded via Course Editor remains default: [_1] MB',$staticdefaults{'uploadquota'}).'</li>';
8120: }
1.192 raeburn 8121: } elsif ($item eq 'coursecredits') {
8122: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
8123: if (($domdefaults{'officialcredits'} eq '') &&
8124: ($domdefaults{'unofficialcredits'} eq '')) {
8125: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
8126: } else {
8127: $resulttext .= '<li>'.&mt('Student credits can be set per course by a Domain Coordinator, with the following defaults applying:').'<ul>'.
8128: '<li>'.&mt('Official courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'official'}).'</li>'.
8129: '<li>'.&mt('Unofficial courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'}).'</li>'.
8130: '</ul>'.
8131: '</li>';
8132: }
8133: } else {
8134: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
8135: }
1.140 raeburn 8136: }
1.121 raeburn 8137: }
8138: $resulttext .= '</ul>';
8139: } else {
8140: $resulttext = &mt('No changes made to course defaults');
8141: }
8142: } else {
8143: $resulttext = '<span class="LC_error">'.
8144: &mt('An error occurred: [_1]',$putresult).'</span>';
8145: }
8146: return $resulttext;
8147: }
8148:
1.137 raeburn 8149: sub modify_usersessions {
8150: my ($dom,%domconfig) = @_;
1.145 raeburn 8151: my @hostingtypes = ('version','excludedomain','includedomain');
8152: my @offloadtypes = ('primary','default');
8153: my %types = (
8154: remote => \@hostingtypes,
8155: hosted => \@hostingtypes,
8156: spares => \@offloadtypes,
8157: );
8158: my @prefixes = ('remote','hosted','spares');
1.137 raeburn 8159: my @lcversions = &Apache::lonnet::all_loncaparevs();
1.138 raeburn 8160: my (%by_ip,%by_location,@intdoms);
8161: &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
8162: my @locations = sort(keys(%by_location));
1.137 raeburn 8163: my (%defaultshash,%changes);
8164: foreach my $prefix (@prefixes) {
8165: $defaultshash{'usersessions'}{$prefix} = {};
8166: }
8167: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
8168: my $resulttext;
1.138 raeburn 8169: my %iphost = &Apache::lonnet::get_iphost();
1.137 raeburn 8170: foreach my $prefix (@prefixes) {
1.145 raeburn 8171: next if ($prefix eq 'spares');
8172: foreach my $type (@{$types{$prefix}}) {
1.137 raeburn 8173: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
8174: if ($type eq 'version') {
8175: my $value = $env{'form.'.$prefix.'_'.$type};
8176: my $okvalue;
8177: if ($value ne '') {
8178: if (grep(/^\Q$value\E$/,@lcversions)) {
8179: $okvalue = $value;
8180: }
8181: }
8182: if (ref($domconfig{'usersessions'}) eq 'HASH') {
8183: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
8184: if ($domconfig{'usersessions'}{$prefix}{$type} ne '') {
8185: if ($inuse == 0) {
8186: $changes{$prefix}{$type} = 1;
8187: } else {
8188: if ($okvalue ne $domconfig{'usersessions'}{$prefix}{$type}) {
8189: $changes{$prefix}{$type} = 1;
8190: }
8191: if ($okvalue ne '') {
8192: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
8193: }
8194: }
8195: } else {
8196: if (($inuse == 1) && ($okvalue ne '')) {
8197: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
8198: $changes{$prefix}{$type} = 1;
8199: }
8200: }
8201: } else {
8202: if (($inuse == 1) && ($okvalue ne '')) {
8203: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
8204: $changes{$prefix}{$type} = 1;
8205: }
8206: }
8207: } else {
8208: if (($inuse == 1) && ($okvalue ne '')) {
8209: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
8210: $changes{$prefix}{$type} = 1;
8211: }
8212: }
8213: } else {
8214: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
8215: my @okvals;
8216: foreach my $val (@vals) {
1.138 raeburn 8217: if ($val =~ /:/) {
8218: my @items = split(/:/,$val);
8219: foreach my $item (@items) {
8220: if (ref($by_location{$item}) eq 'ARRAY') {
8221: push(@okvals,$item);
8222: }
8223: }
8224: } else {
8225: if (ref($by_location{$val}) eq 'ARRAY') {
8226: push(@okvals,$val);
8227: }
1.137 raeburn 8228: }
8229: }
8230: @okvals = sort(@okvals);
8231: if (ref($domconfig{'usersessions'}) eq 'HASH') {
8232: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
8233: if (ref($domconfig{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
8234: if ($inuse == 0) {
8235: $changes{$prefix}{$type} = 1;
8236: } else {
8237: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
8238: my @changed = &Apache::loncommon::compare_arrays($domconfig{'usersessions'}{$prefix}{$type},$defaultshash{'usersessions'}{$prefix}{$type});
8239: if (@changed > 0) {
8240: $changes{$prefix}{$type} = 1;
8241: }
8242: }
8243: } else {
8244: if ($inuse == 1) {
8245: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
8246: $changes{$prefix}{$type} = 1;
8247: }
8248: }
8249: } else {
8250: if ($inuse == 1) {
8251: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
8252: $changes{$prefix}{$type} = 1;
8253: }
8254: }
8255: } else {
8256: if ($inuse == 1) {
8257: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
8258: $changes{$prefix}{$type} = 1;
8259: }
8260: }
8261: }
8262: }
8263: }
1.145 raeburn 8264:
8265: my @alldoms = &Apache::lonnet::all_domains();
1.149 raeburn 8266: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.145 raeburn 8267: my %spareid = ¤t_offloads_to($dom,$domconfig{'usersessions'},\%servers);
8268: my $savespares;
8269:
8270: foreach my $lonhost (sort(keys(%servers))) {
8271: my $serverhomeID =
8272: &Apache::lonnet::get_server_homeID($servers{$lonhost});
1.152 raeburn 8273: my $serverhostname = &Apache::lonnet::hostname($lonhost);
1.145 raeburn 8274: $defaultshash{'usersessions'}{'spares'}{$lonhost} = {};
8275: my %spareschg;
8276: foreach my $type (@{$types{'spares'}}) {
8277: my @okspares;
8278: my @checked = &Apache::loncommon::get_env_multiple('form.spare_'.$type.'_'.$lonhost);
8279: foreach my $server (@checked) {
1.152 raeburn 8280: if (&Apache::lonnet::hostname($server) ne '') {
8281: unless (&Apache::lonnet::hostname($server) eq $serverhostname) {
8282: unless (grep(/^\Q$server\E$/,@okspares)) {
8283: push(@okspares,$server);
8284: }
1.145 raeburn 8285: }
8286: }
8287: }
8288: my $new = $env{'form.newspare_'.$type.'_'.$lonhost};
8289: my $newspare;
1.152 raeburn 8290: if (($new ne '') && (&Apache::lonnet::hostname($new))) {
8291: unless (&Apache::lonnet::hostname($new) eq $serverhostname) {
1.145 raeburn 8292: $newspare = $new;
8293: }
8294: }
1.152 raeburn 8295: my @spares;
8296: if (($newspare ne '') && (!grep(/^\Q$newspare\E$/,@okspares))) {
8297: @spares = sort(@okspares,$newspare);
8298: } else {
8299: @spares = sort(@okspares);
8300: }
8301: $defaultshash{'usersessions'}{'spares'}{$lonhost}{$type} = \@spares;
1.145 raeburn 8302: if (ref($spareid{$lonhost}) eq 'HASH') {
8303: if (ref($spareid{$lonhost}{$type}) eq 'ARRAY') {
1.152 raeburn 8304: my @diffs = &Apache::loncommon::compare_arrays($spareid{$lonhost}{$type},\@spares);
1.145 raeburn 8305: if (@diffs > 0) {
8306: $spareschg{$type} = 1;
8307: }
8308: }
8309: }
8310: }
8311: if (keys(%spareschg) > 0) {
8312: $changes{'spares'}{$lonhost} = \%spareschg;
8313: }
8314: }
8315:
8316: if (ref($domconfig{'usersessions'}) eq 'HASH') {
8317: if (ref($domconfig{'usersessions'}{'spares'}) eq 'HASH') {
8318: if (ref($changes{'spares'}) eq 'HASH') {
8319: if (keys(%{$changes{'spares'}}) > 0) {
8320: $savespares = 1;
8321: }
8322: }
8323: } else {
8324: $savespares = 1;
8325: }
8326: }
8327:
1.147 raeburn 8328: my $nochgmsg = &mt('No changes made to settings for user session hosting/offloading.');
8329: if ((keys(%changes) > 0) || ($savespares)) {
1.137 raeburn 8330: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
8331: $dom);
8332: if ($putresult eq 'ok') {
8333: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
8334: if (ref($defaultshash{'usersessions'}{'remote'}) eq 'HASH') {
8335: $domdefaults{'remotesessions'} = $defaultshash{'usersessions'}{'remote'};
8336: }
8337: if (ref($defaultshash{'usersessions'}{'hosted'}) eq 'HASH') {
8338: $domdefaults{'hostedsessions'} = $defaultshash{'usersessions'}{'hosted'};
8339: }
8340: }
8341: my $cachetime = 24*60*60;
8342: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.147 raeburn 8343: if (keys(%changes) > 0) {
8344: my %lt = &usersession_titles();
8345: $resulttext = &mt('Changes made:').'<ul>';
8346: foreach my $prefix (@prefixes) {
8347: if (ref($changes{$prefix}) eq 'HASH') {
8348: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
8349: if ($prefix eq 'spares') {
8350: if (ref($changes{$prefix}) eq 'HASH') {
8351: foreach my $lonhost (sort(keys(%{$changes{$prefix}}))) {
8352: $resulttext .= '<li><b>'.$lonhost.'</b> ';
1.148 raeburn 8353: my $lonhostdom = &Apache::lonnet::host_domain($lonhost);
8354: &Apache::lonnet::remote_devalidate_cache($lonhost,'spares',$lonhostdom);
1.147 raeburn 8355: if (ref($changes{$prefix}{$lonhost}) eq 'HASH') {
8356: foreach my $type (@{$types{$prefix}}) {
8357: if ($changes{$prefix}{$lonhost}{$type}) {
8358: my $offloadto = &mt('None');
8359: if (ref($defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}) eq 'ARRAY') {
8360: if (@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}} > 0) {
8361: $offloadto = join(', ',@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}});
8362: }
1.145 raeburn 8363: }
1.147 raeburn 8364: $resulttext .= &mt('[_1] set to: [_2].','<i>'.$lt{$type}.'</i>',$offloadto).(' 'x3);
1.145 raeburn 8365: }
1.137 raeburn 8366: }
8367: }
1.147 raeburn 8368: $resulttext .= '</li>';
1.137 raeburn 8369: }
8370: }
1.147 raeburn 8371: } else {
8372: foreach my $type (@{$types{$prefix}}) {
8373: if (defined($changes{$prefix}{$type})) {
8374: my $newvalue;
8375: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
8376: if (ref($defaultshash{'usersessions'}{$prefix})) {
8377: if ($type eq 'version') {
8378: $newvalue = $defaultshash{'usersessions'}{$prefix}{$type};
8379: } elsif (ref($defaultshash{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
8380: if (@{$defaultshash{'usersessions'}{$prefix}{$type}} > 0) {
8381: $newvalue = join(', ',@{$defaultshash{'usersessions'}{$prefix}{$type}});
8382: }
1.145 raeburn 8383: }
8384: }
8385: }
1.147 raeburn 8386: if ($newvalue eq '') {
8387: if ($type eq 'version') {
8388: $resulttext .= '<li>'.&mt('[_1] set to: off',$lt{$type}).'</li>';
8389: } else {
8390: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
8391: }
1.145 raeburn 8392: } else {
1.147 raeburn 8393: if ($type eq 'version') {
8394: $newvalue .= ' '.&mt('(or later)');
8395: }
8396: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
1.145 raeburn 8397: }
1.137 raeburn 8398: }
8399: }
8400: }
1.147 raeburn 8401: $resulttext .= '</ul>';
1.137 raeburn 8402: }
8403: }
1.147 raeburn 8404: $resulttext .= '</ul>';
8405: } else {
8406: $resulttext = $nochgmsg;
1.137 raeburn 8407: }
8408: } else {
8409: $resulttext = '<span class="LC_error">'.
8410: &mt('An error occurred: [_1]',$putresult).'</span>';
8411: }
8412: } else {
1.147 raeburn 8413: $resulttext = $nochgmsg;
1.137 raeburn 8414: }
8415: return $resulttext;
8416: }
8417:
1.150 raeburn 8418: sub modify_loadbalancing {
8419: my ($dom,%domconfig) = @_;
8420: my $primary_id = &Apache::lonnet::domain($dom,'primary');
8421: my $intdom = &Apache::lonnet::internet_dom($primary_id);
8422: my ($othertitle,$usertypes,$types) =
8423: &Apache::loncommon::sorted_inst_types($dom);
8424: my %servers = &Apache::lonnet::internet_dom_servers($dom);
8425: my @sparestypes = ('primary','default');
8426: my %typetitles = &sparestype_titles();
8427: my $resulttext;
1.171 raeburn 8428: my (%currbalancer,%currtargets,%currrules,%existing);
8429: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
8430: %existing = %{$domconfig{'loadbalancing'}};
8431: }
8432: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
8433: \%currtargets,\%currrules);
8434: my ($saveloadbalancing,%defaultshash,%changes);
8435: my ($alltypes,$othertypes,$titles) =
8436: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
8437: my %ruletitles = &offloadtype_text();
8438: my @deletions = &Apache::loncommon::get_env_multiple('form.loadbalancing_delete');
8439: for (my $i=0; $i<$env{'form.loadbalancing_total'}; $i++) {
8440: my $balancer = $env{'form.loadbalancing_lonhost_'.$i};
8441: if ($balancer eq '') {
8442: next;
8443: }
8444: if (!exists($servers{$balancer})) {
8445: if (exists($currbalancer{$balancer})) {
8446: push(@{$changes{'delete'}},$balancer);
1.150 raeburn 8447: }
1.171 raeburn 8448: next;
8449: }
8450: if ((@deletions > 0) && (grep(/^\Q$i\E$/,@deletions))) {
8451: push(@{$changes{'delete'}},$balancer);
8452: next;
8453: }
8454: if (!exists($currbalancer{$balancer})) {
8455: push(@{$changes{'add'}},$balancer);
8456: }
8457: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'} = [];
8458: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'default'} = [];
8459: $defaultshash{'loadbalancing'}{$balancer}{'rules'} = {};
8460: unless (ref($domconfig{'loadbalancing'}) eq 'HASH') {
8461: $saveloadbalancing = 1;
8462: }
8463: foreach my $sparetype (@sparestypes) {
8464: my @targets = &Apache::loncommon::get_env_multiple('form.loadbalancing_target_'.$i.'_'.$sparetype);
8465: my @offloadto;
8466: foreach my $target (@targets) {
8467: if (($servers{$target}) && ($target ne $balancer)) {
8468: if ($sparetype eq 'default') {
8469: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}) eq 'ARRAY') {
8470: next if (grep(/^\Q$target\E$/,@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}}));
1.150 raeburn 8471: }
8472: }
1.171 raeburn 8473: unless(grep(/^\Q$target\E$/,@offloadto)) {
8474: push(@offloadto,$target);
8475: }
1.150 raeburn 8476: }
1.171 raeburn 8477: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype} = \@offloadto;
1.150 raeburn 8478: }
8479: }
1.171 raeburn 8480: if (ref($currtargets{$balancer}) eq 'HASH') {
1.150 raeburn 8481: foreach my $sparetype (@sparestypes) {
1.171 raeburn 8482: if (ref($currtargets{$balancer}{$sparetype}) eq 'ARRAY') {
8483: my @targetdiffs = &Apache::loncommon::compare_arrays($currtargets{$balancer}{$sparetype},$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype});
1.150 raeburn 8484: if (@targetdiffs > 0) {
1.171 raeburn 8485: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 8486: }
1.171 raeburn 8487: } elsif (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
8488: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
8489: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 8490: }
8491: }
8492: }
8493: } else {
1.171 raeburn 8494: if (ref($defaultshash{'loadbalancing'}{$balancer}) eq 'HASH') {
8495: foreach my $sparetype (@sparestypes) {
8496: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
8497: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
8498: $changes{'curr'}{$balancer}{'targets'} = 1;
8499: }
1.150 raeburn 8500: }
8501: }
8502: }
8503: }
8504: my $ishomedom;
1.171 raeburn 8505: if (&Apache::lonnet::host_domain($balancer) eq $dom) {
8506: $ishomedom = 1;
1.150 raeburn 8507: }
8508: if (ref($alltypes) eq 'ARRAY') {
8509: foreach my $type (@{$alltypes}) {
8510: my $rule;
1.171 raeburn 8511: unless ((($type eq '_LC_external') || ($type eq '_LC_internetdom')) &&
1.150 raeburn 8512: (!$ishomedom)) {
1.171 raeburn 8513: $rule = $env{'form.loadbalancing_rules_'.$i.'_'.$type};
8514: }
8515: if ($rule eq 'specific') {
8516: $rule = $env{'form.loadbalancing_singleserver_'.$i.'_'.$type};
1.150 raeburn 8517: }
1.171 raeburn 8518: $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type} = $rule;
8519: if (ref($currrules{$balancer}) eq 'HASH') {
8520: if ($rule ne $currrules{$balancer}{$type}) {
8521: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 8522: }
8523: } elsif ($rule ne '') {
1.171 raeburn 8524: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 8525: }
8526: }
8527: }
1.171 raeburn 8528: }
8529: my $nochgmsg = &mt('No changes made to Load Balancer settings.');
8530: if ((keys(%changes) > 0) || ($saveloadbalancing)) {
8531: unless (ref($defaultshash{'loadbalancing'}) eq 'HASH') {
8532: $defaultshash{'loadbalancing'} = {};
8533: }
8534: my $putresult = &Apache::lonnet::put_dom('configuration',
8535: \%defaultshash,$dom);
8536:
8537: if ($putresult eq 'ok') {
8538: if (keys(%changes) > 0) {
8539: if (ref($changes{'delete'}) eq 'ARRAY') {
8540: foreach my $balancer (sort(@{$changes{'delete'}})) {
8541: $resulttext .= '<li>'.&mt('Load Balancing discontinued for: [_1]',$balancer).'</li>';
1.150 raeburn 8542: &Apache::lonnet::remote_devalidate_cache($balancer,'loadbalancing',$dom);
8543: }
1.171 raeburn 8544: }
8545: if (ref($changes{'add'}) eq 'ARRAY') {
8546: foreach my $balancer (sort(@{$changes{'add'}})) {
8547: $resulttext .= '<li>'.&mt('Load Balancing enabled for: [_1]',$balancer);
8548: }
8549: }
8550: if (ref($changes{'curr'}) eq 'HASH') {
8551: foreach my $balancer (sort(keys(%{$changes{'curr'}}))) {
8552: if (ref($changes{'curr'}{$balancer}) eq 'HASH') {
8553: if ($changes{'curr'}{$balancer}{'targets'}) {
8554: my %offloadstr;
8555: foreach my $sparetype (@sparestypes) {
8556: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
8557: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
8558: $offloadstr{$sparetype} = join(', ',@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
8559: }
8560: }
1.150 raeburn 8561: }
1.171 raeburn 8562: if (keys(%offloadstr) == 0) {
8563: $resulttext .= '<li>'.&mt("Servers to which Load Balance server offloads set to 'None', by default").'</li>';
1.150 raeburn 8564: } else {
1.171 raeburn 8565: my $showoffload;
8566: foreach my $sparetype (@sparestypes) {
8567: $showoffload .= '<i>'.$typetitles{$sparetype}.'</i>: ';
8568: if (defined($offloadstr{$sparetype})) {
8569: $showoffload .= $offloadstr{$sparetype};
8570: } else {
8571: $showoffload .= &mt('None');
8572: }
8573: $showoffload .= (' 'x3);
8574: }
8575: $resulttext .= '<li>'.&mt('By default, Load Balancer: [_1] set to offload to - [_2]',$balancer,$showoffload).'</li>';
1.150 raeburn 8576: }
8577: }
8578: }
1.171 raeburn 8579: if (ref($changes{'curr'}{$balancer}{'rules'}) eq 'HASH') {
8580: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
8581: foreach my $type (@{$alltypes}) {
8582: if ($changes{'curr'}{$balancer}{'rules'}{$type}) {
8583: my $rule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
8584: my $balancetext;
8585: if ($rule eq '') {
8586: $balancetext = $ruletitles{'default'};
8587: } elsif (($rule eq 'homeserver') || ($rule eq 'externalbalancer')) {
8588: $balancetext = $ruletitles{$rule};
8589: } else {
8590: $balancetext = &mt('offload to [_1]',$defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type});
8591: }
8592: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- balancing for [_2] set to - "[_3]"',$balancer,$titles->{$type},$balancetext).'</li>';
1.150 raeburn 8593: }
8594: }
8595: }
8596: }
1.171 raeburn 8597: &Apache::lonnet::remote_devalidate_cache($balancer,'loadbalancing',$dom);
1.150 raeburn 8598: }
1.171 raeburn 8599: }
8600: if ($resulttext ne '') {
8601: $resulttext = &mt('Changes made:').'<ul>'.$resulttext.'</ul>';
1.150 raeburn 8602: } else {
8603: $resulttext = $nochgmsg;
8604: }
8605: } else {
1.171 raeburn 8606: $resulttext = $nochgmsg;
1.150 raeburn 8607: }
8608: } else {
1.171 raeburn 8609: $resulttext = '<span class="LC_error">'.
8610: &mt('An error occurred: [_1]',$putresult).'</span>';
1.150 raeburn 8611: }
8612: } else {
1.171 raeburn 8613: $resulttext = $nochgmsg;
1.150 raeburn 8614: }
8615: return $resulttext;
8616: }
8617:
1.48 raeburn 8618: sub recurse_check {
8619: my ($chkcats,$categories,$depth,$name) = @_;
8620: if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
8621: my $chg = 0;
8622: for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
8623: my $category = $chkcats->[$depth]{$name}[$j];
8624: my $item;
8625: if ($category eq '') {
8626: $chg ++;
8627: } else {
8628: my $deeper = $depth + 1;
8629: $item = &escape($category).':'.&escape($name).':'.$depth;
8630: if ($chg) {
8631: $categories->{$item} -= $chg;
8632: }
8633: &recurse_check($chkcats,$categories,$deeper,$category);
8634: $deeper --;
8635: }
8636: }
8637: }
8638: return;
8639: }
8640:
8641: sub recurse_cat_deletes {
8642: my ($item,$coursecategories,$deletions) = @_;
8643: my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
8644: my $subdepth = $depth + 1;
8645: if (ref($coursecategories) eq 'HASH') {
8646: foreach my $subitem (keys(%{$coursecategories})) {
8647: my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
8648: if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
8649: delete($coursecategories->{$subitem});
8650: $deletions->{$subitem} = 1;
8651: &recurse_cat_deletes($subitem,$coursecategories,$deletions);
1.168 raeburn 8652: }
1.48 raeburn 8653: }
8654: }
8655: return;
8656: }
8657:
1.125 raeburn 8658: sub get_active_dcs {
8659: my ($dom) = @_;
1.191 raeburn 8660: my $now = time;
8661: my %dompersonnel = &Apache::lonnet::get_domain_roles($dom,['dc'],$now,$now);
1.125 raeburn 8662: my %domcoords;
8663: my $numdcs = 0;
8664: foreach my $server (keys(%dompersonnel)) {
8665: foreach my $user (sort(keys(%{$dompersonnel{$server}}))) {
8666: my ($trole,$uname,$udom,$runame,$rudom,$rsec) = split(/:/,$user);
1.191 raeburn 8667: $domcoords{$uname.':'.$udom} = $dompersonnel{$server}{$user};
1.125 raeburn 8668: }
8669: }
8670: return %domcoords;
8671: }
8672:
8673: sub active_dc_picker {
1.191 raeburn 8674: my ($dom,$numinrow,$inputtype,$name,%currhash) = @_;
1.125 raeburn 8675: my %domcoords = &get_active_dcs($dom);
1.191 raeburn 8676: my @domcoord = keys(%domcoords);
8677: if (keys(%currhash)) {
8678: foreach my $dc (keys(%currhash)) {
8679: unless (exists($domcoords{$dc})) {
8680: push(@domcoord,$dc);
8681: }
8682: }
8683: }
8684: @domcoord = sort(@domcoord);
8685: my $numdcs = scalar(@domcoord);
8686: my $rows = 0;
8687: my $table;
1.125 raeburn 8688: if ($numdcs > 1) {
1.191 raeburn 8689: $table = '<table>';
8690: for (my $i=0; $i<@domcoord; $i++) {
1.125 raeburn 8691: my $rem = $i%($numinrow);
8692: if ($rem == 0) {
8693: if ($i > 0) {
1.191 raeburn 8694: $table .= '</tr>';
1.125 raeburn 8695: }
1.191 raeburn 8696: $table .= '<tr>';
8697: $rows ++;
1.125 raeburn 8698: }
1.191 raeburn 8699: my $check = '';
8700: if ($inputtype eq 'radio') {
8701: if (keys(%currhash) == 0) {
8702: if (!$i) {
8703: $check = ' checked="checked"';
8704: }
8705: } elsif (exists($currhash{$domcoord[$i]})) {
8706: $check = ' checked="checked"';
8707: }
8708: } else {
8709: if (exists($currhash{$domcoord[$i]})) {
8710: $check = ' checked="checked"';
1.125 raeburn 8711: }
8712: }
1.191 raeburn 8713: if ($i == @domcoord - 1) {
1.125 raeburn 8714: my $colsleft = $numinrow - $rem;
8715: if ($colsleft > 1) {
1.191 raeburn 8716: $table .= '<td class="LC_left_item" colspan="'.$colsleft.'">';
1.125 raeburn 8717: } else {
1.191 raeburn 8718: $table .= '<td class="LC_left_item">';
1.125 raeburn 8719: }
8720: } else {
1.191 raeburn 8721: $table .= '<td class="LC_left_item">';
8722: }
8723: my ($dcname,$dcdom) = split(':',$domcoord[$i]);
8724: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
8725: $table .= '<span class="LC_nobreak"><label>'.
8726: '<input type="'.$inputtype.'" name="'.$name.'"'.
8727: ' value="'.$domcoord[$i].'"'.$check.' />'.$user;
8728: if ($user ne $dcname.':'.$dcdom) {
8729: $table .= ' ('.$dcname.':'.$dcdom.')'.
8730: '</label></span></td>';
8731: }
8732: }
8733: $table .= '</tr></table>';
8734: } elsif ($numdcs == 1) {
8735: if ($inputtype eq 'radio') {
8736: $table .= '<input type="hidden" name="'.$name.'" value="'.$domcoord[0].'" />';
8737: } else {
8738: my $check;
8739: if (exists($currhash{$domcoord[0]})) {
8740: $check = ' checked="checked"';
1.125 raeburn 8741: }
1.191 raeburn 8742: $table .= '<input type="checkbox" name="'.$name.'" '.
8743: 'value="'.$domcoord[0].'"'.$check.' />';
8744: $rows ++;
1.125 raeburn 8745: }
8746: }
1.191 raeburn 8747: return ($numdcs,$table,$rows);
1.125 raeburn 8748: }
8749:
1.137 raeburn 8750: sub usersession_titles {
8751: return &Apache::lonlocal::texthash(
8752: hosted => 'Hosting of sessions for users from other domains on servers in this domain',
8753: remote => 'Hosting of sessions for users in this domain on servers in other domains',
1.145 raeburn 8754: spares => 'Servers offloaded to, when busy',
1.137 raeburn 8755: version => 'LON-CAPA version requirement',
1.138 raeburn 8756: excludedomain => 'Allow all, but exclude specific domains',
8757: includedomain => 'Deny all, but include specific domains',
1.145 raeburn 8758: primary => 'Primary (checked first)',
1.154 raeburn 8759: default => 'Default',
1.137 raeburn 8760: );
8761: }
8762:
1.152 raeburn 8763: sub id_for_thisdom {
8764: my (%servers) = @_;
8765: my %altids;
8766: foreach my $server (keys(%servers)) {
8767: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
8768: if ($serverhome ne $server) {
8769: $altids{$serverhome} = $server;
8770: }
8771: }
8772: return %altids;
8773: }
8774:
1.150 raeburn 8775: sub count_servers {
8776: my ($currbalancer,%servers) = @_;
8777: my (@spares,$numspares);
8778: foreach my $lonhost (sort(keys(%servers))) {
8779: next if ($currbalancer eq $lonhost);
8780: push(@spares,$lonhost);
8781: }
8782: if ($currbalancer) {
8783: $numspares = scalar(@spares);
8784: } else {
8785: $numspares = scalar(@spares) - 1;
8786: }
8787: return ($numspares,@spares);
8788: }
8789:
8790: sub lonbalance_targets_js {
1.171 raeburn 8791: my ($dom,$types,$servers,$settings) = @_;
1.150 raeburn 8792: my $select = &mt('Select');
8793: my ($alltargets,$allishome,$allinsttypes,@alltypes);
8794: if (ref($servers) eq 'HASH') {
8795: $alltargets = join("','",sort(keys(%{$servers})));
8796: my @homedoms;
8797: foreach my $server (sort(keys(%{$servers}))) {
8798: if (&Apache::lonnet::host_domain($server) eq $dom) {
8799: push(@homedoms,'1');
8800: } else {
8801: push(@homedoms,'0');
8802: }
8803: }
8804: $allishome = join("','",@homedoms);
8805: }
8806: if (ref($types) eq 'ARRAY') {
8807: if (@{$types} > 0) {
8808: @alltypes = @{$types};
8809: }
8810: }
8811: push(@alltypes,'default','_LC_adv','_LC_author','_LC_internetdom','_LC_external');
8812: $allinsttypes = join("','",@alltypes);
1.171 raeburn 8813: my (%currbalancer,%currtargets,%currrules,%existing);
8814: if (ref($settings) eq 'HASH') {
8815: %existing = %{$settings};
8816: }
8817: &get_loadbalancers_config($servers,\%existing,\%currbalancer,
8818: \%currtargets,\%currrules);
8819: my $balancers = join("','",sort(keys(%currbalancer)));
1.150 raeburn 8820: return <<"END";
8821:
8822: <script type="text/javascript">
8823: // <![CDATA[
8824:
1.171 raeburn 8825: currBalancers = new Array('$balancers');
8826:
8827: function toggleTargets(balnum) {
8828: var lonhostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
8829: var prevhostitem = document.getElementById('loadbalancing_prevlonhost_'+balnum);
8830: var balancer = lonhostitem.options[lonhostitem.selectedIndex].value;
8831: var prevbalancer = prevhostitem.value;
8832: var baltotal = document.getElementById('loadbalancing_total').value;
8833: prevhostitem.value = balancer;
8834: if (prevbalancer != '') {
8835: var prevIdx = currBalancers.indexOf(prevbalancer);
8836: if (prevIdx != -1) {
8837: currBalancers.splice(prevIdx,1);
8838: }
8839: }
1.150 raeburn 8840: if (balancer == '') {
1.171 raeburn 8841: hideSpares(balnum);
1.150 raeburn 8842: } else {
1.171 raeburn 8843: var currIdx = currBalancers.indexOf(balancer);
8844: if (currIdx == -1) {
8845: currBalancers.push(balancer);
8846: }
1.150 raeburn 8847: var homedoms = new Array('$allishome');
1.171 raeburn 8848: var ishomedom = homedoms[lonhostitem.selectedIndex];
8849: showSpares(balancer,ishomedom,balnum);
1.150 raeburn 8850: }
1.171 raeburn 8851: balancerChange(balnum,baltotal,'change',prevbalancer,balancer);
1.150 raeburn 8852: return;
8853: }
8854:
1.171 raeburn 8855: function showSpares(balancer,ishomedom,balnum) {
1.150 raeburn 8856: var alltargets = new Array('$alltargets');
8857: var insttypes = new Array('$allinsttypes');
1.151 raeburn 8858: var offloadtypes = new Array('primary','default');
8859:
1.171 raeburn 8860: document.getElementById('loadbalancing_targets_'+balnum).style.display='block';
8861: document.getElementById('loadbalancing_disabled_'+balnum).style.display='none';
1.152 raeburn 8862:
1.151 raeburn 8863: for (var i=0; i<offloadtypes.length; i++) {
8864: var count = 0;
8865: for (var j=0; j<alltargets.length; j++) {
8866: if (alltargets[j] != balancer) {
1.171 raeburn 8867: var item = document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+count);
8868: item.value = alltargets[j];
8869: item.style.textAlign='left';
8870: item.style.textFace='normal';
8871: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+count).innerHTML = alltargets[j];
8872: if (currBalancers.indexOf(alltargets[j]) == -1) {
8873: item.disabled = '';
8874: } else {
8875: item.disabled = 'disabled';
8876: item.checked = false;
8877: }
1.151 raeburn 8878: count ++;
8879: }
1.150 raeburn 8880: }
8881: }
1.151 raeburn 8882: for (var k=0; k<insttypes.length; k++) {
8883: if ((insttypes[k] == '_LC_external') || (insttypes[k] == '_LC_internetdom')) {
1.150 raeburn 8884: if (ishomedom == 1) {
1.171 raeburn 8885: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
8886: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 8887: } else {
1.171 raeburn 8888: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
8889: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.150 raeburn 8890:
8891: }
8892: } else {
1.171 raeburn 8893: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
8894: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 8895: }
1.151 raeburn 8896: if ((insttypes[k] != '_LC_external') &&
8897: ((insttypes[k] != '_LC_internetdom') ||
8898: ((insttypes[k] == '_LC_internetdom') && (ishomedom == 1)))) {
1.171 raeburn 8899: var item = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]);
8900: item.options.length = 0;
8901: item.options[0] = new Option("","",true,true);
8902: var idx = 0;
1.151 raeburn 8903: for (var m=0; m<alltargets.length; m++) {
1.171 raeburn 8904: if ((currBalancers.indexOf(alltargets[m]) == -1) && (alltargets[m] != balancer)) {
8905: idx ++;
8906: item.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
8907:
1.150 raeburn 8908: }
8909: }
8910: }
8911: }
8912: return;
8913: }
8914:
1.171 raeburn 8915: function hideSpares(balnum) {
1.150 raeburn 8916: var alltargets = new Array('$alltargets');
8917: var insttypes = new Array('$allinsttypes');
8918: var offloadtypes = new Array('primary','default');
8919:
1.171 raeburn 8920: document.getElementById('loadbalancing_targets_'+balnum).style.display='none';
8921: document.getElementById('loadbalancing_disabled_'+balnum).style.display='block';
1.150 raeburn 8922:
8923: var total = alltargets.length - 1;
8924: for (var i=0; i<offloadtypes; i++) {
8925: for (var j=0; j<total; j++) {
1.171 raeburn 8926: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).checked = false;
8927: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).value = '';
8928: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+j).innerHTML = '';
1.151 raeburn 8929: }
1.150 raeburn 8930: }
8931: for (var k=0; k<insttypes.length; k++) {
1.171 raeburn 8932: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
8933: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.151 raeburn 8934: if (insttypes[k] != '_LC_external') {
1.171 raeburn 8935: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).length = 0;
8936: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).options[0] = new Option("","",true,true);
1.150 raeburn 8937: }
8938: }
8939: return;
8940: }
8941:
1.171 raeburn 8942: function checkOffloads(item,balnum,type) {
1.150 raeburn 8943: var alltargets = new Array('$alltargets');
8944: var offloadtypes = new Array('primary','default');
8945: if (item.checked) {
8946: var total = alltargets.length - 1;
8947: var other;
8948: if (type == offloadtypes[0]) {
1.151 raeburn 8949: other = offloadtypes[1];
1.150 raeburn 8950: } else {
1.151 raeburn 8951: other = offloadtypes[0];
1.150 raeburn 8952: }
8953: for (var i=0; i<total; i++) {
1.171 raeburn 8954: var server = document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).value;
1.150 raeburn 8955: if (server == item.value) {
1.171 raeburn 8956: if (document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked) {
8957: document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked = false;
1.150 raeburn 8958: }
8959: }
8960: }
8961: }
8962: return;
8963: }
8964:
1.171 raeburn 8965: function singleServerToggle(balnum,type) {
8966: var offloadtoSelIdx = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex;
1.150 raeburn 8967: if (offloadtoSelIdx == 0) {
1.171 raeburn 8968: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_0').checked = true;
8969: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 8970:
8971: } else {
1.171 raeburn 8972: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_2').checked = true;
8973: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
1.150 raeburn 8974: }
8975: return;
8976: }
8977:
1.171 raeburn 8978: function balanceruleChange(formname,balnum,type) {
1.150 raeburn 8979: if (type == '_LC_external') {
1.171 raeburn 8980: return;
1.150 raeburn 8981: }
1.171 raeburn 8982: var typesRules = getIndicesByName(formname,'loadbalancing_rules_'+balnum+'_'+type);
1.150 raeburn 8983: for (var i=0; i<typesRules.length; i++) {
8984: if (formname.elements[typesRules[i]].checked) {
8985: if (formname.elements[typesRules[i]].value != 'specific') {
1.171 raeburn 8986: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex = 0;
8987: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 8988: } else {
1.171 raeburn 8989: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
8990: }
8991: }
8992: }
8993: return;
8994: }
8995:
8996: function balancerDeleteChange(balnum) {
8997: var hostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
8998: var baltotal = document.getElementById('loadbalancing_total').value;
8999: var addtarget;
9000: var removetarget;
9001: var action = 'delete';
9002: if (document.getElementById('loadbalancing_delete_'+balnum)) {
9003: var lonhost = hostitem.value;
9004: var currIdx = currBalancers.indexOf(lonhost);
9005: if (document.getElementById('loadbalancing_delete_'+balnum).checked) {
9006: if (currIdx != -1) {
9007: currBalancers.splice(currIdx,1);
9008: }
9009: addtarget = lonhost;
9010: } else {
9011: if (currIdx == -1) {
9012: currBalancers.push(lonhost);
9013: }
9014: removetarget = lonhost;
9015: action = 'undelete';
9016: }
9017: balancerChange(balnum,baltotal,action,addtarget,removetarget);
9018: }
9019: return;
9020: }
9021:
9022: function balancerChange(balnum,baltotal,action,addtarget,removetarget) {
9023: if (baltotal > 1) {
9024: var offloadtypes = new Array('primary','default');
9025: var alltargets = new Array('$alltargets');
9026: var insttypes = new Array('$allinsttypes');
9027: for (var i=0; i<baltotal; i++) {
9028: if (i != balnum) {
9029: for (var j=0; j<offloadtypes.length; j++) {
9030: var total = alltargets.length - 1;
9031: for (var k=0; k<total; k++) {
9032: var serveritem = document.getElementById('loadbalancing_target_'+i+'_'+offloadtypes[j]+'_'+k);
9033: var server = serveritem.value;
9034: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
9035: if (server == addtarget) {
9036: serveritem.disabled = '';
9037: }
9038: }
9039: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
9040: if (server == removetarget) {
9041: serveritem.disabled = 'disabled';
9042: serveritem.checked = false;
9043: }
9044: }
9045: }
9046: }
9047: for (var j=0; j<insttypes.length; j++) {
9048: if (insttypes[j] != '_LC_external') {
9049: if (document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j])) {
9050: var singleserver = document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j]);
9051: var currSel = singleserver.selectedIndex;
9052: var currVal = singleserver.options[currSel].value;
9053: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
9054: var numoptions = singleserver.options.length;
9055: var needsnew = 1;
9056: for (var k=0; k<numoptions; k++) {
9057: if (singleserver.options[k] == addtarget) {
9058: needsnew = 0;
9059: break;
9060: }
9061: }
9062: if (needsnew == 1) {
9063: singleserver.options[numoptions] = new Option(addtarget,addtarget,false,false);
9064: }
9065: }
9066: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
9067: singleserver.options.length = 0;
9068: if ((currVal) && (currVal != removetarget)) {
9069: singleserver.options[0] = new Option("","",false,false);
9070: } else {
9071: singleserver.options[0] = new Option("","",true,true);
9072: }
9073: var idx = 0;
9074: for (var m=0; m<alltargets.length; m++) {
9075: if (currBalancers.indexOf(alltargets[m]) == -1) {
9076: idx ++;
9077: if (currVal == alltargets[m]) {
9078: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],true,true);
9079: } else {
9080: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
9081: }
9082: }
9083: }
9084: }
9085: }
9086: }
9087: }
1.150 raeburn 9088: }
9089: }
9090: }
9091: return;
9092: }
9093:
1.152 raeburn 9094: // ]]>
9095: </script>
9096:
9097: END
9098: }
9099:
9100: sub new_spares_js {
9101: my @sparestypes = ('primary','default');
9102: my $types = join("','",@sparestypes);
9103: my $select = &mt('Select');
9104: return <<"END";
9105:
9106: <script type="text/javascript">
9107: // <![CDATA[
9108:
9109: function updateNewSpares(formname,lonhost) {
9110: var types = new Array('$types');
9111: var include = new Array();
9112: var exclude = new Array();
9113: for (var i=0; i<types.length; i++) {
9114: var spareboxes = getIndicesByName(formname,'spare_'+types[i]+'_'+lonhost);
9115: for (var j=0; j<spareboxes.length; j++) {
9116: if (formname.elements[spareboxes[j]].checked) {
9117: exclude.push(formname.elements[spareboxes[j]].value);
9118: } else {
9119: include.push(formname.elements[spareboxes[j]].value);
9120: }
9121: }
9122: }
9123: for (var i=0; i<types.length; i++) {
9124: var newSpare = document.getElementById('newspare_'+types[i]+'_'+lonhost);
9125: var selIdx = newSpare.selectedIndex;
9126: var currnew = newSpare.options[selIdx].value;
9127: var okSpares = new Array();
9128: for (var j=0; j<newSpare.options.length; j++) {
9129: var possible = newSpare.options[j].value;
9130: if (possible != '') {
9131: if (exclude.indexOf(possible) == -1) {
9132: okSpares.push(possible);
9133: } else {
9134: if (currnew == possible) {
9135: selIdx = 0;
9136: }
9137: }
9138: }
9139: }
9140: for (var k=0; k<include.length; k++) {
9141: if (okSpares.indexOf(include[k]) == -1) {
9142: okSpares.push(include[k]);
9143: }
9144: }
9145: okSpares.sort();
9146: newSpare.options.length = 0;
9147: if (selIdx == 0) {
9148: newSpare.options[0] = new Option("$select","",true,true);
9149: } else {
9150: newSpare.options[0] = new Option("$select","",false,false);
9151: }
9152: for (var m=0; m<okSpares.length; m++) {
9153: var idx = m+1;
9154: var selThis = 0;
9155: if (selIdx != 0) {
9156: if (okSpares[m] == currnew) {
9157: selThis = 1;
9158: }
9159: }
9160: if (selThis == 1) {
9161: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],true,true);
9162: } else {
9163: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],false,false);
9164: }
9165: }
9166: }
9167: return;
9168: }
9169:
9170: function checkNewSpares(lonhost,type) {
9171: var newSpare = document.getElementById('newspare_'+type+'_'+lonhost);
9172: var chosen = newSpare.options[newSpare.selectedIndex].value;
9173: if (chosen != '') {
9174: var othertype;
9175: var othernewSpare;
9176: if (type == 'primary') {
9177: othernewSpare = document.getElementById('newspare_default_'+lonhost);
9178: }
9179: if (type == 'default') {
9180: othernewSpare = document.getElementById('newspare_primary_'+lonhost);
9181: }
9182: if (othernewSpare.options[othernewSpare.selectedIndex].value == chosen) {
9183: othernewSpare.selectedIndex = 0;
9184: }
9185: }
9186: return;
9187: }
9188:
9189: // ]]>
9190: </script>
9191:
9192: END
9193:
9194: }
9195:
9196: sub common_domprefs_js {
9197: return <<"END";
9198:
9199: <script type="text/javascript">
9200: // <![CDATA[
9201:
1.150 raeburn 9202: function getIndicesByName(formname,item) {
1.152 raeburn 9203: var group = new Array();
1.150 raeburn 9204: for (var i=0;i<formname.elements.length;i++) {
9205: if (formname.elements[i].name == item) {
1.152 raeburn 9206: group.push(formname.elements[i].id);
1.150 raeburn 9207: }
9208: }
1.152 raeburn 9209: return group;
1.150 raeburn 9210: }
9211:
9212: // ]]>
9213: </script>
9214:
9215: END
1.152 raeburn 9216:
1.150 raeburn 9217: }
9218:
1.165 raeburn 9219: sub recaptcha_js {
9220: my %lt = &captcha_phrases();
9221: return <<"END";
9222:
9223: <script type="text/javascript">
9224: // <![CDATA[
9225:
9226: function updateCaptcha(caller,context) {
9227: var privitem;
9228: var pubitem;
9229: var privtext;
9230: var pubtext;
9231: if (document.getElementById(context+'_recaptchapub')) {
9232: pubitem = document.getElementById(context+'_recaptchapub');
9233: } else {
9234: return;
9235: }
9236: if (document.getElementById(context+'_recaptchapriv')) {
9237: privitem = document.getElementById(context+'_recaptchapriv');
9238: } else {
9239: return;
9240: }
9241: if (document.getElementById(context+'_recaptchapubtxt')) {
9242: pubtext = document.getElementById(context+'_recaptchapubtxt');
9243: } else {
9244: return;
9245: }
9246: if (document.getElementById(context+'_recaptchaprivtxt')) {
9247: privtext = document.getElementById(context+'_recaptchaprivtxt');
9248: } else {
9249: return;
9250: }
9251: if (caller.checked) {
9252: if (caller.value == 'recaptcha') {
9253: pubitem.type = 'text';
9254: privitem.type = 'text';
9255: pubitem.size = '40';
9256: privitem.size = '40';
9257: pubtext.innerHTML = "$lt{'pub'}";
9258: privtext.innerHTML = "$lt{'priv'}";
9259: } else {
9260: pubitem.type = 'hidden';
9261: privitem.type = 'hidden';
9262: pubtext.innerHTML = '';
9263: privtext.innerHTML = '';
9264: }
9265: }
9266: return;
9267: }
9268:
9269: // ]]>
9270: </script>
9271:
9272: END
9273:
9274: }
9275:
1.192 raeburn 9276: sub credits_js {
9277: return <<"END";
9278:
9279: <script type="text/javascript">
9280: // <![CDATA[
9281:
9282: function toggleCredits(domForm) {
9283: if (document.getElementById('credits')) {
9284: creditsitem = document.getElementById('credits');
9285: var creditsLength = domForm.coursecredits.length;
9286: if (creditsLength) {
9287: var currval;
9288: for (var i=0; i<creditsLength; i++) {
9289: if (domForm.coursecredits[i].checked) {
9290: currval = domForm.coursecredits[i].value;
9291: }
9292: }
9293: if (currval == 1) {
9294: creditsitem.style.display = 'block';
9295: } else {
9296: creditsitem.style.display = 'none';
9297: }
9298: }
9299: }
9300: return;
9301: }
9302:
9303: // ]]>
9304: </script>
9305:
9306: END
9307:
9308: }
9309:
1.165 raeburn 9310: sub captcha_phrases {
9311: return &Apache::lonlocal::texthash (
9312: priv => 'Private key',
9313: pub => 'Public key',
9314: original => 'original (CAPTCHA)',
9315: recaptcha => 'successor (ReCAPTCHA)',
9316: notused => 'unused',
9317: );
9318: }
9319:
1.3 raeburn 9320: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>