Annotation of loncom/interface/domainprefs.pm, revision 1.197
1.1 raeburn 1: # The LearningOnline Network with CAPA
2: # Handler to set domain-wide configuration settings
3: #
1.197 ! raeburn 4: # $Id: domainprefs.pm,v 1.196 2013/06/04 23:12:08 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);
1145: my %defaults = (
1146: img => $defaultdesign{$role.'.img'},
1147: font => $defaultdesign{$role.'.font'},
1.97 tempelho 1148: fontmenu => $defaultdesign{$role.'.fontmenu'},
1.6 raeburn 1149: );
1150: foreach my $item (@bgs) {
1151: $defaults{'bgs'}{$item} = $defaultdesign{$role.'.'.$item};
1152: }
1153: foreach my $item (@links) {
1154: $defaults{'links'}{$item} = $defaultdesign{$role.'.'.$item};
1155: }
1156: if (ref($settings) eq 'HASH') {
1157: if (ref($settings->{$role}) eq 'HASH') {
1158: if ($settings->{$role}->{'img'} ne '') {
1159: $designs{'img'} = $settings->{$role}->{'img'};
1160: $is_custom{'img'} = 1;
1161: }
1162: if ($settings->{$role}->{'font'} ne '') {
1163: $designs{'font'} = $settings->{$role}->{'font'};
1164: $is_custom{'font'} = 1;
1165: }
1.97 tempelho 1166: if ($settings->{$role}->{'fontmenu'} ne '') {
1167: $designs{'fontmenu'} = $settings->{$role}->{'fontmenu'};
1168: $is_custom{'fontmenu'} = 1;
1169: }
1.6 raeburn 1170: foreach my $item (@bgs) {
1171: if ($settings->{$role}->{$item} ne '') {
1172: $designs{'bgs'}{$item} = $settings->{$role}->{$item};
1173: $is_custom{$item} = 1;
1174: }
1175: }
1176: foreach my $item (@links) {
1177: if ($settings->{$role}->{$item} ne '') {
1178: $designs{'links'}{$item} = $settings->{$role}->{$item};
1179: $is_custom{$item} = 1;
1180: }
1181: }
1182: }
1183: } else {
1184: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
1185: $designs{img} = $designhash{$dom.'.'.$role.'.img'};
1186: $is_custom{'img'} = 1;
1187: }
1.97 tempelho 1188: if ($designhash{$dom.'.'.$role.'.fontmenu'} ne '') {
1189: $designs{fontmenu} = $designhash{$dom.'.'.$role.'.fontmenu'};
1190: $is_custom{'fontmenu'} = 1;
1191: }
1.6 raeburn 1192: if ($designhash{$dom.'.'.$role.'.font'} ne '') {
1193: $designs{font} = $designhash{$dom.'.'.$role.'.font'};
1194: $is_custom{'font'} = 1;
1195: }
1196: foreach my $item (@bgs) {
1197: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1198: $designs{'bgs'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1199: $is_custom{$item} = 1;
1200:
1201: }
1202: }
1203: foreach my $item (@links) {
1204: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1205: $designs{'links'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1206: $is_custom{$item} = 1;
1207: }
1208: }
1209: }
1210: my $itemcount = 1;
1.30 raeburn 1211: my $datatable = &display_color_options($dom,$confname,$phase,$role,$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal);
1.6 raeburn 1212: $datatable .= '</tr></table></td></tr>';
1213: return $datatable;
1214: }
1215:
1216: sub display_color_options {
1.9 raeburn 1217: my ($dom,$confname,$phase,$role,$itemcount,$choices,$is_custom,$defaults,$designs,
1.135 bisitz 1218: $images,$bgs,$links,$alt_text,$rowtotal,$logintext) = @_;
1.159 raeburn 1219: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.6 raeburn 1220: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.176 raeburn 1221: my $datatable = '<tr'.$css_class.'>'.
1.6 raeburn 1222: '<td>'.$choices->{'font'}.'</td>';
1223: if (!$is_custom->{'font'}) {
1.30 raeburn 1224: $datatable .= '<td>'.&mt('Default in use:').' <span id="css_default_'.$role.'_font" style="color: '.$defaults->{'font'}.';">'.$defaults->{'font'}.'</span></td>';
1.6 raeburn 1225: } else {
1226: $datatable .= '<td> </td>';
1227: }
1.174 foxr 1228: my $current_color = $designs->{'font'} ? $designs->{'font'} : $defaults->{'font'};
1229:
1.8 raeburn 1230: $datatable .= '<td><span class="LC_nobreak">'.
1.174 foxr 1231: '<input type="text" class="colorchooser" size="10" name="'.$role.'_font"'.
1232: ' value="'.$current_color.'" /> '.
1233: ' </td></tr>';
1.107 raeburn 1234: unless ($role eq 'login') {
1235: $datatable .= '<tr'.$css_class.'>'.
1236: '<td>'.$choices->{'fontmenu'}.'</td>';
1237: if (!$is_custom->{'fontmenu'}) {
1238: $datatable .= '<td>'.&mt('Default in use:').' <span id="css_default_'.$role.'_font" style="color: '.$defaults->{'fontmenu'}.';">'.$defaults->{'fontmenu'}.'</span></td>';
1239: } else {
1240: $datatable .= '<td> </td>';
1241: }
1.174 foxr 1242: $current_color = $designs->{'fontmenu'} ?
1243: $designs->{'fontmenu'} : $defaults->{'fontmenu'};
1.107 raeburn 1244: $datatable .= '<td><span class="LC_nobreak">'.
1.174 foxr 1245: '<input class="colorchooser" type="text" size="10" name="'
1246: .$role.'_fontmenu"'.
1247: ' value="'.$current_color.'" /> '.
1248: ' </td></tr>';
1.97 tempelho 1249: }
1.9 raeburn 1250: my $switchserver = &check_switchserver($dom,$confname);
1.6 raeburn 1251: foreach my $img (@{$images}) {
1.18 albertel 1252: $itemcount ++;
1.6 raeburn 1253: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.8 raeburn 1254: $datatable .= '<tr'.$css_class.'>'.
1.70 raeburn 1255: '<td>'.$choices->{$img};
1.41 raeburn 1256: my ($imgfile,$img_import,$login_hdr_pick,$logincolors);
1.70 raeburn 1257: if ($role eq 'login') {
1258: if ($img eq 'login') {
1259: $login_hdr_pick =
1.135 bisitz 1260: &login_header_options($img,$role,$defaults,$is_custom,$choices);
1.70 raeburn 1261: $logincolors =
1262: &login_text_colors($img,$role,$logintext,$phase,$choices,
1263: $designs);
1264: } elsif ($img ne 'domlogo') {
1265: $datatable.= &logo_display_options($img,$defaults,$designs);
1266: }
1267: }
1268: $datatable .= '</td>';
1.6 raeburn 1269: if ($designs->{$img} ne '') {
1270: $imgfile = $designs->{$img};
1.18 albertel 1271: $img_import = ($imgfile =~ m{^/adm/});
1.6 raeburn 1272: } else {
1273: $imgfile = $defaults->{$img};
1274: }
1275: if ($imgfile) {
1.9 raeburn 1276: my ($showfile,$fullsize);
1277: if ($imgfile =~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
1.6 raeburn 1278: my $urldir = $1;
1279: my $filename = $2;
1280: my @info = &Apache::lonnet::stat_file($designs->{$img});
1281: if (@info) {
1282: my $thumbfile = 'tn-'.$filename;
1283: my @thumb=&Apache::lonnet::stat_file($urldir.'/'.$thumbfile);
1284: if (@thumb) {
1285: $showfile = $urldir.'/'.$thumbfile;
1286: } else {
1287: $showfile = $imgfile;
1288: }
1289: } else {
1290: $showfile = '';
1291: }
1292: } elsif ($imgfile =~ m-^/(adm/[^/]+)/([^/]+)$-) {
1.16 raeburn 1293: $showfile = $imgfile;
1.6 raeburn 1294: my $imgdir = $1;
1295: my $filename = $2;
1.159 raeburn 1296: if (-e "$londocroot/$imgdir/tn-".$filename) {
1.6 raeburn 1297: $showfile = "/$imgdir/tn-".$filename;
1298: } else {
1.159 raeburn 1299: my $input = $londocroot.$imgfile;
1300: my $output = "$londocroot/$imgdir/tn-".$filename;
1.6 raeburn 1301: if (!-e $output) {
1.9 raeburn 1302: my ($width,$height) = &thumb_dimensions();
1.16 raeburn 1303: my ($fullwidth,$fullheight) = &check_dimensions($input);
1304: if ($fullwidth ne '' && $fullheight ne '') {
1305: if ($fullwidth > $width && $fullheight > $height) {
1306: my $size = $width.'x'.$height;
1307: system("convert -sample $size $input $output");
1.159 raeburn 1308: $showfile = "/$imgdir/tn-".$filename;
1.16 raeburn 1309: }
1310: }
1.6 raeburn 1311: }
1312: }
1.16 raeburn 1313: }
1.6 raeburn 1314: if ($showfile) {
1.40 raeburn 1315: if ($showfile =~ m{^/(adm|res)/}) {
1316: if ($showfile =~ m{^/res/}) {
1317: my $local_showfile =
1318: &Apache::lonnet::filelocation('',$showfile);
1319: &Apache::lonnet::repcopy($local_showfile);
1320: }
1321: $showfile = &Apache::loncommon::lonhttpdurl($showfile);
1322: }
1323: if ($imgfile) {
1324: if ($imgfile =~ m{^/(adm|res)/}) {
1325: if ($imgfile =~ m{^/res/}) {
1326: my $local_imgfile =
1327: &Apache::lonnet::filelocation('',$imgfile);
1328: &Apache::lonnet::repcopy($local_imgfile);
1329: }
1330: $fullsize = &Apache::loncommon::lonhttpdurl($imgfile);
1331: } else {
1332: $fullsize = $imgfile;
1333: }
1334: }
1.41 raeburn 1335: $datatable .= '<td>';
1336: if ($img eq 'login') {
1.135 bisitz 1337: $datatable .= $login_hdr_pick;
1338: }
1.41 raeburn 1339: $datatable .= &image_changes($is_custom->{$img},$alt_text->{$img},$img_import,
1340: $showfile,$fullsize,$role,$img,$imgfile,$logincolors);
1.6 raeburn 1341: } else {
1342: $datatable .= '<td colspan="2" class="LC_right_item"><br />'.
1343: &mt('Upload:');
1344: }
1345: } else {
1346: $datatable .= '<td colspan="2" class="LC_right_item"><br />'.
1347: &mt('Upload:');
1348: }
1.9 raeburn 1349: if ($switchserver) {
1350: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1351: } else {
1.135 bisitz 1352: if ($img ne 'login') { # suppress file selection for Log-in header
1353: $datatable .=' <input type="file" name="'.$role.'_'.$img.'" />';
1354: }
1.9 raeburn 1355: }
1356: $datatable .= '</td></tr>';
1.6 raeburn 1357: }
1358: $itemcount ++;
1359: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1360: $datatable .= '<tr'.$css_class.'>'.
1361: '<td>'.$choices->{'bgs'}.'</td>';
1362: my $bgs_def;
1363: foreach my $item (@{$bgs}) {
1364: if (!$is_custom->{$item}) {
1.70 raeburn 1365: $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 1366: }
1367: }
1368: if ($bgs_def) {
1.8 raeburn 1369: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$bgs_def.'</tr></table></td>';
1.6 raeburn 1370: } else {
1371: $datatable .= '<td> </td>';
1372: }
1373: $datatable .= '<td class="LC_right_item">'.
1374: '<table border="0"><tr>';
1.174 foxr 1375:
1.6 raeburn 1376: foreach my $item (@{$bgs}) {
1.174 foxr 1377: $datatable .= '<td align="center">';
1378: my $color = $designs->{'bgs'}{$item} ? $designs->{'bgs'}{$item} : $defaults->{'bgs'}{$item};
1.6 raeburn 1379: if ($designs->{'bgs'}{$item}) {
1.174 foxr 1380: $datatable .= ' ';
1.6 raeburn 1381: }
1.174 foxr 1382: $datatable .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1.41 raeburn 1383: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.6 raeburn 1384: }
1385: $datatable .= '</tr></table></td></tr>';
1386: $itemcount ++;
1387: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1388: $datatable .= '<tr'.$css_class.'>'.
1389: '<td>'.$choices->{'links'}.'</td>';
1390: my $links_def;
1391: foreach my $item (@{$links}) {
1392: if (!$is_custom->{$item}) {
1.30 raeburn 1393: $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 1394: }
1395: }
1396: if ($links_def) {
1.8 raeburn 1397: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$links_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>';
1403: foreach my $item (@{$links}) {
1.174 foxr 1404: my $color = $designs->{'link'}{$item} ? $designs->{'link'}{$item} : $defaults->{'links'}{$item};
1405: $datatable .= '<td align="center">'."\n";
1406:
1.6 raeburn 1407: if ($designs->{'links'}{$item}) {
1.174 foxr 1408: $datatable.=' ';
1.6 raeburn 1409: }
1.174 foxr 1410: $datatable .= '<br /><input type="text" size="8" class="colorchooser" name="'.$role.'_'.$item.'" value="'.$color.
1.6 raeburn 1411: '" /></td>';
1412: }
1.30 raeburn 1413: $$rowtotal += $itemcount;
1.3 raeburn 1414: return $datatable;
1415: }
1416:
1.70 raeburn 1417: sub logo_display_options {
1418: my ($img,$defaults,$designs) = @_;
1419: my $checkedon;
1420: if (ref($defaults) eq 'HASH') {
1421: if (ref($defaults->{'showlogo'}) eq 'HASH') {
1422: if ($defaults->{'showlogo'}{$img}) {
1423: $checkedon = 'checked="checked" ';
1424: }
1425: }
1426: }
1427: if (ref($designs) eq 'HASH') {
1428: if (ref($designs->{'showlogo'}) eq 'HASH') {
1429: if (defined($designs->{'showlogo'}{$img})) {
1430: if ($designs->{'showlogo'}{$img} == 0) {
1431: $checkedon = '';
1432: } elsif ($designs->{'showlogo'}{$img} == 1) {
1433: $checkedon = 'checked="checked" ';
1434: }
1435: }
1436: }
1437: }
1438: return '<br /><label> <input type="checkbox" name="'.
1439: 'login_showlogo_'.$img.'" value="1" '.$checkedon.'/>'.
1440: &mt('show').'</label>'."\n";
1441: }
1442:
1.41 raeburn 1443: sub login_header_options {
1.135 bisitz 1444: my ($img,$role,$defaults,$is_custom,$choices) = @_;
1445: my $output = '';
1.41 raeburn 1446: if ((!$is_custom->{'textcol'}) || (!$is_custom->{'bgcol'})) {
1.135 bisitz 1447: $output .= &mt('Text default(s):').'<br />';
1.41 raeburn 1448: if (!$is_custom->{'textcol'}) {
1449: $output .= $choices->{'textcol'}.': '.$defaults->{'logintext'}{'textcol'}.
1450: ' ';
1451: }
1452: if (!$is_custom->{'bgcol'}) {
1453: $output .= $choices->{'bgcol'}.': '.
1454: '<span id="css_'.$role.'_font" style="background-color: '.
1455: $defaults->{'logintext'}{'bgcol'}.';"> </span>';
1456: }
1457: $output .= '<br />';
1458: }
1459: $output .='<br />';
1460: return $output;
1461: }
1462:
1463: sub login_text_colors {
1464: my ($img,$role,$logintext,$phase,$choices,$designs) = @_;
1465: my $color_menu = '<table border="0"><tr>';
1466: foreach my $item (@{$logintext}) {
1467: my $link = &color_pick($phase,$role,$item,$choices->{$item},$designs->{'logintext'}{$item});
1468: $color_menu .= '<td align="center">'.$link;
1469: if ($designs->{'logintext'}{$item}) {
1470: $color_menu .= ' <span id="css_'.$role.'_'.$item.'" style="background-color: '.$designs->{'logintext'}{$item}.';"> </span>';
1471: }
1472: $color_menu .= '<br /><input type="text" size="8" name="'.$role.'_'.$item.'" value="'.
1473: $designs->{'logintext'}{$item}.'" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>'.
1474: '<td> </td>';
1475: }
1476: $color_menu .= '</tr></table><br />';
1477: return $color_menu;
1478: }
1479:
1480: sub image_changes {
1481: my ($is_custom,$alt_text,$img_import,$showfile,$fullsize,$role,$img,$imgfile,$logincolors) = @_;
1482: my $output;
1.135 bisitz 1483: if ($img eq 'login') {
1484: # suppress image for Log-in header
1485: } elsif (!$is_custom) {
1.70 raeburn 1486: if ($img ne 'domlogo') {
1.41 raeburn 1487: $output .= &mt('Default image:').'<br />';
1488: } else {
1489: $output .= &mt('Default in use:').'<br />';
1490: }
1491: }
1.135 bisitz 1492: if ($img eq 'login') { # suppress image for Log-in header
1493: $output .= '<td>'.$logincolors;
1.41 raeburn 1494: } else {
1.135 bisitz 1495: if ($img_import) {
1496: $output .= '<input type="hidden" name="'.$role.'_import_'.$img.'" value="'.$imgfile.'" />';
1497: }
1498: $output .= '<a href="'.$fullsize.'" target="_blank"><img src="'.
1499: $showfile.'" alt="'.$alt_text.'" border="0" /></a></td>';
1500: if ($is_custom) {
1501: $output .= '<td>'.$logincolors.'<span class="LC_nobreak"><label>'.
1502: '<input type="checkbox" name="'.
1503: $role.'_del_'.$img.'" value="1" />'.&mt('Delete?').
1504: '</label> '.&mt('Replace:').'</span><br />';
1505: } else {
1506: $output .= '<td valign="bottom">'.$logincolors.&mt('Upload:').'<br />';
1507: }
1.41 raeburn 1508: }
1509: return $output;
1510: }
1511:
1.6 raeburn 1512: sub color_pick {
1513: my ($phase,$role,$item,$desc,$curcol) = @_;
1514: my $link = '<a href="javascript:pjump('."'color_custom','".$desc.
1515: "','".$curcol."','".$role.'_'.$item."','parmform.pres','psub'".
1516: ');">'.$desc.'</a>';
1517: return $link;
1518: }
1519:
1.3 raeburn 1520: sub print_quotas {
1.86 raeburn 1521: my ($dom,$settings,$rowtotal,$action) = @_;
1522: my $context;
1523: if ($action eq 'quotas') {
1524: $context = 'tools';
1525: } else {
1526: $context = $action;
1527: }
1.197 ! raeburn 1528: my ($datatable,$defaultquota,$authorquota,@usertools,@options,%validations);
1.44 raeburn 1529: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.3 raeburn 1530: my $typecount = 0;
1.101 raeburn 1531: my ($css_class,%titles);
1.86 raeburn 1532: if ($context eq 'requestcourses') {
1.98 raeburn 1533: @usertools = ('official','unofficial','community');
1.106 raeburn 1534: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 1535: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
1536: %titles = &courserequest_titles();
1.163 raeburn 1537: } elsif ($context eq 'requestauthor') {
1538: @usertools = ('author');
1539: @options = ('norequest','approval','automatic');
1540: %titles = &authorrequest_titles();
1.86 raeburn 1541: } else {
1.162 raeburn 1542: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 1543: %titles = &tool_titles();
1.86 raeburn 1544: }
1.26 raeburn 1545: if (ref($types) eq 'ARRAY') {
1.23 raeburn 1546: foreach my $type (@{$types}) {
1.197 ! raeburn 1547: my ($currdefquota,$currauthorquota);
1.163 raeburn 1548: unless (($context eq 'requestcourses') ||
1549: ($context eq 'requestauthor')) {
1.86 raeburn 1550: if (ref($settings) eq 'HASH') {
1551: if (ref($settings->{defaultquota}) eq 'HASH') {
1.197 ! raeburn 1552: $currdefquota = $settings->{defaultquota}->{$type};
1.86 raeburn 1553: } else {
1554: $currdefquota = $settings->{$type};
1555: }
1.197 ! raeburn 1556: if (ref($settings->{authorquota}) eq 'HASH') {
! 1557: $currauthorquota = $settings->{authorquota}->{$type};
! 1558: }
1.78 raeburn 1559: }
1.72 raeburn 1560: }
1.3 raeburn 1561: if (defined($usertypes->{$type})) {
1562: $typecount ++;
1563: $css_class = $typecount%2?' class="LC_odd_row"':'';
1.72 raeburn 1564: $datatable .= '<tr'.$css_class.'>'.
1.3 raeburn 1565: '<td>'.$usertypes->{$type}.'</td>'.
1.72 raeburn 1566: '<td class="LC_left_item">';
1.101 raeburn 1567: if ($context eq 'requestcourses') {
1568: $datatable .= '<table><tr>';
1569: }
1570: my %cell;
1.72 raeburn 1571: foreach my $item (@usertools) {
1.101 raeburn 1572: if ($context eq 'requestcourses') {
1573: my ($curroption,$currlimit);
1574: if (ref($settings) eq 'HASH') {
1575: if (ref($settings->{$item}) eq 'HASH') {
1576: $curroption = $settings->{$item}->{$type};
1577: if ($curroption =~ /^autolimit=(\d*)$/) {
1578: $currlimit = $1;
1579: }
1580: }
1581: }
1582: if (!$curroption) {
1583: $curroption = 'norequest';
1584: }
1585: $datatable .= '<th>'.$titles{$item}.'</th>';
1586: foreach my $option (@options) {
1587: my $val = $option;
1588: if ($option eq 'norequest') {
1589: $val = 0;
1590: }
1591: if ($option eq 'validate') {
1592: my $canvalidate = 0;
1593: if (ref($validations{$item}) eq 'HASH') {
1594: if ($validations{$item}{$type}) {
1595: $canvalidate = 1;
1596: }
1597: }
1598: next if (!$canvalidate);
1599: }
1600: my $checked = '';
1601: if ($option eq $curroption) {
1602: $checked = ' checked="checked"';
1603: } elsif ($option eq 'autolimit') {
1604: if ($curroption =~ /^autolimit/) {
1605: $checked = ' checked="checked"';
1606: }
1607: }
1608: $cell{$item} .= '<span class="LC_nobreak"><label>'.
1609: '<input type="radio" name="crsreq_'.$item.
1610: '_'.$type.'" value="'.$val.'"'.$checked.' />'.
1.127 raeburn 1611: $titles{$option}.'</label>';
1.101 raeburn 1612: if ($option eq 'autolimit') {
1.127 raeburn 1613: $cell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 1614: $item.'_limit_'.$type.'" size="1" '.
1.103 raeburn 1615: 'value="'.$currlimit.'" />';
1.101 raeburn 1616: }
1.127 raeburn 1617: $cell{$item} .= '</span> ';
1.103 raeburn 1618: if ($option eq 'autolimit') {
1.127 raeburn 1619: $cell{$item} .= $titles{'unlimited'};
1.103 raeburn 1620: }
1.101 raeburn 1621: }
1.163 raeburn 1622: } elsif ($context eq 'requestauthor') {
1623: my $curroption;
1624: if (ref($settings) eq 'HASH') {
1625: $curroption = $settings->{$type};
1626: }
1627: if (!$curroption) {
1628: $curroption = 'norequest';
1629: }
1630: foreach my $option (@options) {
1631: my $val = $option;
1632: if ($option eq 'norequest') {
1633: $val = 0;
1634: }
1635: my $checked = '';
1636: if ($option eq $curroption) {
1637: $checked = ' checked="checked"';
1638: }
1639: $datatable .= '<span class="LC_nobreak"><label>'.
1640: '<input type="radio" name="authorreq_'.$type.
1641: '" value="'.$val.'"'.$checked.' />'.
1642: $titles{$option}.'</label></span> ';
1643: }
1.101 raeburn 1644: } else {
1645: my $checked = 'checked="checked" ';
1646: if (ref($settings) eq 'HASH') {
1647: if (ref($settings->{$item}) eq 'HASH') {
1648: if ($settings->{$item}->{$type} == 0) {
1649: $checked = '';
1650: } elsif ($settings->{$item}->{$type} == 1) {
1651: $checked = 'checked="checked" ';
1652: }
1.78 raeburn 1653: }
1.72 raeburn 1654: }
1.101 raeburn 1655: $datatable .= '<span class="LC_nobreak"><label>'.
1656: '<input type="checkbox" name="'.$context.'_'.$item.
1657: '" value="'.$type.'" '.$checked.'/>'.$titles{$item}.
1658: '</label></span> ';
1.72 raeburn 1659: }
1.101 raeburn 1660: }
1661: if ($context eq 'requestcourses') {
1662: $datatable .= '</tr><tr>';
1663: foreach my $item (@usertools) {
1.106 raeburn 1664: $datatable .= '<td style="vertical-align: top">'.$cell{$item}.'</td>';
1.101 raeburn 1665: }
1666: $datatable .= '</tr></table>';
1.72 raeburn 1667: }
1.86 raeburn 1668: $datatable .= '</td>';
1.163 raeburn 1669: unless (($context eq 'requestcourses') ||
1670: ($context eq 'requestauthor')) {
1.86 raeburn 1671: $datatable .=
1.197 ! raeburn 1672: '<td class="LC_right_item">'.
! 1673: '<span class="LC_nobreak">'.&mt('Portfolio').': '.
1.3 raeburn 1674: '<input type="text" name="quota_'.$type.
1.72 raeburn 1675: '" value="'.$currdefquota.
1.197 ! raeburn 1676: '" size="5" /></span>'.(' ' x 2).
! 1677: '<span class="LC_nobreak">'.&mt('Authoring').': '.
! 1678: '<input type="text" name="authorquota_'.$type.
! 1679: '" value="'.$currauthorquota.
! 1680: '" size="5" /></span></td>';
1.86 raeburn 1681: }
1682: $datatable .= '</tr>';
1.3 raeburn 1683: }
1684: }
1685: }
1.163 raeburn 1686: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 1687: $defaultquota = '20';
1.197 ! raeburn 1688: $authorquota = '500';
1.86 raeburn 1689: if (ref($settings) eq 'HASH') {
1690: if (ref($settings->{'defaultquota'}) eq 'HASH') {
1691: $defaultquota = $settings->{'defaultquota'}->{'default'};
1692: } elsif (defined($settings->{'default'})) {
1693: $defaultquota = $settings->{'default'};
1694: }
1.197 ! raeburn 1695: if (ref($settings->{'authorquota'}) eq 'HASH') {
! 1696: $authorquota = $settings->{'authorquota'}->{'default'};
! 1697: }
1.3 raeburn 1698: }
1699: }
1700: $typecount ++;
1701: $css_class = $typecount%2?' class="LC_odd_row"':'';
1702: $datatable .= '<tr'.$css_class.'>'.
1.26 raeburn 1703: '<td>'.$othertitle.'</td>'.
1.72 raeburn 1704: '<td class="LC_left_item">';
1.101 raeburn 1705: if ($context eq 'requestcourses') {
1706: $datatable .= '<table><tr>';
1707: }
1708: my %defcell;
1.72 raeburn 1709: foreach my $item (@usertools) {
1.101 raeburn 1710: if ($context eq 'requestcourses') {
1711: my ($curroption,$currlimit);
1712: if (ref($settings) eq 'HASH') {
1713: if (ref($settings->{$item}) eq 'HASH') {
1714: $curroption = $settings->{$item}->{'default'};
1715: if ($curroption =~ /^autolimit=(\d*)$/) {
1716: $currlimit = $1;
1717: }
1718: }
1719: }
1720: if (!$curroption) {
1721: $curroption = 'norequest';
1722: }
1723: $datatable .= '<th>'.$titles{$item}.'</th>';
1724: foreach my $option (@options) {
1725: my $val = $option;
1726: if ($option eq 'norequest') {
1727: $val = 0;
1728: }
1729: if ($option eq 'validate') {
1730: my $canvalidate = 0;
1731: if (ref($validations{$item}) eq 'HASH') {
1732: if ($validations{$item}{'default'}) {
1733: $canvalidate = 1;
1734: }
1735: }
1736: next if (!$canvalidate);
1737: }
1738: my $checked = '';
1739: if ($option eq $curroption) {
1740: $checked = ' checked="checked"';
1741: } elsif ($option eq 'autolimit') {
1742: if ($curroption =~ /^autolimit/) {
1743: $checked = ' checked="checked"';
1744: }
1745: }
1746: $defcell{$item} .= '<span class="LC_nobreak"><label>'.
1747: '<input type="radio" name="crsreq_'.$item.
1748: '_default" value="'.$val.'"'.$checked.' />'.
1749: $titles{$option}.'</label>';
1750: if ($option eq 'autolimit') {
1.127 raeburn 1751: $defcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 1752: $item.'_limit_default" size="1" '.
1753: 'value="'.$currlimit.'" />';
1754: }
1.127 raeburn 1755: $defcell{$item} .= '</span> ';
1.104 raeburn 1756: if ($option eq 'autolimit') {
1.127 raeburn 1757: $defcell{$item} .= $titles{'unlimited'};
1.104 raeburn 1758: }
1.101 raeburn 1759: }
1.163 raeburn 1760: } elsif ($context eq 'requestauthor') {
1761: my $curroption;
1762: if (ref($settings) eq 'HASH') {
1.172 raeburn 1763: $curroption = $settings->{'default'};
1.163 raeburn 1764: }
1765: if (!$curroption) {
1766: $curroption = 'norequest';
1767: }
1768: foreach my $option (@options) {
1769: my $val = $option;
1770: if ($option eq 'norequest') {
1771: $val = 0;
1772: }
1773: my $checked = '';
1774: if ($option eq $curroption) {
1775: $checked = ' checked="checked"';
1776: }
1777: $datatable .= '<span class="LC_nobreak"><label>'.
1778: '<input type="radio" name="authorreq_default"'.
1779: ' value="'.$val.'"'.$checked.' />'.
1780: $titles{$option}.'</label></span> ';
1781: }
1.101 raeburn 1782: } else {
1783: my $checked = 'checked="checked" ';
1784: if (ref($settings) eq 'HASH') {
1785: if (ref($settings->{$item}) eq 'HASH') {
1786: if ($settings->{$item}->{'default'} == 0) {
1787: $checked = '';
1788: } elsif ($settings->{$item}->{'default'} == 1) {
1789: $checked = 'checked="checked" ';
1790: }
1.78 raeburn 1791: }
1.72 raeburn 1792: }
1.101 raeburn 1793: $datatable .= '<span class="LC_nobreak"><label>'.
1794: '<input type="checkbox" name="'.$context.'_'.$item.
1795: '" value="default" '.$checked.'/>'.$titles{$item}.
1796: '</label></span> ';
1797: }
1798: }
1799: if ($context eq 'requestcourses') {
1800: $datatable .= '</tr><tr>';
1801: foreach my $item (@usertools) {
1.106 raeburn 1802: $datatable .= '<td style="vertical-align: top">'.$defcell{$item}.'</td>';
1.72 raeburn 1803: }
1.101 raeburn 1804: $datatable .= '</tr></table>';
1.72 raeburn 1805: }
1.86 raeburn 1806: $datatable .= '</td>';
1.163 raeburn 1807: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.197 ! raeburn 1808: $datatable .= '<td class="LC_right_item">'.
! 1809: '<span class="LC_nobreak">'.&mt('Portfolio').': '.
1.86 raeburn 1810: '<input type="text" name="defaultquota" value="'.
1.197 ! raeburn 1811: $defaultquota.'" size="5" /></span>'.(' ' x2).
! 1812: '<span class="LC_nobreak">'.&mt('Authoring').': '.
! 1813: '<input type="text" name="authorquota" value="'.
! 1814: $authorquota.'" size="5" /></span></td>';
1.86 raeburn 1815: }
1816: $datatable .= '</tr>';
1.72 raeburn 1817: $typecount ++;
1818: $css_class = $typecount%2?' class="LC_odd_row"':'';
1819: $datatable .= '<tr'.$css_class.'>'.
1.197 ! raeburn 1820: '<td>'.&mt('LON-CAPA Advanced Users').'<br />';
1.104 raeburn 1821: if ($context eq 'requestcourses') {
1.109 raeburn 1822: $datatable .= &mt('(overrides affiliation, if set)').
1823: '</td>'.
1824: '<td class="LC_left_item">'.
1825: '<table><tr>';
1.101 raeburn 1826: } else {
1.109 raeburn 1827: $datatable .= &mt('(overrides affiliation, if checked)').
1828: '</td>'.
1829: '<td class="LC_left_item" colspan="2">'.
1830: '<br />';
1.101 raeburn 1831: }
1832: my %advcell;
1.72 raeburn 1833: foreach my $item (@usertools) {
1.101 raeburn 1834: if ($context eq 'requestcourses') {
1835: my ($curroption,$currlimit);
1836: if (ref($settings) eq 'HASH') {
1837: if (ref($settings->{$item}) eq 'HASH') {
1838: $curroption = $settings->{$item}->{'_LC_adv'};
1839: if ($curroption =~ /^autolimit=(\d*)$/) {
1840: $currlimit = $1;
1841: }
1842: }
1843: }
1844: $datatable .= '<th>'.$titles{$item}.'</th>';
1.104 raeburn 1845: my $checked = '';
1846: if ($curroption eq '') {
1847: $checked = ' checked="checked"';
1848: }
1849: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
1850: '<input type="radio" name="crsreq_'.$item.
1851: '__LC_adv" value=""'.$checked.' />'.
1852: &mt('No override set').'</label></span> ';
1.101 raeburn 1853: foreach my $option (@options) {
1854: my $val = $option;
1855: if ($option eq 'norequest') {
1856: $val = 0;
1857: }
1858: if ($option eq 'validate') {
1859: my $canvalidate = 0;
1860: if (ref($validations{$item}) eq 'HASH') {
1861: if ($validations{$item}{'_LC_adv'}) {
1862: $canvalidate = 1;
1863: }
1864: }
1865: next if (!$canvalidate);
1866: }
1867: my $checked = '';
1.104 raeburn 1868: if ($val eq $curroption) {
1.101 raeburn 1869: $checked = ' checked="checked"';
1870: } elsif ($option eq 'autolimit') {
1871: if ($curroption =~ /^autolimit/) {
1872: $checked = ' checked="checked"';
1873: }
1874: }
1875: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
1876: '<input type="radio" name="crsreq_'.$item.
1877: '__LC_adv" value="'.$val.'"'.$checked.' />'.
1878: $titles{$option}.'</label>';
1879: if ($option eq 'autolimit') {
1.127 raeburn 1880: $advcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 1881: $item.'_limit__LC_adv" size="1" '.
1882: 'value="'.$currlimit.'" />';
1883: }
1.127 raeburn 1884: $advcell{$item} .= '</span> ';
1.104 raeburn 1885: if ($option eq 'autolimit') {
1.127 raeburn 1886: $advcell{$item} .= $titles{'unlimited'};
1.104 raeburn 1887: }
1.101 raeburn 1888: }
1.163 raeburn 1889: } elsif ($context eq 'requestauthor') {
1890: my $curroption;
1891: if (ref($settings) eq 'HASH') {
1892: $curroption = $settings->{'_LC_adv'};
1893: }
1894: my $checked = '';
1895: if ($curroption eq '') {
1896: $checked = ' checked="checked"';
1897: }
1898: $datatable .= '<span class="LC_nobreak"><label>'.
1899: '<input type="radio" name="authorreq__LC_adv"'.
1900: ' value=""'.$checked.' />'.
1901: &mt('No override set').'</label></span> ';
1902: foreach my $option (@options) {
1903: my $val = $option;
1904: if ($option eq 'norequest') {
1905: $val = 0;
1906: }
1907: my $checked = '';
1908: if ($val eq $curroption) {
1909: $checked = ' checked="checked"';
1910: }
1911: $datatable .= '<span class="LC_nobreak"><label>'.
1.173 raeburn 1912: '<input type="radio" name="authorreq__LC_adv"'.
1913: ' value="'.$val.'"'.$checked.' />'.
1.163 raeburn 1914: $titles{$option}.'</label></span> ';
1915: }
1.101 raeburn 1916: } else {
1917: my $checked = 'checked="checked" ';
1918: if (ref($settings) eq 'HASH') {
1919: if (ref($settings->{$item}) eq 'HASH') {
1920: if ($settings->{$item}->{'_LC_adv'} == 0) {
1921: $checked = '';
1922: } elsif ($settings->{$item}->{'_LC_adv'} == 1) {
1923: $checked = 'checked="checked" ';
1924: }
1.79 raeburn 1925: }
1.72 raeburn 1926: }
1.101 raeburn 1927: $datatable .= '<span class="LC_nobreak"><label>'.
1928: '<input type="checkbox" name="'.$context.'_'.$item.
1929: '" value="_LC_adv" '.$checked.'/>'.$titles{$item}.
1930: '</label></span> ';
1931: }
1932: }
1933: if ($context eq 'requestcourses') {
1934: $datatable .= '</tr><tr>';
1935: foreach my $item (@usertools) {
1.106 raeburn 1936: $datatable .= '<td style="vertical-align: top">'.$advcell{$item}.'</td>';
1.72 raeburn 1937: }
1.101 raeburn 1938: $datatable .= '</tr></table>';
1.72 raeburn 1939: }
1.98 raeburn 1940: $datatable .= '</td></tr>';
1.30 raeburn 1941: $$rowtotal += $typecount;
1.3 raeburn 1942: return $datatable;
1943: }
1944:
1.163 raeburn 1945: sub print_requestmail {
1946: my ($dom,$action,$settings,$rowtotal) = @_;
1.191 raeburn 1947: my ($now,$datatable,%currapp,$rows);
1.102 raeburn 1948: $now = time;
1949: if (ref($settings) eq 'HASH') {
1950: if (ref($settings->{'notify'}) eq 'HASH') {
1951: if ($settings->{'notify'}{'approval'} ne '') {
1.191 raeburn 1952: map {$currapp{$_}=1;} split(/,/,$settings->{'notify'}{'approval'});
1.102 raeburn 1953: }
1954: }
1955: }
1.191 raeburn 1956: my $numinrow = 2;
1.102 raeburn 1957: my $css_class = 'class="LC_odd_row"';
1.163 raeburn 1958: my $text;
1959: if ($action eq 'requestcourses') {
1960: $text = &mt('Receive notification of course requests requiring approval');
1961: } else {
1962: $text = &mt('Receive notification of authoring space requests requiring approval')
1963: }
1964: $datatable = '<tr '.$css_class.'>'.
1965: ' <td>'.$text.'</td>'.
1.102 raeburn 1966: ' <td class="LC_left_item">';
1.191 raeburn 1967: my ($numdc,$table,$rows) = &active_dc_picker($dom,$numinrow,'checkbox',
1968: 'reqapprovalnotify',%currapp);
1969: if ($numdc > 0) {
1970: $datatable .= $table;
1.102 raeburn 1971: } else {
1972: $datatable .= &mt('There are no active Domain Coordinators');
1973: }
1974: $datatable .='</td></tr>';
1975: $$rowtotal += $rows;
1976: return $datatable;
1977: }
1978:
1.3 raeburn 1979: sub print_autoenroll {
1.30 raeburn 1980: my ($dom,$settings,$rowtotal) = @_;
1.3 raeburn 1981: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
1.129 raeburn 1982: my ($defdom,$runon,$runoff,$coownerson,$coownersoff);
1.3 raeburn 1983: if (ref($settings) eq 'HASH') {
1984: if (exists($settings->{'run'})) {
1985: if ($settings->{'run'} eq '0') {
1986: $runoff = ' checked="checked" ';
1987: $runon = ' ';
1988: } else {
1989: $runon = ' checked="checked" ';
1990: $runoff = ' ';
1991: }
1992: } else {
1993: if ($autorun) {
1994: $runon = ' checked="checked" ';
1995: $runoff = ' ';
1996: } else {
1997: $runoff = ' checked="checked" ';
1998: $runon = ' ';
1999: }
2000: }
1.129 raeburn 2001: if (exists($settings->{'co-owners'})) {
2002: if ($settings->{'co-owners'} eq '0') {
2003: $coownersoff = ' checked="checked" ';
2004: $coownerson = ' ';
2005: } else {
2006: $coownerson = ' checked="checked" ';
2007: $coownersoff = ' ';
2008: }
2009: } else {
2010: $coownersoff = ' checked="checked" ';
2011: $coownerson = ' ';
2012: }
1.3 raeburn 2013: if (exists($settings->{'sender_domain'})) {
2014: $defdom = $settings->{'sender_domain'};
2015: }
1.14 raeburn 2016: } else {
2017: if ($autorun) {
2018: $runon = ' checked="checked" ';
2019: $runoff = ' ';
2020: } else {
2021: $runoff = ' checked="checked" ';
2022: $runon = ' ';
2023: }
1.3 raeburn 2024: }
2025: my $domform = &Apache::loncommon::select_dom_form($defdom,'sender_domain',1);
1.39 raeburn 2026: my $notif_sender;
2027: if (ref($settings) eq 'HASH') {
2028: $notif_sender = $settings->{'sender_uname'};
2029: }
1.3 raeburn 2030: my $datatable='<tr class="LC_odd_row">'.
2031: '<td>'.&mt('Auto-enrollment active?').'</td>'.
1.8 raeburn 2032: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 2033: '<input type="radio" name="autoenroll_run"'.
1.8 raeburn 2034: $runon.' value="1" />'.&mt('Yes').'</label> '.
2035: '<label><input type="radio" name="autoenroll_run"'.
1.14 raeburn 2036: $runoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 2037: '</tr><tr>'.
2038: '<td>'.&mt('Notification messages - sender').
1.8 raeburn 2039: '</td><td class="LC_right_item"><span class="LC_nobreak">'.
1.3 raeburn 2040: &mt('username').': '.
2041: '<input type="text" name="sender_uname" value="'.
1.39 raeburn 2042: $notif_sender.'" size="10" /> '.&mt('domain').
1.129 raeburn 2043: ': '.$domform.'</span></td></tr>'.
2044: '<tr class="LC_odd_row">'.
2045: '<td>'.&mt('Automatically assign co-ownership').'</td>'.
2046: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2047: '<input type="radio" name="autoassign_coowners"'.
2048: $coownerson.' value="1" />'.&mt('Yes').'</label> '.
2049: '<label><input type="radio" name="autoassign_coowners"'.
2050: $coownersoff.' value="0" />'.&mt('No').'</label></span></td>'.
2051: '</tr>';
2052: $$rowtotal += 3;
1.3 raeburn 2053: return $datatable;
2054: }
2055:
2056: sub print_autoupdate {
1.30 raeburn 2057: my ($position,$dom,$settings,$rowtotal) = @_;
1.3 raeburn 2058: my $datatable;
2059: if ($position eq 'top') {
2060: my $updateon = ' ';
2061: my $updateoff = ' checked="checked" ';
2062: my $classlistson = ' ';
2063: my $classlistsoff = ' checked="checked" ';
2064: if (ref($settings) eq 'HASH') {
2065: if ($settings->{'run'} eq '1') {
2066: $updateon = $updateoff;
2067: $updateoff = ' ';
2068: }
2069: if ($settings->{'classlists'} eq '1') {
2070: $classlistson = $classlistsoff;
2071: $classlistsoff = ' ';
2072: }
2073: }
2074: my %title = (
2075: run => 'Auto-update active?',
2076: classlists => 'Update information in classlists?',
2077: );
2078: $datatable = '<tr class="LC_odd_row">'.
2079: '<td>'.&mt($title{'run'}).'</td>'.
1.8 raeburn 2080: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 2081: '<input type="radio" name="autoupdate_run"'.
1.8 raeburn 2082: $updateon.' value="1" />'.&mt('Yes').'</label> '.
2083: '<label><input type="radio" name="autoupdate_run"'.
2084: $updateoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 2085: '</tr><tr>'.
2086: '<td>'.&mt($title{'classlists'}).'</td>'.
1.8 raeburn 2087: '<td class="LC_right_item"><span class="LC_nobreak">'.
2088: '<label><input type="radio" name="classlists"'.
2089: $classlistson.' value="1" />'.&mt('Yes').'</label> '.
2090: '<label><input type="radio" name="classlists"'.
2091: $classlistsoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 2092: '</tr>';
1.30 raeburn 2093: $$rowtotal += 2;
1.131 raeburn 2094: } elsif ($position eq 'middle') {
2095: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
2096: my $numinrow = 3;
2097: my $locknamesettings;
2098: $datatable .= &insttypes_row($settings,$types,$usertypes,
2099: $dom,$numinrow,$othertitle,
2100: 'lockablenames');
2101: $$rowtotal ++;
1.3 raeburn 2102: } else {
1.44 raeburn 2103: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.132 raeburn 2104: my @fields = ('lastname','firstname','middlename','generation',
1.20 raeburn 2105: 'permanentemail','id');
1.33 raeburn 2106: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1.3 raeburn 2107: my $numrows = 0;
1.26 raeburn 2108: if (ref($types) eq 'ARRAY') {
2109: if (@{$types} > 0) {
2110: $datatable =
2111: &usertype_update_row($settings,$usertypes,\%fieldtitles,
2112: \@fields,$types,\$numrows);
1.30 raeburn 2113: $$rowtotal += @{$types};
1.26 raeburn 2114: }
1.3 raeburn 2115: }
2116: $datatable .=
2117: &usertype_update_row($settings,{'default' => $othertitle},
2118: \%fieldtitles,\@fields,['default'],
2119: \$numrows);
1.30 raeburn 2120: $$rowtotal ++;
1.3 raeburn 2121: }
2122: return $datatable;
2123: }
2124:
1.125 raeburn 2125: sub print_autocreate {
2126: my ($dom,$settings,$rowtotal) = @_;
1.191 raeburn 2127: my (%createon,%createoff,%currhash);
1.125 raeburn 2128: my @types = ('xml','req');
2129: if (ref($settings) eq 'HASH') {
2130: foreach my $item (@types) {
2131: $createoff{$item} = ' checked="checked" ';
2132: $createon{$item} = ' ';
2133: if (exists($settings->{$item})) {
2134: if ($settings->{$item}) {
2135: $createon{$item} = ' checked="checked" ';
2136: $createoff{$item} = ' ';
2137: }
2138: }
2139: }
1.191 raeburn 2140: if ($settings->{'xmldc'} ne '') {
2141: $currhash{$settings->{'xmldc'}} = 1;
2142: }
1.125 raeburn 2143: } else {
2144: foreach my $item (@types) {
2145: $createoff{$item} = ' checked="checked" ';
2146: $createon{$item} = ' ';
2147: }
2148: }
2149: $$rowtotal += 2;
1.191 raeburn 2150: my $numinrow = 2;
1.125 raeburn 2151: my $datatable='<tr class="LC_odd_row">'.
2152: '<td>'.&mt('Create pending official courses from XML files').'</td>'.
2153: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2154: '<input type="radio" name="autocreate_xml"'.
2155: $createon{'xml'}.' value="1" />'.&mt('Yes').'</label> '.
2156: '<label><input type="radio" name="autocreate_xml"'.
1.143 raeburn 2157: $createoff{'xml'}.' value="0" />'.&mt('No').'</label></span>'.
2158: '</td></tr><tr>'.
2159: '<td>'.&mt('Create pending requests for official courses (if validated)').'</td>'.
2160: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2161: '<input type="radio" name="autocreate_req"'.
2162: $createon{'req'}.' value="1" />'.&mt('Yes').'</label> '.
2163: '<label><input type="radio" name="autocreate_req"'.
2164: $createoff{'req'}.' value="0" />'.&mt('No').'</label></span>';
1.191 raeburn 2165: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
2166: 'autocreate_xmldc',%currhash);
1.125 raeburn 2167: if ($numdc > 1) {
1.143 raeburn 2168: $datatable .= '</td></tr><tr class="LC_odd_row"><td>'.
2169: &mt('Course creation processed as: (choose Dom. Coord.)').
2170: '</td><td class="LC_left_item">'.$dctable.'</td></tr>';
1.125 raeburn 2171: } else {
1.143 raeburn 2172: $datatable .= $dctable.'</td></tr>';
1.125 raeburn 2173: }
1.191 raeburn 2174: $$rowtotal += $rows;
1.125 raeburn 2175: return $datatable;
2176: }
2177:
1.23 raeburn 2178: sub print_directorysrch {
1.30 raeburn 2179: my ($dom,$settings,$rowtotal) = @_;
1.23 raeburn 2180: my $srchon = ' ';
2181: my $srchoff = ' checked="checked" ';
1.25 raeburn 2182: my ($exacton,$containson,$beginson);
1.24 raeburn 2183: my $localon = ' ';
2184: my $localoff = ' checked="checked" ';
1.23 raeburn 2185: if (ref($settings) eq 'HASH') {
2186: if ($settings->{'available'} eq '1') {
2187: $srchon = $srchoff;
2188: $srchoff = ' ';
2189: }
1.24 raeburn 2190: if ($settings->{'localonly'} eq '1') {
2191: $localon = $localoff;
2192: $localoff = ' ';
2193: }
1.25 raeburn 2194: if (ref($settings->{'searchtypes'}) eq 'ARRAY') {
2195: foreach my $type (@{$settings->{'searchtypes'}}) {
2196: if ($type eq 'exact') {
2197: $exacton = ' checked="checked" ';
2198: } elsif ($type eq 'contains') {
2199: $containson = ' checked="checked" ';
2200: } elsif ($type eq 'begins') {
2201: $beginson = ' checked="checked" ';
2202: }
2203: }
2204: } else {
2205: if ($settings->{'searchtypes'} eq 'exact') {
2206: $exacton = ' checked="checked" ';
2207: } elsif ($settings->{'searchtypes'} eq 'contains') {
2208: $containson = ' checked="checked" ';
2209: } elsif ($settings->{'searchtypes'} eq 'specify') {
2210: $exacton = ' checked="checked" ';
2211: $containson = ' checked="checked" ';
2212: }
1.23 raeburn 2213: }
2214: }
2215: my ($searchtitles,$titleorder) = &sorted_searchtitles();
1.45 raeburn 2216: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.23 raeburn 2217:
2218: my $numinrow = 4;
1.26 raeburn 2219: my $cansrchrow = 0;
1.23 raeburn 2220: my $datatable='<tr class="LC_odd_row">'.
1.30 raeburn 2221: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Directory search available?').'</span></td>'.
1.23 raeburn 2222: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2223: '<input type="radio" name="dirsrch_available"'.
2224: $srchon.' value="1" />'.&mt('Yes').'</label> '.
2225: '<label><input type="radio" name="dirsrch_available"'.
2226: $srchoff.' value="0" />'.&mt('No').'</label></span></td>'.
2227: '</tr><tr>'.
1.30 raeburn 2228: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search?').'</span></td>'.
1.24 raeburn 2229: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2230: '<input type="radio" name="dirsrch_localonly"'.
2231: $localoff.' value="0" />'.&mt('Yes').'</label> '.
2232: '<label><input type="radio" name="dirsrch_localonly"'.
2233: $localon.' value="1" />'.&mt('No').'</label></span></td>'.
1.25 raeburn 2234: '</tr>';
1.30 raeburn 2235: $$rowtotal += 2;
1.26 raeburn 2236: if (ref($usertypes) eq 'HASH') {
2237: if (keys(%{$usertypes}) > 0) {
1.93 raeburn 2238: $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
2239: $numinrow,$othertitle,'cansearch');
1.26 raeburn 2240: $cansrchrow = 1;
2241: }
2242: }
2243: if ($cansrchrow) {
1.30 raeburn 2244: $$rowtotal ++;
1.26 raeburn 2245: $datatable .= '<tr>';
2246: } else {
2247: $datatable .= '<tr class="LC_odd_row">';
2248: }
1.30 raeburn 2249: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Supported search methods').
2250: '</span></td><td class="LC_left_item" colspan="2"><table><tr>';
1.25 raeburn 2251: foreach my $title (@{$titleorder}) {
2252: if (defined($searchtitles->{$title})) {
2253: my $check = ' ';
1.93 raeburn 2254: if (ref($settings) eq 'HASH') {
1.39 raeburn 2255: if (ref($settings->{'searchby'}) eq 'ARRAY') {
2256: if (grep(/^\Q$title\E$/,@{$settings->{'searchby'}})) {
2257: $check = ' checked="checked" ';
2258: }
1.25 raeburn 2259: }
2260: }
2261: $datatable .= '<td class="LC_left_item">'.
2262: '<span class="LC_nobreak"><label>'.
2263: '<input type="checkbox" name="searchby" '.
2264: 'value="'.$title.'"'.$check.'/>'.
2265: $searchtitles->{$title}.'</label></span></td>';
2266: }
2267: }
1.26 raeburn 2268: $datatable .= '</tr></table></td></tr>';
1.30 raeburn 2269: $$rowtotal ++;
1.26 raeburn 2270: if ($cansrchrow) {
2271: $datatable .= '<tr class="LC_odd_row">';
2272: } else {
2273: $datatable .= '<tr>';
2274: }
1.30 raeburn 2275: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Search latitude').'</span></td>'.
1.26 raeburn 2276: '<td class="LC_left_item" colspan="2">'.
1.25 raeburn 2277: '<span class="LC_nobreak"><label>'.
2278: '<input type="checkbox" name="searchtypes" '.
2279: $exacton.' value="exact" />'.&mt('Exact match').
2280: '</label> '.
2281: '<label><input type="checkbox" name="searchtypes" '.
2282: $beginson.' value="begins" />'.&mt('Begins with').
2283: '</label> '.
2284: '<label><input type="checkbox" name="searchtypes" '.
2285: $containson.' value="contains" />'.&mt('Contains').
2286: '</label></span></td></tr>';
1.30 raeburn 2287: $$rowtotal ++;
1.25 raeburn 2288: return $datatable;
2289: }
2290:
1.28 raeburn 2291: sub print_contacts {
1.30 raeburn 2292: my ($dom,$settings,$rowtotal) = @_;
1.28 raeburn 2293: my $datatable;
2294: my @contacts = ('adminemail','supportemail');
1.134 raeburn 2295: my (%checked,%to,%otheremails,%bccemails);
1.102 raeburn 2296: my @mailings = ('errormail','packagesmail','lonstatusmail','helpdeskmail',
1.190 raeburn 2297: 'requestsmail','updatesmail');
1.28 raeburn 2298: foreach my $type (@mailings) {
2299: $otheremails{$type} = '';
2300: }
1.134 raeburn 2301: $bccemails{'helpdeskmail'} = '';
1.28 raeburn 2302: if (ref($settings) eq 'HASH') {
2303: foreach my $item (@contacts) {
2304: if (exists($settings->{$item})) {
2305: $to{$item} = $settings->{$item};
2306: }
2307: }
2308: foreach my $type (@mailings) {
2309: if (exists($settings->{$type})) {
2310: if (ref($settings->{$type}) eq 'HASH') {
2311: foreach my $item (@contacts) {
2312: if ($settings->{$type}{$item}) {
2313: $checked{$type}{$item} = ' checked="checked" ';
2314: }
2315: }
2316: $otheremails{$type} = $settings->{$type}{'others'};
1.134 raeburn 2317: if ($type eq 'helpdeskmail') {
2318: $bccemails{$type} = $settings->{$type}{'bcc'};
2319: }
1.28 raeburn 2320: }
1.89 raeburn 2321: } elsif ($type eq 'lonstatusmail') {
2322: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
1.28 raeburn 2323: }
2324: }
2325: } else {
2326: $to{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
2327: $to{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
2328: $checked{'errormail'}{'adminemail'} = ' checked="checked" ';
2329: $checked{'packagesmail'}{'adminemail'} = ' checked="checked" ';
1.89 raeburn 2330: $checked{'helpdeskmail'}{'supportemail'} = ' checked="checked" ';
2331: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
1.102 raeburn 2332: $checked{'requestsmail'}{'adminemail'} = ' checked="checked" ';
1.190 raeburn 2333: $checked{'updatesmail'}{'adminemail'} = ' checked="checked" ';
1.28 raeburn 2334: }
2335: my ($titles,$short_titles) = &contact_titles();
2336: my $rownum = 0;
2337: my $css_class;
2338: foreach my $item (@contacts) {
1.69 raeburn 2339: $rownum ++;
2340: $css_class = $rownum%2?' class="LC_odd_row"':'';
1.30 raeburn 2341: $datatable .= '<tr'.$css_class.'>'.
2342: '<td><span class="LC_nobreak">'.$titles->{$item}.
2343: '</span></td><td class="LC_right_item">'.
1.28 raeburn 2344: '<input type="text" name="'.$item.'" value="'.
2345: $to{$item}.'" /></td></tr>';
2346: }
2347: foreach my $type (@mailings) {
1.69 raeburn 2348: $rownum ++;
2349: $css_class = $rownum%2?' class="LC_odd_row"':'';
1.28 raeburn 2350: $datatable .= '<tr'.$css_class.'>'.
1.30 raeburn 2351: '<td><span class="LC_nobreak">'.
2352: $titles->{$type}.': </span></td>'.
1.28 raeburn 2353: '<td class="LC_left_item">'.
2354: '<span class="LC_nobreak">';
2355: foreach my $item (@contacts) {
2356: $datatable .= '<label>'.
2357: '<input type="checkbox" name="'.$type.'"'.
2358: $checked{$type}{$item}.
2359: ' value="'.$item.'" />'.$short_titles->{$item}.
2360: '</label> ';
2361: }
2362: $datatable .= '</span><br />'.&mt('Others').': '.
2363: '<input type="text" name="'.$type.'_others" '.
1.134 raeburn 2364: 'value="'.$otheremails{$type}.'" />';
2365: if ($type eq 'helpdeskmail') {
1.136 raeburn 2366: $datatable .= '<br />'.&mt('Bcc:').(' 'x6).
1.134 raeburn 2367: '<input type="text" name="'.$type.'_bcc" '.
2368: 'value="'.$bccemails{$type}.'" />';
2369: }
2370: $datatable .= '</td></tr>'."\n";
1.28 raeburn 2371: }
1.30 raeburn 2372: $$rowtotal += $rownum;
1.28 raeburn 2373: return $datatable;
2374: }
2375:
1.118 jms 2376: sub print_helpsettings {
1.168 raeburn 2377: my ($dom,$confname,$settings,$rowtotal) = @_;
2378: my ($datatable,$itemcount);
1.166 raeburn 2379: $itemcount = 1;
1.168 raeburn 2380: my (%choices,%defaultchecked,@toggles);
2381: $choices{'submitbugs'} = &mt('Display link to: [_1]?',
2382: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
2383: &mt('LON-CAPA bug tracker'),600,500));
2384: %defaultchecked = ('submitbugs' => 'on');
2385: @toggles = ('submitbugs',);
1.166 raeburn 2386:
1.168 raeburn 2387: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
2388: \%choices,$itemcount);
1.166 raeburn 2389: return $datatable;
1.121 raeburn 2390: }
2391:
2392: sub radiobutton_prefs {
1.192 raeburn 2393: my ($settings,$toggles,$defaultchecked,$choices,$itemcount,$onclick,
2394: $additional) = @_;
1.121 raeburn 2395: return unless ((ref($toggles) eq 'ARRAY') && (ref($defaultchecked) eq 'HASH') &&
2396: (ref($choices) eq 'HASH'));
2397:
1.170 raeburn 2398: my (%checkedon,%checkedoff,$datatable,$css_class);
1.121 raeburn 2399:
2400: foreach my $item (@{$toggles}) {
2401: if ($defaultchecked->{$item} eq 'on') {
1.118 jms 2402: $checkedon{$item} = ' checked="checked" ';
2403: $checkedoff{$item} = ' ';
1.121 raeburn 2404: } elsif ($defaultchecked->{$item} eq 'off') {
1.118 jms 2405: $checkedoff{$item} = ' checked="checked" ';
2406: $checkedon{$item} = ' ';
2407: }
2408: }
2409: if (ref($settings) eq 'HASH') {
1.121 raeburn 2410: foreach my $item (@{$toggles}) {
1.118 jms 2411: if ($settings->{$item} eq '1') {
2412: $checkedon{$item} = ' checked="checked" ';
2413: $checkedoff{$item} = ' ';
2414: } elsif ($settings->{$item} eq '0') {
2415: $checkedoff{$item} = ' checked="checked" ';
2416: $checkedon{$item} = ' ';
2417: }
2418: }
1.121 raeburn 2419: }
1.192 raeburn 2420: if ($onclick) {
2421: $onclick = ' onclick="'.$onclick.'"';
2422: }
1.121 raeburn 2423: foreach my $item (@{$toggles}) {
1.118 jms 2424: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.121 raeburn 2425: $datatable .=
1.192 raeburn 2426: '<tr'.$css_class.'><td valign="top">'.
2427: '<span class="LC_nobreak">'.$choices->{$item}.
1.118 jms 2428: '</span></td>'.
2429: '<td class="LC_right_item"><span class="LC_nobreak">'.
2430: '<label><input type="radio" name="'.
1.192 raeburn 2431: $item.'" '.$checkedon{$item}.' value="1"'.$onclick.' />'.&mt('Yes').
1.118 jms 2432: '</label> <label><input type="radio" name="'.$item.'" '.
1.192 raeburn 2433: $checkedoff{$item}.' value="0"'.$onclick.' />'.&mt('No').'</label>'.
2434: '</span>'.$additional.
2435: '</td>'.
1.118 jms 2436: '</tr>';
2437: $itemcount ++;
1.121 raeburn 2438: }
2439: return ($datatable,$itemcount);
2440: }
2441:
2442: sub print_coursedefaults {
1.139 raeburn 2443: my ($position,$dom,$settings,$rowtotal) = @_;
1.192 raeburn 2444: my ($css_class,$datatable,%checkedon,%checkedoff,%defaultchecked,@toggles);
1.121 raeburn 2445: my $itemcount = 1;
1.192 raeburn 2446: my %choices = &Apache::lonlocal::texthash (
2447: canuse_pdfforms => 'Course/Community users can create/upload PDF forms',
2448: anonsurvey_threshold => 'Responder count needed before showing submissions for anonymous surveys',
2449: coursecredits => 'Credits can be specified for courses',
2450: );
1.139 raeburn 2451: if ($position eq 'top') {
2452: %defaultchecked = ('canuse_pdfforms' => 'off');
1.192 raeburn 2453: @toggles = ('canuse_pdfforms');
1.139 raeburn 2454: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
1.121 raeburn 2455: \%choices,$itemcount);
1.139 raeburn 2456: } else {
2457: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.192 raeburn 2458: my ($currdefresponder,$def_official_credits,$def_unofficial_credits);
2459: my $currusecredits = 0;
1.139 raeburn 2460: if (ref($settings) eq 'HASH') {
2461: $currdefresponder = $settings->{'anonsurvey_threshold'};
1.192 raeburn 2462: if (ref($settings->{'coursecredits'}) eq 'HASH') {
2463: $def_official_credits = $settings->{'coursecredits'}->{'official'};
2464: $def_unofficial_credits = $settings->{'coursecredits'}->{'unofficial'};
2465: if (($def_official_credits ne '') || ($def_unofficial_credits ne '')) {
2466: $currusecredits = 1;
2467: }
2468: }
1.139 raeburn 2469: }
2470: if (!$currdefresponder) {
2471: $currdefresponder = 10;
2472: } elsif ($currdefresponder < 1) {
2473: $currdefresponder = 1;
2474: }
2475: $datatable .=
1.192 raeburn 2476: '<tr'.$css_class.'><td><span class="LC_nobreak">'.
2477: $choices{'anonsurvey_threshold'}.
1.139 raeburn 2478: '</span></td>'.
2479: '<td class="LC_right_item"><span class="LC_nobreak">'.
2480: '<input type="text" name="anonsurvey_threshold"'.
2481: ' value="'.$currdefresponder.'" size="5" /></span>'.
1.192 raeburn 2482: '</td></tr>'."\n";
2483: $itemcount ++;
2484: my $onclick = 'toggleCredits(this.form);';
2485: my $display = 'none';
2486: if ($currusecredits) {
2487: $display = 'block';
2488: }
2489: my $additional = '<div id="credits" style="display: '.$display.'">'.
2490: '<span class="LC_nobreak">'.
2491: &mt('Default credits for official courses [_1]',
2492: '<input type="text" name="official_credits" value="'.
2493: $def_official_credits.'" size="3" />').
2494: '</span><br />'.
2495: '<span class="LC_nobreak">'.
2496: &mt('Default credits for unofficial courses [_1]',
2497: '<input type="text" name="unofficial_credits" value="'.
2498: $def_unofficial_credits.'" size="3" />').
2499: '</span></div>'."\n";
2500: %defaultchecked = ('coursecredits' => 'off');
2501: @toggles = ('coursecredits');
2502: my $current = {
2503: 'coursecredits' => $currusecredits,
2504: };
2505: (my $table,$itemcount) =
2506: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
2507: \%choices,$itemcount,$onclick,$additional);
2508: $datatable .= $table;
1.139 raeburn 2509: }
1.192 raeburn 2510: $$rowtotal += $itemcount;
1.121 raeburn 2511: return $datatable;
1.118 jms 2512: }
2513:
1.137 raeburn 2514: sub print_usersessions {
2515: my ($position,$dom,$settings,$rowtotal) = @_;
2516: my ($css_class,$datatable,%checked,%choices);
1.140 raeburn 2517: my (%by_ip,%by_location,@intdoms);
2518: &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
1.145 raeburn 2519:
2520: my @alldoms = &Apache::lonnet::all_domains();
1.152 raeburn 2521: my %serverhomes = %Apache::lonnet::serverhomeIDs;
1.149 raeburn 2522: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.152 raeburn 2523: my %altids = &id_for_thisdom(%servers);
1.145 raeburn 2524: my $itemcount = 1;
2525: if ($position eq 'top') {
1.152 raeburn 2526: if (keys(%serverhomes) > 1) {
1.145 raeburn 2527: my %spareid = ¤t_offloads_to($dom,$settings,\%servers);
1.152 raeburn 2528: $datatable .= &spares_row($dom,\%servers,\%spareid,\%serverhomes,\%altids,$rowtotal);
1.145 raeburn 2529: } else {
1.140 raeburn 2530: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.150 raeburn 2531: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one server.');
1.140 raeburn 2532: }
1.137 raeburn 2533: } else {
1.145 raeburn 2534: if (keys(%by_location) == 0) {
2535: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.150 raeburn 2536: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one institution.');
1.145 raeburn 2537: } else {
2538: my %lt = &usersession_titles();
2539: my $numinrow = 5;
2540: my $prefix;
2541: my @types;
2542: if ($position eq 'bottom') {
2543: $prefix = 'remote';
2544: @types = ('version','excludedomain','includedomain');
2545: } else {
2546: $prefix = 'hosted';
2547: @types = ('excludedomain','includedomain');
2548: }
2549: my (%current,%checkedon,%checkedoff);
2550: my @lcversions = &Apache::lonnet::all_loncaparevs();
2551: my @locations = sort(keys(%by_location));
2552: foreach my $type (@types) {
2553: $checkedon{$type} = '';
2554: $checkedoff{$type} = ' checked="checked"';
2555: }
2556: if (ref($settings) eq 'HASH') {
2557: if (ref($settings->{$prefix}) eq 'HASH') {
2558: foreach my $key (keys(%{$settings->{$prefix}})) {
2559: $current{$key} = $settings->{$prefix}{$key};
2560: if ($key eq 'version') {
2561: if ($current{$key} ne '') {
2562: $checkedon{$key} = ' checked="checked"';
2563: $checkedoff{$key} = '';
2564: }
2565: } elsif (ref($current{$key}) eq 'ARRAY') {
2566: $checkedon{$key} = ' checked="checked"';
2567: $checkedoff{$key} = '';
2568: }
1.137 raeburn 2569: }
2570: }
2571: }
1.145 raeburn 2572: foreach my $type (@types) {
2573: next if ($type ne 'version' && !@locations);
2574: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
2575: $datatable .= '<tr'.$css_class.'>
2576: <td><span class="LC_nobreak">'.$lt{$type}.'</span><br />
2577: <span class="LC_nobreak">
2578: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedoff{$type}.' value="0" />'.&mt('Not in use').'</label>
2579: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedon{$type}.' value="1" />'.&mt('In use').'</label></span></td><td>';
2580: if ($type eq 'version') {
2581: my $selector = '<select name="'.$prefix.'_version">';
2582: foreach my $version (@lcversions) {
2583: my $selected = '';
2584: if ($current{'version'} eq $version) {
2585: $selected = ' selected="selected"';
2586: }
2587: $selector .= ' <option value="'.$version.'"'.
2588: $selected.'>'.$version.'</option>';
2589: }
2590: $selector .= '</select> ';
2591: $datatable .= &mt('remote server must be version: [_1] or later',$selector);
2592: } else {
2593: $datatable.= '<div><input type="button" value="'.&mt('check all').'" '.
2594: 'onclick="javascript:checkAll(document.display.'.$prefix.'_'.$type.')"'.
2595: ' />'.(' 'x2).
2596: '<input type="button" value="'.&mt('uncheck all').'" '.
2597: 'onclick="javascript:uncheckAll(document.display.'.$prefix.'_'.$type.')" />'.
2598: "\n".
2599: '</div><div><table>';
2600: my $rem;
2601: for (my $i=0; $i<@locations; $i++) {
2602: my ($showloc,$value,$checkedtype);
2603: if (ref($by_location{$locations[$i]}) eq 'ARRAY') {
2604: my $ip = $by_location{$locations[$i]}->[0];
2605: if (ref($by_ip{$ip}) eq 'ARRAY') {
2606: $value = join(':',@{$by_ip{$ip}});
2607: $showloc = join(', ',@{$by_ip{$ip}});
2608: if (ref($current{$type}) eq 'ARRAY') {
2609: foreach my $loc (@{$by_ip{$ip}}) {
2610: if (grep(/^\Q$loc\E$/,@{$current{$type}})) {
2611: $checkedtype = ' checked="checked"';
2612: last;
2613: }
2614: }
1.138 raeburn 2615: }
2616: }
2617: }
1.145 raeburn 2618: $rem = $i%($numinrow);
2619: if ($rem == 0) {
2620: if ($i > 0) {
2621: $datatable .= '</tr>';
2622: }
2623: $datatable .= '<tr>';
2624: }
2625: $datatable .= '<td class="LC_left_item">'.
2626: '<span class="LC_nobreak"><label>'.
2627: '<input type="checkbox" name="'.$prefix.'_'.$type.
2628: '" value="'.$value.'"'.$checkedtype.' />'.$showloc.
2629: '</label></span></td>';
1.137 raeburn 2630: }
1.145 raeburn 2631: $rem = @locations%($numinrow);
2632: my $colsleft = $numinrow - $rem;
2633: if ($colsleft > 1 ) {
2634: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
2635: ' </td>';
2636: } elsif ($colsleft == 1) {
2637: $datatable .= '<td class="LC_left_item"> </td>';
1.137 raeburn 2638: }
1.145 raeburn 2639: $datatable .= '</tr></table>';
1.137 raeburn 2640: }
1.145 raeburn 2641: $datatable .= '</td></tr>';
2642: $itemcount ++;
1.137 raeburn 2643: }
2644: }
2645: }
2646: $$rowtotal += $itemcount;
2647: return $datatable;
2648: }
2649:
1.138 raeburn 2650: sub build_location_hashes {
2651: my ($intdoms,$by_ip,$by_location) = @_;
2652: return unless((ref($intdoms) eq 'ARRAY') && (ref($by_ip) eq 'HASH') &&
2653: (ref($by_location) eq 'HASH'));
2654: my %iphost = &Apache::lonnet::get_iphost();
2655: my $primary_id = &Apache::lonnet::domain($env{'request.role.domain'},'primary');
2656: my $primary_ip = &Apache::lonnet::get_host_ip($primary_id);
2657: if (ref($iphost{$primary_ip}) eq 'ARRAY') {
2658: foreach my $id (@{$iphost{$primary_ip}}) {
2659: my $intdom = &Apache::lonnet::internet_dom($id);
2660: unless(grep(/^\Q$intdom\E$/,@{$intdoms})) {
2661: push(@{$intdoms},$intdom);
2662: }
2663: }
2664: }
2665: foreach my $ip (keys(%iphost)) {
2666: if (ref($iphost{$ip}) eq 'ARRAY') {
2667: foreach my $id (@{$iphost{$ip}}) {
2668: my $location = &Apache::lonnet::internet_dom($id);
2669: if ($location) {
2670: next if (grep(/^\Q$location\E$/,@{$intdoms}));
2671: if (ref($by_ip->{$ip}) eq 'ARRAY') {
2672: unless(grep(/^\Q$location\E$/,@{$by_ip->{$ip}})) {
2673: push(@{$by_ip->{$ip}},$location);
2674: }
2675: } else {
2676: $by_ip->{$ip} = [$location];
2677: }
2678: }
2679: }
2680: }
2681: }
2682: foreach my $ip (sort(keys(%{$by_ip}))) {
2683: if (ref($by_ip->{$ip}) eq 'ARRAY') {
2684: @{$by_ip->{$ip}} = sort(@{$by_ip->{$ip}});
2685: my $first = $by_ip->{$ip}->[0];
2686: if (ref($by_location->{$first}) eq 'ARRAY') {
2687: unless (grep(/^\Q$ip\E$/,@{$by_location->{$first}})) {
2688: push(@{$by_location->{$first}},$ip);
2689: }
2690: } else {
2691: $by_location->{$first} = [$ip];
2692: }
2693: }
2694: }
2695: return;
2696: }
2697:
1.145 raeburn 2698: sub current_offloads_to {
2699: my ($dom,$settings,$servers) = @_;
2700: my (%spareid,%otherdomconfigs);
1.152 raeburn 2701: if (ref($servers) eq 'HASH') {
1.145 raeburn 2702: foreach my $lonhost (sort(keys(%{$servers}))) {
2703: my $gotspares;
1.152 raeburn 2704: if (ref($settings) eq 'HASH') {
2705: if (ref($settings->{'spares'}) eq 'HASH') {
2706: if (ref($settings->{'spares'}{$lonhost}) eq 'HASH') {
2707: $spareid{$lonhost}{'primary'} = $settings->{'spares'}{$lonhost}{'primary'};
2708: $spareid{$lonhost}{'default'} = $settings->{'spares'}{$lonhost}{'default'};
2709: $gotspares = 1;
2710: }
1.145 raeburn 2711: }
2712: }
2713: unless ($gotspares) {
2714: my $gotspares;
2715: my $serverhomeID =
2716: &Apache::lonnet::get_server_homeID($servers->{$lonhost});
2717: my $serverhomedom =
2718: &Apache::lonnet::host_domain($serverhomeID);
2719: if ($serverhomedom ne $dom) {
2720: if (ref($otherdomconfigs{$serverhomedom} eq 'HASH')) {
2721: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
2722: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
2723: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
2724: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
2725: $gotspares = 1;
2726: }
2727: }
2728: } else {
2729: $otherdomconfigs{$serverhomedom} =
2730: &Apache::lonnet::get_dom('configuration',['usersessions'],$serverhomedom);
2731: if (ref($otherdomconfigs{$serverhomedom}) eq 'HASH') {
2732: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
2733: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
2734: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{$lonhost}) eq 'HASH') {
2735: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
2736: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
2737: $gotspares = 1;
2738: }
2739: }
2740: }
2741: }
2742: }
2743: }
2744: }
2745: unless ($gotspares) {
2746: if ($lonhost eq $Apache::lonnet::perlvar{'lonHostID'}) {
2747: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
2748: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
2749: } else {
2750: my $server_hostname = &Apache::lonnet::hostname($lonhost);
2751: my $server_homeID = &Apache::lonnet::get_server_homeID($server_hostname);
2752: if ($server_homeID eq $Apache::lonnet::perlvar{'lonHostID'}) {
2753: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
2754: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
2755: } else {
1.150 raeburn 2756: my %what = (
2757: spareid => 1,
2758: );
2759: my ($result,$returnhash) =
2760: &Apache::lonnet::get_remote_globals($lonhost,\%what);
2761: if ($result eq 'ok') {
2762: if (ref($returnhash) eq 'HASH') {
2763: if (ref($returnhash->{'spareid'}) eq 'HASH') {
2764: $spareid{$lonhost}{'primary'} = $returnhash->{'spareid'}->{'primary'};
2765: $spareid{$lonhost}{'default'} = $returnhash->{'spareid'}->{'default'};
2766: }
2767: }
1.145 raeburn 2768: }
2769: }
2770: }
2771: }
2772: }
2773: }
2774: return %spareid;
2775: }
2776:
2777: sub spares_row {
1.152 raeburn 2778: my ($dom,$servers,$spareid,$serverhomes,$altids,$rowtotal) = @_;
1.145 raeburn 2779: my $css_class;
2780: my $numinrow = 4;
2781: my $itemcount = 1;
2782: my $datatable;
1.152 raeburn 2783: my %typetitles = &sparestype_titles();
2784: if ((ref($servers) eq 'HASH') && (ref($spareid) eq 'HASH') && (ref($altids) eq 'HASH')) {
1.145 raeburn 2785: foreach my $server (sort(keys(%{$servers}))) {
1.152 raeburn 2786: my $serverhome = &Apache::lonnet::get_server_homeID($servers->{$server});
2787: my ($othercontrol,$serverdom);
2788: if ($serverhome ne $server) {
2789: $serverdom = &Apache::lonnet::host_domain($serverhome);
2790: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
2791: } else {
2792: $serverdom = &Apache::lonnet::host_domain($server);
2793: if ($serverdom ne $dom) {
2794: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
2795: }
2796: }
2797: next unless (ref($spareid->{$server}) eq 'HASH');
1.145 raeburn 2798: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
2799: $datatable .= '<tr'.$css_class.'>
2800: <td rowspan="2">
1.183 bisitz 2801: <span class="LC_nobreak">'.
2802: &mt('[_1] when busy, offloads to:'
2803: ,'<b>'.$server.'</b>').
2804: "\n";
1.145 raeburn 2805: my (%current,%canselect);
1.152 raeburn 2806: my @choices =
2807: &possible_newspares($server,$spareid->{$server},$serverhomes,$altids);
2808: foreach my $type ('primary','default') {
2809: if (ref($spareid->{$server}) eq 'HASH') {
1.145 raeburn 2810: if (ref($spareid->{$server}{$type}) eq 'ARRAY') {
2811: my @spares = @{$spareid->{$server}{$type}};
2812: if (@spares > 0) {
1.152 raeburn 2813: if ($othercontrol) {
2814: $current{$type} = join(', ',@spares);
2815: } else {
2816: $current{$type} .= '<table>';
2817: my $numspares = scalar(@spares);
2818: for (my $i=0; $i<@spares; $i++) {
2819: my $rem = $i%($numinrow);
2820: if ($rem == 0) {
2821: if ($i > 0) {
2822: $current{$type} .= '</tr>';
2823: }
2824: $current{$type} .= '<tr>';
1.145 raeburn 2825: }
1.152 raeburn 2826: $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'".');" /> '.
2827: $spareid->{$server}{$type}[$i].
2828: '</label></td>'."\n";
2829: }
2830: my $rem = @spares%($numinrow);
2831: my $colsleft = $numinrow - $rem;
2832: if ($colsleft > 1 ) {
2833: $current{$type} .= '<td colspan="'.$colsleft.
2834: '" class="LC_left_item">'.
2835: ' </td>';
2836: } elsif ($colsleft == 1) {
2837: $current{$type} .= '<td class="LC_left_item"> </td>'."\n";
1.145 raeburn 2838: }
1.152 raeburn 2839: $current{$type} .= '</tr></table>';
1.150 raeburn 2840: }
1.145 raeburn 2841: }
2842: }
2843: if ($current{$type} eq '') {
2844: $current{$type} = &mt('None specified');
2845: }
1.152 raeburn 2846: if ($othercontrol) {
2847: if ($type eq 'primary') {
2848: $canselect{$type} = $othercontrol;
2849: }
2850: } else {
2851: $canselect{$type} =
2852: &mt('Add new [_1]'.$type.'[_2]:','<i>','</i>').' '.
2853: '<select name="newspare_'.$type.'_'.$server.'" '.
2854: 'id="newspare_'.$type.'_'.$server.'" onchange="checkNewSpares('."'$server','$type'".');">'."\n".
2855: '<option value="" selected ="selected">'.&mt('Select').'</option>'."\n";
2856: if (@choices > 0) {
2857: foreach my $lonhost (@choices) {
2858: $canselect{$type} .= '<option value="'.$lonhost.'">'.$lonhost.'</option>'."\n";
2859: }
2860: }
2861: $canselect{$type} .= '</select>'."\n";
2862: }
2863: } else {
2864: $current{$type} = &mt('Could not be determined');
2865: if ($type eq 'primary') {
2866: $canselect{$type} = $othercontrol;
2867: }
1.145 raeburn 2868: }
1.152 raeburn 2869: if ($type eq 'default') {
2870: $datatable .= '<tr'.$css_class.'>';
2871: }
2872: $datatable .= '<td><i>'.$typetitles{$type}.'</i></td>'."\n".
2873: '<td>'.$current{$type}.'</td>'."\n".
2874: '<td>'.$canselect{$type}.'</td></tr>'."\n";
1.145 raeburn 2875: }
2876: $itemcount ++;
2877: }
2878: }
2879: $$rowtotal += $itemcount;
2880: return $datatable;
2881: }
2882:
1.152 raeburn 2883: sub possible_newspares {
2884: my ($server,$currspares,$serverhomes,$altids) = @_;
2885: my $serverhostname = &Apache::lonnet::hostname($server);
2886: my %excluded;
2887: if ($serverhostname ne '') {
2888: %excluded = (
2889: $serverhostname => 1,
2890: );
2891: }
2892: if (ref($currspares) eq 'HASH') {
2893: foreach my $type (keys(%{$currspares})) {
2894: if (ref($currspares->{$type}) eq 'ARRAY') {
2895: if (@{$currspares->{$type}} > 0) {
2896: foreach my $curr (@{$currspares->{$type}}) {
2897: my $hostname = &Apache::lonnet::hostname($curr);
2898: $excluded{$hostname} = 1;
2899: }
2900: }
2901: }
2902: }
2903: }
2904: my @choices;
2905: if ((ref($serverhomes) eq 'HASH') && (ref($altids) eq 'HASH')) {
2906: if (keys(%{$serverhomes}) > 1) {
2907: foreach my $name (sort(keys(%{$serverhomes}))) {
2908: unless ($excluded{$name}) {
2909: if (exists($altids->{$serverhomes->{$name}})) {
2910: push(@choices,$altids->{$serverhomes->{$name}});
2911: } else {
2912: push(@choices,$serverhomes->{$name});
1.145 raeburn 2913: }
2914: }
2915: }
2916: }
2917: }
1.152 raeburn 2918: return sort(@choices);
1.145 raeburn 2919: }
2920:
1.150 raeburn 2921: sub print_loadbalancing {
2922: my ($dom,$settings,$rowtotal) = @_;
2923: my $primary_id = &Apache::lonnet::domain($dom,'primary');
2924: my $intdom = &Apache::lonnet::internet_dom($primary_id);
2925: my $numinrow = 1;
2926: my $datatable;
2927: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.171 raeburn 2928: my (%currbalancer,%currtargets,%currrules,%existing);
2929: if (ref($settings) eq 'HASH') {
2930: %existing = %{$settings};
2931: }
2932: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
2933: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
2934: \%currtargets,\%currrules);
1.150 raeburn 2935: } else {
2936: return;
2937: }
2938: my ($othertitle,$usertypes,$types) =
2939: &Apache::loncommon::sorted_inst_types($dom);
2940: my $rownum = 6;
2941: if (ref($types) eq 'ARRAY') {
2942: $rownum += scalar(@{$types});
2943: }
1.171 raeburn 2944: my @css_class = ('LC_odd_row','LC_even_row');
2945: my $balnum = 0;
2946: my $islast;
2947: my (@toshow,$disabledtext);
2948: if (keys(%currbalancer) > 0) {
2949: @toshow = sort(keys(%currbalancer));
2950: if (scalar(@toshow) < scalar(keys(%servers)) + 1) {
2951: push(@toshow,'');
2952: }
2953: } else {
2954: @toshow = ('');
2955: $disabledtext = &mt('No existing load balancer');
2956: }
2957: foreach my $lonhost (@toshow) {
2958: if ($balnum == scalar(@toshow)-1) {
2959: $islast = 1;
2960: } else {
2961: $islast = 0;
2962: }
2963: my $cssidx = $balnum%2;
2964: my $targets_div_style = 'display: none';
2965: my $disabled_div_style = 'display: block';
2966: my $homedom_div_style = 'display: none';
2967: $datatable .= '<tr class="'.$css_class[$cssidx].'">'.
2968: '<td rowspan="'.$rownum.'" valign="top">'.
2969: '<p>';
2970: if ($lonhost eq '') {
2971: $datatable .= '<span class="LC_nobreak">';
2972: if (keys(%currbalancer) > 0) {
2973: $datatable .= &mt('Add balancer:');
2974: } else {
2975: $datatable .= &mt('Enable balancer:');
2976: }
2977: $datatable .= ' '.
2978: '<select name="loadbalancing_lonhost_'.$balnum.'"'.
2979: ' id="loadbalancing_lonhost_'.$balnum.'"'.
2980: ' onchange="toggleTargets('."'$balnum'".');">'."\n".
2981: '<option value="" selected="selected">'.&mt('None').
2982: '</option>'."\n";
2983: foreach my $server (sort(keys(%servers))) {
2984: next if ($currbalancer{$server});
2985: $datatable .= '<option value="'.$server.'">'.$server.'</option>'."\n";
2986: }
2987: $datatable .=
2988: '</select>'."\n".
2989: '<input type="hidden" name="loadbalancing_prevlonhost_'.$balnum.'" id="loadbalancing_prevlonhost_'.$balnum.'" value="" /> </span>'."\n";
2990: } else {
2991: $datatable .= '<i>'.$lonhost.'</i><br /><span class="LC_nobreak">'.
2992: '<label><input type="checkbox" name="loadbalancing_delete" value="'.$balnum.'" id="loadbalancing_delete_'.$balnum.'" onclick="javascript:balancerDeleteChange('."'$balnum'".');" /> '.
2993: &mt('Stop balancing').'</label>'.
2994: '<input type="hidden" name="loadbalancing_lonhost_'.$balnum.'" value="'.$lonhost.'" id="loadbalancing_lonhost_'.$balnum.'" /></span>';
2995: $targets_div_style = 'display: block';
2996: $disabled_div_style = 'display: none';
2997: if ($dom eq &Apache::lonnet::host_domain($lonhost)) {
2998: $homedom_div_style = 'display: block';
2999: }
3000: }
3001: $datatable .= '</p></td><td rowspan="'.$rownum.'" valign="top">'.
3002: '<div id="loadbalancing_disabled_'.$balnum.'" style="'.
3003: $disabled_div_style.'">'.$disabledtext.'</div>'."\n".
3004: '<div id="loadbalancing_targets_'.$balnum.'" style="'.$targets_div_style.'">'.&mt('Offloads to:').'<br />';
3005: my ($numspares,@spares) = &count_servers($lonhost,%servers);
3006: my @sparestypes = ('primary','default');
3007: my %typetitles = &sparestype_titles();
3008: foreach my $sparetype (@sparestypes) {
3009: my $targettable;
3010: for (my $i=0; $i<$numspares; $i++) {
3011: my $checked;
3012: if (ref($currtargets{$lonhost}) eq 'HASH') {
3013: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
3014: if (grep(/^\Q$spares[$i]\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
3015: $checked = ' checked="checked"';
3016: }
3017: }
3018: }
3019: my ($chkboxval,$disabled);
3020: if (($lonhost ne '') && (exists($servers{$lonhost}))) {
3021: $chkboxval = $spares[$i];
3022: }
3023: if (exists($currbalancer{$spares[$i]})) {
3024: $disabled = ' disabled="disabled"';
3025: }
3026: $targettable .=
3027: '<td><label><input type="checkbox" name="loadbalancing_target_'.$balnum.'_'.$sparetype.'"'.
3028: $checked.$disabled.' value="'.$chkboxval.'" id="loadbalancing_target_'.$balnum.'_'.$sparetype.'_'.$i.'" onclick="checkOffloads('."this,'$balnum','$sparetype'".');" /><span id="loadbalancing_targettxt_'.$balnum.'_'.$sparetype.'_'.$i.'"> '.$chkboxval.
3029: '</span></label></td>';
3030: my $rem = $i%($numinrow);
3031: if ($rem == 0) {
3032: if (($i > 0) && ($i < $numspares-1)) {
3033: $targettable .= '</tr>';
3034: }
3035: if ($i < $numspares-1) {
3036: $targettable .= '<tr>';
1.150 raeburn 3037: }
3038: }
3039: }
1.171 raeburn 3040: if ($targettable ne '') {
3041: my $rem = $numspares%($numinrow);
3042: my $colsleft = $numinrow - $rem;
3043: if ($colsleft > 1 ) {
3044: $targettable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
3045: ' </td>';
3046: } elsif ($colsleft == 1) {
3047: $targettable .= '<td class="LC_left_item"> </td>';
3048: }
3049: $datatable .= '<i>'.$typetitles{$sparetype}.'</i><br />'.
3050: '<table><tr>'.$targettable.'</tr></table><br />';
3051: }
3052: }
3053: $datatable .= '</div></td></tr>'.
3054: &loadbalancing_rules($dom,$intdom,$currrules{$lonhost},
3055: $othertitle,$usertypes,$types,\%servers,
3056: \%currbalancer,$lonhost,
3057: $targets_div_style,$homedom_div_style,
3058: $css_class[$cssidx],$balnum,$islast);
3059: $$rowtotal += $rownum;
3060: $balnum ++;
3061: }
3062: $datatable .= '<input type="hidden" name="loadbalancing_total" id="loadbalancing_total" value="'.$balnum.'" />';
3063: return $datatable;
3064: }
3065:
3066: sub get_loadbalancers_config {
3067: my ($servers,$existing,$currbalancer,$currtargets,$currrules) = @_;
3068: return unless ((ref($servers) eq 'HASH') &&
3069: (ref($existing) eq 'HASH') && (ref($currbalancer) eq 'HASH') &&
3070: (ref($currtargets) eq 'HASH') && (ref($currrules) eq 'HASH'));
3071: if (keys(%{$existing}) > 0) {
3072: my $oldlonhost;
3073: foreach my $key (sort(keys(%{$existing}))) {
3074: if ($key eq 'lonhost') {
3075: $oldlonhost = $existing->{'lonhost'};
3076: $currbalancer->{$oldlonhost} = 1;
3077: } elsif ($key eq 'targets') {
3078: if ($oldlonhost) {
3079: $currtargets->{$oldlonhost} = $existing->{'targets'};
3080: }
3081: } elsif ($key eq 'rules') {
3082: if ($oldlonhost) {
3083: $currrules->{$oldlonhost} = $existing->{'rules'};
3084: }
3085: } elsif (ref($existing->{$key}) eq 'HASH') {
3086: $currbalancer->{$key} = 1;
3087: $currtargets->{$key} = $existing->{$key}{'targets'};
3088: $currrules->{$key} = $existing->{$key}{'rules'};
1.150 raeburn 3089: }
3090: }
1.171 raeburn 3091: } else {
3092: my ($balancerref,$targetsref) =
3093: &Apache::lonnet::get_lonbalancer_config($servers);
3094: if ((ref($balancerref) eq 'HASH') && (ref($targetsref) eq 'HASH')) {
3095: foreach my $server (sort(keys(%{$balancerref}))) {
3096: $currbalancer->{$server} = 1;
3097: $currtargets->{$server} = $targetsref->{$server};
1.150 raeburn 3098: }
3099: }
3100: }
1.171 raeburn 3101: return;
1.150 raeburn 3102: }
3103:
3104: sub loadbalancing_rules {
3105: my ($dom,$intdom,$currrules,$othertitle,$usertypes,$types,$servers,
1.171 raeburn 3106: $currbalancer,$lonhost,$targets_div_style,$homedom_div_style,
3107: $css_class,$balnum,$islast) = @_;
1.150 raeburn 3108: my $output;
1.171 raeburn 3109: my $num = 0;
1.150 raeburn 3110: my ($alltypes,$othertypes,$titles) =
3111: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
3112: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
3113: foreach my $type (@{$alltypes}) {
1.171 raeburn 3114: $num ++;
1.150 raeburn 3115: my $current;
3116: if (ref($currrules) eq 'HASH') {
3117: $current = $currrules->{$type};
3118: }
3119: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.171 raeburn 3120: if ($dom ne &Apache::lonnet::host_domain($lonhost)) {
1.150 raeburn 3121: $current = '';
3122: }
3123: }
3124: $output .= &loadbalance_rule_row($type,$titles->{$type},$current,
1.171 raeburn 3125: $servers,$currbalancer,$lonhost,$dom,
3126: $targets_div_style,$homedom_div_style,
3127: $css_class,$balnum,$num,$islast);
1.150 raeburn 3128: }
3129: }
3130: return $output;
3131: }
3132:
3133: sub loadbalancing_titles {
3134: my ($dom,$intdom,$usertypes,$types) = @_;
3135: my %othertypes = (
3136: '_LC_adv' => &mt('Advanced users from [_1]',$dom),
3137: '_LC_author' => &mt('Users from [_1] with author role',$dom),
3138: '_LC_internetdom' => &mt('Users not from [_1], but from [_2]',$dom,$intdom),
3139: '_LC_external' => &mt('Users not from [_1]',$intdom),
3140: );
3141: my @alltypes = ('_LC_adv','_LC_author','_LC_internetdom','_LC_external');
3142: if (ref($types) eq 'ARRAY') {
3143: unshift(@alltypes,@{$types},'default');
3144: }
3145: my %titles;
3146: foreach my $type (@alltypes) {
3147: if ($type =~ /^_LC_/) {
3148: $titles{$type} = $othertypes{$type};
3149: } elsif ($type eq 'default') {
3150: $titles{$type} = &mt('All users from [_1]',$dom);
3151: if (ref($types) eq 'ARRAY') {
3152: if (@{$types} > 0) {
3153: $titles{$type} = &mt('Other users from [_1]',$dom);
3154: }
3155: }
3156: } elsif (ref($usertypes) eq 'HASH') {
3157: $titles{$type} = $usertypes->{$type};
3158: }
3159: }
3160: return (\@alltypes,\%othertypes,\%titles);
3161: }
3162:
3163: sub loadbalance_rule_row {
1.171 raeburn 3164: my ($type,$title,$current,$servers,$currbalancer,$lonhost,$dom,
3165: $targets_div_style,$homedom_div_style,$css_class,$balnum,$num,$islast) = @_;
1.150 raeburn 3166: my @rulenames = ('default','homeserver');
3167: my %ruletitles = &offloadtype_text();
3168: if ($type eq '_LC_external') {
3169: push(@rulenames,'externalbalancer');
3170: } else {
3171: push(@rulenames,'specific');
3172: }
1.161 raeburn 3173: push(@rulenames,'none');
1.150 raeburn 3174: my $style = $targets_div_style;
3175: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
3176: $style = $homedom_div_style;
3177: }
1.171 raeburn 3178: my $space;
3179: if ($islast && $num == 1) {
3180: $space = '<div display="inline-block"> </div>';
3181: }
1.150 raeburn 3182: my $output =
1.171 raeburn 3183: '<tr class="'.$css_class.'" id="balanceruletr_'.$balnum.'_'.$num.'"><td valign="top">'.$space.
3184: '<div id="balanceruletitle_'.$balnum.'_'.$type.'" style="'.$style.'">'.$title.'</div></td>'."\n".
3185: '<td valaign="top">'.$space.
3186: '<div id="balancerule_'.$balnum.'_'.$type.'" style="'.$style.'">'."\n";
1.150 raeburn 3187: for (my $i=0; $i<@rulenames; $i++) {
3188: my $rule = $rulenames[$i];
3189: my ($checked,$extra);
3190: if ($rulenames[$i] eq 'default') {
3191: $rule = '';
3192: }
3193: if ($rulenames[$i] eq 'specific') {
3194: if (ref($servers) eq 'HASH') {
3195: my $default;
3196: if (($current ne '') && (exists($servers->{$current}))) {
3197: $checked = ' checked="checked"';
3198: }
3199: unless ($checked) {
3200: $default = ' selected="selected"';
3201: }
1.171 raeburn 3202: $extra =
3203: ': <select name="loadbalancing_singleserver_'.$balnum.'_'.$type.
3204: '" id="loadbalancing_singleserver_'.$balnum.'_'.$type.
3205: '" onchange="singleServerToggle('."'$balnum','$type'".')">'."\n".
3206: '<option value=""'.$default.'></option>'."\n";
3207: foreach my $server (sort(keys(%{$servers}))) {
3208: if (ref($currbalancer) eq 'HASH') {
3209: next if (exists($currbalancer->{$server}));
3210: }
1.150 raeburn 3211: my $selected;
1.171 raeburn 3212: if ($server eq $current) {
1.150 raeburn 3213: $selected = ' selected="selected"';
3214: }
1.171 raeburn 3215: $extra .= '<option value="'.$server.'"'.$selected.'>'.$server.'</option>';
1.150 raeburn 3216: }
3217: $extra .= '</select>';
3218: }
3219: } elsif ($rule eq $current) {
3220: $checked = ' checked="checked"';
3221: }
3222: $output .= '<span class="LC_nobreak"><label>'.
1.171 raeburn 3223: '<input type="radio" name="loadbalancing_rules_'.$balnum.'_'.$type.
3224: '" id="loadbalancing_rules_'.$balnum.'_'.$type.'_'.$i.'" value="'.
3225: $rule.'" onclick="balanceruleChange('."this.form,'$balnum','$type'".
1.150 raeburn 3226: ')"'.$checked.' /> '.$ruletitles{$rulenames[$i]}.
3227: '</label>'.$extra.'</span><br />'."\n";
3228: }
3229: $output .= '</div></td></tr>'."\n";
3230: return $output;
3231: }
3232:
3233: sub offloadtype_text {
3234: my %ruletitles = &Apache::lonlocal::texthash (
3235: 'default' => 'Offloads to default destinations',
3236: 'homeserver' => "Offloads to user's home server",
3237: 'externalbalancer' => "Offloads to Load Balancer in user's domain",
3238: 'specific' => 'Offloads to specific server',
1.161 raeburn 3239: 'none' => 'No offload',
1.150 raeburn 3240: );
3241: return %ruletitles;
3242: }
3243:
3244: sub sparestype_titles {
3245: my %typestitles = &Apache::lonlocal::texthash (
3246: 'primary' => 'primary',
3247: 'default' => 'default',
3248: );
3249: return %typestitles;
3250: }
3251:
1.28 raeburn 3252: sub contact_titles {
3253: my %titles = &Apache::lonlocal::texthash (
3254: 'supportemail' => 'Support E-mail address',
1.69 raeburn 3255: 'adminemail' => 'Default Server Admin E-mail address',
1.28 raeburn 3256: 'errormail' => 'Error reports to be e-mailed to',
3257: 'packagesmail' => 'Package update alerts to be e-mailed to',
1.89 raeburn 3258: 'helpdeskmail' => 'Helpdesk requests to be e-mailed to',
3259: 'lonstatusmail' => 'E-mail from nightly status check (warnings/errors)',
1.102 raeburn 3260: 'requestsmail' => 'E-mail from course requests requiring approval',
1.190 raeburn 3261: 'updatesmail' => 'E-mail from nightly check of LON-CAPA module integrity/updates',
1.28 raeburn 3262: );
3263: my %short_titles = &Apache::lonlocal::texthash (
3264: adminemail => 'Admin E-mail address',
3265: supportemail => 'Support E-mail',
3266: );
3267: return (\%titles,\%short_titles);
3268: }
3269:
1.72 raeburn 3270: sub tool_titles {
3271: my %titles = &Apache::lonlocal::texthash (
1.162 raeburn 3272: aboutme => 'Personal web page',
1.86 raeburn 3273: blog => 'Blog',
1.162 raeburn 3274: webdav => 'WebDAV',
1.86 raeburn 3275: portfolio => 'Portfolio',
1.88 bisitz 3276: official => 'Official courses (with institutional codes)',
3277: unofficial => 'Unofficial courses',
1.98 raeburn 3278: community => 'Communities',
1.86 raeburn 3279: );
1.72 raeburn 3280: return %titles;
3281: }
3282:
1.101 raeburn 3283: sub courserequest_titles {
3284: my %titles = &Apache::lonlocal::texthash (
3285: official => 'Official',
3286: unofficial => 'Unofficial',
3287: community => 'Communities',
3288: norequest => 'Not allowed',
1.104 raeburn 3289: approval => 'Approval by Dom. Coord.',
1.101 raeburn 3290: validate => 'With validation',
3291: autolimit => 'Numerical limit',
1.103 raeburn 3292: unlimited => '(blank for unlimited)',
1.101 raeburn 3293: );
3294: return %titles;
3295: }
3296:
1.163 raeburn 3297: sub authorrequest_titles {
3298: my %titles = &Apache::lonlocal::texthash (
3299: norequest => 'Not allowed',
3300: approval => 'Approval by Dom. Coord.',
3301: automatic => 'Automatic approval',
3302: );
3303: return %titles;
3304: }
3305:
1.101 raeburn 3306: sub courserequest_conditions {
3307: my %conditions = &Apache::lonlocal::texthash (
1.104 raeburn 3308: approval => '(Processing of request subject to approval by Domain Coordinator).',
1.193 bisitz 3309: validate => '(Processing of request subject to institutional validation).',
1.101 raeburn 3310: );
3311: return %conditions;
3312: }
3313:
3314:
1.27 raeburn 3315: sub print_usercreation {
1.30 raeburn 3316: my ($position,$dom,$settings,$rowtotal) = @_;
1.27 raeburn 3317: my $numinrow = 4;
1.28 raeburn 3318: my $datatable;
3319: if ($position eq 'top') {
1.30 raeburn 3320: $$rowtotal ++;
1.34 raeburn 3321: my $rowcount = 0;
1.32 raeburn 3322: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username');
1.28 raeburn 3323: if (ref($rules) eq 'HASH') {
3324: if (keys(%{$rules}) > 0) {
1.32 raeburn 3325: $datatable .= &user_formats_row('username',$settings,$rules,
3326: $ruleorder,$numinrow,$rowcount);
1.30 raeburn 3327: $$rowtotal ++;
1.32 raeburn 3328: $rowcount ++;
3329: }
3330: }
3331: my ($idrules,$idruleorder) = &Apache::lonnet::inst_userrules($dom,'id');
3332: if (ref($idrules) eq 'HASH') {
3333: if (keys(%{$idrules}) > 0) {
3334: $datatable .= &user_formats_row('id',$settings,$idrules,
3335: $idruleorder,$numinrow,$rowcount);
3336: $$rowtotal ++;
3337: $rowcount ++;
1.28 raeburn 3338: }
3339: }
1.43 raeburn 3340: my ($emailrules,$emailruleorder) =
3341: &Apache::lonnet::inst_userrules($dom,'email');
3342: if (ref($emailrules) eq 'HASH') {
3343: if (keys(%{$emailrules}) > 0) {
3344: $datatable .= &user_formats_row('email',$settings,$emailrules,
3345: $emailruleorder,$numinrow,$rowcount);
3346: $$rowtotal ++;
3347: $rowcount ++;
3348: }
3349: }
1.39 raeburn 3350: if ($rowcount == 0) {
3351: $datatable .= '<tr><td colspan="2">'.&mt('No format rules have been defined for usernames or IDs in this domain.').'</td></tr>';
3352: $$rowtotal ++;
3353: $rowcount ++;
3354: }
1.34 raeburn 3355: } elsif ($position eq 'middle') {
1.100 raeburn 3356: my @creators = ('author','course','requestcrs','selfcreate');
1.37 raeburn 3357: my ($rules,$ruleorder) =
3358: &Apache::lonnet::inst_userrules($dom,'username');
1.34 raeburn 3359: my %lt = &usercreation_types();
3360: my %checked;
1.50 raeburn 3361: my @selfcreate;
1.34 raeburn 3362: if (ref($settings) eq 'HASH') {
3363: if (ref($settings->{'cancreate'}) eq 'HASH') {
3364: foreach my $item (@creators) {
3365: $checked{$item} = $settings->{'cancreate'}{$item};
3366: }
1.50 raeburn 3367: if (ref($settings->{'cancreate'}{'selfcreate'}) eq 'ARRAY') {
3368: @selfcreate = @{$settings->{'cancreate'}{'selfcreate'}};
3369: } elsif ($settings->{'cancreate'}{'selfcreate'} ne '') {
3370: if ($settings->{'cancreate'}{'selfcreate'} eq 'any') {
3371: @selfcreate = ('email','login','sso');
3372: } elsif ($settings->{'cancreate'}{'selfcreate'} ne 'none') {
3373: @selfcreate = ($settings->{'cancreate'}{'selfcreate'});
3374: }
3375: }
1.34 raeburn 3376: } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {
3377: foreach my $item (@creators) {
3378: if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {
3379: $checked{$item} = 'none';
3380: }
3381: }
3382: }
3383: }
3384: my $rownum = 0;
3385: foreach my $item (@creators) {
3386: $rownum ++;
1.50 raeburn 3387: if ($item ne 'selfcreate') {
3388: if ($checked{$item} eq '') {
1.43 raeburn 3389: $checked{$item} = 'any';
3390: }
1.34 raeburn 3391: }
3392: my $css_class;
3393: if ($rownum%2) {
3394: $css_class = '';
3395: } else {
3396: $css_class = ' class="LC_odd_row" ';
3397: }
3398: $datatable .= '<tr'.$css_class.'>'.
3399: '<td><span class="LC_nobreak">'.$lt{$item}.
3400: '</span></td><td align="right">';
1.50 raeburn 3401: my @options;
1.45 raeburn 3402: if ($item eq 'selfcreate') {
1.43 raeburn 3403: push(@options,('email','login','sso'));
3404: } else {
1.50 raeburn 3405: @options = ('any');
1.43 raeburn 3406: if (ref($rules) eq 'HASH') {
3407: if (keys(%{$rules}) > 0) {
3408: push(@options,('official','unofficial'));
3409: }
1.37 raeburn 3410: }
1.50 raeburn 3411: push(@options,'none');
1.37 raeburn 3412: }
3413: foreach my $option (@options) {
1.50 raeburn 3414: my $type = 'radio';
1.34 raeburn 3415: my $check = ' ';
1.50 raeburn 3416: if ($item eq 'selfcreate') {
3417: $type = 'checkbox';
3418: if (grep(/^\Q$option\E$/,@selfcreate)) {
3419: $check = ' checked="checked" ';
3420: }
3421: } else {
3422: if ($checked{$item} eq $option) {
3423: $check = ' checked="checked" ';
3424: }
1.34 raeburn 3425: }
3426: $datatable .= '<span class="LC_nobreak"><label>'.
1.50 raeburn 3427: '<input type="'.$type.'" name="can_createuser_'.
1.34 raeburn 3428: $item.'" value="'.$option.'"'.$check.'/> '.
3429: $lt{$option}.'</label> </span>';
3430: }
3431: $datatable .= '</td></tr>';
3432: }
1.93 raeburn 3433: my ($othertitle,$usertypes,$types) =
3434: &Apache::loncommon::sorted_inst_types($dom);
1.165 raeburn 3435: my $createsettings;
3436: if (ref($settings) eq 'HASH') {
3437: $createsettings = $settings->{cancreate};
3438: }
1.93 raeburn 3439: if (ref($usertypes) eq 'HASH') {
3440: if (keys(%{$usertypes}) > 0) {
1.99 raeburn 3441: $datatable .= &insttypes_row($createsettings,$types,$usertypes,
1.93 raeburn 3442: $dom,$numinrow,$othertitle,
3443: 'statustocreate');
3444: $$rowtotal ++;
1.169 raeburn 3445: $rownum ++;
1.93 raeburn 3446: }
3447: }
1.169 raeburn 3448: $datatable .= &captcha_choice('cancreate',$createsettings,$rownum);
1.28 raeburn 3449: } else {
3450: my @contexts = ('author','course','domain');
3451: my @authtypes = ('int','krb4','krb5','loc');
3452: my %checked;
3453: if (ref($settings) eq 'HASH') {
3454: if (ref($settings->{'authtypes'}) eq 'HASH') {
3455: foreach my $item (@contexts) {
3456: if (ref($settings->{'authtypes'}{$item}) eq 'HASH') {
3457: foreach my $auth (@authtypes) {
3458: if ($settings->{'authtypes'}{$item}{$auth}) {
3459: $checked{$item}{$auth} = ' checked="checked" ';
3460: }
3461: }
3462: }
3463: }
1.27 raeburn 3464: }
1.35 raeburn 3465: } else {
3466: foreach my $item (@contexts) {
1.36 raeburn 3467: foreach my $auth (@authtypes) {
1.35 raeburn 3468: $checked{$item}{$auth} = ' checked="checked" ';
3469: }
3470: }
1.27 raeburn 3471: }
1.28 raeburn 3472: my %title = &context_names();
3473: my %authname = &authtype_names();
3474: my $rownum = 0;
3475: my $css_class;
3476: foreach my $item (@contexts) {
3477: if ($rownum%2) {
3478: $css_class = '';
3479: } else {
3480: $css_class = ' class="LC_odd_row" ';
3481: }
1.30 raeburn 3482: $datatable .= '<tr'.$css_class.'>'.
1.28 raeburn 3483: '<td>'.$title{$item}.
3484: '</td><td class="LC_left_item">'.
3485: '<span class="LC_nobreak">';
3486: foreach my $auth (@authtypes) {
3487: $datatable .= '<label>'.
3488: '<input type="checkbox" name="'.$item.'_auth" '.
3489: $checked{$item}{$auth}.' value="'.$auth.'" />'.
3490: $authname{$auth}.'</label> ';
3491: }
3492: $datatable .= '</span></td></tr>';
3493: $rownum ++;
1.27 raeburn 3494: }
1.30 raeburn 3495: $$rowtotal += $rownum;
1.27 raeburn 3496: }
3497: return $datatable;
3498: }
3499:
1.165 raeburn 3500: sub captcha_choice {
1.169 raeburn 3501: my ($context,$settings,$itemcount) = @_;
1.165 raeburn 3502: my ($keyentry,$currpub,$currpriv,%checked,$rowname,$pubtext,$privtext);
3503: my %lt = &captcha_phrases();
3504: $keyentry = 'hidden';
3505: if ($context eq 'cancreate') {
3506: $rowname = &mt('CAPTCHA validation (e-mail as username)');
1.169 raeburn 3507: } elsif ($context eq 'login') {
3508: $rowname = &mt('"Contact helpdesk" CAPTCHA validation');
1.165 raeburn 3509: }
3510: if (ref($settings) eq 'HASH') {
3511: if ($settings->{'captcha'}) {
3512: $checked{$settings->{'captcha'}} = ' checked="checked"';
3513: } else {
3514: $checked{'original'} = ' checked="checked"';
3515: }
3516: if ($settings->{'captcha'} eq 'recaptcha') {
3517: $pubtext = $lt{'pub'};
3518: $privtext = $lt{'priv'};
3519: $keyentry = 'text';
3520: }
3521: if (ref($settings->{'recaptchakeys'}) eq 'HASH') {
3522: $currpub = $settings->{'recaptchakeys'}{'public'};
3523: $currpriv = $settings->{'recaptchakeys'}{'private'};
3524: }
3525: } else {
3526: $checked{'original'} = ' checked="checked"';
3527: }
1.169 raeburn 3528: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
3529: my $output = '<tr'.$css_class.'>'.
3530: '<td class="LC_left_item">'.$rowname.'</td><td class="LC_left_item" colspan="2">'."\n".
1.165 raeburn 3531: '<table><tr><td>'."\n";
3532: foreach my $option ('original','recaptcha','notused') {
3533: $output .= '<span class="LC_nobreak"><label><input type="radio" name="'.$context.'_captcha" value="'.
3534: $option.'" '.$checked{$option}.' onchange="javascript:updateCaptcha('."this,'$context'".');" />'.
3535: $lt{$option}.'</label></span>';
3536: unless ($option eq 'notused') {
3537: $output .= (' 'x2)."\n";
3538: }
3539: }
3540: #
3541: # Note: If reCAPTCHA is to be used for LON-CAPA servers in a domain, a domain coordinator should visit:
3542: # https://www.google.com/recaptcha and generate a Public and Private key. For domains with multiple
3543: # servers a single key pair will be used for all servers, so the internet domain (e.g., yourcollege.edu)
3544: # specified for use with the key should be broad enough to accommodate all servers in the LON-CAPA domain.
3545: #
3546: $output .= '</td></tr>'."\n".
3547: '<tr><td>'."\n".
3548: '<span class="LC_nobreak"><span id="'.$context.'_recaptchapubtxt">'.$pubtext.'</span> '."\n".
3549: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapub" name="'.$context.'_recaptchapub" value="'.
3550: $currpub.'" size="40" /></span><br />'."\n".
3551: '<span class="LC_nobreak"><span id="'.$context.'_recaptchaprivtxt">'.$privtext.'</span> '."\n".
3552: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapriv" name="'.$context.'_recaptchapriv" value="'.
3553: $currpriv.'" size="40" /></span></td></tr></table>'."\n".
3554: '</td></tr>';
3555: return $output;
3556: }
3557:
1.32 raeburn 3558: sub user_formats_row {
3559: my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount) = @_;
3560: my $output;
3561: my %text = (
3562: 'username' => 'new usernames',
3563: 'id' => 'IDs',
1.45 raeburn 3564: 'email' => 'self-created accounts (e-mail)',
1.32 raeburn 3565: );
3566: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
3567: $output = '<tr '.$css_class.'>'.
1.63 raeburn 3568: '<td><span class="LC_nobreak">';
3569: if ($type eq 'email') {
3570: $output .= &mt("Formats disallowed for $text{$type}: ");
3571: } else {
3572: $output .= &mt("Format rules to check for $text{$type}: ");
3573: }
3574: $output .= '</span></td>'.
3575: '<td class="LC_left_item" colspan="2"><table>';
1.27 raeburn 3576: my $rem;
3577: if (ref($ruleorder) eq 'ARRAY') {
3578: for (my $i=0; $i<@{$ruleorder}; $i++) {
3579: if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
3580: my $rem = $i%($numinrow);
3581: if ($rem == 0) {
3582: if ($i > 0) {
3583: $output .= '</tr>';
3584: }
3585: $output .= '<tr>';
3586: }
3587: my $check = ' ';
1.39 raeburn 3588: if (ref($settings) eq 'HASH') {
3589: if (ref($settings->{$type.'_rule'}) eq 'ARRAY') {
3590: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) {
3591: $check = ' checked="checked" ';
3592: }
1.27 raeburn 3593: }
3594: }
3595: $output .= '<td class="LC_left_item">'.
3596: '<span class="LC_nobreak"><label>'.
1.32 raeburn 3597: '<input type="checkbox" name="'.$type.'_rule" '.
1.27 raeburn 3598: 'value="'.$ruleorder->[$i].'"'.$check.'/>'.
3599: $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
3600: }
3601: }
3602: $rem = @{$ruleorder}%($numinrow);
3603: }
3604: my $colsleft = $numinrow - $rem;
3605: if ($colsleft > 1 ) {
3606: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
3607: ' </td>';
3608: } elsif ($colsleft == 1) {
3609: $output .= '<td class="LC_left_item"> </td>';
3610: }
3611: $output .= '</tr></table></td></tr>';
3612: return $output;
3613: }
3614:
1.34 raeburn 3615: sub usercreation_types {
3616: my %lt = &Apache::lonlocal::texthash (
3617: author => 'When adding a co-author',
3618: course => 'When adding a user to a course',
1.100 raeburn 3619: requestcrs => 'When requesting a course',
1.45 raeburn 3620: selfcreate => 'User creates own account',
1.34 raeburn 3621: any => 'Any',
3622: official => 'Institutional only ',
3623: unofficial => 'Non-institutional only',
1.85 schafran 3624: email => 'E-mail address',
1.43 raeburn 3625: login => 'Institutional Login',
3626: sso => 'SSO',
1.34 raeburn 3627: none => 'None',
3628: );
3629: return %lt;
1.48 raeburn 3630: }
1.34 raeburn 3631:
1.28 raeburn 3632: sub authtype_names {
3633: my %lt = &Apache::lonlocal::texthash(
3634: int => 'Internal',
3635: krb4 => 'Kerberos 4',
3636: krb5 => 'Kerberos 5',
3637: loc => 'Local',
3638: );
3639: return %lt;
3640: }
3641:
3642: sub context_names {
3643: my %context_title = &Apache::lonlocal::texthash(
3644: author => 'Creating users when an Author',
3645: course => 'Creating users when in a course',
3646: domain => 'Creating users when a Domain Coordinator',
3647: );
3648: return %context_title;
3649: }
3650:
1.33 raeburn 3651: sub print_usermodification {
3652: my ($position,$dom,$settings,$rowtotal) = @_;
3653: my $numinrow = 4;
3654: my ($context,$datatable,$rowcount);
3655: if ($position eq 'top') {
3656: $rowcount = 0;
3657: $context = 'author';
3658: foreach my $role ('ca','aa') {
3659: $datatable .= &modifiable_userdata_row($context,$role,$settings,
3660: $numinrow,$rowcount);
3661: $$rowtotal ++;
3662: $rowcount ++;
3663: }
1.63 raeburn 3664: } elsif ($position eq 'middle') {
1.33 raeburn 3665: $context = 'course';
3666: $rowcount = 0;
3667: foreach my $role ('st','ep','ta','in','cr') {
3668: $datatable .= &modifiable_userdata_row($context,$role,$settings,
3669: $numinrow,$rowcount);
3670: $$rowtotal ++;
3671: $rowcount ++;
3672: }
1.63 raeburn 3673: } elsif ($position eq 'bottom') {
3674: $context = 'selfcreate';
3675: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
3676: $usertypes->{'default'} = $othertitle;
3677: if (ref($types) eq 'ARRAY') {
3678: push(@{$types},'default');
3679: $usertypes->{'default'} = $othertitle;
3680: foreach my $status (@{$types}) {
3681: $datatable .= &modifiable_userdata_row($context,$status,$settings,
3682: $numinrow,$rowcount,$usertypes);
3683: $$rowtotal ++;
3684: $rowcount ++;
3685: }
3686: }
1.33 raeburn 3687: }
3688: return $datatable;
3689: }
3690:
1.43 raeburn 3691: sub print_defaults {
3692: my ($dom,$rowtotal) = @_;
1.68 raeburn 3693: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def',
1.141 raeburn 3694: 'datelocale_def','portal_def');
1.43 raeburn 3695: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.141 raeburn 3696: my $titles = &defaults_titles($dom);
1.43 raeburn 3697: my $rownum = 0;
3698: my ($datatable,$css_class);
3699: foreach my $item (@items) {
3700: if ($rownum%2) {
3701: $css_class = '';
3702: } else {
3703: $css_class = ' class="LC_odd_row" ';
3704: }
3705: $datatable .= '<tr'.$css_class.'>'.
3706: '<td><span class="LC_nobreak">'.$titles->{$item}.
3707: '</span></td><td class="LC_right_item">';
3708: if ($item eq 'auth_def') {
3709: my @authtypes = ('internal','krb4','krb5','localauth');
3710: my %shortauth = (
3711: internal => 'int',
3712: krb4 => 'krb4',
3713: krb5 => 'krb5',
3714: localauth => 'loc'
3715: );
3716: my %authnames = &authtype_names();
3717: foreach my $auth (@authtypes) {
3718: my $checked = ' ';
3719: if ($domdefaults{$item} eq $auth) {
3720: $checked = ' checked="checked" ';
3721: }
3722: $datatable .= '<label><input type="radio" name="'.$item.
3723: '" value="'.$auth.'"'.$checked.'/>'.
3724: $authnames{$shortauth{$auth}}.'</label> ';
3725: }
1.54 raeburn 3726: } elsif ($item eq 'timezone_def') {
3727: my $includeempty = 1;
3728: $datatable .= &Apache::loncommon::select_timezone($item,$domdefaults{$item},undef,$includeempty);
1.68 raeburn 3729: } elsif ($item eq 'datelocale_def') {
3730: my $includeempty = 1;
3731: $datatable .= &Apache::loncommon::select_datelocale($item,$domdefaults{$item},undef,$includeempty);
1.167 raeburn 3732: } elsif ($item eq 'lang_def') {
1.168 raeburn 3733: my %langchoices = &get_languages_hash();
3734: $langchoices{''} = 'No language preference';
1.167 raeburn 3735: %langchoices = &Apache::lonlocal::texthash(%langchoices);
3736: $datatable .= &Apache::loncommon::select_form($domdefaults{$item},$item,
3737: \%langchoices);
1.43 raeburn 3738: } else {
1.141 raeburn 3739: my $size;
3740: if ($item eq 'portal_def') {
3741: $size = ' size="25"';
3742: }
1.43 raeburn 3743: $datatable .= '<input type="text" name="'.$item.'" value="'.
1.141 raeburn 3744: $domdefaults{$item}.'"'.$size.' />';
1.43 raeburn 3745: }
3746: $datatable .= '</td></tr>';
3747: $rownum ++;
3748: }
3749: $$rowtotal += $rownum;
3750: return $datatable;
3751: }
3752:
1.168 raeburn 3753: sub get_languages_hash {
3754: my %langchoices;
3755: foreach my $id (&Apache::loncommon::languageids()) {
3756: my $code = &Apache::loncommon::supportedlanguagecode($id);
3757: if ($code ne '') {
3758: $langchoices{$code} = &Apache::loncommon::plainlanguagedescription($id);
3759: }
3760: }
3761: return %langchoices;
3762: }
3763:
1.43 raeburn 3764: sub defaults_titles {
1.141 raeburn 3765: my ($dom) = @_;
1.43 raeburn 3766: my %titles = &Apache::lonlocal::texthash (
3767: 'auth_def' => 'Default authentication type',
3768: 'auth_arg_def' => 'Default authentication argument',
3769: 'lang_def' => 'Default language',
1.54 raeburn 3770: 'timezone_def' => 'Default timezone',
1.68 raeburn 3771: 'datelocale_def' => 'Default locale for dates',
1.141 raeburn 3772: 'portal_def' => 'Portal/Default URL',
1.43 raeburn 3773: );
1.141 raeburn 3774: if ($dom) {
3775: my $uprimary_id = &Apache::lonnet::domain($dom,'primary');
3776: my $uint_dom = &Apache::lonnet::internet_dom($uprimary_id);
3777: my $protocol = $Apache::lonnet::protocol{$uprimary_id};
3778: $protocol = 'http' if ($protocol ne 'https');
3779: if ($uint_dom) {
3780: $titles{'portal_def'} .= ' '.&mt('(for example: [_1])',$protocol.'://loncapa.'.
3781: $uint_dom);
3782: }
3783: }
1.43 raeburn 3784: return (\%titles);
3785: }
3786:
1.46 raeburn 3787: sub print_scantronformat {
3788: my ($r,$dom,$confname,$settings,$rowtotal) = @_;
3789: my $itemcount = 1;
1.60 raeburn 3790: my ($datatable,$css_class,$scantronurl,$is_custom,%error,%scantronurls,
3791: %confhash);
1.46 raeburn 3792: my $switchserver = &check_switchserver($dom,$confname);
3793: my %lt = &Apache::lonlocal::texthash (
1.95 www 3794: default => 'Default bubblesheet format file error',
3795: custom => 'Custom bubblesheet format file error',
1.46 raeburn 3796: );
3797: my %scantronfiles = (
3798: default => 'default.tab',
3799: custom => 'custom.tab',
3800: );
3801: foreach my $key (keys(%scantronfiles)) {
3802: $scantronurls{$key} = '/res/'.$dom.'/'.$confname.'/scantron/'
3803: .$scantronfiles{$key};
3804: }
3805: my @defaultinfo = &Apache::lonnet::stat_file($scantronurls{'default'});
3806: if ((!@defaultinfo) || ($defaultinfo[0] eq 'no_such_dir')) {
3807: if (!$switchserver) {
3808: my $servadm = $r->dir_config('lonAdmEMail');
3809: my ($configuserok,$author_ok) = &config_check($dom,$confname,$servadm);
3810: if ($configuserok eq 'ok') {
3811: if ($author_ok eq 'ok') {
3812: my %legacyfile = (
3813: default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab',
3814: custom => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab',
3815: );
3816: my %md5chk;
3817: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 3818: ($md5chk{$type}) = split(/ /,`md5sum $legacyfile{$type}`);
3819: chomp($md5chk{$type});
1.46 raeburn 3820: }
3821: if ($md5chk{'default'} ne $md5chk{'custom'}) {
3822: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 3823: ($scantronurls{$type},my $error) =
1.46 raeburn 3824: &legacy_scantronformat($r,$dom,$confname,
3825: $type,$legacyfile{$type},
3826: $scantronurls{$type},
3827: $scantronfiles{$type});
1.60 raeburn 3828: if ($error ne '') {
3829: $error{$type} = $error;
3830: }
3831: }
3832: if (keys(%error) == 0) {
3833: $is_custom = 1;
3834: $confhash{'scantron'}{'scantronformat'} =
3835: $scantronurls{'custom'};
3836: my $putresult =
3837: &Apache::lonnet::put_dom('configuration',
3838: \%confhash,$dom);
3839: if ($putresult ne 'ok') {
3840: $error{'custom'} =
3841: '<span class="LC_error">'.
3842: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
3843: }
1.46 raeburn 3844: }
3845: } else {
1.60 raeburn 3846: ($scantronurls{'default'},my $error) =
1.46 raeburn 3847: &legacy_scantronformat($r,$dom,$confname,
3848: 'default',$legacyfile{'default'},
3849: $scantronurls{'default'},
3850: $scantronfiles{'default'});
1.60 raeburn 3851: if ($error eq '') {
3852: $confhash{'scantron'}{'scantronformat'} = '';
3853: my $putresult =
3854: &Apache::lonnet::put_dom('configuration',
3855: \%confhash,$dom);
3856: if ($putresult ne 'ok') {
3857: $error{'default'} =
3858: '<span class="LC_error">'.
3859: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
3860: }
3861: } else {
3862: $error{'default'} = $error;
3863: }
1.46 raeburn 3864: }
3865: }
3866: }
3867: } else {
1.95 www 3868: $error{'default'} = &mt("Unable to copy default bubblesheet formatfile to domain's RES space: [_1]",$switchserver);
1.46 raeburn 3869: }
3870: }
3871: if (ref($settings) eq 'HASH') {
3872: if ($settings->{'scantronformat'} eq "/res/$dom/$confname/scantron/custom.tab") {
3873: my @info = &Apache::lonnet::stat_file($settings->{'scantronformat'});
3874: if ((!@info) || ($info[0] eq 'no_such_dir')) {
3875: $scantronurl = '';
3876: } else {
3877: $scantronurl = $settings->{'scantronformat'};
3878: }
3879: $is_custom = 1;
3880: } else {
3881: $scantronurl = $scantronurls{'default'};
3882: }
3883: } else {
1.60 raeburn 3884: if ($is_custom) {
3885: $scantronurl = $scantronurls{'custom'};
3886: } else {
3887: $scantronurl = $scantronurls{'default'};
3888: }
1.46 raeburn 3889: }
3890: $css_class = $itemcount%2?' class="LC_odd_row"':'';
3891: $datatable .= '<tr'.$css_class.'>';
3892: if (!$is_custom) {
1.65 raeburn 3893: $datatable .= '<td>'.&mt('Default in use:').'<br />'.
3894: '<span class="LC_nobreak">';
1.46 raeburn 3895: if ($scantronurl) {
3896: $datatable .= '<a href="'.$scantronurl.'" target="_blank">'.
1.130 raeburn 3897: &mt('Default bubblesheet format file').'</a>';
1.46 raeburn 3898: } else {
3899: $datatable = &mt('File unavailable for display');
3900: }
1.65 raeburn 3901: $datatable .= '</span></td>';
1.60 raeburn 3902: if (keys(%error) == 0) {
3903: $datatable .= '<td valign="bottom">';
3904: if (!$switchserver) {
3905: $datatable .= &mt('Upload:').'<br />';
3906: }
3907: } else {
3908: my $errorstr;
3909: foreach my $key (sort(keys(%error))) {
3910: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
3911: }
3912: $datatable .= '<td>'.$errorstr;
3913: }
1.46 raeburn 3914: } else {
3915: if (keys(%error) > 0) {
3916: my $errorstr;
3917: foreach my $key (sort(keys(%error))) {
3918: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
3919: }
1.60 raeburn 3920: $datatable .= '<td>'.$errorstr.'</td><td> ';
1.46 raeburn 3921: } elsif ($scantronurl) {
1.65 raeburn 3922: $datatable .= '<td><span class="LC_nobreak">'.
3923: '<a href="'.$scantronurl.'" target="_blank">'.
1.130 raeburn 3924: &mt('Custom bubblesheet format file').'</a><label>'.
1.65 raeburn 3925: '<input type="checkbox" name="scantronformat_del"'.
3926: '" value="1" />'.&mt('Delete?').'</label></span></td>'.
3927: '<td><span class="LC_nobreak"> '.
3928: &mt('Replace:').'</span><br />';
1.46 raeburn 3929: }
3930: }
3931: if (keys(%error) == 0) {
3932: if ($switchserver) {
3933: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
3934: } else {
1.65 raeburn 3935: $datatable .='<span class="LC_nobreak"> '.
3936: '<input type="file" name="scantronformat" /></span>';
1.46 raeburn 3937: }
3938: }
3939: $datatable .= '</td></tr>';
3940: $$rowtotal ++;
3941: return $datatable;
3942: }
3943:
3944: sub legacy_scantronformat {
3945: my ($r,$dom,$confname,$file,$legacyfile,$newurl,$newfile) = @_;
3946: my ($url,$error);
3947: my @statinfo = &Apache::lonnet::stat_file($newurl);
3948: if ((!@statinfo) || ($statinfo[0] eq 'no_such_dir')) {
3949: (my $result,$url) =
3950: &publishlogo($r,'copy',$legacyfile,$dom,$confname,'scantron',
3951: '','',$newfile);
3952: if ($result ne 'ok') {
1.130 raeburn 3953: $error = &mt("An error occurred publishing the [_1] bubblesheet format file in RES space. Error was: [_2].",$newfile,$result);
1.46 raeburn 3954: }
3955: }
3956: return ($url,$error);
3957: }
1.43 raeburn 3958:
1.49 raeburn 3959: sub print_coursecategories {
1.57 raeburn 3960: my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;
3961: my $datatable;
3962: if ($position eq 'top') {
3963: my $toggle_cats_crs = ' ';
3964: my $toggle_cats_dom = ' checked="checked" ';
3965: my $can_cat_crs = ' ';
3966: my $can_cat_dom = ' checked="checked" ';
1.120 raeburn 3967: my $toggle_catscomm_comm = ' ';
3968: my $toggle_catscomm_dom = ' checked="checked" ';
3969: my $can_catcomm_comm = ' ';
3970: my $can_catcomm_dom = ' checked="checked" ';
3971:
1.57 raeburn 3972: if (ref($settings) eq 'HASH') {
3973: if ($settings->{'togglecats'} eq 'crs') {
3974: $toggle_cats_crs = $toggle_cats_dom;
3975: $toggle_cats_dom = ' ';
3976: }
3977: if ($settings->{'categorize'} eq 'crs') {
3978: $can_cat_crs = $can_cat_dom;
3979: $can_cat_dom = ' ';
3980: }
1.120 raeburn 3981: if ($settings->{'togglecatscomm'} eq 'comm') {
3982: $toggle_catscomm_comm = $toggle_catscomm_dom;
3983: $toggle_catscomm_dom = ' ';
3984: }
3985: if ($settings->{'categorizecomm'} eq 'comm') {
3986: $can_catcomm_comm = $can_catcomm_dom;
3987: $can_catcomm_dom = ' ';
3988: }
1.57 raeburn 3989: }
3990: my %title = &Apache::lonlocal::texthash (
1.120 raeburn 3991: togglecats => 'Show/Hide a course in catalog',
3992: togglecatscomm => 'Show/Hide a community in catalog',
3993: categorize => 'Assign a category to a course',
3994: categorizecomm => 'Assign a category to a community',
1.57 raeburn 3995: );
3996: my %level = &Apache::lonlocal::texthash (
1.120 raeburn 3997: dom => 'Set in Domain',
3998: crs => 'Set in Course',
3999: comm => 'Set in Community',
1.57 raeburn 4000: );
4001: $datatable = '<tr class="LC_odd_row">'.
4002: '<td>'.$title{'togglecats'}.'</td>'.
4003: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4004: '<input type="radio" name="togglecats"'.
4005: $toggle_cats_dom.' value="dom" />'.$level{'dom'}.'</label> '.
4006: '<label><input type="radio" name="togglecats"'.
4007: $toggle_cats_crs.' value="crs" />'.$level{'crs'}.'</label></span></td>'.
4008: '</tr><tr>'.
4009: '<td>'.$title{'categorize'}.'</td>'.
4010: '<td class="LC_right_item"><span class="LC_nobreak">'.
4011: '<label><input type="radio" name="categorize"'.
4012: $can_cat_dom.' value="dom" />'.$level{'dom'}.'</label> '.
4013: '<label><input type="radio" name="categorize"'.
4014: $can_cat_crs.'value="crs" />'.$level{'crs'}.'</label></span></td>'.
1.120 raeburn 4015: '</tr><tr class="LC_odd_row">'.
4016: '<td>'.$title{'togglecatscomm'}.'</td>'.
4017: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4018: '<input type="radio" name="togglecatscomm"'.
4019: $toggle_catscomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
4020: '<label><input type="radio" name="togglecatscomm"'.
4021: $toggle_catscomm_comm.' value="comm" />'.$level{'comm'}.'</label></span></td>'.
4022: '</tr><tr>'.
4023: '<td>'.$title{'categorizecomm'}.'</td>'.
4024: '<td class="LC_right_item"><span class="LC_nobreak">'.
4025: '<label><input type="radio" name="categorizecomm"'.
4026: $can_catcomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
4027: '<label><input type="radio" name="categorizecomm"'.
4028: $can_catcomm_comm.'value="comm" />'.$level{'comm'}.'</label></span></td>'.
1.57 raeburn 4029: '</tr>';
1.120 raeburn 4030: $$rowtotal += 4;
1.57 raeburn 4031: } else {
4032: my $css_class;
4033: my $itemcount = 1;
4034: my $cathash;
4035: if (ref($settings) eq 'HASH') {
4036: $cathash = $settings->{'cats'};
4037: }
4038: if (ref($cathash) eq 'HASH') {
4039: my (@cats,@trails,%allitems,%idx,@jsarray);
4040: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
4041: \%allitems,\%idx,\@jsarray);
4042: my $maxdepth = scalar(@cats);
4043: my $colattrib = '';
4044: if ($maxdepth > 2) {
4045: $colattrib = ' colspan="2" ';
4046: }
4047: my @path;
4048: if (@cats > 0) {
4049: if (ref($cats[0]) eq 'ARRAY') {
4050: my $numtop = @{$cats[0]};
4051: my $maxnum = $numtop;
1.120 raeburn 4052: my %default_names = (
4053: instcode => &mt('Official courses'),
4054: communities => &mt('Communities'),
4055: );
4056:
4057: if ((!grep(/^instcode$/,@{$cats[0]})) ||
4058: ($cathash->{'instcode::0'} eq '') ||
4059: (!grep(/^communities$/,@{$cats[0]})) ||
4060: ($cathash->{'communities::0'} eq '')) {
1.57 raeburn 4061: $maxnum ++;
4062: }
4063: my $lastidx;
4064: for (my $i=0; $i<$numtop; $i++) {
4065: my $parent = $cats[0][$i];
4066: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4067: my $item = &escape($parent).'::0';
4068: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$item','$idx{$item}'".');"';
4069: $lastidx = $idx{$item};
4070: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
4071: .'<select name="'.$item.'"'.$chgstr.'>';
4072: for (my $k=0; $k<=$maxnum; $k++) {
4073: my $vpos = $k+1;
4074: my $selstr;
4075: if ($k == $i) {
4076: $selstr = ' selected="selected" ';
4077: }
4078: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4079: }
4080: $datatable .= '</select></td><td>';
1.120 raeburn 4081: if ($parent eq 'instcode' || $parent eq 'communities') {
4082: $datatable .= '<span class="LC_nobreak">'
4083: .$default_names{$parent}.'</span>';
4084: if ($parent eq 'instcode') {
4085: $datatable .= '<br /><span class="LC_nobreak">('
4086: .&mt('with institutional codes')
4087: .')</span></td><td'.$colattrib.'>';
4088: } else {
4089: $datatable .= '<table><tr><td>';
4090: }
4091: $datatable .= '<span class="LC_nobreak">'
4092: .'<label><input type="radio" name="'
4093: .$parent.'" value="1" checked="checked" />'
4094: .&mt('Display').'</label>';
4095: if ($parent eq 'instcode') {
4096: $datatable .= ' ';
4097: } else {
4098: $datatable .= '</span></td></tr><tr><td>'
4099: .'<span class="LC_nobreak">';
4100: }
4101: $datatable .= '<label><input type="radio" name="'
4102: .$parent.'" value="0" />'
4103: .&mt('Do not display').'</label></span>';
4104: if ($parent eq 'communities') {
4105: $datatable .= '</td></tr></table>';
4106: }
4107: $datatable .= '</td>';
1.57 raeburn 4108: } else {
4109: $datatable .= $parent
4110: .' <label><input type="checkbox" name="deletecategory" '
4111: .'value="'.$item.'" />'.&mt('Delete').'</label></span></td>';
4112: }
4113: my $depth = 1;
4114: push(@path,$parent);
4115: $datatable .= &build_category_rows($itemcount,\@cats,$depth,$parent,\@path,\%idx);
4116: pop(@path);
4117: $datatable .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
4118: $itemcount ++;
4119: }
1.48 raeburn 4120: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.57 raeburn 4121: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','$lastidx'".');"';
4122: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="addcategory_pos"'.$chgstr.'>';
1.48 raeburn 4123: for (my $k=0; $k<=$maxnum; $k++) {
4124: my $vpos = $k+1;
4125: my $selstr;
1.57 raeburn 4126: if ($k == $numtop) {
1.48 raeburn 4127: $selstr = ' selected="selected" ';
4128: }
4129: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4130: }
1.59 bisitz 4131: $datatable .= '</select></span></td><td colspan="2">'.&mt('Add category:').' '
1.57 raeburn 4132: .'<input type="text" size="20" name="addcategory_name" value="" /></td>'
4133: .'</tr>'."\n";
1.48 raeburn 4134: $itemcount ++;
1.120 raeburn 4135: foreach my $default ('instcode','communities') {
4136: if ((!grep(/^\Q$default\E$/,@{$cats[0]})) || ($cathash->{$default.'::0'} eq '')) {
4137: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4138: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','$lastidx'".');"';
4139: $datatable .= '<tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr><tr '.$css_class.'><td>'.
4140: '<span class="LC_nobreak"><select name="'.$default.'_pos"'.$chgstr.'>';
4141: for (my $k=0; $k<=$maxnum; $k++) {
4142: my $vpos = $k+1;
4143: my $selstr;
4144: if ($k == $maxnum) {
4145: $selstr = ' selected="selected" ';
4146: }
4147: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.57 raeburn 4148: }
1.120 raeburn 4149: $datatable .= '</select></span></td>'.
4150: '<td><span class="LC_nobreak">'.
4151: $default_names{$default}.'</span>';
4152: if ($default eq 'instcode') {
4153: $datatable .= '<br /><span class="LC_nobreak">('
4154: .&mt('with institutional codes').')</span>';
4155: }
4156: $datatable .= '</td>'
4157: .'<td><span class="LC_nobreak"><label><input type="radio" name="'.$default.'" value="1" />'
4158: .&mt('Display').'</label> '
4159: .'<label><input type="radio" name="'.$default.'" value="0" checked="checked"/>'
4160: .&mt('Do not display').'</label></span></td></tr>';
1.48 raeburn 4161: }
4162: }
4163: }
1.57 raeburn 4164: } else {
4165: $datatable .= &initialize_categories($itemcount);
1.48 raeburn 4166: }
4167: } else {
1.57 raeburn 4168: $datatable .= '<td class="LC_right_item">'.$hdritem->{'header'}->[0]->{'col2'}.'</td>'
4169: .&initialize_categories($itemcount);
1.48 raeburn 4170: }
1.57 raeburn 4171: $$rowtotal += $itemcount;
1.48 raeburn 4172: }
4173: return $datatable;
4174: }
4175:
1.69 raeburn 4176: sub print_serverstatuses {
4177: my ($dom,$settings,$rowtotal) = @_;
4178: my $datatable;
4179: my @pages = &serverstatus_pages();
4180: my (%namedaccess,%machineaccess);
4181: foreach my $type (@pages) {
4182: $namedaccess{$type} = '';
4183: $machineaccess{$type}= '';
4184: }
4185: if (ref($settings) eq 'HASH') {
4186: foreach my $type (@pages) {
4187: if (exists($settings->{$type})) {
4188: if (ref($settings->{$type}) eq 'HASH') {
4189: foreach my $key (keys(%{$settings->{$type}})) {
4190: if ($key eq 'namedusers') {
4191: $namedaccess{$type} = $settings->{$type}->{$key};
4192: } elsif ($key eq 'machines') {
4193: $machineaccess{$type} = $settings->{$type}->{$key};
4194: }
4195: }
4196: }
4197: }
4198: }
4199: }
1.81 raeburn 4200: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 4201: my $rownum = 0;
4202: my $css_class;
4203: foreach my $type (@pages) {
4204: $rownum ++;
4205: $css_class = $rownum%2?' class="LC_odd_row"':'';
4206: $datatable .= '<tr'.$css_class.'>'.
4207: '<td><span class="LC_nobreak">'.
4208: $titles->{$type}.'</span></td>'.
4209: '<td class="LC_left_item">'.
4210: '<input type="text" name="'.$type.'_namedusers" '.
4211: 'value="'.$namedaccess{$type}.'" size="30" /></td>'.
4212: '<td class="LC_right_item">'.
4213: '<span class="LC_nobreak">'.
4214: '<input type="text" name="'.$type.'_machines" '.
4215: 'value="'.$machineaccess{$type}.'" size="10" />'.
4216: '</td></tr>'."\n";
4217: }
4218: $$rowtotal += $rownum;
4219: return $datatable;
4220: }
4221:
4222: sub serverstatus_pages {
4223: return ('userstatus','lonstatus','loncron','server-status','codeversions',
1.189 raeburn 4224: 'checksums','clusterstatus','metadata_keywords','metadata_harvest',
1.156 raeburn 4225: 'takeoffline','takeonline','showenv','toggledebug','ping','domconf');
1.69 raeburn 4226: }
4227:
1.49 raeburn 4228: sub coursecategories_javascript {
4229: my ($settings) = @_;
1.57 raeburn 4230: my ($output,$jstext,$cathash);
1.49 raeburn 4231: if (ref($settings) eq 'HASH') {
1.57 raeburn 4232: $cathash = $settings->{'cats'};
4233: }
4234: if (ref($cathash) eq 'HASH') {
1.49 raeburn 4235: my (@cats,@jsarray,%idx);
1.57 raeburn 4236: &Apache::loncommon::gather_categories($cathash,\@cats,\%idx,\@jsarray);
1.49 raeburn 4237: if (@jsarray > 0) {
4238: $jstext = ' var categories = Array('.scalar(@jsarray).');'."\n";
4239: for (my $i=0; $i<@jsarray; $i++) {
4240: if (ref($jsarray[$i]) eq 'ARRAY') {
4241: my $catstr = join('","',@{$jsarray[$i]});
4242: $jstext .= ' categories['.$i.'] = Array("'.$catstr.'");'."\n";
4243: }
4244: }
4245: }
4246: } else {
4247: $jstext = ' var categories = Array(1);'."\n".
4248: ' categories[0] = Array("instcode_pos");'."\n";
4249: }
1.120 raeburn 4250: my $instcode_reserved = &mt('The name: "instcode" is a reserved category');
4251: my $communities_reserved = &mt('The name: "communities" is a reserved category');
4252: my $choose_again = '\\n'.&mt('Please use a different name for the new top level category');
1.49 raeburn 4253: $output = <<"ENDSCRIPT";
4254: <script type="text/javascript">
1.109 raeburn 4255: // <![CDATA[
1.49 raeburn 4256: function reorderCats(form,parent,item,idx) {
4257: var changedVal;
4258: $jstext
4259: var newpos = 'addcategory_pos';
4260: var current = new Array;
4261: if (parent == '') {
4262: var has_instcode = 0;
4263: var maxtop = categories[idx].length;
4264: for (var j=0; j<maxtop; j++) {
4265: if (categories[idx][j] == 'instcode::0') {
4266: has_instcode == 1;
4267: }
4268: }
4269: if (has_instcode == 0) {
4270: categories[idx][maxtop] = 'instcode_pos';
4271: }
4272: } else {
4273: newpos += '_'+parent;
4274: }
4275: var maxh = 1 + categories[idx].length;
4276: var current = new Array;
4277: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
4278: if (item == newpos) {
4279: changedVal = newitemVal;
4280: } else {
4281: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
4282: current[newitemVal] = newpos;
4283: }
4284: for (var i=0; i<categories[idx].length; i++) {
4285: var elementName = categories[idx][i];
4286: if (elementName != item) {
4287: if (form.elements[elementName]) {
4288: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
4289: current[currVal] = elementName;
4290: }
4291: }
4292: }
4293: var oldVal;
4294: for (var j=0; j<maxh; j++) {
4295: if (current[j] == undefined) {
4296: oldVal = j;
4297: }
4298: }
4299: if (oldVal < changedVal) {
4300: for (var k=oldVal+1; k<=changedVal ; k++) {
4301: var elementName = current[k];
4302: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
4303: }
4304: } else {
4305: for (var k=changedVal; k<oldVal; k++) {
4306: var elementName = current[k];
4307: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
4308: }
4309: }
4310: return;
4311: }
1.120 raeburn 4312:
4313: function categoryCheck(form) {
4314: if (form.elements['addcategory_name'].value == 'instcode') {
4315: alert('$instcode_reserved\\n$choose_again');
4316: return false;
4317: }
4318: if (form.elements['addcategory_name'].value == 'communities') {
4319: alert('$communities_reserved\\n$choose_again');
4320: return false;
4321: }
4322: return true;
4323: }
4324:
1.109 raeburn 4325: // ]]>
1.49 raeburn 4326: </script>
4327:
4328: ENDSCRIPT
4329: return $output;
4330: }
4331:
1.48 raeburn 4332: sub initialize_categories {
4333: my ($itemcount) = @_;
1.120 raeburn 4334: my ($datatable,$css_class,$chgstr);
4335: my %default_names = (
4336: instcode => 'Official courses (with institutional codes)',
4337: communities => 'Communities',
4338: );
4339: my $select0 = ' selected="selected"';
4340: my $select1 = '';
4341: foreach my $default ('instcode','communities') {
4342: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4343: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'',$default"."_pos','0'".');"';
4344: if ($default eq 'communities') {
4345: $select1 = $select0;
4346: $select0 = '';
4347: }
4348: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
4349: .'<select name="'.$default.'_pos">'
4350: .'<option value="0"'.$select0.'>1</option>'
4351: .'<option value="1"'.$select1.'>2</option>'
4352: .'<option value="2">3</option></select> '
4353: .$default_names{$default}
4354: .'</span></td><td><span class="LC_nobreak">'
4355: .'<label><input type="radio" name="'.$default.'" value="1" checked="checked" />'
4356: .&mt('Display').'</label> <label>'
4357: .'<input type="radio" name="'.$default.'" value="0" />'.&mt('Do not display')
1.48 raeburn 4358: .'</label></span></td></tr>';
1.120 raeburn 4359: $itemcount ++;
4360: }
1.48 raeburn 4361: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.49 raeburn 4362: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','0'".');"';
1.48 raeburn 4363: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.120 raeburn 4364: .'<select name="addcategory_pos"'.$chgstr.'>'
4365: .'<option value="0">1</option>'
4366: .'<option value="1">2</option>'
4367: .'<option value="2" selected="selected">3</option></select> '
1.48 raeburn 4368: .&mt('Add category').'</td><td>'.&mt('Name:')
4369: .' <input type="text" size="20" name="addcategory_name" value="" /></td></tr>';
4370: return $datatable;
4371: }
4372:
4373: sub build_category_rows {
1.49 raeburn 4374: my ($itemcount,$cats,$depth,$parent,$path,$idx) = @_;
4375: my ($text,$name,$item,$chgstr);
1.48 raeburn 4376: if (ref($cats) eq 'ARRAY') {
4377: my $maxdepth = scalar(@{$cats});
4378: if (ref($cats->[$depth]) eq 'HASH') {
4379: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
4380: my $numchildren = @{$cats->[$depth]{$parent}};
4381: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
4382: $text .= '<td><table class="LC_datatable">';
1.49 raeburn 4383: my ($idxnum,$parent_name,$parent_item);
4384: my $higher = $depth - 1;
4385: if ($higher == 0) {
4386: $parent_name = &escape($parent).'::'.$higher;
4387: } else {
4388: if (ref($path) eq 'ARRAY') {
4389: $parent_name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
4390: }
4391: }
4392: $parent_item = 'addcategory_pos_'.$parent_name;
1.48 raeburn 4393: for (my $j=0; $j<=$numchildren; $j++) {
1.49 raeburn 4394: if ($j < $numchildren) {
1.48 raeburn 4395: $name = $cats->[$depth]{$parent}[$j];
4396: $item = &escape($name).':'.&escape($parent).':'.$depth;
1.49 raeburn 4397: $idxnum = $idx->{$item};
4398: } else {
4399: $name = $parent_name;
4400: $item = $parent_item;
1.48 raeburn 4401: }
1.49 raeburn 4402: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'$parent_name','$item','$idxnum'".');"';
4403: $text .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="'.$item.'"'.$chgstr.'>';
1.48 raeburn 4404: for (my $i=0; $i<=$numchildren; $i++) {
4405: my $vpos = $i+1;
4406: my $selstr;
4407: if ($j == $i) {
4408: $selstr = ' selected="selected" ';
4409: }
4410: $text .= '<option value="'.$i.'"'.$selstr.'>'.$vpos.'</option>';
4411: }
4412: $text .= '</select> ';
4413: if ($j < $numchildren) {
4414: my $deeper = $depth+1;
4415: $text .= $name.' '
4416: .'<label><input type="checkbox" name="deletecategory" value="'
4417: .$item.'" />'.&mt('Delete').'</label></span></td><td>';
4418: if(ref($path) eq 'ARRAY') {
4419: push(@{$path},$name);
1.49 raeburn 4420: $text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path,$idx);
1.48 raeburn 4421: pop(@{$path});
4422: }
4423: } else {
1.59 bisitz 4424: $text .= &mt('Add subcategory:').' </span><input type="textbox" size="20" name="addcategory_name_';
1.48 raeburn 4425: if ($j == $numchildren) {
4426: $text .= $name;
4427: } else {
4428: $text .= $item;
4429: }
4430: $text .= '" value="" />';
4431: }
4432: $text .= '</td></tr>';
4433: }
4434: $text .= '</table></td>';
4435: } else {
4436: my $higher = $depth-1;
4437: if ($higher == 0) {
4438: $name = &escape($parent).'::'.$higher;
4439: } else {
4440: if (ref($path) eq 'ARRAY') {
4441: $name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
4442: }
4443: }
4444: my $colspan;
4445: if ($parent ne 'instcode') {
4446: $colspan = $maxdepth - $depth - 1;
4447: $text .= '<td colspan="'.$colspan.'">'.&mt('Add subcategory:').'<input type="textbox" size="20" name="subcat_'.$name.'" value="" /></td>';
4448: }
4449: }
4450: }
4451: }
4452: return $text;
4453: }
4454:
1.33 raeburn 4455: sub modifiable_userdata_row {
1.63 raeburn 4456: my ($context,$role,$settings,$numinrow,$rowcount,$usertypes) = @_;
1.33 raeburn 4457: my $rolename;
1.63 raeburn 4458: if ($context eq 'selfcreate') {
4459: if (ref($usertypes) eq 'HASH') {
4460: $rolename = $usertypes->{$role};
4461: } else {
4462: $rolename = $role;
4463: }
1.33 raeburn 4464: } else {
1.63 raeburn 4465: if ($role eq 'cr') {
4466: $rolename = &mt('Custom role');
4467: } else {
4468: $rolename = &Apache::lonnet::plaintext($role);
4469: }
1.33 raeburn 4470: }
4471: my @fields = ('lastname','firstname','middlename','generation',
4472: 'permanentemail','id');
4473: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
4474: my $output;
4475: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
4476: $output = '<tr '.$css_class.'>'.
4477: '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
4478: '<td class="LC_left_item" colspan="2"><table>';
4479: my $rem;
4480: my %checks;
4481: if (ref($settings) eq 'HASH') {
4482: if (ref($settings->{$context}) eq 'HASH') {
4483: if (ref($settings->{$context}->{$role}) eq 'HASH') {
4484: foreach my $field (@fields) {
4485: if ($settings->{$context}->{$role}->{$field}) {
4486: $checks{$field} = ' checked="checked" ';
4487: }
4488: }
4489: }
4490: }
4491: }
4492: for (my $i=0; $i<@fields; $i++) {
4493: my $rem = $i%($numinrow);
4494: if ($rem == 0) {
4495: if ($i > 0) {
4496: $output .= '</tr>';
4497: }
4498: $output .= '<tr>';
4499: }
4500: my $check = ' ';
4501: if (exists($checks{$fields[$i]})) {
4502: $check = $checks{$fields[$i]}
4503: } else {
4504: if ($role eq 'st') {
4505: if (ref($settings) ne 'HASH') {
4506: $check = ' checked="checked" ';
4507: }
4508: }
4509: }
4510: $output .= '<td class="LC_left_item">'.
4511: '<span class="LC_nobreak"><label>'.
4512: '<input type="checkbox" name="canmodify_'.$role.'" '.
4513: 'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
4514: '</label></span></td>';
4515: $rem = @fields%($numinrow);
4516: }
4517: my $colsleft = $numinrow - $rem;
4518: if ($colsleft > 1 ) {
4519: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
4520: ' </td>';
4521: } elsif ($colsleft == 1) {
4522: $output .= '<td class="LC_left_item"> </td>';
4523: }
4524: $output .= '</tr></table></td></tr>';
4525: return $output;
4526: }
1.28 raeburn 4527:
1.93 raeburn 4528: sub insttypes_row {
4529: my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle,$context) = @_;
4530: my %lt = &Apache::lonlocal::texthash (
4531: cansearch => 'Users allowed to search',
4532: statustocreate => 'Institutional affiliation(s) able to create own account (login/SSO)',
1.131 raeburn 4533: lockablenames => 'User preference to lock name',
1.93 raeburn 4534: );
4535: my $showdom;
4536: if ($context eq 'cansearch') {
4537: $showdom = ' ('.$dom.')';
4538: }
1.165 raeburn 4539: my $class = 'LC_left_item';
4540: if ($context eq 'statustocreate') {
4541: $class = 'LC_right_item';
4542: }
1.25 raeburn 4543: my $output = '<tr class="LC_odd_row">'.
1.93 raeburn 4544: '<td>'.$lt{$context}.$showdom.
1.165 raeburn 4545: '</td><td class="'.$class.'" colspan="2"><table>';
1.26 raeburn 4546: my $rem;
4547: if (ref($types) eq 'ARRAY') {
4548: for (my $i=0; $i<@{$types}; $i++) {
4549: if (defined($usertypes->{$types->[$i]})) {
4550: my $rem = $i%($numinrow);
4551: if ($rem == 0) {
4552: if ($i > 0) {
4553: $output .= '</tr>';
4554: }
4555: $output .= '<tr>';
1.23 raeburn 4556: }
1.26 raeburn 4557: my $check = ' ';
1.99 raeburn 4558: if (ref($settings) eq 'HASH') {
4559: if (ref($settings->{$context}) eq 'ARRAY') {
4560: if (grep(/^\Q$types->[$i]\E$/,@{$settings->{$context}})) {
4561: $check = ' checked="checked" ';
4562: }
4563: } elsif ($context eq 'statustocreate') {
1.26 raeburn 4564: $check = ' checked="checked" ';
4565: }
1.23 raeburn 4566: }
1.26 raeburn 4567: $output .= '<td class="LC_left_item">'.
4568: '<span class="LC_nobreak"><label>'.
1.93 raeburn 4569: '<input type="checkbox" name="'.$context.'" '.
1.26 raeburn 4570: 'value="'.$types->[$i].'"'.$check.'/>'.
4571: $usertypes->{$types->[$i]}.'</label></span></td>';
1.23 raeburn 4572: }
4573: }
1.26 raeburn 4574: $rem = @{$types}%($numinrow);
1.23 raeburn 4575: }
4576: my $colsleft = $numinrow - $rem;
1.131 raeburn 4577: if (($rem == 0) && (@{$types} > 0)) {
4578: $output .= '<tr>';
4579: }
1.23 raeburn 4580: if ($colsleft > 1) {
1.25 raeburn 4581: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
1.23 raeburn 4582: } else {
1.25 raeburn 4583: $output .= '<td class="LC_left_item">';
1.23 raeburn 4584: }
4585: my $defcheck = ' ';
1.99 raeburn 4586: if (ref($settings) eq 'HASH') {
4587: if (ref($settings->{$context}) eq 'ARRAY') {
4588: if (grep(/^default$/,@{$settings->{$context}})) {
4589: $defcheck = ' checked="checked" ';
4590: }
4591: } elsif ($context eq 'statustocreate') {
1.26 raeburn 4592: $defcheck = ' checked="checked" ';
4593: }
1.23 raeburn 4594: }
1.25 raeburn 4595: $output .= '<span class="LC_nobreak"><label>'.
1.93 raeburn 4596: '<input type="checkbox" name="'.$context.'" '.
1.25 raeburn 4597: 'value="default"'.$defcheck.'/>'.
4598: $othertitle.'</label></span></td>'.
4599: '</tr></table></td></tr>';
4600: return $output;
1.23 raeburn 4601: }
4602:
4603: sub sorted_searchtitles {
4604: my %searchtitles = &Apache::lonlocal::texthash(
4605: 'uname' => 'username',
4606: 'lastname' => 'last name',
4607: 'lastfirst' => 'last name, first name',
4608: );
4609: my @titleorder = ('uname','lastname','lastfirst');
4610: return (\%searchtitles,\@titleorder);
4611: }
4612:
1.25 raeburn 4613: sub sorted_searchtypes {
4614: my %srchtypes_desc = (
4615: exact => 'is exact match',
4616: contains => 'contains ..',
4617: begins => 'begins with ..',
4618: );
4619: my @srchtypeorder = ('exact','begins','contains');
4620: return (\%srchtypes_desc,\@srchtypeorder);
4621: }
4622:
1.3 raeburn 4623: sub usertype_update_row {
4624: my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
4625: my $datatable;
4626: my $numinrow = 4;
4627: foreach my $type (@{$types}) {
4628: if (defined($usertypes->{$type})) {
4629: $$rownums ++;
4630: my $css_class = $$rownums%2?' class="LC_odd_row"':'';
4631: $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
4632: '</td><td class="LC_left_item"><table>';
4633: for (my $i=0; $i<@{$fields}; $i++) {
4634: my $rem = $i%($numinrow);
4635: if ($rem == 0) {
4636: if ($i > 0) {
4637: $datatable .= '</tr>';
4638: }
4639: $datatable .= '<tr>';
4640: }
4641: my $check = ' ';
1.39 raeburn 4642: if (ref($settings) eq 'HASH') {
4643: if (ref($settings->{'fields'}) eq 'HASH') {
4644: if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
4645: if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
4646: $check = ' checked="checked" ';
4647: }
1.3 raeburn 4648: }
4649: }
4650: }
4651:
4652: if ($i == @{$fields}-1) {
4653: my $colsleft = $numinrow - $rem;
4654: if ($colsleft > 1) {
4655: $datatable .= '<td colspan="'.$colsleft.'">';
4656: } else {
4657: $datatable .= '<td>';
4658: }
4659: } else {
4660: $datatable .= '<td>';
4661: }
1.8 raeburn 4662: $datatable .= '<span class="LC_nobreak"><label>'.
4663: '<input type="checkbox" name="updateable_'.$type.
4664: '_'.$fields->[$i].'" value="1"'.$check.'/>'.
4665: $fieldtitles->{$fields->[$i]}.'</label></span></td>';
1.3 raeburn 4666: }
4667: $datatable .= '</tr></table></td></tr>';
4668: }
4669: }
4670: return $datatable;
1.1 raeburn 4671: }
4672:
4673: sub modify_login {
1.9 raeburn 4674: my ($r,$dom,$confname,%domconfig) = @_;
1.168 raeburn 4675: my ($resulttext,$errors,$colchgtext,%changes,%colchanges,%newfile,%newurl,
4676: %curr_loginvia,%loginhash,@currlangs,@newlangs,$addedfile,%title,@offon);
4677: %title = ( coursecatalog => 'Display course catalog',
4678: adminmail => 'Display administrator E-mail address',
1.188 raeburn 4679: helpdesk => 'Display "Contact Helpdesk" link',
1.168 raeburn 4680: newuser => 'Link for visitors to create a user account',
4681: loginheader => 'Log-in box header');
4682: @offon = ('off','on');
1.112 raeburn 4683: if (ref($domconfig{login}) eq 'HASH') {
4684: if (ref($domconfig{login}{loginvia}) eq 'HASH') {
4685: foreach my $lonhost (keys(%{$domconfig{login}{loginvia}})) {
4686: $curr_loginvia{$lonhost} = $domconfig{login}{loginvia}{$lonhost};
4687: }
4688: }
4689: }
1.9 raeburn 4690: ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
4691: \%domconfig,\%loginhash);
1.188 raeburn 4692: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 4693: foreach my $item (@toggles) {
4694: $loginhash{login}{$item} = $env{'form.'.$item};
4695: }
1.41 raeburn 4696: $loginhash{login}{loginheader} = $env{'form.loginheader'};
1.6 raeburn 4697: if (ref($colchanges{'login'}) eq 'HASH') {
4698: $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
4699: \%loginhash);
4700: }
1.110 raeburn 4701:
1.149 raeburn 4702: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.128 raeburn 4703: my @loginvia_attribs = ('serverpath','custompath','exempt');
1.110 raeburn 4704: if (keys(%servers) > 1) {
4705: foreach my $lonhost (keys(%servers)) {
1.128 raeburn 4706: next if ($env{'form.'.$lonhost.'_server'} eq $lonhost);
4707: if (ref($curr_loginvia{$lonhost}) eq 'HASH') {
4708: if ($env{'form.'.$lonhost.'_server'} eq $curr_loginvia{$lonhost}{'server'}) {
4709: $loginhash{login}{loginvia}{$lonhost}{'server'} = $curr_loginvia{$lonhost}{'server'};
4710: } elsif ($curr_loginvia{$lonhost}{'server'} ne '') {
4711: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
4712: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
4713: $changes{'loginvia'}{$lonhost} = 1;
4714: } else {
4715: $loginhash{login}{loginvia}{$lonhost}{'server'} = '';
4716: $changes{'loginvia'}{$lonhost} = 1;
4717: }
4718: } else {
4719: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
4720: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
4721: $changes{'loginvia'}{$lonhost} = 1;
4722: }
4723: }
4724: if ($loginhash{login}{loginvia}{$lonhost}{'server'} eq '') {
4725: foreach my $item (@loginvia_attribs) {
4726: $loginhash{login}{loginvia}{$lonhost}{$item} = '';
4727: }
4728: } else {
4729: foreach my $item (@loginvia_attribs) {
4730: my $new = $env{'form.'.$lonhost.'_'.$item};
4731: if (($item eq 'serverpath') && ($new eq 'custom')) {
4732: $env{'form.'.$lonhost.'_custompath'} =~ s/\s+//g;
4733: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
4734: $new = '/';
4735: }
4736: }
4737: if (($item eq 'custompath') &&
4738: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
4739: $new = '';
4740: }
4741: if ($new ne $curr_loginvia{$lonhost}{$item}) {
4742: $changes{'loginvia'}{$lonhost} = 1;
4743: }
4744: if ($item eq 'exempt') {
4745: $new =~ s/^\s+//;
4746: $new =~ s/\s+$//;
4747: my @poss_ips = split(/\s*[,:]\s*/,$new);
4748: my @okips;
4749: foreach my $ip (@poss_ips) {
4750: if ($ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
4751: if (($1 <= 255) && ($2 <= 255) && ($3 <= 255) && ($4 <= 255)) {
4752: push(@okips,$ip);
4753: }
4754: }
4755: }
4756: if (@okips > 0) {
4757: $new = join(',',@okips);
4758: } else {
4759: $new = '';
4760: }
4761: }
4762: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
4763: }
4764: }
1.112 raeburn 4765: } else {
1.128 raeburn 4766: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
4767: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
1.112 raeburn 4768: $changes{'loginvia'}{$lonhost} = 1;
1.128 raeburn 4769: foreach my $item (@loginvia_attribs) {
4770: my $new = $env{'form.'.$lonhost.'_'.$item};
4771: if (($item eq 'serverpath') && ($new eq 'custom')) {
4772: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
4773: $new = '/';
4774: }
4775: }
4776: if (($item eq 'custompath') &&
4777: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
4778: $new = '';
4779: }
4780: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
4781: }
1.110 raeburn 4782: }
4783: }
4784: }
4785: }
1.119 raeburn 4786:
1.168 raeburn 4787: my $servadm = $r->dir_config('lonAdmEMail');
4788: my %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
4789: if (ref($domconfig{'login'}) eq 'HASH') {
4790: if (ref($domconfig{'login'}{'helpurl'}) eq 'HASH') {
4791: foreach my $lang (sort(keys(%{$domconfig{'login'}{'helpurl'}}))) {
4792: if ($lang eq 'nolang') {
4793: push(@currlangs,$lang);
4794: } elsif (defined($langchoices{$lang})) {
4795: push(@currlangs,$lang);
4796: } else {
4797: next;
4798: }
4799: }
4800: }
4801: }
4802: my @delurls = &Apache::loncommon::get_env_multiple('form.loginhelpurl_del');
4803: if (@currlangs > 0) {
4804: foreach my $lang (@currlangs) {
4805: if (grep(/^\Q$lang\E$/,@delurls)) {
4806: $changes{'helpurl'}{$lang} = 1;
4807: } elsif ($env{'form.loginhelpurl_'.$lang.'.filename'}) {
4808: $changes{'helpurl'}{$lang} = 1;
4809: $newfile{$lang} = $env{'form.loginhelpurl_'.$lang.'.filename'};
4810: push(@newlangs,$lang);
4811: } else {
4812: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
4813: }
4814: }
4815: }
4816: unless (grep(/^nolang$/,@currlangs)) {
4817: if ($env{'form.loginhelpurl_nolang.filename'}) {
4818: $changes{'helpurl'}{'nolang'} = 1;
4819: $newfile{'nolang'} = $env{'form.loginhelpurl_nolang.filename'};
4820: push(@newlangs,'nolang');
4821: }
4822: }
4823: if ($env{'form.loginhelpurl_add_lang'}) {
4824: if ((defined($langchoices{$env{'form.loginhelpurl_add_lang'}})) &&
4825: ($env{'form.loginhelpurl_add_file.filename'})) {
4826: $newfile{$env{'form.loginhelpurl_add_lang'}} = $env{'form.loginhelpurl_add_file.filename'};
4827: $addedfile = $env{'form.loginhelpurl_add_lang'};
4828: }
4829: }
4830: if ((@newlangs > 0) || ($addedfile)) {
4831: my $error;
4832: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
4833: if ($configuserok eq 'ok') {
4834: if ($switchserver) {
4835: $error = &mt("Upload of custom help file is not permitted to this server: [_1]",$switchserver);
4836: } elsif ($author_ok eq 'ok') {
4837: my @allnew = @newlangs;
4838: if ($addedfile ne '') {
4839: push(@allnew,$addedfile);
4840: }
4841: foreach my $lang (@allnew) {
4842: my $formelem = 'loginhelpurl_'.$lang;
4843: if ($lang eq $env{'form.loginhelpurl_add_lang'}) {
4844: $formelem = 'loginhelpurl_add_file';
4845: }
4846: (my $result,$newurl{$lang}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
4847: "help/$lang",'','',$newfile{$lang});
4848: if ($result eq 'ok') {
4849: $loginhash{'login'}{'helpurl'}{$lang} = $newurl{$lang};
4850: $changes{'helpurl'}{$lang} = 1;
4851: } else {
4852: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$newfile{$lang},$result);
4853: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
4854: if ((grep(/^\Q$lang\E$/,@currlangs)) &&
4855: (!grep(/^\Q$lang\E$/,@delurls))) {
4856:
4857: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
4858: }
4859: }
4860: }
4861: } else {
4862: $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);
4863: }
4864: } else {
4865: $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);
4866: }
4867: if ($error) {
4868: &Apache::lonnet::logthis($error);
4869: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
4870: }
4871: }
1.169 raeburn 4872: &process_captcha('login',\%changes,$loginhash{'login'},$domconfig{'login'});
1.168 raeburn 4873:
4874: my $defaulthelpfile = '/adm/loginproblems.html';
4875: my $defaulttext = &mt('Default in use');
4876:
1.1 raeburn 4877: my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
4878: $dom);
4879: if ($putresult eq 'ok') {
1.188 raeburn 4880: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 4881: my %defaultchecked = (
4882: 'coursecatalog' => 'on',
1.188 raeburn 4883: 'helpdesk' => 'on',
1.42 raeburn 4884: 'adminmail' => 'off',
1.43 raeburn 4885: 'newuser' => 'off',
1.42 raeburn 4886: );
1.55 raeburn 4887: if (ref($domconfig{'login'}) eq 'HASH') {
4888: foreach my $item (@toggles) {
4889: if ($defaultchecked{$item} eq 'on') {
4890: if (($domconfig{'login'}{$item} eq '0') &&
4891: ($env{'form.'.$item} eq '1')) {
4892: $changes{$item} = 1;
4893: } elsif (($domconfig{'login'}{$item} eq '' ||
4894: $domconfig{'login'}{$item} eq '1') &&
4895: ($env{'form.'.$item} eq '0')) {
4896: $changes{$item} = 1;
4897: }
4898: } elsif ($defaultchecked{$item} eq 'off') {
4899: if (($domconfig{'login'}{$item} eq '1') &&
4900: ($env{'form.'.$item} eq '0')) {
4901: $changes{$item} = 1;
4902: } elsif (($domconfig{'login'}{$item} eq '' ||
4903: $domconfig{'login'}{$item} eq '0') &&
4904: ($env{'form.'.$item} eq '1')) {
4905: $changes{$item} = 1;
4906: }
1.42 raeburn 4907: }
4908: }
1.41 raeburn 4909: }
1.6 raeburn 4910: if (keys(%changes) > 0 || $colchgtext) {
1.41 raeburn 4911: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.1 raeburn 4912: $resulttext = &mt('Changes made:').'<ul>';
4913: foreach my $item (sort(keys(%changes))) {
1.135 bisitz 4914: if ($item eq 'loginvia') {
1.112 raeburn 4915: if (ref($changes{$item}) eq 'HASH') {
4916: $resulttext .= '<li>'.&mt('Log-in page availability:').'<ul>';
4917: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
1.128 raeburn 4918: if (defined($servers{$loginhash{login}{loginvia}{$lonhost}{'server'}})) {
4919: if (ref($loginhash{login}{loginvia}{$lonhost}) eq 'HASH') {
4920: my $protocol = $Apache::lonnet::protocol{$env{'form.'.$lonhost.'_server'}};
4921: $protocol = 'http' if ($protocol ne 'https');
4922: my $target = $protocol.'://'.$servers{$env{'form.'.$lonhost.'_server'}};
4923:
4924: if ($loginhash{login}{loginvia}{$lonhost}{'serverpath'} eq 'custom') {
4925: $target .= $loginhash{login}{loginvia}{$lonhost}{'custompath'};
4926: } else {
4927: $target .= $loginhash{login}{loginvia}{$lonhost}{'serverpath'};
4928: }
4929: $resulttext .= '<li>'.&mt('Server: [_1] log-in page redirects to [_2].',$servers{$lonhost},'<a href="'.$target.'">'.$target.'</a>');
4930: if ($loginhash{login}{loginvia}{$lonhost}{'exempt'} ne '') {
4931: $resulttext .= ' '.&mt('No redirection for clients from following IPs:').' '.$loginhash{login}{loginvia}{$lonhost}{'exempt'};
4932: }
4933: $resulttext .= '</li>';
4934: } else {
4935: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$lonhost).'</li>';
4936: }
1.112 raeburn 4937: } else {
1.128 raeburn 4938: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$servers{$lonhost}).'</li>';
1.112 raeburn 4939: }
4940: }
1.128 raeburn 4941: $resulttext .= '</ul></li>';
1.112 raeburn 4942: }
1.168 raeburn 4943: } elsif ($item eq 'helpurl') {
4944: if (ref($changes{$item}) eq 'HASH') {
4945: foreach my $lang (sort(keys(%{$changes{$item}}))) {
4946: if (grep(/^\Q$lang\E$/,@delurls)) {
4947: my ($chg,$link);
4948: $link = &Apache::loncommon::modal_link($defaulthelpfile,$defaulttext,600,500);
4949: if ($lang eq 'nolang') {
4950: $chg = &mt('custom log-in help file removed for no preferred language; [_1]',$link);
4951: } else {
4952: $chg = &mt('custom log-in help file removed for specific language: [_1]; [_2]',$langchoices{$lang},$link);
4953: }
4954: $resulttext .= '<li>'.$chg.'</li>';
4955: } else {
4956: my $chg;
4957: if ($lang eq 'nolang') {
4958: $chg = &mt('custom log-in help file for no preferred language');
4959: } else {
4960: $chg = &mt('custom log-in help file for specific language: [_1]',$langchoices{$lang});
4961: }
4962: $resulttext .= '<li>'.&Apache::loncommon::modal_link(
4963: $loginhash{'login'}{'helpurl'}{$lang}.
4964: '?inhibitmenu=yes',$chg,600,500).
4965: '</li>';
4966: }
4967: }
4968: }
1.169 raeburn 4969: } elsif ($item eq 'captcha') {
4970: if (ref($loginhash{'login'}) eq 'HASH') {
4971: my $chgtxt;
4972: if ($loginhash{'login'}{$item} eq 'notused') {
4973: $chgtxt .= &mt('No CAPTCHA validation in use for helpdesk form.');
4974: } else {
4975: my %captchas = &captcha_phrases();
4976: if ($captchas{$loginhash{'login'}{$item}}) {
4977: $chgtxt .= &mt("Validation for helpdesk form set to $captchas{$loginhash{'login'}{$item}}.");
4978: } else {
4979: $chgtxt .= &mt('Validation for helpdesk form set to unknown type.');
4980: }
4981: }
4982: $resulttext .= '<li>'.$chgtxt.'</li>';
4983: }
4984: } elsif ($item eq 'recaptchakeys') {
4985: if (ref($loginhash{'login'}) eq 'HASH') {
4986: my ($privkey,$pubkey);
4987: if (ref($loginhash{'login'}{$item}) eq 'HASH') {
4988: $pubkey = $loginhash{'login'}{$item}{'public'};
4989: $privkey = $loginhash{'login'}{$item}{'private'};
4990: }
4991: my $chgtxt .= &mt('ReCAPTCHA keys changes').'<ul>';
4992: if (!$pubkey) {
4993: $chgtxt .= '<li>'.&mt('Public key deleted').'</li>';
4994: } else {
4995: $chgtxt .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
4996: }
4997: if (!$privkey) {
4998: $chgtxt .= '<li>'.&mt('Private key deleted').'</li>';
4999: } else {
5000: $chgtxt .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
5001: }
5002: $chgtxt .= '</ul>';
5003: $resulttext .= '<li>'.$chgtxt.'</li>';
5004: }
1.41 raeburn 5005: } else {
5006: $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
5007: }
1.1 raeburn 5008: }
1.6 raeburn 5009: $resulttext .= $colchgtext.'</ul>';
1.1 raeburn 5010: } else {
5011: $resulttext = &mt('No changes made to log-in page settings');
5012: }
5013: } else {
1.11 albertel 5014: $resulttext = '<span class="LC_error">'.
5015: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 5016: }
1.6 raeburn 5017: if ($errors) {
1.9 raeburn 5018: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.6 raeburn 5019: $errors.'</ul>';
5020: }
5021: return $resulttext;
5022: }
5023:
5024: sub color_font_choices {
5025: my %choices =
5026: &Apache::lonlocal::texthash (
5027: img => "Header",
5028: bgs => "Background colors",
5029: links => "Link colors",
1.55 raeburn 5030: images => "Images",
1.6 raeburn 5031: font => "Font color",
1.97 tempelho 5032: fontmenu => "Font Menu",
1.76 raeburn 5033: pgbg => "Page",
1.6 raeburn 5034: tabbg => "Header",
5035: sidebg => "Border",
5036: link => "Link",
5037: alink => "Active link",
5038: vlink => "Visited link",
5039: );
5040: return %choices;
5041: }
5042:
5043: sub modify_rolecolors {
1.9 raeburn 5044: my ($r,$dom,$confname,$roles,%domconfig) = @_;
1.6 raeburn 5045: my ($resulttext,%rolehash);
5046: $rolehash{'rolecolors'} = {};
1.55 raeburn 5047: if (ref($domconfig{'rolecolors'}) ne 'HASH') {
5048: if ($domconfig{'rolecolors'} eq '') {
5049: $domconfig{'rolecolors'} = {};
5050: }
5051: }
1.9 raeburn 5052: my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
1.6 raeburn 5053: $domconfig{'rolecolors'},$rolehash{'rolecolors'});
5054: my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
5055: $dom);
5056: if ($putresult eq 'ok') {
5057: if (keys(%changes) > 0) {
1.41 raeburn 5058: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.6 raeburn 5059: $resulttext = &display_colorchgs($dom,\%changes,$roles,
5060: $rolehash{'rolecolors'});
5061: } else {
5062: $resulttext = &mt('No changes made to default color schemes');
5063: }
5064: } else {
1.11 albertel 5065: $resulttext = '<span class="LC_error">'.
5066: &mt('An error occurred: [_1]',$putresult).'</span>';
1.6 raeburn 5067: }
5068: if ($errors) {
5069: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
5070: $errors.'</ul>';
5071: }
5072: return $resulttext;
5073: }
5074:
5075: sub modify_colors {
1.9 raeburn 5076: my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
1.12 raeburn 5077: my (%changes,%choices);
1.51 raeburn 5078: my @bgs;
1.6 raeburn 5079: my @links = ('link','alink','vlink');
1.41 raeburn 5080: my @logintext;
1.6 raeburn 5081: my @images;
5082: my $servadm = $r->dir_config('lonAdmEMail');
5083: my $errors;
5084: foreach my $role (@{$roles}) {
5085: if ($role eq 'login') {
1.12 raeburn 5086: %choices = &login_choices();
1.41 raeburn 5087: @logintext = ('textcol','bgcol');
1.12 raeburn 5088: } else {
5089: %choices = &color_font_choices();
1.107 raeburn 5090: $confhash->{$role}{'fontmenu'} = $env{'form.'.$role.'_fontmenu'};
1.12 raeburn 5091: }
5092: if ($role eq 'login') {
1.41 raeburn 5093: @images = ('img','logo','domlogo','login');
1.51 raeburn 5094: @bgs = ('pgbg','mainbg','sidebg');
1.6 raeburn 5095: } else {
5096: @images = ('img');
1.51 raeburn 5097: @bgs = ('pgbg','tabbg','sidebg');
1.6 raeburn 5098: }
5099: $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
1.41 raeburn 5100: foreach my $item (@bgs,@links,@logintext) {
1.6 raeburn 5101: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
5102: }
1.46 raeburn 5103: my ($configuserok,$author_ok,$switchserver) =
5104: &config_check($dom,$confname,$servadm);
1.9 raeburn 5105: my ($width,$height) = &thumb_dimensions();
1.40 raeburn 5106: if (ref($domconfig->{$role}) ne 'HASH') {
5107: $domconfig->{$role} = {};
5108: }
1.8 raeburn 5109: foreach my $img (@images) {
1.70 raeburn 5110: if (($role eq 'login') && (($img eq 'img') || ($img eq 'logo'))) {
5111: if (defined($env{'form.login_showlogo_'.$img})) {
5112: $confhash->{$role}{'showlogo'}{$img} = 1;
5113: } else {
5114: $confhash->{$role}{'showlogo'}{$img} = 0;
5115: }
5116: }
1.18 albertel 5117: if ( ! $env{'form.'.$role.'_'.$img.'.filename'}
5118: && !defined($domconfig->{$role}{$img})
5119: && !$env{'form.'.$role.'_del_'.$img}
5120: && $env{'form.'.$role.'_import_'.$img}) {
5121: # import the old configured image from the .tab setting
5122: # if they haven't provided a new one
5123: $domconfig->{$role}{$img} =
5124: $env{'form.'.$role.'_import_'.$img};
5125: }
1.6 raeburn 5126: if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
1.9 raeburn 5127: my $error;
1.6 raeburn 5128: if ($configuserok eq 'ok') {
1.9 raeburn 5129: if ($switchserver) {
1.12 raeburn 5130: $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
1.9 raeburn 5131: } else {
5132: if ($author_ok eq 'ok') {
5133: my ($result,$logourl) =
5134: &publishlogo($r,'upload',$role.'_'.$img,
5135: $dom,$confname,$img,$width,$height);
5136: if ($result eq 'ok') {
5137: $confhash->{$role}{$img} = $logourl;
1.12 raeburn 5138: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 5139: } else {
1.12 raeburn 5140: $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 5141: }
5142: } else {
1.46 raeburn 5143: $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 5144: }
5145: }
5146: } else {
1.46 raeburn 5147: $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 5148: }
5149: if ($error) {
1.8 raeburn 5150: &Apache::lonnet::logthis($error);
1.11 albertel 5151: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
1.8 raeburn 5152: }
5153: } elsif ($domconfig->{$role}{$img} ne '') {
1.9 raeburn 5154: if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
5155: my $error;
5156: if ($configuserok eq 'ok') {
5157: # is confname an author?
5158: if ($switchserver eq '') {
5159: if ($author_ok eq 'ok') {
5160: my ($result,$logourl) =
5161: &publishlogo($r,'copy',$domconfig->{$role}{$img},
5162: $dom,$confname,$img,$width,$height);
5163: if ($result eq 'ok') {
5164: $confhash->{$role}{$img} = $logourl;
1.18 albertel 5165: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 5166: }
5167: }
5168: }
5169: }
1.6 raeburn 5170: }
5171: }
5172: }
5173: if (ref($domconfig) eq 'HASH') {
5174: if (ref($domconfig->{$role}) eq 'HASH') {
5175: foreach my $img (@images) {
5176: if ($domconfig->{$role}{$img} ne '') {
5177: if ($env{'form.'.$role.'_del_'.$img}) {
5178: $confhash->{$role}{$img} = '';
1.12 raeburn 5179: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 5180: } else {
1.9 raeburn 5181: if ($confhash->{$role}{$img} eq '') {
5182: $confhash->{$role}{$img} = $domconfig->{$role}{$img};
5183: }
1.6 raeburn 5184: }
5185: } else {
5186: if ($env{'form.'.$role.'_del_'.$img}) {
5187: $confhash->{$role}{$img} = '';
1.12 raeburn 5188: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 5189: }
5190: }
1.70 raeburn 5191: if (($role eq 'login') && (($img eq 'logo') || ($img eq 'img'))) {
5192: if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') {
5193: if ($confhash->{$role}{'showlogo'}{$img} ne
5194: $domconfig->{$role}{'showlogo'}{$img}) {
5195: $changes{$role}{'showlogo'}{$img} = 1;
5196: }
5197: } else {
5198: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
5199: $changes{$role}{'showlogo'}{$img} = 1;
5200: }
5201: }
5202: }
5203: }
1.6 raeburn 5204: if ($domconfig->{$role}{'font'} ne '') {
5205: if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
5206: $changes{$role}{'font'} = 1;
5207: }
5208: } else {
5209: if ($confhash->{$role}{'font'}) {
5210: $changes{$role}{'font'} = 1;
5211: }
5212: }
1.107 raeburn 5213: if ($role ne 'login') {
5214: if ($domconfig->{$role}{'fontmenu'} ne '') {
5215: if ($confhash->{$role}{'fontmenu'} ne $domconfig->{$role}{'fontmenu'}) {
5216: $changes{$role}{'fontmenu'} = 1;
5217: }
5218: } else {
5219: if ($confhash->{$role}{'fontmenu'}) {
5220: $changes{$role}{'fontmenu'} = 1;
5221: }
1.97 tempelho 5222: }
5223: }
1.6 raeburn 5224: foreach my $item (@bgs) {
5225: if ($domconfig->{$role}{$item} ne '') {
5226: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
5227: $changes{$role}{'bgs'}{$item} = 1;
5228: }
5229: } else {
5230: if ($confhash->{$role}{$item}) {
5231: $changes{$role}{'bgs'}{$item} = 1;
5232: }
5233: }
5234: }
5235: foreach my $item (@links) {
5236: if ($domconfig->{$role}{$item} ne '') {
5237: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
5238: $changes{$role}{'links'}{$item} = 1;
5239: }
5240: } else {
5241: if ($confhash->{$role}{$item}) {
5242: $changes{$role}{'links'}{$item} = 1;
5243: }
5244: }
5245: }
1.41 raeburn 5246: foreach my $item (@logintext) {
5247: if ($domconfig->{$role}{$item} ne '') {
5248: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
5249: $changes{$role}{'logintext'}{$item} = 1;
5250: }
5251: } else {
5252: if ($confhash->{$role}{$item}) {
5253: $changes{$role}{'logintext'}{$item} = 1;
5254: }
5255: }
5256: }
1.6 raeburn 5257: } else {
5258: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 5259: \@logintext,$confhash,\%changes);
1.6 raeburn 5260: }
5261: } else {
5262: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 5263: \@logintext,$confhash,\%changes);
1.6 raeburn 5264: }
5265: }
5266: return ($errors,%changes);
5267: }
5268:
1.46 raeburn 5269: sub config_check {
5270: my ($dom,$confname,$servadm) = @_;
5271: my ($configuserok,$author_ok,$switchserver,%currroles);
5272: my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
5273: ($configuserok,%currroles) = &check_configuser($uhome,$dom,
5274: $confname,$servadm);
5275: if ($configuserok eq 'ok') {
5276: $switchserver = &check_switchserver($dom,$confname);
5277: if ($switchserver eq '') {
5278: $author_ok = &check_authorstatus($dom,$confname,%currroles);
5279: }
5280: }
5281: return ($configuserok,$author_ok,$switchserver);
5282: }
5283:
1.6 raeburn 5284: sub default_change_checker {
1.41 raeburn 5285: my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
1.6 raeburn 5286: foreach my $item (@{$links}) {
5287: if ($confhash->{$role}{$item}) {
5288: $changes->{$role}{'links'}{$item} = 1;
5289: }
5290: }
5291: foreach my $item (@{$bgs}) {
5292: if ($confhash->{$role}{$item}) {
5293: $changes->{$role}{'bgs'}{$item} = 1;
5294: }
5295: }
1.41 raeburn 5296: foreach my $item (@{$logintext}) {
5297: if ($confhash->{$role}{$item}) {
5298: $changes->{$role}{'logintext'}{$item} = 1;
5299: }
5300: }
1.6 raeburn 5301: foreach my $img (@{$images}) {
5302: if ($env{'form.'.$role.'_del_'.$img}) {
5303: $confhash->{$role}{$img} = '';
1.12 raeburn 5304: $changes->{$role}{'images'}{$img} = 1;
1.6 raeburn 5305: }
1.70 raeburn 5306: if ($role eq 'login') {
5307: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
5308: $changes->{$role}{'showlogo'}{$img} = 1;
5309: }
5310: }
1.6 raeburn 5311: }
5312: if ($confhash->{$role}{'font'}) {
5313: $changes->{$role}{'font'} = 1;
5314: }
1.48 raeburn 5315: }
1.6 raeburn 5316:
5317: sub display_colorchgs {
5318: my ($dom,$changes,$roles,$confhash) = @_;
5319: my (%choices,$resulttext);
5320: if (!grep(/^login$/,@{$roles})) {
5321: $resulttext = &mt('Changes made:').'<br />';
5322: }
5323: foreach my $role (@{$roles}) {
5324: if ($role eq 'login') {
5325: %choices = &login_choices();
5326: } else {
5327: %choices = &color_font_choices();
5328: }
5329: if (ref($changes->{$role}) eq 'HASH') {
5330: if ($role ne 'login') {
5331: $resulttext .= '<h4>'.&mt($role).'</h4>';
5332: }
5333: foreach my $key (sort(keys(%{$changes->{$role}}))) {
5334: if ($role ne 'login') {
5335: $resulttext .= '<ul>';
5336: }
5337: if (ref($changes->{$role}{$key}) eq 'HASH') {
5338: if ($role ne 'login') {
5339: $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
5340: }
5341: foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
1.70 raeburn 5342: if (($role eq 'login') && ($key eq 'showlogo')) {
5343: if ($confhash->{$role}{$key}{$item}) {
5344: $resulttext .= '<li>'.&mt("$choices{$item} set to be displayed").'</li>';
5345: } else {
5346: $resulttext .= '<li>'.&mt("$choices{$item} set to not be displayed").'</li>';
5347: }
5348: } elsif ($confhash->{$role}{$item} eq '') {
1.6 raeburn 5349: $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
5350: } else {
1.12 raeburn 5351: my $newitem = $confhash->{$role}{$item};
5352: if ($key eq 'images') {
5353: $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" valign="bottom" />';
5354: }
5355: $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
1.6 raeburn 5356: }
5357: }
5358: if ($role ne 'login') {
5359: $resulttext .= '</ul></li>';
5360: }
5361: } else {
5362: if ($confhash->{$role}{$key} eq '') {
5363: $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
5364: } else {
5365: $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
5366: }
5367: }
5368: if ($role ne 'login') {
5369: $resulttext .= '</ul>';
5370: }
5371: }
5372: }
5373: }
1.3 raeburn 5374: return $resulttext;
1.1 raeburn 5375: }
5376:
1.9 raeburn 5377: sub thumb_dimensions {
5378: return ('200','50');
5379: }
5380:
1.16 raeburn 5381: sub check_dimensions {
5382: my ($inputfile) = @_;
5383: my ($fullwidth,$fullheight);
5384: if ($inputfile =~ m|^[/\w.\-]+$|) {
5385: if (open(PIPE,"identify $inputfile 2>&1 |")) {
5386: my $imageinfo = <PIPE>;
5387: if (!close(PIPE)) {
5388: &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
5389: }
5390: chomp($imageinfo);
5391: my ($fullsize) =
1.21 raeburn 5392: ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
1.16 raeburn 5393: if ($fullsize) {
5394: ($fullwidth,$fullheight) = split(/x/,$fullsize);
5395: }
5396: }
5397: }
5398: return ($fullwidth,$fullheight);
5399: }
5400:
1.9 raeburn 5401: sub check_configuser {
5402: my ($uhome,$dom,$confname,$servadm) = @_;
5403: my ($configuserok,%currroles);
5404: if ($uhome eq 'no_host') {
5405: srand( time() ^ ($$ + ($$ << 15)) ); # Seed rand.
5406: my $configpass = &LONCAPA::Enrollment::create_password();
5407: $configuserok =
5408: &Apache::lonnet::modifyuser($dom,$confname,'','internal',
5409: $configpass,'','','','','',undef,$servadm);
5410: } else {
5411: $configuserok = 'ok';
5412: %currroles =
5413: &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
5414: }
5415: return ($configuserok,%currroles);
5416: }
5417:
5418: sub check_authorstatus {
5419: my ($dom,$confname,%currroles) = @_;
5420: my $author_ok;
1.40 raeburn 5421: if (!$currroles{':'.$dom.':au'}) {
1.9 raeburn 5422: my $start = time;
5423: my $end = 0;
5424: $author_ok =
5425: &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
1.47 raeburn 5426: 'au',$end,$start,'','','domconfig');
1.9 raeburn 5427: } else {
5428: $author_ok = 'ok';
5429: }
5430: return $author_ok;
5431: }
5432:
5433: sub publishlogo {
1.46 raeburn 5434: my ($r,$action,$formname,$dom,$confname,$subdir,$thumbwidth,$thumbheight,$savefileas) = @_;
1.9 raeburn 5435: my ($output,$fname,$logourl);
5436: if ($action eq 'upload') {
5437: $fname=$env{'form.'.$formname.'.filename'};
5438: chop($env{'form.'.$formname});
5439: } else {
5440: ($fname) = ($formname =~ /([^\/]+)$/);
5441: }
1.46 raeburn 5442: if ($savefileas ne '') {
5443: $fname = $savefileas;
5444: }
1.9 raeburn 5445: $fname=&Apache::lonnet::clean_filename($fname);
5446: # See if there is anything left
5447: unless ($fname) { return ('error: no uploaded file'); }
5448: $fname="$subdir/$fname";
1.164 raeburn 5449: my $docroot=$r->dir_config('lonDocRoot');
5450: my $filepath="$docroot/priv";
5451: my $relpath = "$dom/$confname";
1.9 raeburn 5452: my ($fnamepath,$file,$fetchthumb);
5453: $file=$fname;
5454: if ($fname=~m|/|) {
5455: ($fnamepath,$file) = ($fname =~ m|^(.*)/([^/]+)$|);
5456: }
1.164 raeburn 5457: my @parts=split(/\//,"$filepath/$relpath/$fnamepath");
1.9 raeburn 5458: my $count;
1.164 raeburn 5459: for ($count=5;$count<=$#parts;$count++) {
1.9 raeburn 5460: $filepath.="/$parts[$count]";
5461: if ((-e $filepath)!=1) {
5462: mkdir($filepath,02770);
5463: }
5464: }
5465: # Check for bad extension and disallow upload
5466: if ($file=~/\.(\w+)$/ &&
5467: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
5468: $output =
5469: &mt('Invalid file extension ([_1]) - reserved for LONCAPA use.',$1);
5470: } elsif ($file=~/\.(\w+)$/ &&
5471: !defined(&Apache::loncommon::fileembstyle($1))) {
5472: $output = &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
5473: } elsif ($file=~/\.(\d+)\.(\w+)$/) {
1.195 bisitz 5474: $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 5475: } elsif (-d "$filepath/$file") {
1.195 bisitz 5476: $output = &mt('Filename is a directory name - rename the file and re-upload');
1.9 raeburn 5477: } else {
5478: my $source = $filepath.'/'.$file;
5479: my $logfile;
5480: if (!open($logfile,">>$source".'.log')) {
1.196 raeburn 5481: return (&mt('No write permission to Authoring Space'));
1.9 raeburn 5482: }
5483: print $logfile
5484: "\n================= Publish ".localtime()." ================\n".
5485: $env{'user.name'}.':'.$env{'user.domain'}."\n";
5486: # Save the file
5487: if (!open(FH,'>'.$source)) {
5488: &Apache::lonnet::logthis('Failed to create '.$source);
5489: return (&mt('Failed to create file'));
5490: }
5491: if ($action eq 'upload') {
5492: if (!print FH ($env{'form.'.$formname})) {
5493: &Apache::lonnet::logthis('Failed to write to '.$source);
5494: return (&mt('Failed to write file'));
5495: }
5496: } else {
5497: my $original = &Apache::lonnet::filelocation('',$formname);
5498: if(!copy($original,$source)) {
5499: &Apache::lonnet::logthis('Failed to copy '.$original.' to '.$source);
5500: return (&mt('Failed to write file'));
5501: }
5502: }
5503: close(FH);
5504: chmod(0660, $source); # Permissions to rw-rw---.
5505:
5506: my $targetdir=$docroot.'/res/'.$dom.'/'.$confname .'/'.$fnamepath;
5507: my $copyfile=$targetdir.'/'.$file;
5508:
5509: my @parts=split(/\//,$targetdir);
5510: my $path="/$parts[1]/$parts[2]/$parts[3]/$parts[4]";
5511: for (my $count=5;$count<=$#parts;$count++) {
5512: $path.="/$parts[$count]";
5513: if (!-e $path) {
5514: print $logfile "\nCreating directory ".$path;
5515: mkdir($path,02770);
5516: }
5517: }
5518: my $versionresult;
5519: if (-e $copyfile) {
5520: $versionresult = &logo_versioning($targetdir,$file,$logfile);
5521: } else {
5522: $versionresult = 'ok';
5523: }
5524: if ($versionresult eq 'ok') {
5525: if (copy($source,$copyfile)) {
5526: print $logfile "\nCopied original source to ".$copyfile."\n";
5527: $output = 'ok';
5528: $logourl = '/res/'.$dom.'/'.$confname.'/'.$fname;
1.155 raeburn 5529: push(@{$modified_urls},[$copyfile,$source]);
5530: my $metaoutput =
5531: &write_metadata($dom,$confname,$formname,$targetdir,$file,$logfile);
5532: unless ($registered_cleanup) {
5533: my $handlers = $r->get_handlers('PerlCleanupHandler');
5534: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
5535: $registered_cleanup=1;
5536: }
1.9 raeburn 5537: } else {
5538: print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";
5539: $output = &mt('Failed to copy file to RES space').", $!";
5540: }
5541: if (($thumbwidth =~ /^\d+$/) && ($thumbheight =~ /^\d+$/)) {
5542: my $inputfile = $filepath.'/'.$file;
5543: my $outfile = $filepath.'/'.'tn-'.$file;
1.16 raeburn 5544: my ($fullwidth,$fullheight) = &check_dimensions($inputfile);
5545: if ($fullwidth ne '' && $fullheight ne '') {
5546: if ($fullwidth > $thumbwidth && $fullheight > $thumbheight) {
5547: my $thumbsize = $thumbwidth.'x'.$thumbheight;
5548: system("convert -sample $thumbsize $inputfile $outfile");
5549: chmod(0660, $filepath.'/tn-'.$file);
5550: if (-e $outfile) {
5551: my $copyfile=$targetdir.'/tn-'.$file;
5552: if (copy($outfile,$copyfile)) {
5553: print $logfile "\nCopied source to ".$copyfile."\n";
1.155 raeburn 5554: my $thumb_metaoutput =
5555: &write_metadata($dom,$confname,$formname,
5556: $targetdir,'tn-'.$file,$logfile);
5557: push(@{$modified_urls},[$copyfile,$outfile]);
5558: unless ($registered_cleanup) {
5559: my $handlers = $r->get_handlers('PerlCleanupHandler');
5560: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
5561: $registered_cleanup=1;
5562: }
1.16 raeburn 5563: } else {
5564: print $logfile "\nUnable to write ".$copyfile.
5565: ':'.$!."\n";
5566: }
5567: }
1.9 raeburn 5568: }
5569: }
5570: }
5571: } else {
5572: $output = $versionresult;
5573: }
5574: }
5575: return ($output,$logourl);
5576: }
5577:
5578: sub logo_versioning {
5579: my ($targetdir,$file,$logfile) = @_;
5580: my $target = $targetdir.'/'.$file;
5581: my ($maxversion,$fn,$extn,$output);
5582: $maxversion = 0;
5583: if ($file =~ /^(.+)\.(\w+)$/) {
5584: $fn=$1;
5585: $extn=$2;
5586: }
5587: opendir(DIR,$targetdir);
5588: while (my $filename=readdir(DIR)) {
5589: if ($filename=~/\Q$fn\E\.(\d+)\.\Q$extn\E$/) {
5590: $maxversion=($1>$maxversion)?$1:$maxversion;
5591: }
5592: }
5593: $maxversion++;
5594: print $logfile "\nCreating old version ".$maxversion."\n";
5595: my $copyfile=$targetdir.'/'.$fn.'.'.$maxversion.'.'.$extn;
5596: if (copy($target,$copyfile)) {
5597: print $logfile "Copied old target to ".$copyfile."\n";
5598: $copyfile=$copyfile.'.meta';
5599: if (copy($target.'.meta',$copyfile)) {
5600: print $logfile "Copied old target metadata to ".$copyfile."\n";
5601: $output = 'ok';
5602: } else {
5603: print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";
5604: $output = &mt('Failed to copy old meta').", $!, ";
5605: }
5606: } else {
5607: print $logfile "Unable to write ".$copyfile.':'.$!."\n";
5608: $output = &mt('Failed to copy old target').", $!, ";
5609: }
5610: return $output;
5611: }
5612:
5613: sub write_metadata {
5614: my ($dom,$confname,$formname,$targetdir,$file,$logfile) = @_;
5615: my (%metadatafields,%metadatakeys,$output);
5616: $metadatafields{'title'}=$formname;
5617: $metadatafields{'creationdate'}=time;
5618: $metadatafields{'lastrevisiondate'}=time;
5619: $metadatafields{'copyright'}='public';
5620: $metadatafields{'modifyinguser'}=$env{'user.name'}.':'.
5621: $env{'user.domain'};
5622: $metadatafields{'authorspace'}=$confname.':'.$dom;
5623: $metadatafields{'domain'}=$dom;
5624: {
5625: print $logfile "\nWrite metadata file for ".$targetdir.'/'.$file;
5626: my $mfh;
1.155 raeburn 5627: if (open($mfh,'>'.$targetdir.'/'.$file.'.meta')) {
1.184 raeburn 5628: foreach (sort(keys(%metadatafields))) {
1.155 raeburn 5629: unless ($_=~/\./) {
5630: my $unikey=$_;
5631: $unikey=~/^([A-Za-z]+)/;
5632: my $tag=$1;
5633: $tag=~tr/A-Z/a-z/;
5634: print $mfh "\n\<$tag";
5635: foreach (split(/\,/,$metadatakeys{$unikey})) {
5636: my $value=$metadatafields{$unikey.'.'.$_};
5637: $value=~s/\"/\'\'/g;
5638: print $mfh ' '.$_.'="'.$value.'"';
5639: }
5640: print $mfh '>'.
5641: &HTML::Entities::encode($metadatafields{$unikey},'<>&"')
5642: .'</'.$tag.'>';
5643: }
5644: }
5645: $output = 'ok';
5646: print $logfile "\nWrote metadata";
5647: close($mfh);
5648: } else {
5649: print $logfile "\nFailed to open metadata file";
1.9 raeburn 5650: $output = &mt('Could not write metadata');
5651: }
5652: }
1.155 raeburn 5653: return $output;
5654: }
5655:
5656: sub notifysubscribed {
5657: foreach my $targetsource (@{$modified_urls}){
5658: next unless (ref($targetsource) eq 'ARRAY');
5659: my ($target,$source)=@{$targetsource};
5660: if ($source ne '') {
5661: if (open(my $logfh,'>>'.$source.'.log')) {
5662: print $logfh "\nCleanup phase: Notifications\n";
5663: my @subscribed=&subscribed_hosts($target);
5664: foreach my $subhost (@subscribed) {
5665: print $logfh "\nNotifying host ".$subhost.':';
5666: my $reply=&Apache::lonnet::critical('update:'.$target,$subhost);
5667: print $logfh $reply;
5668: }
5669: my @subscribedmeta=&subscribed_hosts("$target.meta");
5670: foreach my $subhost (@subscribedmeta) {
5671: print $logfh "\nNotifying host for metadata only ".$subhost.':';
5672: my $reply=&Apache::lonnet::critical('update:'.$target.'.meta',
5673: $subhost);
5674: print $logfh $reply;
5675: }
5676: print $logfh "\n============ Done ============\n";
1.160 raeburn 5677: close($logfh);
1.155 raeburn 5678: }
5679: }
5680: }
5681: return OK;
5682: }
5683:
5684: sub subscribed_hosts {
5685: my ($target) = @_;
5686: my @subscribed;
5687: if (open(my $fh,"<$target.subscription")) {
5688: while (my $subline=<$fh>) {
5689: if ($subline =~ /^($match_lonid):/) {
5690: my $host = $1;
5691: if ($host ne $Apache::lonnet::perlvar{'lonHostID'}) {
5692: unless (grep(/^\Q$host\E$/,@subscribed)) {
5693: push(@subscribed,$host);
5694: }
5695: }
5696: }
5697: }
5698: }
5699: return @subscribed;
1.9 raeburn 5700: }
5701:
5702: sub check_switchserver {
5703: my ($dom,$confname) = @_;
5704: my ($allowed,$switchserver);
5705: my $home = &Apache::lonnet::homeserver($confname,$dom);
5706: if ($home eq 'no_host') {
5707: $home = &Apache::lonnet::domain($dom,'primary');
5708: }
5709: my @ids=&Apache::lonnet::current_machine_ids();
1.10 albertel 5710: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
5711: if (!$allowed) {
1.180 raeburn 5712: $switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role=dc./'.$dom.'/&destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
1.9 raeburn 5713: }
5714: return $switchserver;
5715: }
5716:
1.1 raeburn 5717: sub modify_quotas {
1.86 raeburn 5718: my ($dom,$action,%domconfig) = @_;
1.101 raeburn 5719: my ($context,@usertools,@options,%validations,%titles,%confhash,%toolshash,
5720: %limithash,$toolregexp,%conditions,$resulttext,%changes);
1.86 raeburn 5721: if ($action eq 'quotas') {
5722: $context = 'tools';
1.163 raeburn 5723: } else {
1.86 raeburn 5724: $context = $action;
5725: }
5726: if ($context eq 'requestcourses') {
1.98 raeburn 5727: @usertools = ('official','unofficial','community');
1.106 raeburn 5728: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 5729: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
5730: %titles = &courserequest_titles();
5731: $toolregexp = join('|',@usertools);
5732: %conditions = &courserequest_conditions();
1.163 raeburn 5733: } elsif ($context eq 'requestauthor') {
5734: @usertools = ('author');
5735: %titles = &authorrequest_titles();
1.86 raeburn 5736: } else {
1.162 raeburn 5737: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 5738: %titles = &tool_titles();
1.86 raeburn 5739: }
1.72 raeburn 5740: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.44 raeburn 5741: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 5742: foreach my $key (keys(%env)) {
1.101 raeburn 5743: if ($context eq 'requestcourses') {
5744: if ($key =~ /^form\.crsreq_($toolregexp)_(.+)$/) {
5745: my $item = $1;
5746: my $type = $2;
5747: if ($type =~ /^limit_(.+)/) {
5748: $limithash{$item}{$1} = $env{$key};
5749: } else {
5750: $confhash{$item}{$type} = $env{$key};
5751: }
5752: }
1.163 raeburn 5753: } elsif ($context eq 'requestauthor') {
5754: if ($key =~ /^\Qform.authorreq_\E(.+)$/) {
5755: $confhash{$1} = $env{$key};
5756: }
1.101 raeburn 5757: } else {
1.86 raeburn 5758: if ($key =~ /^form\.quota_(.+)$/) {
5759: $confhash{'defaultquota'}{$1} = $env{$key};
1.197 ! raeburn 5760: } elsif ($key =~ /^form\.authorquota_(.+)$/) {
! 5761: $confhash{'authorquota'}{$1} = $env{$key};
! 5762: } elsif ($key =~ /^form\.\Q$context\E_(.+)$/) {
1.101 raeburn 5763: @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key);
5764: }
1.72 raeburn 5765: }
5766: }
1.163 raeburn 5767: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.102 raeburn 5768: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.reqapprovalnotify');
5769: @approvalnotify = sort(@approvalnotify);
5770: $confhash{'notify'}{'approval'} = join(',',@approvalnotify);
5771: if (ref($domconfig{$action}) eq 'HASH') {
5772: if (ref($domconfig{$action}{'notify'}) eq 'HASH') {
5773: if ($domconfig{$action}{'notify'}{'approval'} ne $confhash{'notify'}{'approval'}) {
5774: $changes{'notify'}{'approval'} = 1;
5775: }
5776: } else {
1.144 raeburn 5777: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 5778: $changes{'notify'}{'approval'} = 1;
5779: }
5780: }
5781: } else {
1.144 raeburn 5782: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 5783: $changes{'notify'}{'approval'} = 1;
5784: }
5785: }
5786: } else {
1.86 raeburn 5787: $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
1.197 ! raeburn 5788: $confhash{'authorquota'}{'default'} = $env{'form.authorquota'};
1.86 raeburn 5789: }
1.72 raeburn 5790: foreach my $item (@usertools) {
5791: foreach my $type (@{$types},'default','_LC_adv') {
1.104 raeburn 5792: my $unset;
1.101 raeburn 5793: if ($context eq 'requestcourses') {
1.104 raeburn 5794: $unset = '0';
5795: if ($type eq '_LC_adv') {
5796: $unset = '';
5797: }
1.101 raeburn 5798: if ($confhash{$item}{$type} eq 'autolimit') {
5799: $confhash{$item}{$type} .= '=';
5800: unless ($limithash{$item}{$type} =~ /\D/) {
5801: $confhash{$item}{$type} .= $limithash{$item}{$type};
5802: }
5803: }
1.163 raeburn 5804: } elsif ($context eq 'requestauthor') {
5805: $unset = '0';
5806: if ($type eq '_LC_adv') {
5807: $unset = '';
5808: }
1.72 raeburn 5809: } else {
1.101 raeburn 5810: if (grep(/^\Q$type\E$/,@{$toolshash{$item}})) {
5811: $confhash{$item}{$type} = 1;
5812: } else {
5813: $confhash{$item}{$type} = 0;
5814: }
1.72 raeburn 5815: }
1.86 raeburn 5816: if (ref($domconfig{$action}) eq 'HASH') {
1.163 raeburn 5817: if ($action eq 'requestauthor') {
5818: if ($domconfig{$action}{$type} ne $confhash{$type}) {
5819: $changes{$type} = 1;
5820: }
5821: } elsif (ref($domconfig{$action}{$item}) eq 'HASH') {
1.86 raeburn 5822: if ($domconfig{$action}{$item}{$type} ne $confhash{$item}{$type}) {
5823: $changes{$item}{$type} = 1;
5824: }
5825: } else {
5826: if ($context eq 'requestcourses') {
1.104 raeburn 5827: if ($confhash{$item}{$type} ne $unset) {
1.86 raeburn 5828: $changes{$item}{$type} = 1;
5829: }
5830: } else {
5831: if (!$confhash{$item}{$type}) {
5832: $changes{$item}{$type} = 1;
5833: }
5834: }
5835: }
5836: } else {
5837: if ($context eq 'requestcourses') {
1.104 raeburn 5838: if ($confhash{$item}{$type} ne $unset) {
1.72 raeburn 5839: $changes{$item}{$type} = 1;
5840: }
1.163 raeburn 5841: } elsif ($context eq 'requestauthor') {
5842: if ($confhash{$type} ne $unset) {
5843: $changes{$type} = 1;
5844: }
1.72 raeburn 5845: } else {
5846: if (!$confhash{$item}{$type}) {
5847: $changes{$item}{$type} = 1;
5848: }
5849: }
5850: }
1.1 raeburn 5851: }
5852: }
1.163 raeburn 5853: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 5854: if (ref($domconfig{'quotas'}) eq 'HASH') {
5855: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
5856: foreach my $key (keys(%{$domconfig{'quotas'}{'defaultquota'}})) {
5857: if (exists($confhash{'defaultquota'}{$key})) {
5858: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{'defaultquota'}{$key}) {
5859: $changes{'defaultquota'}{$key} = 1;
5860: }
5861: } else {
5862: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{'defaultquota'}{$key};
1.72 raeburn 5863: }
5864: }
1.86 raeburn 5865: } else {
5866: foreach my $key (keys(%{$domconfig{'quotas'}})) {
5867: if (exists($confhash{'defaultquota'}{$key})) {
5868: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{$key}) {
5869: $changes{'defaultquota'}{$key} = 1;
5870: }
5871: } else {
5872: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{$key};
1.72 raeburn 5873: }
1.1 raeburn 5874: }
5875: }
1.197 ! raeburn 5876: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
! 5877: foreach my $key (keys(%{$domconfig{'quotas'}{'authorquota'}})) {
! 5878: if (exists($confhash{'authorquota'}{$key})) {
! 5879: if ($confhash{'authorquota'}{$key} ne $domconfig{'quotas'}{'authorquota'}{$key}) {
! 5880: $changes{'authorquota'}{$key} = 1;
! 5881: }
! 5882: } else {
! 5883: $confhash{'authorquota'}{$key} = $domconfig{'quotas'}{'authorquota'}{$key};
! 5884: }
! 5885: }
! 5886: }
1.1 raeburn 5887: }
1.86 raeburn 5888: if (ref($confhash{'defaultquota'}) eq 'HASH') {
5889: foreach my $key (keys(%{$confhash{'defaultquota'}})) {
5890: if (ref($domconfig{'quotas'}) eq 'HASH') {
5891: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
5892: if (!exists($domconfig{'quotas'}{'defaultquota'}{$key})) {
5893: $changes{'defaultquota'}{$key} = 1;
5894: }
5895: } else {
5896: if (!exists($domconfig{'quotas'}{$key})) {
5897: $changes{'defaultquota'}{$key} = 1;
5898: }
1.72 raeburn 5899: }
5900: } else {
1.86 raeburn 5901: $changes{'defaultquota'}{$key} = 1;
1.55 raeburn 5902: }
1.1 raeburn 5903: }
5904: }
1.197 ! raeburn 5905: if (ref($confhash{'authorquota'}) eq 'HASH') {
! 5906: foreach my $key (keys(%{$confhash{'authorquota'}})) {
! 5907: if (ref($domconfig{'quotas'}) eq 'HASH') {
! 5908: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
! 5909: if (!exists($domconfig{'quotas'}{'authorquota'}{$key})) {
! 5910: $changes{'authorquota'}{$key} = 1;
! 5911: }
! 5912: } else {
! 5913: $changes{'authorquota'}{$key} = 1;
! 5914: }
! 5915: } else {
! 5916: $changes{'authorquota'}{$key} = 1;
! 5917: }
! 5918: }
! 5919: }
1.1 raeburn 5920: }
1.72 raeburn 5921:
1.163 raeburn 5922: if ($context eq 'requestauthor') {
5923: $domdefaults{'requestauthor'} = \%confhash;
5924: } else {
5925: foreach my $key (keys(%confhash)) {
5926: $domdefaults{$key} = $confhash{$key};
5927: }
1.72 raeburn 5928: }
1.163 raeburn 5929:
1.1 raeburn 5930: my %quotahash = (
1.86 raeburn 5931: $action => { %confhash }
1.1 raeburn 5932: );
5933: my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
5934: $dom);
5935: if ($putresult eq 'ok') {
5936: if (keys(%changes) > 0) {
1.72 raeburn 5937: my $cachetime = 24*60*60;
5938: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
5939:
1.1 raeburn 5940: $resulttext = &mt('Changes made:').'<ul>';
1.163 raeburn 5941: unless (($context eq 'requestcourses') ||
5942: ($context eq 'requestauthor')) {
1.86 raeburn 5943: if (ref($changes{'defaultquota'}) eq 'HASH') {
5944: $resulttext .= '<li>'.&mt('Portfolio default quotas').'<ul>';
5945: foreach my $type (@{$types},'default') {
5946: if (defined($changes{'defaultquota'}{$type})) {
5947: my $typetitle = $usertypes->{$type};
5948: if ($type eq 'default') {
5949: $typetitle = $othertitle;
5950: }
5951: $resulttext .= '<li>'.&mt('[_1] set to [_2] Mb',$typetitle,$confhash{'defaultquota'}{$type}).'</li>';
1.72 raeburn 5952: }
5953: }
1.86 raeburn 5954: $resulttext .= '</ul></li>';
1.72 raeburn 5955: }
1.197 ! raeburn 5956: if (ref($changes{'authorquota'}) eq 'HASH') {
! 5957: $resulttext .= '<li>'.&mt('Authoring space default quotas').'<ul>';
! 5958: foreach my $type (@{$types},'default') {
! 5959: if (defined($changes{'authorquota'}{$type})) {
! 5960: my $typetitle = $usertypes->{$type};
! 5961: if ($type eq 'default') {
! 5962: $typetitle = $othertitle;
! 5963: }
! 5964: $resulttext .= '<li>'.&mt('[_1] set to [_2] Mb',$typetitle,$confhash{'authorquota'}{$type}).'</li>';
! 5965: }
! 5966: }
! 5967: $resulttext .= '</ul></li>';
! 5968: }
1.72 raeburn 5969: }
1.80 raeburn 5970: my %newenv;
1.72 raeburn 5971: foreach my $item (@usertools) {
1.163 raeburn 5972: my (%haschgs,%inconf);
5973: if ($context eq 'requestauthor') {
5974: %haschgs = %changes;
5975: %inconf = %confhash;
5976: } else {
5977: if (ref($changes{$item}) eq 'HASH') {
5978: %haschgs = %{$changes{$item}};
5979: }
5980: if (ref($confhash{$item}) eq 'HASH') {
5981: %inconf = %{$confhash{$item}};
5982: }
5983: }
5984: if (keys(%haschgs) > 0) {
1.80 raeburn 5985: my $newacc =
5986: &Apache::lonnet::usertools_access($env{'user.name'},
5987: $env{'user.domain'},
1.86 raeburn 5988: $item,'reload',$context);
1.163 raeburn 5989: if (($context eq 'requestcourses') ||
5990: ($context eq 'requestauthor')) {
1.108 raeburn 5991: if ($env{'environment.canrequest.'.$item} ne $newacc) {
5992: $newenv{'environment.canrequest.'.$item} = $newacc;
1.86 raeburn 5993: }
5994: } else {
5995: if ($env{'environment.availabletools.'.$item} ne $newacc) {
5996: $newenv{'environment.availabletools.'.$item} = $newacc;
5997: }
1.80 raeburn 5998: }
1.163 raeburn 5999: unless ($context eq 'requestauthor') {
6000: $resulttext .= '<li>'.$titles{$item}.'<ul>';
6001: }
1.72 raeburn 6002: foreach my $type (@{$types},'default','_LC_adv') {
1.163 raeburn 6003: if ($haschgs{$type}) {
1.72 raeburn 6004: my $typetitle = $usertypes->{$type};
6005: if ($type eq 'default') {
6006: $typetitle = $othertitle;
6007: } elsif ($type eq '_LC_adv') {
6008: $typetitle = 'LON-CAPA Advanced Users';
6009: }
1.163 raeburn 6010: if ($inconf{$type}) {
1.101 raeburn 6011: if ($context eq 'requestcourses') {
6012: my $cond;
1.163 raeburn 6013: if ($inconf{$type} =~ /^autolimit=(\d*)$/) {
1.101 raeburn 6014: if ($1 eq '') {
6015: $cond = &mt('(Automatic processing of any request).');
6016: } else {
6017: $cond = &mt('(Automatic processing of requests up to limit of [quant,_1,request] per user).',$1);
6018: }
6019: } else {
1.163 raeburn 6020: $cond = $conditions{$inconf{$type}};
1.101 raeburn 6021: }
6022: $resulttext .= '<li>'.&mt('Set to be available to [_1].',$typetitle).' '.$cond.'</li>';
1.172 raeburn 6023: } elsif ($context eq 'requestauthor') {
6024: $resulttext .= '<li>'.&mt('Set to "[_1]" for "[_2]".',
6025: $titles{$inconf{$type}},$typetitle);
6026:
1.101 raeburn 6027: } else {
6028: $resulttext .= '<li>'.&mt('Set to be available to [_1]',$typetitle).'</li>';
6029: }
1.72 raeburn 6030: } else {
1.104 raeburn 6031: if ($type eq '_LC_adv') {
1.163 raeburn 6032: if ($inconf{$type} eq '0') {
1.104 raeburn 6033: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
6034: } else {
6035: $resulttext .= '<li>'.&mt('No override set for [_1]',$typetitle).'</li>';
6036: }
6037: } else {
6038: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
6039: }
1.72 raeburn 6040: }
6041: }
1.26 raeburn 6042: }
1.163 raeburn 6043: unless ($context eq 'requestauthor') {
6044: $resulttext .= '</ul></li>';
6045: }
1.26 raeburn 6046: }
1.1 raeburn 6047: }
1.163 raeburn 6048: if (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.102 raeburn 6049: if (ref($changes{'notify'}) eq 'HASH') {
6050: if ($changes{'notify'}{'approval'}) {
6051: if (ref($confhash{'notify'}) eq 'HASH') {
6052: if ($confhash{'notify'}{'approval'}) {
6053: $resulttext .= '<li>'.&mt('Notification of requests requiring approval will be sent to: ').$confhash{'notify'}{'approval'}.'</li>';
6054: } else {
1.163 raeburn 6055: $resulttext .= '<li>'.&mt('No Domain Coordinators will receive notification of requests requiring approval.').'</li>';
1.102 raeburn 6056: }
6057: }
6058: }
6059: }
6060: }
1.1 raeburn 6061: $resulttext .= '</ul>';
1.80 raeburn 6062: if (keys(%newenv)) {
6063: &Apache::lonnet::appenv(\%newenv);
6064: }
1.1 raeburn 6065: } else {
1.86 raeburn 6066: if ($context eq 'requestcourses') {
6067: $resulttext = &mt('No changes made to rights to request creation of courses.');
1.163 raeburn 6068: } elsif ($context eq 'requestauthor') {
6069: $resulttext = &mt('No changes made to rights to request author space.');
1.86 raeburn 6070: } else {
1.90 weissno 6071: $resulttext = &mt('No changes made to availability of personal information pages, blogs, portfolios or default quotas');
1.86 raeburn 6072: }
1.1 raeburn 6073: }
6074: } else {
1.11 albertel 6075: $resulttext = '<span class="LC_error">'.
6076: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 6077: }
1.3 raeburn 6078: return $resulttext;
1.1 raeburn 6079: }
6080:
1.3 raeburn 6081: sub modify_autoenroll {
6082: my ($dom,%domconfig) = @_;
1.1 raeburn 6083: my ($resulttext,%changes);
6084: my %currautoenroll;
6085: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
6086: foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
6087: $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
6088: }
6089: }
6090: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
6091: my %title = ( run => 'Auto-enrollment active',
1.129 raeburn 6092: sender => 'Sender for notification messages',
6093: coowners => 'Automatic assignment of co-ownership to instructors of record (institutional data)');
1.1 raeburn 6094: my @offon = ('off','on');
1.17 raeburn 6095: my $sender_uname = $env{'form.sender_uname'};
6096: my $sender_domain = $env{'form.sender_domain'};
6097: if ($sender_domain eq '') {
6098: $sender_uname = '';
6099: } elsif ($sender_uname eq '') {
6100: $sender_domain = '';
6101: }
1.129 raeburn 6102: my $coowners = $env{'form.autoassign_coowners'};
1.1 raeburn 6103: my %autoenrollhash = (
1.129 raeburn 6104: autoenroll => { 'run' => $env{'form.autoenroll_run'},
6105: 'sender_uname' => $sender_uname,
6106: 'sender_domain' => $sender_domain,
6107: 'co-owners' => $coowners,
1.1 raeburn 6108: }
6109: );
1.4 raeburn 6110: my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
6111: $dom);
1.1 raeburn 6112: if ($putresult eq 'ok') {
6113: if (exists($currautoenroll{'run'})) {
6114: if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
6115: $changes{'run'} = 1;
6116: }
6117: } elsif ($autorun) {
6118: if ($env{'form.autoenroll_run'} ne '1') {
1.23 raeburn 6119: $changes{'run'} = 1;
1.1 raeburn 6120: }
6121: }
1.17 raeburn 6122: if ($currautoenroll{'sender_uname'} ne $sender_uname) {
1.1 raeburn 6123: $changes{'sender'} = 1;
6124: }
1.17 raeburn 6125: if ($currautoenroll{'sender_domain'} ne $sender_domain) {
1.1 raeburn 6126: $changes{'sender'} = 1;
6127: }
1.129 raeburn 6128: if ($currautoenroll{'co-owners'} ne '') {
6129: if ($currautoenroll{'co-owners'} ne $coowners) {
6130: $changes{'coowners'} = 1;
6131: }
6132: } elsif ($coowners) {
6133: $changes{'coowners'} = 1;
6134: }
1.1 raeburn 6135: if (keys(%changes) > 0) {
6136: $resulttext = &mt('Changes made:').'<ul>';
1.3 raeburn 6137: if ($changes{'run'}) {
1.1 raeburn 6138: $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
6139: }
6140: if ($changes{'sender'}) {
1.17 raeburn 6141: if ($sender_uname eq '' || $sender_domain eq '') {
6142: $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
6143: } else {
6144: $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
6145: }
1.1 raeburn 6146: }
1.129 raeburn 6147: if ($changes{'coowners'}) {
6148: $resulttext .= '<li>'.&mt("$title{'coowners'} set to $offon[$env{'form.autoassign_coowners'}]").'</li>';
6149: &Apache::loncommon::devalidate_domconfig_cache($dom);
6150: }
1.1 raeburn 6151: $resulttext .= '</ul>';
6152: } else {
6153: $resulttext = &mt('No changes made to auto-enrollment settings');
6154: }
6155: } else {
1.11 albertel 6156: $resulttext = '<span class="LC_error">'.
6157: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 6158: }
1.3 raeburn 6159: return $resulttext;
1.1 raeburn 6160: }
6161:
6162: sub modify_autoupdate {
1.3 raeburn 6163: my ($dom,%domconfig) = @_;
1.1 raeburn 6164: my ($resulttext,%currautoupdate,%fields,%changes);
6165: if (ref($domconfig{'autoupdate'}) eq 'HASH') {
6166: foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
6167: $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
6168: }
6169: }
6170: my @offon = ('off','on');
6171: my %title = &Apache::lonlocal::texthash (
6172: run => 'Auto-update:',
6173: classlists => 'Updates to user information in classlists?'
6174: );
1.44 raeburn 6175: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 6176: my %fieldtitles = &Apache::lonlocal::texthash (
6177: id => 'Student/Employee ID',
1.20 raeburn 6178: permanentemail => 'E-mail address',
1.1 raeburn 6179: lastname => 'Last Name',
6180: firstname => 'First Name',
6181: middlename => 'Middle Name',
1.132 raeburn 6182: generation => 'Generation',
1.1 raeburn 6183: );
1.142 raeburn 6184: $othertitle = &mt('All users');
1.1 raeburn 6185: if (keys(%{$usertypes}) > 0) {
1.26 raeburn 6186: $othertitle = &mt('Other users');
1.1 raeburn 6187: }
6188: foreach my $key (keys(%env)) {
6189: if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
1.132 raeburn 6190: my ($usertype,$item) = ($1,$2);
6191: if (grep(/^\Q$item\E$/,keys(%fieldtitles))) {
6192: if ($usertype eq 'default') {
6193: push(@{$fields{$1}},$2);
6194: } elsif (ref($types) eq 'ARRAY') {
6195: if (grep(/^\Q$usertype\E$/,@{$types})) {
6196: push(@{$fields{$1}},$2);
6197: }
6198: }
6199: }
1.1 raeburn 6200: }
6201: }
1.131 raeburn 6202: my @lockablenames = &Apache::loncommon::get_env_multiple('form.lockablenames');
6203: @lockablenames = sort(@lockablenames);
6204: if (ref($currautoupdate{'lockablenames'}) eq 'ARRAY') {
6205: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
6206: if (@changed) {
6207: $changes{'lockablenames'} = 1;
6208: }
6209: } else {
6210: if (@lockablenames) {
6211: $changes{'lockablenames'} = 1;
6212: }
6213: }
1.1 raeburn 6214: my %updatehash = (
6215: autoupdate => { run => $env{'form.autoupdate_run'},
6216: classlists => $env{'form.classlists'},
6217: fields => {%fields},
1.131 raeburn 6218: lockablenames => \@lockablenames,
1.1 raeburn 6219: }
6220: );
6221: foreach my $key (keys(%currautoupdate)) {
6222: if (($key eq 'run') || ($key eq 'classlists')) {
6223: if (exists($updatehash{autoupdate}{$key})) {
6224: if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
6225: $changes{$key} = 1;
6226: }
6227: }
6228: } elsif ($key eq 'fields') {
6229: if (ref($currautoupdate{$key}) eq 'HASH') {
1.26 raeburn 6230: foreach my $item (@{$types},'default') {
1.1 raeburn 6231: if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
6232: my $change = 0;
6233: foreach my $type (@{$currautoupdate{$key}{$item}}) {
6234: if (!exists($fields{$item})) {
6235: $change = 1;
1.132 raeburn 6236: last;
1.1 raeburn 6237: } elsif (ref($fields{$item}) eq 'ARRAY') {
1.26 raeburn 6238: if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
1.1 raeburn 6239: $change = 1;
1.132 raeburn 6240: last;
1.1 raeburn 6241: }
6242: }
6243: }
6244: if ($change) {
6245: push(@{$changes{$key}},$item);
6246: }
1.26 raeburn 6247: }
1.1 raeburn 6248: }
6249: }
1.131 raeburn 6250: } elsif ($key eq 'lockablenames') {
6251: if (ref($currautoupdate{$key}) eq 'ARRAY') {
6252: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
6253: if (@changed) {
6254: $changes{'lockablenames'} = 1;
6255: }
6256: } else {
6257: if (@lockablenames) {
6258: $changes{'lockablenames'} = 1;
6259: }
6260: }
6261: }
6262: }
6263: unless (grep(/^\Qlockablenames\E$/,keys(%currautoupdate))) {
6264: if (@lockablenames) {
6265: $changes{'lockablenames'} = 1;
1.1 raeburn 6266: }
6267: }
1.26 raeburn 6268: foreach my $item (@{$types},'default') {
6269: if (defined($fields{$item})) {
6270: if (ref($currautoupdate{'fields'}) eq 'HASH') {
1.132 raeburn 6271: if (ref($currautoupdate{'fields'}{$item}) eq 'ARRAY') {
6272: my $change = 0;
6273: if (ref($fields{$item}) eq 'ARRAY') {
6274: foreach my $type (@{$fields{$item}}) {
6275: if (!grep(/^\Q$type\E$/,@{$currautoupdate{'fields'}{$item}})) {
6276: $change = 1;
6277: last;
6278: }
6279: }
6280: }
6281: if ($change) {
6282: push(@{$changes{'fields'}},$item);
6283: }
6284: } else {
1.26 raeburn 6285: push(@{$changes{'fields'}},$item);
6286: }
6287: } else {
6288: push(@{$changes{'fields'}},$item);
1.1 raeburn 6289: }
6290: }
6291: }
6292: my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
6293: $dom);
6294: if ($putresult eq 'ok') {
6295: if (keys(%changes) > 0) {
6296: $resulttext = &mt('Changes made:').'<ul>';
6297: foreach my $key (sort(keys(%changes))) {
1.131 raeburn 6298: if ($key eq 'lockablenames') {
6299: $resulttext .= '<li>';
6300: if (@lockablenames) {
6301: $usertypes->{'default'} = $othertitle;
6302: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update), available for the following affiliations:").' '.
6303: join(', ', map { $usertypes->{$_}; } @lockablenames).'</li>';
6304: } else {
6305: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update) is unavailable.");
6306: }
6307: $resulttext .= '</li>';
6308: } elsif (ref($changes{$key}) eq 'ARRAY') {
1.1 raeburn 6309: foreach my $item (@{$changes{$key}}) {
6310: my @newvalues;
6311: foreach my $type (@{$fields{$item}}) {
6312: push(@newvalues,$fieldtitles{$type});
6313: }
1.3 raeburn 6314: my $newvaluestr;
6315: if (@newvalues > 0) {
6316: $newvaluestr = join(', ',@newvalues);
6317: } else {
6318: $newvaluestr = &mt('none');
1.6 raeburn 6319: }
1.1 raeburn 6320: if ($item eq 'default') {
1.26 raeburn 6321: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
1.1 raeburn 6322: } else {
1.26 raeburn 6323: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
1.1 raeburn 6324: }
6325: }
6326: } else {
6327: my $newvalue;
6328: if ($key eq 'run') {
6329: $newvalue = $offon[$env{'form.autoupdate_run'}];
6330: } else {
6331: $newvalue = $offon[$env{'form.'.$key}];
1.3 raeburn 6332: }
1.1 raeburn 6333: $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
6334: }
6335: }
6336: $resulttext .= '</ul>';
6337: } else {
1.3 raeburn 6338: $resulttext = &mt('No changes made to autoupdates');
1.1 raeburn 6339: }
6340: } else {
1.11 albertel 6341: $resulttext = '<span class="LC_error">'.
6342: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 6343: }
1.3 raeburn 6344: return $resulttext;
1.1 raeburn 6345: }
6346:
1.125 raeburn 6347: sub modify_autocreate {
6348: my ($dom,%domconfig) = @_;
6349: my ($resulttext,%changes,%currautocreate,%newvals,%autocreatehash);
6350: if (ref($domconfig{'autocreate'}) eq 'HASH') {
6351: foreach my $key (keys(%{$domconfig{'autocreate'}})) {
6352: $currautocreate{$key} = $domconfig{'autocreate'}{$key};
6353: }
6354: }
6355: my %title= ( xml => 'Auto-creation of courses in XML course description files',
6356: req => 'Auto-creation of validated requests for official courses',
6357: xmldc => 'Identity of course creator of courses from XML files',
6358: );
6359: my @types = ('xml','req');
6360: foreach my $item (@types) {
6361: $newvals{$item} = $env{'form.autocreate_'.$item};
6362: $newvals{$item} =~ s/\D//g;
6363: $newvals{$item} = 0 if ($newvals{$item} eq '');
6364: }
6365: $newvals{'xmldc'} = $env{'form.autocreate_xmldc'};
6366: my %domcoords = &get_active_dcs($dom);
6367: unless (exists($domcoords{$newvals{'xmldc'}})) {
6368: $newvals{'xmldc'} = '';
6369: }
6370: %autocreatehash = (
6371: autocreate => { xml => $newvals{'xml'},
6372: req => $newvals{'req'},
6373: }
6374: );
6375: if ($newvals{'xmldc'} ne '') {
6376: $autocreatehash{'autocreate'}{'xmldc'} = $newvals{'xmldc'};
6377: }
6378: my $putresult = &Apache::lonnet::put_dom('configuration',\%autocreatehash,
6379: $dom);
6380: if ($putresult eq 'ok') {
6381: my @items = @types;
6382: if ($newvals{'xml'}) {
6383: push(@items,'xmldc');
6384: }
6385: foreach my $item (@items) {
6386: if (exists($currautocreate{$item})) {
6387: if ($currautocreate{$item} ne $newvals{$item}) {
6388: $changes{$item} = 1;
6389: }
6390: } elsif ($newvals{$item}) {
6391: $changes{$item} = 1;
6392: }
6393: }
6394: if (keys(%changes) > 0) {
6395: my @offon = ('off','on');
6396: $resulttext = &mt('Changes made:').'<ul>';
6397: foreach my $item (@types) {
6398: if ($changes{$item}) {
6399: my $newtxt = $offon[$newvals{$item}];
1.178 raeburn 6400: $resulttext .= '<li>'.
6401: &mt("$title{$item} set to [_1]$newtxt [_2]",
6402: '<b>','</b>').
6403: '</li>';
1.125 raeburn 6404: }
6405: }
6406: if ($changes{'xmldc'}) {
6407: my ($dcname,$dcdom) = split(':',$newvals{'xmldc'});
6408: my $newtxt = &Apache::loncommon::plainname($dcname,$dcdom);
1.178 raeburn 6409: $resulttext .= '<li>'.&mt("$title{'xmldc'} set to [_1]",'<b>'.$newtxt.'</b>').'</li>';
1.125 raeburn 6410: }
6411: $resulttext .= '</ul>';
6412: } else {
6413: $resulttext = &mt('No changes made to auto-creation settings');
6414: }
6415: } else {
6416: $resulttext = '<span class="LC_error">'.
6417: &mt('An error occurred: [_1]',$putresult).'</span>';
6418: }
6419: return $resulttext;
6420: }
6421:
1.23 raeburn 6422: sub modify_directorysrch {
6423: my ($dom,%domconfig) = @_;
6424: my ($resulttext,%changes);
6425: my %currdirsrch;
6426: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
6427: foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
6428: $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
6429: }
6430: }
6431: my %title = ( available => 'Directory search available',
1.24 raeburn 6432: localonly => 'Other domains can search',
1.23 raeburn 6433: searchby => 'Search types',
6434: searchtypes => 'Search latitude');
6435: my @offon = ('off','on');
1.24 raeburn 6436: my @otherdoms = ('Yes','No');
1.23 raeburn 6437:
1.25 raeburn 6438: my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');
1.23 raeburn 6439: my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
6440: my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
6441:
1.44 raeburn 6442: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.26 raeburn 6443: if (keys(%{$usertypes}) == 0) {
6444: @cansearch = ('default');
6445: } else {
6446: if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
6447: foreach my $type (@{$currdirsrch{'cansearch'}}) {
6448: if (!grep(/^\Q$type\E$/,@cansearch)) {
6449: push(@{$changes{'cansearch'}},$type);
6450: }
1.23 raeburn 6451: }
1.26 raeburn 6452: foreach my $type (@cansearch) {
6453: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
6454: push(@{$changes{'cansearch'}},$type);
6455: }
1.23 raeburn 6456: }
1.26 raeburn 6457: } else {
6458: push(@{$changes{'cansearch'}},@cansearch);
1.23 raeburn 6459: }
6460: }
6461:
6462: if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
6463: foreach my $by (@{$currdirsrch{'searchby'}}) {
6464: if (!grep(/^\Q$by\E$/,@searchby)) {
6465: push(@{$changes{'searchby'}},$by);
6466: }
6467: }
6468: foreach my $by (@searchby) {
6469: if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
6470: push(@{$changes{'searchby'}},$by);
6471: }
6472: }
6473: } else {
6474: push(@{$changes{'searchby'}},@searchby);
6475: }
1.25 raeburn 6476:
6477: if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
6478: foreach my $type (@{$currdirsrch{'searchtypes'}}) {
6479: if (!grep(/^\Q$type\E$/,@searchtypes)) {
6480: push(@{$changes{'searchtypes'}},$type);
6481: }
6482: }
6483: foreach my $type (@searchtypes) {
6484: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
6485: push(@{$changes{'searchtypes'}},$type);
6486: }
6487: }
6488: } else {
6489: if (exists($currdirsrch{'searchtypes'})) {
6490: foreach my $type (@searchtypes) {
6491: if ($type ne $currdirsrch{'searchtypes'}) {
6492: push(@{$changes{'searchtypes'}},$type);
6493: }
6494: }
6495: if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
6496: push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
6497: }
6498: } else {
6499: push(@{$changes{'searchtypes'}},@searchtypes);
6500: }
6501: }
6502:
1.23 raeburn 6503: my %dirsrch_hash = (
6504: directorysrch => { available => $env{'form.dirsrch_available'},
6505: cansearch => \@cansearch,
1.24 raeburn 6506: localonly => $env{'form.dirsrch_localonly'},
1.23 raeburn 6507: searchby => \@searchby,
1.25 raeburn 6508: searchtypes => \@searchtypes,
1.23 raeburn 6509: }
6510: );
6511: my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
6512: $dom);
6513: if ($putresult eq 'ok') {
6514: if (exists($currdirsrch{'available'})) {
6515: if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
6516: $changes{'available'} = 1;
6517: }
6518: } else {
6519: if ($env{'form.dirsrch_available'} eq '1') {
6520: $changes{'available'} = 1;
6521: }
6522: }
1.24 raeburn 6523: if (exists($currdirsrch{'localonly'})) {
6524: if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_localonly'}) {
6525: $changes{'localonly'} = 1;
6526: }
6527: } else {
6528: if ($env{'form.dirsrch_localonly'} eq '1') {
6529: $changes{'localonly'} = 1;
6530: }
6531: }
1.23 raeburn 6532: if (keys(%changes) > 0) {
6533: $resulttext = &mt('Changes made:').'<ul>';
6534: if ($changes{'available'}) {
6535: $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
6536: }
1.24 raeburn 6537: if ($changes{'localonly'}) {
6538: $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_localonly'}]").'</li>';
6539: }
6540:
1.23 raeburn 6541: if (ref($changes{'cansearch'}) eq 'ARRAY') {
6542: my $chgtext;
1.26 raeburn 6543: if (ref($usertypes) eq 'HASH') {
6544: if (keys(%{$usertypes}) > 0) {
6545: foreach my $type (@{$types}) {
6546: if (grep(/^\Q$type\E$/,@cansearch)) {
6547: $chgtext .= $usertypes->{$type}.'; ';
6548: }
6549: }
6550: if (grep(/^default$/,@cansearch)) {
6551: $chgtext .= $othertitle;
6552: } else {
6553: $chgtext =~ s/\; $//;
6554: }
1.178 raeburn 6555: $resulttext .=
6556: '<li>'.
6557: &mt("Users from domain '[_1]' permitted to search the institutional directory set to: [_2]",
6558: '<span class="LC_cusr_emph">'.$dom.'</span>',$chgtext).
6559: '</li>';
1.23 raeburn 6560: }
6561: }
6562: }
6563: if (ref($changes{'searchby'}) eq 'ARRAY') {
6564: my ($searchtitles,$titleorder) = &sorted_searchtitles();
6565: my $chgtext;
6566: foreach my $type (@{$titleorder}) {
6567: if (grep(/^\Q$type\E$/,@searchby)) {
6568: if (defined($searchtitles->{$type})) {
6569: $chgtext .= $searchtitles->{$type}.'; ';
6570: }
6571: }
6572: }
6573: $chgtext =~ s/\; $//;
6574: $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
6575: }
1.25 raeburn 6576: if (ref($changes{'searchtypes'}) eq 'ARRAY') {
6577: my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes();
6578: my $chgtext;
6579: foreach my $type (@{$srchtypeorder}) {
6580: if (grep(/^\Q$type\E$/,@searchtypes)) {
6581: if (defined($srchtypes_desc->{$type})) {
6582: $chgtext .= $srchtypes_desc->{$type}.'; ';
6583: }
6584: }
6585: }
6586: $chgtext =~ s/\; $//;
1.178 raeburn 6587: $resulttext .= '<li>'.&mt($title{'searchtypes'}.' set to: "[_1]"',$chgtext).'</li>';
1.23 raeburn 6588: }
6589: $resulttext .= '</ul>';
6590: } else {
6591: $resulttext = &mt('No changes made to institution directory search settings');
6592: }
6593: } else {
6594: $resulttext = '<span class="LC_error">'.
1.27 raeburn 6595: &mt('An error occurred: [_1]',$putresult).'</span>';
6596: }
6597: return $resulttext;
6598: }
6599:
1.28 raeburn 6600: sub modify_contacts {
6601: my ($dom,%domconfig) = @_;
6602: my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
6603: if (ref($domconfig{'contacts'}) eq 'HASH') {
6604: foreach my $key (keys(%{$domconfig{'contacts'}})) {
6605: $currsetting{$key} = $domconfig{'contacts'}{$key};
6606: }
6607: }
1.134 raeburn 6608: my (%others,%to,%bcc);
1.28 raeburn 6609: my @contacts = ('supportemail','adminemail');
1.102 raeburn 6610: my @mailings = ('errormail','packagesmail','helpdeskmail','lonstatusmail',
1.190 raeburn 6611: 'requestsmail','updatesmail');
1.28 raeburn 6612: foreach my $type (@mailings) {
6613: @{$newsetting{$type}} =
6614: &Apache::loncommon::get_env_multiple('form.'.$type);
6615: foreach my $item (@contacts) {
6616: if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
6617: $contacts_hash{contacts}{$type}{$item} = 1;
6618: } else {
6619: $contacts_hash{contacts}{$type}{$item} = 0;
6620: }
6621: }
6622: $others{$type} = $env{'form.'.$type.'_others'};
6623: $contacts_hash{contacts}{$type}{'others'} = $others{$type};
1.134 raeburn 6624: if ($type eq 'helpdeskmail') {
6625: $bcc{$type} = $env{'form.'.$type.'_bcc'};
6626: $contacts_hash{contacts}{$type}{'bcc'} = $bcc{$type};
6627: }
1.28 raeburn 6628: }
6629: foreach my $item (@contacts) {
6630: $to{$item} = $env{'form.'.$item};
6631: $contacts_hash{'contacts'}{$item} = $to{$item};
6632: }
6633: if (keys(%currsetting) > 0) {
6634: foreach my $item (@contacts) {
6635: if ($to{$item} ne $currsetting{$item}) {
6636: $changes{$item} = 1;
6637: }
6638: }
6639: foreach my $type (@mailings) {
6640: foreach my $item (@contacts) {
6641: if (ref($currsetting{$type}) eq 'HASH') {
6642: if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
6643: push(@{$changes{$type}},$item);
6644: }
6645: } else {
6646: push(@{$changes{$type}},@{$newsetting{$type}});
6647: }
6648: }
6649: if ($others{$type} ne $currsetting{$type}{'others'}) {
6650: push(@{$changes{$type}},'others');
6651: }
1.134 raeburn 6652: if ($type eq 'helpdeskmail') {
6653: if ($bcc{$type} ne $currsetting{$type}{'bcc'}) {
6654: push(@{$changes{$type}},'bcc');
6655: }
6656: }
1.28 raeburn 6657: }
6658: } else {
6659: my %default;
6660: $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
6661: $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
6662: $default{'errormail'} = 'adminemail';
6663: $default{'packagesmail'} = 'adminemail';
6664: $default{'helpdeskmail'} = 'supportemail';
1.89 raeburn 6665: $default{'lonstatusmail'} = 'adminemail';
1.102 raeburn 6666: $default{'requestsmail'} = 'adminemail';
1.190 raeburn 6667: $default{'updatesmail'} = 'adminemail';
1.28 raeburn 6668: foreach my $item (@contacts) {
6669: if ($to{$item} ne $default{$item}) {
6670: $changes{$item} = 1;
6671: }
6672: }
6673: foreach my $type (@mailings) {
6674: if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
6675:
6676: push(@{$changes{$type}},@{$newsetting{$type}});
6677: }
6678: if ($others{$type} ne '') {
6679: push(@{$changes{$type}},'others');
1.134 raeburn 6680: }
6681: if ($type eq 'helpdeskmail') {
6682: if ($bcc{$type} ne '') {
6683: push(@{$changes{$type}},'bcc');
6684: }
6685: }
1.28 raeburn 6686: }
6687: }
6688: my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
6689: $dom);
6690: if ($putresult eq 'ok') {
6691: if (keys(%changes) > 0) {
6692: my ($titles,$short_titles) = &contact_titles();
6693: $resulttext = &mt('Changes made:').'<ul>';
6694: foreach my $item (@contacts) {
6695: if ($changes{$item}) {
6696: $resulttext .= '<li>'.$titles->{$item}.
6697: &mt(' set to: ').
6698: '<span class="LC_cusr_emph">'.
6699: $to{$item}.'</span></li>';
6700: }
6701: }
6702: foreach my $type (@mailings) {
6703: if (ref($changes{$type}) eq 'ARRAY') {
6704: $resulttext .= '<li>'.$titles->{$type}.': ';
6705: my @text;
6706: foreach my $item (@{$newsetting{$type}}) {
6707: push(@text,$short_titles->{$item});
6708: }
6709: if ($others{$type} ne '') {
6710: push(@text,$others{$type});
6711: }
6712: $resulttext .= '<span class="LC_cusr_emph">'.
1.134 raeburn 6713: join(', ',@text).'</span>';
6714: if ($type eq 'helpdeskmail') {
6715: if ($bcc{$type} ne '') {
6716: $resulttext .= ' '.&mt('with Bcc to').': <span class="LC_cusr_emph">'.$bcc{$type}.'</span>';
6717: }
6718: }
6719: $resulttext .= '</li>';
1.28 raeburn 6720: }
6721: }
6722: $resulttext .= '</ul>';
6723: } else {
1.34 raeburn 6724: $resulttext = &mt('No changes made to contact information');
1.28 raeburn 6725: }
6726: } else {
6727: $resulttext = '<span class="LC_error">'.
6728: &mt('An error occurred: [_1].',$putresult).'</span>';
6729: }
6730: return $resulttext;
6731: }
6732:
6733: sub modify_usercreation {
1.27 raeburn 6734: my ($dom,%domconfig) = @_;
1.34 raeburn 6735: my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate);
1.43 raeburn 6736: my $warningmsg;
1.27 raeburn 6737: if (ref($domconfig{'usercreation'}) eq 'HASH') {
6738: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
6739: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
6740: }
6741: }
6742: my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
1.32 raeburn 6743: my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
1.43 raeburn 6744: my @email_rule = &Apache::loncommon::get_env_multiple('form.email_rule');
1.100 raeburn 6745: my @contexts = ('author','course','requestcrs','selfcreate');
1.34 raeburn 6746: foreach my $item(@contexts) {
1.45 raeburn 6747: if ($item eq 'selfcreate') {
1.50 raeburn 6748: @{$cancreate{$item}} = &Apache::loncommon::get_env_multiple('form.can_createuser_'.$item);
1.43 raeburn 6749: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
6750: if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) || ($domdefaults{'auth_def'} eq 'localauth'))) {
1.50 raeburn 6751: if (ref($cancreate{$item}) eq 'ARRAY') {
6752: if (grep(/^login$/,@{$cancreate{$item}})) {
6753: $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.');
6754: }
1.43 raeburn 6755: }
6756: }
1.50 raeburn 6757: } else {
6758: $cancreate{$item} = $env{'form.can_createuser_'.$item};
1.43 raeburn 6759: }
1.34 raeburn 6760: }
1.93 raeburn 6761: my ($othertitle,$usertypes,$types) =
6762: &Apache::loncommon::sorted_inst_types($dom);
6763: if (ref($types) eq 'ARRAY') {
6764: if (@{$types} > 0) {
6765: @{$cancreate{'statustocreate'}} =
6766: &Apache::loncommon::get_env_multiple('form.statustocreate');
1.103 raeburn 6767: } else {
6768: @{$cancreate{'statustocreate'}} = ();
1.93 raeburn 6769: }
6770: push(@contexts,'statustocreate');
6771: }
1.165 raeburn 6772: &process_captcha('cancreate',\%changes,\%cancreate,\%curr_usercreation);
1.34 raeburn 6773: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
6774: foreach my $item (@contexts) {
1.93 raeburn 6775: if (($item eq 'selfcreate') || ($item eq 'statustocreate')) {
6776: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
1.50 raeburn 6777: foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
1.103 raeburn 6778: if (ref($cancreate{$item}) eq 'ARRAY') {
6779: if (!grep(/^$curr$/,@{$cancreate{$item}})) {
6780: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6781: push(@{$changes{'cancreate'}},$item);
6782: }
1.50 raeburn 6783: }
6784: }
6785: }
6786: } else {
6787: if ($curr_usercreation{'cancreate'}{$item} eq '') {
6788: if (@{$cancreate{$item}} > 0) {
6789: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6790: push(@{$changes{'cancreate'}},$item);
6791: }
6792: }
6793: } else {
6794: if ($curr_usercreation{'cancreate'}{$item} eq 'any') {
6795: if (@{$cancreate{$item}} < 3) {
6796: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6797: push(@{$changes{'cancreate'}},$item);
6798: }
6799: }
6800: } elsif ($curr_usercreation{'cancreate'}{$item} eq 'none') {
6801: if (@{$cancreate{$item}} > 0) {
6802: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6803: push(@{$changes{'cancreate'}},$item);
6804: }
6805: }
6806: } elsif (!grep(/^$curr_usercreation{'cancreate'}{$item}$/,@{$cancreate{$item}})) {
6807: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6808: push(@{$changes{'cancreate'}},$item);
6809: }
6810: }
6811: }
6812: }
6813: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6814: foreach my $type (@{$cancreate{$item}}) {
6815: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
6816: if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
6817: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6818: push(@{$changes{'cancreate'}},$item);
6819: }
6820: }
6821: } elsif (($curr_usercreation{'cancreate'}{$item} ne 'any') &&
6822: ($curr_usercreation{'cancreate'}{$item} ne 'none')) {
6823: if ($curr_usercreation{'cancreate'}{$item} ne $type) {
6824: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6825: push(@{$changes{'cancreate'}},$item);
6826: }
6827: }
6828: }
6829: }
6830: }
6831: } else {
6832: if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
6833: push(@{$changes{'cancreate'}},$item);
6834: }
6835: }
1.27 raeburn 6836: }
1.34 raeburn 6837: } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
6838: foreach my $item (@contexts) {
1.43 raeburn 6839: if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
1.34 raeburn 6840: if ($cancreate{$item} ne 'any') {
6841: push(@{$changes{'cancreate'}},$item);
6842: }
6843: } else {
6844: if ($cancreate{$item} ne 'none') {
6845: push(@{$changes{'cancreate'}},$item);
6846: }
1.27 raeburn 6847: }
6848: }
6849: } else {
1.43 raeburn 6850: foreach my $item (@contexts) {
1.34 raeburn 6851: push(@{$changes{'cancreate'}},$item);
6852: }
1.27 raeburn 6853: }
1.34 raeburn 6854:
1.27 raeburn 6855: if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
6856: foreach my $type (@{$curr_usercreation{'username_rule'}}) {
6857: if (!grep(/^\Q$type\E$/,@username_rule)) {
6858: push(@{$changes{'username_rule'}},$type);
6859: }
6860: }
6861: foreach my $type (@username_rule) {
6862: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
6863: push(@{$changes{'username_rule'}},$type);
6864: }
6865: }
6866: } else {
6867: push(@{$changes{'username_rule'}},@username_rule);
6868: }
6869:
1.32 raeburn 6870: if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
6871: foreach my $type (@{$curr_usercreation{'id_rule'}}) {
6872: if (!grep(/^\Q$type\E$/,@id_rule)) {
6873: push(@{$changes{'id_rule'}},$type);
6874: }
6875: }
6876: foreach my $type (@id_rule) {
6877: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
6878: push(@{$changes{'id_rule'}},$type);
6879: }
6880: }
6881: } else {
6882: push(@{$changes{'id_rule'}},@id_rule);
6883: }
6884:
1.43 raeburn 6885: if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
6886: foreach my $type (@{$curr_usercreation{'email_rule'}}) {
6887: if (!grep(/^\Q$type\E$/,@email_rule)) {
6888: push(@{$changes{'email_rule'}},$type);
6889: }
6890: }
6891: foreach my $type (@email_rule) {
6892: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'email_rule'}})) {
6893: push(@{$changes{'email_rule'}},$type);
6894: }
6895: }
6896: } else {
6897: push(@{$changes{'email_rule'}},@email_rule);
6898: }
6899:
6900: my @authen_contexts = ('author','course','domain');
1.28 raeburn 6901: my @authtypes = ('int','krb4','krb5','loc');
6902: my %authhash;
1.43 raeburn 6903: foreach my $item (@authen_contexts) {
1.28 raeburn 6904: my @authallowed = &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
6905: foreach my $auth (@authtypes) {
6906: if (grep(/^\Q$auth\E$/,@authallowed)) {
6907: $authhash{$item}{$auth} = 1;
6908: } else {
6909: $authhash{$item}{$auth} = 0;
6910: }
6911: }
6912: }
6913: if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
1.43 raeburn 6914: foreach my $item (@authen_contexts) {
1.28 raeburn 6915: if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
6916: foreach my $auth (@authtypes) {
6917: if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
6918: push(@{$changes{'authtypes'}},$item);
6919: last;
6920: }
6921: }
6922: }
6923: }
6924: } else {
1.43 raeburn 6925: foreach my $item (@authen_contexts) {
1.28 raeburn 6926: push(@{$changes{'authtypes'}},$item);
6927: }
6928: }
6929:
1.27 raeburn 6930: my %usercreation_hash = (
1.28 raeburn 6931: usercreation => {
1.34 raeburn 6932: cancreate => \%cancreate,
1.27 raeburn 6933: username_rule => \@username_rule,
1.32 raeburn 6934: id_rule => \@id_rule,
1.43 raeburn 6935: email_rule => \@email_rule,
1.32 raeburn 6936: authtypes => \%authhash,
1.27 raeburn 6937: }
6938: );
6939:
6940: my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
6941: $dom);
1.50 raeburn 6942:
6943: my %selfcreatetypes = (
6944: sso => 'users authenticated by institutional single sign on',
6945: login => 'users authenticated by institutional log-in',
6946: email => 'users who provide a valid e-mail address for use as the username',
6947: );
1.27 raeburn 6948: if ($putresult eq 'ok') {
6949: if (keys(%changes) > 0) {
6950: $resulttext = &mt('Changes made:').'<ul>';
6951: if (ref($changes{'cancreate'}) eq 'ARRAY') {
1.34 raeburn 6952: my %lt = &usercreation_types();
6953: foreach my $type (@{$changes{'cancreate'}}) {
1.100 raeburn 6954: my $chgtext;
1.165 raeburn 6955: unless (($type eq 'statustocreate') || ($type eq 'captcha') || ($type eq 'recaptchakeys')) {
1.100 raeburn 6956: $chgtext = $lt{$type}.', ';
6957: }
1.45 raeburn 6958: if ($type eq 'selfcreate') {
1.50 raeburn 6959: if (@{$cancreate{$type}} == 0) {
1.43 raeburn 6960: $chgtext .= &mt('creation of a new user account is not permitted.');
1.50 raeburn 6961: } else {
1.100 raeburn 6962: $chgtext .= &mt('creation of a new account is permitted for:').'<ul>';
1.50 raeburn 6963: foreach my $case (@{$cancreate{$type}}) {
6964: $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
6965: }
6966: $chgtext .= '</ul>';
1.100 raeburn 6967: if (ref($cancreate{$type}) eq 'ARRAY') {
6968: if (grep(/^(login|sso)$/,@{$cancreate{$type}})) {
6969: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
6970: if (@{$cancreate{'statustocreate'}} == 0) {
6971: $chgtext .= '<br /><span class="LC_warning">'.&mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").'</span>';
6972: }
6973: }
6974: }
6975: }
1.43 raeburn 6976: }
1.93 raeburn 6977: } elsif ($type eq 'statustocreate') {
1.96 raeburn 6978: if ((ref($cancreate{'selfcreate'}) eq 'ARRAY') &&
6979: (ref($cancreate{'statustocreate'}) eq 'ARRAY')) {
6980: if (@{$cancreate{'selfcreate'}} > 0) {
6981: if (@{$cancreate{'statustocreate'}} == 0) {
1.100 raeburn 6982:
6983: $chgtext .= &mt("Institutional affiliations permitted to create accounts set to 'None'.");
1.96 raeburn 6984: if (!grep(/^email$/,@{$cancreate{'selfcreate'}})) {
1.100 raeburn 6985: $chgtext .= '<br /><span class="LC_warning">'.&mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").'</span>';
6986: }
1.96 raeburn 6987: } elsif (ref($usertypes) eq 'HASH') {
6988: if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.100 raeburn 6989: $chgtext .= &mt('Creation of a new account for an institutional user is restricted to the following institutional affiliation(s):');
6990: } else {
6991: $chgtext .= &mt('Institutional affiliations permitted to create accounts with institutional authentication were set as follows:');
6992: }
6993: $chgtext .= '<ul>';
6994: foreach my $case (@{$cancreate{$type}}) {
6995: if ($case eq 'default') {
6996: $chgtext .= '<li>'.$othertitle.'</li>';
6997: } else {
6998: $chgtext .= '<li>'.$usertypes->{$case}.'</li>';
1.93 raeburn 6999: }
7000: }
1.100 raeburn 7001: $chgtext .= '</ul>';
7002: if (!grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
7003: $chgtext .= '<br /><span class="LC_warning">'.&mt('However, users authenticated by institutional login/single sign on are not currently permitted to create accounts.').'</span>';
7004: }
7005: }
7006: } else {
7007: if (@{$cancreate{$type}} == 0) {
7008: $chgtext .= &mt("Institutional affiliations permitted to create accounts were set to 'none'.");
7009: } else {
7010: $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 7011: }
7012: }
7013: }
1.165 raeburn 7014: } elsif ($type eq 'captcha') {
7015: if ($cancreate{$type} eq 'notused') {
7016: $chgtext .= &mt('No CAPTCHA validation in use for self-creation screen.');
7017: } else {
7018: my %captchas = &captcha_phrases();
7019: if ($captchas{$cancreate{$type}}) {
7020: $chgtext .= &mt("Validation for self-creation screen set to $captchas{$cancreate{$type}}.");
7021: } else {
7022: $chgtext .= &mt('Validation for self-creation screen set to unknown type.');
7023: }
7024: }
7025: } elsif ($type eq 'recaptchakeys') {
7026: my ($privkey,$pubkey);
7027: if (ref($cancreate{$type}) eq 'HASH') {
7028: $pubkey = $cancreate{$type}{'public'};
7029: $privkey = $cancreate{$type}{'private'};
7030: }
7031: $chgtext .= &mt('ReCAPTCHA keys changes').'<ul>';
7032: if (!$pubkey) {
7033: $chgtext .= '<li>'.&mt('Public key deleted').'</li>';
7034: } else {
7035: $chgtext .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
7036: }
7037: if (!$privkey) {
7038: $chgtext .= '<li>'.&mt('Private key deleted').'</li>';
7039: } else {
7040: $chgtext .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
7041: }
7042: $chgtext .= '</ul>';
1.43 raeburn 7043: } else {
7044: if ($cancreate{$type} eq 'none') {
7045: $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
7046: } elsif ($cancreate{$type} eq 'any') {
7047: $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
7048: } elsif ($cancreate{$type} eq 'official') {
7049: $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
7050: } elsif ($cancreate{$type} eq 'unofficial') {
7051: $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
7052: }
1.34 raeburn 7053: }
7054: $resulttext .= '<li>'.$chgtext.'</li>';
1.27 raeburn 7055: }
7056: }
7057: if (ref($changes{'username_rule'}) eq 'ARRAY') {
1.32 raeburn 7058: my ($rules,$ruleorder) =
7059: &Apache::lonnet::inst_userrules($dom,'username');
1.27 raeburn 7060: my $chgtext = '<ul>';
7061: foreach my $type (@username_rule) {
7062: if (ref($rules->{$type}) eq 'HASH') {
7063: $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
7064: }
7065: }
7066: $chgtext .= '</ul>';
7067: if (@username_rule > 0) {
7068: $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
7069: } else {
1.28 raeburn 7070: $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>';
1.27 raeburn 7071: }
7072: }
1.32 raeburn 7073: if (ref($changes{'id_rule'}) eq 'ARRAY') {
7074: my ($idrules,$idruleorder) =
7075: &Apache::lonnet::inst_userrules($dom,'id');
7076: my $chgtext = '<ul>';
7077: foreach my $type (@id_rule) {
7078: if (ref($idrules->{$type}) eq 'HASH') {
7079: $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
7080: }
7081: }
7082: $chgtext .= '</ul>';
7083: if (@id_rule > 0) {
7084: $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
7085: } else {
7086: $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
7087: }
7088: }
1.43 raeburn 7089: if (ref($changes{'email_rule'}) eq 'ARRAY') {
7090: my ($emailrules,$emailruleorder) =
7091: &Apache::lonnet::inst_userrules($dom,'email');
7092: my $chgtext = '<ul>';
7093: foreach my $type (@email_rule) {
7094: if (ref($emailrules->{$type}) eq 'HASH') {
7095: $chgtext .= '<li>'.$emailrules->{$type}{'name'}.'</li>';
7096: }
7097: }
7098: $chgtext .= '</ul>';
7099: if (@email_rule > 0) {
7100: $resulttext .= '<li>'.&mt('Accounts may not be created by users self-enrolling with e-mail addresses of the following types: ').$chgtext.'</li>';
7101: } else {
7102: $resulttext .= '<li>'.&mt('There are now no restrictions on e-mail addresses which may be used as a username when self-enrolling.').'</li>';
7103: }
7104: }
7105:
1.28 raeburn 7106: my %authname = &authtype_names();
7107: my %context_title = &context_names();
7108: if (ref($changes{'authtypes'}) eq 'ARRAY') {
7109: my $chgtext = '<ul>';
7110: foreach my $type (@{$changes{'authtypes'}}) {
7111: my @allowed;
7112: $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
7113: foreach my $auth (@authtypes) {
7114: if ($authhash{$type}{$auth}) {
7115: push(@allowed,$authname{$auth});
7116: }
7117: }
1.43 raeburn 7118: if (@allowed > 0) {
7119: $chgtext .= join(', ',@allowed).'</li>';
7120: } else {
7121: $chgtext .= &mt('none').'</li>';
7122: }
1.28 raeburn 7123: }
7124: $chgtext .= '</ul>';
7125: $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
7126: $resulttext .= '</li>';
7127: }
1.27 raeburn 7128: $resulttext .= '</ul>';
7129: } else {
1.28 raeburn 7130: $resulttext = &mt('No changes made to user creation settings');
1.27 raeburn 7131: }
7132: } else {
7133: $resulttext = '<span class="LC_error">'.
1.23 raeburn 7134: &mt('An error occurred: [_1]',$putresult).'</span>';
7135: }
1.43 raeburn 7136: if ($warningmsg ne '') {
7137: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
7138: }
1.23 raeburn 7139: return $resulttext;
7140: }
7141:
1.165 raeburn 7142: sub process_captcha {
7143: my ($container,$changes,$newsettings,$current) = @_;
7144: return unless ((ref($changes) eq 'HASH') && (ref($newsettings) eq 'HASH') || (ref($current) eq 'HASH'));
7145: $newsettings->{'captcha'} = $env{'form.'.$container.'_captcha'};
7146: unless ($newsettings->{'captcha'} eq 'recaptcha' || $newsettings->{'captcha'} eq 'notused') {
7147: $newsettings->{'captcha'} = 'original';
7148: }
7149: if ($current->{'captcha'} ne $newsettings->{'captcha'}) {
1.169 raeburn 7150: if ($container eq 'cancreate') {
7151: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
7152: push(@{$changes->{'cancreate'}},'captcha');
7153: } elsif (!defined($changes->{'cancreate'})) {
7154: $changes->{'cancreate'} = ['captcha'];
7155: }
7156: } else {
7157: $changes->{'captcha'} = 1;
1.165 raeburn 7158: }
7159: }
7160: my ($newpub,$newpriv,$currpub,$currpriv);
7161: if ($newsettings->{'captcha'} eq 'recaptcha') {
7162: $newpub = $env{'form.'.$container.'_recaptchapub'};
7163: $newpriv = $env{'form.'.$container.'_recaptchapriv'};
1.169 raeburn 7164: $newpub =~ s/\W//g;
7165: $newpriv =~ s/\W//g;
7166: $newsettings->{'recaptchakeys'} = {
7167: public => $newpub,
7168: private => $newpriv,
7169: };
1.165 raeburn 7170: }
7171: if (ref($current->{'recaptchakeys'}) eq 'HASH') {
7172: $currpub = $current->{'recaptchakeys'}{'public'};
7173: $currpriv = $current->{'recaptchakeys'}{'private'};
1.179 raeburn 7174: unless ($newsettings->{'captcha'} eq 'recaptcha') {
7175: $newsettings->{'recaptchakeys'} = {
7176: public => '',
7177: private => '',
7178: }
7179: }
1.165 raeburn 7180: }
7181: if (($newpub ne $currpub) || ($newpriv ne $currpriv)) {
1.169 raeburn 7182: if ($container eq 'cancreate') {
7183: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
7184: push(@{$changes->{'cancreate'}},'recaptchakeys');
7185: } elsif (!defined($changes->{'cancreate'})) {
7186: $changes->{'cancreate'} = ['recaptchakeys'];
7187: }
7188: } else {
7189: $changes->{'recaptchakeys'} = 1;
1.165 raeburn 7190: }
7191: }
7192: return;
7193: }
7194:
1.33 raeburn 7195: sub modify_usermodification {
7196: my ($dom,%domconfig) = @_;
7197: my ($resulttext,%curr_usermodification,%changes);
7198: if (ref($domconfig{'usermodification'}) eq 'HASH') {
7199: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
7200: $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
7201: }
7202: }
1.63 raeburn 7203: my @contexts = ('author','course','selfcreate');
1.33 raeburn 7204: my %context_title = (
7205: author => 'In author context',
7206: course => 'In course context',
1.63 raeburn 7207: selfcreate => 'When self creating account',
1.33 raeburn 7208: );
7209: my @fields = ('lastname','firstname','middlename','generation',
7210: 'permanentemail','id');
7211: my %roles = (
7212: author => ['ca','aa'],
7213: course => ['st','ep','ta','in','cr'],
7214: );
1.63 raeburn 7215: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
7216: if (ref($types) eq 'ARRAY') {
7217: push(@{$types},'default');
7218: $usertypes->{'default'} = $othertitle;
7219: }
7220: $roles{'selfcreate'} = $types;
1.33 raeburn 7221: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
7222: my %modifyhash;
7223: foreach my $context (@contexts) {
7224: foreach my $role (@{$roles{$context}}) {
7225: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$role);
7226: foreach my $item (@fields) {
7227: if (grep(/^\Q$item\E$/,@modifiable)) {
7228: $modifyhash{$context}{$role}{$item} = 1;
7229: } else {
7230: $modifyhash{$context}{$role}{$item} = 0;
7231: }
7232: }
7233: }
7234: if (ref($curr_usermodification{$context}) eq 'HASH') {
7235: foreach my $role (@{$roles{$context}}) {
7236: if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
7237: foreach my $field (@fields) {
7238: if ($modifyhash{$context}{$role}{$field} ne
7239: $curr_usermodification{$context}{$role}{$field}) {
7240: push(@{$changes{$context}},$role);
7241: last;
7242: }
7243: }
7244: }
7245: }
7246: } else {
7247: foreach my $context (@contexts) {
7248: foreach my $role (@{$roles{$context}}) {
7249: push(@{$changes{$context}},$role);
7250: }
7251: }
7252: }
7253: }
7254: my %usermodification_hash = (
7255: usermodification => \%modifyhash,
7256: );
7257: my $putresult = &Apache::lonnet::put_dom('configuration',
7258: \%usermodification_hash,$dom);
7259: if ($putresult eq 'ok') {
7260: if (keys(%changes) > 0) {
7261: $resulttext = &mt('Changes made: ').'<ul>';
7262: foreach my $context (@contexts) {
7263: if (ref($changes{$context}) eq 'ARRAY') {
7264: $resulttext .= '<li>'.$context_title{$context}.':<ul>';
7265: if (ref($changes{$context}) eq 'ARRAY') {
7266: foreach my $role (@{$changes{$context}}) {
7267: my $rolename;
1.63 raeburn 7268: if ($context eq 'selfcreate') {
7269: $rolename = $role;
7270: if (ref($usertypes) eq 'HASH') {
7271: if ($usertypes->{$role} ne '') {
7272: $rolename = $usertypes->{$role};
7273: }
7274: }
1.33 raeburn 7275: } else {
1.63 raeburn 7276: if ($role eq 'cr') {
7277: $rolename = &mt('Custom');
7278: } else {
7279: $rolename = &Apache::lonnet::plaintext($role);
7280: }
1.33 raeburn 7281: }
7282: my @modifiable;
1.63 raeburn 7283: if ($context eq 'selfcreate') {
1.126 bisitz 7284: $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 7285: } else {
7286: $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
7287: }
1.33 raeburn 7288: foreach my $field (@fields) {
7289: if ($modifyhash{$context}{$role}{$field}) {
7290: push(@modifiable,$fieldtitles{$field});
7291: }
7292: }
7293: if (@modifiable > 0) {
7294: $resulttext .= join(', ',@modifiable);
7295: } else {
7296: $resulttext .= &mt('none');
7297: }
7298: $resulttext .= '</li>';
7299: }
7300: $resulttext .= '</ul></li>';
7301: }
7302: }
7303: }
7304: $resulttext .= '</ul>';
7305: } else {
7306: $resulttext = &mt('No changes made to user modification settings');
7307: }
7308: } else {
7309: $resulttext = '<span class="LC_error">'.
7310: &mt('An error occurred: [_1]',$putresult).'</span>';
7311: }
7312: return $resulttext;
7313: }
7314:
1.43 raeburn 7315: sub modify_defaults {
7316: my ($dom,$r) = @_;
7317: my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
7318: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.141 raeburn 7319: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def','portal_def');
1.43 raeburn 7320: my @authtypes = ('internal','krb4','krb5','localauth');
7321: foreach my $item (@items) {
7322: $newvalues{$item} = $env{'form.'.$item};
7323: if ($item eq 'auth_def') {
7324: if ($newvalues{$item} ne '') {
7325: if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
7326: push(@errors,$item);
7327: }
7328: }
7329: } elsif ($item eq 'lang_def') {
7330: if ($newvalues{$item} ne '') {
7331: if ($newvalues{$item} =~ /^(\w+)/) {
7332: my $langcode = $1;
1.103 raeburn 7333: if ($langcode ne 'x_chef') {
7334: if (code2language($langcode) eq '') {
7335: push(@errors,$item);
7336: }
1.43 raeburn 7337: }
7338: } else {
7339: push(@errors,$item);
7340: }
7341: }
1.54 raeburn 7342: } elsif ($item eq 'timezone_def') {
7343: if ($newvalues{$item} ne '') {
1.62 raeburn 7344: if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
1.54 raeburn 7345: push(@errors,$item);
7346: }
7347: }
1.68 raeburn 7348: } elsif ($item eq 'datelocale_def') {
7349: if ($newvalues{$item} ne '') {
7350: my @datelocale_ids = DateTime::Locale->ids();
7351: if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
7352: push(@errors,$item);
7353: }
7354: }
1.141 raeburn 7355: } elsif ($item eq 'portal_def') {
7356: if ($newvalues{$item} ne '') {
7357: 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])\/?$/) {
7358: push(@errors,$item);
7359: }
7360: }
1.43 raeburn 7361: }
7362: if (grep(/^\Q$item\E$/,@errors)) {
7363: $newvalues{$item} = $domdefaults{$item};
7364: } elsif ($domdefaults{$item} ne $newvalues{$item}) {
7365: $changes{$item} = 1;
7366: }
1.72 raeburn 7367: $domdefaults{$item} = $newvalues{$item};
1.43 raeburn 7368: }
7369: my %defaults_hash = (
1.72 raeburn 7370: defaults => \%newvalues,
7371: );
1.43 raeburn 7372: my $title = &defaults_titles();
7373: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
7374: $dom);
7375: if ($putresult eq 'ok') {
7376: if (keys(%changes) > 0) {
7377: $resulttext = &mt('Changes made:').'<ul>';
7378: my $version = $r->dir_config('lonVersion');
7379: 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";
7380: foreach my $item (sort(keys(%changes))) {
7381: my $value = $env{'form.'.$item};
7382: if ($value eq '') {
7383: $value = &mt('none');
7384: } elsif ($item eq 'auth_def') {
7385: my %authnames = &authtype_names();
7386: my %shortauth = (
7387: internal => 'int',
7388: krb4 => 'krb4',
7389: krb5 => 'krb5',
7390: localauth => 'loc',
7391: );
7392: $value = $authnames{$shortauth{$value}};
7393: }
7394: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
7395: $mailmsgtext .= "$title->{$item} set to $value\n";
7396: }
7397: $resulttext .= '</ul>';
7398: $mailmsgtext .= "\n";
7399: my $cachetime = 24*60*60;
1.72 raeburn 7400: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.68 raeburn 7401: if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
1.54 raeburn 7402: my $sysmail = $r->dir_config('lonSysEMail');
7403: &Apache::lonmsg::sendemail($sysmail,"LON-CAPA Domain Settings Change - $dom",$mailmsgtext);
7404: }
1.43 raeburn 7405: } else {
1.54 raeburn 7406: $resulttext = &mt('No changes made to default authentication/language/timezone settings');
1.43 raeburn 7407: }
7408: } else {
7409: $resulttext = '<span class="LC_error">'.
7410: &mt('An error occurred: [_1]',$putresult).'</span>';
7411: }
7412: if (@errors > 0) {
7413: $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
7414: foreach my $item (@errors) {
7415: $resulttext .= ' "'.$title->{$item}.'",';
7416: }
7417: $resulttext =~ s/,$//;
7418: }
7419: return $resulttext;
7420: }
7421:
1.46 raeburn 7422: sub modify_scantron {
1.48 raeburn 7423: my ($r,$dom,$confname,%domconfig) = @_;
1.46 raeburn 7424: my ($resulttext,%confhash,%changes,$errors);
7425: my $custom = 'custom.tab';
7426: my $default = 'default.tab';
7427: my $servadm = $r->dir_config('lonAdmEMail');
7428: my ($configuserok,$author_ok,$switchserver) =
7429: &config_check($dom,$confname,$servadm);
7430: if ($env{'form.scantronformat.filename'} ne '') {
7431: my $error;
7432: if ($configuserok eq 'ok') {
7433: if ($switchserver) {
1.130 raeburn 7434: $error = &mt("Upload of bubblesheet format file is not permitted to this server: [_1]",$switchserver);
1.46 raeburn 7435: } else {
7436: if ($author_ok eq 'ok') {
7437: my ($result,$scantronurl) =
7438: &publishlogo($r,'upload','scantronformat',$dom,
7439: $confname,'scantron','','',$custom);
7440: if ($result eq 'ok') {
7441: $confhash{'scantron'}{'scantronformat'} = $scantronurl;
1.48 raeburn 7442: $changes{'scantronformat'} = 1;
1.46 raeburn 7443: } else {
7444: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
7445: }
7446: } else {
7447: $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);
7448: }
7449: }
7450: } else {
7451: $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);
7452: }
7453: if ($error) {
7454: &Apache::lonnet::logthis($error);
7455: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
7456: }
7457: }
1.48 raeburn 7458: if (ref($domconfig{'scantron'}) eq 'HASH') {
7459: if ($domconfig{'scantron'}{'scantronformat'} ne '') {
7460: if ($env{'form.scantronformat_del'}) {
7461: $confhash{'scantron'}{'scantronformat'} = '';
7462: $changes{'scantronformat'} = 1;
1.46 raeburn 7463: }
7464: }
7465: }
7466: if (keys(%confhash) > 0) {
7467: my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
7468: $dom);
7469: if ($putresult eq 'ok') {
7470: if (keys(%changes) > 0) {
1.48 raeburn 7471: if (ref($confhash{'scantron'}) eq 'HASH') {
7472: $resulttext = &mt('Changes made:').'<ul>';
7473: if ($confhash{'scantron'}{'scantronformat'} eq '') {
1.130 raeburn 7474: $resulttext .= '<li>'.&mt('[_1] bubblesheet format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
1.48 raeburn 7475: } else {
1.130 raeburn 7476: $resulttext .= '<li>'.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
1.46 raeburn 7477: }
1.48 raeburn 7478: $resulttext .= '</ul>';
7479: } else {
1.130 raeburn 7480: $resulttext = &mt('Changes made to bubblesheet format file.');
1.46 raeburn 7481: }
7482: $resulttext .= '</ul>';
7483: &Apache::loncommon::devalidate_domconfig_cache($dom);
7484: } else {
1.130 raeburn 7485: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 7486: }
7487: } else {
7488: $resulttext = '<span class="LC_error">'.
7489: &mt('An error occurred: [_1]',$putresult).'</span>';
7490: }
7491: } else {
1.130 raeburn 7492: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 7493: }
7494: if ($errors) {
7495: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
7496: $errors.'</ul>';
7497: }
7498: return $resulttext;
7499: }
7500:
1.48 raeburn 7501: sub modify_coursecategories {
7502: my ($dom,%domconfig) = @_;
1.57 raeburn 7503: my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
7504: $cathash);
1.48 raeburn 7505: my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
1.55 raeburn 7506: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
1.57 raeburn 7507: $cathash = $domconfig{'coursecategories'}{'cats'};
7508: if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
7509: $changes{'togglecats'} = 1;
7510: $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
7511: }
7512: if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
7513: $changes{'categorize'} = 1;
7514: $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
7515: }
1.120 raeburn 7516: if ($domconfig{'coursecategories'}{'togglecatscomm'} ne $env{'form.togglecatscomm'}) {
7517: $changes{'togglecatscomm'} = 1;
7518: $domconfig{'coursecategories'}{'togglecatscomm'} = $env{'form.togglecatscomm'};
7519: }
7520: if ($domconfig{'coursecategories'}{'categorizecomm'} ne $env{'form.categorizecomm'}) {
7521: $changes{'categorizecomm'} = 1;
7522: $domconfig{'coursecategories'}{'categorizecomm'} = $env{'form.categorizecomm'};
7523: }
1.57 raeburn 7524: } else {
7525: $changes{'togglecats'} = 1;
7526: $changes{'categorize'} = 1;
1.124 raeburn 7527: $changes{'togglecatscomm'} = 1;
7528: $changes{'categorizecomm'} = 1;
1.87 raeburn 7529: $domconfig{'coursecategories'} = {
7530: togglecats => $env{'form.togglecats'},
7531: categorize => $env{'form.categorize'},
1.124 raeburn 7532: togglecatscomm => $env{'form.togglecatscomm'},
7533: categorizecomm => $env{'form.categorizecomm'},
1.120 raeburn 7534: };
1.57 raeburn 7535: }
7536: if (ref($cathash) eq 'HASH') {
7537: if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '') && ($env{'form.instcode'} == 0)) {
1.55 raeburn 7538: push (@deletecategory,'instcode::0');
7539: }
1.120 raeburn 7540: if (($domconfig{'coursecategories'}{'cats'}{'communities::0'} ne '') && ($env{'form.communities'} == 0)) {
7541: push(@deletecategory,'communities::0');
7542: }
1.48 raeburn 7543: }
1.57 raeburn 7544: my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
7545: if (ref($cathash) eq 'HASH') {
1.48 raeburn 7546: if (@deletecategory > 0) {
7547: #FIXME Need to remove category from all courses using a deleted category
1.57 raeburn 7548: &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
1.48 raeburn 7549: foreach my $item (@deletecategory) {
1.57 raeburn 7550: if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
7551: delete($domconfig{'coursecategories'}{'cats'}{$item});
1.48 raeburn 7552: $deletions{$item} = 1;
1.57 raeburn 7553: &recurse_cat_deletes($item,$cathash,\%deletions);
1.48 raeburn 7554: }
7555: }
7556: }
1.57 raeburn 7557: foreach my $item (keys(%{$cathash})) {
1.48 raeburn 7558: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
1.57 raeburn 7559: if ($cathash->{$item} ne $env{'form.'.$item}) {
1.48 raeburn 7560: $reorderings{$item} = 1;
1.57 raeburn 7561: $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
1.48 raeburn 7562: }
7563: if ($env{'form.addcategory_name_'.$item} ne '') {
7564: my $newcat = $env{'form.addcategory_name_'.$item};
7565: my $newdepth = $depth+1;
7566: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 7567: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
1.48 raeburn 7568: $adds{$newitem} = 1;
7569: }
7570: if ($env{'form.subcat_'.$item} ne '') {
7571: my $newcat = $env{'form.subcat_'.$item};
7572: my $newdepth = $depth+1;
7573: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 7574: $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
1.48 raeburn 7575: $adds{$newitem} = 1;
7576: }
7577: }
7578: }
7579: if ($env{'form.instcode'} eq '1') {
1.57 raeburn 7580: if (ref($cathash) eq 'HASH') {
1.48 raeburn 7581: my $newitem = 'instcode::0';
1.57 raeburn 7582: if ($cathash->{$newitem} eq '') {
7583: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 7584: $adds{$newitem} = 1;
7585: }
7586: } else {
7587: my $newitem = 'instcode::0';
1.57 raeburn 7588: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 7589: $adds{$newitem} = 1;
7590: }
7591: }
1.120 raeburn 7592: if ($env{'form.communities'} eq '1') {
7593: if (ref($cathash) eq 'HASH') {
7594: my $newitem = 'communities::0';
7595: if ($cathash->{$newitem} eq '') {
7596: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
7597: $adds{$newitem} = 1;
7598: }
7599: } else {
7600: my $newitem = 'communities::0';
7601: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
7602: $adds{$newitem} = 1;
7603: }
7604: }
1.48 raeburn 7605: if ($env{'form.addcategory_name'} ne '') {
1.120 raeburn 7606: if (($env{'form.addcategory_name'} ne 'instcode') &&
7607: ($env{'form.addcategory_name'} ne 'communities')) {
7608: my $newitem = &escape($env{'form.addcategory_name'}).'::0';
7609: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
7610: $adds{$newitem} = 1;
7611: }
1.48 raeburn 7612: }
1.57 raeburn 7613: my $putresult;
1.48 raeburn 7614: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
7615: if (keys(%deletions) > 0) {
7616: foreach my $key (keys(%deletions)) {
7617: if ($predelallitems{$key} ne '') {
7618: $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
7619: }
7620: }
7621: }
7622: my (@chkcats,@chktrails,%chkallitems);
1.57 raeburn 7623: &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
1.48 raeburn 7624: if (ref($chkcats[0]) eq 'ARRAY') {
7625: my $depth = 0;
7626: my $chg = 0;
7627: for (my $i=0; $i<@{$chkcats[0]}; $i++) {
7628: my $name = $chkcats[0][$i];
7629: my $item;
7630: if ($name eq '') {
7631: $chg ++;
7632: } else {
7633: $item = &escape($name).'::0';
7634: if ($chg) {
1.57 raeburn 7635: $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
1.48 raeburn 7636: }
7637: $depth ++;
1.57 raeburn 7638: &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
1.48 raeburn 7639: $depth --;
7640: }
7641: }
7642: }
1.57 raeburn 7643: }
7644: if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
7645: $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
1.48 raeburn 7646: if ($putresult eq 'ok') {
1.57 raeburn 7647: my %title = (
1.120 raeburn 7648: togglecats => 'Show/Hide a course in catalog',
7649: categorize => 'Assign a category to a course',
7650: togglecatscomm => 'Show/Hide a community in catalog',
7651: categorizecomm => 'Assign a category to a community',
1.57 raeburn 7652: );
7653: my %level = (
1.120 raeburn 7654: dom => 'set in Domain ("Modify Course/Community")',
7655: crs => 'set in Course ("Course Configuration")',
7656: comm => 'set in Community ("Community Configuration")',
1.57 raeburn 7657: );
1.48 raeburn 7658: $resulttext = &mt('Changes made:').'<ul>';
1.57 raeburn 7659: if ($changes{'togglecats'}) {
7660: $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>';
7661: }
7662: if ($changes{'categorize'}) {
7663: $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
1.48 raeburn 7664: }
1.120 raeburn 7665: if ($changes{'togglecatscomm'}) {
7666: $resulttext .= '<li>'.&mt("$title{'togglecatscomm'} $level{$env{'form.togglecatscomm'}}").'</li>';
7667: }
7668: if ($changes{'categorizecomm'}) {
7669: $resulttext .= '<li>'.&mt("$title{'categorizecomm'} $level{$env{'form.categorizecomm'}}").'</li>';
7670: }
1.57 raeburn 7671: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
7672: my $cathash;
7673: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
7674: $cathash = $domconfig{'coursecategories'}{'cats'};
7675: } else {
7676: $cathash = {};
7677: }
7678: my (@cats,@trails,%allitems);
7679: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
7680: if (keys(%deletions) > 0) {
7681: $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
7682: foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) {
7683: $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
7684: }
7685: $resulttext .= '</ul></li>';
7686: }
7687: if (keys(%reorderings) > 0) {
7688: my %sort_by_trail;
7689: $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
7690: foreach my $key (keys(%reorderings)) {
7691: if ($allitems{$key} ne '') {
7692: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
7693: }
1.48 raeburn 7694: }
1.57 raeburn 7695: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
7696: $resulttext .= '<li>'.$trails[$trail].'</li>';
7697: }
7698: $resulttext .= '</ul></li>';
1.48 raeburn 7699: }
1.57 raeburn 7700: if (keys(%adds) > 0) {
7701: my %sort_by_trail;
7702: $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
7703: foreach my $key (keys(%adds)) {
7704: if ($allitems{$key} ne '') {
7705: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
7706: }
7707: }
7708: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
7709: $resulttext .= '<li>'.$trails[$trail].'</li>';
1.48 raeburn 7710: }
1.57 raeburn 7711: $resulttext .= '</ul></li>';
1.48 raeburn 7712: }
7713: }
7714: $resulttext .= '</ul>';
7715: } else {
7716: $resulttext = '<span class="LC_error">'.
1.57 raeburn 7717: &mt('An error occurred: [_1]',$putresult).'</span>';
1.48 raeburn 7718: }
7719: } else {
1.120 raeburn 7720: $resulttext = &mt('No changes made to course and community categories');
1.48 raeburn 7721: }
7722: return $resulttext;
7723: }
7724:
1.69 raeburn 7725: sub modify_serverstatuses {
7726: my ($dom,%domconfig) = @_;
7727: my ($resulttext,%changes,%currserverstatus,%newserverstatus);
7728: if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
7729: %currserverstatus = %{$domconfig{'serverstatuses'}};
7730: }
7731: my @pages = &serverstatus_pages();
7732: foreach my $type (@pages) {
7733: $newserverstatus{$type}{'namedusers'} = '';
7734: $newserverstatus{$type}{'machines'} = '';
7735: if (defined($env{'form.'.$type.'_namedusers'})) {
7736: my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
7737: my @okusers;
7738: foreach my $user (@users) {
7739: my ($uname,$udom) = split(/:/,$user);
7740: if (($udom =~ /^$match_domain$/) &&
7741: (&Apache::lonnet::domain($udom)) &&
7742: ($uname =~ /^$match_username$/)) {
7743: if (!grep(/^\Q$user\E/,@okusers)) {
7744: push(@okusers,$user);
7745: }
7746: }
7747: }
7748: if (@okusers > 0) {
7749: @okusers = sort(@okusers);
7750: $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
7751: }
7752: }
7753: if (defined($env{'form.'.$type.'_machines'})) {
7754: my @machines = split(/,/,$env{'form.'.$type.'_machines'});
7755: my @okmachines;
7756: foreach my $ip (@machines) {
7757: my @parts = split(/\./,$ip);
7758: next if (@parts < 4);
7759: my $badip = 0;
7760: for (my $i=0; $i<4; $i++) {
7761: if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
7762: $badip = 1;
7763: last;
7764: }
7765: }
7766: if (!$badip) {
7767: push(@okmachines,$ip);
7768: }
7769: }
7770: @okmachines = sort(@okmachines);
7771: $newserverstatus{$type}{'machines'} = join(',',@okmachines);
7772: }
7773: }
7774: my %serverstatushash = (
7775: serverstatuses => \%newserverstatus,
7776: );
7777: foreach my $type (@pages) {
1.83 raeburn 7778: foreach my $setting ('namedusers','machines') {
1.84 raeburn 7779: my (@current,@new);
1.83 raeburn 7780: if (ref($currserverstatus{$type}) eq 'HASH') {
1.84 raeburn 7781: if ($currserverstatus{$type}{$setting} ne '') {
7782: @current = split(/,/,$currserverstatus{$type}{$setting});
7783: }
7784: }
7785: if ($newserverstatus{$type}{$setting} ne '') {
7786: @new = split(/,/,$newserverstatus{$type}{$setting});
1.83 raeburn 7787: }
7788: if (@current > 0) {
7789: if (@new > 0) {
7790: foreach my $item (@current) {
7791: if (!grep(/^\Q$item\E$/,@new)) {
7792: $changes{$type}{$setting} = 1;
1.82 raeburn 7793: last;
7794: }
7795: }
1.84 raeburn 7796: foreach my $item (@new) {
7797: if (!grep(/^\Q$item\E$/,@current)) {
7798: $changes{$type}{$setting} = 1;
7799: last;
1.82 raeburn 7800: }
7801: }
7802: } else {
1.83 raeburn 7803: $changes{$type}{$setting} = 1;
1.69 raeburn 7804: }
1.83 raeburn 7805: } elsif (@new > 0) {
7806: $changes{$type}{$setting} = 1;
1.69 raeburn 7807: }
7808: }
7809: }
7810: if (keys(%changes) > 0) {
1.81 raeburn 7811: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 7812: my $putresult = &Apache::lonnet::put_dom('configuration',
7813: \%serverstatushash,$dom);
7814: if ($putresult eq 'ok') {
7815: $resulttext .= &mt('Changes made:').'<ul>';
7816: foreach my $type (@pages) {
1.84 raeburn 7817: if (ref($changes{$type}) eq 'HASH') {
1.69 raeburn 7818: $resulttext .= '<li>'.$titles->{$type}.'<ul>';
1.84 raeburn 7819: if ($changes{$type}{'namedusers'}) {
1.69 raeburn 7820: if ($newserverstatus{$type}{'namedusers'} eq '') {
7821: $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n";
7822: } else {
7823: $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n";
7824: }
1.84 raeburn 7825: }
7826: if ($changes{$type}{'machines'}) {
1.69 raeburn 7827: if ($newserverstatus{$type}{'machines'} eq '') {
7828: $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n";
7829: } else {
7830: $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n";
7831: }
7832:
7833: }
7834: $resulttext .= '</ul></li>';
7835: }
7836: }
7837: $resulttext .= '</ul>';
7838: } else {
7839: $resulttext = '<span class="LC_error">'.
7840: &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>';
7841:
7842: }
7843: } else {
7844: $resulttext = &mt('No changes made to access to server status pages');
7845: }
7846: return $resulttext;
7847: }
7848:
1.118 jms 7849: sub modify_helpsettings {
1.122 jms 7850: my ($r,$dom,$confname,%domconfig) = @_;
1.166 raeburn 7851: my ($resulttext,$errors,%changes,%helphash);
7852: my %defaultchecked = ('submitbugs' => 'on');
7853: my @offon = ('off','on');
1.118 jms 7854: my @toggles = ('submitbugs');
7855: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
7856: foreach my $item (@toggles) {
1.166 raeburn 7857: if ($defaultchecked{$item} eq 'on') {
7858: if ($domconfig{'helpsettings'}{$item} eq '') {
7859: if ($env{'form.'.$item} eq '0') {
7860: $changes{$item} = 1;
7861: }
7862: } elsif ($domconfig{'helpsettings'}{$item} ne $env{'form.'.$item}) {
7863: $changes{$item} = 1;
7864: }
7865: } elsif ($defaultchecked{$item} eq 'off') {
7866: if ($domconfig{'helpsettings'}{$item} eq '') {
7867: if ($env{'form.'.$item} eq '1') {
7868: $changes{$item} = 1;
7869: }
7870: } elsif ($domconfig{'helpsettings'}{$item} ne $env{'form.'.$item}) {
7871: $changes{$item} = 1;
7872: }
7873: }
7874: if (($env{'form.'.$item} eq '0') || ($env{'form.'.$item} eq '1')) {
7875: $helphash{'helpsettings'}{$item} = $env{'form.'.$item};
7876: }
7877: }
1.118 jms 7878: }
1.123 jms 7879: my $putresult;
7880: if (keys(%changes) > 0) {
1.166 raeburn 7881: $putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom);
1.168 raeburn 7882: if ($putresult eq 'ok') {
1.166 raeburn 7883: $resulttext = &mt('Changes made:').'<ul>';
7884: foreach my $item (sort(keys(%changes))) {
7885: if ($item eq 'submitbugs') {
7886: $resulttext .= '<li>'.&mt('Display link to: [_1] set to "'.$offon[$env{'form.'.$item}].'".',
7887: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
7888: &mt('LON-CAPA bug tracker'),600,500)).'</li>';
7889: }
7890: }
7891: $resulttext .= '</ul>';
7892: } else {
7893: $resulttext = &mt('No changes made to help settings');
1.168 raeburn 7894: $errors .= '<li><span class="LC_error">'.
7895: &mt('An error occurred storing the settings: [_1]',
7896: $putresult).'</span></li>';
1.166 raeburn 7897: }
1.118 jms 7898: }
7899: if ($errors) {
1.168 raeburn 7900: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.118 jms 7901: $errors.'</ul>';
7902: }
7903: return $resulttext;
7904: }
7905:
1.121 raeburn 7906: sub modify_coursedefaults {
7907: my ($dom,%domconfig) = @_;
7908: my ($resulttext,$errors,%changes,%defaultshash);
7909: my %defaultchecked = ('canuse_pdfforms' => 'off');
7910: my @toggles = ('canuse_pdfforms');
7911:
7912: $defaultshash{'coursedefaults'} = {};
7913:
7914: if (ref($domconfig{'coursedefaults'}) ne 'HASH') {
7915: if ($domconfig{'coursedefaults'} eq '') {
7916: $domconfig{'coursedefaults'} = {};
7917: }
7918: }
7919:
7920: if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
7921: foreach my $item (@toggles) {
7922: if ($defaultchecked{$item} eq 'on') {
7923: if (($domconfig{'coursedefaults'}{$item} eq '') &&
7924: ($env{'form.'.$item} eq '0')) {
7925: $changes{$item} = 1;
1.192 raeburn 7926: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
1.121 raeburn 7927: $changes{$item} = 1;
7928: }
7929: } elsif ($defaultchecked{$item} eq 'off') {
7930: if (($domconfig{'coursedefaults'}{$item} eq '') &&
7931: ($env{'form.'.$item} eq '1')) {
7932: $changes{$item} = 1;
7933: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
7934: $changes{$item} = 1;
7935: }
7936: }
7937: $defaultshash{'coursedefaults'}{$item} = $env{'form.'.$item};
7938: }
1.139 raeburn 7939: my $currdefresponder = $domconfig{'coursedefaults'}{'anonsurvey_threshold'};
7940: my $newdefresponder = $env{'form.anonsurvey_threshold'};
7941: $newdefresponder =~ s/\D//g;
7942: if ($newdefresponder eq '' || $newdefresponder < 1) {
7943: $newdefresponder = 1;
7944: }
7945: $defaultshash{'coursedefaults'}{'anonsurvey_threshold'} = $newdefresponder;
7946: if ($currdefresponder ne $newdefresponder) {
7947: unless ($currdefresponder eq '' && $newdefresponder == 10) {
7948: $changes{'anonsurvey_threshold'} = 1;
7949: }
7950: }
1.192 raeburn 7951: my $officialcreds = $env{'form.official_credits'};
7952: $officialcreds =~ s/^[^\d\.]//g;
7953: my $unofficialcreds = $env{'form.unofficial_credits'};
7954: $unofficialcreds =~ s/^[^\d\.]//g;
7955: if (ref($domconfig{'coursedefaults'}{'coursecredits'} ne 'HASH') &&
7956: ($env{'form.coursecredits'} eq '1')) {
7957: $changes{'coursecredits'} = 1;
7958: } else {
7959: if (($domconfig{'coursedefaults'}{'coursecredits'}{'official'} ne $officialcreds) ||
7960: ($domconfig{'coursedefaults'}{'coursecredits'}{'unofficial'} ne $unofficialcreds)) {
7961: $changes{'coursecredits'} = 1;
7962: }
7963: }
7964: $defaultshash{'coursedefaults'}{'coursecredits'} = {
7965: official => $officialcreds,
7966: unofficial => $unofficialcreds,
7967: }
1.121 raeburn 7968: }
7969: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
7970: $dom);
7971: if ($putresult eq 'ok') {
1.192 raeburn 7972: my %domdefaults;
1.121 raeburn 7973: if (keys(%changes) > 0) {
1.192 raeburn 7974: if (($changes{'canuse_pdfforms'}) || ($changes{'coursecredits'})) {
7975: %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
7976: if ($changes{'canuse_pdfforms'}) {
7977: $domdefaults{'canuse_pdfforms'}=$defaultshash{'coursedefaults'}{'canuse_pdfforms'};
7978: }
7979: if ($changes{'coursecredits'}) {
7980: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
7981: $domdefaults{'officialcredits'} =
7982: $defaultshash{'coursedefaults'}{'coursecredits'}{'official'};
7983: $domdefaults{'unofficialcredits'} =
7984: $defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'};
7985: }
7986: }
1.121 raeburn 7987: my $cachetime = 24*60*60;
7988: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
7989: }
7990: $resulttext = &mt('Changes made:').'<ul>';
7991: foreach my $item (sort(keys(%changes))) {
7992: if ($item eq 'canuse_pdfforms') {
7993: if ($env{'form.'.$item} eq '1') {
7994: $resulttext .= '<li>'.&mt("Course/Community users can create/upload PDF forms set to 'on'").'</li>';
7995: } else {
7996: $resulttext .= '<li>'.&mt('Course/Community users can create/upload PDF forms set to "off"').'</li>';
7997: }
1.139 raeburn 7998: } elsif ($item eq 'anonsurvey_threshold') {
1.192 raeburn 7999: $resulttext .= '<li>'.&mt('Responder count required for display of anonymous survey submissions set to [_1].',$defaultshash{'coursedefaults'}{'anonsurvey_threshold'}).'</li>';
8000: } elsif ($item eq 'coursecredits') {
8001: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
8002: if (($domdefaults{'officialcredits'} eq '') &&
8003: ($domdefaults{'unofficialcredits'} eq '')) {
8004: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
8005: } else {
8006: $resulttext .= '<li>'.&mt('Student credits can be set per course by a Domain Coordinator, with the following defaults applying:').'<ul>'.
8007: '<li>'.&mt('Official courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'official'}).'</li>'.
8008: '<li>'.&mt('Unofficial courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'}).'</li>'.
8009: '</ul>'.
8010: '</li>';
8011: }
8012: } else {
8013: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
8014: }
1.140 raeburn 8015: }
1.121 raeburn 8016: }
8017: $resulttext .= '</ul>';
8018: } else {
8019: $resulttext = &mt('No changes made to course defaults');
8020: }
8021: } else {
8022: $resulttext = '<span class="LC_error">'.
8023: &mt('An error occurred: [_1]',$putresult).'</span>';
8024: }
8025: return $resulttext;
8026: }
8027:
1.137 raeburn 8028: sub modify_usersessions {
8029: my ($dom,%domconfig) = @_;
1.145 raeburn 8030: my @hostingtypes = ('version','excludedomain','includedomain');
8031: my @offloadtypes = ('primary','default');
8032: my %types = (
8033: remote => \@hostingtypes,
8034: hosted => \@hostingtypes,
8035: spares => \@offloadtypes,
8036: );
8037: my @prefixes = ('remote','hosted','spares');
1.137 raeburn 8038: my @lcversions = &Apache::lonnet::all_loncaparevs();
1.138 raeburn 8039: my (%by_ip,%by_location,@intdoms);
8040: &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
8041: my @locations = sort(keys(%by_location));
1.137 raeburn 8042: my (%defaultshash,%changes);
8043: foreach my $prefix (@prefixes) {
8044: $defaultshash{'usersessions'}{$prefix} = {};
8045: }
8046: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
8047: my $resulttext;
1.138 raeburn 8048: my %iphost = &Apache::lonnet::get_iphost();
1.137 raeburn 8049: foreach my $prefix (@prefixes) {
1.145 raeburn 8050: next if ($prefix eq 'spares');
8051: foreach my $type (@{$types{$prefix}}) {
1.137 raeburn 8052: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
8053: if ($type eq 'version') {
8054: my $value = $env{'form.'.$prefix.'_'.$type};
8055: my $okvalue;
8056: if ($value ne '') {
8057: if (grep(/^\Q$value\E$/,@lcversions)) {
8058: $okvalue = $value;
8059: }
8060: }
8061: if (ref($domconfig{'usersessions'}) eq 'HASH') {
8062: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
8063: if ($domconfig{'usersessions'}{$prefix}{$type} ne '') {
8064: if ($inuse == 0) {
8065: $changes{$prefix}{$type} = 1;
8066: } else {
8067: if ($okvalue ne $domconfig{'usersessions'}{$prefix}{$type}) {
8068: $changes{$prefix}{$type} = 1;
8069: }
8070: if ($okvalue ne '') {
8071: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
8072: }
8073: }
8074: } else {
8075: if (($inuse == 1) && ($okvalue ne '')) {
8076: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
8077: $changes{$prefix}{$type} = 1;
8078: }
8079: }
8080: } else {
8081: if (($inuse == 1) && ($okvalue ne '')) {
8082: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
8083: $changes{$prefix}{$type} = 1;
8084: }
8085: }
8086: } else {
8087: if (($inuse == 1) && ($okvalue ne '')) {
8088: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
8089: $changes{$prefix}{$type} = 1;
8090: }
8091: }
8092: } else {
8093: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
8094: my @okvals;
8095: foreach my $val (@vals) {
1.138 raeburn 8096: if ($val =~ /:/) {
8097: my @items = split(/:/,$val);
8098: foreach my $item (@items) {
8099: if (ref($by_location{$item}) eq 'ARRAY') {
8100: push(@okvals,$item);
8101: }
8102: }
8103: } else {
8104: if (ref($by_location{$val}) eq 'ARRAY') {
8105: push(@okvals,$val);
8106: }
1.137 raeburn 8107: }
8108: }
8109: @okvals = sort(@okvals);
8110: if (ref($domconfig{'usersessions'}) eq 'HASH') {
8111: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
8112: if (ref($domconfig{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
8113: if ($inuse == 0) {
8114: $changes{$prefix}{$type} = 1;
8115: } else {
8116: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
8117: my @changed = &Apache::loncommon::compare_arrays($domconfig{'usersessions'}{$prefix}{$type},$defaultshash{'usersessions'}{$prefix}{$type});
8118: if (@changed > 0) {
8119: $changes{$prefix}{$type} = 1;
8120: }
8121: }
8122: } else {
8123: if ($inuse == 1) {
8124: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
8125: $changes{$prefix}{$type} = 1;
8126: }
8127: }
8128: } else {
8129: if ($inuse == 1) {
8130: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
8131: $changes{$prefix}{$type} = 1;
8132: }
8133: }
8134: } else {
8135: if ($inuse == 1) {
8136: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
8137: $changes{$prefix}{$type} = 1;
8138: }
8139: }
8140: }
8141: }
8142: }
1.145 raeburn 8143:
8144: my @alldoms = &Apache::lonnet::all_domains();
1.149 raeburn 8145: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.145 raeburn 8146: my %spareid = ¤t_offloads_to($dom,$domconfig{'usersessions'},\%servers);
8147: my $savespares;
8148:
8149: foreach my $lonhost (sort(keys(%servers))) {
8150: my $serverhomeID =
8151: &Apache::lonnet::get_server_homeID($servers{$lonhost});
1.152 raeburn 8152: my $serverhostname = &Apache::lonnet::hostname($lonhost);
1.145 raeburn 8153: $defaultshash{'usersessions'}{'spares'}{$lonhost} = {};
8154: my %spareschg;
8155: foreach my $type (@{$types{'spares'}}) {
8156: my @okspares;
8157: my @checked = &Apache::loncommon::get_env_multiple('form.spare_'.$type.'_'.$lonhost);
8158: foreach my $server (@checked) {
1.152 raeburn 8159: if (&Apache::lonnet::hostname($server) ne '') {
8160: unless (&Apache::lonnet::hostname($server) eq $serverhostname) {
8161: unless (grep(/^\Q$server\E$/,@okspares)) {
8162: push(@okspares,$server);
8163: }
1.145 raeburn 8164: }
8165: }
8166: }
8167: my $new = $env{'form.newspare_'.$type.'_'.$lonhost};
8168: my $newspare;
1.152 raeburn 8169: if (($new ne '') && (&Apache::lonnet::hostname($new))) {
8170: unless (&Apache::lonnet::hostname($new) eq $serverhostname) {
1.145 raeburn 8171: $newspare = $new;
8172: }
8173: }
1.152 raeburn 8174: my @spares;
8175: if (($newspare ne '') && (!grep(/^\Q$newspare\E$/,@okspares))) {
8176: @spares = sort(@okspares,$newspare);
8177: } else {
8178: @spares = sort(@okspares);
8179: }
8180: $defaultshash{'usersessions'}{'spares'}{$lonhost}{$type} = \@spares;
1.145 raeburn 8181: if (ref($spareid{$lonhost}) eq 'HASH') {
8182: if (ref($spareid{$lonhost}{$type}) eq 'ARRAY') {
1.152 raeburn 8183: my @diffs = &Apache::loncommon::compare_arrays($spareid{$lonhost}{$type},\@spares);
1.145 raeburn 8184: if (@diffs > 0) {
8185: $spareschg{$type} = 1;
8186: }
8187: }
8188: }
8189: }
8190: if (keys(%spareschg) > 0) {
8191: $changes{'spares'}{$lonhost} = \%spareschg;
8192: }
8193: }
8194:
8195: if (ref($domconfig{'usersessions'}) eq 'HASH') {
8196: if (ref($domconfig{'usersessions'}{'spares'}) eq 'HASH') {
8197: if (ref($changes{'spares'}) eq 'HASH') {
8198: if (keys(%{$changes{'spares'}}) > 0) {
8199: $savespares = 1;
8200: }
8201: }
8202: } else {
8203: $savespares = 1;
8204: }
8205: }
8206:
1.147 raeburn 8207: my $nochgmsg = &mt('No changes made to settings for user session hosting/offloading.');
8208: if ((keys(%changes) > 0) || ($savespares)) {
1.137 raeburn 8209: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
8210: $dom);
8211: if ($putresult eq 'ok') {
8212: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
8213: if (ref($defaultshash{'usersessions'}{'remote'}) eq 'HASH') {
8214: $domdefaults{'remotesessions'} = $defaultshash{'usersessions'}{'remote'};
8215: }
8216: if (ref($defaultshash{'usersessions'}{'hosted'}) eq 'HASH') {
8217: $domdefaults{'hostedsessions'} = $defaultshash{'usersessions'}{'hosted'};
8218: }
8219: }
8220: my $cachetime = 24*60*60;
8221: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.147 raeburn 8222: if (keys(%changes) > 0) {
8223: my %lt = &usersession_titles();
8224: $resulttext = &mt('Changes made:').'<ul>';
8225: foreach my $prefix (@prefixes) {
8226: if (ref($changes{$prefix}) eq 'HASH') {
8227: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
8228: if ($prefix eq 'spares') {
8229: if (ref($changes{$prefix}) eq 'HASH') {
8230: foreach my $lonhost (sort(keys(%{$changes{$prefix}}))) {
8231: $resulttext .= '<li><b>'.$lonhost.'</b> ';
1.148 raeburn 8232: my $lonhostdom = &Apache::lonnet::host_domain($lonhost);
8233: &Apache::lonnet::remote_devalidate_cache($lonhost,'spares',$lonhostdom);
1.147 raeburn 8234: if (ref($changes{$prefix}{$lonhost}) eq 'HASH') {
8235: foreach my $type (@{$types{$prefix}}) {
8236: if ($changes{$prefix}{$lonhost}{$type}) {
8237: my $offloadto = &mt('None');
8238: if (ref($defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}) eq 'ARRAY') {
8239: if (@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}} > 0) {
8240: $offloadto = join(', ',@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}});
8241: }
1.145 raeburn 8242: }
1.147 raeburn 8243: $resulttext .= &mt('[_1] set to: [_2].','<i>'.$lt{$type}.'</i>',$offloadto).(' 'x3);
1.145 raeburn 8244: }
1.137 raeburn 8245: }
8246: }
1.147 raeburn 8247: $resulttext .= '</li>';
1.137 raeburn 8248: }
8249: }
1.147 raeburn 8250: } else {
8251: foreach my $type (@{$types{$prefix}}) {
8252: if (defined($changes{$prefix}{$type})) {
8253: my $newvalue;
8254: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
8255: if (ref($defaultshash{'usersessions'}{$prefix})) {
8256: if ($type eq 'version') {
8257: $newvalue = $defaultshash{'usersessions'}{$prefix}{$type};
8258: } elsif (ref($defaultshash{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
8259: if (@{$defaultshash{'usersessions'}{$prefix}{$type}} > 0) {
8260: $newvalue = join(', ',@{$defaultshash{'usersessions'}{$prefix}{$type}});
8261: }
1.145 raeburn 8262: }
8263: }
8264: }
1.147 raeburn 8265: if ($newvalue eq '') {
8266: if ($type eq 'version') {
8267: $resulttext .= '<li>'.&mt('[_1] set to: off',$lt{$type}).'</li>';
8268: } else {
8269: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
8270: }
1.145 raeburn 8271: } else {
1.147 raeburn 8272: if ($type eq 'version') {
8273: $newvalue .= ' '.&mt('(or later)');
8274: }
8275: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
1.145 raeburn 8276: }
1.137 raeburn 8277: }
8278: }
8279: }
1.147 raeburn 8280: $resulttext .= '</ul>';
1.137 raeburn 8281: }
8282: }
1.147 raeburn 8283: $resulttext .= '</ul>';
8284: } else {
8285: $resulttext = $nochgmsg;
1.137 raeburn 8286: }
8287: } else {
8288: $resulttext = '<span class="LC_error">'.
8289: &mt('An error occurred: [_1]',$putresult).'</span>';
8290: }
8291: } else {
1.147 raeburn 8292: $resulttext = $nochgmsg;
1.137 raeburn 8293: }
8294: return $resulttext;
8295: }
8296:
1.150 raeburn 8297: sub modify_loadbalancing {
8298: my ($dom,%domconfig) = @_;
8299: my $primary_id = &Apache::lonnet::domain($dom,'primary');
8300: my $intdom = &Apache::lonnet::internet_dom($primary_id);
8301: my ($othertitle,$usertypes,$types) =
8302: &Apache::loncommon::sorted_inst_types($dom);
8303: my %servers = &Apache::lonnet::internet_dom_servers($dom);
8304: my @sparestypes = ('primary','default');
8305: my %typetitles = &sparestype_titles();
8306: my $resulttext;
1.171 raeburn 8307: my (%currbalancer,%currtargets,%currrules,%existing);
8308: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
8309: %existing = %{$domconfig{'loadbalancing'}};
8310: }
8311: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
8312: \%currtargets,\%currrules);
8313: my ($saveloadbalancing,%defaultshash,%changes);
8314: my ($alltypes,$othertypes,$titles) =
8315: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
8316: my %ruletitles = &offloadtype_text();
8317: my @deletions = &Apache::loncommon::get_env_multiple('form.loadbalancing_delete');
8318: for (my $i=0; $i<$env{'form.loadbalancing_total'}; $i++) {
8319: my $balancer = $env{'form.loadbalancing_lonhost_'.$i};
8320: if ($balancer eq '') {
8321: next;
8322: }
8323: if (!exists($servers{$balancer})) {
8324: if (exists($currbalancer{$balancer})) {
8325: push(@{$changes{'delete'}},$balancer);
1.150 raeburn 8326: }
1.171 raeburn 8327: next;
8328: }
8329: if ((@deletions > 0) && (grep(/^\Q$i\E$/,@deletions))) {
8330: push(@{$changes{'delete'}},$balancer);
8331: next;
8332: }
8333: if (!exists($currbalancer{$balancer})) {
8334: push(@{$changes{'add'}},$balancer);
8335: }
8336: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'} = [];
8337: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'default'} = [];
8338: $defaultshash{'loadbalancing'}{$balancer}{'rules'} = {};
8339: unless (ref($domconfig{'loadbalancing'}) eq 'HASH') {
8340: $saveloadbalancing = 1;
8341: }
8342: foreach my $sparetype (@sparestypes) {
8343: my @targets = &Apache::loncommon::get_env_multiple('form.loadbalancing_target_'.$i.'_'.$sparetype);
8344: my @offloadto;
8345: foreach my $target (@targets) {
8346: if (($servers{$target}) && ($target ne $balancer)) {
8347: if ($sparetype eq 'default') {
8348: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}) eq 'ARRAY') {
8349: next if (grep(/^\Q$target\E$/,@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}}));
1.150 raeburn 8350: }
8351: }
1.171 raeburn 8352: unless(grep(/^\Q$target\E$/,@offloadto)) {
8353: push(@offloadto,$target);
8354: }
1.150 raeburn 8355: }
1.171 raeburn 8356: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype} = \@offloadto;
1.150 raeburn 8357: }
8358: }
1.171 raeburn 8359: if (ref($currtargets{$balancer}) eq 'HASH') {
1.150 raeburn 8360: foreach my $sparetype (@sparestypes) {
1.171 raeburn 8361: if (ref($currtargets{$balancer}{$sparetype}) eq 'ARRAY') {
8362: my @targetdiffs = &Apache::loncommon::compare_arrays($currtargets{$balancer}{$sparetype},$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype});
1.150 raeburn 8363: if (@targetdiffs > 0) {
1.171 raeburn 8364: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 8365: }
1.171 raeburn 8366: } elsif (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
8367: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
8368: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 8369: }
8370: }
8371: }
8372: } else {
1.171 raeburn 8373: if (ref($defaultshash{'loadbalancing'}{$balancer}) eq 'HASH') {
8374: foreach my $sparetype (@sparestypes) {
8375: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
8376: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
8377: $changes{'curr'}{$balancer}{'targets'} = 1;
8378: }
1.150 raeburn 8379: }
8380: }
8381: }
8382: }
8383: my $ishomedom;
1.171 raeburn 8384: if (&Apache::lonnet::host_domain($balancer) eq $dom) {
8385: $ishomedom = 1;
1.150 raeburn 8386: }
8387: if (ref($alltypes) eq 'ARRAY') {
8388: foreach my $type (@{$alltypes}) {
8389: my $rule;
1.171 raeburn 8390: unless ((($type eq '_LC_external') || ($type eq '_LC_internetdom')) &&
1.150 raeburn 8391: (!$ishomedom)) {
1.171 raeburn 8392: $rule = $env{'form.loadbalancing_rules_'.$i.'_'.$type};
8393: }
8394: if ($rule eq 'specific') {
8395: $rule = $env{'form.loadbalancing_singleserver_'.$i.'_'.$type};
1.150 raeburn 8396: }
1.171 raeburn 8397: $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type} = $rule;
8398: if (ref($currrules{$balancer}) eq 'HASH') {
8399: if ($rule ne $currrules{$balancer}{$type}) {
8400: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 8401: }
8402: } elsif ($rule ne '') {
1.171 raeburn 8403: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 8404: }
8405: }
8406: }
1.171 raeburn 8407: }
8408: my $nochgmsg = &mt('No changes made to Load Balancer settings.');
8409: if ((keys(%changes) > 0) || ($saveloadbalancing)) {
8410: unless (ref($defaultshash{'loadbalancing'}) eq 'HASH') {
8411: $defaultshash{'loadbalancing'} = {};
8412: }
8413: my $putresult = &Apache::lonnet::put_dom('configuration',
8414: \%defaultshash,$dom);
8415:
8416: if ($putresult eq 'ok') {
8417: if (keys(%changes) > 0) {
8418: if (ref($changes{'delete'}) eq 'ARRAY') {
8419: foreach my $balancer (sort(@{$changes{'delete'}})) {
8420: $resulttext .= '<li>'.&mt('Load Balancing discontinued for: [_1]',$balancer).'</li>';
1.150 raeburn 8421: &Apache::lonnet::remote_devalidate_cache($balancer,'loadbalancing',$dom);
8422: }
1.171 raeburn 8423: }
8424: if (ref($changes{'add'}) eq 'ARRAY') {
8425: foreach my $balancer (sort(@{$changes{'add'}})) {
8426: $resulttext .= '<li>'.&mt('Load Balancing enabled for: [_1]',$balancer);
8427: }
8428: }
8429: if (ref($changes{'curr'}) eq 'HASH') {
8430: foreach my $balancer (sort(keys(%{$changes{'curr'}}))) {
8431: if (ref($changes{'curr'}{$balancer}) eq 'HASH') {
8432: if ($changes{'curr'}{$balancer}{'targets'}) {
8433: my %offloadstr;
8434: foreach my $sparetype (@sparestypes) {
8435: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
8436: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
8437: $offloadstr{$sparetype} = join(', ',@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
8438: }
8439: }
1.150 raeburn 8440: }
1.171 raeburn 8441: if (keys(%offloadstr) == 0) {
8442: $resulttext .= '<li>'.&mt("Servers to which Load Balance server offloads set to 'None', by default").'</li>';
1.150 raeburn 8443: } else {
1.171 raeburn 8444: my $showoffload;
8445: foreach my $sparetype (@sparestypes) {
8446: $showoffload .= '<i>'.$typetitles{$sparetype}.'</i>: ';
8447: if (defined($offloadstr{$sparetype})) {
8448: $showoffload .= $offloadstr{$sparetype};
8449: } else {
8450: $showoffload .= &mt('None');
8451: }
8452: $showoffload .= (' 'x3);
8453: }
8454: $resulttext .= '<li>'.&mt('By default, Load Balancer: [_1] set to offload to - [_2]',$balancer,$showoffload).'</li>';
1.150 raeburn 8455: }
8456: }
8457: }
1.171 raeburn 8458: if (ref($changes{'curr'}{$balancer}{'rules'}) eq 'HASH') {
8459: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
8460: foreach my $type (@{$alltypes}) {
8461: if ($changes{'curr'}{$balancer}{'rules'}{$type}) {
8462: my $rule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
8463: my $balancetext;
8464: if ($rule eq '') {
8465: $balancetext = $ruletitles{'default'};
8466: } elsif (($rule eq 'homeserver') || ($rule eq 'externalbalancer')) {
8467: $balancetext = $ruletitles{$rule};
8468: } else {
8469: $balancetext = &mt('offload to [_1]',$defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type});
8470: }
8471: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- balancing for [_2] set to - "[_3]"',$balancer,$titles->{$type},$balancetext).'</li>';
1.150 raeburn 8472: }
8473: }
8474: }
8475: }
1.171 raeburn 8476: &Apache::lonnet::remote_devalidate_cache($balancer,'loadbalancing',$dom);
1.150 raeburn 8477: }
1.171 raeburn 8478: }
8479: if ($resulttext ne '') {
8480: $resulttext = &mt('Changes made:').'<ul>'.$resulttext.'</ul>';
1.150 raeburn 8481: } else {
8482: $resulttext = $nochgmsg;
8483: }
8484: } else {
1.171 raeburn 8485: $resulttext = $nochgmsg;
1.150 raeburn 8486: }
8487: } else {
1.171 raeburn 8488: $resulttext = '<span class="LC_error">'.
8489: &mt('An error occurred: [_1]',$putresult).'</span>';
1.150 raeburn 8490: }
8491: } else {
1.171 raeburn 8492: $resulttext = $nochgmsg;
1.150 raeburn 8493: }
8494: return $resulttext;
8495: }
8496:
1.48 raeburn 8497: sub recurse_check {
8498: my ($chkcats,$categories,$depth,$name) = @_;
8499: if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
8500: my $chg = 0;
8501: for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
8502: my $category = $chkcats->[$depth]{$name}[$j];
8503: my $item;
8504: if ($category eq '') {
8505: $chg ++;
8506: } else {
8507: my $deeper = $depth + 1;
8508: $item = &escape($category).':'.&escape($name).':'.$depth;
8509: if ($chg) {
8510: $categories->{$item} -= $chg;
8511: }
8512: &recurse_check($chkcats,$categories,$deeper,$category);
8513: $deeper --;
8514: }
8515: }
8516: }
8517: return;
8518: }
8519:
8520: sub recurse_cat_deletes {
8521: my ($item,$coursecategories,$deletions) = @_;
8522: my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
8523: my $subdepth = $depth + 1;
8524: if (ref($coursecategories) eq 'HASH') {
8525: foreach my $subitem (keys(%{$coursecategories})) {
8526: my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
8527: if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
8528: delete($coursecategories->{$subitem});
8529: $deletions->{$subitem} = 1;
8530: &recurse_cat_deletes($subitem,$coursecategories,$deletions);
1.168 raeburn 8531: }
1.48 raeburn 8532: }
8533: }
8534: return;
8535: }
8536:
1.125 raeburn 8537: sub get_active_dcs {
8538: my ($dom) = @_;
1.191 raeburn 8539: my $now = time;
8540: my %dompersonnel = &Apache::lonnet::get_domain_roles($dom,['dc'],$now,$now);
1.125 raeburn 8541: my %domcoords;
8542: my $numdcs = 0;
8543: foreach my $server (keys(%dompersonnel)) {
8544: foreach my $user (sort(keys(%{$dompersonnel{$server}}))) {
8545: my ($trole,$uname,$udom,$runame,$rudom,$rsec) = split(/:/,$user);
1.191 raeburn 8546: $domcoords{$uname.':'.$udom} = $dompersonnel{$server}{$user};
1.125 raeburn 8547: }
8548: }
8549: return %domcoords;
8550: }
8551:
8552: sub active_dc_picker {
1.191 raeburn 8553: my ($dom,$numinrow,$inputtype,$name,%currhash) = @_;
1.125 raeburn 8554: my %domcoords = &get_active_dcs($dom);
1.191 raeburn 8555: my @domcoord = keys(%domcoords);
8556: if (keys(%currhash)) {
8557: foreach my $dc (keys(%currhash)) {
8558: unless (exists($domcoords{$dc})) {
8559: push(@domcoord,$dc);
8560: }
8561: }
8562: }
8563: @domcoord = sort(@domcoord);
8564: my $numdcs = scalar(@domcoord);
8565: my $rows = 0;
8566: my $table;
1.125 raeburn 8567: if ($numdcs > 1) {
1.191 raeburn 8568: $table = '<table>';
8569: for (my $i=0; $i<@domcoord; $i++) {
1.125 raeburn 8570: my $rem = $i%($numinrow);
8571: if ($rem == 0) {
8572: if ($i > 0) {
1.191 raeburn 8573: $table .= '</tr>';
1.125 raeburn 8574: }
1.191 raeburn 8575: $table .= '<tr>';
8576: $rows ++;
1.125 raeburn 8577: }
1.191 raeburn 8578: my $check = '';
8579: if ($inputtype eq 'radio') {
8580: if (keys(%currhash) == 0) {
8581: if (!$i) {
8582: $check = ' checked="checked"';
8583: }
8584: } elsif (exists($currhash{$domcoord[$i]})) {
8585: $check = ' checked="checked"';
8586: }
8587: } else {
8588: if (exists($currhash{$domcoord[$i]})) {
8589: $check = ' checked="checked"';
1.125 raeburn 8590: }
8591: }
1.191 raeburn 8592: if ($i == @domcoord - 1) {
1.125 raeburn 8593: my $colsleft = $numinrow - $rem;
8594: if ($colsleft > 1) {
1.191 raeburn 8595: $table .= '<td class="LC_left_item" colspan="'.$colsleft.'">';
1.125 raeburn 8596: } else {
1.191 raeburn 8597: $table .= '<td class="LC_left_item">';
1.125 raeburn 8598: }
8599: } else {
1.191 raeburn 8600: $table .= '<td class="LC_left_item">';
8601: }
8602: my ($dcname,$dcdom) = split(':',$domcoord[$i]);
8603: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
8604: $table .= '<span class="LC_nobreak"><label>'.
8605: '<input type="'.$inputtype.'" name="'.$name.'"'.
8606: ' value="'.$domcoord[$i].'"'.$check.' />'.$user;
8607: if ($user ne $dcname.':'.$dcdom) {
8608: $table .= ' ('.$dcname.':'.$dcdom.')'.
8609: '</label></span></td>';
8610: }
8611: }
8612: $table .= '</tr></table>';
8613: } elsif ($numdcs == 1) {
8614: if ($inputtype eq 'radio') {
8615: $table .= '<input type="hidden" name="'.$name.'" value="'.$domcoord[0].'" />';
8616: } else {
8617: my $check;
8618: if (exists($currhash{$domcoord[0]})) {
8619: $check = ' checked="checked"';
1.125 raeburn 8620: }
1.191 raeburn 8621: $table .= '<input type="checkbox" name="'.$name.'" '.
8622: 'value="'.$domcoord[0].'"'.$check.' />';
8623: $rows ++;
1.125 raeburn 8624: }
8625: }
1.191 raeburn 8626: return ($numdcs,$table,$rows);
1.125 raeburn 8627: }
8628:
1.137 raeburn 8629: sub usersession_titles {
8630: return &Apache::lonlocal::texthash(
8631: hosted => 'Hosting of sessions for users from other domains on servers in this domain',
8632: remote => 'Hosting of sessions for users in this domain on servers in other domains',
1.145 raeburn 8633: spares => 'Servers offloaded to, when busy',
1.137 raeburn 8634: version => 'LON-CAPA version requirement',
1.138 raeburn 8635: excludedomain => 'Allow all, but exclude specific domains',
8636: includedomain => 'Deny all, but include specific domains',
1.145 raeburn 8637: primary => 'Primary (checked first)',
1.154 raeburn 8638: default => 'Default',
1.137 raeburn 8639: );
8640: }
8641:
1.152 raeburn 8642: sub id_for_thisdom {
8643: my (%servers) = @_;
8644: my %altids;
8645: foreach my $server (keys(%servers)) {
8646: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
8647: if ($serverhome ne $server) {
8648: $altids{$serverhome} = $server;
8649: }
8650: }
8651: return %altids;
8652: }
8653:
1.150 raeburn 8654: sub count_servers {
8655: my ($currbalancer,%servers) = @_;
8656: my (@spares,$numspares);
8657: foreach my $lonhost (sort(keys(%servers))) {
8658: next if ($currbalancer eq $lonhost);
8659: push(@spares,$lonhost);
8660: }
8661: if ($currbalancer) {
8662: $numspares = scalar(@spares);
8663: } else {
8664: $numspares = scalar(@spares) - 1;
8665: }
8666: return ($numspares,@spares);
8667: }
8668:
8669: sub lonbalance_targets_js {
1.171 raeburn 8670: my ($dom,$types,$servers,$settings) = @_;
1.150 raeburn 8671: my $select = &mt('Select');
8672: my ($alltargets,$allishome,$allinsttypes,@alltypes);
8673: if (ref($servers) eq 'HASH') {
8674: $alltargets = join("','",sort(keys(%{$servers})));
8675: my @homedoms;
8676: foreach my $server (sort(keys(%{$servers}))) {
8677: if (&Apache::lonnet::host_domain($server) eq $dom) {
8678: push(@homedoms,'1');
8679: } else {
8680: push(@homedoms,'0');
8681: }
8682: }
8683: $allishome = join("','",@homedoms);
8684: }
8685: if (ref($types) eq 'ARRAY') {
8686: if (@{$types} > 0) {
8687: @alltypes = @{$types};
8688: }
8689: }
8690: push(@alltypes,'default','_LC_adv','_LC_author','_LC_internetdom','_LC_external');
8691: $allinsttypes = join("','",@alltypes);
1.171 raeburn 8692: my (%currbalancer,%currtargets,%currrules,%existing);
8693: if (ref($settings) eq 'HASH') {
8694: %existing = %{$settings};
8695: }
8696: &get_loadbalancers_config($servers,\%existing,\%currbalancer,
8697: \%currtargets,\%currrules);
8698: my $balancers = join("','",sort(keys(%currbalancer)));
1.150 raeburn 8699: return <<"END";
8700:
8701: <script type="text/javascript">
8702: // <![CDATA[
8703:
1.171 raeburn 8704: currBalancers = new Array('$balancers');
8705:
8706: function toggleTargets(balnum) {
8707: var lonhostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
8708: var prevhostitem = document.getElementById('loadbalancing_prevlonhost_'+balnum);
8709: var balancer = lonhostitem.options[lonhostitem.selectedIndex].value;
8710: var prevbalancer = prevhostitem.value;
8711: var baltotal = document.getElementById('loadbalancing_total').value;
8712: prevhostitem.value = balancer;
8713: if (prevbalancer != '') {
8714: var prevIdx = currBalancers.indexOf(prevbalancer);
8715: if (prevIdx != -1) {
8716: currBalancers.splice(prevIdx,1);
8717: }
8718: }
1.150 raeburn 8719: if (balancer == '') {
1.171 raeburn 8720: hideSpares(balnum);
1.150 raeburn 8721: } else {
1.171 raeburn 8722: var currIdx = currBalancers.indexOf(balancer);
8723: if (currIdx == -1) {
8724: currBalancers.push(balancer);
8725: }
1.150 raeburn 8726: var homedoms = new Array('$allishome');
1.171 raeburn 8727: var ishomedom = homedoms[lonhostitem.selectedIndex];
8728: showSpares(balancer,ishomedom,balnum);
1.150 raeburn 8729: }
1.171 raeburn 8730: balancerChange(balnum,baltotal,'change',prevbalancer,balancer);
1.150 raeburn 8731: return;
8732: }
8733:
1.171 raeburn 8734: function showSpares(balancer,ishomedom,balnum) {
1.150 raeburn 8735: var alltargets = new Array('$alltargets');
8736: var insttypes = new Array('$allinsttypes');
1.151 raeburn 8737: var offloadtypes = new Array('primary','default');
8738:
1.171 raeburn 8739: document.getElementById('loadbalancing_targets_'+balnum).style.display='block';
8740: document.getElementById('loadbalancing_disabled_'+balnum).style.display='none';
1.152 raeburn 8741:
1.151 raeburn 8742: for (var i=0; i<offloadtypes.length; i++) {
8743: var count = 0;
8744: for (var j=0; j<alltargets.length; j++) {
8745: if (alltargets[j] != balancer) {
1.171 raeburn 8746: var item = document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+count);
8747: item.value = alltargets[j];
8748: item.style.textAlign='left';
8749: item.style.textFace='normal';
8750: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+count).innerHTML = alltargets[j];
8751: if (currBalancers.indexOf(alltargets[j]) == -1) {
8752: item.disabled = '';
8753: } else {
8754: item.disabled = 'disabled';
8755: item.checked = false;
8756: }
1.151 raeburn 8757: count ++;
8758: }
1.150 raeburn 8759: }
8760: }
1.151 raeburn 8761: for (var k=0; k<insttypes.length; k++) {
8762: if ((insttypes[k] == '_LC_external') || (insttypes[k] == '_LC_internetdom')) {
1.150 raeburn 8763: if (ishomedom == 1) {
1.171 raeburn 8764: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
8765: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 8766: } else {
1.171 raeburn 8767: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
8768: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.150 raeburn 8769:
8770: }
8771: } else {
1.171 raeburn 8772: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
8773: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 8774: }
1.151 raeburn 8775: if ((insttypes[k] != '_LC_external') &&
8776: ((insttypes[k] != '_LC_internetdom') ||
8777: ((insttypes[k] == '_LC_internetdom') && (ishomedom == 1)))) {
1.171 raeburn 8778: var item = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]);
8779: item.options.length = 0;
8780: item.options[0] = new Option("","",true,true);
8781: var idx = 0;
1.151 raeburn 8782: for (var m=0; m<alltargets.length; m++) {
1.171 raeburn 8783: if ((currBalancers.indexOf(alltargets[m]) == -1) && (alltargets[m] != balancer)) {
8784: idx ++;
8785: item.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
8786:
1.150 raeburn 8787: }
8788: }
8789: }
8790: }
8791: return;
8792: }
8793:
1.171 raeburn 8794: function hideSpares(balnum) {
1.150 raeburn 8795: var alltargets = new Array('$alltargets');
8796: var insttypes = new Array('$allinsttypes');
8797: var offloadtypes = new Array('primary','default');
8798:
1.171 raeburn 8799: document.getElementById('loadbalancing_targets_'+balnum).style.display='none';
8800: document.getElementById('loadbalancing_disabled_'+balnum).style.display='block';
1.150 raeburn 8801:
8802: var total = alltargets.length - 1;
8803: for (var i=0; i<offloadtypes; i++) {
8804: for (var j=0; j<total; j++) {
1.171 raeburn 8805: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).checked = false;
8806: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).value = '';
8807: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+j).innerHTML = '';
1.151 raeburn 8808: }
1.150 raeburn 8809: }
8810: for (var k=0; k<insttypes.length; k++) {
1.171 raeburn 8811: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
8812: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.151 raeburn 8813: if (insttypes[k] != '_LC_external') {
1.171 raeburn 8814: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).length = 0;
8815: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).options[0] = new Option("","",true,true);
1.150 raeburn 8816: }
8817: }
8818: return;
8819: }
8820:
1.171 raeburn 8821: function checkOffloads(item,balnum,type) {
1.150 raeburn 8822: var alltargets = new Array('$alltargets');
8823: var offloadtypes = new Array('primary','default');
8824: if (item.checked) {
8825: var total = alltargets.length - 1;
8826: var other;
8827: if (type == offloadtypes[0]) {
1.151 raeburn 8828: other = offloadtypes[1];
1.150 raeburn 8829: } else {
1.151 raeburn 8830: other = offloadtypes[0];
1.150 raeburn 8831: }
8832: for (var i=0; i<total; i++) {
1.171 raeburn 8833: var server = document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).value;
1.150 raeburn 8834: if (server == item.value) {
1.171 raeburn 8835: if (document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked) {
8836: document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked = false;
1.150 raeburn 8837: }
8838: }
8839: }
8840: }
8841: return;
8842: }
8843:
1.171 raeburn 8844: function singleServerToggle(balnum,type) {
8845: var offloadtoSelIdx = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex;
1.150 raeburn 8846: if (offloadtoSelIdx == 0) {
1.171 raeburn 8847: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_0').checked = true;
8848: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 8849:
8850: } else {
1.171 raeburn 8851: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_2').checked = true;
8852: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
1.150 raeburn 8853: }
8854: return;
8855: }
8856:
1.171 raeburn 8857: function balanceruleChange(formname,balnum,type) {
1.150 raeburn 8858: if (type == '_LC_external') {
1.171 raeburn 8859: return;
1.150 raeburn 8860: }
1.171 raeburn 8861: var typesRules = getIndicesByName(formname,'loadbalancing_rules_'+balnum+'_'+type);
1.150 raeburn 8862: for (var i=0; i<typesRules.length; i++) {
8863: if (formname.elements[typesRules[i]].checked) {
8864: if (formname.elements[typesRules[i]].value != 'specific') {
1.171 raeburn 8865: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex = 0;
8866: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 8867: } else {
1.171 raeburn 8868: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
8869: }
8870: }
8871: }
8872: return;
8873: }
8874:
8875: function balancerDeleteChange(balnum) {
8876: var hostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
8877: var baltotal = document.getElementById('loadbalancing_total').value;
8878: var addtarget;
8879: var removetarget;
8880: var action = 'delete';
8881: if (document.getElementById('loadbalancing_delete_'+balnum)) {
8882: var lonhost = hostitem.value;
8883: var currIdx = currBalancers.indexOf(lonhost);
8884: if (document.getElementById('loadbalancing_delete_'+balnum).checked) {
8885: if (currIdx != -1) {
8886: currBalancers.splice(currIdx,1);
8887: }
8888: addtarget = lonhost;
8889: } else {
8890: if (currIdx == -1) {
8891: currBalancers.push(lonhost);
8892: }
8893: removetarget = lonhost;
8894: action = 'undelete';
8895: }
8896: balancerChange(balnum,baltotal,action,addtarget,removetarget);
8897: }
8898: return;
8899: }
8900:
8901: function balancerChange(balnum,baltotal,action,addtarget,removetarget) {
8902: if (baltotal > 1) {
8903: var offloadtypes = new Array('primary','default');
8904: var alltargets = new Array('$alltargets');
8905: var insttypes = new Array('$allinsttypes');
8906: for (var i=0; i<baltotal; i++) {
8907: if (i != balnum) {
8908: for (var j=0; j<offloadtypes.length; j++) {
8909: var total = alltargets.length - 1;
8910: for (var k=0; k<total; k++) {
8911: var serveritem = document.getElementById('loadbalancing_target_'+i+'_'+offloadtypes[j]+'_'+k);
8912: var server = serveritem.value;
8913: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
8914: if (server == addtarget) {
8915: serveritem.disabled = '';
8916: }
8917: }
8918: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
8919: if (server == removetarget) {
8920: serveritem.disabled = 'disabled';
8921: serveritem.checked = false;
8922: }
8923: }
8924: }
8925: }
8926: for (var j=0; j<insttypes.length; j++) {
8927: if (insttypes[j] != '_LC_external') {
8928: if (document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j])) {
8929: var singleserver = document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j]);
8930: var currSel = singleserver.selectedIndex;
8931: var currVal = singleserver.options[currSel].value;
8932: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
8933: var numoptions = singleserver.options.length;
8934: var needsnew = 1;
8935: for (var k=0; k<numoptions; k++) {
8936: if (singleserver.options[k] == addtarget) {
8937: needsnew = 0;
8938: break;
8939: }
8940: }
8941: if (needsnew == 1) {
8942: singleserver.options[numoptions] = new Option(addtarget,addtarget,false,false);
8943: }
8944: }
8945: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
8946: singleserver.options.length = 0;
8947: if ((currVal) && (currVal != removetarget)) {
8948: singleserver.options[0] = new Option("","",false,false);
8949: } else {
8950: singleserver.options[0] = new Option("","",true,true);
8951: }
8952: var idx = 0;
8953: for (var m=0; m<alltargets.length; m++) {
8954: if (currBalancers.indexOf(alltargets[m]) == -1) {
8955: idx ++;
8956: if (currVal == alltargets[m]) {
8957: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],true,true);
8958: } else {
8959: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
8960: }
8961: }
8962: }
8963: }
8964: }
8965: }
8966: }
1.150 raeburn 8967: }
8968: }
8969: }
8970: return;
8971: }
8972:
1.152 raeburn 8973: // ]]>
8974: </script>
8975:
8976: END
8977: }
8978:
8979: sub new_spares_js {
8980: my @sparestypes = ('primary','default');
8981: my $types = join("','",@sparestypes);
8982: my $select = &mt('Select');
8983: return <<"END";
8984:
8985: <script type="text/javascript">
8986: // <![CDATA[
8987:
8988: function updateNewSpares(formname,lonhost) {
8989: var types = new Array('$types');
8990: var include = new Array();
8991: var exclude = new Array();
8992: for (var i=0; i<types.length; i++) {
8993: var spareboxes = getIndicesByName(formname,'spare_'+types[i]+'_'+lonhost);
8994: for (var j=0; j<spareboxes.length; j++) {
8995: if (formname.elements[spareboxes[j]].checked) {
8996: exclude.push(formname.elements[spareboxes[j]].value);
8997: } else {
8998: include.push(formname.elements[spareboxes[j]].value);
8999: }
9000: }
9001: }
9002: for (var i=0; i<types.length; i++) {
9003: var newSpare = document.getElementById('newspare_'+types[i]+'_'+lonhost);
9004: var selIdx = newSpare.selectedIndex;
9005: var currnew = newSpare.options[selIdx].value;
9006: var okSpares = new Array();
9007: for (var j=0; j<newSpare.options.length; j++) {
9008: var possible = newSpare.options[j].value;
9009: if (possible != '') {
9010: if (exclude.indexOf(possible) == -1) {
9011: okSpares.push(possible);
9012: } else {
9013: if (currnew == possible) {
9014: selIdx = 0;
9015: }
9016: }
9017: }
9018: }
9019: for (var k=0; k<include.length; k++) {
9020: if (okSpares.indexOf(include[k]) == -1) {
9021: okSpares.push(include[k]);
9022: }
9023: }
9024: okSpares.sort();
9025: newSpare.options.length = 0;
9026: if (selIdx == 0) {
9027: newSpare.options[0] = new Option("$select","",true,true);
9028: } else {
9029: newSpare.options[0] = new Option("$select","",false,false);
9030: }
9031: for (var m=0; m<okSpares.length; m++) {
9032: var idx = m+1;
9033: var selThis = 0;
9034: if (selIdx != 0) {
9035: if (okSpares[m] == currnew) {
9036: selThis = 1;
9037: }
9038: }
9039: if (selThis == 1) {
9040: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],true,true);
9041: } else {
9042: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],false,false);
9043: }
9044: }
9045: }
9046: return;
9047: }
9048:
9049: function checkNewSpares(lonhost,type) {
9050: var newSpare = document.getElementById('newspare_'+type+'_'+lonhost);
9051: var chosen = newSpare.options[newSpare.selectedIndex].value;
9052: if (chosen != '') {
9053: var othertype;
9054: var othernewSpare;
9055: if (type == 'primary') {
9056: othernewSpare = document.getElementById('newspare_default_'+lonhost);
9057: }
9058: if (type == 'default') {
9059: othernewSpare = document.getElementById('newspare_primary_'+lonhost);
9060: }
9061: if (othernewSpare.options[othernewSpare.selectedIndex].value == chosen) {
9062: othernewSpare.selectedIndex = 0;
9063: }
9064: }
9065: return;
9066: }
9067:
9068: // ]]>
9069: </script>
9070:
9071: END
9072:
9073: }
9074:
9075: sub common_domprefs_js {
9076: return <<"END";
9077:
9078: <script type="text/javascript">
9079: // <![CDATA[
9080:
1.150 raeburn 9081: function getIndicesByName(formname,item) {
1.152 raeburn 9082: var group = new Array();
1.150 raeburn 9083: for (var i=0;i<formname.elements.length;i++) {
9084: if (formname.elements[i].name == item) {
1.152 raeburn 9085: group.push(formname.elements[i].id);
1.150 raeburn 9086: }
9087: }
1.152 raeburn 9088: return group;
1.150 raeburn 9089: }
9090:
9091: // ]]>
9092: </script>
9093:
9094: END
1.152 raeburn 9095:
1.150 raeburn 9096: }
9097:
1.165 raeburn 9098: sub recaptcha_js {
9099: my %lt = &captcha_phrases();
9100: return <<"END";
9101:
9102: <script type="text/javascript">
9103: // <![CDATA[
9104:
9105: function updateCaptcha(caller,context) {
9106: var privitem;
9107: var pubitem;
9108: var privtext;
9109: var pubtext;
9110: if (document.getElementById(context+'_recaptchapub')) {
9111: pubitem = document.getElementById(context+'_recaptchapub');
9112: } else {
9113: return;
9114: }
9115: if (document.getElementById(context+'_recaptchapriv')) {
9116: privitem = document.getElementById(context+'_recaptchapriv');
9117: } else {
9118: return;
9119: }
9120: if (document.getElementById(context+'_recaptchapubtxt')) {
9121: pubtext = document.getElementById(context+'_recaptchapubtxt');
9122: } else {
9123: return;
9124: }
9125: if (document.getElementById(context+'_recaptchaprivtxt')) {
9126: privtext = document.getElementById(context+'_recaptchaprivtxt');
9127: } else {
9128: return;
9129: }
9130: if (caller.checked) {
9131: if (caller.value == 'recaptcha') {
9132: pubitem.type = 'text';
9133: privitem.type = 'text';
9134: pubitem.size = '40';
9135: privitem.size = '40';
9136: pubtext.innerHTML = "$lt{'pub'}";
9137: privtext.innerHTML = "$lt{'priv'}";
9138: } else {
9139: pubitem.type = 'hidden';
9140: privitem.type = 'hidden';
9141: pubtext.innerHTML = '';
9142: privtext.innerHTML = '';
9143: }
9144: }
9145: return;
9146: }
9147:
9148: // ]]>
9149: </script>
9150:
9151: END
9152:
9153: }
9154:
1.192 raeburn 9155: sub credits_js {
9156: return <<"END";
9157:
9158: <script type="text/javascript">
9159: // <![CDATA[
9160:
9161: function toggleCredits(domForm) {
9162: if (document.getElementById('credits')) {
9163: creditsitem = document.getElementById('credits');
9164: var creditsLength = domForm.coursecredits.length;
9165: if (creditsLength) {
9166: var currval;
9167: for (var i=0; i<creditsLength; i++) {
9168: if (domForm.coursecredits[i].checked) {
9169: currval = domForm.coursecredits[i].value;
9170: }
9171: }
9172: if (currval == 1) {
9173: creditsitem.style.display = 'block';
9174: } else {
9175: creditsitem.style.display = 'none';
9176: }
9177: }
9178: }
9179: return;
9180: }
9181:
9182: // ]]>
9183: </script>
9184:
9185: END
9186:
9187: }
9188:
1.165 raeburn 9189: sub captcha_phrases {
9190: return &Apache::lonlocal::texthash (
9191: priv => 'Private key',
9192: pub => 'Public key',
9193: original => 'original (CAPTCHA)',
9194: recaptcha => 'successor (ReCAPTCHA)',
9195: notused => 'unused',
9196: );
9197: }
9198:
1.3 raeburn 9199: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>